cirrusfb.c 76 KB

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