s3fb.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  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/version.h>
  14. #include <linux/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/errno.h>
  17. #include <linux/string.h>
  18. #include <linux/mm.h>
  19. #include <linux/tty.h>
  20. #include <linux/slab.h>
  21. #include <linux/delay.h>
  22. #include <linux/fb.h>
  23. #include <linux/svga.h>
  24. #include <linux/init.h>
  25. #include <linux/pci.h>
  26. #include <linux/console.h> /* Why should fb driver call console functions? because acquire_console_sem() */
  27. #include <video/vga.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. };
  39. /* ------------------------------------------------------------------------- */
  40. static const struct svga_fb_format s3fb_formats[] = {
  41. { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
  42. FB_TYPE_TEXT, FB_AUX_TEXT_SVGA_STEP4, FB_VISUAL_PSEUDOCOLOR, 8, 16},
  43. { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
  44. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 16},
  45. { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 1,
  46. FB_TYPE_INTERLEAVED_PLANES, 1, FB_VISUAL_PSEUDOCOLOR, 8, 16},
  47. { 8, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
  48. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 4, 8},
  49. {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0,
  50. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 4},
  51. {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0,
  52. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 4},
  53. {24, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
  54. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 1, 2},
  55. {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
  56. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 1, 2},
  57. SVGA_FORMAT_END
  58. };
  59. static const struct svga_pll s3_pll = {3, 129, 3, 33, 0, 3,
  60. 60000, 240000, 14318};
  61. static const int s3_memsizes[] = {4096, 0, 3072, 8192, 2048, 6144, 1024, 512};
  62. static const char * const s3_names[] = {"S3 Unknown", "S3 Trio32", "S3 Trio64", "S3 Trio64V+",
  63. "S3 Trio64UV+", "S3 Trio64V2/DX", "S3 Trio64V2/GX",
  64. "S3 Plato/PX", "S3 Aurora64VP", "S3 Virge",
  65. "S3 Virge/VX", "S3 Virge/DX", "S3 Virge/GX",
  66. "S3 Virge/GX2", "S3 Virge/GX2P", "S3 Virge/GX2P"};
  67. #define CHIP_UNKNOWN 0x00
  68. #define CHIP_732_TRIO32 0x01
  69. #define CHIP_764_TRIO64 0x02
  70. #define CHIP_765_TRIO64VP 0x03
  71. #define CHIP_767_TRIO64UVP 0x04
  72. #define CHIP_775_TRIO64V2_DX 0x05
  73. #define CHIP_785_TRIO64V2_GX 0x06
  74. #define CHIP_551_PLATO_PX 0x07
  75. #define CHIP_M65_AURORA64VP 0x08
  76. #define CHIP_325_VIRGE 0x09
  77. #define CHIP_988_VIRGE_VX 0x0A
  78. #define CHIP_375_VIRGE_DX 0x0B
  79. #define CHIP_385_VIRGE_GX 0x0C
  80. #define CHIP_356_VIRGE_GX2 0x0D
  81. #define CHIP_357_VIRGE_GX2P 0x0E
  82. #define CHIP_359_VIRGE_GX2P 0x0F
  83. #define CHIP_XXX_TRIO 0x80
  84. #define CHIP_XXX_TRIO64V2_DXGX 0x81
  85. #define CHIP_XXX_VIRGE_DXGX 0x82
  86. #define CHIP_UNDECIDED_FLAG 0x80
  87. #define CHIP_MASK 0xFF
  88. /* CRT timing register sets */
  89. static const struct vga_regset s3_h_total_regs[] = {{0x00, 0, 7}, {0x5D, 0, 0}, VGA_REGSET_END};
  90. static const struct vga_regset s3_h_display_regs[] = {{0x01, 0, 7}, {0x5D, 1, 1}, VGA_REGSET_END};
  91. static const struct vga_regset s3_h_blank_start_regs[] = {{0x02, 0, 7}, {0x5D, 2, 2}, VGA_REGSET_END};
  92. static const struct vga_regset s3_h_blank_end_regs[] = {{0x03, 0, 4}, {0x05, 7, 7}, VGA_REGSET_END};
  93. static const struct vga_regset s3_h_sync_start_regs[] = {{0x04, 0, 7}, {0x5D, 4, 4}, VGA_REGSET_END};
  94. static const struct vga_regset s3_h_sync_end_regs[] = {{0x05, 0, 4}, VGA_REGSET_END};
  95. static const struct vga_regset s3_v_total_regs[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x5E, 0, 0}, VGA_REGSET_END};
  96. static const struct vga_regset s3_v_display_regs[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x5E, 1, 1}, VGA_REGSET_END};
  97. 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};
  98. static const struct vga_regset s3_v_blank_end_regs[] = {{0x16, 0, 7}, VGA_REGSET_END};
  99. 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};
  100. static const struct vga_regset s3_v_sync_end_regs[] = {{0x11, 0, 3}, VGA_REGSET_END};
  101. static const struct vga_regset s3_line_compare_regs[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, {0x5E, 6, 6}, VGA_REGSET_END};
  102. static const struct vga_regset s3_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x31, 4, 5}, {0x51, 0, 1}, VGA_REGSET_END};
  103. static const struct vga_regset s3_offset_regs[] = {{0x13, 0, 7}, {0x51, 4, 5}, VGA_REGSET_END}; /* set 0x43 bit 2 to 0 */
  104. static const struct svga_timing_regs s3_timing_regs = {
  105. s3_h_total_regs, s3_h_display_regs, s3_h_blank_start_regs,
  106. s3_h_blank_end_regs, s3_h_sync_start_regs, s3_h_sync_end_regs,
  107. s3_v_total_regs, s3_v_display_regs, s3_v_blank_start_regs,
  108. s3_v_blank_end_regs, s3_v_sync_start_regs, s3_v_sync_end_regs,
  109. };
  110. /* ------------------------------------------------------------------------- */
  111. /* Module parameters */
  112. static char *mode = "640x480-8@60";
  113. #ifdef CONFIG_MTRR
  114. static int mtrr = 1;
  115. #endif
  116. static int fasttext = 1;
  117. MODULE_AUTHOR("(c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>");
  118. MODULE_LICENSE("GPL");
  119. MODULE_DESCRIPTION("fbdev driver for S3 Trio/Virge");
  120. module_param(mode, charp, 0444);
  121. MODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc)");
  122. #ifdef CONFIG_MTRR
  123. module_param(mtrr, int, 0444);
  124. MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)");
  125. #endif
  126. module_param(fasttext, int, 0644);
  127. MODULE_PARM_DESC(fasttext, "Enable S3 fast text mode (1=enable, 0=disable, default=1)");
  128. /* ------------------------------------------------------------------------- */
  129. /* Set font in S3 fast text mode */
  130. static void s3fb_settile_fast(struct fb_info *info, struct fb_tilemap *map)
  131. {
  132. const u8 *font = map->data;
  133. u8 __iomem *fb = (u8 __iomem *) info->screen_base;
  134. int i, c;
  135. if ((map->width != 8) || (map->height != 16) ||
  136. (map->depth != 1) || (map->length != 256)) {
  137. printk(KERN_ERR "fb%d: unsupported font parameters: width %d, height %d, depth %d, length %d\n",
  138. info->node, map->width, map->height, map->depth, map->length);
  139. return;
  140. }
  141. fb += 2;
  142. for (i = 0; i < map->height; i++) {
  143. for (c = 0; c < map->length; c++) {
  144. fb_writeb(font[c * map->height + i], fb + c * 4);
  145. }
  146. fb += 1024;
  147. }
  148. }
  149. static struct fb_tile_ops s3fb_tile_ops = {
  150. .fb_settile = svga_settile,
  151. .fb_tilecopy = svga_tilecopy,
  152. .fb_tilefill = svga_tilefill,
  153. .fb_tileblit = svga_tileblit,
  154. .fb_tilecursor = svga_tilecursor,
  155. };
  156. static struct fb_tile_ops s3fb_fast_tile_ops = {
  157. .fb_settile = s3fb_settile_fast,
  158. .fb_tilecopy = svga_tilecopy,
  159. .fb_tilefill = svga_tilefill,
  160. .fb_tileblit = svga_tileblit,
  161. .fb_tilecursor = svga_tilecursor,
  162. };
  163. /* ------------------------------------------------------------------------- */
  164. /* image data is MSB-first, fb structure is MSB-first too */
  165. static inline u32 expand_color(u32 c)
  166. {
  167. return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF;
  168. }
  169. /* s3fb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */
  170. static void s3fb_iplan_imageblit(struct fb_info *info, const struct fb_image *image)
  171. {
  172. u32 fg = expand_color(image->fg_color);
  173. u32 bg = expand_color(image->bg_color);
  174. const u8 *src1, *src;
  175. u8 __iomem *dst1;
  176. u32 __iomem *dst;
  177. u32 val;
  178. int x, y;
  179. src1 = image->data;
  180. dst1 = info->screen_base + (image->dy * info->fix.line_length)
  181. + ((image->dx / 8) * 4);
  182. for (y = 0; y < image->height; y++) {
  183. src = src1;
  184. dst = (u32 __iomem *) dst1;
  185. for (x = 0; x < image->width; x += 8) {
  186. val = *(src++) * 0x01010101;
  187. val = (val & fg) | (~val & bg);
  188. fb_writel(val, dst++);
  189. }
  190. src1 += image->width / 8;
  191. dst1 += info->fix.line_length;
  192. }
  193. }
  194. /* s3fb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */
  195. static void s3fb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  196. {
  197. u32 fg = expand_color(rect->color);
  198. u8 __iomem *dst1;
  199. u32 __iomem *dst;
  200. int x, y;
  201. dst1 = info->screen_base + (rect->dy * info->fix.line_length)
  202. + ((rect->dx / 8) * 4);
  203. for (y = 0; y < rect->height; y++) {
  204. dst = (u32 __iomem *) dst1;
  205. for (x = 0; x < rect->width; x += 8) {
  206. fb_writel(fg, dst++);
  207. }
  208. dst1 += info->fix.line_length;
  209. }
  210. }
  211. /* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */
  212. static inline u32 expand_pixel(u32 c)
  213. {
  214. return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) |
  215. ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF;
  216. }
  217. /* s3fb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */
  218. static void s3fb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image)
  219. {
  220. u32 fg = image->fg_color * 0x11111111;
  221. u32 bg = image->bg_color * 0x11111111;
  222. const u8 *src1, *src;
  223. u8 __iomem *dst1;
  224. u32 __iomem *dst;
  225. u32 val;
  226. int x, y;
  227. src1 = image->data;
  228. dst1 = info->screen_base + (image->dy * info->fix.line_length)
  229. + ((image->dx / 8) * 4);
  230. for (y = 0; y < image->height; y++) {
  231. src = src1;
  232. dst = (u32 __iomem *) dst1;
  233. for (x = 0; x < image->width; x += 8) {
  234. val = expand_pixel(*(src++));
  235. val = (val & fg) | (~val & bg);
  236. fb_writel(val, dst++);
  237. }
  238. src1 += image->width / 8;
  239. dst1 += info->fix.line_length;
  240. }
  241. }
  242. static void s3fb_imageblit(struct fb_info *info, const struct fb_image *image)
  243. {
  244. if ((info->var.bits_per_pixel == 4) && (image->depth == 1)
  245. && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) {
  246. if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)
  247. s3fb_iplan_imageblit(info, image);
  248. else
  249. s3fb_cfb4_imageblit(info, image);
  250. } else
  251. cfb_imageblit(info, image);
  252. }
  253. static void s3fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  254. {
  255. if ((info->var.bits_per_pixel == 4)
  256. && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0)
  257. && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES))
  258. s3fb_iplan_fillrect(info, rect);
  259. else
  260. cfb_fillrect(info, rect);
  261. }
  262. /* ------------------------------------------------------------------------- */
  263. static void s3_set_pixclock(struct fb_info *info, u32 pixclock)
  264. {
  265. u16 m, n, r;
  266. u8 regval;
  267. svga_compute_pll(&s3_pll, 1000000000 / pixclock, &m, &n, &r, info->node);
  268. /* Set VGA misc register */
  269. regval = vga_r(NULL, VGA_MIS_R);
  270. vga_w(NULL, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD);
  271. /* Set S3 clock registers */
  272. vga_wseq(NULL, 0x12, ((n - 2) | (r << 5)));
  273. vga_wseq(NULL, 0x13, m - 2);
  274. udelay(1000);
  275. /* Activate clock - write 0, 1, 0 to seq/15 bit 5 */
  276. regval = vga_rseq (NULL, 0x15); /* | 0x80; */
  277. vga_wseq(NULL, 0x15, regval & ~(1<<5));
  278. vga_wseq(NULL, 0x15, regval | (1<<5));
  279. vga_wseq(NULL, 0x15, regval & ~(1<<5));
  280. }
  281. /* Open framebuffer */
  282. static int s3fb_open(struct fb_info *info, int user)
  283. {
  284. struct s3fb_info *par = info->par;
  285. mutex_lock(&(par->open_lock));
  286. if (par->ref_count == 0) {
  287. memset(&(par->state), 0, sizeof(struct vgastate));
  288. par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP;
  289. par->state.num_crtc = 0x70;
  290. par->state.num_seq = 0x20;
  291. save_vga(&(par->state));
  292. }
  293. par->ref_count++;
  294. mutex_unlock(&(par->open_lock));
  295. return 0;
  296. }
  297. /* Close framebuffer */
  298. static int s3fb_release(struct fb_info *info, int user)
  299. {
  300. struct s3fb_info *par = info->par;
  301. mutex_lock(&(par->open_lock));
  302. if (par->ref_count == 0) {
  303. mutex_unlock(&(par->open_lock));
  304. return -EINVAL;
  305. }
  306. if (par->ref_count == 1)
  307. restore_vga(&(par->state));
  308. par->ref_count--;
  309. mutex_unlock(&(par->open_lock));
  310. return 0;
  311. }
  312. /* Validate passed in var */
  313. static int s3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  314. {
  315. struct s3fb_info *par = info->par;
  316. int rv, mem, step;
  317. /* Find appropriate format */
  318. rv = svga_match_format (s3fb_formats, var, NULL);
  319. if ((rv < 0) || ((par->chip == CHIP_988_VIRGE_VX) ? (rv == 7) : (rv == 6)))
  320. { /* 24bpp on VIRGE VX, 32bpp on others */
  321. printk(KERN_ERR "fb%d: unsupported mode requested\n", info->node);
  322. return rv;
  323. }
  324. /* Do not allow to have real resoulution larger than virtual */
  325. if (var->xres > var->xres_virtual)
  326. var->xres_virtual = var->xres;
  327. if (var->yres > var->yres_virtual)
  328. var->yres_virtual = var->yres;
  329. /* Round up xres_virtual to have proper alignment of lines */
  330. step = s3fb_formats[rv].xresstep - 1;
  331. var->xres_virtual = (var->xres_virtual+step) & ~step;
  332. /* Check whether have enough memory */
  333. mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual;
  334. if (mem > info->screen_size)
  335. {
  336. printk(KERN_ERR "fb%d: not enough framebuffer memory (%d kB requested , %d kB available)\n",
  337. info->node, mem >> 10, (unsigned int) (info->screen_size >> 10));
  338. return -EINVAL;
  339. }
  340. rv = svga_check_timings (&s3_timing_regs, var, info->node);
  341. if (rv < 0)
  342. {
  343. printk(KERN_ERR "fb%d: invalid timings requested\n", info->node);
  344. return rv;
  345. }
  346. return 0;
  347. }
  348. /* Set video mode from par */
  349. static int s3fb_set_par(struct fb_info *info)
  350. {
  351. struct s3fb_info *par = info->par;
  352. u32 value, mode, hmul, offset_value, screen_size, multiplex;
  353. u32 bpp = info->var.bits_per_pixel;
  354. if (bpp != 0) {
  355. info->fix.ypanstep = 1;
  356. info->fix.line_length = (info->var.xres_virtual * bpp) / 8;
  357. info->flags &= ~FBINFO_MISC_TILEBLITTING;
  358. info->tileops = NULL;
  359. /* supports blit rectangles of any dimension */
  360. info->pixmap.blit_x = ~(u32)0;
  361. info->pixmap.blit_y = ~(u32)0;
  362. offset_value = (info->var.xres_virtual * bpp) / 64;
  363. screen_size = info->var.yres_virtual * info->fix.line_length;
  364. } else {
  365. info->fix.ypanstep = 16;
  366. info->fix.line_length = 0;
  367. info->flags |= FBINFO_MISC_TILEBLITTING;
  368. info->tileops = fasttext ? &s3fb_fast_tile_ops : &s3fb_tile_ops;
  369. /* supports 8x16 tiles only */
  370. info->pixmap.blit_x = 1 << (8 - 1);
  371. info->pixmap.blit_y = 1 << (16 - 1);
  372. offset_value = info->var.xres_virtual / 16;
  373. screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
  374. }
  375. info->var.xoffset = 0;
  376. info->var.yoffset = 0;
  377. info->var.activate = FB_ACTIVATE_NOW;
  378. /* Unlock registers */
  379. vga_wcrt(NULL, 0x38, 0x48);
  380. vga_wcrt(NULL, 0x39, 0xA5);
  381. vga_wseq(NULL, 0x08, 0x06);
  382. svga_wcrt_mask(0x11, 0x00, 0x80);
  383. /* Blank screen and turn off sync */
  384. svga_wseq_mask(0x01, 0x20, 0x20);
  385. svga_wcrt_mask(0x17, 0x00, 0x80);
  386. /* Set default values */
  387. svga_set_default_gfx_regs();
  388. svga_set_default_atc_regs();
  389. svga_set_default_seq_regs();
  390. svga_set_default_crt_regs();
  391. svga_wcrt_multi(s3_line_compare_regs, 0xFFFFFFFF);
  392. svga_wcrt_multi(s3_start_address_regs, 0);
  393. /* S3 specific initialization */
  394. svga_wcrt_mask(0x58, 0x10, 0x10); /* enable linear framebuffer */
  395. svga_wcrt_mask(0x31, 0x08, 0x08); /* enable sequencer access to framebuffer above 256 kB */
  396. /* svga_wcrt_mask(0x33, 0x08, 0x08); */ /* DDR ? */
  397. /* svga_wcrt_mask(0x43, 0x01, 0x01); */ /* DDR ? */
  398. svga_wcrt_mask(0x33, 0x00, 0x08); /* no DDR ? */
  399. svga_wcrt_mask(0x43, 0x00, 0x01); /* no DDR ? */
  400. svga_wcrt_mask(0x5D, 0x00, 0x28); // Clear strange HSlen bits
  401. /* svga_wcrt_mask(0x58, 0x03, 0x03); */
  402. /* svga_wcrt_mask(0x53, 0x12, 0x13); */ /* enable MMIO */
  403. /* svga_wcrt_mask(0x40, 0x08, 0x08); */ /* enable write buffer */
  404. /* Set the offset register */
  405. pr_debug("fb%d: offset register : %d\n", info->node, offset_value);
  406. svga_wcrt_multi(s3_offset_regs, offset_value);
  407. vga_wcrt(NULL, 0x54, 0x18); /* M parameter */
  408. vga_wcrt(NULL, 0x60, 0xff); /* N parameter */
  409. vga_wcrt(NULL, 0x61, 0xff); /* L parameter */
  410. vga_wcrt(NULL, 0x62, 0xff); /* L parameter */
  411. vga_wcrt(NULL, 0x3A, 0x35);
  412. svga_wattr(0x33, 0x00);
  413. if (info->var.vmode & FB_VMODE_DOUBLE)
  414. svga_wcrt_mask(0x09, 0x80, 0x80);
  415. else
  416. svga_wcrt_mask(0x09, 0x00, 0x80);
  417. if (info->var.vmode & FB_VMODE_INTERLACED)
  418. svga_wcrt_mask(0x42, 0x20, 0x20);
  419. else
  420. svga_wcrt_mask(0x42, 0x00, 0x20);
  421. /* Disable hardware graphics cursor */
  422. svga_wcrt_mask(0x45, 0x00, 0x01);
  423. /* Disable Streams engine */
  424. svga_wcrt_mask(0x67, 0x00, 0x0C);
  425. mode = svga_match_format(s3fb_formats, &(info->var), &(info->fix));
  426. /* S3 virge DX hack */
  427. if (par->chip == CHIP_375_VIRGE_DX) {
  428. vga_wcrt(NULL, 0x86, 0x80);
  429. vga_wcrt(NULL, 0x90, 0x00);
  430. }
  431. /* S3 virge VX hack */
  432. if (par->chip == CHIP_988_VIRGE_VX) {
  433. vga_wcrt(NULL, 0x50, 0x00);
  434. vga_wcrt(NULL, 0x67, 0x50);
  435. vga_wcrt(NULL, 0x63, (mode <= 2) ? 0x90 : 0x09);
  436. vga_wcrt(NULL, 0x66, 0x90);
  437. }
  438. svga_wcrt_mask(0x31, 0x00, 0x40);
  439. multiplex = 0;
  440. hmul = 1;
  441. /* Set mode-specific register values */
  442. switch (mode) {
  443. case 0:
  444. pr_debug("fb%d: text mode\n", info->node);
  445. svga_set_textmode_vga_regs();
  446. /* Set additional registers like in 8-bit mode */
  447. svga_wcrt_mask(0x50, 0x00, 0x30);
  448. svga_wcrt_mask(0x67, 0x00, 0xF0);
  449. /* Disable enhanced mode */
  450. svga_wcrt_mask(0x3A, 0x00, 0x30);
  451. if (fasttext) {
  452. pr_debug("fb%d: high speed text mode set\n", info->node);
  453. svga_wcrt_mask(0x31, 0x40, 0x40);
  454. }
  455. break;
  456. case 1:
  457. pr_debug("fb%d: 4 bit pseudocolor\n", info->node);
  458. vga_wgfx(NULL, VGA_GFX_MODE, 0x40);
  459. /* Set additional registers like in 8-bit mode */
  460. svga_wcrt_mask(0x50, 0x00, 0x30);
  461. svga_wcrt_mask(0x67, 0x00, 0xF0);
  462. /* disable enhanced mode */
  463. svga_wcrt_mask(0x3A, 0x00, 0x30);
  464. break;
  465. case 2:
  466. pr_debug("fb%d: 4 bit pseudocolor, planar\n", info->node);
  467. /* Set additional registers like in 8-bit mode */
  468. svga_wcrt_mask(0x50, 0x00, 0x30);
  469. svga_wcrt_mask(0x67, 0x00, 0xF0);
  470. /* disable enhanced mode */
  471. svga_wcrt_mask(0x3A, 0x00, 0x30);
  472. break;
  473. case 3:
  474. pr_debug("fb%d: 8 bit pseudocolor\n", info->node);
  475. if (info->var.pixclock > 20000) {
  476. svga_wcrt_mask(0x50, 0x00, 0x30);
  477. svga_wcrt_mask(0x67, 0x00, 0xF0);
  478. } else {
  479. svga_wcrt_mask(0x50, 0x00, 0x30);
  480. svga_wcrt_mask(0x67, 0x10, 0xF0);
  481. multiplex = 1;
  482. }
  483. break;
  484. case 4:
  485. pr_debug("fb%d: 5/5/5 truecolor\n", info->node);
  486. if (par->chip == CHIP_988_VIRGE_VX) {
  487. if (info->var.pixclock > 20000)
  488. svga_wcrt_mask(0x67, 0x20, 0xF0);
  489. else
  490. svga_wcrt_mask(0x67, 0x30, 0xF0);
  491. } else {
  492. svga_wcrt_mask(0x50, 0x10, 0x30);
  493. svga_wcrt_mask(0x67, 0x30, 0xF0);
  494. hmul = 2;
  495. }
  496. break;
  497. case 5:
  498. pr_debug("fb%d: 5/6/5 truecolor\n", info->node);
  499. if (par->chip == CHIP_988_VIRGE_VX) {
  500. if (info->var.pixclock > 20000)
  501. svga_wcrt_mask(0x67, 0x40, 0xF0);
  502. else
  503. svga_wcrt_mask(0x67, 0x50, 0xF0);
  504. } else {
  505. svga_wcrt_mask(0x50, 0x10, 0x30);
  506. svga_wcrt_mask(0x67, 0x50, 0xF0);
  507. hmul = 2;
  508. }
  509. break;
  510. case 6:
  511. /* VIRGE VX case */
  512. pr_debug("fb%d: 8/8/8 truecolor\n", info->node);
  513. svga_wcrt_mask(0x67, 0xD0, 0xF0);
  514. break;
  515. case 7:
  516. pr_debug("fb%d: 8/8/8/8 truecolor\n", info->node);
  517. svga_wcrt_mask(0x50, 0x30, 0x30);
  518. svga_wcrt_mask(0x67, 0xD0, 0xF0);
  519. break;
  520. default:
  521. printk(KERN_ERR "fb%d: unsupported mode - bug\n", info->node);
  522. return -EINVAL;
  523. }
  524. if (par->chip != CHIP_988_VIRGE_VX) {
  525. svga_wseq_mask(0x15, multiplex ? 0x10 : 0x00, 0x10);
  526. svga_wseq_mask(0x18, multiplex ? 0x80 : 0x00, 0x80);
  527. }
  528. s3_set_pixclock(info, info->var.pixclock);
  529. svga_set_timings(&s3_timing_regs, &(info->var), hmul, 1,
  530. (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1,
  531. (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1,
  532. hmul, info->node);
  533. /* Set interlaced mode start/end register */
  534. value = info->var.xres + info->var.left_margin + info->var.right_margin + info->var.hsync_len;
  535. value = ((value * hmul) / 8) - 5;
  536. vga_wcrt(NULL, 0x3C, (value + 1) / 2);
  537. memset_io(info->screen_base, 0x00, screen_size);
  538. /* Device and screen back on */
  539. svga_wcrt_mask(0x17, 0x80, 0x80);
  540. svga_wseq_mask(0x01, 0x00, 0x20);
  541. return 0;
  542. }
  543. /* Set a colour register */
  544. static int s3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  545. u_int transp, struct fb_info *fb)
  546. {
  547. switch (fb->var.bits_per_pixel) {
  548. case 0:
  549. case 4:
  550. if (regno >= 16)
  551. return -EINVAL;
  552. if ((fb->var.bits_per_pixel == 4) &&
  553. (fb->var.nonstd == 0)) {
  554. outb(0xF0, VGA_PEL_MSK);
  555. outb(regno*16, VGA_PEL_IW);
  556. } else {
  557. outb(0x0F, VGA_PEL_MSK);
  558. outb(regno, VGA_PEL_IW);
  559. }
  560. outb(red >> 10, VGA_PEL_D);
  561. outb(green >> 10, VGA_PEL_D);
  562. outb(blue >> 10, VGA_PEL_D);
  563. break;
  564. case 8:
  565. if (regno >= 256)
  566. return -EINVAL;
  567. outb(0xFF, VGA_PEL_MSK);
  568. outb(regno, VGA_PEL_IW);
  569. outb(red >> 10, VGA_PEL_D);
  570. outb(green >> 10, VGA_PEL_D);
  571. outb(blue >> 10, VGA_PEL_D);
  572. break;
  573. case 16:
  574. if (regno >= 16)
  575. return -EINVAL;
  576. if (fb->var.green.length == 5)
  577. ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
  578. ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);
  579. else if (fb->var.green.length == 6)
  580. ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |
  581. ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
  582. else return -EINVAL;
  583. break;
  584. case 24:
  585. case 32:
  586. if (regno >= 16)
  587. return -EINVAL;
  588. ((u32*)fb->pseudo_palette)[regno] = ((transp & 0xFF00) << 16) | ((red & 0xFF00) << 8) |
  589. (green & 0xFF00) | ((blue & 0xFF00) >> 8);
  590. break;
  591. default:
  592. return -EINVAL;
  593. }
  594. return 0;
  595. }
  596. /* Set the display blanking state */
  597. static int s3fb_blank(int blank_mode, struct fb_info *info)
  598. {
  599. switch (blank_mode) {
  600. case FB_BLANK_UNBLANK:
  601. pr_debug("fb%d: unblank\n", info->node);
  602. svga_wcrt_mask(0x56, 0x00, 0x06);
  603. svga_wseq_mask(0x01, 0x00, 0x20);
  604. break;
  605. case FB_BLANK_NORMAL:
  606. pr_debug("fb%d: blank\n", info->node);
  607. svga_wcrt_mask(0x56, 0x00, 0x06);
  608. svga_wseq_mask(0x01, 0x20, 0x20);
  609. break;
  610. case FB_BLANK_HSYNC_SUSPEND:
  611. pr_debug("fb%d: hsync\n", info->node);
  612. svga_wcrt_mask(0x56, 0x02, 0x06);
  613. svga_wseq_mask(0x01, 0x20, 0x20);
  614. break;
  615. case FB_BLANK_VSYNC_SUSPEND:
  616. pr_debug("fb%d: vsync\n", info->node);
  617. svga_wcrt_mask(0x56, 0x04, 0x06);
  618. svga_wseq_mask(0x01, 0x20, 0x20);
  619. break;
  620. case FB_BLANK_POWERDOWN:
  621. pr_debug("fb%d: sync down\n", info->node);
  622. svga_wcrt_mask(0x56, 0x06, 0x06);
  623. svga_wseq_mask(0x01, 0x20, 0x20);
  624. break;
  625. }
  626. return 0;
  627. }
  628. /* Pan the display */
  629. static int s3fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) {
  630. unsigned int offset;
  631. /* Validate the offsets */
  632. if ((var->xoffset + var->xres) > var->xres_virtual)
  633. return -EINVAL;
  634. if ((var->yoffset + var->yres) > var->yres_virtual)
  635. return -EINVAL;
  636. /* Calculate the offset */
  637. if (var->bits_per_pixel == 0) {
  638. offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2);
  639. offset = offset >> 2;
  640. } else {
  641. offset = (var->yoffset * info->fix.line_length) +
  642. (var->xoffset * var->bits_per_pixel / 8);
  643. offset = offset >> 2;
  644. }
  645. /* Set the offset */
  646. svga_wcrt_multi(s3_start_address_regs, offset);
  647. return 0;
  648. }
  649. /* ------------------------------------------------------------------------- */
  650. /* Frame buffer operations */
  651. static struct fb_ops s3fb_ops = {
  652. .owner = THIS_MODULE,
  653. .fb_open = s3fb_open,
  654. .fb_release = s3fb_release,
  655. .fb_check_var = s3fb_check_var,
  656. .fb_set_par = s3fb_set_par,
  657. .fb_setcolreg = s3fb_setcolreg,
  658. .fb_blank = s3fb_blank,
  659. .fb_pan_display = s3fb_pan_display,
  660. .fb_fillrect = s3fb_fillrect,
  661. .fb_copyarea = cfb_copyarea,
  662. .fb_imageblit = s3fb_imageblit,
  663. };
  664. /* ------------------------------------------------------------------------- */
  665. static int __devinit s3_identification(int chip)
  666. {
  667. if (chip == CHIP_XXX_TRIO) {
  668. u8 cr30 = vga_rcrt(NULL, 0x30);
  669. u8 cr2e = vga_rcrt(NULL, 0x2e);
  670. u8 cr2f = vga_rcrt(NULL, 0x2f);
  671. if ((cr30 == 0xE0) || (cr30 == 0xE1)) {
  672. if (cr2e == 0x10)
  673. return CHIP_732_TRIO32;
  674. if (cr2e == 0x11) {
  675. if (! (cr2f & 0x40))
  676. return CHIP_764_TRIO64;
  677. else
  678. return CHIP_765_TRIO64VP;
  679. }
  680. }
  681. }
  682. if (chip == CHIP_XXX_TRIO64V2_DXGX) {
  683. u8 cr6f = vga_rcrt(NULL, 0x6f);
  684. if (! (cr6f & 0x01))
  685. return CHIP_775_TRIO64V2_DX;
  686. else
  687. return CHIP_785_TRIO64V2_GX;
  688. }
  689. if (chip == CHIP_XXX_VIRGE_DXGX) {
  690. u8 cr6f = vga_rcrt(NULL, 0x6f);
  691. if (! (cr6f & 0x01))
  692. return CHIP_375_VIRGE_DX;
  693. else
  694. return CHIP_385_VIRGE_GX;
  695. }
  696. return CHIP_UNKNOWN;
  697. }
  698. /* PCI probe */
  699. static int __devinit s3_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  700. {
  701. struct fb_info *info;
  702. struct s3fb_info *par;
  703. int rc;
  704. u8 regval, cr38, cr39;
  705. /* Ignore secondary VGA device because there is no VGA arbitration */
  706. if (! svga_primary_device(dev)) {
  707. dev_info(&(dev->dev), "ignoring secondary device\n");
  708. return -ENODEV;
  709. }
  710. /* Allocate and fill driver data structure */
  711. info = framebuffer_alloc(sizeof(struct s3fb_info), NULL);
  712. if (!info) {
  713. dev_err(&(dev->dev), "cannot allocate memory\n");
  714. return -ENOMEM;
  715. }
  716. par = info->par;
  717. mutex_init(&par->open_lock);
  718. info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
  719. info->fbops = &s3fb_ops;
  720. /* Prepare PCI device */
  721. rc = pci_enable_device(dev);
  722. if (rc < 0) {
  723. dev_err(&(dev->dev), "cannot enable PCI device\n");
  724. goto err_enable_device;
  725. }
  726. rc = pci_request_regions(dev, "s3fb");
  727. if (rc < 0) {
  728. dev_err(&(dev->dev), "cannot reserve framebuffer region\n");
  729. goto err_request_regions;
  730. }
  731. info->fix.smem_start = pci_resource_start(dev, 0);
  732. info->fix.smem_len = pci_resource_len(dev, 0);
  733. /* Map physical IO memory address into kernel space */
  734. info->screen_base = pci_iomap(dev, 0, 0);
  735. if (! info->screen_base) {
  736. rc = -ENOMEM;
  737. dev_err(&(dev->dev), "iomap for framebuffer failed\n");
  738. goto err_iomap;
  739. }
  740. /* Unlock regs */
  741. cr38 = vga_rcrt(NULL, 0x38);
  742. cr39 = vga_rcrt(NULL, 0x39);
  743. vga_wseq(NULL, 0x08, 0x06);
  744. vga_wcrt(NULL, 0x38, 0x48);
  745. vga_wcrt(NULL, 0x39, 0xA5);
  746. /* Find how many physical memory there is on card */
  747. /* 0x36 register is accessible even if other registers are locked */
  748. regval = vga_rcrt(NULL, 0x36);
  749. info->screen_size = s3_memsizes[regval >> 5] << 10;
  750. info->fix.smem_len = info->screen_size;
  751. par->chip = id->driver_data & CHIP_MASK;
  752. par->rev = vga_rcrt(NULL, 0x2f);
  753. if (par->chip & CHIP_UNDECIDED_FLAG)
  754. par->chip = s3_identification(par->chip);
  755. /* Find MCLK frequency */
  756. regval = vga_rseq(NULL, 0x10);
  757. par->mclk_freq = ((vga_rseq(NULL, 0x11) + 2) * 14318) / ((regval & 0x1F) + 2);
  758. par->mclk_freq = par->mclk_freq >> (regval >> 5);
  759. /* Restore locks */
  760. vga_wcrt(NULL, 0x38, cr38);
  761. vga_wcrt(NULL, 0x39, cr39);
  762. strcpy(info->fix.id, s3_names [par->chip]);
  763. info->fix.mmio_start = 0;
  764. info->fix.mmio_len = 0;
  765. info->fix.type = FB_TYPE_PACKED_PIXELS;
  766. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  767. info->fix.ypanstep = 0;
  768. info->fix.accel = FB_ACCEL_NONE;
  769. info->pseudo_palette = (void*) (par->pseudo_palette);
  770. /* Prepare startup mode */
  771. rc = fb_find_mode(&(info->var), info, mode, NULL, 0, NULL, 8);
  772. if (! ((rc == 1) || (rc == 2))) {
  773. rc = -EINVAL;
  774. dev_err(&(dev->dev), "mode %s not found\n", mode);
  775. goto err_find_mode;
  776. }
  777. rc = fb_alloc_cmap(&info->cmap, 256, 0);
  778. if (rc < 0) {
  779. dev_err(&(dev->dev), "cannot allocate colormap\n");
  780. goto err_alloc_cmap;
  781. }
  782. rc = register_framebuffer(info);
  783. if (rc < 0) {
  784. dev_err(&(dev->dev), "cannot register framebuffer\n");
  785. goto err_reg_fb;
  786. }
  787. printk(KERN_INFO "fb%d: %s on %s, %d MB RAM, %d MHz MCLK\n", info->node, info->fix.id,
  788. pci_name(dev), info->fix.smem_len >> 20, (par->mclk_freq + 500) / 1000);
  789. if (par->chip == CHIP_UNKNOWN)
  790. printk(KERN_INFO "fb%d: unknown chip, CR2D=%x, CR2E=%x, CRT2F=%x, CRT30=%x\n",
  791. info->node, vga_rcrt(NULL, 0x2d), vga_rcrt(NULL, 0x2e),
  792. vga_rcrt(NULL, 0x2f), vga_rcrt(NULL, 0x30));
  793. /* Record a reference to the driver data */
  794. pci_set_drvdata(dev, info);
  795. #ifdef CONFIG_MTRR
  796. if (mtrr) {
  797. par->mtrr_reg = -1;
  798. par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1);
  799. }
  800. #endif
  801. return 0;
  802. /* Error handling */
  803. err_reg_fb:
  804. fb_dealloc_cmap(&info->cmap);
  805. err_alloc_cmap:
  806. err_find_mode:
  807. pci_iounmap(dev, info->screen_base);
  808. err_iomap:
  809. pci_release_regions(dev);
  810. err_request_regions:
  811. /* pci_disable_device(dev); */
  812. err_enable_device:
  813. framebuffer_release(info);
  814. return rc;
  815. }
  816. /* PCI remove */
  817. static void __devexit s3_pci_remove(struct pci_dev *dev)
  818. {
  819. struct fb_info *info = pci_get_drvdata(dev);
  820. if (info) {
  821. #ifdef CONFIG_MTRR
  822. struct s3fb_info *par = info->par;
  823. if (par->mtrr_reg >= 0) {
  824. mtrr_del(par->mtrr_reg, 0, 0);
  825. par->mtrr_reg = -1;
  826. }
  827. #endif
  828. unregister_framebuffer(info);
  829. fb_dealloc_cmap(&info->cmap);
  830. pci_iounmap(dev, info->screen_base);
  831. pci_release_regions(dev);
  832. /* pci_disable_device(dev); */
  833. pci_set_drvdata(dev, NULL);
  834. framebuffer_release(info);
  835. }
  836. }
  837. /* PCI suspend */
  838. static int s3_pci_suspend(struct pci_dev* dev, pm_message_t state)
  839. {
  840. struct fb_info *info = pci_get_drvdata(dev);
  841. struct s3fb_info *par = info->par;
  842. dev_info(&(dev->dev), "suspend\n");
  843. acquire_console_sem();
  844. mutex_lock(&(par->open_lock));
  845. if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {
  846. mutex_unlock(&(par->open_lock));
  847. release_console_sem();
  848. return 0;
  849. }
  850. fb_set_suspend(info, 1);
  851. pci_save_state(dev);
  852. pci_disable_device(dev);
  853. pci_set_power_state(dev, pci_choose_state(dev, state));
  854. mutex_unlock(&(par->open_lock));
  855. release_console_sem();
  856. return 0;
  857. }
  858. /* PCI resume */
  859. static int s3_pci_resume(struct pci_dev* dev)
  860. {
  861. struct fb_info *info = pci_get_drvdata(dev);
  862. struct s3fb_info *par = info->par;
  863. int err;
  864. dev_info(&(dev->dev), "resume\n");
  865. acquire_console_sem();
  866. mutex_lock(&(par->open_lock));
  867. if (par->ref_count == 0) {
  868. mutex_unlock(&(par->open_lock));
  869. release_console_sem();
  870. return 0;
  871. }
  872. pci_set_power_state(dev, PCI_D0);
  873. pci_restore_state(dev);
  874. err = pci_enable_device(dev);
  875. if (err) {
  876. mutex_unlock(&(par->open_lock));
  877. release_console_sem();
  878. dev_err(&(dev->dev), "error %d enabling device for resume\n", err);
  879. return err;
  880. }
  881. pci_set_master(dev);
  882. s3fb_set_par(info);
  883. fb_set_suspend(info, 0);
  884. mutex_unlock(&(par->open_lock));
  885. release_console_sem();
  886. return 0;
  887. }
  888. /* List of boards that we are trying to support */
  889. static struct pci_device_id s3_devices[] __devinitdata = {
  890. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8810), .driver_data = CHIP_XXX_TRIO},
  891. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8811), .driver_data = CHIP_XXX_TRIO},
  892. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8812), .driver_data = CHIP_M65_AURORA64VP},
  893. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8814), .driver_data = CHIP_767_TRIO64UVP},
  894. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8901), .driver_data = CHIP_XXX_TRIO64V2_DXGX},
  895. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8902), .driver_data = CHIP_551_PLATO_PX},
  896. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x5631), .driver_data = CHIP_325_VIRGE},
  897. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x883D), .driver_data = CHIP_988_VIRGE_VX},
  898. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A01), .driver_data = CHIP_XXX_VIRGE_DXGX},
  899. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A10), .driver_data = CHIP_356_VIRGE_GX2},
  900. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A11), .driver_data = CHIP_357_VIRGE_GX2P},
  901. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A12), .driver_data = CHIP_359_VIRGE_GX2P},
  902. {0, 0, 0, 0, 0, 0, 0}
  903. };
  904. MODULE_DEVICE_TABLE(pci, s3_devices);
  905. static struct pci_driver s3fb_pci_driver = {
  906. .name = "s3fb",
  907. .id_table = s3_devices,
  908. .probe = s3_pci_probe,
  909. .remove = __devexit_p(s3_pci_remove),
  910. .suspend = s3_pci_suspend,
  911. .resume = s3_pci_resume,
  912. };
  913. /* Parse user speficied options */
  914. #ifndef MODULE
  915. static int __init s3fb_setup(char *options)
  916. {
  917. char *opt;
  918. if (!options || !*options)
  919. return 0;
  920. while ((opt = strsep(&options, ",")) != NULL) {
  921. if (!*opt)
  922. continue;
  923. #ifdef CONFIG_MTRR
  924. else if (!strncmp(opt, "mtrr:", 5))
  925. mtrr = simple_strtoul(opt + 5, NULL, 0);
  926. #endif
  927. else if (!strncmp(opt, "fasttext:", 9))
  928. fasttext = simple_strtoul(opt + 9, NULL, 0);
  929. else
  930. mode = opt;
  931. }
  932. return 0;
  933. }
  934. #endif
  935. /* Cleanup */
  936. static void __exit s3fb_cleanup(void)
  937. {
  938. pr_debug("s3fb: cleaning up\n");
  939. pci_unregister_driver(&s3fb_pci_driver);
  940. }
  941. /* Driver Initialisation */
  942. static int __init s3fb_init(void)
  943. {
  944. #ifndef MODULE
  945. char *option = NULL;
  946. if (fb_get_options("s3fb", &option))
  947. return -ENODEV;
  948. s3fb_setup(option);
  949. #endif
  950. pr_debug("s3fb: initializing\n");
  951. return pci_register_driver(&s3fb_pci_driver);
  952. }
  953. /* ------------------------------------------------------------------------- */
  954. /* Modularization */
  955. module_init(s3fb_init);
  956. module_exit(s3fb_cleanup);