cirrusfb.c 76 KB

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