cirrusfb.c 76 KB

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