cirrusfb.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997
  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, /* 0x02000000 for 64 MiB boards */
  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 bool 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. if (zorro_resource_len(z) == 64 * MB_) {
  1956. /* Quirk for 64 MiB Picasso IV */
  1957. rambase += zcl->ramoffset;
  1958. }
  1959. } else {
  1960. struct zorro_dev *ram = zorro_find_device(zcl->ramid, NULL);
  1961. if (!ram || !zorro_resource_len(ram)) {
  1962. dev_err(info->device, "No video RAM found\n");
  1963. error = -ENODEV;
  1964. goto err_release_fb;
  1965. }
  1966. rambase = zorro_resource_start(ram);
  1967. ramsize = zorro_resource_len(ram);
  1968. if (zcl->ramid2 &&
  1969. (ram = zorro_find_device(zcl->ramid2, NULL))) {
  1970. if (zorro_resource_start(ram) != rambase + ramsize) {
  1971. dev_warn(info->device,
  1972. "Skipping non-contiguous RAM at %pR\n",
  1973. &ram->resource);
  1974. } else {
  1975. ramsize += zorro_resource_len(ram);
  1976. }
  1977. }
  1978. }
  1979. dev_info(info->device,
  1980. "%s board detected, REG at 0x%lx, %lu MiB RAM at 0x%lx\n",
  1981. cirrusfb_board_info[btype].name, regbase, ramsize / MB_,
  1982. rambase);
  1983. if (!zorro_request_device(z, "cirrusfb")) {
  1984. dev_err(info->device, "Cannot reserve %pR\n", &z->resource);
  1985. error = -EBUSY;
  1986. goto err_release_fb;
  1987. }
  1988. cinfo = info->par;
  1989. cinfo->btype = btype;
  1990. info->fix.mmio_start = regbase;
  1991. cinfo->regbase = regbase > 16 * MB_ ? ioremap(regbase, 64 * 1024)
  1992. : (caddr_t)ZTWO_VADDR(regbase);
  1993. if (!cinfo->regbase) {
  1994. dev_err(info->device, "Cannot map registers\n");
  1995. error = -EIO;
  1996. goto err_release_dev;
  1997. }
  1998. info->fix.smem_start = rambase;
  1999. info->screen_size = ramsize;
  2000. info->screen_base = rambase > 16 * MB_ ? ioremap(rambase, ramsize)
  2001. : (caddr_t)ZTWO_VADDR(rambase);
  2002. if (!info->screen_base) {
  2003. dev_err(info->device, "Cannot map video RAM\n");
  2004. error = -EIO;
  2005. goto err_unmap_reg;
  2006. }
  2007. cinfo->unmap = cirrusfb_zorro_unmap;
  2008. dev_info(info->device,
  2009. "Cirrus Logic chipset on Zorro bus, RAM (%lu MiB) at 0x%lx\n",
  2010. ramsize / MB_, rambase);
  2011. /* MCLK select etc. */
  2012. if (cirrusfb_board_info[btype].init_sr1f)
  2013. vga_wseq(cinfo->regbase, CL_SEQR1F,
  2014. cirrusfb_board_info[btype].sr1f);
  2015. error = cirrusfb_register(info);
  2016. if (error) {
  2017. dev_err(info->device, "Failed to register device, error %d\n",
  2018. error);
  2019. goto err_unmap_ram;
  2020. }
  2021. zorro_set_drvdata(z, info);
  2022. return 0;
  2023. err_unmap_ram:
  2024. if (rambase > 16 * MB_)
  2025. iounmap(info->screen_base);
  2026. err_unmap_reg:
  2027. if (regbase > 16 * MB_)
  2028. iounmap(cinfo->regbase);
  2029. err_release_dev:
  2030. zorro_release_device(z);
  2031. err_release_fb:
  2032. framebuffer_release(info);
  2033. return error;
  2034. }
  2035. void __devexit cirrusfb_zorro_unregister(struct zorro_dev *z)
  2036. {
  2037. struct fb_info *info = zorro_get_drvdata(z);
  2038. cirrusfb_cleanup(info);
  2039. zorro_set_drvdata(z, NULL);
  2040. }
  2041. static struct zorro_driver cirrusfb_zorro_driver = {
  2042. .name = "cirrusfb",
  2043. .id_table = cirrusfb_zorro_table,
  2044. .probe = cirrusfb_zorro_register,
  2045. .remove = __devexit_p(cirrusfb_zorro_unregister),
  2046. };
  2047. #endif /* CONFIG_ZORRO */
  2048. #ifndef MODULE
  2049. static int __init cirrusfb_setup(char *options)
  2050. {
  2051. char *this_opt;
  2052. if (!options || !*options)
  2053. return 0;
  2054. while ((this_opt = strsep(&options, ",")) != NULL) {
  2055. if (!*this_opt)
  2056. continue;
  2057. if (!strcmp(this_opt, "noaccel"))
  2058. noaccel = 1;
  2059. else if (!strncmp(this_opt, "mode:", 5))
  2060. mode_option = this_opt + 5;
  2061. else
  2062. mode_option = this_opt;
  2063. }
  2064. return 0;
  2065. }
  2066. #endif
  2067. /*
  2068. * Modularization
  2069. */
  2070. MODULE_AUTHOR("Copyright 1999,2000 Jeff Garzik <jgarzik@pobox.com>");
  2071. MODULE_DESCRIPTION("Accelerated FBDev driver for Cirrus Logic chips");
  2072. MODULE_LICENSE("GPL");
  2073. static int __init cirrusfb_init(void)
  2074. {
  2075. int error = 0;
  2076. #ifndef MODULE
  2077. char *option = NULL;
  2078. if (fb_get_options("cirrusfb", &option))
  2079. return -ENODEV;
  2080. cirrusfb_setup(option);
  2081. #endif
  2082. #ifdef CONFIG_ZORRO
  2083. error |= zorro_register_driver(&cirrusfb_zorro_driver);
  2084. #endif
  2085. #ifdef CONFIG_PCI
  2086. error |= pci_register_driver(&cirrusfb_pci_driver);
  2087. #endif
  2088. return error;
  2089. }
  2090. static void __exit cirrusfb_exit(void)
  2091. {
  2092. #ifdef CONFIG_PCI
  2093. pci_unregister_driver(&cirrusfb_pci_driver);
  2094. #endif
  2095. #ifdef CONFIG_ZORRO
  2096. zorro_unregister_driver(&cirrusfb_zorro_driver);
  2097. #endif
  2098. }
  2099. module_init(cirrusfb_init);
  2100. module_param(mode_option, charp, 0);
  2101. MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'");
  2102. module_param(noaccel, bool, 0);
  2103. MODULE_PARM_DESC(noaccel, "Disable acceleration");
  2104. #ifdef MODULE
  2105. module_exit(cirrusfb_exit);
  2106. #endif
  2107. /**********************************************************************/
  2108. /* about the following functions - I have used the same names for the */
  2109. /* functions as Markus Wild did in his Retina driver for NetBSD as */
  2110. /* they just made sense for this purpose. Apart from that, I wrote */
  2111. /* these functions myself. */
  2112. /**********************************************************************/
  2113. /*** WGen() - write into one of the external/general registers ***/
  2114. static void WGen(const struct cirrusfb_info *cinfo,
  2115. int regnum, unsigned char val)
  2116. {
  2117. unsigned long regofs = 0;
  2118. if (cinfo->btype == BT_PICASSO) {
  2119. /* Picasso II specific hack */
  2120. /* if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D ||
  2121. regnum == CL_VSSM2) */
  2122. if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D)
  2123. regofs = 0xfff;
  2124. }
  2125. vga_w(cinfo->regbase, regofs + regnum, val);
  2126. }
  2127. /*** RGen() - read out one of the external/general registers ***/
  2128. static unsigned char RGen(const struct cirrusfb_info *cinfo, int regnum)
  2129. {
  2130. unsigned long regofs = 0;
  2131. if (cinfo->btype == BT_PICASSO) {
  2132. /* Picasso II specific hack */
  2133. /* if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D ||
  2134. regnum == CL_VSSM2) */
  2135. if (regnum == VGA_PEL_IR || regnum == VGA_PEL_D)
  2136. regofs = 0xfff;
  2137. }
  2138. return vga_r(cinfo->regbase, regofs + regnum);
  2139. }
  2140. /*** AttrOn() - turn on VideoEnable for Attribute controller ***/
  2141. static void AttrOn(const struct cirrusfb_info *cinfo)
  2142. {
  2143. assert(cinfo != NULL);
  2144. if (vga_rcrt(cinfo->regbase, CL_CRT24) & 0x80) {
  2145. /* if we're just in "write value" mode, write back the */
  2146. /* same value as before to not modify anything */
  2147. vga_w(cinfo->regbase, VGA_ATT_IW,
  2148. vga_r(cinfo->regbase, VGA_ATT_R));
  2149. }
  2150. /* turn on video bit */
  2151. /* vga_w(cinfo->regbase, VGA_ATT_IW, 0x20); */
  2152. vga_w(cinfo->regbase, VGA_ATT_IW, 0x33);
  2153. /* dummy write on Reg0 to be on "write index" mode next time */
  2154. vga_w(cinfo->regbase, VGA_ATT_IW, 0x00);
  2155. }
  2156. /*** WHDR() - write into the Hidden DAC register ***/
  2157. /* as the HDR is the only extension register that requires special treatment
  2158. * (the other extension registers are accessible just like the "ordinary"
  2159. * registers of their functional group) here is a specialized routine for
  2160. * accessing the HDR
  2161. */
  2162. static void WHDR(const struct cirrusfb_info *cinfo, unsigned char val)
  2163. {
  2164. unsigned char dummy;
  2165. if (is_laguna(cinfo))
  2166. return;
  2167. if (cinfo->btype == BT_PICASSO) {
  2168. /* Klaus' hint for correct access to HDR on some boards */
  2169. /* first write 0 to pixel mask (3c6) */
  2170. WGen(cinfo, VGA_PEL_MSK, 0x00);
  2171. udelay(200);
  2172. /* next read dummy from pixel address (3c8) */
  2173. dummy = RGen(cinfo, VGA_PEL_IW);
  2174. udelay(200);
  2175. }
  2176. /* now do the usual stuff to access the HDR */
  2177. dummy = RGen(cinfo, VGA_PEL_MSK);
  2178. udelay(200);
  2179. dummy = RGen(cinfo, VGA_PEL_MSK);
  2180. udelay(200);
  2181. dummy = RGen(cinfo, VGA_PEL_MSK);
  2182. udelay(200);
  2183. dummy = RGen(cinfo, VGA_PEL_MSK);
  2184. udelay(200);
  2185. WGen(cinfo, VGA_PEL_MSK, val);
  2186. udelay(200);
  2187. if (cinfo->btype == BT_PICASSO) {
  2188. /* now first reset HDR access counter */
  2189. dummy = RGen(cinfo, VGA_PEL_IW);
  2190. udelay(200);
  2191. /* and at the end, restore the mask value */
  2192. /* ## is this mask always 0xff? */
  2193. WGen(cinfo, VGA_PEL_MSK, 0xff);
  2194. udelay(200);
  2195. }
  2196. }
  2197. /*** WSFR() - write to the "special function register" (SFR) ***/
  2198. static void WSFR(struct cirrusfb_info *cinfo, unsigned char val)
  2199. {
  2200. #ifdef CONFIG_ZORRO
  2201. assert(cinfo->regbase != NULL);
  2202. cinfo->SFR = val;
  2203. z_writeb(val, cinfo->regbase + 0x8000);
  2204. #endif
  2205. }
  2206. /* The Picasso has a second register for switching the monitor bit */
  2207. static void WSFR2(struct cirrusfb_info *cinfo, unsigned char val)
  2208. {
  2209. #ifdef CONFIG_ZORRO
  2210. /* writing an arbitrary value to this one causes the monitor switcher */
  2211. /* to flip to Amiga display */
  2212. assert(cinfo->regbase != NULL);
  2213. cinfo->SFR = val;
  2214. z_writeb(val, cinfo->regbase + 0x9000);
  2215. #endif
  2216. }
  2217. /*** WClut - set CLUT entry (range: 0..63) ***/
  2218. static void WClut(struct cirrusfb_info *cinfo, unsigned char regnum, unsigned char red,
  2219. unsigned char green, unsigned char blue)
  2220. {
  2221. unsigned int data = VGA_PEL_D;
  2222. /* address write mode register is not translated.. */
  2223. vga_w(cinfo->regbase, VGA_PEL_IW, regnum);
  2224. if (cinfo->btype == BT_PICASSO || cinfo->btype == BT_PICASSO4 ||
  2225. cinfo->btype == BT_ALPINE || cinfo->btype == BT_GD5480 ||
  2226. cinfo->btype == BT_SD64 || is_laguna(cinfo)) {
  2227. /* but DAC data register IS, at least for Picasso II */
  2228. if (cinfo->btype == BT_PICASSO)
  2229. data += 0xfff;
  2230. vga_w(cinfo->regbase, data, red);
  2231. vga_w(cinfo->regbase, data, green);
  2232. vga_w(cinfo->regbase, data, blue);
  2233. } else {
  2234. vga_w(cinfo->regbase, data, blue);
  2235. vga_w(cinfo->regbase, data, green);
  2236. vga_w(cinfo->regbase, data, red);
  2237. }
  2238. }
  2239. #if 0
  2240. /*** RClut - read CLUT entry (range 0..63) ***/
  2241. static void RClut(struct cirrusfb_info *cinfo, unsigned char regnum, unsigned char *red,
  2242. unsigned char *green, unsigned char *blue)
  2243. {
  2244. unsigned int data = VGA_PEL_D;
  2245. vga_w(cinfo->regbase, VGA_PEL_IR, regnum);
  2246. if (cinfo->btype == BT_PICASSO || cinfo->btype == BT_PICASSO4 ||
  2247. cinfo->btype == BT_ALPINE || cinfo->btype == BT_GD5480) {
  2248. if (cinfo->btype == BT_PICASSO)
  2249. data += 0xfff;
  2250. *red = vga_r(cinfo->regbase, data);
  2251. *green = vga_r(cinfo->regbase, data);
  2252. *blue = vga_r(cinfo->regbase, data);
  2253. } else {
  2254. *blue = vga_r(cinfo->regbase, data);
  2255. *green = vga_r(cinfo->regbase, data);
  2256. *red = vga_r(cinfo->regbase, data);
  2257. }
  2258. }
  2259. #endif
  2260. /*******************************************************************
  2261. cirrusfb_WaitBLT()
  2262. Wait for the BitBLT engine to complete a possible earlier job
  2263. *********************************************************************/
  2264. /* FIXME: use interrupts instead */
  2265. static void cirrusfb_WaitBLT(u8 __iomem *regbase)
  2266. {
  2267. while (vga_rgfx(regbase, CL_GR31) & 0x08)
  2268. cpu_relax();
  2269. }
  2270. /*******************************************************************
  2271. cirrusfb_BitBLT()
  2272. perform accelerated "scrolling"
  2273. ********************************************************************/
  2274. static void cirrusfb_set_blitter(u8 __iomem *regbase,
  2275. u_short nwidth, u_short nheight,
  2276. u_long nsrc, u_long ndest,
  2277. u_short bltmode, u_short line_length)
  2278. {
  2279. /* pitch: set to line_length */
  2280. /* dest pitch low */
  2281. vga_wgfx(regbase, CL_GR24, line_length & 0xff);
  2282. /* dest pitch hi */
  2283. vga_wgfx(regbase, CL_GR25, line_length >> 8);
  2284. /* source pitch low */
  2285. vga_wgfx(regbase, CL_GR26, line_length & 0xff);
  2286. /* source pitch hi */
  2287. vga_wgfx(regbase, CL_GR27, line_length >> 8);
  2288. /* BLT width: actual number of pixels - 1 */
  2289. /* BLT width low */
  2290. vga_wgfx(regbase, CL_GR20, nwidth & 0xff);
  2291. /* BLT width hi */
  2292. vga_wgfx(regbase, CL_GR21, nwidth >> 8);
  2293. /* BLT height: actual number of lines -1 */
  2294. /* BLT height low */
  2295. vga_wgfx(regbase, CL_GR22, nheight & 0xff);
  2296. /* BLT width hi */
  2297. vga_wgfx(regbase, CL_GR23, nheight >> 8);
  2298. /* BLT destination */
  2299. /* BLT dest low */
  2300. vga_wgfx(regbase, CL_GR28, (u_char) (ndest & 0xff));
  2301. /* BLT dest mid */
  2302. vga_wgfx(regbase, CL_GR29, (u_char) (ndest >> 8));
  2303. /* BLT dest hi */
  2304. vga_wgfx(regbase, CL_GR2A, (u_char) (ndest >> 16));
  2305. /* BLT source */
  2306. /* BLT src low */
  2307. vga_wgfx(regbase, CL_GR2C, (u_char) (nsrc & 0xff));
  2308. /* BLT src mid */
  2309. vga_wgfx(regbase, CL_GR2D, (u_char) (nsrc >> 8));
  2310. /* BLT src hi */
  2311. vga_wgfx(regbase, CL_GR2E, (u_char) (nsrc >> 16));
  2312. /* BLT mode */
  2313. vga_wgfx(regbase, CL_GR30, bltmode); /* BLT mode */
  2314. /* BLT ROP: SrcCopy */
  2315. vga_wgfx(regbase, CL_GR32, 0x0d); /* BLT ROP */
  2316. /* and finally: GO! */
  2317. vga_wgfx(regbase, CL_GR31, 0x02); /* BLT Start/status */
  2318. }
  2319. /*******************************************************************
  2320. cirrusfb_BitBLT()
  2321. perform accelerated "scrolling"
  2322. ********************************************************************/
  2323. static void cirrusfb_BitBLT(u8 __iomem *regbase, int bits_per_pixel,
  2324. u_short curx, u_short cury,
  2325. u_short destx, u_short desty,
  2326. u_short width, u_short height,
  2327. u_short line_length)
  2328. {
  2329. u_short nwidth = width - 1;
  2330. u_short nheight = height - 1;
  2331. u_long nsrc, ndest;
  2332. u_char bltmode;
  2333. bltmode = 0x00;
  2334. /* if source adr < dest addr, do the Blt backwards */
  2335. if (cury <= desty) {
  2336. if (cury == desty) {
  2337. /* if src and dest are on the same line, check x */
  2338. if (curx < destx)
  2339. bltmode |= 0x01;
  2340. } else
  2341. bltmode |= 0x01;
  2342. }
  2343. /* standard case: forward blitting */
  2344. nsrc = (cury * line_length) + curx;
  2345. ndest = (desty * line_length) + destx;
  2346. if (bltmode) {
  2347. /* this means start addresses are at the end,
  2348. * counting backwards
  2349. */
  2350. nsrc += nheight * line_length + nwidth;
  2351. ndest += nheight * line_length + nwidth;
  2352. }
  2353. cirrusfb_WaitBLT(regbase);
  2354. cirrusfb_set_blitter(regbase, nwidth, nheight,
  2355. nsrc, ndest, bltmode, line_length);
  2356. }
  2357. /*******************************************************************
  2358. cirrusfb_RectFill()
  2359. perform accelerated rectangle fill
  2360. ********************************************************************/
  2361. static void cirrusfb_RectFill(u8 __iomem *regbase, int bits_per_pixel,
  2362. u_short x, u_short y, u_short width, u_short height,
  2363. u32 fg_color, u32 bg_color, u_short line_length,
  2364. u_char blitmode)
  2365. {
  2366. u_long ndest = (y * line_length) + x;
  2367. u_char op;
  2368. cirrusfb_WaitBLT(regbase);
  2369. /* This is a ColorExpand Blt, using the */
  2370. /* same color for foreground and background */
  2371. vga_wgfx(regbase, VGA_GFX_SR_VALUE, bg_color);
  2372. vga_wgfx(regbase, VGA_GFX_SR_ENABLE, fg_color);
  2373. op = 0x80;
  2374. if (bits_per_pixel >= 16) {
  2375. vga_wgfx(regbase, CL_GR10, bg_color >> 8);
  2376. vga_wgfx(regbase, CL_GR11, fg_color >> 8);
  2377. op = 0x90;
  2378. }
  2379. if (bits_per_pixel >= 24) {
  2380. vga_wgfx(regbase, CL_GR12, bg_color >> 16);
  2381. vga_wgfx(regbase, CL_GR13, fg_color >> 16);
  2382. op = 0xa0;
  2383. }
  2384. if (bits_per_pixel == 32) {
  2385. vga_wgfx(regbase, CL_GR14, bg_color >> 24);
  2386. vga_wgfx(regbase, CL_GR15, fg_color >> 24);
  2387. op = 0xb0;
  2388. }
  2389. cirrusfb_set_blitter(regbase, width - 1, height - 1,
  2390. 0, ndest, op | blitmode, line_length);
  2391. }
  2392. /**************************************************************************
  2393. * bestclock() - determine closest possible clock lower(?) than the
  2394. * desired pixel clock
  2395. **************************************************************************/
  2396. static void bestclock(long freq, int *nom, int *den, int *div)
  2397. {
  2398. int n, d;
  2399. long h, diff;
  2400. assert(nom != NULL);
  2401. assert(den != NULL);
  2402. assert(div != NULL);
  2403. *nom = 0;
  2404. *den = 0;
  2405. *div = 0;
  2406. if (freq < 8000)
  2407. freq = 8000;
  2408. diff = freq;
  2409. for (n = 32; n < 128; n++) {
  2410. int s = 0;
  2411. d = (14318 * n) / freq;
  2412. if ((d >= 7) && (d <= 63)) {
  2413. int temp = d;
  2414. if (temp > 31) {
  2415. s = 1;
  2416. temp >>= 1;
  2417. }
  2418. h = ((14318 * n) / temp) >> s;
  2419. h = h > freq ? h - freq : freq - h;
  2420. if (h < diff) {
  2421. diff = h;
  2422. *nom = n;
  2423. *den = temp;
  2424. *div = s;
  2425. }
  2426. }
  2427. d++;
  2428. if ((d >= 7) && (d <= 63)) {
  2429. if (d > 31) {
  2430. s = 1;
  2431. d >>= 1;
  2432. }
  2433. h = ((14318 * n) / d) >> s;
  2434. h = h > freq ? h - freq : freq - h;
  2435. if (h < diff) {
  2436. diff = h;
  2437. *nom = n;
  2438. *den = d;
  2439. *div = s;
  2440. }
  2441. }
  2442. }
  2443. }
  2444. /* -------------------------------------------------------------------------
  2445. *
  2446. * debugging functions
  2447. *
  2448. * -------------------------------------------------------------------------
  2449. */
  2450. #ifdef CIRRUSFB_DEBUG
  2451. /**
  2452. * cirrusfb_dbg_print_regs
  2453. * @base: If using newmmio, the newmmio base address, otherwise %NULL
  2454. * @reg_class: type of registers to read: %CRT, or %SEQ
  2455. *
  2456. * DESCRIPTION:
  2457. * Dumps the given list of VGA CRTC registers. If @base is %NULL,
  2458. * old-style I/O ports are queried for information, otherwise MMIO is
  2459. * used at the given @base address to query the information.
  2460. */
  2461. static void cirrusfb_dbg_print_regs(struct fb_info *info,
  2462. caddr_t regbase,
  2463. enum cirrusfb_dbg_reg_class reg_class, ...)
  2464. {
  2465. va_list list;
  2466. unsigned char val = 0;
  2467. unsigned reg;
  2468. char *name;
  2469. va_start(list, reg_class);
  2470. name = va_arg(list, char *);
  2471. while (name != NULL) {
  2472. reg = va_arg(list, int);
  2473. switch (reg_class) {
  2474. case CRT:
  2475. val = vga_rcrt(regbase, (unsigned char) reg);
  2476. break;
  2477. case SEQ:
  2478. val = vga_rseq(regbase, (unsigned char) reg);
  2479. break;
  2480. default:
  2481. /* should never occur */
  2482. assert(false);
  2483. break;
  2484. }
  2485. dev_dbg(info->device, "%8s = 0x%02X\n", name, val);
  2486. name = va_arg(list, char *);
  2487. }
  2488. va_end(list);
  2489. }
  2490. /**
  2491. * cirrusfb_dbg_reg_dump
  2492. * @base: If using newmmio, the newmmio base address, otherwise %NULL
  2493. *
  2494. * DESCRIPTION:
  2495. * Dumps a list of interesting VGA and CIRRUSFB registers. If @base is %NULL,
  2496. * old-style I/O ports are queried for information, otherwise MMIO is
  2497. * used at the given @base address to query the information.
  2498. */
  2499. static void cirrusfb_dbg_reg_dump(struct fb_info *info, caddr_t regbase)
  2500. {
  2501. dev_dbg(info->device, "VGA CRTC register dump:\n");
  2502. cirrusfb_dbg_print_regs(info, regbase, CRT,
  2503. "CR00", 0x00,
  2504. "CR01", 0x01,
  2505. "CR02", 0x02,
  2506. "CR03", 0x03,
  2507. "CR04", 0x04,
  2508. "CR05", 0x05,
  2509. "CR06", 0x06,
  2510. "CR07", 0x07,
  2511. "CR08", 0x08,
  2512. "CR09", 0x09,
  2513. "CR0A", 0x0A,
  2514. "CR0B", 0x0B,
  2515. "CR0C", 0x0C,
  2516. "CR0D", 0x0D,
  2517. "CR0E", 0x0E,
  2518. "CR0F", 0x0F,
  2519. "CR10", 0x10,
  2520. "CR11", 0x11,
  2521. "CR12", 0x12,
  2522. "CR13", 0x13,
  2523. "CR14", 0x14,
  2524. "CR15", 0x15,
  2525. "CR16", 0x16,
  2526. "CR17", 0x17,
  2527. "CR18", 0x18,
  2528. "CR22", 0x22,
  2529. "CR24", 0x24,
  2530. "CR26", 0x26,
  2531. "CR2D", 0x2D,
  2532. "CR2E", 0x2E,
  2533. "CR2F", 0x2F,
  2534. "CR30", 0x30,
  2535. "CR31", 0x31,
  2536. "CR32", 0x32,
  2537. "CR33", 0x33,
  2538. "CR34", 0x34,
  2539. "CR35", 0x35,
  2540. "CR36", 0x36,
  2541. "CR37", 0x37,
  2542. "CR38", 0x38,
  2543. "CR39", 0x39,
  2544. "CR3A", 0x3A,
  2545. "CR3B", 0x3B,
  2546. "CR3C", 0x3C,
  2547. "CR3D", 0x3D,
  2548. "CR3E", 0x3E,
  2549. "CR3F", 0x3F,
  2550. NULL);
  2551. dev_dbg(info->device, "\n");
  2552. dev_dbg(info->device, "VGA SEQ register dump:\n");
  2553. cirrusfb_dbg_print_regs(info, regbase, SEQ,
  2554. "SR00", 0x00,
  2555. "SR01", 0x01,
  2556. "SR02", 0x02,
  2557. "SR03", 0x03,
  2558. "SR04", 0x04,
  2559. "SR08", 0x08,
  2560. "SR09", 0x09,
  2561. "SR0A", 0x0A,
  2562. "SR0B", 0x0B,
  2563. "SR0D", 0x0D,
  2564. "SR10", 0x10,
  2565. "SR11", 0x11,
  2566. "SR12", 0x12,
  2567. "SR13", 0x13,
  2568. "SR14", 0x14,
  2569. "SR15", 0x15,
  2570. "SR16", 0x16,
  2571. "SR17", 0x17,
  2572. "SR18", 0x18,
  2573. "SR19", 0x19,
  2574. "SR1A", 0x1A,
  2575. "SR1B", 0x1B,
  2576. "SR1C", 0x1C,
  2577. "SR1D", 0x1D,
  2578. "SR1E", 0x1E,
  2579. "SR1F", 0x1F,
  2580. NULL);
  2581. dev_dbg(info->device, "\n");
  2582. }
  2583. #endif /* CIRRUSFB_DEBUG */