cirrusfb.c 81 KB

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