s3fb.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566
  1. /*
  2. * linux/drivers/video/s3fb.c -- Frame buffer device driver for S3 Trio/Virge
  3. *
  4. * Copyright (c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive for
  8. * more details.
  9. *
  10. * Code is based on David Boucher's viafb (http://davesdomain.org.uk/viafb/)
  11. * which is based on the code of neofb.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/errno.h>
  16. #include <linux/string.h>
  17. #include <linux/mm.h>
  18. #include <linux/tty.h>
  19. #include <linux/delay.h>
  20. #include <linux/fb.h>
  21. #include <linux/svga.h>
  22. #include <linux/init.h>
  23. #include <linux/pci.h>
  24. #include <linux/console.h> /* Why should fb driver call console functions? because console_lock() */
  25. #include <video/vga.h>
  26. #include <linux/i2c.h>
  27. #include <linux/i2c-algo-bit.h>
  28. #ifdef CONFIG_MTRR
  29. #include <asm/mtrr.h>
  30. #endif
  31. struct s3fb_info {
  32. int chip, rev, mclk_freq;
  33. int mtrr_reg;
  34. struct vgastate state;
  35. struct mutex open_lock;
  36. unsigned int ref_count;
  37. u32 pseudo_palette[16];
  38. #ifdef CONFIG_FB_S3_DDC
  39. u8 __iomem *mmio;
  40. bool ddc_registered;
  41. struct i2c_adapter ddc_adapter;
  42. struct i2c_algo_bit_data ddc_algo;
  43. #endif
  44. };
  45. /* ------------------------------------------------------------------------- */
  46. static const struct svga_fb_format s3fb_formats[] = {
  47. { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
  48. FB_TYPE_TEXT, FB_AUX_TEXT_SVGA_STEP4, FB_VISUAL_PSEUDOCOLOR, 8, 16},
  49. { 4, {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0}, 0,
  50. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 16},
  51. { 4, {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0}, 1,
  52. FB_TYPE_INTERLEAVED_PLANES, 1, FB_VISUAL_PSEUDOCOLOR, 8, 16},
  53. { 8, {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
  54. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 4, 8},
  55. {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0,
  56. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 4},
  57. {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0,
  58. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 4},
  59. {24, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
  60. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 1, 2},
  61. {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
  62. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 1, 2},
  63. SVGA_FORMAT_END
  64. };
  65. static const struct svga_pll s3_pll = {3, 129, 3, 33, 0, 3,
  66. 35000, 240000, 14318};
  67. static const struct svga_pll s3_trio3d_pll = {3, 129, 3, 31, 0, 4,
  68. 230000, 460000, 14318};
  69. static const int s3_memsizes[] = {4096, 0, 3072, 8192, 2048, 6144, 1024, 512};
  70. static const char * const s3_names[] = {"S3 Unknown", "S3 Trio32", "S3 Trio64", "S3 Trio64V+",
  71. "S3 Trio64UV+", "S3 Trio64V2/DX", "S3 Trio64V2/GX",
  72. "S3 Plato/PX", "S3 Aurora64V+", "S3 Virge",
  73. "S3 Virge/VX", "S3 Virge/DX", "S3 Virge/GX",
  74. "S3 Virge/GX2", "S3 Virge/GX2+", "",
  75. "S3 Trio3D/1X", "S3 Trio3D/2X", "S3 Trio3D/2X",
  76. "S3 Trio3D"};
  77. #define CHIP_UNKNOWN 0x00
  78. #define CHIP_732_TRIO32 0x01
  79. #define CHIP_764_TRIO64 0x02
  80. #define CHIP_765_TRIO64VP 0x03
  81. #define CHIP_767_TRIO64UVP 0x04
  82. #define CHIP_775_TRIO64V2_DX 0x05
  83. #define CHIP_785_TRIO64V2_GX 0x06
  84. #define CHIP_551_PLATO_PX 0x07
  85. #define CHIP_M65_AURORA64VP 0x08
  86. #define CHIP_325_VIRGE 0x09
  87. #define CHIP_988_VIRGE_VX 0x0A
  88. #define CHIP_375_VIRGE_DX 0x0B
  89. #define CHIP_385_VIRGE_GX 0x0C
  90. #define CHIP_357_VIRGE_GX2 0x0D
  91. #define CHIP_359_VIRGE_GX2P 0x0E
  92. #define CHIP_360_TRIO3D_1X 0x10
  93. #define CHIP_362_TRIO3D_2X 0x11
  94. #define CHIP_368_TRIO3D_2X 0x12
  95. #define CHIP_365_TRIO3D 0x13
  96. #define CHIP_XXX_TRIO 0x80
  97. #define CHIP_XXX_TRIO64V2_DXGX 0x81
  98. #define CHIP_XXX_VIRGE_DXGX 0x82
  99. #define CHIP_36X_TRIO3D_1X_2X 0x83
  100. #define CHIP_UNDECIDED_FLAG 0x80
  101. #define CHIP_MASK 0xFF
  102. #define MMIO_OFFSET 0x1000000
  103. #define MMIO_SIZE 0x10000
  104. /* CRT timing register sets */
  105. static const struct vga_regset s3_h_total_regs[] = {{0x00, 0, 7}, {0x5D, 0, 0}, VGA_REGSET_END};
  106. static const struct vga_regset s3_h_display_regs[] = {{0x01, 0, 7}, {0x5D, 1, 1}, VGA_REGSET_END};
  107. static const struct vga_regset s3_h_blank_start_regs[] = {{0x02, 0, 7}, {0x5D, 2, 2}, VGA_REGSET_END};
  108. static const struct vga_regset s3_h_blank_end_regs[] = {{0x03, 0, 4}, {0x05, 7, 7}, VGA_REGSET_END};
  109. static const struct vga_regset s3_h_sync_start_regs[] = {{0x04, 0, 7}, {0x5D, 4, 4}, VGA_REGSET_END};
  110. static const struct vga_regset s3_h_sync_end_regs[] = {{0x05, 0, 4}, VGA_REGSET_END};
  111. static const struct vga_regset s3_v_total_regs[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x5E, 0, 0}, VGA_REGSET_END};
  112. static const struct vga_regset s3_v_display_regs[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x5E, 1, 1}, VGA_REGSET_END};
  113. static const struct vga_regset s3_v_blank_start_regs[] = {{0x15, 0, 7}, {0x07, 3, 3}, {0x09, 5, 5}, {0x5E, 2, 2}, VGA_REGSET_END};
  114. static const struct vga_regset s3_v_blank_end_regs[] = {{0x16, 0, 7}, VGA_REGSET_END};
  115. static const struct vga_regset s3_v_sync_start_regs[] = {{0x10, 0, 7}, {0x07, 2, 2}, {0x07, 7, 7}, {0x5E, 4, 4}, VGA_REGSET_END};
  116. static const struct vga_regset s3_v_sync_end_regs[] = {{0x11, 0, 3}, VGA_REGSET_END};
  117. static const struct vga_regset s3_line_compare_regs[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, {0x5E, 6, 6}, VGA_REGSET_END};
  118. static const struct vga_regset s3_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x69, 0, 4}, VGA_REGSET_END};
  119. static const struct vga_regset s3_offset_regs[] = {{0x13, 0, 7}, {0x51, 4, 5}, VGA_REGSET_END}; /* set 0x43 bit 2 to 0 */
  120. static const struct vga_regset s3_dtpc_regs[] = {{0x3B, 0, 7}, {0x5D, 6, 6}, VGA_REGSET_END};
  121. static const struct svga_timing_regs s3_timing_regs = {
  122. s3_h_total_regs, s3_h_display_regs, s3_h_blank_start_regs,
  123. s3_h_blank_end_regs, s3_h_sync_start_regs, s3_h_sync_end_regs,
  124. s3_v_total_regs, s3_v_display_regs, s3_v_blank_start_regs,
  125. s3_v_blank_end_regs, s3_v_sync_start_regs, s3_v_sync_end_regs,
  126. };
  127. /* ------------------------------------------------------------------------- */
  128. /* Module parameters */
  129. static char *mode_option __devinitdata;
  130. #ifdef CONFIG_MTRR
  131. static int mtrr __devinitdata = 1;
  132. #endif
  133. static int fasttext = 1;
  134. MODULE_AUTHOR("(c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>");
  135. MODULE_LICENSE("GPL");
  136. MODULE_DESCRIPTION("fbdev driver for S3 Trio/Virge");
  137. module_param(mode_option, charp, 0444);
  138. MODULE_PARM_DESC(mode_option, "Default video mode ('640x480-8@60', etc)");
  139. module_param_named(mode, mode_option, charp, 0444);
  140. MODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc) (deprecated)");
  141. #ifdef CONFIG_MTRR
  142. module_param(mtrr, int, 0444);
  143. MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)");
  144. #endif
  145. module_param(fasttext, int, 0644);
  146. MODULE_PARM_DESC(fasttext, "Enable S3 fast text mode (1=enable, 0=disable, default=1)");
  147. /* ------------------------------------------------------------------------- */
  148. #ifdef CONFIG_FB_S3_DDC
  149. #define DDC_REG 0xaa /* Trio 3D/1X/2X */
  150. #define DDC_MMIO_REG 0xff20 /* all other chips */
  151. #define DDC_SCL_OUT (1 << 0)
  152. #define DDC_SDA_OUT (1 << 1)
  153. #define DDC_SCL_IN (1 << 2)
  154. #define DDC_SDA_IN (1 << 3)
  155. #define DDC_DRIVE_EN (1 << 4)
  156. static bool s3fb_ddc_needs_mmio(int chip)
  157. {
  158. return !(chip == CHIP_360_TRIO3D_1X ||
  159. chip == CHIP_362_TRIO3D_2X ||
  160. chip == CHIP_368_TRIO3D_2X);
  161. }
  162. static u8 s3fb_ddc_read(struct s3fb_info *par)
  163. {
  164. if (s3fb_ddc_needs_mmio(par->chip))
  165. return readb(par->mmio + DDC_MMIO_REG);
  166. else
  167. return vga_rcrt(par->state.vgabase, DDC_REG);
  168. }
  169. static void s3fb_ddc_write(struct s3fb_info *par, u8 val)
  170. {
  171. if (s3fb_ddc_needs_mmio(par->chip))
  172. writeb(val, par->mmio + DDC_MMIO_REG);
  173. else
  174. vga_wcrt(par->state.vgabase, DDC_REG, val);
  175. }
  176. static void s3fb_ddc_setscl(void *data, int val)
  177. {
  178. struct s3fb_info *par = data;
  179. unsigned char reg;
  180. reg = s3fb_ddc_read(par) | DDC_DRIVE_EN;
  181. if (val)
  182. reg |= DDC_SCL_OUT;
  183. else
  184. reg &= ~DDC_SCL_OUT;
  185. s3fb_ddc_write(par, reg);
  186. }
  187. static void s3fb_ddc_setsda(void *data, int val)
  188. {
  189. struct s3fb_info *par = data;
  190. unsigned char reg;
  191. reg = s3fb_ddc_read(par) | DDC_DRIVE_EN;
  192. if (val)
  193. reg |= DDC_SDA_OUT;
  194. else
  195. reg &= ~DDC_SDA_OUT;
  196. s3fb_ddc_write(par, reg);
  197. }
  198. static int s3fb_ddc_getscl(void *data)
  199. {
  200. struct s3fb_info *par = data;
  201. return !!(s3fb_ddc_read(par) & DDC_SCL_IN);
  202. }
  203. static int s3fb_ddc_getsda(void *data)
  204. {
  205. struct s3fb_info *par = data;
  206. return !!(s3fb_ddc_read(par) & DDC_SDA_IN);
  207. }
  208. static int __devinit s3fb_setup_ddc_bus(struct fb_info *info)
  209. {
  210. struct s3fb_info *par = info->par;
  211. strlcpy(par->ddc_adapter.name, info->fix.id,
  212. sizeof(par->ddc_adapter.name));
  213. par->ddc_adapter.owner = THIS_MODULE;
  214. par->ddc_adapter.class = I2C_CLASS_DDC;
  215. par->ddc_adapter.algo_data = &par->ddc_algo;
  216. par->ddc_adapter.dev.parent = info->device;
  217. par->ddc_algo.setsda = s3fb_ddc_setsda;
  218. par->ddc_algo.setscl = s3fb_ddc_setscl;
  219. par->ddc_algo.getsda = s3fb_ddc_getsda;
  220. par->ddc_algo.getscl = s3fb_ddc_getscl;
  221. par->ddc_algo.udelay = 10;
  222. par->ddc_algo.timeout = 20;
  223. par->ddc_algo.data = par;
  224. i2c_set_adapdata(&par->ddc_adapter, par);
  225. /*
  226. * some Virge cards have external MUX to switch chip I2C bus between
  227. * DDC and extension pins - switch it do DDC
  228. */
  229. /* vga_wseq(par->state.vgabase, 0x08, 0x06); - not needed, already unlocked */
  230. if (par->chip == CHIP_357_VIRGE_GX2 ||
  231. par->chip == CHIP_359_VIRGE_GX2P)
  232. svga_wseq_mask(par->state.vgabase, 0x0d, 0x01, 0x03);
  233. else
  234. svga_wseq_mask(par->state.vgabase, 0x0d, 0x00, 0x03);
  235. /* some Virge need this or the DDC is ignored */
  236. svga_wcrt_mask(par->state.vgabase, 0x5c, 0x03, 0x03);
  237. return i2c_bit_add_bus(&par->ddc_adapter);
  238. }
  239. #endif /* CONFIG_FB_S3_DDC */
  240. /* ------------------------------------------------------------------------- */
  241. /* Set font in S3 fast text mode */
  242. static void s3fb_settile_fast(struct fb_info *info, struct fb_tilemap *map)
  243. {
  244. const u8 *font = map->data;
  245. u8 __iomem *fb = (u8 __iomem *) info->screen_base;
  246. int i, c;
  247. if ((map->width != 8) || (map->height != 16) ||
  248. (map->depth != 1) || (map->length != 256)) {
  249. printk(KERN_ERR "fb%d: unsupported font parameters: width %d, height %d, depth %d, length %d\n",
  250. info->node, map->width, map->height, map->depth, map->length);
  251. return;
  252. }
  253. fb += 2;
  254. for (i = 0; i < map->height; i++) {
  255. for (c = 0; c < map->length; c++) {
  256. fb_writeb(font[c * map->height + i], fb + c * 4);
  257. }
  258. fb += 1024;
  259. }
  260. }
  261. static void s3fb_tilecursor(struct fb_info *info, struct fb_tilecursor *cursor)
  262. {
  263. struct s3fb_info *par = info->par;
  264. svga_tilecursor(par->state.vgabase, info, cursor);
  265. }
  266. static struct fb_tile_ops s3fb_tile_ops = {
  267. .fb_settile = svga_settile,
  268. .fb_tilecopy = svga_tilecopy,
  269. .fb_tilefill = svga_tilefill,
  270. .fb_tileblit = svga_tileblit,
  271. .fb_tilecursor = s3fb_tilecursor,
  272. .fb_get_tilemax = svga_get_tilemax,
  273. };
  274. static struct fb_tile_ops s3fb_fast_tile_ops = {
  275. .fb_settile = s3fb_settile_fast,
  276. .fb_tilecopy = svga_tilecopy,
  277. .fb_tilefill = svga_tilefill,
  278. .fb_tileblit = svga_tileblit,
  279. .fb_tilecursor = s3fb_tilecursor,
  280. .fb_get_tilemax = svga_get_tilemax,
  281. };
  282. /* ------------------------------------------------------------------------- */
  283. /* image data is MSB-first, fb structure is MSB-first too */
  284. static inline u32 expand_color(u32 c)
  285. {
  286. return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF;
  287. }
  288. /* s3fb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */
  289. static void s3fb_iplan_imageblit(struct fb_info *info, const struct fb_image *image)
  290. {
  291. u32 fg = expand_color(image->fg_color);
  292. u32 bg = expand_color(image->bg_color);
  293. const u8 *src1, *src;
  294. u8 __iomem *dst1;
  295. u32 __iomem *dst;
  296. u32 val;
  297. int x, y;
  298. src1 = image->data;
  299. dst1 = info->screen_base + (image->dy * info->fix.line_length)
  300. + ((image->dx / 8) * 4);
  301. for (y = 0; y < image->height; y++) {
  302. src = src1;
  303. dst = (u32 __iomem *) dst1;
  304. for (x = 0; x < image->width; x += 8) {
  305. val = *(src++) * 0x01010101;
  306. val = (val & fg) | (~val & bg);
  307. fb_writel(val, dst++);
  308. }
  309. src1 += image->width / 8;
  310. dst1 += info->fix.line_length;
  311. }
  312. }
  313. /* s3fb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */
  314. static void s3fb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  315. {
  316. u32 fg = expand_color(rect->color);
  317. u8 __iomem *dst1;
  318. u32 __iomem *dst;
  319. int x, y;
  320. dst1 = info->screen_base + (rect->dy * info->fix.line_length)
  321. + ((rect->dx / 8) * 4);
  322. for (y = 0; y < rect->height; y++) {
  323. dst = (u32 __iomem *) dst1;
  324. for (x = 0; x < rect->width; x += 8) {
  325. fb_writel(fg, dst++);
  326. }
  327. dst1 += info->fix.line_length;
  328. }
  329. }
  330. /* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */
  331. static inline u32 expand_pixel(u32 c)
  332. {
  333. return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) |
  334. ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF;
  335. }
  336. /* s3fb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */
  337. static void s3fb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image)
  338. {
  339. u32 fg = image->fg_color * 0x11111111;
  340. u32 bg = image->bg_color * 0x11111111;
  341. const u8 *src1, *src;
  342. u8 __iomem *dst1;
  343. u32 __iomem *dst;
  344. u32 val;
  345. int x, y;
  346. src1 = image->data;
  347. dst1 = info->screen_base + (image->dy * info->fix.line_length)
  348. + ((image->dx / 8) * 4);
  349. for (y = 0; y < image->height; y++) {
  350. src = src1;
  351. dst = (u32 __iomem *) dst1;
  352. for (x = 0; x < image->width; x += 8) {
  353. val = expand_pixel(*(src++));
  354. val = (val & fg) | (~val & bg);
  355. fb_writel(val, dst++);
  356. }
  357. src1 += image->width / 8;
  358. dst1 += info->fix.line_length;
  359. }
  360. }
  361. static void s3fb_imageblit(struct fb_info *info, const struct fb_image *image)
  362. {
  363. if ((info->var.bits_per_pixel == 4) && (image->depth == 1)
  364. && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) {
  365. if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)
  366. s3fb_iplan_imageblit(info, image);
  367. else
  368. s3fb_cfb4_imageblit(info, image);
  369. } else
  370. cfb_imageblit(info, image);
  371. }
  372. static void s3fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  373. {
  374. if ((info->var.bits_per_pixel == 4)
  375. && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0)
  376. && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES))
  377. s3fb_iplan_fillrect(info, rect);
  378. else
  379. cfb_fillrect(info, rect);
  380. }
  381. /* ------------------------------------------------------------------------- */
  382. static void s3_set_pixclock(struct fb_info *info, u32 pixclock)
  383. {
  384. struct s3fb_info *par = info->par;
  385. u16 m, n, r;
  386. u8 regval;
  387. int rv;
  388. rv = svga_compute_pll((par->chip == CHIP_365_TRIO3D) ? &s3_trio3d_pll : &s3_pll,
  389. 1000000000 / pixclock, &m, &n, &r, info->node);
  390. if (rv < 0) {
  391. printk(KERN_ERR "fb%d: cannot set requested pixclock, keeping old value\n", info->node);
  392. return;
  393. }
  394. /* Set VGA misc register */
  395. regval = vga_r(par->state.vgabase, VGA_MIS_R);
  396. vga_w(par->state.vgabase, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD);
  397. /* Set S3 clock registers */
  398. if (par->chip == CHIP_357_VIRGE_GX2 ||
  399. par->chip == CHIP_359_VIRGE_GX2P ||
  400. par->chip == CHIP_360_TRIO3D_1X ||
  401. par->chip == CHIP_362_TRIO3D_2X ||
  402. par->chip == CHIP_368_TRIO3D_2X) {
  403. vga_wseq(par->state.vgabase, 0x12, (n - 2) | ((r & 3) << 6)); /* n and two bits of r */
  404. vga_wseq(par->state.vgabase, 0x29, r >> 2); /* remaining highest bit of r */
  405. } else
  406. vga_wseq(par->state.vgabase, 0x12, (n - 2) | (r << 5));
  407. vga_wseq(par->state.vgabase, 0x13, m - 2);
  408. udelay(1000);
  409. /* Activate clock - write 0, 1, 0 to seq/15 bit 5 */
  410. regval = vga_rseq (par->state.vgabase, 0x15); /* | 0x80; */
  411. vga_wseq(par->state.vgabase, 0x15, regval & ~(1<<5));
  412. vga_wseq(par->state.vgabase, 0x15, regval | (1<<5));
  413. vga_wseq(par->state.vgabase, 0x15, regval & ~(1<<5));
  414. }
  415. /* Open framebuffer */
  416. static int s3fb_open(struct fb_info *info, int user)
  417. {
  418. struct s3fb_info *par = info->par;
  419. mutex_lock(&(par->open_lock));
  420. if (par->ref_count == 0) {
  421. void __iomem *vgabase = par->state.vgabase;
  422. memset(&(par->state), 0, sizeof(struct vgastate));
  423. par->state.vgabase = vgabase;
  424. par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP;
  425. par->state.num_crtc = 0x70;
  426. par->state.num_seq = 0x20;
  427. save_vga(&(par->state));
  428. }
  429. par->ref_count++;
  430. mutex_unlock(&(par->open_lock));
  431. return 0;
  432. }
  433. /* Close framebuffer */
  434. static int s3fb_release(struct fb_info *info, int user)
  435. {
  436. struct s3fb_info *par = info->par;
  437. mutex_lock(&(par->open_lock));
  438. if (par->ref_count == 0) {
  439. mutex_unlock(&(par->open_lock));
  440. return -EINVAL;
  441. }
  442. if (par->ref_count == 1)
  443. restore_vga(&(par->state));
  444. par->ref_count--;
  445. mutex_unlock(&(par->open_lock));
  446. return 0;
  447. }
  448. /* Validate passed in var */
  449. static int s3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  450. {
  451. struct s3fb_info *par = info->par;
  452. int rv, mem, step;
  453. u16 m, n, r;
  454. /* Find appropriate format */
  455. rv = svga_match_format (s3fb_formats, var, NULL);
  456. /* 32bpp mode is not supported on VIRGE VX,
  457. 24bpp is not supported on others */
  458. if ((par->chip == CHIP_988_VIRGE_VX) ? (rv == 7) : (rv == 6))
  459. rv = -EINVAL;
  460. if (rv < 0) {
  461. printk(KERN_ERR "fb%d: unsupported mode requested\n", info->node);
  462. return rv;
  463. }
  464. /* Do not allow to have real resoulution larger than virtual */
  465. if (var->xres > var->xres_virtual)
  466. var->xres_virtual = var->xres;
  467. if (var->yres > var->yres_virtual)
  468. var->yres_virtual = var->yres;
  469. /* Round up xres_virtual to have proper alignment of lines */
  470. step = s3fb_formats[rv].xresstep - 1;
  471. var->xres_virtual = (var->xres_virtual+step) & ~step;
  472. /* Check whether have enough memory */
  473. mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual;
  474. if (mem > info->screen_size) {
  475. printk(KERN_ERR "fb%d: not enough framebuffer memory (%d kB requested , %d kB available)\n",
  476. info->node, mem >> 10, (unsigned int) (info->screen_size >> 10));
  477. return -EINVAL;
  478. }
  479. rv = svga_check_timings (&s3_timing_regs, var, info->node);
  480. if (rv < 0) {
  481. printk(KERN_ERR "fb%d: invalid timings requested\n", info->node);
  482. return rv;
  483. }
  484. rv = svga_compute_pll(&s3_pll, PICOS2KHZ(var->pixclock), &m, &n, &r,
  485. info->node);
  486. if (rv < 0) {
  487. printk(KERN_ERR "fb%d: invalid pixclock value requested\n",
  488. info->node);
  489. return rv;
  490. }
  491. return 0;
  492. }
  493. /* Set video mode from par */
  494. static int s3fb_set_par(struct fb_info *info)
  495. {
  496. struct s3fb_info *par = info->par;
  497. u32 value, mode, hmul, offset_value, screen_size, multiplex, dbytes;
  498. u32 bpp = info->var.bits_per_pixel;
  499. u32 htotal, hsstart;
  500. if (bpp != 0) {
  501. info->fix.ypanstep = 1;
  502. info->fix.line_length = (info->var.xres_virtual * bpp) / 8;
  503. info->flags &= ~FBINFO_MISC_TILEBLITTING;
  504. info->tileops = NULL;
  505. /* in 4bpp supports 8p wide tiles only, any tiles otherwise */
  506. info->pixmap.blit_x = (bpp == 4) ? (1 << (8 - 1)) : (~(u32)0);
  507. info->pixmap.blit_y = ~(u32)0;
  508. offset_value = (info->var.xres_virtual * bpp) / 64;
  509. screen_size = info->var.yres_virtual * info->fix.line_length;
  510. } else {
  511. info->fix.ypanstep = 16;
  512. info->fix.line_length = 0;
  513. info->flags |= FBINFO_MISC_TILEBLITTING;
  514. info->tileops = fasttext ? &s3fb_fast_tile_ops : &s3fb_tile_ops;
  515. /* supports 8x16 tiles only */
  516. info->pixmap.blit_x = 1 << (8 - 1);
  517. info->pixmap.blit_y = 1 << (16 - 1);
  518. offset_value = info->var.xres_virtual / 16;
  519. screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
  520. }
  521. info->var.xoffset = 0;
  522. info->var.yoffset = 0;
  523. info->var.activate = FB_ACTIVATE_NOW;
  524. /* Unlock registers */
  525. vga_wcrt(par->state.vgabase, 0x38, 0x48);
  526. vga_wcrt(par->state.vgabase, 0x39, 0xA5);
  527. vga_wseq(par->state.vgabase, 0x08, 0x06);
  528. svga_wcrt_mask(par->state.vgabase, 0x11, 0x00, 0x80);
  529. /* Blank screen and turn off sync */
  530. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  531. svga_wcrt_mask(par->state.vgabase, 0x17, 0x00, 0x80);
  532. /* Set default values */
  533. svga_set_default_gfx_regs(par->state.vgabase);
  534. svga_set_default_atc_regs(par->state.vgabase);
  535. svga_set_default_seq_regs(par->state.vgabase);
  536. svga_set_default_crt_regs(par->state.vgabase);
  537. svga_wcrt_multi(par->state.vgabase, s3_line_compare_regs, 0xFFFFFFFF);
  538. svga_wcrt_multi(par->state.vgabase, s3_start_address_regs, 0);
  539. /* S3 specific initialization */
  540. svga_wcrt_mask(par->state.vgabase, 0x58, 0x10, 0x10); /* enable linear framebuffer */
  541. svga_wcrt_mask(par->state.vgabase, 0x31, 0x08, 0x08); /* enable sequencer access to framebuffer above 256 kB */
  542. /* svga_wcrt_mask(par->state.vgabase, 0x33, 0x08, 0x08); */ /* DDR ? */
  543. /* svga_wcrt_mask(par->state.vgabase, 0x43, 0x01, 0x01); */ /* DDR ? */
  544. svga_wcrt_mask(par->state.vgabase, 0x33, 0x00, 0x08); /* no DDR ? */
  545. svga_wcrt_mask(par->state.vgabase, 0x43, 0x00, 0x01); /* no DDR ? */
  546. svga_wcrt_mask(par->state.vgabase, 0x5D, 0x00, 0x28); /* Clear strange HSlen bits */
  547. /* svga_wcrt_mask(par->state.vgabase, 0x58, 0x03, 0x03); */
  548. /* svga_wcrt_mask(par->state.vgabase, 0x53, 0x12, 0x13); */ /* enable MMIO */
  549. /* svga_wcrt_mask(par->state.vgabase, 0x40, 0x08, 0x08); */ /* enable write buffer */
  550. /* Set the offset register */
  551. pr_debug("fb%d: offset register : %d\n", info->node, offset_value);
  552. svga_wcrt_multi(par->state.vgabase, s3_offset_regs, offset_value);
  553. if (par->chip != CHIP_357_VIRGE_GX2 &&
  554. par->chip != CHIP_359_VIRGE_GX2P &&
  555. par->chip != CHIP_360_TRIO3D_1X &&
  556. par->chip != CHIP_362_TRIO3D_2X &&
  557. par->chip != CHIP_368_TRIO3D_2X) {
  558. vga_wcrt(par->state.vgabase, 0x54, 0x18); /* M parameter */
  559. vga_wcrt(par->state.vgabase, 0x60, 0xff); /* N parameter */
  560. vga_wcrt(par->state.vgabase, 0x61, 0xff); /* L parameter */
  561. vga_wcrt(par->state.vgabase, 0x62, 0xff); /* L parameter */
  562. }
  563. vga_wcrt(par->state.vgabase, 0x3A, 0x35);
  564. svga_wattr(par->state.vgabase, 0x33, 0x00);
  565. if (info->var.vmode & FB_VMODE_DOUBLE)
  566. svga_wcrt_mask(par->state.vgabase, 0x09, 0x80, 0x80);
  567. else
  568. svga_wcrt_mask(par->state.vgabase, 0x09, 0x00, 0x80);
  569. if (info->var.vmode & FB_VMODE_INTERLACED)
  570. svga_wcrt_mask(par->state.vgabase, 0x42, 0x20, 0x20);
  571. else
  572. svga_wcrt_mask(par->state.vgabase, 0x42, 0x00, 0x20);
  573. /* Disable hardware graphics cursor */
  574. svga_wcrt_mask(par->state.vgabase, 0x45, 0x00, 0x01);
  575. /* Disable Streams engine */
  576. svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0x0C);
  577. mode = svga_match_format(s3fb_formats, &(info->var), &(info->fix));
  578. /* S3 virge DX hack */
  579. if (par->chip == CHIP_375_VIRGE_DX) {
  580. vga_wcrt(par->state.vgabase, 0x86, 0x80);
  581. vga_wcrt(par->state.vgabase, 0x90, 0x00);
  582. }
  583. /* S3 virge VX hack */
  584. if (par->chip == CHIP_988_VIRGE_VX) {
  585. vga_wcrt(par->state.vgabase, 0x50, 0x00);
  586. vga_wcrt(par->state.vgabase, 0x67, 0x50);
  587. vga_wcrt(par->state.vgabase, 0x63, (mode <= 2) ? 0x90 : 0x09);
  588. vga_wcrt(par->state.vgabase, 0x66, 0x90);
  589. }
  590. if (par->chip == CHIP_357_VIRGE_GX2 ||
  591. par->chip == CHIP_359_VIRGE_GX2P ||
  592. par->chip == CHIP_360_TRIO3D_1X ||
  593. par->chip == CHIP_362_TRIO3D_2X ||
  594. par->chip == CHIP_368_TRIO3D_2X ||
  595. par->chip == CHIP_365_TRIO3D ||
  596. par->chip == CHIP_375_VIRGE_DX ||
  597. par->chip == CHIP_385_VIRGE_GX) {
  598. dbytes = info->var.xres * ((bpp+7)/8);
  599. vga_wcrt(par->state.vgabase, 0x91, (dbytes + 7) / 8);
  600. vga_wcrt(par->state.vgabase, 0x90, (((dbytes + 7) / 8) >> 8) | 0x80);
  601. vga_wcrt(par->state.vgabase, 0x66, 0x81);
  602. }
  603. if (par->chip == CHIP_357_VIRGE_GX2 ||
  604. par->chip == CHIP_359_VIRGE_GX2P ||
  605. par->chip == CHIP_360_TRIO3D_1X ||
  606. par->chip == CHIP_362_TRIO3D_2X ||
  607. par->chip == CHIP_368_TRIO3D_2X)
  608. vga_wcrt(par->state.vgabase, 0x34, 0x00);
  609. else /* enable Data Transfer Position Control (DTPC) */
  610. vga_wcrt(par->state.vgabase, 0x34, 0x10);
  611. svga_wcrt_mask(par->state.vgabase, 0x31, 0x00, 0x40);
  612. multiplex = 0;
  613. hmul = 1;
  614. /* Set mode-specific register values */
  615. switch (mode) {
  616. case 0:
  617. pr_debug("fb%d: text mode\n", info->node);
  618. svga_set_textmode_vga_regs(par->state.vgabase);
  619. /* Set additional registers like in 8-bit mode */
  620. svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
  621. svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
  622. /* Disable enhanced mode */
  623. svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30);
  624. if (fasttext) {
  625. pr_debug("fb%d: high speed text mode set\n", info->node);
  626. svga_wcrt_mask(par->state.vgabase, 0x31, 0x40, 0x40);
  627. }
  628. break;
  629. case 1:
  630. pr_debug("fb%d: 4 bit pseudocolor\n", info->node);
  631. vga_wgfx(par->state.vgabase, VGA_GFX_MODE, 0x40);
  632. /* Set additional registers like in 8-bit mode */
  633. svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
  634. svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
  635. /* disable enhanced mode */
  636. svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30);
  637. break;
  638. case 2:
  639. pr_debug("fb%d: 4 bit pseudocolor, planar\n", info->node);
  640. /* Set additional registers like in 8-bit mode */
  641. svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
  642. svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
  643. /* disable enhanced mode */
  644. svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30);
  645. break;
  646. case 3:
  647. pr_debug("fb%d: 8 bit pseudocolor\n", info->node);
  648. svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
  649. if (info->var.pixclock > 20000 ||
  650. par->chip == CHIP_357_VIRGE_GX2 ||
  651. par->chip == CHIP_359_VIRGE_GX2P ||
  652. par->chip == CHIP_360_TRIO3D_1X ||
  653. par->chip == CHIP_362_TRIO3D_2X ||
  654. par->chip == CHIP_368_TRIO3D_2X)
  655. svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
  656. else {
  657. svga_wcrt_mask(par->state.vgabase, 0x67, 0x10, 0xF0);
  658. multiplex = 1;
  659. }
  660. break;
  661. case 4:
  662. pr_debug("fb%d: 5/5/5 truecolor\n", info->node);
  663. if (par->chip == CHIP_988_VIRGE_VX) {
  664. if (info->var.pixclock > 20000)
  665. svga_wcrt_mask(par->state.vgabase, 0x67, 0x20, 0xF0);
  666. else
  667. svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0);
  668. } else if (par->chip == CHIP_365_TRIO3D) {
  669. svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
  670. if (info->var.pixclock > 8695) {
  671. svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0);
  672. hmul = 2;
  673. } else {
  674. svga_wcrt_mask(par->state.vgabase, 0x67, 0x20, 0xF0);
  675. multiplex = 1;
  676. }
  677. } else {
  678. svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
  679. svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0);
  680. if (par->chip != CHIP_357_VIRGE_GX2 &&
  681. par->chip != CHIP_359_VIRGE_GX2P &&
  682. par->chip != CHIP_360_TRIO3D_1X &&
  683. par->chip != CHIP_362_TRIO3D_2X &&
  684. par->chip != CHIP_368_TRIO3D_2X)
  685. hmul = 2;
  686. }
  687. break;
  688. case 5:
  689. pr_debug("fb%d: 5/6/5 truecolor\n", info->node);
  690. if (par->chip == CHIP_988_VIRGE_VX) {
  691. if (info->var.pixclock > 20000)
  692. svga_wcrt_mask(par->state.vgabase, 0x67, 0x40, 0xF0);
  693. else
  694. svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
  695. } else if (par->chip == CHIP_365_TRIO3D) {
  696. svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
  697. if (info->var.pixclock > 8695) {
  698. svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
  699. hmul = 2;
  700. } else {
  701. svga_wcrt_mask(par->state.vgabase, 0x67, 0x40, 0xF0);
  702. multiplex = 1;
  703. }
  704. } else {
  705. svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
  706. svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
  707. if (par->chip != CHIP_357_VIRGE_GX2 &&
  708. par->chip != CHIP_359_VIRGE_GX2P &&
  709. par->chip != CHIP_360_TRIO3D_1X &&
  710. par->chip != CHIP_362_TRIO3D_2X &&
  711. par->chip != CHIP_368_TRIO3D_2X)
  712. hmul = 2;
  713. }
  714. break;
  715. case 6:
  716. /* VIRGE VX case */
  717. pr_debug("fb%d: 8/8/8 truecolor\n", info->node);
  718. svga_wcrt_mask(par->state.vgabase, 0x67, 0xD0, 0xF0);
  719. break;
  720. case 7:
  721. pr_debug("fb%d: 8/8/8/8 truecolor\n", info->node);
  722. svga_wcrt_mask(par->state.vgabase, 0x50, 0x30, 0x30);
  723. svga_wcrt_mask(par->state.vgabase, 0x67, 0xD0, 0xF0);
  724. break;
  725. default:
  726. printk(KERN_ERR "fb%d: unsupported mode - bug\n", info->node);
  727. return -EINVAL;
  728. }
  729. if (par->chip != CHIP_988_VIRGE_VX) {
  730. svga_wseq_mask(par->state.vgabase, 0x15, multiplex ? 0x10 : 0x00, 0x10);
  731. svga_wseq_mask(par->state.vgabase, 0x18, multiplex ? 0x80 : 0x00, 0x80);
  732. }
  733. s3_set_pixclock(info, info->var.pixclock);
  734. svga_set_timings(par->state.vgabase, &s3_timing_regs, &(info->var), hmul, 1,
  735. (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1,
  736. (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1,
  737. hmul, info->node);
  738. /* Set interlaced mode start/end register */
  739. htotal = info->var.xres + info->var.left_margin + info->var.right_margin + info->var.hsync_len;
  740. htotal = ((htotal * hmul) / 8) - 5;
  741. vga_wcrt(par->state.vgabase, 0x3C, (htotal + 1) / 2);
  742. /* Set Data Transfer Position */
  743. hsstart = ((info->var.xres + info->var.right_margin) * hmul) / 8;
  744. value = clamp((htotal + hsstart + 1) / 2, hsstart + 4, htotal + 1);
  745. svga_wcrt_multi(par->state.vgabase, s3_dtpc_regs, value);
  746. memset_io(info->screen_base, 0x00, screen_size);
  747. /* Device and screen back on */
  748. svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80);
  749. svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
  750. return 0;
  751. }
  752. /* Set a colour register */
  753. static int s3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  754. u_int transp, struct fb_info *fb)
  755. {
  756. switch (fb->var.bits_per_pixel) {
  757. case 0:
  758. case 4:
  759. if (regno >= 16)
  760. return -EINVAL;
  761. if ((fb->var.bits_per_pixel == 4) &&
  762. (fb->var.nonstd == 0)) {
  763. outb(0xF0, VGA_PEL_MSK);
  764. outb(regno*16, VGA_PEL_IW);
  765. } else {
  766. outb(0x0F, VGA_PEL_MSK);
  767. outb(regno, VGA_PEL_IW);
  768. }
  769. outb(red >> 10, VGA_PEL_D);
  770. outb(green >> 10, VGA_PEL_D);
  771. outb(blue >> 10, VGA_PEL_D);
  772. break;
  773. case 8:
  774. if (regno >= 256)
  775. return -EINVAL;
  776. outb(0xFF, VGA_PEL_MSK);
  777. outb(regno, VGA_PEL_IW);
  778. outb(red >> 10, VGA_PEL_D);
  779. outb(green >> 10, VGA_PEL_D);
  780. outb(blue >> 10, VGA_PEL_D);
  781. break;
  782. case 16:
  783. if (regno >= 16)
  784. return 0;
  785. if (fb->var.green.length == 5)
  786. ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
  787. ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);
  788. else if (fb->var.green.length == 6)
  789. ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |
  790. ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
  791. else return -EINVAL;
  792. break;
  793. case 24:
  794. case 32:
  795. if (regno >= 16)
  796. return 0;
  797. ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) |
  798. (green & 0xFF00) | ((blue & 0xFF00) >> 8);
  799. break;
  800. default:
  801. return -EINVAL;
  802. }
  803. return 0;
  804. }
  805. /* Set the display blanking state */
  806. static int s3fb_blank(int blank_mode, struct fb_info *info)
  807. {
  808. struct s3fb_info *par = info->par;
  809. switch (blank_mode) {
  810. case FB_BLANK_UNBLANK:
  811. pr_debug("fb%d: unblank\n", info->node);
  812. svga_wcrt_mask(par->state.vgabase, 0x56, 0x00, 0x06);
  813. svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
  814. break;
  815. case FB_BLANK_NORMAL:
  816. pr_debug("fb%d: blank\n", info->node);
  817. svga_wcrt_mask(par->state.vgabase, 0x56, 0x00, 0x06);
  818. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  819. break;
  820. case FB_BLANK_HSYNC_SUSPEND:
  821. pr_debug("fb%d: hsync\n", info->node);
  822. svga_wcrt_mask(par->state.vgabase, 0x56, 0x02, 0x06);
  823. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  824. break;
  825. case FB_BLANK_VSYNC_SUSPEND:
  826. pr_debug("fb%d: vsync\n", info->node);
  827. svga_wcrt_mask(par->state.vgabase, 0x56, 0x04, 0x06);
  828. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  829. break;
  830. case FB_BLANK_POWERDOWN:
  831. pr_debug("fb%d: sync down\n", info->node);
  832. svga_wcrt_mask(par->state.vgabase, 0x56, 0x06, 0x06);
  833. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  834. break;
  835. }
  836. return 0;
  837. }
  838. /* Pan the display */
  839. static int s3fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  840. {
  841. struct s3fb_info *par = info->par;
  842. unsigned int offset;
  843. /* Calculate the offset */
  844. if (var->bits_per_pixel == 0) {
  845. offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2);
  846. offset = offset >> 2;
  847. } else {
  848. offset = (var->yoffset * info->fix.line_length) +
  849. (var->xoffset * var->bits_per_pixel / 8);
  850. offset = offset >> 2;
  851. }
  852. /* Set the offset */
  853. svga_wcrt_multi(par->state.vgabase, s3_start_address_regs, offset);
  854. return 0;
  855. }
  856. /* ------------------------------------------------------------------------- */
  857. /* Frame buffer operations */
  858. static struct fb_ops s3fb_ops = {
  859. .owner = THIS_MODULE,
  860. .fb_open = s3fb_open,
  861. .fb_release = s3fb_release,
  862. .fb_check_var = s3fb_check_var,
  863. .fb_set_par = s3fb_set_par,
  864. .fb_setcolreg = s3fb_setcolreg,
  865. .fb_blank = s3fb_blank,
  866. .fb_pan_display = s3fb_pan_display,
  867. .fb_fillrect = s3fb_fillrect,
  868. .fb_copyarea = cfb_copyarea,
  869. .fb_imageblit = s3fb_imageblit,
  870. .fb_get_caps = svga_get_caps,
  871. };
  872. /* ------------------------------------------------------------------------- */
  873. static int __devinit s3_identification(struct s3fb_info *par)
  874. {
  875. int chip = par->chip;
  876. if (chip == CHIP_XXX_TRIO) {
  877. u8 cr30 = vga_rcrt(par->state.vgabase, 0x30);
  878. u8 cr2e = vga_rcrt(par->state.vgabase, 0x2e);
  879. u8 cr2f = vga_rcrt(par->state.vgabase, 0x2f);
  880. if ((cr30 == 0xE0) || (cr30 == 0xE1)) {
  881. if (cr2e == 0x10)
  882. return CHIP_732_TRIO32;
  883. if (cr2e == 0x11) {
  884. if (! (cr2f & 0x40))
  885. return CHIP_764_TRIO64;
  886. else
  887. return CHIP_765_TRIO64VP;
  888. }
  889. }
  890. }
  891. if (chip == CHIP_XXX_TRIO64V2_DXGX) {
  892. u8 cr6f = vga_rcrt(par->state.vgabase, 0x6f);
  893. if (! (cr6f & 0x01))
  894. return CHIP_775_TRIO64V2_DX;
  895. else
  896. return CHIP_785_TRIO64V2_GX;
  897. }
  898. if (chip == CHIP_XXX_VIRGE_DXGX) {
  899. u8 cr6f = vga_rcrt(par->state.vgabase, 0x6f);
  900. if (! (cr6f & 0x01))
  901. return CHIP_375_VIRGE_DX;
  902. else
  903. return CHIP_385_VIRGE_GX;
  904. }
  905. if (chip == CHIP_36X_TRIO3D_1X_2X) {
  906. switch (vga_rcrt(par->state.vgabase, 0x2f)) {
  907. case 0x00:
  908. return CHIP_360_TRIO3D_1X;
  909. case 0x01:
  910. return CHIP_362_TRIO3D_2X;
  911. case 0x02:
  912. return CHIP_368_TRIO3D_2X;
  913. }
  914. }
  915. return CHIP_UNKNOWN;
  916. }
  917. /* PCI probe */
  918. static int __devinit s3_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  919. {
  920. struct pci_bus_region bus_reg;
  921. struct resource vga_res;
  922. struct fb_info *info;
  923. struct s3fb_info *par;
  924. int rc;
  925. u8 regval, cr38, cr39;
  926. bool found = false;
  927. /* Ignore secondary VGA device because there is no VGA arbitration */
  928. if (! svga_primary_device(dev)) {
  929. dev_info(&(dev->dev), "ignoring secondary device\n");
  930. return -ENODEV;
  931. }
  932. /* Allocate and fill driver data structure */
  933. info = framebuffer_alloc(sizeof(struct s3fb_info), &(dev->dev));
  934. if (!info) {
  935. dev_err(&(dev->dev), "cannot allocate memory\n");
  936. return -ENOMEM;
  937. }
  938. par = info->par;
  939. mutex_init(&par->open_lock);
  940. info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
  941. info->fbops = &s3fb_ops;
  942. /* Prepare PCI device */
  943. rc = pci_enable_device(dev);
  944. if (rc < 0) {
  945. dev_err(info->device, "cannot enable PCI device\n");
  946. goto err_enable_device;
  947. }
  948. rc = pci_request_regions(dev, "s3fb");
  949. if (rc < 0) {
  950. dev_err(info->device, "cannot reserve framebuffer region\n");
  951. goto err_request_regions;
  952. }
  953. info->fix.smem_start = pci_resource_start(dev, 0);
  954. info->fix.smem_len = pci_resource_len(dev, 0);
  955. /* Map physical IO memory address into kernel space */
  956. info->screen_base = pci_iomap(dev, 0, 0);
  957. if (! info->screen_base) {
  958. rc = -ENOMEM;
  959. dev_err(info->device, "iomap for framebuffer failed\n");
  960. goto err_iomap;
  961. }
  962. bus_reg.start = 0;
  963. bus_reg.end = 64 * 1024;
  964. vga_res.flags = IORESOURCE_IO;
  965. pcibios_bus_to_resource(dev, &vga_res, &bus_reg);
  966. par->state.vgabase = (void __iomem *) vga_res.start;
  967. /* Unlock regs */
  968. cr38 = vga_rcrt(par->state.vgabase, 0x38);
  969. cr39 = vga_rcrt(par->state.vgabase, 0x39);
  970. vga_wseq(par->state.vgabase, 0x08, 0x06);
  971. vga_wcrt(par->state.vgabase, 0x38, 0x48);
  972. vga_wcrt(par->state.vgabase, 0x39, 0xA5);
  973. /* Identify chip type */
  974. par->chip = id->driver_data & CHIP_MASK;
  975. par->rev = vga_rcrt(par->state.vgabase, 0x2f);
  976. if (par->chip & CHIP_UNDECIDED_FLAG)
  977. par->chip = s3_identification(par);
  978. /* Find how many physical memory there is on card */
  979. /* 0x36 register is accessible even if other registers are locked */
  980. regval = vga_rcrt(par->state.vgabase, 0x36);
  981. if (par->chip == CHIP_360_TRIO3D_1X ||
  982. par->chip == CHIP_362_TRIO3D_2X ||
  983. par->chip == CHIP_368_TRIO3D_2X ||
  984. par->chip == CHIP_365_TRIO3D) {
  985. switch ((regval & 0xE0) >> 5) {
  986. case 0: /* 8MB -- only 4MB usable for display */
  987. case 1: /* 4MB with 32-bit bus */
  988. case 2: /* 4MB */
  989. info->screen_size = 4 << 20;
  990. break;
  991. case 4: /* 2MB on 365 Trio3D */
  992. case 6: /* 2MB */
  993. info->screen_size = 2 << 20;
  994. break;
  995. }
  996. } else if (par->chip == CHIP_357_VIRGE_GX2 ||
  997. par->chip == CHIP_359_VIRGE_GX2P) {
  998. switch ((regval & 0xC0) >> 6) {
  999. case 1: /* 4MB */
  1000. info->screen_size = 4 << 20;
  1001. break;
  1002. case 3: /* 2MB */
  1003. info->screen_size = 2 << 20;
  1004. break;
  1005. }
  1006. } else
  1007. info->screen_size = s3_memsizes[regval >> 5] << 10;
  1008. info->fix.smem_len = info->screen_size;
  1009. /* Find MCLK frequency */
  1010. regval = vga_rseq(par->state.vgabase, 0x10);
  1011. par->mclk_freq = ((vga_rseq(par->state.vgabase, 0x11) + 2) * 14318) / ((regval & 0x1F) + 2);
  1012. par->mclk_freq = par->mclk_freq >> (regval >> 5);
  1013. /* Restore locks */
  1014. vga_wcrt(par->state.vgabase, 0x38, cr38);
  1015. vga_wcrt(par->state.vgabase, 0x39, cr39);
  1016. strcpy(info->fix.id, s3_names [par->chip]);
  1017. info->fix.mmio_start = 0;
  1018. info->fix.mmio_len = 0;
  1019. info->fix.type = FB_TYPE_PACKED_PIXELS;
  1020. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  1021. info->fix.ypanstep = 0;
  1022. info->fix.accel = FB_ACCEL_NONE;
  1023. info->pseudo_palette = (void*) (par->pseudo_palette);
  1024. info->var.bits_per_pixel = 8;
  1025. #ifdef CONFIG_FB_S3_DDC
  1026. /* Enable MMIO if needed */
  1027. if (s3fb_ddc_needs_mmio(par->chip)) {
  1028. par->mmio = ioremap(info->fix.smem_start + MMIO_OFFSET, MMIO_SIZE);
  1029. if (par->mmio)
  1030. svga_wcrt_mask(par->state.vgabase, 0x53, 0x08, 0x08); /* enable MMIO */
  1031. else
  1032. dev_err(info->device, "unable to map MMIO at 0x%lx, disabling DDC",
  1033. info->fix.smem_start + MMIO_OFFSET);
  1034. }
  1035. if (!s3fb_ddc_needs_mmio(par->chip) || par->mmio)
  1036. if (s3fb_setup_ddc_bus(info) == 0) {
  1037. u8 *edid = fb_ddc_read(&par->ddc_adapter);
  1038. par->ddc_registered = true;
  1039. if (edid) {
  1040. fb_edid_to_monspecs(edid, &info->monspecs);
  1041. kfree(edid);
  1042. if (!info->monspecs.modedb)
  1043. dev_err(info->device, "error getting mode database\n");
  1044. else {
  1045. const struct fb_videomode *m;
  1046. fb_videomode_to_modelist(info->monspecs.modedb,
  1047. info->monspecs.modedb_len,
  1048. &info->modelist);
  1049. m = fb_find_best_display(&info->monspecs, &info->modelist);
  1050. if (m) {
  1051. fb_videomode_to_var(&info->var, m);
  1052. /* fill all other info->var's fields */
  1053. if (s3fb_check_var(&info->var, info) == 0)
  1054. found = true;
  1055. }
  1056. }
  1057. }
  1058. }
  1059. #endif
  1060. if (!mode_option && !found)
  1061. mode_option = "640x480-8@60";
  1062. /* Prepare startup mode */
  1063. if (mode_option) {
  1064. rc = fb_find_mode(&info->var, info, mode_option,
  1065. info->monspecs.modedb, info->monspecs.modedb_len,
  1066. NULL, info->var.bits_per_pixel);
  1067. if (!rc || rc == 4) {
  1068. rc = -EINVAL;
  1069. dev_err(info->device, "mode %s not found\n", mode_option);
  1070. fb_destroy_modedb(info->monspecs.modedb);
  1071. info->monspecs.modedb = NULL;
  1072. goto err_find_mode;
  1073. }
  1074. }
  1075. fb_destroy_modedb(info->monspecs.modedb);
  1076. info->monspecs.modedb = NULL;
  1077. /* maximize virtual vertical size for fast scrolling */
  1078. info->var.yres_virtual = info->fix.smem_len * 8 /
  1079. (info->var.bits_per_pixel * info->var.xres_virtual);
  1080. if (info->var.yres_virtual < info->var.yres) {
  1081. dev_err(info->device, "virtual vertical size smaller than real\n");
  1082. goto err_find_mode;
  1083. }
  1084. /* maximize virtual vertical size for fast scrolling */
  1085. info->var.yres_virtual = info->fix.smem_len * 8 /
  1086. (info->var.bits_per_pixel * info->var.xres_virtual);
  1087. if (info->var.yres_virtual < info->var.yres) {
  1088. dev_err(info->device, "virtual vertical size smaller than real\n");
  1089. goto err_find_mode;
  1090. }
  1091. rc = fb_alloc_cmap(&info->cmap, 256, 0);
  1092. if (rc < 0) {
  1093. dev_err(info->device, "cannot allocate colormap\n");
  1094. goto err_alloc_cmap;
  1095. }
  1096. rc = register_framebuffer(info);
  1097. if (rc < 0) {
  1098. dev_err(info->device, "cannot register framebuffer\n");
  1099. goto err_reg_fb;
  1100. }
  1101. printk(KERN_INFO "fb%d: %s on %s, %d MB RAM, %d MHz MCLK\n", info->node, info->fix.id,
  1102. pci_name(dev), info->fix.smem_len >> 20, (par->mclk_freq + 500) / 1000);
  1103. if (par->chip == CHIP_UNKNOWN)
  1104. printk(KERN_INFO "fb%d: unknown chip, CR2D=%x, CR2E=%x, CRT2F=%x, CRT30=%x\n",
  1105. info->node, vga_rcrt(par->state.vgabase, 0x2d), vga_rcrt(par->state.vgabase, 0x2e),
  1106. vga_rcrt(par->state.vgabase, 0x2f), vga_rcrt(par->state.vgabase, 0x30));
  1107. /* Record a reference to the driver data */
  1108. pci_set_drvdata(dev, info);
  1109. #ifdef CONFIG_MTRR
  1110. if (mtrr) {
  1111. par->mtrr_reg = -1;
  1112. par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1);
  1113. }
  1114. #endif
  1115. return 0;
  1116. /* Error handling */
  1117. err_reg_fb:
  1118. fb_dealloc_cmap(&info->cmap);
  1119. err_alloc_cmap:
  1120. err_find_mode:
  1121. #ifdef CONFIG_FB_S3_DDC
  1122. if (par->ddc_registered)
  1123. i2c_del_adapter(&par->ddc_adapter);
  1124. if (par->mmio)
  1125. iounmap(par->mmio);
  1126. #endif
  1127. pci_iounmap(dev, info->screen_base);
  1128. err_iomap:
  1129. pci_release_regions(dev);
  1130. err_request_regions:
  1131. /* pci_disable_device(dev); */
  1132. err_enable_device:
  1133. framebuffer_release(info);
  1134. return rc;
  1135. }
  1136. /* PCI remove */
  1137. static void __devexit s3_pci_remove(struct pci_dev *dev)
  1138. {
  1139. struct fb_info *info = pci_get_drvdata(dev);
  1140. struct s3fb_info __maybe_unused *par = info->par;
  1141. if (info) {
  1142. #ifdef CONFIG_MTRR
  1143. if (par->mtrr_reg >= 0) {
  1144. mtrr_del(par->mtrr_reg, 0, 0);
  1145. par->mtrr_reg = -1;
  1146. }
  1147. #endif
  1148. unregister_framebuffer(info);
  1149. fb_dealloc_cmap(&info->cmap);
  1150. #ifdef CONFIG_FB_S3_DDC
  1151. if (par->ddc_registered)
  1152. i2c_del_adapter(&par->ddc_adapter);
  1153. if (par->mmio)
  1154. iounmap(par->mmio);
  1155. #endif
  1156. pci_iounmap(dev, info->screen_base);
  1157. pci_release_regions(dev);
  1158. /* pci_disable_device(dev); */
  1159. pci_set_drvdata(dev, NULL);
  1160. framebuffer_release(info);
  1161. }
  1162. }
  1163. /* PCI suspend */
  1164. static int s3_pci_suspend(struct pci_dev* dev, pm_message_t state)
  1165. {
  1166. struct fb_info *info = pci_get_drvdata(dev);
  1167. struct s3fb_info *par = info->par;
  1168. dev_info(info->device, "suspend\n");
  1169. console_lock();
  1170. mutex_lock(&(par->open_lock));
  1171. if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {
  1172. mutex_unlock(&(par->open_lock));
  1173. console_unlock();
  1174. return 0;
  1175. }
  1176. fb_set_suspend(info, 1);
  1177. pci_save_state(dev);
  1178. pci_disable_device(dev);
  1179. pci_set_power_state(dev, pci_choose_state(dev, state));
  1180. mutex_unlock(&(par->open_lock));
  1181. console_unlock();
  1182. return 0;
  1183. }
  1184. /* PCI resume */
  1185. static int s3_pci_resume(struct pci_dev* dev)
  1186. {
  1187. struct fb_info *info = pci_get_drvdata(dev);
  1188. struct s3fb_info *par = info->par;
  1189. int err;
  1190. dev_info(info->device, "resume\n");
  1191. console_lock();
  1192. mutex_lock(&(par->open_lock));
  1193. if (par->ref_count == 0) {
  1194. mutex_unlock(&(par->open_lock));
  1195. console_unlock();
  1196. return 0;
  1197. }
  1198. pci_set_power_state(dev, PCI_D0);
  1199. pci_restore_state(dev);
  1200. err = pci_enable_device(dev);
  1201. if (err) {
  1202. mutex_unlock(&(par->open_lock));
  1203. console_unlock();
  1204. dev_err(info->device, "error %d enabling device for resume\n", err);
  1205. return err;
  1206. }
  1207. pci_set_master(dev);
  1208. s3fb_set_par(info);
  1209. fb_set_suspend(info, 0);
  1210. mutex_unlock(&(par->open_lock));
  1211. console_unlock();
  1212. return 0;
  1213. }
  1214. /* List of boards that we are trying to support */
  1215. static struct pci_device_id s3_devices[] __devinitdata = {
  1216. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8810), .driver_data = CHIP_XXX_TRIO},
  1217. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8811), .driver_data = CHIP_XXX_TRIO},
  1218. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8812), .driver_data = CHIP_M65_AURORA64VP},
  1219. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8814), .driver_data = CHIP_767_TRIO64UVP},
  1220. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8901), .driver_data = CHIP_XXX_TRIO64V2_DXGX},
  1221. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8902), .driver_data = CHIP_551_PLATO_PX},
  1222. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x5631), .driver_data = CHIP_325_VIRGE},
  1223. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x883D), .driver_data = CHIP_988_VIRGE_VX},
  1224. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A01), .driver_data = CHIP_XXX_VIRGE_DXGX},
  1225. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A10), .driver_data = CHIP_357_VIRGE_GX2},
  1226. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A11), .driver_data = CHIP_359_VIRGE_GX2P},
  1227. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A12), .driver_data = CHIP_359_VIRGE_GX2P},
  1228. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A13), .driver_data = CHIP_36X_TRIO3D_1X_2X},
  1229. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8904), .driver_data = CHIP_365_TRIO3D},
  1230. {0, 0, 0, 0, 0, 0, 0}
  1231. };
  1232. MODULE_DEVICE_TABLE(pci, s3_devices);
  1233. static struct pci_driver s3fb_pci_driver = {
  1234. .name = "s3fb",
  1235. .id_table = s3_devices,
  1236. .probe = s3_pci_probe,
  1237. .remove = __devexit_p(s3_pci_remove),
  1238. .suspend = s3_pci_suspend,
  1239. .resume = s3_pci_resume,
  1240. };
  1241. /* Parse user speficied options */
  1242. #ifndef MODULE
  1243. static int __init s3fb_setup(char *options)
  1244. {
  1245. char *opt;
  1246. if (!options || !*options)
  1247. return 0;
  1248. while ((opt = strsep(&options, ",")) != NULL) {
  1249. if (!*opt)
  1250. continue;
  1251. #ifdef CONFIG_MTRR
  1252. else if (!strncmp(opt, "mtrr:", 5))
  1253. mtrr = simple_strtoul(opt + 5, NULL, 0);
  1254. #endif
  1255. else if (!strncmp(opt, "fasttext:", 9))
  1256. fasttext = simple_strtoul(opt + 9, NULL, 0);
  1257. else
  1258. mode_option = opt;
  1259. }
  1260. return 0;
  1261. }
  1262. #endif
  1263. /* Cleanup */
  1264. static void __exit s3fb_cleanup(void)
  1265. {
  1266. pr_debug("s3fb: cleaning up\n");
  1267. pci_unregister_driver(&s3fb_pci_driver);
  1268. }
  1269. /* Driver Initialisation */
  1270. static int __init s3fb_init(void)
  1271. {
  1272. #ifndef MODULE
  1273. char *option = NULL;
  1274. if (fb_get_options("s3fb", &option))
  1275. return -ENODEV;
  1276. s3fb_setup(option);
  1277. #endif
  1278. pr_debug("s3fb: initializing\n");
  1279. return pci_register_driver(&s3fb_pci_driver);
  1280. }
  1281. /* ------------------------------------------------------------------------- */
  1282. /* Modularization */
  1283. module_init(s3fb_init);
  1284. module_exit(s3fb_cleanup);