cirrusfb.c 84 KB

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