cirrusfb.c 77 KB

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