cirrusfb.c 76 KB

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