cirrusfb.c 85 KB

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