cirrusfb.c 76 KB

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