cirrusfb.c 77 KB

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