cirrusfb.c 85 KB

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