imsttfb.c 44 KB

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