cirrusfb.c 81 KB

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