s3fb.c 32 KB

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