s3fb.c 32 KB

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