cirrusfb.c 76 KB

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