cirrusfb.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992
  1. /*
  2. * drivers/video/cirrusfb.c - driver for Cirrus Logic chipsets
  3. *
  4. * Copyright 1999-2001 Jeff Garzik <jgarzik@pobox.com>
  5. *
  6. * Contributors (thanks, all!)
  7. *
  8. * David Eger:
  9. * Overhaul for Linux 2.6
  10. *
  11. * Jeff Rugen:
  12. * Major contributions; Motorola PowerStack (PPC and PCI) support,
  13. * GD54xx, 1280x1024 mode support, change MCLK based on VCLK.
  14. *
  15. * Geert Uytterhoeven:
  16. * Excellent code review.
  17. *
  18. * Lars Hecking:
  19. * Amiga updates and testing.
  20. *
  21. * Original cirrusfb author: Frank Neumann
  22. *
  23. * Based on retz3fb.c and cirrusfb.c:
  24. * Copyright (C) 1997 Jes Sorensen
  25. * Copyright (C) 1996 Frank Neumann
  26. *
  27. ***************************************************************
  28. *
  29. * Format this code with GNU indent '-kr -i8 -pcs' options.
  30. *
  31. * This file is subject to the terms and conditions of the GNU General Public
  32. * License. See the file COPYING in the main directory of this archive
  33. * for more details.
  34. *
  35. */
  36. #include <linux/module.h>
  37. #include <linux/kernel.h>
  38. #include <linux/errno.h>
  39. #include <linux/string.h>
  40. #include <linux/mm.h>
  41. #include <linux/delay.h>
  42. #include <linux/fb.h>
  43. #include <linux/init.h>
  44. #include <asm/pgtable.h>
  45. #ifdef CONFIG_ZORRO
  46. #include <linux/zorro.h>
  47. #endif
  48. #ifdef CONFIG_PCI
  49. #include <linux/pci.h>
  50. #endif
  51. #ifdef CONFIG_AMIGA
  52. #include <asm/amigahw.h>
  53. #endif
  54. #ifdef CONFIG_PPC_PREP
  55. #include <asm/machdep.h>
  56. #define isPReP machine_is(prep)
  57. #else
  58. #define isPReP 0
  59. #endif
  60. #include <video/vga.h>
  61. #include <video/cirrus.h>
  62. /*****************************************************************
  63. *
  64. * debugging and utility macros
  65. *
  66. */
  67. /* disable runtime assertions? */
  68. /* #define CIRRUSFB_NDEBUG */
  69. /* debugging assertions */
  70. #ifndef CIRRUSFB_NDEBUG
  71. #define assert(expr) \
  72. if (!(expr)) { \
  73. printk("Assertion failed! %s,%s,%s,line=%d\n", \
  74. #expr, __FILE__, __func__, __LINE__); \
  75. }
  76. #else
  77. #define assert(expr)
  78. #endif
  79. #define MB_ (1024 * 1024)
  80. /*****************************************************************
  81. *
  82. * chipset information
  83. *
  84. */
  85. /* board types */
  86. enum cirrus_board {
  87. BT_NONE = 0,
  88. BT_SD64, /* GD5434 */
  89. BT_PICCOLO, /* GD5426 */
  90. BT_PICASSO, /* GD5426 or GD5428 */
  91. BT_SPECTRUM, /* GD5426 or GD5428 */
  92. BT_PICASSO4, /* GD5446 */
  93. BT_ALPINE, /* GD543x/4x */
  94. BT_GD5480,
  95. BT_LAGUNA, /* GD5462/64 */
  96. BT_LAGUNAB, /* GD5465 */
  97. };
  98. /*
  99. * per-board-type information, used for enumerating and abstracting
  100. * chip-specific information
  101. * NOTE: MUST be in the same order as enum cirrus_board in order to
  102. * use direct indexing on this array
  103. * NOTE: '__initdata' cannot be used as some of this info
  104. * is required at runtime. Maybe separate into an init-only and
  105. * a run-time table?
  106. */
  107. static const struct cirrusfb_board_info_rec {
  108. char *name; /* ASCII name of chipset */
  109. long maxclock[5]; /* maximum video clock */
  110. /* for 1/4bpp, 8bpp 15/16bpp, 24bpp, 32bpp - numbers from xorg code */
  111. bool init_sr07 : 1; /* init SR07 during init_vgachip() */
  112. bool init_sr1f : 1; /* write SR1F during init_vgachip() */
  113. /* construct bit 19 of screen start address */
  114. bool scrn_start_bit19 : 1;
  115. /* initial SR07 value, then for each mode */
  116. unsigned char sr07;
  117. unsigned char sr07_1bpp;
  118. unsigned char sr07_1bpp_mux;
  119. unsigned char sr07_8bpp;
  120. unsigned char sr07_8bpp_mux;
  121. unsigned char sr1f; /* SR1F VGA initial register value */
  122. } cirrusfb_board_info[] = {
  123. [BT_SD64] = {
  124. .name = "CL SD64",
  125. .maxclock = {
  126. /* guess */
  127. /* the SD64/P4 have a higher max. videoclock */
  128. 135100, 135100, 85500, 85500, 0
  129. },
  130. .init_sr07 = true,
  131. .init_sr1f = true,
  132. .scrn_start_bit19 = true,
  133. .sr07 = 0xF0,
  134. .sr07_1bpp = 0xF0,
  135. .sr07_1bpp_mux = 0xF6,
  136. .sr07_8bpp = 0xF1,
  137. .sr07_8bpp_mux = 0xF7,
  138. .sr1f = 0x1E
  139. },
  140. [BT_PICCOLO] = {
  141. .name = "CL Piccolo",
  142. .maxclock = {
  143. /* guess */
  144. 90000, 90000, 90000, 90000, 90000
  145. },
  146. .init_sr07 = true,
  147. .init_sr1f = true,
  148. .scrn_start_bit19 = false,
  149. .sr07 = 0x80,
  150. .sr07_1bpp = 0x80,
  151. .sr07_8bpp = 0x81,
  152. .sr1f = 0x22
  153. },
  154. [BT_PICASSO] = {
  155. .name = "CL Picasso",
  156. .maxclock = {
  157. /* guess */
  158. 90000, 90000, 90000, 90000, 90000
  159. },
  160. .init_sr07 = true,
  161. .init_sr1f = true,
  162. .scrn_start_bit19 = false,
  163. .sr07 = 0x20,
  164. .sr07_1bpp = 0x20,
  165. .sr07_8bpp = 0x21,
  166. .sr1f = 0x22
  167. },
  168. [BT_SPECTRUM] = {
  169. .name = "CL Spectrum",
  170. .maxclock = {
  171. /* guess */
  172. 90000, 90000, 90000, 90000, 90000
  173. },
  174. .init_sr07 = true,
  175. .init_sr1f = true,
  176. .scrn_start_bit19 = false,
  177. .sr07 = 0x80,
  178. .sr07_1bpp = 0x80,
  179. .sr07_8bpp = 0x81,
  180. .sr1f = 0x22
  181. },
  182. [BT_PICASSO4] = {
  183. .name = "CL Picasso4",
  184. .maxclock = {
  185. 135100, 135100, 85500, 85500, 0
  186. },
  187. .init_sr07 = true,
  188. .init_sr1f = false,
  189. .scrn_start_bit19 = true,
  190. .sr07 = 0xA0,
  191. .sr07_1bpp = 0xA0,
  192. .sr07_1bpp_mux = 0xA6,
  193. .sr07_8bpp = 0xA1,
  194. .sr07_8bpp_mux = 0xA7,
  195. .sr1f = 0
  196. },
  197. [BT_ALPINE] = {
  198. .name = "CL Alpine",
  199. .maxclock = {
  200. /* for the GD5430. GD5446 can do more... */
  201. 85500, 85500, 50000, 28500, 0
  202. },
  203. .init_sr07 = true,
  204. .init_sr1f = true,
  205. .scrn_start_bit19 = true,
  206. .sr07 = 0xA0,
  207. .sr07_1bpp = 0xA0,
  208. .sr07_1bpp_mux = 0xA6,
  209. .sr07_8bpp = 0xA1,
  210. .sr07_8bpp_mux = 0xA7,
  211. .sr1f = 0x1C
  212. },
  213. [BT_GD5480] = {
  214. .name = "CL GD5480",
  215. .maxclock = {
  216. 135100, 200000, 200000, 135100, 135100
  217. },
  218. .init_sr07 = true,
  219. .init_sr1f = true,
  220. .scrn_start_bit19 = true,
  221. .sr07 = 0x10,
  222. .sr07_1bpp = 0x11,
  223. .sr07_8bpp = 0x11,
  224. .sr1f = 0x1C
  225. },
  226. [BT_LAGUNA] = {
  227. .name = "CL Laguna",
  228. .maxclock = {
  229. /* taken from X11 code */
  230. 170000, 170000, 170000, 170000, 135100,
  231. },
  232. .init_sr07 = false,
  233. .init_sr1f = false,
  234. .scrn_start_bit19 = true,
  235. },
  236. [BT_LAGUNAB] = {
  237. .name = "CL Laguna AGP",
  238. .maxclock = {
  239. /* taken from X11 code */
  240. 170000, 250000, 170000, 170000, 135100,
  241. },
  242. .init_sr07 = false,
  243. .init_sr1f = false,
  244. .scrn_start_bit19 = true,
  245. }
  246. };
  247. #ifdef CONFIG_PCI
  248. #define CHIP(id, btype) \
  249. { PCI_VENDOR_ID_CIRRUS, id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (btype) }
  250. static struct pci_device_id cirrusfb_pci_table[] = {
  251. CHIP(PCI_DEVICE_ID_CIRRUS_5436, BT_ALPINE),
  252. CHIP(PCI_DEVICE_ID_CIRRUS_5434_8, BT_SD64),
  253. CHIP(PCI_DEVICE_ID_CIRRUS_5434_4, BT_SD64),
  254. CHIP(PCI_DEVICE_ID_CIRRUS_5430, BT_ALPINE), /* GD-5440 is same id */
  255. CHIP(PCI_DEVICE_ID_CIRRUS_7543, BT_ALPINE),
  256. CHIP(PCI_DEVICE_ID_CIRRUS_7548, BT_ALPINE),
  257. CHIP(PCI_DEVICE_ID_CIRRUS_5480, BT_GD5480), /* MacPicasso likely */
  258. CHIP(PCI_DEVICE_ID_CIRRUS_5446, BT_PICASSO4), /* Picasso 4 is 5446 */
  259. CHIP(PCI_DEVICE_ID_CIRRUS_5462, BT_LAGUNA), /* CL Laguna */
  260. CHIP(PCI_DEVICE_ID_CIRRUS_5464, BT_LAGUNA), /* CL Laguna 3D */
  261. CHIP(PCI_DEVICE_ID_CIRRUS_5465, BT_LAGUNAB), /* CL Laguna 3DA*/
  262. { 0, }
  263. };
  264. MODULE_DEVICE_TABLE(pci, cirrusfb_pci_table);
  265. #undef CHIP
  266. #endif /* CONFIG_PCI */
  267. #ifdef CONFIG_ZORRO
  268. struct zorrocl {
  269. enum cirrus_board type; /* Board type */
  270. u32 regoffset; /* Offset of registers in first Zorro device */
  271. u32 ramsize; /* Size of video RAM in first Zorro device */
  272. /* If zero, use autoprobe on RAM device */
  273. u32 ramoffset; /* Offset of video RAM in first Zorro device */
  274. zorro_id ramid; /* Zorro ID of RAM device */
  275. zorro_id ramid2; /* Zorro ID of optional second RAM device */
  276. };
  277. static const struct zorrocl zcl_sd64 __devinitconst = {
  278. .type = BT_SD64,
  279. .ramid = ZORRO_PROD_HELFRICH_SD64_RAM,
  280. };
  281. static const struct zorrocl zcl_piccolo __devinitconst = {
  282. .type = BT_PICCOLO,
  283. .ramid = ZORRO_PROD_HELFRICH_PICCOLO_RAM,
  284. };
  285. static const struct zorrocl zcl_picasso __devinitconst = {
  286. .type = BT_PICASSO,
  287. .ramid = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_RAM,
  288. };
  289. static const struct zorrocl zcl_spectrum __devinitconst = {
  290. .type = BT_SPECTRUM,
  291. .ramid = ZORRO_PROD_GVP_EGS_28_24_SPECTRUM_RAM,
  292. };
  293. static const struct zorrocl zcl_picasso4_z3 __devinitconst = {
  294. .type = BT_PICASSO4,
  295. .regoffset = 0x00600000,
  296. .ramsize = 4 * MB_,
  297. .ramoffset = 0x01000000,
  298. };
  299. static const struct zorrocl zcl_picasso4_z2 __devinitconst = {
  300. .type = BT_PICASSO4,
  301. .regoffset = 0x10000,
  302. .ramid = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z2_RAM1,
  303. .ramid2 = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z2_RAM2,
  304. };
  305. static const struct zorro_device_id cirrusfb_zorro_table[] __devinitconst = {
  306. {
  307. .id = ZORRO_PROD_HELFRICH_SD64_REG,
  308. .driver_data = (unsigned long)&zcl_sd64,
  309. }, {
  310. .id = ZORRO_PROD_HELFRICH_PICCOLO_REG,
  311. .driver_data = (unsigned long)&zcl_piccolo,
  312. }, {
  313. .id = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_REG,
  314. .driver_data = (unsigned long)&zcl_picasso,
  315. }, {
  316. .id = ZORRO_PROD_GVP_EGS_28_24_SPECTRUM_REG,
  317. .driver_data = (unsigned long)&zcl_spectrum,
  318. }, {
  319. .id = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z3,
  320. .driver_data = (unsigned long)&zcl_picasso4_z3,
  321. }, {
  322. .id = ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z2_REG,
  323. .driver_data = (unsigned long)&zcl_picasso4_z2,
  324. },
  325. { 0 }
  326. };
  327. MODULE_DEVICE_TABLE(zorro, cirrusfb_zorro_table);
  328. #endif /* CONFIG_ZORRO */
  329. #ifdef CIRRUSFB_DEBUG
  330. enum cirrusfb_dbg_reg_class {
  331. CRT,
  332. SEQ
  333. };
  334. #endif /* CIRRUSFB_DEBUG */
  335. /* info about board */
  336. struct cirrusfb_info {
  337. u8 __iomem *regbase;
  338. u8 __iomem *laguna_mmio;
  339. enum cirrus_board btype;
  340. unsigned char SFR; /* Shadow of special function register */
  341. int multiplexing;
  342. int doubleVCLK;
  343. int blank_mode;
  344. u32 pseudo_palette[16];
  345. void (*unmap)(struct fb_info *info);
  346. };
  347. static int noaccel __devinitdata;
  348. static char *mode_option __devinitdata = "640x480@60";
  349. /****************************************************************************/
  350. /**** BEGIN PROTOTYPES ******************************************************/
  351. /*--- Interface used by the world ------------------------------------------*/
  352. static int cirrusfb_pan_display(struct fb_var_screeninfo *var,
  353. struct fb_info *info);
  354. /*--- Internal routines ----------------------------------------------------*/
  355. static void init_vgachip(struct fb_info *info);
  356. static void switch_monitor(struct cirrusfb_info *cinfo, int on);
  357. static void WGen(const struct cirrusfb_info *cinfo,
  358. int regnum, unsigned char val);
  359. static unsigned char RGen(const struct cirrusfb_info *cinfo, int regnum);
  360. static void AttrOn(const struct cirrusfb_info *cinfo);
  361. static void WHDR(const struct cirrusfb_info *cinfo, unsigned char val);
  362. static void WSFR(struct cirrusfb_info *cinfo, unsigned char val);
  363. static void WSFR2(struct cirrusfb_info *cinfo, unsigned char val);
  364. static void WClut(struct cirrusfb_info *cinfo, unsigned char regnum,
  365. unsigned char red, unsigned char green, unsigned char blue);
  366. #if 0
  367. static void RClut(struct cirrusfb_info *cinfo, unsigned char regnum,
  368. unsigned char *red, unsigned char *green,
  369. unsigned char *blue);
  370. #endif
  371. static void cirrusfb_WaitBLT(u8 __iomem *regbase);
  372. static void cirrusfb_BitBLT(u8 __iomem *regbase, int bits_per_pixel,
  373. u_short curx, u_short cury,
  374. u_short destx, u_short desty,
  375. u_short width, u_short height,
  376. u_short line_length);
  377. static void cirrusfb_RectFill(u8 __iomem *regbase, int bits_per_pixel,
  378. u_short x, u_short y,
  379. u_short width, u_short height,
  380. u32 fg_color, u32 bg_color,
  381. u_short line_length, u_char blitmode);
  382. static void bestclock(long freq, int *nom, int *den, int *div);
  383. #ifdef CIRRUSFB_DEBUG
  384. static void cirrusfb_dbg_reg_dump(struct fb_info *info, caddr_t regbase);
  385. static void cirrusfb_dbg_print_regs(struct fb_info *info,
  386. caddr_t regbase,
  387. enum cirrusfb_dbg_reg_class reg_class, ...);
  388. #endif /* CIRRUSFB_DEBUG */
  389. /*** END PROTOTYPES ********************************************************/
  390. /*****************************************************************************/
  391. /*** BEGIN Interface Used by the World ***************************************/
  392. static inline int is_laguna(const struct cirrusfb_info *cinfo)
  393. {
  394. return cinfo->btype == BT_LAGUNA || cinfo->btype == BT_LAGUNAB;
  395. }
  396. static int opencount;
  397. /*--- Open /dev/fbx ---------------------------------------------------------*/
  398. static int cirrusfb_open(struct fb_info *info, int user)
  399. {
  400. if (opencount++ == 0)
  401. switch_monitor(info->par, 1);
  402. return 0;
  403. }
  404. /*--- Close /dev/fbx --------------------------------------------------------*/
  405. static int cirrusfb_release(struct fb_info *info, int user)
  406. {
  407. if (--opencount == 0)
  408. switch_monitor(info->par, 0);
  409. return 0;
  410. }
  411. /**** END Interface used by the World *************************************/
  412. /****************************************************************************/
  413. /**** BEGIN Hardware specific Routines **************************************/
  414. /* Check if the MCLK is not a better clock source */
  415. static int cirrusfb_check_mclk(struct fb_info *info, long freq)
  416. {
  417. struct cirrusfb_info *cinfo = info->par;
  418. long mclk = vga_rseq(cinfo->regbase, CL_SEQR1F) & 0x3f;
  419. /* Read MCLK value */
  420. mclk = (14318 * mclk) >> 3;
  421. dev_dbg(info->device, "Read MCLK of %ld kHz\n", mclk);
  422. /* Determine if we should use MCLK instead of VCLK, and if so, what we
  423. * should divide it by to get VCLK
  424. */
  425. if (abs(freq - mclk) < 250) {
  426. dev_dbg(info->device, "Using VCLK = MCLK\n");
  427. return 1;
  428. } else if (abs(freq - (mclk / 2)) < 250) {
  429. dev_dbg(info->device, "Using VCLK = MCLK/2\n");
  430. return 2;
  431. }
  432. return 0;
  433. }
  434. static int cirrusfb_check_pixclock(const struct fb_var_screeninfo *var,
  435. struct fb_info *info)
  436. {
  437. long freq;
  438. long maxclock;
  439. struct cirrusfb_info *cinfo = info->par;
  440. unsigned maxclockidx = var->bits_per_pixel >> 3;
  441. /* convert from ps to kHz */
  442. freq = PICOS2KHZ(var->pixclock);
  443. dev_dbg(info->device, "desired pixclock: %ld kHz\n", freq);
  444. maxclock = cirrusfb_board_info[cinfo->btype].maxclock[maxclockidx];
  445. cinfo->multiplexing = 0;
  446. /* If the frequency is greater than we can support, we might be able
  447. * to use multiplexing for the video mode */
  448. if (freq > maxclock) {
  449. dev_err(info->device,
  450. "Frequency greater than maxclock (%ld kHz)\n",
  451. maxclock);
  452. return -EINVAL;
  453. }
  454. /*
  455. * Additional constraint: 8bpp uses DAC clock doubling to allow maximum
  456. * pixel clock
  457. */
  458. if (var->bits_per_pixel == 8) {
  459. switch (cinfo->btype) {
  460. case BT_ALPINE:
  461. case BT_SD64:
  462. case BT_PICASSO4:
  463. if (freq > 85500)
  464. cinfo->multiplexing = 1;
  465. break;
  466. case BT_GD5480:
  467. if (freq > 135100)
  468. cinfo->multiplexing = 1;
  469. break;
  470. default:
  471. break;
  472. }
  473. }
  474. /* If we have a 1MB 5434, we need to put ourselves in a mode where
  475. * the VCLK is double the pixel clock. */
  476. cinfo->doubleVCLK = 0;
  477. if (cinfo->btype == BT_SD64 && info->fix.smem_len <= MB_ &&
  478. var->bits_per_pixel == 16) {
  479. cinfo->doubleVCLK = 1;
  480. }
  481. return 0;
  482. }
  483. static int cirrusfb_check_var(struct fb_var_screeninfo *var,
  484. struct fb_info *info)
  485. {
  486. int yres;
  487. /* memory size in pixels */
  488. unsigned pixels = info->screen_size * 8 / var->bits_per_pixel;
  489. struct cirrusfb_info *cinfo = info->par;
  490. switch (var->bits_per_pixel) {
  491. case 1:
  492. var->red.offset = 0;
  493. var->red.length = 1;
  494. var->green = var->red;
  495. var->blue = var->red;
  496. break;
  497. case 8:
  498. var->red.offset = 0;
  499. var->red.length = 8;
  500. var->green = var->red;
  501. var->blue = var->red;
  502. break;
  503. case 16:
  504. if (isPReP) {
  505. var->red.offset = 2;
  506. var->green.offset = -3;
  507. var->blue.offset = 8;
  508. } else {
  509. var->red.offset = 11;
  510. var->green.offset = 5;
  511. var->blue.offset = 0;
  512. }
  513. var->red.length = 5;
  514. var->green.length = 6;
  515. var->blue.length = 5;
  516. break;
  517. case 24:
  518. if (isPReP) {
  519. var->red.offset = 0;
  520. var->green.offset = 8;
  521. var->blue.offset = 16;
  522. } else {
  523. var->red.offset = 16;
  524. var->green.offset = 8;
  525. var->blue.offset = 0;
  526. }
  527. var->red.length = 8;
  528. var->green.length = 8;
  529. var->blue.length = 8;
  530. break;
  531. default:
  532. dev_dbg(info->device,
  533. "Unsupported bpp size: %d\n", var->bits_per_pixel);
  534. return -EINVAL;
  535. }
  536. if (var->xres_virtual < var->xres)
  537. var->xres_virtual = var->xres;
  538. /* use highest possible virtual resolution */
  539. if (var->yres_virtual == -1) {
  540. var->yres_virtual = pixels / var->xres_virtual;
  541. dev_info(info->device,
  542. "virtual resolution set to maximum of %dx%d\n",
  543. var->xres_virtual, var->yres_virtual);
  544. }
  545. if (var->yres_virtual < var->yres)
  546. var->yres_virtual = var->yres;
  547. if (var->xres_virtual * var->yres_virtual > pixels) {
  548. dev_err(info->device, "mode %dx%dx%d rejected... "
  549. "virtual resolution too high to fit into video memory!\n",
  550. var->xres_virtual, var->yres_virtual,
  551. var->bits_per_pixel);
  552. return -EINVAL;
  553. }
  554. if (var->xoffset < 0)
  555. var->xoffset = 0;
  556. if (var->yoffset < 0)
  557. var->yoffset = 0;
  558. /* truncate xoffset and yoffset to maximum if too high */
  559. if (var->xoffset > var->xres_virtual - var->xres)
  560. var->xoffset = var->xres_virtual - var->xres - 1;
  561. if (var->yoffset > var->yres_virtual - var->yres)
  562. var->yoffset = var->yres_virtual - var->yres - 1;
  563. var->red.msb_right =
  564. var->green.msb_right =
  565. var->blue.msb_right =
  566. var->transp.offset =
  567. var->transp.length =
  568. var->transp.msb_right = 0;
  569. yres = var->yres;
  570. if (var->vmode & FB_VMODE_DOUBLE)
  571. yres *= 2;
  572. else if (var->vmode & FB_VMODE_INTERLACED)
  573. yres = (yres + 1) / 2;
  574. if (yres >= 1280) {
  575. dev_err(info->device, "ERROR: VerticalTotal >= 1280; "
  576. "special treatment required! (TODO)\n");
  577. return -EINVAL;
  578. }
  579. if (cirrusfb_check_pixclock(var, info))
  580. return -EINVAL;
  581. if (!is_laguna(cinfo))
  582. var->accel_flags = FB_ACCELF_TEXT;
  583. return 0;
  584. }
  585. static void cirrusfb_set_mclk_as_source(const struct fb_info *info, int div)
  586. {
  587. struct cirrusfb_info *cinfo = info->par;
  588. unsigned char old1f, old1e;
  589. assert(cinfo != NULL);
  590. old1f = vga_rseq(cinfo->regbase, CL_SEQR1F) & ~0x40;
  591. if (div) {
  592. dev_dbg(info->device, "Set %s as pixclock source.\n",
  593. (div == 2) ? "MCLK/2" : "MCLK");
  594. old1f |= 0x40;
  595. old1e = vga_rseq(cinfo->regbase, CL_SEQR1E) & ~0x1;
  596. if (div == 2)
  597. old1e |= 1;
  598. vga_wseq(cinfo->regbase, CL_SEQR1E, old1e);
  599. }
  600. vga_wseq(cinfo->regbase, CL_SEQR1F, old1f);
  601. }
  602. /*************************************************************************
  603. cirrusfb_set_par_foo()
  604. actually writes the values for a new video mode into the hardware,
  605. **************************************************************************/
  606. static int cirrusfb_set_par_foo(struct fb_info *info)
  607. {
  608. struct cirrusfb_info *cinfo = info->par;
  609. struct fb_var_screeninfo *var = &info->var;
  610. u8 __iomem *regbase = cinfo->regbase;
  611. unsigned char tmp;
  612. int pitch;
  613. const struct cirrusfb_board_info_rec *bi;
  614. int hdispend, hsyncstart, hsyncend, htotal;
  615. int yres, vdispend, vsyncstart, vsyncend, vtotal;
  616. long freq;
  617. int nom, den, div;
  618. unsigned int control = 0, format = 0, threshold = 0;
  619. dev_dbg(info->device, "Requested mode: %dx%dx%d\n",
  620. var->xres, var->yres, var->bits_per_pixel);
  621. switch (var->bits_per_pixel) {
  622. case 1:
  623. info->fix.line_length = var->xres_virtual / 8;
  624. info->fix.visual = FB_VISUAL_MONO10;
  625. break;
  626. case 8:
  627. info->fix.line_length = var->xres_virtual;
  628. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  629. break;
  630. case 16:
  631. case 24:
  632. info->fix.line_length = var->xres_virtual *
  633. var->bits_per_pixel >> 3;
  634. info->fix.visual = FB_VISUAL_TRUECOLOR;
  635. break;
  636. }
  637. info->fix.type = FB_TYPE_PACKED_PIXELS;
  638. init_vgachip(info);
  639. bi = &cirrusfb_board_info[cinfo->btype];
  640. hsyncstart = var->xres + var->right_margin;
  641. hsyncend = hsyncstart + var->hsync_len;
  642. htotal = (hsyncend + var->left_margin) / 8;
  643. hdispend = var->xres / 8;
  644. hsyncstart = hsyncstart / 8;
  645. hsyncend = hsyncend / 8;
  646. vdispend = var->yres;
  647. vsyncstart = vdispend + var->lower_margin;
  648. vsyncend = vsyncstart + var->vsync_len;
  649. vtotal = vsyncend + var->upper_margin;
  650. if (var->vmode & FB_VMODE_DOUBLE) {
  651. vdispend *= 2;
  652. vsyncstart *= 2;
  653. vsyncend *= 2;
  654. vtotal *= 2;
  655. } else if (var->vmode & FB_VMODE_INTERLACED) {
  656. vdispend = (vdispend + 1) / 2;
  657. vsyncstart = (vsyncstart + 1) / 2;
  658. vsyncend = (vsyncend + 1) / 2;
  659. vtotal = (vtotal + 1) / 2;
  660. }
  661. yres = vdispend;
  662. if (yres >= 1024) {
  663. vtotal /= 2;
  664. vsyncstart /= 2;
  665. vsyncend /= 2;
  666. vdispend /= 2;
  667. }
  668. vdispend -= 1;
  669. vsyncstart -= 1;
  670. vsyncend -= 1;
  671. vtotal -= 2;
  672. if (cinfo->multiplexing) {
  673. htotal /= 2;
  674. hsyncstart /= 2;
  675. hsyncend /= 2;
  676. hdispend /= 2;
  677. }
  678. htotal -= 5;
  679. hdispend -= 1;
  680. hsyncstart += 1;
  681. hsyncend += 1;
  682. /* unlock register VGA_CRTC_H_TOTAL..CRT7 */
  683. vga_wcrt(regbase, VGA_CRTC_V_SYNC_END, 0x20); /* previously: 0x00) */
  684. /* if debugging is enabled, all parameters get output before writing */
  685. dev_dbg(info->device, "CRT0: %d\n", htotal);
  686. vga_wcrt(regbase, VGA_CRTC_H_TOTAL, htotal);
  687. dev_dbg(info->device, "CRT1: %d\n", hdispend);
  688. vga_wcrt(regbase, VGA_CRTC_H_DISP, hdispend);
  689. dev_dbg(info->device, "CRT2: %d\n", var->xres / 8);
  690. vga_wcrt(regbase, VGA_CRTC_H_BLANK_START, var->xres / 8);
  691. /* + 128: Compatible read */
  692. dev_dbg(info->device, "CRT3: 128+%d\n", (htotal + 5) % 32);
  693. vga_wcrt(regbase, VGA_CRTC_H_BLANK_END,
  694. 128 + ((htotal + 5) % 32));
  695. dev_dbg(info->device, "CRT4: %d\n", hsyncstart);
  696. vga_wcrt(regbase, VGA_CRTC_H_SYNC_START, hsyncstart);
  697. tmp = hsyncend % 32;
  698. if ((htotal + 5) & 32)
  699. tmp += 128;
  700. dev_dbg(info->device, "CRT5: %d\n", tmp);
  701. vga_wcrt(regbase, VGA_CRTC_H_SYNC_END, tmp);
  702. dev_dbg(info->device, "CRT6: %d\n", vtotal & 0xff);
  703. vga_wcrt(regbase, VGA_CRTC_V_TOTAL, vtotal & 0xff);
  704. tmp = 16; /* LineCompare bit #9 */
  705. if (vtotal & 256)
  706. tmp |= 1;
  707. if (vdispend & 256)
  708. tmp |= 2;
  709. if (vsyncstart & 256)
  710. tmp |= 4;
  711. if ((vdispend + 1) & 256)
  712. tmp |= 8;
  713. if (vtotal & 512)
  714. tmp |= 32;
  715. if (vdispend & 512)
  716. tmp |= 64;
  717. if (vsyncstart & 512)
  718. tmp |= 128;
  719. dev_dbg(info->device, "CRT7: %d\n", tmp);
  720. vga_wcrt(regbase, VGA_CRTC_OVERFLOW, tmp);
  721. tmp = 0x40; /* LineCompare bit #8 */
  722. if ((vdispend + 1) & 512)
  723. tmp |= 0x20;
  724. if (var->vmode & FB_VMODE_DOUBLE)
  725. tmp |= 0x80;
  726. dev_dbg(info->device, "CRT9: %d\n", tmp);
  727. vga_wcrt(regbase, VGA_CRTC_MAX_SCAN, tmp);
  728. dev_dbg(info->device, "CRT10: %d\n", vsyncstart & 0xff);
  729. vga_wcrt(regbase, VGA_CRTC_V_SYNC_START, vsyncstart & 0xff);
  730. dev_dbg(info->device, "CRT11: 64+32+%d\n", vsyncend % 16);
  731. vga_wcrt(regbase, VGA_CRTC_V_SYNC_END, vsyncend % 16 + 64 + 32);
  732. dev_dbg(info->device, "CRT12: %d\n", vdispend & 0xff);
  733. vga_wcrt(regbase, VGA_CRTC_V_DISP_END, vdispend & 0xff);
  734. dev_dbg(info->device, "CRT15: %d\n", (vdispend + 1) & 0xff);
  735. vga_wcrt(regbase, VGA_CRTC_V_BLANK_START, (vdispend + 1) & 0xff);
  736. dev_dbg(info->device, "CRT16: %d\n", vtotal & 0xff);
  737. vga_wcrt(regbase, VGA_CRTC_V_BLANK_END, vtotal & 0xff);
  738. dev_dbg(info->device, "CRT18: 0xff\n");
  739. vga_wcrt(regbase, VGA_CRTC_LINE_COMPARE, 0xff);
  740. tmp = 0;
  741. if (var->vmode & FB_VMODE_INTERLACED)
  742. tmp |= 1;
  743. if ((htotal + 5) & 64)
  744. tmp |= 16;
  745. if ((htotal + 5) & 128)
  746. tmp |= 32;
  747. if (vtotal & 256)
  748. tmp |= 64;
  749. if (vtotal & 512)
  750. tmp |= 128;
  751. dev_dbg(info->device, "CRT1a: %d\n", tmp);
  752. vga_wcrt(regbase, CL_CRT1A, tmp);
  753. freq = PICOS2KHZ(var->pixclock);
  754. if (var->bits_per_pixel == 24)
  755. if (cinfo->btype == BT_ALPINE || cinfo->btype == BT_SD64)
  756. freq *= 3;
  757. if (cinfo->multiplexing)
  758. freq /= 2;
  759. if (cinfo->doubleVCLK)
  760. freq *= 2;
  761. bestclock(freq, &nom, &den, &div);
  762. dev_dbg(info->device, "VCLK freq: %ld kHz nom: %d den: %d div: %d\n",
  763. freq, nom, den, div);
  764. /* set VCLK0 */
  765. /* hardware RefClock: 14.31818 MHz */
  766. /* formula: VClk = (OSC * N) / (D * (1+P)) */
  767. /* Example: VClk = (14.31818 * 91) / (23 * (1+1)) = 28.325 MHz */
  768. if (cinfo->btype == BT_ALPINE || cinfo->btype == BT_PICASSO4 ||
  769. cinfo->btype == BT_SD64) {
  770. /* if freq is close to mclk or mclk/2 select mclk
  771. * as clock source
  772. */
  773. int divMCLK = cirrusfb_check_mclk(info, freq);
  774. if (divMCLK)
  775. nom = 0;
  776. cirrusfb_set_mclk_as_source(info, divMCLK);
  777. }
  778. if (is_laguna(cinfo)) {
  779. long pcifc = fb_readl(cinfo->laguna_mmio + 0x3fc);
  780. unsigned char tile = fb_readb(cinfo->laguna_mmio + 0x407);
  781. unsigned short tile_control;
  782. if (cinfo->btype == BT_LAGUNAB) {
  783. tile_control = fb_readw(cinfo->laguna_mmio + 0x2c4);
  784. tile_control &= ~0x80;
  785. fb_writew(tile_control, cinfo->laguna_mmio + 0x2c4);
  786. }
  787. fb_writel(pcifc | 0x10000000l, cinfo->laguna_mmio + 0x3fc);
  788. fb_writeb(tile & 0x3f, cinfo->laguna_mmio + 0x407);
  789. control = fb_readw(cinfo->laguna_mmio + 0x402);
  790. threshold = fb_readw(cinfo->laguna_mmio + 0xea);
  791. control &= ~0x6800;
  792. format = 0;
  793. threshold &= 0xffc0 & 0x3fbf;
  794. }
  795. if (nom) {
  796. tmp = den << 1;
  797. if (div != 0)
  798. tmp |= 1;
  799. /* 6 bit denom; ONLY 5434!!! (bugged me 10 days) */
  800. if ((cinfo->btype == BT_SD64) ||
  801. (cinfo->btype == BT_ALPINE) ||
  802. (cinfo->btype == BT_GD5480))
  803. tmp |= 0x80;
  804. /* Laguna chipset has reversed clock registers */
  805. if (is_laguna(cinfo)) {
  806. vga_wseq(regbase, CL_SEQRE, tmp);
  807. vga_wseq(regbase, CL_SEQR1E, nom);
  808. } else {
  809. vga_wseq(regbase, CL_SEQRE, nom);
  810. vga_wseq(regbase, CL_SEQR1E, tmp);
  811. }
  812. }
  813. if (yres >= 1024)
  814. /* 1280x1024 */
  815. vga_wcrt(regbase, VGA_CRTC_MODE, 0xc7);
  816. else
  817. /* mode control: VGA_CRTC_START_HI enable, ROTATE(?), 16bit
  818. * address wrap, no compat. */
  819. vga_wcrt(regbase, VGA_CRTC_MODE, 0xc3);
  820. /* don't know if it would hurt to also program this if no interlaced */
  821. /* mode is used, but I feel better this way.. :-) */
  822. if (var->vmode & FB_VMODE_INTERLACED)
  823. vga_wcrt(regbase, VGA_CRTC_REGS, htotal / 2);
  824. else
  825. vga_wcrt(regbase, VGA_CRTC_REGS, 0x00); /* interlace control */
  826. /* adjust horizontal/vertical sync type (low/high), use VCLK3 */
  827. /* enable display memory & CRTC I/O address for color mode */
  828. tmp = 0x03 | 0xc;
  829. if (var->sync & FB_SYNC_HOR_HIGH_ACT)
  830. tmp |= 0x40;
  831. if (var->sync & FB_SYNC_VERT_HIGH_ACT)
  832. tmp |= 0x80;
  833. WGen(cinfo, VGA_MIS_W, tmp);
  834. /* text cursor on and start line */
  835. vga_wcrt(regbase, VGA_CRTC_CURSOR_START, 0);
  836. /* text cursor end line */
  837. vga_wcrt(regbase, VGA_CRTC_CURSOR_END, 31);
  838. /******************************************************
  839. *
  840. * 1 bpp
  841. *
  842. */
  843. /* programming for different color depths */
  844. if (var->bits_per_pixel == 1) {
  845. dev_dbg(info->device, "preparing for 1 bit deep display\n");
  846. vga_wgfx(regbase, VGA_GFX_MODE, 0); /* mode register */
  847. /* SR07 */
  848. switch (cinfo->btype) {
  849. case BT_SD64:
  850. case BT_PICCOLO:
  851. case BT_PICASSO:
  852. case BT_SPECTRUM:
  853. case BT_PICASSO4:
  854. case BT_ALPINE:
  855. case BT_GD5480:
  856. vga_wseq(regbase, CL_SEQR7,
  857. cinfo->multiplexing ?
  858. bi->sr07_1bpp_mux : bi->sr07_1bpp);
  859. break;
  860. case BT_LAGUNA:
  861. case BT_LAGUNAB:
  862. vga_wseq(regbase, CL_SEQR7,
  863. vga_rseq(regbase, CL_SEQR7) & ~0x01);
  864. break;
  865. default:
  866. dev_warn(info->device, "unknown Board\n");
  867. break;
  868. }
  869. /* Extended Sequencer Mode */
  870. switch (cinfo->btype) {
  871. case BT_PICCOLO:
  872. case BT_SPECTRUM:
  873. /* evtl d0 bei 1 bit? avoid FIFO underruns..? */
  874. vga_wseq(regbase, CL_SEQRF, 0xb0);
  875. break;
  876. case BT_PICASSO:
  877. /* ## vorher d0 avoid FIFO underruns..? */
  878. vga_wseq(regbase, CL_SEQRF, 0xd0);
  879. break;
  880. case BT_SD64:
  881. case BT_PICASSO4:
  882. case BT_ALPINE:
  883. case BT_GD5480:
  884. case BT_LAGUNA:
  885. case BT_LAGUNAB:
  886. /* do nothing */
  887. break;
  888. default:
  889. dev_warn(info->device, "unknown Board\n");
  890. break;
  891. }
  892. /* pixel mask: pass-through for first plane */
  893. WGen(cinfo, VGA_PEL_MSK, 0x01);
  894. if (cinfo->multiplexing)
  895. /* hidden dac reg: 1280x1024 */
  896. WHDR(cinfo, 0x4a);
  897. else
  898. /* hidden dac: nothing */
  899. WHDR(cinfo, 0);
  900. /* memory mode: odd/even, ext. memory */
  901. vga_wseq(regbase, VGA_SEQ_MEMORY_MODE, 0x06);
  902. /* plane mask: only write to first plane */
  903. vga_wseq(regbase, VGA_SEQ_PLANE_WRITE, 0x01);
  904. }
  905. /******************************************************
  906. *
  907. * 8 bpp
  908. *
  909. */
  910. else if (var->bits_per_pixel == 8) {
  911. dev_dbg(info->device, "preparing for 8 bit deep display\n");
  912. switch (cinfo->btype) {
  913. case BT_SD64:
  914. case BT_PICCOLO:
  915. case BT_PICASSO:
  916. case BT_SPECTRUM:
  917. case BT_PICASSO4:
  918. case BT_ALPINE:
  919. case BT_GD5480:
  920. vga_wseq(regbase, CL_SEQR7,
  921. cinfo->multiplexing ?
  922. bi->sr07_8bpp_mux : bi->sr07_8bpp);
  923. break;
  924. case BT_LAGUNA:
  925. case BT_LAGUNAB:
  926. vga_wseq(regbase, CL_SEQR7,
  927. vga_rseq(regbase, CL_SEQR7) | 0x01);
  928. threshold |= 0x10;
  929. break;
  930. default:
  931. dev_warn(info->device, "unknown Board\n");
  932. break;
  933. }
  934. switch (cinfo->btype) {
  935. case BT_PICCOLO:
  936. case BT_PICASSO:
  937. case BT_SPECTRUM:
  938. /* Fast Page-Mode writes */
  939. vga_wseq(regbase, CL_SEQRF, 0xb0);
  940. break;
  941. case BT_PICASSO4:
  942. #ifdef CONFIG_ZORRO
  943. /* ### INCOMPLETE!! */
  944. vga_wseq(regbase, CL_SEQRF, 0xb8);
  945. #endif
  946. case BT_ALPINE:
  947. case BT_SD64:
  948. case BT_GD5480:
  949. case BT_LAGUNA:
  950. case BT_LAGUNAB:
  951. /* do nothing */
  952. break;
  953. default:
  954. dev_warn(info->device, "unknown board\n");
  955. break;
  956. }
  957. /* mode register: 256 color mode */
  958. vga_wgfx(regbase, VGA_GFX_MODE, 64);
  959. if (cinfo->multiplexing)
  960. /* hidden dac reg: 1280x1024 */
  961. WHDR(cinfo, 0x4a);
  962. else
  963. /* hidden dac: nothing */
  964. WHDR(cinfo, 0);
  965. }
  966. /******************************************************
  967. *
  968. * 16 bpp
  969. *
  970. */
  971. else if (var->bits_per_pixel == 16) {
  972. dev_dbg(info->device, "preparing for 16 bit deep display\n");
  973. switch (cinfo->btype) {
  974. case BT_PICCOLO:
  975. case BT_SPECTRUM:
  976. vga_wseq(regbase, CL_SEQR7, 0x87);
  977. /* Fast Page-Mode writes */
  978. vga_wseq(regbase, CL_SEQRF, 0xb0);
  979. break;
  980. case BT_PICASSO:
  981. vga_wseq(regbase, CL_SEQR7, 0x27);
  982. /* Fast Page-Mode writes */
  983. vga_wseq(regbase, CL_SEQRF, 0xb0);
  984. break;
  985. case BT_SD64:
  986. case BT_PICASSO4:
  987. case BT_ALPINE:
  988. /* Extended Sequencer Mode: 256c col. mode */
  989. vga_wseq(regbase, CL_SEQR7,
  990. cinfo->doubleVCLK ? 0xa3 : 0xa7);
  991. break;
  992. case BT_GD5480:
  993. vga_wseq(regbase, CL_SEQR7, 0x17);
  994. /* We already set SRF and SR1F */
  995. break;
  996. case BT_LAGUNA:
  997. case BT_LAGUNAB:
  998. vga_wseq(regbase, CL_SEQR7,
  999. vga_rseq(regbase, CL_SEQR7) & ~0x01);
  1000. control |= 0x2000;
  1001. format |= 0x1400;
  1002. threshold |= 0x10;
  1003. break;
  1004. default:
  1005. dev_warn(info->device, "unknown Board\n");
  1006. break;
  1007. }
  1008. /* mode register: 256 color mode */
  1009. vga_wgfx(regbase, VGA_GFX_MODE, 64);
  1010. #ifdef CONFIG_PCI
  1011. WHDR(cinfo, cinfo->doubleVCLK ? 0xe1 : 0xc1);
  1012. #elif defined(CONFIG_ZORRO)
  1013. /* FIXME: CONFIG_PCI and CONFIG_ZORRO may be defined both */
  1014. WHDR(cinfo, 0xa0); /* hidden dac reg: nothing special */
  1015. #endif
  1016. }
  1017. /******************************************************
  1018. *
  1019. * 24 bpp
  1020. *
  1021. */
  1022. else if (var->bits_per_pixel == 24) {
  1023. dev_dbg(info->device, "preparing for 24 bit deep display\n");
  1024. switch (cinfo->btype) {
  1025. case BT_PICCOLO:
  1026. case BT_SPECTRUM:
  1027. vga_wseq(regbase, CL_SEQR7, 0x85);
  1028. /* Fast Page-Mode writes */
  1029. vga_wseq(regbase, CL_SEQRF, 0xb0);
  1030. break;
  1031. case BT_PICASSO:
  1032. vga_wseq(regbase, CL_SEQR7, 0x25);
  1033. /* Fast Page-Mode writes */
  1034. vga_wseq(regbase, CL_SEQRF, 0xb0);
  1035. break;
  1036. case BT_SD64:
  1037. case BT_PICASSO4:
  1038. case BT_ALPINE:
  1039. /* Extended Sequencer Mode: 256c col. mode */
  1040. vga_wseq(regbase, CL_SEQR7, 0xa5);
  1041. break;
  1042. case BT_GD5480:
  1043. vga_wseq(regbase, CL_SEQR7, 0x15);
  1044. /* We already set SRF and SR1F */
  1045. break;
  1046. case BT_LAGUNA:
  1047. case BT_LAGUNAB:
  1048. vga_wseq(regbase, CL_SEQR7,
  1049. vga_rseq(regbase, CL_SEQR7) & ~0x01);
  1050. control |= 0x4000;
  1051. format |= 0x2400;
  1052. threshold |= 0x20;
  1053. break;
  1054. default:
  1055. dev_warn(info->device, "unknown Board\n");
  1056. break;
  1057. }
  1058. /* mode register: 256 color mode */
  1059. vga_wgfx(regbase, VGA_GFX_MODE, 64);
  1060. /* hidden dac reg: 8-8-8 mode (24 or 32) */
  1061. WHDR(cinfo, 0xc5);
  1062. }
  1063. /******************************************************
  1064. *
  1065. * unknown/unsupported bpp
  1066. *
  1067. */
  1068. else
  1069. dev_err(info->device,
  1070. "What's this? requested color depth == %d.\n",
  1071. var->bits_per_pixel);
  1072. pitch = info->fix.line_length >> 3;
  1073. vga_wcrt(regbase, VGA_CRTC_OFFSET, pitch & 0xff);
  1074. tmp = 0x22;
  1075. if (pitch & 0x100)
  1076. tmp |= 0x10; /* offset overflow bit */
  1077. /* screen start addr #16-18, fastpagemode cycles */
  1078. vga_wcrt(regbase, CL_CRT1B, tmp);
  1079. /* screen start address bit 19 */
  1080. if (cirrusfb_board_info[cinfo->btype].scrn_start_bit19)
  1081. vga_wcrt(regbase, CL_CRT1D, (pitch >> 9) & 1);
  1082. if (is_laguna(cinfo)) {
  1083. tmp = 0;
  1084. if ((htotal + 5) & 256)
  1085. tmp |= 128;
  1086. if (hdispend & 256)
  1087. tmp |= 64;
  1088. if (hsyncstart & 256)
  1089. tmp |= 48;
  1090. if (vtotal & 1024)
  1091. tmp |= 8;
  1092. if (vdispend & 1024)
  1093. tmp |= 4;
  1094. if (vsyncstart & 1024)
  1095. tmp |= 3;
  1096. vga_wcrt(regbase, CL_CRT1E, tmp);
  1097. dev_dbg(info->device, "CRT1e: %d\n", tmp);
  1098. }
  1099. /* pixel panning */
  1100. vga_wattr(regbase, CL_AR33, 0);
  1101. /* [ EGS: SetOffset(); ] */
  1102. /* From SetOffset(): Turn on VideoEnable bit in Attribute controller */
  1103. AttrOn(cinfo);
  1104. if (is_laguna(cinfo)) {
  1105. /* no tiles */
  1106. fb_writew(control | 0x1000, cinfo->laguna_mmio + 0x402);
  1107. fb_writew(format, cinfo->laguna_mmio + 0xc0);
  1108. fb_writew(threshold, cinfo->laguna_mmio + 0xea);
  1109. }
  1110. /* finally, turn on everything - turn off "FullBandwidth" bit */
  1111. /* also, set "DotClock%2" bit where requested */
  1112. tmp = 0x01;
  1113. /*** FB_VMODE_CLOCK_HALVE in linux/fb.h not defined anymore ?
  1114. if (var->vmode & FB_VMODE_CLOCK_HALVE)
  1115. tmp |= 0x08;
  1116. */
  1117. vga_wseq(regbase, VGA_SEQ_CLOCK_MODE, tmp);
  1118. dev_dbg(info->device, "CL_SEQR1: %d\n", tmp);
  1119. #ifdef CIRRUSFB_DEBUG
  1120. cirrusfb_dbg_reg_dump(info, NULL);
  1121. #endif
  1122. return 0;
  1123. }
  1124. /* for some reason incomprehensible to me, cirrusfb requires that you write
  1125. * the registers twice for the settings to take..grr. -dte */
  1126. static int cirrusfb_set_par(struct fb_info *info)
  1127. {
  1128. cirrusfb_set_par_foo(info);
  1129. return cirrusfb_set_par_foo(info);
  1130. }
  1131. static int cirrusfb_setcolreg(unsigned regno, unsigned red, unsigned green,
  1132. unsigned blue, unsigned transp,
  1133. struct fb_info *info)
  1134. {
  1135. struct cirrusfb_info *cinfo = info->par;
  1136. if (regno > 255)
  1137. return -EINVAL;
  1138. if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
  1139. u32 v;
  1140. red >>= (16 - info->var.red.length);
  1141. green >>= (16 - info->var.green.length);
  1142. blue >>= (16 - info->var.blue.length);
  1143. if (regno >= 16)
  1144. return 1;
  1145. v = (red << info->var.red.offset) |
  1146. (green << info->var.green.offset) |
  1147. (blue << info->var.blue.offset);
  1148. cinfo->pseudo_palette[regno] = v;
  1149. return 0;
  1150. }
  1151. if (info->var.bits_per_pixel == 8)
  1152. WClut(cinfo, regno, red >> 10, green >> 10, blue >> 10);
  1153. return 0;
  1154. }
  1155. /*************************************************************************
  1156. cirrusfb_pan_display()
  1157. performs display panning - provided hardware permits this
  1158. **************************************************************************/
  1159. static int cirrusfb_pan_display(struct fb_var_screeninfo *var,
  1160. struct fb_info *info)
  1161. {
  1162. int xoffset;
  1163. unsigned long base;
  1164. unsigned char tmp, xpix;
  1165. struct cirrusfb_info *cinfo = info->par;
  1166. /* no range checks for xoffset and yoffset, */
  1167. /* as fb_pan_display has already done this */
  1168. if (var->vmode & FB_VMODE_YWRAP)
  1169. return -EINVAL;
  1170. xoffset = var->xoffset * info->var.bits_per_pixel / 8;
  1171. base = var->yoffset * info->fix.line_length + xoffset;
  1172. if (info->var.bits_per_pixel == 1) {
  1173. /* base is already correct */
  1174. xpix = (unsigned char) (var->xoffset % 8);
  1175. } else {
  1176. base /= 4;
  1177. xpix = (unsigned char) ((xoffset % 4) * 2);
  1178. }
  1179. if (!is_laguna(cinfo))
  1180. cirrusfb_WaitBLT(cinfo->regbase);
  1181. /* lower 8 + 8 bits of screen start address */
  1182. vga_wcrt(cinfo->regbase, VGA_CRTC_START_LO, base & 0xff);
  1183. vga_wcrt(cinfo->regbase, VGA_CRTC_START_HI, (base >> 8) & 0xff);
  1184. /* 0xf2 is %11110010, exclude tmp bits */
  1185. tmp = vga_rcrt(cinfo->regbase, CL_CRT1B) & 0xf2;
  1186. /* construct bits 16, 17 and 18 of screen start address */
  1187. if (base & 0x10000)
  1188. tmp |= 0x01;
  1189. if (base & 0x20000)
  1190. tmp |= 0x04;
  1191. if (base & 0x40000)
  1192. tmp |= 0x08;
  1193. vga_wcrt(cinfo->regbase, CL_CRT1B, tmp);
  1194. /* construct bit 19 of screen start address */
  1195. if (cirrusfb_board_info[cinfo->btype].scrn_start_bit19) {
  1196. tmp = vga_rcrt(cinfo->regbase, CL_CRT1D);
  1197. if (is_laguna(cinfo))
  1198. tmp = (tmp & ~0x18) | ((base >> 16) & 0x18);
  1199. else
  1200. tmp = (tmp & ~0x80) | ((base >> 12) & 0x80);
  1201. vga_wcrt(cinfo->regbase, CL_CRT1D, tmp);
  1202. }
  1203. /* write pixel panning value to AR33; this does not quite work in 8bpp
  1204. *
  1205. * ### Piccolo..? Will this work?
  1206. */
  1207. if (info->var.bits_per_pixel == 1)
  1208. vga_wattr(cinfo->regbase, CL_AR33, xpix);
  1209. return 0;
  1210. }
  1211. static int cirrusfb_blank(int blank_mode, struct fb_info *info)
  1212. {
  1213. /*
  1214. * Blank the screen if blank_mode != 0, else unblank. If blank == NULL
  1215. * then the caller blanks by setting the CLUT (Color Look Up Table)
  1216. * to all black. Return 0 if blanking succeeded, != 0 if un-/blanking
  1217. * failed due to e.g. a video mode which doesn't support it.
  1218. * Implements VESA suspend and powerdown modes on hardware that
  1219. * supports disabling hsync/vsync:
  1220. * blank_mode == 2: suspend vsync
  1221. * blank_mode == 3: suspend hsync
  1222. * blank_mode == 4: powerdown
  1223. */
  1224. unsigned char val;
  1225. struct cirrusfb_info *cinfo = info->par;
  1226. int current_mode = cinfo->blank_mode;
  1227. dev_dbg(info->device, "ENTER, blank mode = %d\n", blank_mode);
  1228. if (info->state != FBINFO_STATE_RUNNING ||
  1229. current_mode == blank_mode) {
  1230. dev_dbg(info->device, "EXIT, returning 0\n");
  1231. return 0;
  1232. }
  1233. /* Undo current */
  1234. if (current_mode == FB_BLANK_NORMAL ||
  1235. current_mode == FB_BLANK_UNBLANK)
  1236. /* clear "FullBandwidth" bit */
  1237. val = 0;
  1238. else
  1239. /* set "FullBandwidth" bit */
  1240. val = 0x20;
  1241. val |= vga_rseq(cinfo->regbase, VGA_SEQ_CLOCK_MODE) & 0xdf;
  1242. vga_wseq(cinfo->regbase, VGA_SEQ_CLOCK_MODE, val);
  1243. switch (blank_mode) {
  1244. case FB_BLANK_UNBLANK:
  1245. case FB_BLANK_NORMAL:
  1246. val = 0x00;
  1247. break;
  1248. case FB_BLANK_VSYNC_SUSPEND:
  1249. val = 0x04;
  1250. break;
  1251. case FB_BLANK_HSYNC_SUSPEND:
  1252. val = 0x02;
  1253. break;
  1254. case FB_BLANK_POWERDOWN:
  1255. val = 0x06;
  1256. break;
  1257. default:
  1258. dev_dbg(info->device, "EXIT, returning 1\n");
  1259. return 1;
  1260. }
  1261. vga_wgfx(cinfo->regbase, CL_GRE, val);
  1262. cinfo->blank_mode = blank_mode;
  1263. dev_dbg(info->device, "EXIT, returning 0\n");
  1264. /* Let fbcon do a soft blank for us */
  1265. return (blank_mode == FB_BLANK_NORMAL) ? 1 : 0;
  1266. }
  1267. /**** END Hardware specific Routines **************************************/
  1268. /****************************************************************************/
  1269. /**** BEGIN Internal Routines ***********************************************/
  1270. static void init_vgachip(struct fb_info *info)
  1271. {
  1272. struct cirrusfb_info *cinfo = info->par;
  1273. const struct cirrusfb_board_info_rec *bi;
  1274. assert(cinfo != NULL);
  1275. bi = &cirrusfb_board_info[cinfo->btype];
  1276. /* reset board globally */
  1277. switch (cinfo->btype) {
  1278. case BT_PICCOLO:
  1279. WSFR(cinfo, 0x01);
  1280. udelay(500);
  1281. WSFR(cinfo, 0x51);
  1282. udelay(500);
  1283. break;
  1284. case BT_PICASSO:
  1285. WSFR2(cinfo, 0xff);
  1286. udelay(500);
  1287. break;
  1288. case BT_SD64:
  1289. case BT_SPECTRUM:
  1290. WSFR(cinfo, 0x1f);
  1291. udelay(500);
  1292. WSFR(cinfo, 0x4f);
  1293. udelay(500);
  1294. break;
  1295. case BT_PICASSO4:
  1296. /* disable flickerfixer */
  1297. vga_wcrt(cinfo->regbase, CL_CRT51, 0x00);
  1298. mdelay(100);
  1299. /* mode */
  1300. vga_wgfx(cinfo->regbase, CL_GR31, 0x00);
  1301. case BT_GD5480: /* fall through */
  1302. /* from Klaus' NetBSD driver: */
  1303. vga_wgfx(cinfo->regbase, CL_GR2F, 0x00);
  1304. case BT_ALPINE: /* fall through */
  1305. /* put blitter into 542x compat */
  1306. vga_wgfx(cinfo->regbase, CL_GR33, 0x00);
  1307. break;
  1308. case BT_LAGUNA:
  1309. case BT_LAGUNAB:
  1310. /* Nothing to do to reset the board. */
  1311. break;
  1312. default:
  1313. dev_err(info->device, "Warning: Unknown board type\n");
  1314. break;
  1315. }
  1316. /* make sure RAM size set by this point */
  1317. assert(info->screen_size > 0);
  1318. /* the P4 is not fully initialized here; I rely on it having been */
  1319. /* inited under AmigaOS already, which seems to work just fine */
  1320. /* (Klaus advised to do it this way) */
  1321. if (cinfo->btype != BT_PICASSO4) {
  1322. WGen(cinfo, CL_VSSM, 0x10); /* EGS: 0x16 */
  1323. WGen(cinfo, CL_POS102, 0x01);
  1324. WGen(cinfo, CL_VSSM, 0x08); /* EGS: 0x0e */
  1325. if (cinfo->btype != BT_SD64)
  1326. WGen(cinfo, CL_VSSM2, 0x01);
  1327. /* reset sequencer logic */
  1328. vga_wseq(cinfo->regbase, VGA_SEQ_RESET, 0x03);
  1329. /* FullBandwidth (video off) and 8/9 dot clock */
  1330. vga_wseq(cinfo->regbase, VGA_SEQ_CLOCK_MODE, 0x21);
  1331. /* "magic cookie" - doesn't make any sense to me.. */
  1332. /* vga_wgfx(cinfo->regbase, CL_GRA, 0xce); */
  1333. /* unlock all extension registers */
  1334. vga_wseq(cinfo->regbase, CL_SEQR6, 0x12);
  1335. switch (cinfo->btype) {
  1336. case BT_GD5480:
  1337. vga_wseq(cinfo->regbase, CL_SEQRF, 0x98);
  1338. break;
  1339. case BT_ALPINE:
  1340. case BT_LAGUNA:
  1341. case BT_LAGUNAB:
  1342. break;
  1343. case BT_SD64:
  1344. #ifdef CONFIG_ZORRO
  1345. vga_wseq(cinfo->regbase, CL_SEQRF, 0xb8);
  1346. #endif
  1347. break;
  1348. default:
  1349. vga_wseq(cinfo->regbase, CL_SEQR16, 0x0f);
  1350. vga_wseq(cinfo->regbase, CL_SEQRF, 0xb0);
  1351. break;
  1352. }
  1353. }
  1354. /* plane mask: nothing */
  1355. vga_wseq(cinfo->regbase, VGA_SEQ_PLANE_WRITE, 0xff);
  1356. /* character map select: doesn't even matter in gx mode */
  1357. vga_wseq(cinfo->regbase, VGA_SEQ_CHARACTER_MAP, 0x00);
  1358. /* memory mode: chain4, ext. memory */
  1359. vga_wseq(cinfo->regbase, VGA_SEQ_MEMORY_MODE, 0x0a);
  1360. /* controller-internal base address of video memory */
  1361. if (bi->init_sr07)
  1362. vga_wseq(cinfo->regbase, CL_SEQR7, bi->sr07);
  1363. /* vga_wseq(cinfo->regbase, CL_SEQR8, 0x00); */
  1364. /* EEPROM control: shouldn't be necessary to write to this at all.. */
  1365. /* graphics cursor X position (incomplete; position gives rem. 3 bits */
  1366. vga_wseq(cinfo->regbase, CL_SEQR10, 0x00);
  1367. /* graphics cursor Y position (..."... ) */
  1368. vga_wseq(cinfo->regbase, CL_SEQR11, 0x00);
  1369. /* graphics cursor attributes */
  1370. vga_wseq(cinfo->regbase, CL_SEQR12, 0x00);
  1371. /* graphics cursor pattern address */
  1372. vga_wseq(cinfo->regbase, CL_SEQR13, 0x00);
  1373. /* writing these on a P4 might give problems.. */
  1374. if (cinfo->btype != BT_PICASSO4) {
  1375. /* configuration readback and ext. color */
  1376. vga_wseq(cinfo->regbase, CL_SEQR17, 0x00);
  1377. /* signature generator */
  1378. vga_wseq(cinfo->regbase, CL_SEQR18, 0x02);
  1379. }
  1380. /* Screen A preset row scan: none */
  1381. vga_wcrt(cinfo->regbase, VGA_CRTC_PRESET_ROW, 0x00);
  1382. /* Text cursor start: disable text cursor */
  1383. vga_wcrt(cinfo->regbase, VGA_CRTC_CURSOR_START, 0x20);
  1384. /* Text cursor end: - */
  1385. vga_wcrt(cinfo->regbase, VGA_CRTC_CURSOR_END, 0x00);
  1386. /* text cursor location high: 0 */
  1387. vga_wcrt(cinfo->regbase, VGA_CRTC_CURSOR_HI, 0x00);
  1388. /* text cursor location low: 0 */
  1389. vga_wcrt(cinfo->regbase, VGA_CRTC_CURSOR_LO, 0x00);
  1390. /* Underline Row scanline: - */
  1391. vga_wcrt(cinfo->regbase, VGA_CRTC_UNDERLINE, 0x00);
  1392. /* ### add 0x40 for text modes with > 30 MHz pixclock */
  1393. /* ext. display controls: ext.adr. wrap */
  1394. vga_wcrt(cinfo->regbase, CL_CRT1B, 0x02);
  1395. /* Set/Reset registes: - */
  1396. vga_wgfx(cinfo->regbase, VGA_GFX_SR_VALUE, 0x00);
  1397. /* Set/Reset enable: - */
  1398. vga_wgfx(cinfo->regbase, VGA_GFX_SR_ENABLE, 0x00);
  1399. /* Color Compare: - */
  1400. vga_wgfx(cinfo->regbase, VGA_GFX_COMPARE_VALUE, 0x00);
  1401. /* Data Rotate: - */
  1402. vga_wgfx(cinfo->regbase, VGA_GFX_DATA_ROTATE, 0x00);
  1403. /* Read Map Select: - */
  1404. vga_wgfx(cinfo->regbase, VGA_GFX_PLANE_READ, 0x00);
  1405. /* Mode: conf. for 16/4/2 color mode, no odd/even, read/write mode 0 */
  1406. vga_wgfx(cinfo->regbase, VGA_GFX_MODE, 0x00);
  1407. /* Miscellaneous: memory map base address, graphics mode */
  1408. vga_wgfx(cinfo->regbase, VGA_GFX_MISC, 0x01);
  1409. /* Color Don't care: involve all planes */
  1410. vga_wgfx(cinfo->regbase, VGA_GFX_COMPARE_MASK, 0x0f);
  1411. /* Bit Mask: no mask at all */
  1412. vga_wgfx(cinfo->regbase, VGA_GFX_BIT_MASK, 0xff);
  1413. if (cinfo->btype == BT_ALPINE || cinfo->btype == BT_SD64 ||
  1414. is_laguna(cinfo))
  1415. /* (5434 can't have bit 3 set for bitblt) */
  1416. vga_wgfx(cinfo->regbase, CL_GRB, 0x20);
  1417. else
  1418. /* Graphics controller mode extensions: finer granularity,
  1419. * 8byte data latches
  1420. */
  1421. vga_wgfx(cinfo->regbase, CL_GRB, 0x28);
  1422. vga_wgfx(cinfo->regbase, CL_GRC, 0xff); /* Color Key compare: - */
  1423. vga_wgfx(cinfo->regbase, CL_GRD, 0x00); /* Color Key compare mask: - */
  1424. vga_wgfx(cinfo->regbase, CL_GRE, 0x00); /* Miscellaneous control: - */
  1425. /* Background color byte 1: - */
  1426. /* vga_wgfx (cinfo->regbase, CL_GR10, 0x00); */
  1427. /* vga_wgfx (cinfo->regbase, CL_GR11, 0x00); */
  1428. /* Attribute Controller palette registers: "identity mapping" */
  1429. vga_wattr(cinfo->regbase, VGA_ATC_PALETTE0, 0x00);
  1430. vga_wattr(cinfo->regbase, VGA_ATC_PALETTE1, 0x01);
  1431. vga_wattr(cinfo->regbase, VGA_ATC_PALETTE2, 0x02);
  1432. vga_wattr(cinfo->regbase, VGA_ATC_PALETTE3, 0x03);
  1433. vga_wattr(cinfo->regbase, VGA_ATC_PALETTE4, 0x04);
  1434. vga_wattr(cinfo->regbase, VGA_ATC_PALETTE5, 0x05);
  1435. vga_wattr(cinfo->regbase, VGA_ATC_PALETTE6, 0x06);
  1436. vga_wattr(cinfo->regbase, VGA_ATC_PALETTE7, 0x07);
  1437. vga_wattr(cinfo->regbase, VGA_ATC_PALETTE8, 0x08);
  1438. vga_wattr(cinfo->regbase, VGA_ATC_PALETTE9, 0x09);
  1439. vga_wattr(cinfo->regbase, VGA_ATC_PALETTEA, 0x0a);
  1440. vga_wattr(cinfo->regbase, VGA_ATC_PALETTEB, 0x0b);
  1441. vga_wattr(cinfo->regbase, VGA_ATC_PALETTEC, 0x0c);
  1442. vga_wattr(cinfo->regbase, VGA_ATC_PALETTED, 0x0d);
  1443. vga_wattr(cinfo->regbase, VGA_ATC_PALETTEE, 0x0e);
  1444. vga_wattr(cinfo->regbase, VGA_ATC_PALETTEF, 0x0f);
  1445. /* Attribute Controller mode: graphics mode */
  1446. vga_wattr(cinfo->regbase, VGA_ATC_MODE, 0x01);
  1447. /* Overscan color reg.: reg. 0 */
  1448. vga_wattr(cinfo->regbase, VGA_ATC_OVERSCAN, 0x00);
  1449. /* Color Plane enable: Enable all 4 planes */
  1450. vga_wattr(cinfo->regbase, VGA_ATC_PLANE_ENABLE, 0x0f);
  1451. /* Color Select: - */
  1452. vga_wattr(cinfo->regbase, VGA_ATC_COLOR_PAGE, 0x00);
  1453. WGen(cinfo, VGA_PEL_MSK, 0xff); /* Pixel mask: no mask */
  1454. /* BLT Start/status: Blitter reset */
  1455. vga_wgfx(cinfo->regbase, CL_GR31, 0x04);
  1456. /* - " - : "end-of-reset" */
  1457. vga_wgfx(cinfo->regbase, CL_GR31, 0x00);
  1458. /* misc... */
  1459. WHDR(cinfo, 0); /* Hidden DAC register: - */
  1460. return;
  1461. }
  1462. static void switch_monitor(struct cirrusfb_info *cinfo, int on)
  1463. {
  1464. #ifdef CONFIG_ZORRO /* only works on Zorro boards */
  1465. static int IsOn = 0; /* XXX not ok for multiple boards */
  1466. if (cinfo->btype == BT_PICASSO4)
  1467. return; /* nothing to switch */
  1468. if (cinfo->btype == BT_ALPINE)
  1469. return; /* nothing to switch */
  1470. if (cinfo->btype == BT_GD5480)
  1471. return; /* nothing to switch */
  1472. if (cinfo->btype == BT_PICASSO) {
  1473. if ((on && !IsOn) || (!on && IsOn))
  1474. WSFR(cinfo, 0xff);
  1475. return;
  1476. }
  1477. if (on) {
  1478. switch (cinfo->btype) {
  1479. case BT_SD64:
  1480. WSFR(cinfo, cinfo->SFR | 0x21);
  1481. break;
  1482. case BT_PICCOLO:
  1483. WSFR(cinfo, cinfo->SFR | 0x28);
  1484. break;
  1485. case BT_SPECTRUM:
  1486. WSFR(cinfo, 0x6f);
  1487. break;
  1488. default: /* do nothing */ break;
  1489. }
  1490. } else {
  1491. switch (cinfo->btype) {
  1492. case BT_SD64:
  1493. WSFR(cinfo, cinfo->SFR & 0xde);
  1494. break;
  1495. case BT_PICCOLO:
  1496. WSFR(cinfo, cinfo->SFR & 0xd7);
  1497. break;
  1498. case BT_SPECTRUM:
  1499. WSFR(cinfo, 0x4f);
  1500. break;
  1501. default: /* do nothing */
  1502. break;
  1503. }
  1504. }
  1505. #endif /* CONFIG_ZORRO */
  1506. }
  1507. /******************************************/
  1508. /* Linux 2.6-style accelerated functions */
  1509. /******************************************/
  1510. static int cirrusfb_sync(struct fb_info *info)
  1511. {
  1512. struct cirrusfb_info *cinfo = info->par;
  1513. if (!is_laguna(cinfo)) {
  1514. while (vga_rgfx(cinfo->regbase, CL_GR31) & 0x03)
  1515. cpu_relax();
  1516. }
  1517. return 0;
  1518. }
  1519. static void cirrusfb_fillrect(struct fb_info *info,
  1520. const struct fb_fillrect *region)
  1521. {
  1522. struct fb_fillrect modded;
  1523. int vxres, vyres;
  1524. struct cirrusfb_info *cinfo = info->par;
  1525. int m = info->var.bits_per_pixel;
  1526. u32 color = (info->fix.visual == FB_VISUAL_TRUECOLOR) ?
  1527. cinfo->pseudo_palette[region->color] : region->color;
  1528. if (info->state != FBINFO_STATE_RUNNING)
  1529. return;
  1530. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  1531. cfb_fillrect(info, region);
  1532. return;
  1533. }
  1534. vxres = info->var.xres_virtual;
  1535. vyres = info->var.yres_virtual;
  1536. memcpy(&modded, region, sizeof(struct fb_fillrect));
  1537. if (!modded.width || !modded.height ||
  1538. modded.dx >= vxres || modded.dy >= vyres)
  1539. return;
  1540. if (modded.dx + modded.width > vxres)
  1541. modded.width = vxres - modded.dx;
  1542. if (modded.dy + modded.height > vyres)
  1543. modded.height = vyres - modded.dy;
  1544. cirrusfb_RectFill(cinfo->regbase,
  1545. info->var.bits_per_pixel,
  1546. (region->dx * m) / 8, region->dy,
  1547. (region->width * m) / 8, region->height,
  1548. color, color,
  1549. info->fix.line_length, 0x40);
  1550. }
  1551. static void cirrusfb_copyarea(struct fb_info *info,
  1552. const struct fb_copyarea *area)
  1553. {
  1554. struct fb_copyarea modded;
  1555. u32 vxres, vyres;
  1556. struct cirrusfb_info *cinfo = info->par;
  1557. int m = info->var.bits_per_pixel;
  1558. if (info->state != FBINFO_STATE_RUNNING)
  1559. return;
  1560. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  1561. cfb_copyarea(info, area);
  1562. return;
  1563. }
  1564. vxres = info->var.xres_virtual;
  1565. vyres = info->var.yres_virtual;
  1566. memcpy(&modded, area, sizeof(struct fb_copyarea));
  1567. if (!modded.width || !modded.height ||
  1568. modded.sx >= vxres || modded.sy >= vyres ||
  1569. modded.dx >= vxres || modded.dy >= vyres)
  1570. return;
  1571. if (modded.sx + modded.width > vxres)
  1572. modded.width = vxres - modded.sx;
  1573. if (modded.dx + modded.width > vxres)
  1574. modded.width = vxres - modded.dx;
  1575. if (modded.sy + modded.height > vyres)
  1576. modded.height = vyres - modded.sy;
  1577. if (modded.dy + modded.height > vyres)
  1578. modded.height = vyres - modded.dy;
  1579. cirrusfb_BitBLT(cinfo->regbase, info->var.bits_per_pixel,
  1580. (area->sx * m) / 8, area->sy,
  1581. (area->dx * m) / 8, area->dy,
  1582. (area->width * m) / 8, area->height,
  1583. info->fix.line_length);
  1584. }
  1585. static void cirrusfb_imageblit(struct fb_info *info,
  1586. const struct fb_image *image)
  1587. {
  1588. struct cirrusfb_info *cinfo = info->par;
  1589. unsigned char op = (info->var.bits_per_pixel == 24) ? 0xc : 0x4;
  1590. if (info->state != FBINFO_STATE_RUNNING)
  1591. return;
  1592. /* Alpine/SD64 does not work at 24bpp ??? */
  1593. if (info->flags & FBINFO_HWACCEL_DISABLED || image->depth != 1)
  1594. cfb_imageblit(info, image);
  1595. else if ((cinfo->btype == BT_ALPINE || cinfo->btype == BT_SD64) &&
  1596. op == 0xc)
  1597. cfb_imageblit(info, image);
  1598. else {
  1599. unsigned size = ((image->width + 7) >> 3) * image->height;
  1600. int m = info->var.bits_per_pixel;
  1601. u32 fg, bg;
  1602. if (info->var.bits_per_pixel == 8) {
  1603. fg = image->fg_color;
  1604. bg = image->bg_color;
  1605. } else {
  1606. fg = ((u32 *)(info->pseudo_palette))[image->fg_color];
  1607. bg = ((u32 *)(info->pseudo_palette))[image->bg_color];
  1608. }
  1609. if (info->var.bits_per_pixel == 24) {
  1610. /* clear background first */
  1611. cirrusfb_RectFill(cinfo->regbase,
  1612. info->var.bits_per_pixel,
  1613. (image->dx * m) / 8, image->dy,
  1614. (image->width * m) / 8,
  1615. image->height,
  1616. bg, bg,
  1617. info->fix.line_length, 0x40);
  1618. }
  1619. cirrusfb_RectFill(cinfo->regbase,
  1620. info->var.bits_per_pixel,
  1621. (image->dx * m) / 8, image->dy,
  1622. (image->width * m) / 8, image->height,
  1623. fg, bg,
  1624. info->fix.line_length, op);
  1625. memcpy(info->screen_base, image->data, size);
  1626. }
  1627. }
  1628. #ifdef CONFIG_PPC_PREP
  1629. #define PREP_VIDEO_BASE ((volatile unsigned long) 0xC0000000)
  1630. #define PREP_IO_BASE ((volatile unsigned char *) 0x80000000)
  1631. static void get_prep_addrs(unsigned long *display, unsigned long *registers)
  1632. {
  1633. *display = PREP_VIDEO_BASE;
  1634. *registers = (unsigned long) PREP_IO_BASE;
  1635. }
  1636. #endif /* CONFIG_PPC_PREP */
  1637. #ifdef CONFIG_PCI
  1638. static int release_io_ports;
  1639. /* Pulled the logic from XFree86 Cirrus driver to get the memory size,
  1640. * based on the DRAM bandwidth bit and DRAM bank switching bit. This
  1641. * works with 1MB, 2MB and 4MB configurations (which the Motorola boards
  1642. * seem to have. */
  1643. static unsigned int __devinit cirrusfb_get_memsize(struct fb_info *info,
  1644. u8 __iomem *regbase)
  1645. {
  1646. unsigned long mem;
  1647. struct cirrusfb_info *cinfo = info->par;
  1648. if (is_laguna(cinfo)) {
  1649. unsigned char SR14 = vga_rseq(regbase, CL_SEQR14);
  1650. mem = ((SR14 & 7) + 1) << 20;
  1651. } else {
  1652. unsigned char SRF = vga_rseq(regbase, CL_SEQRF);
  1653. switch ((SRF & 0x18)) {
  1654. case 0x08:
  1655. mem = 512 * 1024;
  1656. break;
  1657. case 0x10:
  1658. mem = 1024 * 1024;
  1659. break;
  1660. /* 64-bit DRAM data bus width; assume 2MB.
  1661. * Also indicates 2MB memory on the 5430.
  1662. */
  1663. case 0x18:
  1664. mem = 2048 * 1024;
  1665. break;
  1666. default:
  1667. dev_warn(info->device, "Unknown memory size!\n");
  1668. mem = 1024 * 1024;
  1669. }
  1670. /* If DRAM bank switching is enabled, there must be
  1671. * twice as much memory installed. (4MB on the 5434)
  1672. */
  1673. if (cinfo->btype != BT_ALPINE && (SRF & 0x80) != 0)
  1674. mem *= 2;
  1675. }
  1676. /* TODO: Handling of GD5446/5480 (see XF86 sources ...) */
  1677. return mem;
  1678. }
  1679. static void get_pci_addrs(const struct pci_dev *pdev,
  1680. unsigned long *display, unsigned long *registers)
  1681. {
  1682. assert(pdev != NULL);
  1683. assert(display != NULL);
  1684. assert(registers != NULL);
  1685. *display = 0;
  1686. *registers = 0;
  1687. /* This is a best-guess for now */
  1688. if (pci_resource_flags(pdev, 0) & IORESOURCE_IO) {
  1689. *display = pci_resource_start(pdev, 1);
  1690. *registers = pci_resource_start(pdev, 0);
  1691. } else {
  1692. *display = pci_resource_start(pdev, 0);
  1693. *registers = pci_resource_start(pdev, 1);
  1694. }
  1695. assert(*display != 0);
  1696. }
  1697. static void cirrusfb_pci_unmap(struct fb_info *info)
  1698. {
  1699. struct pci_dev *pdev = to_pci_dev(info->device);
  1700. struct cirrusfb_info *cinfo = info->par;
  1701. if (cinfo->laguna_mmio == NULL)
  1702. iounmap(cinfo->laguna_mmio);
  1703. iounmap(info->screen_base);
  1704. #if 0 /* if system didn't claim this region, we would... */
  1705. release_mem_region(0xA0000, 65535);
  1706. #endif
  1707. if (release_io_ports)
  1708. release_region(0x3C0, 32);
  1709. pci_release_regions(pdev);
  1710. }
  1711. #endif /* CONFIG_PCI */
  1712. #ifdef CONFIG_ZORRO
  1713. static void cirrusfb_zorro_unmap(struct fb_info *info)
  1714. {
  1715. struct cirrusfb_info *cinfo = info->par;
  1716. struct zorro_dev *zdev = to_zorro_dev(info->device);
  1717. if (info->fix.smem_start > 16 * MB_)
  1718. iounmap(info->screen_base);
  1719. if (info->fix.mmio_start > 16 * MB_)
  1720. iounmap(cinfo->regbase);
  1721. zorro_release_device(zdev);
  1722. }
  1723. #endif /* CONFIG_ZORRO */
  1724. /* function table of the above functions */
  1725. static struct fb_ops cirrusfb_ops = {
  1726. .owner = THIS_MODULE,
  1727. .fb_open = cirrusfb_open,
  1728. .fb_release = cirrusfb_release,
  1729. .fb_setcolreg = cirrusfb_setcolreg,
  1730. .fb_check_var = cirrusfb_check_var,
  1731. .fb_set_par = cirrusfb_set_par,
  1732. .fb_pan_display = cirrusfb_pan_display,
  1733. .fb_blank = cirrusfb_blank,
  1734. .fb_fillrect = cirrusfb_fillrect,
  1735. .fb_copyarea = cirrusfb_copyarea,
  1736. .fb_sync = cirrusfb_sync,
  1737. .fb_imageblit = cirrusfb_imageblit,
  1738. };
  1739. static int __devinit cirrusfb_set_fbinfo(struct fb_info *info)
  1740. {
  1741. struct cirrusfb_info *cinfo = info->par;
  1742. struct fb_var_screeninfo *var = &info->var;
  1743. info->pseudo_palette = cinfo->pseudo_palette;
  1744. info->flags = FBINFO_DEFAULT
  1745. | FBINFO_HWACCEL_XPAN
  1746. | FBINFO_HWACCEL_YPAN
  1747. | FBINFO_HWACCEL_FILLRECT
  1748. | FBINFO_HWACCEL_IMAGEBLIT
  1749. | FBINFO_HWACCEL_COPYAREA;
  1750. if (noaccel || is_laguna(cinfo)) {
  1751. info->flags |= FBINFO_HWACCEL_DISABLED;
  1752. info->fix.accel = FB_ACCEL_NONE;
  1753. } else
  1754. info->fix.accel = FB_ACCEL_CIRRUS_ALPINE;
  1755. info->fbops = &cirrusfb_ops;
  1756. if (cinfo->btype == BT_GD5480) {
  1757. if (var->bits_per_pixel == 16)
  1758. info->screen_base += 1 * MB_;
  1759. if (var->bits_per_pixel == 32)
  1760. info->screen_base += 2 * MB_;
  1761. }
  1762. /* Fill fix common fields */
  1763. strlcpy(info->fix.id, cirrusfb_board_info[cinfo->btype].name,
  1764. sizeof(info->fix.id));
  1765. /* monochrome: only 1 memory plane */
  1766. /* 8 bit and above: Use whole memory area */
  1767. info->fix.smem_len = info->screen_size;
  1768. if (var->bits_per_pixel == 1)
  1769. info->fix.smem_len /= 4;
  1770. info->fix.type_aux = 0;
  1771. info->fix.xpanstep = 1;
  1772. info->fix.ypanstep = 1;
  1773. info->fix.ywrapstep = 0;
  1774. /* FIXME: map region at 0xB8000 if available, fill in here */
  1775. info->fix.mmio_len = 0;
  1776. fb_alloc_cmap(&info->cmap, 256, 0);
  1777. return 0;
  1778. }
  1779. static int __devinit cirrusfb_register(struct fb_info *info)
  1780. {
  1781. struct cirrusfb_info *cinfo = info->par;
  1782. int err;
  1783. /* sanity checks */
  1784. assert(cinfo->btype != BT_NONE);
  1785. /* set all the vital stuff */
  1786. cirrusfb_set_fbinfo(info);
  1787. dev_dbg(info->device, "(RAM start set to: 0x%p)\n", info->screen_base);
  1788. err = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
  1789. if (!err) {
  1790. dev_dbg(info->device, "wrong initial video mode\n");
  1791. err = -EINVAL;
  1792. goto err_dealloc_cmap;
  1793. }
  1794. info->var.activate = FB_ACTIVATE_NOW;
  1795. err = cirrusfb_check_var(&info->var, info);
  1796. if (err < 0) {
  1797. /* should never happen */
  1798. dev_dbg(info->device,
  1799. "choking on default var... umm, no good.\n");
  1800. goto err_dealloc_cmap;
  1801. }
  1802. err = register_framebuffer(info);
  1803. if (err < 0) {
  1804. dev_err(info->device,
  1805. "could not register fb device; err = %d!\n", err);
  1806. goto err_dealloc_cmap;
  1807. }
  1808. return 0;
  1809. err_dealloc_cmap:
  1810. fb_dealloc_cmap(&info->cmap);
  1811. return err;
  1812. }
  1813. static void __devexit cirrusfb_cleanup(struct fb_info *info)
  1814. {
  1815. struct cirrusfb_info *cinfo = info->par;
  1816. switch_monitor(cinfo, 0);
  1817. unregister_framebuffer(info);
  1818. fb_dealloc_cmap(&info->cmap);
  1819. dev_dbg(info->device, "Framebuffer unregistered\n");
  1820. cinfo->unmap(info);
  1821. framebuffer_release(info);
  1822. }
  1823. #ifdef CONFIG_PCI
  1824. static int __devinit cirrusfb_pci_register(struct pci_dev *pdev,
  1825. const struct pci_device_id *ent)
  1826. {
  1827. struct cirrusfb_info *cinfo;
  1828. struct fb_info *info;
  1829. unsigned long board_addr, board_size;
  1830. int ret;
  1831. ret = pci_enable_device(pdev);
  1832. if (ret < 0) {
  1833. printk(KERN_ERR "cirrusfb: Cannot enable PCI device\n");
  1834. goto err_out;
  1835. }
  1836. info = framebuffer_alloc(sizeof(struct cirrusfb_info), &pdev->dev);
  1837. if (!info) {
  1838. printk(KERN_ERR "cirrusfb: could not allocate memory\n");
  1839. ret = -ENOMEM;
  1840. goto err_out;
  1841. }
  1842. cinfo = info->par;
  1843. cinfo->btype = (enum cirrus_board) ent->driver_data;
  1844. dev_dbg(info->device,
  1845. " Found PCI device, base address 0 is 0x%Lx, btype set to %d\n",
  1846. (unsigned long long)pdev->resource[0].start, cinfo->btype);
  1847. dev_dbg(info->device, " base address 1 is 0x%Lx\n",
  1848. (unsigned long long)pdev->resource[1].start);
  1849. if (isPReP) {
  1850. pci_write_config_dword(pdev, PCI_BASE_ADDRESS_0, 0x00000000);
  1851. #ifdef CONFIG_PPC_PREP
  1852. get_prep_addrs(&board_addr, &info->fix.mmio_start);
  1853. #endif
  1854. /* PReP dies if we ioremap the IO registers, but it works w/out... */
  1855. cinfo->regbase = (char __iomem *) info->fix.mmio_start;
  1856. } else {
  1857. dev_dbg(info->device,
  1858. "Attempt to get PCI info for Cirrus Graphics Card\n");
  1859. get_pci_addrs(pdev, &board_addr, &info->fix.mmio_start);
  1860. /* FIXME: this forces VGA. alternatives? */
  1861. cinfo->regbase = NULL;
  1862. cinfo->laguna_mmio = ioremap(info->fix.mmio_start, 0x1000);
  1863. }
  1864. dev_dbg(info->device, "Board address: 0x%lx, register address: 0x%lx\n",
  1865. board_addr, info->fix.mmio_start);
  1866. board_size = (cinfo->btype == BT_GD5480) ?
  1867. 32 * MB_ : cirrusfb_get_memsize(info, cinfo->regbase);
  1868. ret = pci_request_regions(pdev, "cirrusfb");
  1869. if (ret < 0) {
  1870. dev_err(info->device, "cannot reserve region 0x%lx, abort\n",
  1871. board_addr);
  1872. goto err_release_fb;
  1873. }
  1874. #if 0 /* if the system didn't claim this region, we would... */
  1875. if (!request_mem_region(0xA0000, 65535, "cirrusfb")) {
  1876. dev_err(info->device, "cannot reserve region 0x%lx, abort\n",
  1877. 0xA0000L);
  1878. ret = -EBUSY;
  1879. goto err_release_regions;
  1880. }
  1881. #endif
  1882. if (request_region(0x3C0, 32, "cirrusfb"))
  1883. release_io_ports = 1;
  1884. info->screen_base = ioremap(board_addr, board_size);
  1885. if (!info->screen_base) {
  1886. ret = -EIO;
  1887. goto err_release_legacy;
  1888. }
  1889. info->fix.smem_start = board_addr;
  1890. info->screen_size = board_size;
  1891. cinfo->unmap = cirrusfb_pci_unmap;
  1892. dev_info(info->device,
  1893. "Cirrus Logic chipset on PCI bus, RAM (%lu kB) at 0x%lx\n",
  1894. info->screen_size >> 10, board_addr);
  1895. pci_set_drvdata(pdev, info);
  1896. ret = cirrusfb_register(info);
  1897. if (!ret)
  1898. return 0;
  1899. pci_set_drvdata(pdev, NULL);
  1900. iounmap(info->screen_base);
  1901. err_release_legacy:
  1902. if (release_io_ports)
  1903. release_region(0x3C0, 32);
  1904. #if 0
  1905. release_mem_region(0xA0000, 65535);
  1906. err_release_regions:
  1907. #endif
  1908. pci_release_regions(pdev);
  1909. err_release_fb:
  1910. if (cinfo->laguna_mmio != NULL)
  1911. iounmap(cinfo->laguna_mmio);
  1912. framebuffer_release(info);
  1913. err_out:
  1914. return ret;
  1915. }
  1916. static void __devexit cirrusfb_pci_unregister(struct pci_dev *pdev)
  1917. {
  1918. struct fb_info *info = pci_get_drvdata(pdev);
  1919. cirrusfb_cleanup(info);
  1920. }
  1921. static struct pci_driver cirrusfb_pci_driver = {
  1922. .name = "cirrusfb",
  1923. .id_table = cirrusfb_pci_table,
  1924. .probe = cirrusfb_pci_register,
  1925. .remove = __devexit_p(cirrusfb_pci_unregister),
  1926. #ifdef CONFIG_PM
  1927. #if 0
  1928. .suspend = cirrusfb_pci_suspend,
  1929. .resume = cirrusfb_pci_resume,
  1930. #endif
  1931. #endif
  1932. };
  1933. #endif /* CONFIG_PCI */
  1934. #ifdef CONFIG_ZORRO
  1935. static int __devinit cirrusfb_zorro_register(struct zorro_dev *z,
  1936. const struct zorro_device_id *ent)
  1937. {
  1938. struct fb_info *info;
  1939. int error;
  1940. const struct zorrocl *zcl;
  1941. enum cirrus_board btype;
  1942. unsigned long regbase, ramsize, rambase;
  1943. struct cirrusfb_info *cinfo;
  1944. info = framebuffer_alloc(sizeof(struct cirrusfb_info), &z->dev);
  1945. if (!info) {
  1946. printk(KERN_ERR "cirrusfb: could not allocate memory\n");
  1947. return -ENOMEM;
  1948. }
  1949. zcl = (const struct zorrocl *)ent->driver_data;
  1950. btype = zcl->type;
  1951. regbase = zorro_resource_start(z) + zcl->regoffset;
  1952. ramsize = zcl->ramsize;
  1953. if (ramsize) {
  1954. rambase = zorro_resource_start(z) + zcl->ramoffset;
  1955. } else {
  1956. struct zorro_dev *ram = zorro_find_device(zcl->ramid, NULL);
  1957. if (!ram || !zorro_resource_len(ram)) {
  1958. dev_err(info->device, "No video RAM found\n");
  1959. error = -ENODEV;
  1960. goto err_release_fb;
  1961. }
  1962. rambase = zorro_resource_start(ram);
  1963. ramsize = zorro_resource_len(ram);
  1964. if (zcl->ramid2 &&
  1965. (ram = zorro_find_device(zcl->ramid2, NULL))) {
  1966. if (zorro_resource_start(ram) != rambase + ramsize) {
  1967. dev_warn(info->device,
  1968. "Skipping non-contiguous RAM at %pR\n",
  1969. &ram->resource);
  1970. } else {
  1971. ramsize += zorro_resource_len(ram);
  1972. }
  1973. }
  1974. }
  1975. dev_info(info->device,
  1976. "%s board detected, REG at 0x%lx, %lu MiB RAM at 0x%lx\n",
  1977. cirrusfb_board_info[btype].name, regbase, ramsize / MB_,
  1978. rambase);
  1979. if (!zorro_request_device(z, "cirrusfb")) {
  1980. dev_err(info->device, "Cannot reserve %pR\n", &z->resource);
  1981. error = -EBUSY;
  1982. goto err_release_fb;
  1983. }
  1984. cinfo = info->par;
  1985. cinfo->btype = btype;
  1986. info->fix.mmio_start = regbase;
  1987. cinfo->regbase = regbase > 16 * MB_ ? ioremap(regbase, 64 * 1024)
  1988. : (caddr_t)ZTWO_VADDR(regbase);
  1989. if (!cinfo->regbase) {
  1990. dev_err(info->device, "Cannot map registers\n");
  1991. error = -EIO;
  1992. goto err_release_dev;
  1993. }
  1994. info->fix.smem_start = rambase;
  1995. info->screen_size = ramsize;
  1996. info->screen_base = rambase > 16 * MB_ ? ioremap(rambase, ramsize)
  1997. : (caddr_t)ZTWO_VADDR(rambase);
  1998. if (!info->screen_base) {
  1999. dev_err(info->device, "Cannot map video RAM\n");
  2000. error = -EIO;
  2001. goto err_unmap_reg;
  2002. }
  2003. cinfo->unmap = cirrusfb_zorro_unmap;
  2004. dev_info(info->device,
  2005. "Cirrus Logic chipset on Zorro bus, RAM (%lu MiB) at 0x%lx\n",
  2006. ramsize / MB_, rambase);
  2007. /* MCLK select etc. */
  2008. if (cirrusfb_board_info[btype].init_sr1f)
  2009. vga_wseq(cinfo->regbase, CL_SEQR1F,
  2010. cirrusfb_board_info[btype].sr1f);
  2011. error = cirrusfb_register(info);
  2012. if (error) {
  2013. dev_err(info->device, "Failed to register device, error %d\n",
  2014. error);
  2015. goto err_unmap_ram;
  2016. }
  2017. zorro_set_drvdata(z, info);
  2018. return 0;
  2019. err_unmap_ram:
  2020. if (rambase > 16 * MB_)
  2021. iounmap(info->screen_base);
  2022. err_unmap_reg:
  2023. if (regbase > 16 * MB_)
  2024. iounmap(cinfo->regbase);
  2025. err_release_dev:
  2026. zorro_release_device(z);
  2027. err_release_fb:
  2028. framebuffer_release(info);
  2029. return error;
  2030. }
  2031. void __devexit cirrusfb_zorro_unregister(struct zorro_dev *z)
  2032. {
  2033. struct fb_info *info = zorro_get_drvdata(z);
  2034. cirrusfb_cleanup(info);
  2035. zorro_set_drvdata(z, NULL);
  2036. }
  2037. static struct zorro_driver cirrusfb_zorro_driver = {
  2038. .name = "cirrusfb",
  2039. .id_table = cirrusfb_zorro_table,
  2040. .probe = cirrusfb_zorro_register,
  2041. .remove = __devexit_p(cirrusfb_zorro_unregister),
  2042. };
  2043. #endif /* CONFIG_ZORRO */
  2044. #ifndef MODULE
  2045. static int __init cirrusfb_setup(char *options)
  2046. {
  2047. char *this_opt;
  2048. if (!options || !*options)
  2049. return 0;
  2050. while ((this_opt = strsep(&options, ",")) != NULL) {
  2051. if (!*this_opt)
  2052. continue;
  2053. if (!strcmp(this_opt, "noaccel"))
  2054. noaccel = 1;
  2055. else if (!strncmp(this_opt, "mode:", 5))
  2056. mode_option = this_opt + 5;
  2057. else
  2058. mode_option = this_opt;
  2059. }
  2060. return 0;
  2061. }
  2062. #endif
  2063. /*
  2064. * Modularization
  2065. */
  2066. MODULE_AUTHOR("Copyright 1999,2000 Jeff Garzik <jgarzik@pobox.com>");
  2067. MODULE_DESCRIPTION("Accelerated FBDev driver for Cirrus Logic chips");
  2068. MODULE_LICENSE("GPL");
  2069. static int __init cirrusfb_init(void)
  2070. {
  2071. int error = 0;
  2072. #ifndef MODULE
  2073. char *option = NULL;
  2074. if (fb_get_options("cirrusfb", &option))
  2075. return -ENODEV;
  2076. cirrusfb_setup(option);
  2077. #endif
  2078. #ifdef CONFIG_ZORRO
  2079. error |= zorro_register_driver(&cirrusfb_zorro_driver);
  2080. #endif
  2081. #ifdef CONFIG_PCI
  2082. error |= pci_register_driver(&cirrusfb_pci_driver);
  2083. #endif
  2084. return error;
  2085. }
  2086. static void __exit cirrusfb_exit(void)
  2087. {
  2088. #ifdef CONFIG_PCI
  2089. pci_unregister_driver(&cirrusfb_pci_driver);
  2090. #endif
  2091. #ifdef CONFIG_ZORRO
  2092. zorro_unregister_driver(&cirrusfb_zorro_driver);
  2093. #endif
  2094. }
  2095. module_init(cirrusfb_init);
  2096. module_param(mode_option, charp, 0);
  2097. MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'");
  2098. module_param(noaccel, bool, 0);
  2099. MODULE_PARM_DESC(noaccel, "Disable acceleration");
  2100. #ifdef MODULE
  2101. module_exit(cirrusfb_exit);
  2102. #endif
  2103. /**********************************************************************/
  2104. /* about the following functions - I have used the same names for the */
  2105. /* functions as Markus Wild did in his Retina driver for NetBSD as */
  2106. /* they just made sense for this purpose. Apart from that, I wrote */
  2107. /* these functions myself. */
  2108. /**********************************************************************/
  2109. /*** WGen() - write into one of the external/general registers ***/
  2110. static void WGen(const struct cirrusfb_info *cinfo,
  2111. int regnum, unsigned char val)
  2112. {
  2113. unsigned long regofs = 0;
  2114. if (cinfo->btype == BT_PICASSO) {
  2115. /* Picasso II specific hack */
  2116. /* if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D ||
  2117. regnum == CL_VSSM2) */
  2118. if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D)
  2119. regofs = 0xfff;
  2120. }
  2121. vga_w(cinfo->regbase, regofs + regnum, val);
  2122. }
  2123. /*** RGen() - read out one of the external/general registers ***/
  2124. static unsigned char RGen(const struct cirrusfb_info *cinfo, int regnum)
  2125. {
  2126. unsigned long regofs = 0;
  2127. if (cinfo->btype == BT_PICASSO) {
  2128. /* Picasso II specific hack */
  2129. /* if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D ||
  2130. regnum == CL_VSSM2) */
  2131. if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D)
  2132. regofs = 0xfff;
  2133. }
  2134. return vga_r(cinfo->regbase, regofs + regnum);
  2135. }
  2136. /*** AttrOn() - turn on VideoEnable for Attribute controller ***/
  2137. static void AttrOn(const struct cirrusfb_info *cinfo)
  2138. {
  2139. assert(cinfo != NULL);
  2140. if (vga_rcrt(cinfo->regbase, CL_CRT24) & 0x80) {
  2141. /* if we're just in "write value" mode, write back the */
  2142. /* same value as before to not modify anything */
  2143. vga_w(cinfo->regbase, VGA_ATT_IW,
  2144. vga_r(cinfo->regbase, VGA_ATT_R));
  2145. }
  2146. /* turn on video bit */
  2147. /* vga_w(cinfo->regbase, VGA_ATT_IW, 0x20); */
  2148. vga_w(cinfo->regbase, VGA_ATT_IW, 0x33);
  2149. /* dummy write on Reg0 to be on "write index" mode next time */
  2150. vga_w(cinfo->regbase, VGA_ATT_IW, 0x00);
  2151. }
  2152. /*** WHDR() - write into the Hidden DAC register ***/
  2153. /* as the HDR is the only extension register that requires special treatment
  2154. * (the other extension registers are accessible just like the "ordinary"
  2155. * registers of their functional group) here is a specialized routine for
  2156. * accessing the HDR
  2157. */
  2158. static void WHDR(const struct cirrusfb_info *cinfo, unsigned char val)
  2159. {
  2160. unsigned char dummy;
  2161. if (is_laguna(cinfo))
  2162. return;
  2163. if (cinfo->btype == BT_PICASSO) {
  2164. /* Klaus' hint for correct access to HDR on some boards */
  2165. /* first write 0 to pixel mask (3c6) */
  2166. WGen(cinfo, VGA_PEL_MSK, 0x00);
  2167. udelay(200);
  2168. /* next read dummy from pixel address (3c8) */
  2169. dummy = RGen(cinfo, VGA_PEL_IW);
  2170. udelay(200);
  2171. }
  2172. /* now do the usual stuff to access the HDR */
  2173. dummy = RGen(cinfo, VGA_PEL_MSK);
  2174. udelay(200);
  2175. dummy = RGen(cinfo, VGA_PEL_MSK);
  2176. udelay(200);
  2177. dummy = RGen(cinfo, VGA_PEL_MSK);
  2178. udelay(200);
  2179. dummy = RGen(cinfo, VGA_PEL_MSK);
  2180. udelay(200);
  2181. WGen(cinfo, VGA_PEL_MSK, val);
  2182. udelay(200);
  2183. if (cinfo->btype == BT_PICASSO) {
  2184. /* now first reset HDR access counter */
  2185. dummy = RGen(cinfo, VGA_PEL_IW);
  2186. udelay(200);
  2187. /* and at the end, restore the mask value */
  2188. /* ## is this mask always 0xff? */
  2189. WGen(cinfo, VGA_PEL_MSK, 0xff);
  2190. udelay(200);
  2191. }
  2192. }
  2193. /*** WSFR() - write to the "special function register" (SFR) ***/
  2194. static void WSFR(struct cirrusfb_info *cinfo, unsigned char val)
  2195. {
  2196. #ifdef CONFIG_ZORRO
  2197. assert(cinfo->regbase != NULL);
  2198. cinfo->SFR = val;
  2199. z_writeb(val, cinfo->regbase + 0x8000);
  2200. #endif
  2201. }
  2202. /* The Picasso has a second register for switching the monitor bit */
  2203. static void WSFR2(struct cirrusfb_info *cinfo, unsigned char val)
  2204. {
  2205. #ifdef CONFIG_ZORRO
  2206. /* writing an arbitrary value to this one causes the monitor switcher */
  2207. /* to flip to Amiga display */
  2208. assert(cinfo->regbase != NULL);
  2209. cinfo->SFR = val;
  2210. z_writeb(val, cinfo->regbase + 0x9000);
  2211. #endif
  2212. }
  2213. /*** WClut - set CLUT entry (range: 0..63) ***/
  2214. static void WClut(struct cirrusfb_info *cinfo, unsigned char regnum, unsigned char red,
  2215. unsigned char green, unsigned char blue)
  2216. {
  2217. unsigned int data = VGA_PEL_D;
  2218. /* address write mode register is not translated.. */
  2219. vga_w(cinfo->regbase, VGA_PEL_IW, regnum);
  2220. if (cinfo->btype == BT_PICASSO || cinfo->btype == BT_PICASSO4 ||
  2221. cinfo->btype == BT_ALPINE || cinfo->btype == BT_GD5480 ||
  2222. cinfo->btype == BT_SD64 || is_laguna(cinfo)) {
  2223. /* but DAC data register IS, at least for Picasso II */
  2224. if (cinfo->btype == BT_PICASSO)
  2225. data += 0xfff;
  2226. vga_w(cinfo->regbase, data, red);
  2227. vga_w(cinfo->regbase, data, green);
  2228. vga_w(cinfo->regbase, data, blue);
  2229. } else {
  2230. vga_w(cinfo->regbase, data, blue);
  2231. vga_w(cinfo->regbase, data, green);
  2232. vga_w(cinfo->regbase, data, red);
  2233. }
  2234. }
  2235. #if 0
  2236. /*** RClut - read CLUT entry (range 0..63) ***/
  2237. static void RClut(struct cirrusfb_info *cinfo, unsigned char regnum, unsigned char *red,
  2238. unsigned char *green, unsigned char *blue)
  2239. {
  2240. unsigned int data = VGA_PEL_D;
  2241. vga_w(cinfo->regbase, VGA_PEL_IR, regnum);
  2242. if (cinfo->btype == BT_PICASSO || cinfo->btype == BT_PICASSO4 ||
  2243. cinfo->btype == BT_ALPINE || cinfo->btype == BT_GD5480) {
  2244. if (cinfo->btype == BT_PICASSO)
  2245. data += 0xfff;
  2246. *red = vga_r(cinfo->regbase, data);
  2247. *green = vga_r(cinfo->regbase, data);
  2248. *blue = vga_r(cinfo->regbase, data);
  2249. } else {
  2250. *blue = vga_r(cinfo->regbase, data);
  2251. *green = vga_r(cinfo->regbase, data);
  2252. *red = vga_r(cinfo->regbase, data);
  2253. }
  2254. }
  2255. #endif
  2256. /*******************************************************************
  2257. cirrusfb_WaitBLT()
  2258. Wait for the BitBLT engine to complete a possible earlier job
  2259. *********************************************************************/
  2260. /* FIXME: use interrupts instead */
  2261. static void cirrusfb_WaitBLT(u8 __iomem *regbase)
  2262. {
  2263. while (vga_rgfx(regbase, CL_GR31) & 0x08)
  2264. cpu_relax();
  2265. }
  2266. /*******************************************************************
  2267. cirrusfb_BitBLT()
  2268. perform accelerated "scrolling"
  2269. ********************************************************************/
  2270. static void cirrusfb_set_blitter(u8 __iomem *regbase,
  2271. u_short nwidth, u_short nheight,
  2272. u_long nsrc, u_long ndest,
  2273. u_short bltmode, u_short line_length)
  2274. {
  2275. /* pitch: set to line_length */
  2276. /* dest pitch low */
  2277. vga_wgfx(regbase, CL_GR24, line_length & 0xff);
  2278. /* dest pitch hi */
  2279. vga_wgfx(regbase, CL_GR25, line_length >> 8);
  2280. /* source pitch low */
  2281. vga_wgfx(regbase, CL_GR26, line_length & 0xff);
  2282. /* source pitch hi */
  2283. vga_wgfx(regbase, CL_GR27, line_length >> 8);
  2284. /* BLT width: actual number of pixels - 1 */
  2285. /* BLT width low */
  2286. vga_wgfx(regbase, CL_GR20, nwidth & 0xff);
  2287. /* BLT width hi */
  2288. vga_wgfx(regbase, CL_GR21, nwidth >> 8);
  2289. /* BLT height: actual number of lines -1 */
  2290. /* BLT height low */
  2291. vga_wgfx(regbase, CL_GR22, nheight & 0xff);
  2292. /* BLT width hi */
  2293. vga_wgfx(regbase, CL_GR23, nheight >> 8);
  2294. /* BLT destination */
  2295. /* BLT dest low */
  2296. vga_wgfx(regbase, CL_GR28, (u_char) (ndest & 0xff));
  2297. /* BLT dest mid */
  2298. vga_wgfx(regbase, CL_GR29, (u_char) (ndest >> 8));
  2299. /* BLT dest hi */
  2300. vga_wgfx(regbase, CL_GR2A, (u_char) (ndest >> 16));
  2301. /* BLT source */
  2302. /* BLT src low */
  2303. vga_wgfx(regbase, CL_GR2C, (u_char) (nsrc & 0xff));
  2304. /* BLT src mid */
  2305. vga_wgfx(regbase, CL_GR2D, (u_char) (nsrc >> 8));
  2306. /* BLT src hi */
  2307. vga_wgfx(regbase, CL_GR2E, (u_char) (nsrc >> 16));
  2308. /* BLT mode */
  2309. vga_wgfx(regbase, CL_GR30, bltmode); /* BLT mode */
  2310. /* BLT ROP: SrcCopy */
  2311. vga_wgfx(regbase, CL_GR32, 0x0d); /* BLT ROP */
  2312. /* and finally: GO! */
  2313. vga_wgfx(regbase, CL_GR31, 0x02); /* BLT Start/status */
  2314. }
  2315. /*******************************************************************
  2316. cirrusfb_BitBLT()
  2317. perform accelerated "scrolling"
  2318. ********************************************************************/
  2319. static void cirrusfb_BitBLT(u8 __iomem *regbase, int bits_per_pixel,
  2320. u_short curx, u_short cury,
  2321. u_short destx, u_short desty,
  2322. u_short width, u_short height,
  2323. u_short line_length)
  2324. {
  2325. u_short nwidth = width - 1;
  2326. u_short nheight = height - 1;
  2327. u_long nsrc, ndest;
  2328. u_char bltmode;
  2329. bltmode = 0x00;
  2330. /* if source adr < dest addr, do the Blt backwards */
  2331. if (cury <= desty) {
  2332. if (cury == desty) {
  2333. /* if src and dest are on the same line, check x */
  2334. if (curx < destx)
  2335. bltmode |= 0x01;
  2336. } else
  2337. bltmode |= 0x01;
  2338. }
  2339. /* standard case: forward blitting */
  2340. nsrc = (cury * line_length) + curx;
  2341. ndest = (desty * line_length) + destx;
  2342. if (bltmode) {
  2343. /* this means start addresses are at the end,
  2344. * counting backwards
  2345. */
  2346. nsrc += nheight * line_length + nwidth;
  2347. ndest += nheight * line_length + nwidth;
  2348. }
  2349. cirrusfb_WaitBLT(regbase);
  2350. cirrusfb_set_blitter(regbase, nwidth, nheight,
  2351. nsrc, ndest, bltmode, line_length);
  2352. }
  2353. /*******************************************************************
  2354. cirrusfb_RectFill()
  2355. perform accelerated rectangle fill
  2356. ********************************************************************/
  2357. static void cirrusfb_RectFill(u8 __iomem *regbase, int bits_per_pixel,
  2358. u_short x, u_short y, u_short width, u_short height,
  2359. u32 fg_color, u32 bg_color, u_short line_length,
  2360. u_char blitmode)
  2361. {
  2362. u_long ndest = (y * line_length) + x;
  2363. u_char op;
  2364. cirrusfb_WaitBLT(regbase);
  2365. /* This is a ColorExpand Blt, using the */
  2366. /* same color for foreground and background */
  2367. vga_wgfx(regbase, VGA_GFX_SR_VALUE, bg_color);
  2368. vga_wgfx(regbase, VGA_GFX_SR_ENABLE, fg_color);
  2369. op = 0x80;
  2370. if (bits_per_pixel >= 16) {
  2371. vga_wgfx(regbase, CL_GR10, bg_color >> 8);
  2372. vga_wgfx(regbase, CL_GR11, fg_color >> 8);
  2373. op = 0x90;
  2374. }
  2375. if (bits_per_pixel >= 24) {
  2376. vga_wgfx(regbase, CL_GR12, bg_color >> 16);
  2377. vga_wgfx(regbase, CL_GR13, fg_color >> 16);
  2378. op = 0xa0;
  2379. }
  2380. if (bits_per_pixel == 32) {
  2381. vga_wgfx(regbase, CL_GR14, bg_color >> 24);
  2382. vga_wgfx(regbase, CL_GR15, fg_color >> 24);
  2383. op = 0xb0;
  2384. }
  2385. cirrusfb_set_blitter(regbase, width - 1, height - 1,
  2386. 0, ndest, op | blitmode, line_length);
  2387. }
  2388. /**************************************************************************
  2389. * bestclock() - determine closest possible clock lower(?) than the
  2390. * desired pixel clock
  2391. **************************************************************************/
  2392. static void bestclock(long freq, int *nom, int *den, int *div)
  2393. {
  2394. int n, d;
  2395. long h, diff;
  2396. assert(nom != NULL);
  2397. assert(den != NULL);
  2398. assert(div != NULL);
  2399. *nom = 0;
  2400. *den = 0;
  2401. *div = 0;
  2402. if (freq < 8000)
  2403. freq = 8000;
  2404. diff = freq;
  2405. for (n = 32; n < 128; n++) {
  2406. int s = 0;
  2407. d = (14318 * n) / freq;
  2408. if ((d >= 7) && (d <= 63)) {
  2409. int temp = d;
  2410. if (temp > 31) {
  2411. s = 1;
  2412. temp >>= 1;
  2413. }
  2414. h = ((14318 * n) / temp) >> s;
  2415. h = h > freq ? h - freq : freq - h;
  2416. if (h < diff) {
  2417. diff = h;
  2418. *nom = n;
  2419. *den = temp;
  2420. *div = s;
  2421. }
  2422. }
  2423. d++;
  2424. if ((d >= 7) && (d <= 63)) {
  2425. if (d > 31) {
  2426. s = 1;
  2427. d >>= 1;
  2428. }
  2429. h = ((14318 * n) / d) >> s;
  2430. h = h > freq ? h - freq : freq - h;
  2431. if (h < diff) {
  2432. diff = h;
  2433. *nom = n;
  2434. *den = d;
  2435. *div = s;
  2436. }
  2437. }
  2438. }
  2439. }
  2440. /* -------------------------------------------------------------------------
  2441. *
  2442. * debugging functions
  2443. *
  2444. * -------------------------------------------------------------------------
  2445. */
  2446. #ifdef CIRRUSFB_DEBUG
  2447. /**
  2448. * cirrusfb_dbg_print_regs
  2449. * @base: If using newmmio, the newmmio base address, otherwise %NULL
  2450. * @reg_class: type of registers to read: %CRT, or %SEQ
  2451. *
  2452. * DESCRIPTION:
  2453. * Dumps the given list of VGA CRTC registers. If @base is %NULL,
  2454. * old-style I/O ports are queried for information, otherwise MMIO is
  2455. * used at the given @base address to query the information.
  2456. */
  2457. static void cirrusfb_dbg_print_regs(struct fb_info *info,
  2458. caddr_t regbase,
  2459. enum cirrusfb_dbg_reg_class reg_class, ...)
  2460. {
  2461. va_list list;
  2462. unsigned char val = 0;
  2463. unsigned reg;
  2464. char *name;
  2465. va_start(list, reg_class);
  2466. name = va_arg(list, char *);
  2467. while (name != NULL) {
  2468. reg = va_arg(list, int);
  2469. switch (reg_class) {
  2470. case CRT:
  2471. val = vga_rcrt(regbase, (unsigned char) reg);
  2472. break;
  2473. case SEQ:
  2474. val = vga_rseq(regbase, (unsigned char) reg);
  2475. break;
  2476. default:
  2477. /* should never occur */
  2478. assert(false);
  2479. break;
  2480. }
  2481. dev_dbg(info->device, "%8s = 0x%02X\n", name, val);
  2482. name = va_arg(list, char *);
  2483. }
  2484. va_end(list);
  2485. }
  2486. /**
  2487. * cirrusfb_dbg_reg_dump
  2488. * @base: If using newmmio, the newmmio base address, otherwise %NULL
  2489. *
  2490. * DESCRIPTION:
  2491. * Dumps a list of interesting VGA and CIRRUSFB registers. If @base is %NULL,
  2492. * old-style I/O ports are queried for information, otherwise MMIO is
  2493. * used at the given @base address to query the information.
  2494. */
  2495. static void cirrusfb_dbg_reg_dump(struct fb_info *info, caddr_t regbase)
  2496. {
  2497. dev_dbg(info->device, "VGA CRTC register dump:\n");
  2498. cirrusfb_dbg_print_regs(info, regbase, CRT,
  2499. "CR00", 0x00,
  2500. "CR01", 0x01,
  2501. "CR02", 0x02,
  2502. "CR03", 0x03,
  2503. "CR04", 0x04,
  2504. "CR05", 0x05,
  2505. "CR06", 0x06,
  2506. "CR07", 0x07,
  2507. "CR08", 0x08,
  2508. "CR09", 0x09,
  2509. "CR0A", 0x0A,
  2510. "CR0B", 0x0B,
  2511. "CR0C", 0x0C,
  2512. "CR0D", 0x0D,
  2513. "CR0E", 0x0E,
  2514. "CR0F", 0x0F,
  2515. "CR10", 0x10,
  2516. "CR11", 0x11,
  2517. "CR12", 0x12,
  2518. "CR13", 0x13,
  2519. "CR14", 0x14,
  2520. "CR15", 0x15,
  2521. "CR16", 0x16,
  2522. "CR17", 0x17,
  2523. "CR18", 0x18,
  2524. "CR22", 0x22,
  2525. "CR24", 0x24,
  2526. "CR26", 0x26,
  2527. "CR2D", 0x2D,
  2528. "CR2E", 0x2E,
  2529. "CR2F", 0x2F,
  2530. "CR30", 0x30,
  2531. "CR31", 0x31,
  2532. "CR32", 0x32,
  2533. "CR33", 0x33,
  2534. "CR34", 0x34,
  2535. "CR35", 0x35,
  2536. "CR36", 0x36,
  2537. "CR37", 0x37,
  2538. "CR38", 0x38,
  2539. "CR39", 0x39,
  2540. "CR3A", 0x3A,
  2541. "CR3B", 0x3B,
  2542. "CR3C", 0x3C,
  2543. "CR3D", 0x3D,
  2544. "CR3E", 0x3E,
  2545. "CR3F", 0x3F,
  2546. NULL);
  2547. dev_dbg(info->device, "\n");
  2548. dev_dbg(info->device, "VGA SEQ register dump:\n");
  2549. cirrusfb_dbg_print_regs(info, regbase, SEQ,
  2550. "SR00", 0x00,
  2551. "SR01", 0x01,
  2552. "SR02", 0x02,
  2553. "SR03", 0x03,
  2554. "SR04", 0x04,
  2555. "SR08", 0x08,
  2556. "SR09", 0x09,
  2557. "SR0A", 0x0A,
  2558. "SR0B", 0x0B,
  2559. "SR0D", 0x0D,
  2560. "SR10", 0x10,
  2561. "SR11", 0x11,
  2562. "SR12", 0x12,
  2563. "SR13", 0x13,
  2564. "SR14", 0x14,
  2565. "SR15", 0x15,
  2566. "SR16", 0x16,
  2567. "SR17", 0x17,
  2568. "SR18", 0x18,
  2569. "SR19", 0x19,
  2570. "SR1A", 0x1A,
  2571. "SR1B", 0x1B,
  2572. "SR1C", 0x1C,
  2573. "SR1D", 0x1D,
  2574. "SR1E", 0x1E,
  2575. "SR1F", 0x1F,
  2576. NULL);
  2577. dev_dbg(info->device, "\n");
  2578. }
  2579. #endif /* CIRRUSFB_DEBUG */