cirrusfb.c 81 KB

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