cirrusfb.c 76 KB

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