cirrusfb.c 86 KB

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