cirrusfb.c 85 KB

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