imsttfb.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623
  1. /*
  2. * drivers/video/imsttfb.c -- frame buffer device for IMS TwinTurbo
  3. *
  4. * This file is derived from the powermac console "imstt" driver:
  5. * Copyright (C) 1997 Sigurdur Asgeirsson
  6. * With additional hacking by Jeffrey Kuskin (jsk@mojave.stanford.edu)
  7. * Modified by Danilo Beuche 1998
  8. * Some register values added by Damien Doligez, INRIA Rocquencourt
  9. * Various cleanups by Paul Mundt (lethal@chaoticdreams.org)
  10. *
  11. * This file was written by Ryan Nielsen (ran@krazynet.com)
  12. * Most of the frame buffer device stuff was copied from atyfb.c
  13. *
  14. * This file is subject to the terms and conditions of the GNU General Public
  15. * License. See the file COPYING in the main directory of this archive for
  16. * more details.
  17. */
  18. #include <linux/module.h>
  19. #include <linux/kernel.h>
  20. #include <linux/errno.h>
  21. #include <linux/string.h>
  22. #include <linux/mm.h>
  23. #include <linux/vmalloc.h>
  24. #include <linux/delay.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/fb.h>
  27. #include <linux/init.h>
  28. #include <linux/pci.h>
  29. #include <asm/io.h>
  30. #include <linux/uaccess.h>
  31. #if defined(CONFIG_PPC)
  32. #include <linux/nvram.h>
  33. #include <asm/prom.h>
  34. #include <asm/pci-bridge.h>
  35. #include "macmodes.h"
  36. #endif
  37. #ifndef __powerpc__
  38. #define eieio() /* Enforce In-order Execution of I/O */
  39. #endif
  40. /* TwinTurbo (Cosmo) registers */
  41. enum {
  42. S1SA = 0, /* 0x00 */
  43. S2SA = 1, /* 0x04 */
  44. SP = 2, /* 0x08 */
  45. DSA = 3, /* 0x0C */
  46. CNT = 4, /* 0x10 */
  47. DP_OCTL = 5, /* 0x14 */
  48. CLR = 6, /* 0x18 */
  49. BI = 8, /* 0x20 */
  50. MBC = 9, /* 0x24 */
  51. BLTCTL = 10, /* 0x28 */
  52. /* Scan Timing Generator Registers */
  53. HES = 12, /* 0x30 */
  54. HEB = 13, /* 0x34 */
  55. HSB = 14, /* 0x38 */
  56. HT = 15, /* 0x3C */
  57. VES = 16, /* 0x40 */
  58. VEB = 17, /* 0x44 */
  59. VSB = 18, /* 0x48 */
  60. VT = 19, /* 0x4C */
  61. HCIV = 20, /* 0x50 */
  62. VCIV = 21, /* 0x54 */
  63. TCDR = 22, /* 0x58 */
  64. VIL = 23, /* 0x5C */
  65. STGCTL = 24, /* 0x60 */
  66. /* Screen Refresh Generator Registers */
  67. SSR = 25, /* 0x64 */
  68. HRIR = 26, /* 0x68 */
  69. SPR = 27, /* 0x6C */
  70. CMR = 28, /* 0x70 */
  71. SRGCTL = 29, /* 0x74 */
  72. /* RAM Refresh Generator Registers */
  73. RRCIV = 30, /* 0x78 */
  74. RRSC = 31, /* 0x7C */
  75. RRCR = 34, /* 0x88 */
  76. /* System Registers */
  77. GIOE = 32, /* 0x80 */
  78. GIO = 33, /* 0x84 */
  79. SCR = 35, /* 0x8C */
  80. SSTATUS = 36, /* 0x90 */
  81. PRC = 37, /* 0x94 */
  82. #if 0
  83. /* PCI Registers */
  84. DVID = 0x00000000L,
  85. SC = 0x00000004L,
  86. CCR = 0x00000008L,
  87. OG = 0x0000000CL,
  88. BARM = 0x00000010L,
  89. BARER = 0x00000030L,
  90. #endif
  91. };
  92. /* IBM 624 RAMDAC Direct Registers */
  93. enum {
  94. PADDRW = 0x00,
  95. PDATA = 0x04,
  96. PPMASK = 0x08,
  97. PADDRR = 0x0c,
  98. PIDXLO = 0x10,
  99. PIDXHI = 0x14,
  100. PIDXDATA= 0x18,
  101. PIDXCTL = 0x1c
  102. };
  103. /* IBM 624 RAMDAC Indirect Registers */
  104. enum {
  105. CLKCTL = 0x02, /* (0x01) Miscellaneous Clock Control */
  106. SYNCCTL = 0x03, /* (0x00) Sync Control */
  107. HSYNCPOS = 0x04, /* (0x00) Horizontal Sync Position */
  108. PWRMNGMT = 0x05, /* (0x00) Power Management */
  109. DACOP = 0x06, /* (0x02) DAC Operation */
  110. PALETCTL = 0x07, /* (0x00) Palette Control */
  111. SYSCLKCTL = 0x08, /* (0x01) System Clock Control */
  112. PIXFMT = 0x0a, /* () Pixel Format [bpp >> 3 + 2] */
  113. BPP8 = 0x0b, /* () 8 Bits/Pixel Control */
  114. BPP16 = 0x0c, /* () 16 Bits/Pixel Control [bit 1=1 for 565] */
  115. BPP24 = 0x0d, /* () 24 Bits/Pixel Control */
  116. BPP32 = 0x0e, /* () 32 Bits/Pixel Control */
  117. PIXCTL1 = 0x10, /* (0x05) Pixel PLL Control 1 */
  118. PIXCTL2 = 0x11, /* (0x00) Pixel PLL Control 2 */
  119. SYSCLKN = 0x15, /* () System Clock N (System PLL Reference Divider) */
  120. SYSCLKM = 0x16, /* () System Clock M (System PLL VCO Divider) */
  121. SYSCLKP = 0x17, /* () System Clock P */
  122. SYSCLKC = 0x18, /* () System Clock C */
  123. /*
  124. * Dot clock rate is 20MHz * (m + 1) / ((n + 1) * (p ? 2 * p : 1)
  125. * c is charge pump bias which depends on the VCO frequency
  126. */
  127. PIXM0 = 0x20, /* () Pixel M 0 */
  128. PIXN0 = 0x21, /* () Pixel N 0 */
  129. PIXP0 = 0x22, /* () Pixel P 0 */
  130. PIXC0 = 0x23, /* () Pixel C 0 */
  131. CURSCTL = 0x30, /* (0x00) Cursor Control */
  132. CURSXLO = 0x31, /* () Cursor X position, low 8 bits */
  133. CURSXHI = 0x32, /* () Cursor X position, high 8 bits */
  134. CURSYLO = 0x33, /* () Cursor Y position, low 8 bits */
  135. CURSYHI = 0x34, /* () Cursor Y position, high 8 bits */
  136. CURSHOTX = 0x35, /* () Cursor Hot Spot X */
  137. CURSHOTY = 0x36, /* () Cursor Hot Spot Y */
  138. CURSACCTL = 0x37, /* () Advanced Cursor Control Enable */
  139. CURSACATTR = 0x38, /* () Advanced Cursor Attribute */
  140. CURS1R = 0x40, /* () Cursor 1 Red */
  141. CURS1G = 0x41, /* () Cursor 1 Green */
  142. CURS1B = 0x42, /* () Cursor 1 Blue */
  143. CURS2R = 0x43, /* () Cursor 2 Red */
  144. CURS2G = 0x44, /* () Cursor 2 Green */
  145. CURS2B = 0x45, /* () Cursor 2 Blue */
  146. CURS3R = 0x46, /* () Cursor 3 Red */
  147. CURS3G = 0x47, /* () Cursor 3 Green */
  148. CURS3B = 0x48, /* () Cursor 3 Blue */
  149. BORDR = 0x60, /* () Border Color Red */
  150. BORDG = 0x61, /* () Border Color Green */
  151. BORDB = 0x62, /* () Border Color Blue */
  152. MISCTL1 = 0x70, /* (0x00) Miscellaneous Control 1 */
  153. MISCTL2 = 0x71, /* (0x00) Miscellaneous Control 2 */
  154. MISCTL3 = 0x72, /* (0x00) Miscellaneous Control 3 */
  155. KEYCTL = 0x78 /* (0x00) Key Control/DB Operation */
  156. };
  157. /* TI TVP 3030 RAMDAC Direct Registers */
  158. enum {
  159. TVPADDRW = 0x00, /* 0 Palette/Cursor RAM Write Address/Index */
  160. TVPPDATA = 0x04, /* 1 Palette Data RAM Data */
  161. TVPPMASK = 0x08, /* 2 Pixel Read-Mask */
  162. TVPPADRR = 0x0c, /* 3 Palette/Cursor RAM Read Address */
  163. TVPCADRW = 0x10, /* 4 Cursor/Overscan Color Write Address */
  164. TVPCDATA = 0x14, /* 5 Cursor/Overscan Color Data */
  165. /* 6 reserved */
  166. TVPCADRR = 0x1c, /* 7 Cursor/Overscan Color Read Address */
  167. /* 8 reserved */
  168. TVPDCCTL = 0x24, /* 9 Direct Cursor Control */
  169. TVPIDATA = 0x28, /* 10 Index Data */
  170. TVPCRDAT = 0x2c, /* 11 Cursor RAM Data */
  171. TVPCXPOL = 0x30, /* 12 Cursor-Position X LSB */
  172. TVPCXPOH = 0x34, /* 13 Cursor-Position X MSB */
  173. TVPCYPOL = 0x38, /* 14 Cursor-Position Y LSB */
  174. TVPCYPOH = 0x3c, /* 15 Cursor-Position Y MSB */
  175. };
  176. /* TI TVP 3030 RAMDAC Indirect Registers */
  177. enum {
  178. TVPIRREV = 0x01, /* Silicon Revision [RO] */
  179. TVPIRICC = 0x06, /* Indirect Cursor Control (0x00) */
  180. TVPIRBRC = 0x07, /* Byte Router Control (0xe4) */
  181. TVPIRLAC = 0x0f, /* Latch Control (0x06) */
  182. TVPIRTCC = 0x18, /* True Color Control (0x80) */
  183. TVPIRMXC = 0x19, /* Multiplex Control (0x98) */
  184. TVPIRCLS = 0x1a, /* Clock Selection (0x07) */
  185. TVPIRPPG = 0x1c, /* Palette Page (0x00) */
  186. TVPIRGEC = 0x1d, /* General Control (0x00) */
  187. TVPIRMIC = 0x1e, /* Miscellaneous Control (0x00) */
  188. TVPIRPLA = 0x2c, /* PLL Address */
  189. TVPIRPPD = 0x2d, /* Pixel Clock PLL Data */
  190. TVPIRMPD = 0x2e, /* Memory Clock PLL Data */
  191. TVPIRLPD = 0x2f, /* Loop Clock PLL Data */
  192. TVPIRCKL = 0x30, /* Color-Key Overlay Low */
  193. TVPIRCKH = 0x31, /* Color-Key Overlay High */
  194. TVPIRCRL = 0x32, /* Color-Key Red Low */
  195. TVPIRCRH = 0x33, /* Color-Key Red High */
  196. TVPIRCGL = 0x34, /* Color-Key Green Low */
  197. TVPIRCGH = 0x35, /* Color-Key Green High */
  198. TVPIRCBL = 0x36, /* Color-Key Blue Low */
  199. TVPIRCBH = 0x37, /* Color-Key Blue High */
  200. TVPIRCKC = 0x38, /* Color-Key Control (0x00) */
  201. TVPIRMLC = 0x39, /* MCLK/Loop Clock Control (0x18) */
  202. TVPIRSEN = 0x3a, /* Sense Test (0x00) */
  203. TVPIRTMD = 0x3b, /* Test Mode Data */
  204. TVPIRRML = 0x3c, /* CRC Remainder LSB [RO] */
  205. TVPIRRMM = 0x3d, /* CRC Remainder MSB [RO] */
  206. TVPIRRMS = 0x3e, /* CRC Bit Select [WO] */
  207. TVPIRDID = 0x3f, /* Device ID [RO] (0x30) */
  208. TVPIRRES = 0xff /* Software Reset [WO] */
  209. };
  210. struct initvalues {
  211. __u8 addr, value;
  212. };
  213. static struct initvalues ibm_initregs[] = {
  214. { CLKCTL, 0x21 },
  215. { SYNCCTL, 0x00 },
  216. { HSYNCPOS, 0x00 },
  217. { PWRMNGMT, 0x00 },
  218. { DACOP, 0x02 },
  219. { PALETCTL, 0x00 },
  220. { SYSCLKCTL, 0x01 },
  221. /*
  222. * Note that colors in X are correct only if all video data is
  223. * passed through the palette in the DAC. That is, "indirect
  224. * color" must be configured. This is the case for the IBM DAC
  225. * used in the 2MB and 4MB cards, at least.
  226. */
  227. { BPP8, 0x00 },
  228. { BPP16, 0x01 },
  229. { BPP24, 0x00 },
  230. { BPP32, 0x00 },
  231. { PIXCTL1, 0x05 },
  232. { PIXCTL2, 0x00 },
  233. { SYSCLKN, 0x08 },
  234. { SYSCLKM, 0x4f },
  235. { SYSCLKP, 0x00 },
  236. { SYSCLKC, 0x00 },
  237. { CURSCTL, 0x00 },
  238. { CURSACCTL, 0x01 },
  239. { CURSACATTR, 0xa8 },
  240. { CURS1R, 0xff },
  241. { CURS1G, 0xff },
  242. { CURS1B, 0xff },
  243. { CURS2R, 0xff },
  244. { CURS2G, 0xff },
  245. { CURS2B, 0xff },
  246. { CURS3R, 0xff },
  247. { CURS3G, 0xff },
  248. { CURS3B, 0xff },
  249. { BORDR, 0xff },
  250. { BORDG, 0xff },
  251. { BORDB, 0xff },
  252. { MISCTL1, 0x01 },
  253. { MISCTL2, 0x45 },
  254. { MISCTL3, 0x00 },
  255. { KEYCTL, 0x00 }
  256. };
  257. static struct initvalues tvp_initregs[] = {
  258. { TVPIRICC, 0x00 },
  259. { TVPIRBRC, 0xe4 },
  260. { TVPIRLAC, 0x06 },
  261. { TVPIRTCC, 0x80 },
  262. { TVPIRMXC, 0x4d },
  263. { TVPIRCLS, 0x05 },
  264. { TVPIRPPG, 0x00 },
  265. { TVPIRGEC, 0x00 },
  266. { TVPIRMIC, 0x08 },
  267. { TVPIRCKL, 0xff },
  268. { TVPIRCKH, 0xff },
  269. { TVPIRCRL, 0xff },
  270. { TVPIRCRH, 0xff },
  271. { TVPIRCGL, 0xff },
  272. { TVPIRCGH, 0xff },
  273. { TVPIRCBL, 0xff },
  274. { TVPIRCBH, 0xff },
  275. { TVPIRCKC, 0x00 },
  276. { TVPIRPLA, 0x00 },
  277. { TVPIRPPD, 0xc0 },
  278. { TVPIRPPD, 0xd5 },
  279. { TVPIRPPD, 0xea },
  280. { TVPIRPLA, 0x00 },
  281. { TVPIRMPD, 0xb9 },
  282. { TVPIRMPD, 0x3a },
  283. { TVPIRMPD, 0xb1 },
  284. { TVPIRPLA, 0x00 },
  285. { TVPIRLPD, 0xc1 },
  286. { TVPIRLPD, 0x3d },
  287. { TVPIRLPD, 0xf3 },
  288. };
  289. struct imstt_regvals {
  290. __u32 pitch;
  291. __u16 hes, heb, hsb, ht, ves, veb, vsb, vt, vil;
  292. __u8 pclk_m, pclk_n, pclk_p;
  293. /* Values of the tvp which change depending on colormode x resolution */
  294. __u8 mlc[3]; /* Memory Loop Config 0x39 */
  295. __u8 lckl_p[3]; /* P value of LCKL PLL */
  296. };
  297. struct imstt_par {
  298. struct imstt_regvals init;
  299. __u32 __iomem *dc_regs;
  300. unsigned long cmap_regs_phys;
  301. __u8 *cmap_regs;
  302. __u32 ramdac;
  303. __u32 palette[16];
  304. };
  305. enum {
  306. IBM = 0,
  307. TVP = 1
  308. };
  309. #define USE_NV_MODES 1
  310. #define INIT_BPP 8
  311. #define INIT_XRES 640
  312. #define INIT_YRES 480
  313. static int inverse = 0;
  314. static char fontname[40] __initdata = { 0 };
  315. #if defined(CONFIG_PPC)
  316. static signed char init_vmode = -1, init_cmode = -1;
  317. #endif
  318. static struct imstt_regvals tvp_reg_init_2 = {
  319. 512,
  320. 0x0002, 0x0006, 0x0026, 0x0028, 0x0003, 0x0016, 0x0196, 0x0197, 0x0196,
  321. 0xec, 0x2a, 0xf3,
  322. { 0x3c, 0x3b, 0x39 }, { 0xf3, 0xf3, 0xf3 }
  323. };
  324. static struct imstt_regvals tvp_reg_init_6 = {
  325. 640,
  326. 0x0004, 0x0009, 0x0031, 0x0036, 0x0003, 0x002a, 0x020a, 0x020d, 0x020a,
  327. 0xef, 0x2e, 0xb2,
  328. { 0x39, 0x39, 0x38 }, { 0xf3, 0xf3, 0xf3 }
  329. };
  330. static struct imstt_regvals tvp_reg_init_12 = {
  331. 800,
  332. 0x0005, 0x000e, 0x0040, 0x0042, 0x0003, 0x018, 0x270, 0x271, 0x270,
  333. 0xf6, 0x2e, 0xf2,
  334. { 0x3a, 0x39, 0x38 }, { 0xf3, 0xf3, 0xf3 }
  335. };
  336. static struct imstt_regvals tvp_reg_init_13 = {
  337. 832,
  338. 0x0004, 0x0011, 0x0045, 0x0048, 0x0003, 0x002a, 0x029a, 0x029b, 0x0000,
  339. 0xfe, 0x3e, 0xf1,
  340. { 0x39, 0x38, 0x38 }, { 0xf3, 0xf3, 0xf2 }
  341. };
  342. static struct imstt_regvals tvp_reg_init_17 = {
  343. 1024,
  344. 0x0006, 0x0210, 0x0250, 0x0053, 0x1003, 0x0021, 0x0321, 0x0324, 0x0000,
  345. 0xfc, 0x3a, 0xf1,
  346. { 0x39, 0x38, 0x38 }, { 0xf3, 0xf3, 0xf2 }
  347. };
  348. static struct imstt_regvals tvp_reg_init_18 = {
  349. 1152,
  350. 0x0009, 0x0011, 0x059, 0x5b, 0x0003, 0x0031, 0x0397, 0x039a, 0x0000,
  351. 0xfd, 0x3a, 0xf1,
  352. { 0x39, 0x38, 0x38 }, { 0xf3, 0xf3, 0xf2 }
  353. };
  354. static struct imstt_regvals tvp_reg_init_19 = {
  355. 1280,
  356. 0x0009, 0x0016, 0x0066, 0x0069, 0x0003, 0x0027, 0x03e7, 0x03e8, 0x03e7,
  357. 0xf7, 0x36, 0xf0,
  358. { 0x38, 0x38, 0x38 }, { 0xf3, 0xf2, 0xf1 }
  359. };
  360. static struct imstt_regvals tvp_reg_init_20 = {
  361. 1280,
  362. 0x0009, 0x0018, 0x0068, 0x006a, 0x0003, 0x0029, 0x0429, 0x042a, 0x0000,
  363. 0xf0, 0x2d, 0xf0,
  364. { 0x38, 0x38, 0x38 }, { 0xf3, 0xf2, 0xf1 }
  365. };
  366. /*
  367. * PCI driver prototypes
  368. */
  369. static int imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
  370. static void imsttfb_remove(struct pci_dev *pdev);
  371. /*
  372. * Register access
  373. */
  374. static inline u32 read_reg_le32(volatile u32 __iomem *base, int regindex)
  375. {
  376. #ifdef __powerpc__
  377. return in_le32(base + regindex);
  378. #else
  379. return readl(base + regindex);
  380. #endif
  381. }
  382. static inline void write_reg_le32(volatile u32 __iomem *base, int regindex, u32 val)
  383. {
  384. #ifdef __powerpc__
  385. out_le32(base + regindex, val);
  386. #else
  387. writel(val, base + regindex);
  388. #endif
  389. }
  390. static __u32
  391. getclkMHz(struct imstt_par *par)
  392. {
  393. __u32 clk_m, clk_n, clk_p;
  394. clk_m = par->init.pclk_m;
  395. clk_n = par->init.pclk_n;
  396. clk_p = par->init.pclk_p;
  397. return 20 * (clk_m + 1) / ((clk_n + 1) * (clk_p ? 2 * clk_p : 1));
  398. }
  399. static void
  400. setclkMHz(struct imstt_par *par, __u32 MHz)
  401. {
  402. __u32 clk_m, clk_n, x, stage, spilled;
  403. clk_m = clk_n = 0;
  404. stage = spilled = 0;
  405. for (;;) {
  406. switch (stage) {
  407. case 0:
  408. clk_m++;
  409. break;
  410. case 1:
  411. clk_n++;
  412. break;
  413. }
  414. x = 20 * (clk_m + 1) / (clk_n + 1);
  415. if (x == MHz)
  416. break;
  417. if (x > MHz) {
  418. spilled = 1;
  419. stage = 1;
  420. } else if (spilled && x < MHz) {
  421. stage = 0;
  422. }
  423. }
  424. par->init.pclk_m = clk_m;
  425. par->init.pclk_n = clk_n;
  426. par->init.pclk_p = 0;
  427. }
  428. static struct imstt_regvals *
  429. compute_imstt_regvals_ibm(struct imstt_par *par, int xres, int yres)
  430. {
  431. struct imstt_regvals *init = &par->init;
  432. __u32 MHz, hes, heb, veb, htp, vtp;
  433. switch (xres) {
  434. case 640:
  435. hes = 0x0008; heb = 0x0012; veb = 0x002a; htp = 10; vtp = 2;
  436. MHz = 30 /* .25 */ ;
  437. break;
  438. case 832:
  439. hes = 0x0005; heb = 0x0020; veb = 0x0028; htp = 8; vtp = 3;
  440. MHz = 57 /* .27_ */ ;
  441. break;
  442. case 1024:
  443. hes = 0x000a; heb = 0x001c; veb = 0x0020; htp = 8; vtp = 3;
  444. MHz = 80;
  445. break;
  446. case 1152:
  447. hes = 0x0012; heb = 0x0022; veb = 0x0031; htp = 4; vtp = 3;
  448. MHz = 101 /* .6_ */ ;
  449. break;
  450. case 1280:
  451. hes = 0x0012; heb = 0x002f; veb = 0x0029; htp = 4; vtp = 1;
  452. MHz = yres == 960 ? 126 : 135;
  453. break;
  454. case 1600:
  455. hes = 0x0018; heb = 0x0040; veb = 0x002a; htp = 4; vtp = 3;
  456. MHz = 200;
  457. break;
  458. default:
  459. return NULL;
  460. }
  461. setclkMHz(par, MHz);
  462. init->hes = hes;
  463. init->heb = heb;
  464. init->hsb = init->heb + (xres >> 3);
  465. init->ht = init->hsb + htp;
  466. init->ves = 0x0003;
  467. init->veb = veb;
  468. init->vsb = init->veb + yres;
  469. init->vt = init->vsb + vtp;
  470. init->vil = init->vsb;
  471. init->pitch = xres;
  472. return init;
  473. }
  474. static struct imstt_regvals *
  475. compute_imstt_regvals_tvp(struct imstt_par *par, int xres, int yres)
  476. {
  477. struct imstt_regvals *init;
  478. switch (xres) {
  479. case 512:
  480. init = &tvp_reg_init_2;
  481. break;
  482. case 640:
  483. init = &tvp_reg_init_6;
  484. break;
  485. case 800:
  486. init = &tvp_reg_init_12;
  487. break;
  488. case 832:
  489. init = &tvp_reg_init_13;
  490. break;
  491. case 1024:
  492. init = &tvp_reg_init_17;
  493. break;
  494. case 1152:
  495. init = &tvp_reg_init_18;
  496. break;
  497. case 1280:
  498. init = yres == 960 ? &tvp_reg_init_19 : &tvp_reg_init_20;
  499. break;
  500. default:
  501. return NULL;
  502. }
  503. par->init = *init;
  504. return init;
  505. }
  506. static struct imstt_regvals *
  507. compute_imstt_regvals (struct imstt_par *par, u_int xres, u_int yres)
  508. {
  509. if (par->ramdac == IBM)
  510. return compute_imstt_regvals_ibm(par, xres, yres);
  511. else
  512. return compute_imstt_regvals_tvp(par, xres, yres);
  513. }
  514. static void
  515. set_imstt_regvals_ibm (struct imstt_par *par, u_int bpp)
  516. {
  517. struct imstt_regvals *init = &par->init;
  518. __u8 pformat = (bpp >> 3) + 2;
  519. par->cmap_regs[PIDXHI] = 0; eieio();
  520. par->cmap_regs[PIDXLO] = PIXM0; eieio();
  521. par->cmap_regs[PIDXDATA] = init->pclk_m;eieio();
  522. par->cmap_regs[PIDXLO] = PIXN0; eieio();
  523. par->cmap_regs[PIDXDATA] = init->pclk_n;eieio();
  524. par->cmap_regs[PIDXLO] = PIXP0; eieio();
  525. par->cmap_regs[PIDXDATA] = init->pclk_p;eieio();
  526. par->cmap_regs[PIDXLO] = PIXC0; eieio();
  527. par->cmap_regs[PIDXDATA] = 0x02; eieio();
  528. par->cmap_regs[PIDXLO] = PIXFMT; eieio();
  529. par->cmap_regs[PIDXDATA] = pformat; eieio();
  530. }
  531. static void
  532. set_imstt_regvals_tvp (struct imstt_par *par, u_int bpp)
  533. {
  534. struct imstt_regvals *init = &par->init;
  535. __u8 tcc, mxc, lckl_n, mic;
  536. __u8 mlc, lckl_p;
  537. switch (bpp) {
  538. default:
  539. case 8:
  540. tcc = 0x80;
  541. mxc = 0x4d;
  542. lckl_n = 0xc1;
  543. mlc = init->mlc[0];
  544. lckl_p = init->lckl_p[0];
  545. break;
  546. case 16:
  547. tcc = 0x44;
  548. mxc = 0x55;
  549. lckl_n = 0xe1;
  550. mlc = init->mlc[1];
  551. lckl_p = init->lckl_p[1];
  552. break;
  553. case 24:
  554. tcc = 0x5e;
  555. mxc = 0x5d;
  556. lckl_n = 0xf1;
  557. mlc = init->mlc[2];
  558. lckl_p = init->lckl_p[2];
  559. break;
  560. case 32:
  561. tcc = 0x46;
  562. mxc = 0x5d;
  563. lckl_n = 0xf1;
  564. mlc = init->mlc[2];
  565. lckl_p = init->lckl_p[2];
  566. break;
  567. }
  568. mic = 0x08;
  569. par->cmap_regs[TVPADDRW] = TVPIRPLA; eieio();
  570. par->cmap_regs[TVPIDATA] = 0x00; eieio();
  571. par->cmap_regs[TVPADDRW] = TVPIRPPD; eieio();
  572. par->cmap_regs[TVPIDATA] = init->pclk_m; eieio();
  573. par->cmap_regs[TVPADDRW] = TVPIRPPD; eieio();
  574. par->cmap_regs[TVPIDATA] = init->pclk_n; eieio();
  575. par->cmap_regs[TVPADDRW] = TVPIRPPD; eieio();
  576. par->cmap_regs[TVPIDATA] = init->pclk_p; eieio();
  577. par->cmap_regs[TVPADDRW] = TVPIRTCC; eieio();
  578. par->cmap_regs[TVPIDATA] = tcc; eieio();
  579. par->cmap_regs[TVPADDRW] = TVPIRMXC; eieio();
  580. par->cmap_regs[TVPIDATA] = mxc; eieio();
  581. par->cmap_regs[TVPADDRW] = TVPIRMIC; eieio();
  582. par->cmap_regs[TVPIDATA] = mic; eieio();
  583. par->cmap_regs[TVPADDRW] = TVPIRPLA; eieio();
  584. par->cmap_regs[TVPIDATA] = 0x00; eieio();
  585. par->cmap_regs[TVPADDRW] = TVPIRLPD; eieio();
  586. par->cmap_regs[TVPIDATA] = lckl_n; eieio();
  587. par->cmap_regs[TVPADDRW] = TVPIRPLA; eieio();
  588. par->cmap_regs[TVPIDATA] = 0x15; eieio();
  589. par->cmap_regs[TVPADDRW] = TVPIRMLC; eieio();
  590. par->cmap_regs[TVPIDATA] = mlc; eieio();
  591. par->cmap_regs[TVPADDRW] = TVPIRPLA; eieio();
  592. par->cmap_regs[TVPIDATA] = 0x2a; eieio();
  593. par->cmap_regs[TVPADDRW] = TVPIRLPD; eieio();
  594. par->cmap_regs[TVPIDATA] = lckl_p; eieio();
  595. }
  596. static void
  597. set_imstt_regvals (struct fb_info *info, u_int bpp)
  598. {
  599. struct imstt_par *par = info->par;
  600. struct imstt_regvals *init = &par->init;
  601. __u32 ctl, pitch, byteswap, scr;
  602. if (par->ramdac == IBM)
  603. set_imstt_regvals_ibm(par, bpp);
  604. else
  605. set_imstt_regvals_tvp(par, bpp);
  606. /*
  607. * From what I (jsk) can gather poking around with MacsBug,
  608. * bits 8 and 9 in the SCR register control endianness
  609. * correction (byte swapping). These bits must be set according
  610. * to the color depth as follows:
  611. * Color depth Bit 9 Bit 8
  612. * ========== ===== =====
  613. * 8bpp 0 0
  614. * 16bpp 0 1
  615. * 32bpp 1 1
  616. */
  617. switch (bpp) {
  618. default:
  619. case 8:
  620. ctl = 0x17b1;
  621. pitch = init->pitch >> 2;
  622. byteswap = 0x000;
  623. break;
  624. case 16:
  625. ctl = 0x17b3;
  626. pitch = init->pitch >> 1;
  627. byteswap = 0x100;
  628. break;
  629. case 24:
  630. ctl = 0x17b9;
  631. pitch = init->pitch - (init->pitch >> 2);
  632. byteswap = 0x200;
  633. break;
  634. case 32:
  635. ctl = 0x17b5;
  636. pitch = init->pitch;
  637. byteswap = 0x300;
  638. break;
  639. }
  640. if (par->ramdac == TVP)
  641. ctl -= 0x30;
  642. write_reg_le32(par->dc_regs, HES, init->hes);
  643. write_reg_le32(par->dc_regs, HEB, init->heb);
  644. write_reg_le32(par->dc_regs, HSB, init->hsb);
  645. write_reg_le32(par->dc_regs, HT, init->ht);
  646. write_reg_le32(par->dc_regs, VES, init->ves);
  647. write_reg_le32(par->dc_regs, VEB, init->veb);
  648. write_reg_le32(par->dc_regs, VSB, init->vsb);
  649. write_reg_le32(par->dc_regs, VT, init->vt);
  650. write_reg_le32(par->dc_regs, VIL, init->vil);
  651. write_reg_le32(par->dc_regs, HCIV, 1);
  652. write_reg_le32(par->dc_regs, VCIV, 1);
  653. write_reg_le32(par->dc_regs, TCDR, 4);
  654. write_reg_le32(par->dc_regs, RRCIV, 1);
  655. write_reg_le32(par->dc_regs, RRSC, 0x980);
  656. write_reg_le32(par->dc_regs, RRCR, 0x11);
  657. if (par->ramdac == IBM) {
  658. write_reg_le32(par->dc_regs, HRIR, 0x0100);
  659. write_reg_le32(par->dc_regs, CMR, 0x00ff);
  660. write_reg_le32(par->dc_regs, SRGCTL, 0x0073);
  661. } else {
  662. write_reg_le32(par->dc_regs, HRIR, 0x0200);
  663. write_reg_le32(par->dc_regs, CMR, 0x01ff);
  664. write_reg_le32(par->dc_regs, SRGCTL, 0x0003);
  665. }
  666. switch (info->fix.smem_len) {
  667. case 0x200000:
  668. scr = 0x059d | byteswap;
  669. break;
  670. /* case 0x400000:
  671. case 0x800000: */
  672. default:
  673. pitch >>= 1;
  674. scr = 0x150dd | byteswap;
  675. break;
  676. }
  677. write_reg_le32(par->dc_regs, SCR, scr);
  678. write_reg_le32(par->dc_regs, SPR, pitch);
  679. write_reg_le32(par->dc_regs, STGCTL, ctl);
  680. }
  681. static inline void
  682. set_offset (struct fb_var_screeninfo *var, struct fb_info *info)
  683. {
  684. struct imstt_par *par = info->par;
  685. __u32 off = var->yoffset * (info->fix.line_length >> 3)
  686. + ((var->xoffset * (info->var.bits_per_pixel >> 3)) >> 3);
  687. write_reg_le32(par->dc_regs, SSR, off);
  688. }
  689. static inline void
  690. set_555 (struct imstt_par *par)
  691. {
  692. if (par->ramdac == IBM) {
  693. par->cmap_regs[PIDXHI] = 0; eieio();
  694. par->cmap_regs[PIDXLO] = BPP16; eieio();
  695. par->cmap_regs[PIDXDATA] = 0x01; eieio();
  696. } else {
  697. par->cmap_regs[TVPADDRW] = TVPIRTCC; eieio();
  698. par->cmap_regs[TVPIDATA] = 0x44; eieio();
  699. }
  700. }
  701. static inline void
  702. set_565 (struct imstt_par *par)
  703. {
  704. if (par->ramdac == IBM) {
  705. par->cmap_regs[PIDXHI] = 0; eieio();
  706. par->cmap_regs[PIDXLO] = BPP16; eieio();
  707. par->cmap_regs[PIDXDATA] = 0x03; eieio();
  708. } else {
  709. par->cmap_regs[TVPADDRW] = TVPIRTCC; eieio();
  710. par->cmap_regs[TVPIDATA] = 0x45; eieio();
  711. }
  712. }
  713. static int
  714. imsttfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  715. {
  716. if ((var->bits_per_pixel != 8 && var->bits_per_pixel != 16
  717. && var->bits_per_pixel != 24 && var->bits_per_pixel != 32)
  718. || var->xres_virtual < var->xres || var->yres_virtual < var->yres
  719. || var->nonstd
  720. || (var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED)
  721. return -EINVAL;
  722. if ((var->xres * var->yres) * (var->bits_per_pixel >> 3) > info->fix.smem_len
  723. || (var->xres_virtual * var->yres_virtual) * (var->bits_per_pixel >> 3) > info->fix.smem_len)
  724. return -EINVAL;
  725. switch (var->bits_per_pixel) {
  726. case 8:
  727. var->red.offset = 0;
  728. var->red.length = 8;
  729. var->green.offset = 0;
  730. var->green.length = 8;
  731. var->blue.offset = 0;
  732. var->blue.length = 8;
  733. var->transp.offset = 0;
  734. var->transp.length = 0;
  735. break;
  736. case 16: /* RGB 555 or 565 */
  737. if (var->green.length != 6)
  738. var->red.offset = 10;
  739. var->red.length = 5;
  740. var->green.offset = 5;
  741. if (var->green.length != 6)
  742. var->green.length = 5;
  743. var->blue.offset = 0;
  744. var->blue.length = 5;
  745. var->transp.offset = 0;
  746. var->transp.length = 0;
  747. break;
  748. case 24: /* RGB 888 */
  749. var->red.offset = 16;
  750. var->red.length = 8;
  751. var->green.offset = 8;
  752. var->green.length = 8;
  753. var->blue.offset = 0;
  754. var->blue.length = 8;
  755. var->transp.offset = 0;
  756. var->transp.length = 0;
  757. break;
  758. case 32: /* RGBA 8888 */
  759. var->red.offset = 16;
  760. var->red.length = 8;
  761. var->green.offset = 8;
  762. var->green.length = 8;
  763. var->blue.offset = 0;
  764. var->blue.length = 8;
  765. var->transp.offset = 24;
  766. var->transp.length = 8;
  767. break;
  768. }
  769. if (var->yres == var->yres_virtual) {
  770. __u32 vram = (info->fix.smem_len - (PAGE_SIZE << 2));
  771. var->yres_virtual = ((vram << 3) / var->bits_per_pixel) / var->xres_virtual;
  772. if (var->yres_virtual < var->yres)
  773. var->yres_virtual = var->yres;
  774. }
  775. var->red.msb_right = 0;
  776. var->green.msb_right = 0;
  777. var->blue.msb_right = 0;
  778. var->transp.msb_right = 0;
  779. var->height = -1;
  780. var->width = -1;
  781. var->vmode = FB_VMODE_NONINTERLACED;
  782. var->left_margin = var->right_margin = 16;
  783. var->upper_margin = var->lower_margin = 16;
  784. var->hsync_len = var->vsync_len = 8;
  785. return 0;
  786. }
  787. static int
  788. imsttfb_set_par(struct fb_info *info)
  789. {
  790. struct imstt_par *par = info->par;
  791. if (!compute_imstt_regvals(par, info->var.xres, info->var.yres))
  792. return -EINVAL;
  793. if (info->var.green.length == 6)
  794. set_565(par);
  795. else
  796. set_555(par);
  797. set_imstt_regvals(info, info->var.bits_per_pixel);
  798. info->var.pixclock = 1000000 / getclkMHz(par);
  799. return 0;
  800. }
  801. static int
  802. imsttfb_setcolreg (u_int regno, u_int red, u_int green, u_int blue,
  803. u_int transp, struct fb_info *info)
  804. {
  805. struct imstt_par *par = info->par;
  806. u_int bpp = info->var.bits_per_pixel;
  807. if (regno > 255)
  808. return 1;
  809. red >>= 8;
  810. green >>= 8;
  811. blue >>= 8;
  812. /* PADDRW/PDATA are the same as TVPPADDRW/TVPPDATA */
  813. if (0 && bpp == 16) /* screws up X */
  814. par->cmap_regs[PADDRW] = regno << 3;
  815. else
  816. par->cmap_regs[PADDRW] = regno;
  817. eieio();
  818. par->cmap_regs[PDATA] = red; eieio();
  819. par->cmap_regs[PDATA] = green; eieio();
  820. par->cmap_regs[PDATA] = blue; eieio();
  821. if (regno < 16)
  822. switch (bpp) {
  823. case 16:
  824. par->palette[regno] =
  825. (regno << (info->var.green.length ==
  826. 5 ? 10 : 11)) | (regno << 5) | regno;
  827. break;
  828. case 24:
  829. par->palette[regno] =
  830. (regno << 16) | (regno << 8) | regno;
  831. break;
  832. case 32: {
  833. int i = (regno << 8) | regno;
  834. par->palette[regno] = (i << 16) |i;
  835. break;
  836. }
  837. }
  838. return 0;
  839. }
  840. static int
  841. imsttfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  842. {
  843. if (var->xoffset + info->var.xres > info->var.xres_virtual
  844. || var->yoffset + info->var.yres > info->var.yres_virtual)
  845. return -EINVAL;
  846. info->var.xoffset = var->xoffset;
  847. info->var.yoffset = var->yoffset;
  848. set_offset(var, info);
  849. return 0;
  850. }
  851. static int
  852. imsttfb_blank(int blank, struct fb_info *info)
  853. {
  854. struct imstt_par *par = info->par;
  855. __u32 ctrl;
  856. ctrl = read_reg_le32(par->dc_regs, STGCTL);
  857. if (blank > 0) {
  858. switch (blank) {
  859. case FB_BLANK_NORMAL:
  860. case FB_BLANK_POWERDOWN:
  861. ctrl &= ~0x00000380;
  862. if (par->ramdac == IBM) {
  863. par->cmap_regs[PIDXHI] = 0; eieio();
  864. par->cmap_regs[PIDXLO] = MISCTL2; eieio();
  865. par->cmap_regs[PIDXDATA] = 0x55; eieio();
  866. par->cmap_regs[PIDXLO] = MISCTL1; eieio();
  867. par->cmap_regs[PIDXDATA] = 0x11; eieio();
  868. par->cmap_regs[PIDXLO] = SYNCCTL; eieio();
  869. par->cmap_regs[PIDXDATA] = 0x0f; eieio();
  870. par->cmap_regs[PIDXLO] = PWRMNGMT; eieio();
  871. par->cmap_regs[PIDXDATA] = 0x1f; eieio();
  872. par->cmap_regs[PIDXLO] = CLKCTL; eieio();
  873. par->cmap_regs[PIDXDATA] = 0xc0;
  874. }
  875. break;
  876. case FB_BLANK_VSYNC_SUSPEND:
  877. ctrl &= ~0x00000020;
  878. break;
  879. case FB_BLANK_HSYNC_SUSPEND:
  880. ctrl &= ~0x00000010;
  881. break;
  882. }
  883. } else {
  884. if (par->ramdac == IBM) {
  885. ctrl |= 0x000017b0;
  886. par->cmap_regs[PIDXHI] = 0; eieio();
  887. par->cmap_regs[PIDXLO] = CLKCTL; eieio();
  888. par->cmap_regs[PIDXDATA] = 0x01; eieio();
  889. par->cmap_regs[PIDXLO] = PWRMNGMT; eieio();
  890. par->cmap_regs[PIDXDATA] = 0x00; eieio();
  891. par->cmap_regs[PIDXLO] = SYNCCTL; eieio();
  892. par->cmap_regs[PIDXDATA] = 0x00; eieio();
  893. par->cmap_regs[PIDXLO] = MISCTL1; eieio();
  894. par->cmap_regs[PIDXDATA] = 0x01; eieio();
  895. par->cmap_regs[PIDXLO] = MISCTL2; eieio();
  896. par->cmap_regs[PIDXDATA] = 0x45; eieio();
  897. } else
  898. ctrl |= 0x00001780;
  899. }
  900. write_reg_le32(par->dc_regs, STGCTL, ctrl);
  901. return 0;
  902. }
  903. static void
  904. imsttfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  905. {
  906. struct imstt_par *par = info->par;
  907. __u32 Bpp, line_pitch, bgc, dx, dy, width, height;
  908. bgc = rect->color;
  909. bgc |= (bgc << 8);
  910. bgc |= (bgc << 16);
  911. Bpp = info->var.bits_per_pixel >> 3,
  912. line_pitch = info->fix.line_length;
  913. dy = rect->dy * line_pitch;
  914. dx = rect->dx * Bpp;
  915. height = rect->height;
  916. height--;
  917. width = rect->width * Bpp;
  918. width--;
  919. if (rect->rop == ROP_COPY) {
  920. while(read_reg_le32(par->dc_regs, SSTATUS) & 0x80);
  921. write_reg_le32(par->dc_regs, DSA, dy + dx);
  922. write_reg_le32(par->dc_regs, CNT, (height << 16) | width);
  923. write_reg_le32(par->dc_regs, DP_OCTL, line_pitch);
  924. write_reg_le32(par->dc_regs, BI, 0xffffffff);
  925. write_reg_le32(par->dc_regs, MBC, 0xffffffff);
  926. write_reg_le32(par->dc_regs, CLR, bgc);
  927. write_reg_le32(par->dc_regs, BLTCTL, 0x840); /* 0x200000 */
  928. while(read_reg_le32(par->dc_regs, SSTATUS) & 0x80);
  929. while(read_reg_le32(par->dc_regs, SSTATUS) & 0x40);
  930. } else {
  931. while(read_reg_le32(par->dc_regs, SSTATUS) & 0x80);
  932. write_reg_le32(par->dc_regs, DSA, dy + dx);
  933. write_reg_le32(par->dc_regs, S1SA, dy + dx);
  934. write_reg_le32(par->dc_regs, CNT, (height << 16) | width);
  935. write_reg_le32(par->dc_regs, DP_OCTL, line_pitch);
  936. write_reg_le32(par->dc_regs, SP, line_pitch);
  937. write_reg_le32(par->dc_regs, BLTCTL, 0x40005);
  938. while(read_reg_le32(par->dc_regs, SSTATUS) & 0x80);
  939. while(read_reg_le32(par->dc_regs, SSTATUS) & 0x40);
  940. }
  941. }
  942. static void
  943. imsttfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
  944. {
  945. struct imstt_par *par = info->par;
  946. __u32 Bpp, line_pitch, fb_offset_old, fb_offset_new, sp, dp_octl;
  947. __u32 cnt, bltctl, sx, sy, dx, dy, height, width;
  948. Bpp = info->var.bits_per_pixel >> 3,
  949. sx = area->sx * Bpp;
  950. sy = area->sy;
  951. dx = area->dx * Bpp;
  952. dy = area->dy;
  953. height = area->height;
  954. height--;
  955. width = area->width * Bpp;
  956. width--;
  957. line_pitch = info->fix.line_length;
  958. bltctl = 0x05;
  959. sp = line_pitch << 16;
  960. cnt = height << 16;
  961. if (sy < dy) {
  962. sy += height;
  963. dy += height;
  964. sp |= -(line_pitch) & 0xffff;
  965. dp_octl = -(line_pitch) & 0xffff;
  966. } else {
  967. sp |= line_pitch;
  968. dp_octl = line_pitch;
  969. }
  970. if (sx < dx) {
  971. sx += width;
  972. dx += width;
  973. bltctl |= 0x80;
  974. cnt |= -(width) & 0xffff;
  975. } else {
  976. cnt |= width;
  977. }
  978. fb_offset_old = sy * line_pitch + sx;
  979. fb_offset_new = dy * line_pitch + dx;
  980. while(read_reg_le32(par->dc_regs, SSTATUS) & 0x80);
  981. write_reg_le32(par->dc_regs, S1SA, fb_offset_old);
  982. write_reg_le32(par->dc_regs, SP, sp);
  983. write_reg_le32(par->dc_regs, DSA, fb_offset_new);
  984. write_reg_le32(par->dc_regs, CNT, cnt);
  985. write_reg_le32(par->dc_regs, DP_OCTL, dp_octl);
  986. write_reg_le32(par->dc_regs, BLTCTL, bltctl);
  987. while(read_reg_le32(par->dc_regs, SSTATUS) & 0x80);
  988. while(read_reg_le32(par->dc_regs, SSTATUS) & 0x40);
  989. }
  990. #if 0
  991. static int
  992. imsttfb_load_cursor_image(struct imstt_par *par, int width, int height, __u8 fgc)
  993. {
  994. u_int x, y;
  995. if (width > 32 || height > 32)
  996. return -EINVAL;
  997. if (par->ramdac == IBM) {
  998. par->cmap_regs[PIDXHI] = 1; eieio();
  999. for (x = 0; x < 0x100; x++) {
  1000. par->cmap_regs[PIDXLO] = x; eieio();
  1001. par->cmap_regs[PIDXDATA] = 0x00; eieio();
  1002. }
  1003. par->cmap_regs[PIDXHI] = 1; eieio();
  1004. for (y = 0; y < height; y++)
  1005. for (x = 0; x < width >> 2; x++) {
  1006. par->cmap_regs[PIDXLO] = x + y * 8; eieio();
  1007. par->cmap_regs[PIDXDATA] = 0xff; eieio();
  1008. }
  1009. par->cmap_regs[PIDXHI] = 0; eieio();
  1010. par->cmap_regs[PIDXLO] = CURS1R; eieio();
  1011. par->cmap_regs[PIDXDATA] = fgc; eieio();
  1012. par->cmap_regs[PIDXLO] = CURS1G; eieio();
  1013. par->cmap_regs[PIDXDATA] = fgc; eieio();
  1014. par->cmap_regs[PIDXLO] = CURS1B; eieio();
  1015. par->cmap_regs[PIDXDATA] = fgc; eieio();
  1016. par->cmap_regs[PIDXLO] = CURS2R; eieio();
  1017. par->cmap_regs[PIDXDATA] = fgc; eieio();
  1018. par->cmap_regs[PIDXLO] = CURS2G; eieio();
  1019. par->cmap_regs[PIDXDATA] = fgc; eieio();
  1020. par->cmap_regs[PIDXLO] = CURS2B; eieio();
  1021. par->cmap_regs[PIDXDATA] = fgc; eieio();
  1022. par->cmap_regs[PIDXLO] = CURS3R; eieio();
  1023. par->cmap_regs[PIDXDATA] = fgc; eieio();
  1024. par->cmap_regs[PIDXLO] = CURS3G; eieio();
  1025. par->cmap_regs[PIDXDATA] = fgc; eieio();
  1026. par->cmap_regs[PIDXLO] = CURS3B; eieio();
  1027. par->cmap_regs[PIDXDATA] = fgc; eieio();
  1028. } else {
  1029. par->cmap_regs[TVPADDRW] = TVPIRICC; eieio();
  1030. par->cmap_regs[TVPIDATA] &= 0x03; eieio();
  1031. par->cmap_regs[TVPADDRW] = 0; eieio();
  1032. for (x = 0; x < 0x200; x++) {
  1033. par->cmap_regs[TVPCRDAT] = 0x00; eieio();
  1034. }
  1035. for (x = 0; x < 0x200; x++) {
  1036. par->cmap_regs[TVPCRDAT] = 0xff; eieio();
  1037. }
  1038. par->cmap_regs[TVPADDRW] = TVPIRICC; eieio();
  1039. par->cmap_regs[TVPIDATA] &= 0x03; eieio();
  1040. for (y = 0; y < height; y++)
  1041. for (x = 0; x < width >> 3; x++) {
  1042. par->cmap_regs[TVPADDRW] = x + y * 8; eieio();
  1043. par->cmap_regs[TVPCRDAT] = 0xff; eieio();
  1044. }
  1045. par->cmap_regs[TVPADDRW] = TVPIRICC; eieio();
  1046. par->cmap_regs[TVPIDATA] |= 0x08; eieio();
  1047. for (y = 0; y < height; y++)
  1048. for (x = 0; x < width >> 3; x++) {
  1049. par->cmap_regs[TVPADDRW] = x + y * 8; eieio();
  1050. par->cmap_regs[TVPCRDAT] = 0xff; eieio();
  1051. }
  1052. par->cmap_regs[TVPCADRW] = 0x00; eieio();
  1053. for (x = 0; x < 12; x++) {
  1054. par->cmap_regs[TVPCDATA] = fgc;
  1055. eieio();
  1056. }
  1057. }
  1058. return 1;
  1059. }
  1060. static void
  1061. imstt_set_cursor(struct imstt_par *par, struct fb_image *d, int on)
  1062. {
  1063. if (par->ramdac == IBM) {
  1064. par->cmap_regs[PIDXHI] = 0; eieio();
  1065. if (!on) {
  1066. par->cmap_regs[PIDXLO] = CURSCTL; eieio();
  1067. par->cmap_regs[PIDXDATA] = 0x00; eieio();
  1068. } else {
  1069. par->cmap_regs[PIDXLO] = CURSXHI; eieio();
  1070. par->cmap_regs[PIDXDATA] = d->dx >> 8; eieio();
  1071. par->cmap_regs[PIDXLO] = CURSXLO; eieio();
  1072. par->cmap_regs[PIDXDATA] = d->dx & 0xff;eieio();
  1073. par->cmap_regs[PIDXLO] = CURSYHI; eieio();
  1074. par->cmap_regs[PIDXDATA] = d->dy >> 8; eieio();
  1075. par->cmap_regs[PIDXLO] = CURSYLO; eieio();
  1076. par->cmap_regs[PIDXDATA] = d->dy & 0xff;eieio();
  1077. par->cmap_regs[PIDXLO] = CURSCTL; eieio();
  1078. par->cmap_regs[PIDXDATA] = 0x02; eieio();
  1079. }
  1080. } else {
  1081. if (!on) {
  1082. par->cmap_regs[TVPADDRW] = TVPIRICC; eieio();
  1083. par->cmap_regs[TVPIDATA] = 0x00; eieio();
  1084. } else {
  1085. __u16 x = d->dx + 0x40, y = d->dy + 0x40;
  1086. par->cmap_regs[TVPCXPOH] = x >> 8; eieio();
  1087. par->cmap_regs[TVPCXPOL] = x & 0xff; eieio();
  1088. par->cmap_regs[TVPCYPOH] = y >> 8; eieio();
  1089. par->cmap_regs[TVPCYPOL] = y & 0xff; eieio();
  1090. par->cmap_regs[TVPADDRW] = TVPIRICC; eieio();
  1091. par->cmap_regs[TVPIDATA] = 0x02; eieio();
  1092. }
  1093. }
  1094. }
  1095. static int
  1096. imsttfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
  1097. {
  1098. struct imstt_par *par = info->par;
  1099. u32 flags = cursor->set, fg, bg, xx, yy;
  1100. if (cursor->dest == NULL && cursor->rop == ROP_XOR)
  1101. return 1;
  1102. imstt_set_cursor(info, cursor, 0);
  1103. if (flags & FB_CUR_SETPOS) {
  1104. xx = cursor->image.dx - info->var.xoffset;
  1105. yy = cursor->image.dy - info->var.yoffset;
  1106. }
  1107. if (flags & FB_CUR_SETSIZE) {
  1108. }
  1109. if (flags & (FB_CUR_SETSHAPE | FB_CUR_SETCMAP)) {
  1110. int fg_idx = cursor->image.fg_color;
  1111. int width = (cursor->image.width+7)/8;
  1112. u8 *dat = (u8 *) cursor->image.data;
  1113. u8 *dst = (u8 *) cursor->dest;
  1114. u8 *msk = (u8 *) cursor->mask;
  1115. switch (cursor->rop) {
  1116. case ROP_XOR:
  1117. for (i = 0; i < cursor->image.height; i++) {
  1118. for (j = 0; j < width; j++) {
  1119. d_idx = i * MAX_CURS/8 + j;
  1120. data[d_idx] = byte_rev[dat[s_idx] ^
  1121. dst[s_idx]];
  1122. mask[d_idx] = byte_rev[msk[s_idx]];
  1123. s_idx++;
  1124. }
  1125. }
  1126. break;
  1127. case ROP_COPY:
  1128. default:
  1129. for (i = 0; i < cursor->image.height; i++) {
  1130. for (j = 0; j < width; j++) {
  1131. d_idx = i * MAX_CURS/8 + j;
  1132. data[d_idx] = byte_rev[dat[s_idx]];
  1133. mask[d_idx] = byte_rev[msk[s_idx]];
  1134. s_idx++;
  1135. }
  1136. }
  1137. break;
  1138. }
  1139. fg = ((info->cmap.red[fg_idx] & 0xf8) << 7) |
  1140. ((info->cmap.green[fg_idx] & 0xf8) << 2) |
  1141. ((info->cmap.blue[fg_idx] & 0xf8) >> 3) | 1 << 15;
  1142. imsttfb_load_cursor_image(par, xx, yy, fgc);
  1143. }
  1144. if (cursor->enable)
  1145. imstt_set_cursor(info, cursor, 1);
  1146. return 0;
  1147. }
  1148. #endif
  1149. #define FBIMSTT_SETREG 0x545401
  1150. #define FBIMSTT_GETREG 0x545402
  1151. #define FBIMSTT_SETCMAPREG 0x545403
  1152. #define FBIMSTT_GETCMAPREG 0x545404
  1153. #define FBIMSTT_SETIDXREG 0x545405
  1154. #define FBIMSTT_GETIDXREG 0x545406
  1155. static int
  1156. imsttfb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
  1157. {
  1158. struct imstt_par *par = info->par;
  1159. void __user *argp = (void __user *)arg;
  1160. __u32 reg[2];
  1161. __u8 idx[2];
  1162. switch (cmd) {
  1163. case FBIMSTT_SETREG:
  1164. if (copy_from_user(reg, argp, 8) || reg[0] > (0x1000 - sizeof(reg[0])) / sizeof(reg[0]))
  1165. return -EFAULT;
  1166. write_reg_le32(par->dc_regs, reg[0], reg[1]);
  1167. return 0;
  1168. case FBIMSTT_GETREG:
  1169. if (copy_from_user(reg, argp, 4) || reg[0] > (0x1000 - sizeof(reg[0])) / sizeof(reg[0]))
  1170. return -EFAULT;
  1171. reg[1] = read_reg_le32(par->dc_regs, reg[0]);
  1172. if (copy_to_user((void __user *)(arg + 4), &reg[1], 4))
  1173. return -EFAULT;
  1174. return 0;
  1175. case FBIMSTT_SETCMAPREG:
  1176. if (copy_from_user(reg, argp, 8) || reg[0] > (0x1000 - sizeof(reg[0])) / sizeof(reg[0]))
  1177. return -EFAULT;
  1178. write_reg_le32(((u_int __iomem *)par->cmap_regs), reg[0], reg[1]);
  1179. return 0;
  1180. case FBIMSTT_GETCMAPREG:
  1181. if (copy_from_user(reg, argp, 4) || reg[0] > (0x1000 - sizeof(reg[0])) / sizeof(reg[0]))
  1182. return -EFAULT;
  1183. reg[1] = read_reg_le32(((u_int __iomem *)par->cmap_regs), reg[0]);
  1184. if (copy_to_user((void __user *)(arg + 4), &reg[1], 4))
  1185. return -EFAULT;
  1186. return 0;
  1187. case FBIMSTT_SETIDXREG:
  1188. if (copy_from_user(idx, argp, 2))
  1189. return -EFAULT;
  1190. par->cmap_regs[PIDXHI] = 0; eieio();
  1191. par->cmap_regs[PIDXLO] = idx[0]; eieio();
  1192. par->cmap_regs[PIDXDATA] = idx[1]; eieio();
  1193. return 0;
  1194. case FBIMSTT_GETIDXREG:
  1195. if (copy_from_user(idx, argp, 1))
  1196. return -EFAULT;
  1197. par->cmap_regs[PIDXHI] = 0; eieio();
  1198. par->cmap_regs[PIDXLO] = idx[0]; eieio();
  1199. idx[1] = par->cmap_regs[PIDXDATA];
  1200. if (copy_to_user((void __user *)(arg + 1), &idx[1], 1))
  1201. return -EFAULT;
  1202. return 0;
  1203. default:
  1204. return -ENOIOCTLCMD;
  1205. }
  1206. }
  1207. static struct pci_device_id imsttfb_pci_tbl[] = {
  1208. { PCI_VENDOR_ID_IMS, PCI_DEVICE_ID_IMS_TT128,
  1209. PCI_ANY_ID, PCI_ANY_ID, 0, 0, IBM },
  1210. { PCI_VENDOR_ID_IMS, PCI_DEVICE_ID_IMS_TT3D,
  1211. PCI_ANY_ID, PCI_ANY_ID, 0, 0, TVP },
  1212. { 0, }
  1213. };
  1214. MODULE_DEVICE_TABLE(pci, imsttfb_pci_tbl);
  1215. static struct pci_driver imsttfb_pci_driver = {
  1216. .name = "imsttfb",
  1217. .id_table = imsttfb_pci_tbl,
  1218. .probe = imsttfb_probe,
  1219. .remove = imsttfb_remove,
  1220. };
  1221. static struct fb_ops imsttfb_ops = {
  1222. .owner = THIS_MODULE,
  1223. .fb_check_var = imsttfb_check_var,
  1224. .fb_set_par = imsttfb_set_par,
  1225. .fb_setcolreg = imsttfb_setcolreg,
  1226. .fb_pan_display = imsttfb_pan_display,
  1227. .fb_blank = imsttfb_blank,
  1228. .fb_fillrect = imsttfb_fillrect,
  1229. .fb_copyarea = imsttfb_copyarea,
  1230. .fb_imageblit = cfb_imageblit,
  1231. .fb_ioctl = imsttfb_ioctl,
  1232. };
  1233. static void init_imstt(struct fb_info *info)
  1234. {
  1235. struct imstt_par *par = info->par;
  1236. __u32 i, tmp, *ip, *end;
  1237. tmp = read_reg_le32(par->dc_regs, PRC);
  1238. if (par->ramdac == IBM)
  1239. info->fix.smem_len = (tmp & 0x0004) ? 0x400000 : 0x200000;
  1240. else
  1241. info->fix.smem_len = 0x800000;
  1242. ip = (__u32 *)info->screen_base;
  1243. end = (__u32 *)(info->screen_base + info->fix.smem_len);
  1244. while (ip < end)
  1245. *ip++ = 0;
  1246. /* initialize the card */
  1247. tmp = read_reg_le32(par->dc_regs, STGCTL);
  1248. write_reg_le32(par->dc_regs, STGCTL, tmp & ~0x1);
  1249. write_reg_le32(par->dc_regs, SSR, 0);
  1250. /* set default values for DAC registers */
  1251. if (par->ramdac == IBM) {
  1252. par->cmap_regs[PPMASK] = 0xff;
  1253. eieio();
  1254. par->cmap_regs[PIDXHI] = 0;
  1255. eieio();
  1256. for (i = 0; i < ARRAY_SIZE(ibm_initregs); i++) {
  1257. par->cmap_regs[PIDXLO] = ibm_initregs[i].addr;
  1258. eieio();
  1259. par->cmap_regs[PIDXDATA] = ibm_initregs[i].value;
  1260. eieio();
  1261. }
  1262. } else {
  1263. for (i = 0; i < ARRAY_SIZE(tvp_initregs); i++) {
  1264. par->cmap_regs[TVPADDRW] = tvp_initregs[i].addr;
  1265. eieio();
  1266. par->cmap_regs[TVPIDATA] = tvp_initregs[i].value;
  1267. eieio();
  1268. }
  1269. }
  1270. #if USE_NV_MODES && defined(CONFIG_PPC32)
  1271. {
  1272. int vmode = init_vmode, cmode = init_cmode;
  1273. if (vmode == -1) {
  1274. vmode = nvram_read_byte(NV_VMODE);
  1275. if (vmode <= 0 || vmode > VMODE_MAX)
  1276. vmode = VMODE_640_480_67;
  1277. }
  1278. if (cmode == -1) {
  1279. cmode = nvram_read_byte(NV_CMODE);
  1280. if (cmode < CMODE_8 || cmode > CMODE_32)
  1281. cmode = CMODE_8;
  1282. }
  1283. if (mac_vmode_to_var(vmode, cmode, &info->var)) {
  1284. info->var.xres = info->var.xres_virtual = INIT_XRES;
  1285. info->var.yres = info->var.yres_virtual = INIT_YRES;
  1286. info->var.bits_per_pixel = INIT_BPP;
  1287. }
  1288. }
  1289. #else
  1290. info->var.xres = info->var.xres_virtual = INIT_XRES;
  1291. info->var.yres = info->var.yres_virtual = INIT_YRES;
  1292. info->var.bits_per_pixel = INIT_BPP;
  1293. #endif
  1294. if ((info->var.xres * info->var.yres) * (info->var.bits_per_pixel >> 3) > info->fix.smem_len
  1295. || !(compute_imstt_regvals(par, info->var.xres, info->var.yres))) {
  1296. printk("imsttfb: %ux%ux%u not supported\n", info->var.xres, info->var.yres, info->var.bits_per_pixel);
  1297. framebuffer_release(info);
  1298. return;
  1299. }
  1300. sprintf(info->fix.id, "IMS TT (%s)", par->ramdac == IBM ? "IBM" : "TVP");
  1301. info->fix.mmio_len = 0x1000;
  1302. info->fix.accel = FB_ACCEL_IMS_TWINTURBO;
  1303. info->fix.type = FB_TYPE_PACKED_PIXELS;
  1304. info->fix.visual = info->var.bits_per_pixel == 8 ? FB_VISUAL_PSEUDOCOLOR
  1305. : FB_VISUAL_DIRECTCOLOR;
  1306. info->fix.line_length = info->var.xres * (info->var.bits_per_pixel >> 3);
  1307. info->fix.xpanstep = 8;
  1308. info->fix.ypanstep = 1;
  1309. info->fix.ywrapstep = 0;
  1310. info->var.accel_flags = FB_ACCELF_TEXT;
  1311. // if (par->ramdac == IBM)
  1312. // imstt_cursor_init(info);
  1313. if (info->var.green.length == 6)
  1314. set_565(par);
  1315. else
  1316. set_555(par);
  1317. set_imstt_regvals(info, info->var.bits_per_pixel);
  1318. info->var.pixclock = 1000000 / getclkMHz(par);
  1319. info->fbops = &imsttfb_ops;
  1320. info->flags = FBINFO_DEFAULT |
  1321. FBINFO_HWACCEL_COPYAREA |
  1322. FBINFO_HWACCEL_FILLRECT |
  1323. FBINFO_HWACCEL_YPAN;
  1324. fb_alloc_cmap(&info->cmap, 0, 0);
  1325. if (register_framebuffer(info) < 0) {
  1326. framebuffer_release(info);
  1327. return;
  1328. }
  1329. tmp = (read_reg_le32(par->dc_regs, SSTATUS) & 0x0f00) >> 8;
  1330. fb_info(info, "%s frame buffer; %uMB vram; chip version %u\n",
  1331. info->fix.id, info->fix.smem_len >> 20, tmp);
  1332. }
  1333. static int imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  1334. {
  1335. unsigned long addr, size;
  1336. struct imstt_par *par;
  1337. struct fb_info *info;
  1338. struct device_node *dp;
  1339. dp = pci_device_to_OF_node(pdev);
  1340. if(dp)
  1341. printk(KERN_INFO "%s: OF name %s\n",__func__, dp->name);
  1342. else if (IS_ENABLED(CONFIG_OF))
  1343. printk(KERN_ERR "imsttfb: no OF node for pci device\n");
  1344. info = framebuffer_alloc(sizeof(struct imstt_par), &pdev->dev);
  1345. if (!info) {
  1346. printk(KERN_ERR "imsttfb: Can't allocate memory\n");
  1347. return -ENOMEM;
  1348. }
  1349. par = info->par;
  1350. addr = pci_resource_start (pdev, 0);
  1351. size = pci_resource_len (pdev, 0);
  1352. if (!request_mem_region(addr, size, "imsttfb")) {
  1353. printk(KERN_ERR "imsttfb: Can't reserve memory region\n");
  1354. framebuffer_release(info);
  1355. return -ENODEV;
  1356. }
  1357. switch (pdev->device) {
  1358. case PCI_DEVICE_ID_IMS_TT128: /* IMS,tt128mbA */
  1359. par->ramdac = IBM;
  1360. if (dp && ((strcmp(dp->name, "IMS,tt128mb8") == 0) ||
  1361. (strcmp(dp->name, "IMS,tt128mb8A") == 0)))
  1362. par->ramdac = TVP;
  1363. break;
  1364. case PCI_DEVICE_ID_IMS_TT3D: /* IMS,tt3d */
  1365. par->ramdac = TVP;
  1366. break;
  1367. default:
  1368. printk(KERN_INFO "imsttfb: Device 0x%x unknown, "
  1369. "contact maintainer.\n", pdev->device);
  1370. release_mem_region(addr, size);
  1371. framebuffer_release(info);
  1372. return -ENODEV;
  1373. }
  1374. info->fix.smem_start = addr;
  1375. info->screen_base = (__u8 *)ioremap(addr, par->ramdac == IBM ?
  1376. 0x400000 : 0x800000);
  1377. info->fix.mmio_start = addr + 0x800000;
  1378. par->dc_regs = ioremap(addr + 0x800000, 0x1000);
  1379. par->cmap_regs_phys = addr + 0x840000;
  1380. par->cmap_regs = (__u8 *)ioremap(addr + 0x840000, 0x1000);
  1381. info->pseudo_palette = par->palette;
  1382. init_imstt(info);
  1383. pci_set_drvdata(pdev, info);
  1384. return 0;
  1385. }
  1386. static void imsttfb_remove(struct pci_dev *pdev)
  1387. {
  1388. struct fb_info *info = pci_get_drvdata(pdev);
  1389. struct imstt_par *par = info->par;
  1390. int size = pci_resource_len(pdev, 0);
  1391. unregister_framebuffer(info);
  1392. iounmap(par->cmap_regs);
  1393. iounmap(par->dc_regs);
  1394. iounmap(info->screen_base);
  1395. release_mem_region(info->fix.smem_start, size);
  1396. framebuffer_release(info);
  1397. }
  1398. #ifndef MODULE
  1399. static int __init
  1400. imsttfb_setup(char *options)
  1401. {
  1402. char *this_opt;
  1403. if (!options || !*options)
  1404. return 0;
  1405. while ((this_opt = strsep(&options, ",")) != NULL) {
  1406. if (!strncmp(this_opt, "font:", 5)) {
  1407. char *p;
  1408. int i;
  1409. p = this_opt + 5;
  1410. for (i = 0; i < sizeof(fontname) - 1; i++)
  1411. if (!*p || *p == ' ' || *p == ',')
  1412. break;
  1413. memcpy(fontname, this_opt + 5, i);
  1414. fontname[i] = 0;
  1415. } else if (!strncmp(this_opt, "inverse", 7)) {
  1416. inverse = 1;
  1417. fb_invert_cmaps();
  1418. }
  1419. #if defined(CONFIG_PPC)
  1420. else if (!strncmp(this_opt, "vmode:", 6)) {
  1421. int vmode = simple_strtoul(this_opt+6, NULL, 0);
  1422. if (vmode > 0 && vmode <= VMODE_MAX)
  1423. init_vmode = vmode;
  1424. } else if (!strncmp(this_opt, "cmode:", 6)) {
  1425. int cmode = simple_strtoul(this_opt+6, NULL, 0);
  1426. switch (cmode) {
  1427. case CMODE_8:
  1428. case 8:
  1429. init_cmode = CMODE_8;
  1430. break;
  1431. case CMODE_16:
  1432. case 15:
  1433. case 16:
  1434. init_cmode = CMODE_16;
  1435. break;
  1436. case CMODE_32:
  1437. case 24:
  1438. case 32:
  1439. init_cmode = CMODE_32;
  1440. break;
  1441. }
  1442. }
  1443. #endif
  1444. }
  1445. return 0;
  1446. }
  1447. #endif /* MODULE */
  1448. static int __init imsttfb_init(void)
  1449. {
  1450. #ifndef MODULE
  1451. char *option = NULL;
  1452. if (fb_get_options("imsttfb", &option))
  1453. return -ENODEV;
  1454. imsttfb_setup(option);
  1455. #endif
  1456. return pci_register_driver(&imsttfb_pci_driver);
  1457. }
  1458. static void __exit imsttfb_exit(void)
  1459. {
  1460. pci_unregister_driver(&imsttfb_pci_driver);
  1461. }
  1462. MODULE_LICENSE("GPL");
  1463. module_init(imsttfb_init);
  1464. module_exit(imsttfb_exit);