cirrusfb.c 81 KB

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