cirrusfb.c 83 KB

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