cirrusfb.c 79 KB

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