s3fb.c 32 KB

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