s3fb.c 34 KB

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