s3fb.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603
  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 console_lock() */
  25. #include <video/vga.h>
  26. #include <linux/i2c.h>
  27. #include <linux/i2c-algo-bit.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. #ifdef CONFIG_FB_S3_DDC
  39. u8 __iomem *mmio;
  40. bool ddc_registered;
  41. struct i2c_adapter ddc_adapter;
  42. struct i2c_algo_bit_data ddc_algo;
  43. #endif
  44. };
  45. /* ------------------------------------------------------------------------- */
  46. static const struct svga_fb_format s3fb_formats[] = {
  47. { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
  48. FB_TYPE_TEXT, FB_AUX_TEXT_SVGA_STEP4, FB_VISUAL_PSEUDOCOLOR, 8, 16},
  49. { 4, {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0}, 0,
  50. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 16},
  51. { 4, {0, 4, 0}, {0, 4, 0}, {0, 4, 0}, {0, 0, 0}, 1,
  52. FB_TYPE_INTERLEAVED_PLANES, 1, FB_VISUAL_PSEUDOCOLOR, 8, 16},
  53. { 8, {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
  54. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 4, 8},
  55. {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0,
  56. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 4},
  57. {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0,
  58. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 4},
  59. {24, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
  60. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 1, 2},
  61. {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
  62. FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 1, 2},
  63. SVGA_FORMAT_END
  64. };
  65. static const struct svga_pll s3_pll = {3, 129, 3, 33, 0, 3,
  66. 35000, 240000, 14318};
  67. static const struct svga_pll s3_trio3d_pll = {3, 129, 3, 31, 0, 4,
  68. 230000, 460000, 14318};
  69. static const int s3_memsizes[] = {4096, 0, 3072, 8192, 2048, 6144, 1024, 512};
  70. static const char * const s3_names[] = {"S3 Unknown", "S3 Trio32", "S3 Trio64", "S3 Trio64V+",
  71. "S3 Trio64UV+", "S3 Trio64V2/DX", "S3 Trio64V2/GX",
  72. "S3 Plato/PX", "S3 Aurora64V+", "S3 Virge",
  73. "S3 Virge/VX", "S3 Virge/DX", "S3 Virge/GX",
  74. "S3 Virge/GX2", "S3 Virge/GX2+", "",
  75. "S3 Trio3D/1X", "S3 Trio3D/2X", "S3 Trio3D/2X",
  76. "S3 Trio3D", "S3 Virge/MX"};
  77. #define CHIP_UNKNOWN 0x00
  78. #define CHIP_732_TRIO32 0x01
  79. #define CHIP_764_TRIO64 0x02
  80. #define CHIP_765_TRIO64VP 0x03
  81. #define CHIP_767_TRIO64UVP 0x04
  82. #define CHIP_775_TRIO64V2_DX 0x05
  83. #define CHIP_785_TRIO64V2_GX 0x06
  84. #define CHIP_551_PLATO_PX 0x07
  85. #define CHIP_M65_AURORA64VP 0x08
  86. #define CHIP_325_VIRGE 0x09
  87. #define CHIP_988_VIRGE_VX 0x0A
  88. #define CHIP_375_VIRGE_DX 0x0B
  89. #define CHIP_385_VIRGE_GX 0x0C
  90. #define CHIP_357_VIRGE_GX2 0x0D
  91. #define CHIP_359_VIRGE_GX2P 0x0E
  92. #define CHIP_360_TRIO3D_1X 0x10
  93. #define CHIP_362_TRIO3D_2X 0x11
  94. #define CHIP_368_TRIO3D_2X 0x12
  95. #define CHIP_365_TRIO3D 0x13
  96. #define CHIP_260_VIRGE_MX 0x14
  97. #define CHIP_XXX_TRIO 0x80
  98. #define CHIP_XXX_TRIO64V2_DXGX 0x81
  99. #define CHIP_XXX_VIRGE_DXGX 0x82
  100. #define CHIP_36X_TRIO3D_1X_2X 0x83
  101. #define CHIP_UNDECIDED_FLAG 0x80
  102. #define CHIP_MASK 0xFF
  103. #define MMIO_OFFSET 0x1000000
  104. #define MMIO_SIZE 0x10000
  105. /* CRT timing register sets */
  106. static const struct vga_regset s3_h_total_regs[] = {{0x00, 0, 7}, {0x5D, 0, 0}, VGA_REGSET_END};
  107. static const struct vga_regset s3_h_display_regs[] = {{0x01, 0, 7}, {0x5D, 1, 1}, VGA_REGSET_END};
  108. static const struct vga_regset s3_h_blank_start_regs[] = {{0x02, 0, 7}, {0x5D, 2, 2}, VGA_REGSET_END};
  109. static const struct vga_regset s3_h_blank_end_regs[] = {{0x03, 0, 4}, {0x05, 7, 7}, VGA_REGSET_END};
  110. static const struct vga_regset s3_h_sync_start_regs[] = {{0x04, 0, 7}, {0x5D, 4, 4}, VGA_REGSET_END};
  111. static const struct vga_regset s3_h_sync_end_regs[] = {{0x05, 0, 4}, VGA_REGSET_END};
  112. static const struct vga_regset s3_v_total_regs[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x5E, 0, 0}, VGA_REGSET_END};
  113. static const struct vga_regset s3_v_display_regs[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x5E, 1, 1}, VGA_REGSET_END};
  114. 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};
  115. static const struct vga_regset s3_v_blank_end_regs[] = {{0x16, 0, 7}, VGA_REGSET_END};
  116. 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};
  117. static const struct vga_regset s3_v_sync_end_regs[] = {{0x11, 0, 3}, VGA_REGSET_END};
  118. static const struct vga_regset s3_line_compare_regs[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, {0x5E, 6, 6}, VGA_REGSET_END};
  119. static const struct vga_regset s3_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x69, 0, 4}, VGA_REGSET_END};
  120. static const struct vga_regset s3_offset_regs[] = {{0x13, 0, 7}, {0x51, 4, 5}, VGA_REGSET_END}; /* set 0x43 bit 2 to 0 */
  121. static const struct vga_regset s3_dtpc_regs[] = {{0x3B, 0, 7}, {0x5D, 6, 6}, VGA_REGSET_END};
  122. static const struct svga_timing_regs s3_timing_regs = {
  123. s3_h_total_regs, s3_h_display_regs, s3_h_blank_start_regs,
  124. s3_h_blank_end_regs, s3_h_sync_start_regs, s3_h_sync_end_regs,
  125. s3_v_total_regs, s3_v_display_regs, s3_v_blank_start_regs,
  126. s3_v_blank_end_regs, s3_v_sync_start_regs, s3_v_sync_end_regs,
  127. };
  128. /* ------------------------------------------------------------------------- */
  129. /* Module parameters */
  130. static char *mode_option;
  131. #ifdef CONFIG_MTRR
  132. static int mtrr = 1;
  133. #endif
  134. static int fasttext = 1;
  135. MODULE_AUTHOR("(c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>");
  136. MODULE_LICENSE("GPL");
  137. MODULE_DESCRIPTION("fbdev driver for S3 Trio/Virge");
  138. module_param(mode_option, charp, 0444);
  139. MODULE_PARM_DESC(mode_option, "Default video mode ('640x480-8@60', etc)");
  140. module_param_named(mode, mode_option, charp, 0444);
  141. MODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc) (deprecated)");
  142. #ifdef CONFIG_MTRR
  143. module_param(mtrr, int, 0444);
  144. MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)");
  145. #endif
  146. module_param(fasttext, int, 0644);
  147. MODULE_PARM_DESC(fasttext, "Enable S3 fast text mode (1=enable, 0=disable, default=1)");
  148. /* ------------------------------------------------------------------------- */
  149. #ifdef CONFIG_FB_S3_DDC
  150. #define DDC_REG 0xaa /* Trio 3D/1X/2X */
  151. #define DDC_MMIO_REG 0xff20 /* all other chips */
  152. #define DDC_SCL_OUT (1 << 0)
  153. #define DDC_SDA_OUT (1 << 1)
  154. #define DDC_SCL_IN (1 << 2)
  155. #define DDC_SDA_IN (1 << 3)
  156. #define DDC_DRIVE_EN (1 << 4)
  157. static bool s3fb_ddc_needs_mmio(int chip)
  158. {
  159. return !(chip == CHIP_360_TRIO3D_1X ||
  160. chip == CHIP_362_TRIO3D_2X ||
  161. chip == CHIP_368_TRIO3D_2X);
  162. }
  163. static u8 s3fb_ddc_read(struct s3fb_info *par)
  164. {
  165. if (s3fb_ddc_needs_mmio(par->chip))
  166. return readb(par->mmio + DDC_MMIO_REG);
  167. else
  168. return vga_rcrt(par->state.vgabase, DDC_REG);
  169. }
  170. static void s3fb_ddc_write(struct s3fb_info *par, u8 val)
  171. {
  172. if (s3fb_ddc_needs_mmio(par->chip))
  173. writeb(val, par->mmio + DDC_MMIO_REG);
  174. else
  175. vga_wcrt(par->state.vgabase, DDC_REG, val);
  176. }
  177. static void s3fb_ddc_setscl(void *data, int val)
  178. {
  179. struct s3fb_info *par = data;
  180. unsigned char reg;
  181. reg = s3fb_ddc_read(par) | DDC_DRIVE_EN;
  182. if (val)
  183. reg |= DDC_SCL_OUT;
  184. else
  185. reg &= ~DDC_SCL_OUT;
  186. s3fb_ddc_write(par, reg);
  187. }
  188. static void s3fb_ddc_setsda(void *data, int val)
  189. {
  190. struct s3fb_info *par = data;
  191. unsigned char reg;
  192. reg = s3fb_ddc_read(par) | DDC_DRIVE_EN;
  193. if (val)
  194. reg |= DDC_SDA_OUT;
  195. else
  196. reg &= ~DDC_SDA_OUT;
  197. s3fb_ddc_write(par, reg);
  198. }
  199. static int s3fb_ddc_getscl(void *data)
  200. {
  201. struct s3fb_info *par = data;
  202. return !!(s3fb_ddc_read(par) & DDC_SCL_IN);
  203. }
  204. static int s3fb_ddc_getsda(void *data)
  205. {
  206. struct s3fb_info *par = data;
  207. return !!(s3fb_ddc_read(par) & DDC_SDA_IN);
  208. }
  209. static int s3fb_setup_ddc_bus(struct fb_info *info)
  210. {
  211. struct s3fb_info *par = info->par;
  212. strlcpy(par->ddc_adapter.name, info->fix.id,
  213. sizeof(par->ddc_adapter.name));
  214. par->ddc_adapter.owner = THIS_MODULE;
  215. par->ddc_adapter.class = I2C_CLASS_DDC;
  216. par->ddc_adapter.algo_data = &par->ddc_algo;
  217. par->ddc_adapter.dev.parent = info->device;
  218. par->ddc_algo.setsda = s3fb_ddc_setsda;
  219. par->ddc_algo.setscl = s3fb_ddc_setscl;
  220. par->ddc_algo.getsda = s3fb_ddc_getsda;
  221. par->ddc_algo.getscl = s3fb_ddc_getscl;
  222. par->ddc_algo.udelay = 10;
  223. par->ddc_algo.timeout = 20;
  224. par->ddc_algo.data = par;
  225. i2c_set_adapdata(&par->ddc_adapter, par);
  226. /*
  227. * some Virge cards have external MUX to switch chip I2C bus between
  228. * DDC and extension pins - switch it do DDC
  229. */
  230. /* vga_wseq(par->state.vgabase, 0x08, 0x06); - not needed, already unlocked */
  231. if (par->chip == CHIP_357_VIRGE_GX2 ||
  232. par->chip == CHIP_359_VIRGE_GX2P ||
  233. par->chip == CHIP_260_VIRGE_MX)
  234. svga_wseq_mask(par->state.vgabase, 0x0d, 0x01, 0x03);
  235. else
  236. svga_wseq_mask(par->state.vgabase, 0x0d, 0x00, 0x03);
  237. /* some Virge need this or the DDC is ignored */
  238. svga_wcrt_mask(par->state.vgabase, 0x5c, 0x03, 0x03);
  239. return i2c_bit_add_bus(&par->ddc_adapter);
  240. }
  241. #endif /* CONFIG_FB_S3_DDC */
  242. /* ------------------------------------------------------------------------- */
  243. /* Set font in S3 fast text mode */
  244. static void s3fb_settile_fast(struct fb_info *info, struct fb_tilemap *map)
  245. {
  246. const u8 *font = map->data;
  247. u8 __iomem *fb = (u8 __iomem *) info->screen_base;
  248. int i, c;
  249. if ((map->width != 8) || (map->height != 16) ||
  250. (map->depth != 1) || (map->length != 256)) {
  251. printk(KERN_ERR "fb%d: unsupported font parameters: width %d, height %d, depth %d, length %d\n",
  252. info->node, map->width, map->height, map->depth, map->length);
  253. return;
  254. }
  255. fb += 2;
  256. for (i = 0; i < map->height; i++) {
  257. for (c = 0; c < map->length; c++) {
  258. fb_writeb(font[c * map->height + i], fb + c * 4);
  259. }
  260. fb += 1024;
  261. }
  262. }
  263. static void s3fb_tilecursor(struct fb_info *info, struct fb_tilecursor *cursor)
  264. {
  265. struct s3fb_info *par = info->par;
  266. svga_tilecursor(par->state.vgabase, info, cursor);
  267. }
  268. static struct fb_tile_ops s3fb_tile_ops = {
  269. .fb_settile = svga_settile,
  270. .fb_tilecopy = svga_tilecopy,
  271. .fb_tilefill = svga_tilefill,
  272. .fb_tileblit = svga_tileblit,
  273. .fb_tilecursor = s3fb_tilecursor,
  274. .fb_get_tilemax = svga_get_tilemax,
  275. };
  276. static struct fb_tile_ops s3fb_fast_tile_ops = {
  277. .fb_settile = s3fb_settile_fast,
  278. .fb_tilecopy = svga_tilecopy,
  279. .fb_tilefill = svga_tilefill,
  280. .fb_tileblit = svga_tileblit,
  281. .fb_tilecursor = s3fb_tilecursor,
  282. .fb_get_tilemax = svga_get_tilemax,
  283. };
  284. /* ------------------------------------------------------------------------- */
  285. /* image data is MSB-first, fb structure is MSB-first too */
  286. static inline u32 expand_color(u32 c)
  287. {
  288. return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF;
  289. }
  290. /* s3fb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */
  291. static void s3fb_iplan_imageblit(struct fb_info *info, const struct fb_image *image)
  292. {
  293. u32 fg = expand_color(image->fg_color);
  294. u32 bg = expand_color(image->bg_color);
  295. const u8 *src1, *src;
  296. u8 __iomem *dst1;
  297. u32 __iomem *dst;
  298. u32 val;
  299. int x, y;
  300. src1 = image->data;
  301. dst1 = info->screen_base + (image->dy * info->fix.line_length)
  302. + ((image->dx / 8) * 4);
  303. for (y = 0; y < image->height; y++) {
  304. src = src1;
  305. dst = (u32 __iomem *) dst1;
  306. for (x = 0; x < image->width; x += 8) {
  307. val = *(src++) * 0x01010101;
  308. val = (val & fg) | (~val & bg);
  309. fb_writel(val, dst++);
  310. }
  311. src1 += image->width / 8;
  312. dst1 += info->fix.line_length;
  313. }
  314. }
  315. /* s3fb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */
  316. static void s3fb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  317. {
  318. u32 fg = expand_color(rect->color);
  319. u8 __iomem *dst1;
  320. u32 __iomem *dst;
  321. int x, y;
  322. dst1 = info->screen_base + (rect->dy * info->fix.line_length)
  323. + ((rect->dx / 8) * 4);
  324. for (y = 0; y < rect->height; y++) {
  325. dst = (u32 __iomem *) dst1;
  326. for (x = 0; x < rect->width; x += 8) {
  327. fb_writel(fg, dst++);
  328. }
  329. dst1 += info->fix.line_length;
  330. }
  331. }
  332. /* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */
  333. static inline u32 expand_pixel(u32 c)
  334. {
  335. return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) |
  336. ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF;
  337. }
  338. /* s3fb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */
  339. static void s3fb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image)
  340. {
  341. u32 fg = image->fg_color * 0x11111111;
  342. u32 bg = image->bg_color * 0x11111111;
  343. const u8 *src1, *src;
  344. u8 __iomem *dst1;
  345. u32 __iomem *dst;
  346. u32 val;
  347. int x, y;
  348. src1 = image->data;
  349. dst1 = info->screen_base + (image->dy * info->fix.line_length)
  350. + ((image->dx / 8) * 4);
  351. for (y = 0; y < image->height; y++) {
  352. src = src1;
  353. dst = (u32 __iomem *) dst1;
  354. for (x = 0; x < image->width; x += 8) {
  355. val = expand_pixel(*(src++));
  356. val = (val & fg) | (~val & bg);
  357. fb_writel(val, dst++);
  358. }
  359. src1 += image->width / 8;
  360. dst1 += info->fix.line_length;
  361. }
  362. }
  363. static void s3fb_imageblit(struct fb_info *info, const struct fb_image *image)
  364. {
  365. if ((info->var.bits_per_pixel == 4) && (image->depth == 1)
  366. && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) {
  367. if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)
  368. s3fb_iplan_imageblit(info, image);
  369. else
  370. s3fb_cfb4_imageblit(info, image);
  371. } else
  372. cfb_imageblit(info, image);
  373. }
  374. static void s3fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  375. {
  376. if ((info->var.bits_per_pixel == 4)
  377. && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0)
  378. && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES))
  379. s3fb_iplan_fillrect(info, rect);
  380. else
  381. cfb_fillrect(info, rect);
  382. }
  383. /* ------------------------------------------------------------------------- */
  384. static void s3_set_pixclock(struct fb_info *info, u32 pixclock)
  385. {
  386. struct s3fb_info *par = info->par;
  387. u16 m, n, r;
  388. u8 regval;
  389. int rv;
  390. rv = svga_compute_pll((par->chip == CHIP_365_TRIO3D) ? &s3_trio3d_pll : &s3_pll,
  391. 1000000000 / pixclock, &m, &n, &r, info->node);
  392. if (rv < 0) {
  393. printk(KERN_ERR "fb%d: cannot set requested pixclock, keeping old value\n", info->node);
  394. return;
  395. }
  396. /* Set VGA misc register */
  397. regval = vga_r(par->state.vgabase, VGA_MIS_R);
  398. vga_w(par->state.vgabase, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD);
  399. /* Set S3 clock registers */
  400. if (par->chip == CHIP_357_VIRGE_GX2 ||
  401. par->chip == CHIP_359_VIRGE_GX2P ||
  402. par->chip == CHIP_360_TRIO3D_1X ||
  403. par->chip == CHIP_362_TRIO3D_2X ||
  404. par->chip == CHIP_368_TRIO3D_2X ||
  405. par->chip == CHIP_260_VIRGE_MX) {
  406. vga_wseq(par->state.vgabase, 0x12, (n - 2) | ((r & 3) << 6)); /* n and two bits of r */
  407. vga_wseq(par->state.vgabase, 0x29, r >> 2); /* remaining highest bit of r */
  408. } else
  409. vga_wseq(par->state.vgabase, 0x12, (n - 2) | (r << 5));
  410. vga_wseq(par->state.vgabase, 0x13, m - 2);
  411. udelay(1000);
  412. /* Activate clock - write 0, 1, 0 to seq/15 bit 5 */
  413. regval = vga_rseq (par->state.vgabase, 0x15); /* | 0x80; */
  414. vga_wseq(par->state.vgabase, 0x15, regval & ~(1<<5));
  415. vga_wseq(par->state.vgabase, 0x15, regval | (1<<5));
  416. vga_wseq(par->state.vgabase, 0x15, regval & ~(1<<5));
  417. }
  418. /* Open framebuffer */
  419. static int s3fb_open(struct fb_info *info, int user)
  420. {
  421. struct s3fb_info *par = info->par;
  422. mutex_lock(&(par->open_lock));
  423. if (par->ref_count == 0) {
  424. void __iomem *vgabase = par->state.vgabase;
  425. memset(&(par->state), 0, sizeof(struct vgastate));
  426. par->state.vgabase = vgabase;
  427. par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP;
  428. par->state.num_crtc = 0x70;
  429. par->state.num_seq = 0x20;
  430. save_vga(&(par->state));
  431. }
  432. par->ref_count++;
  433. mutex_unlock(&(par->open_lock));
  434. return 0;
  435. }
  436. /* Close framebuffer */
  437. static int s3fb_release(struct fb_info *info, int user)
  438. {
  439. struct s3fb_info *par = info->par;
  440. mutex_lock(&(par->open_lock));
  441. if (par->ref_count == 0) {
  442. mutex_unlock(&(par->open_lock));
  443. return -EINVAL;
  444. }
  445. if (par->ref_count == 1)
  446. restore_vga(&(par->state));
  447. par->ref_count--;
  448. mutex_unlock(&(par->open_lock));
  449. return 0;
  450. }
  451. /* Validate passed in var */
  452. static int s3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  453. {
  454. struct s3fb_info *par = info->par;
  455. int rv, mem, step;
  456. u16 m, n, r;
  457. /* Find appropriate format */
  458. rv = svga_match_format (s3fb_formats, var, NULL);
  459. /* 32bpp mode is not supported on VIRGE VX,
  460. 24bpp is not supported on others */
  461. if ((par->chip == CHIP_988_VIRGE_VX) ? (rv == 7) : (rv == 6))
  462. rv = -EINVAL;
  463. if (rv < 0) {
  464. printk(KERN_ERR "fb%d: unsupported mode requested\n", info->node);
  465. return rv;
  466. }
  467. /* Do not allow to have real resoulution larger than virtual */
  468. if (var->xres > var->xres_virtual)
  469. var->xres_virtual = var->xres;
  470. if (var->yres > var->yres_virtual)
  471. var->yres_virtual = var->yres;
  472. /* Round up xres_virtual to have proper alignment of lines */
  473. step = s3fb_formats[rv].xresstep - 1;
  474. var->xres_virtual = (var->xres_virtual+step) & ~step;
  475. /* Check whether have enough memory */
  476. mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual;
  477. if (mem > info->screen_size) {
  478. printk(KERN_ERR "fb%d: not enough framebuffer memory (%d kB requested , %d kB available)\n",
  479. info->node, mem >> 10, (unsigned int) (info->screen_size >> 10));
  480. return -EINVAL;
  481. }
  482. rv = svga_check_timings (&s3_timing_regs, var, info->node);
  483. if (rv < 0) {
  484. printk(KERN_ERR "fb%d: invalid timings requested\n", info->node);
  485. return rv;
  486. }
  487. rv = svga_compute_pll(&s3_pll, PICOS2KHZ(var->pixclock), &m, &n, &r,
  488. info->node);
  489. if (rv < 0) {
  490. printk(KERN_ERR "fb%d: invalid pixclock value requested\n",
  491. info->node);
  492. return rv;
  493. }
  494. return 0;
  495. }
  496. /* Set video mode from par */
  497. static int s3fb_set_par(struct fb_info *info)
  498. {
  499. struct s3fb_info *par = info->par;
  500. u32 value, mode, hmul, offset_value, screen_size, multiplex, dbytes;
  501. u32 bpp = info->var.bits_per_pixel;
  502. u32 htotal, hsstart;
  503. if (bpp != 0) {
  504. info->fix.ypanstep = 1;
  505. info->fix.line_length = (info->var.xres_virtual * bpp) / 8;
  506. info->flags &= ~FBINFO_MISC_TILEBLITTING;
  507. info->tileops = NULL;
  508. /* in 4bpp supports 8p wide tiles only, any tiles otherwise */
  509. info->pixmap.blit_x = (bpp == 4) ? (1 << (8 - 1)) : (~(u32)0);
  510. info->pixmap.blit_y = ~(u32)0;
  511. offset_value = (info->var.xres_virtual * bpp) / 64;
  512. screen_size = info->var.yres_virtual * info->fix.line_length;
  513. } else {
  514. info->fix.ypanstep = 16;
  515. info->fix.line_length = 0;
  516. info->flags |= FBINFO_MISC_TILEBLITTING;
  517. info->tileops = fasttext ? &s3fb_fast_tile_ops : &s3fb_tile_ops;
  518. /* supports 8x16 tiles only */
  519. info->pixmap.blit_x = 1 << (8 - 1);
  520. info->pixmap.blit_y = 1 << (16 - 1);
  521. offset_value = info->var.xres_virtual / 16;
  522. screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
  523. }
  524. info->var.xoffset = 0;
  525. info->var.yoffset = 0;
  526. info->var.activate = FB_ACTIVATE_NOW;
  527. /* Unlock registers */
  528. vga_wcrt(par->state.vgabase, 0x38, 0x48);
  529. vga_wcrt(par->state.vgabase, 0x39, 0xA5);
  530. vga_wseq(par->state.vgabase, 0x08, 0x06);
  531. svga_wcrt_mask(par->state.vgabase, 0x11, 0x00, 0x80);
  532. /* Blank screen and turn off sync */
  533. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  534. svga_wcrt_mask(par->state.vgabase, 0x17, 0x00, 0x80);
  535. /* Set default values */
  536. svga_set_default_gfx_regs(par->state.vgabase);
  537. svga_set_default_atc_regs(par->state.vgabase);
  538. svga_set_default_seq_regs(par->state.vgabase);
  539. svga_set_default_crt_regs(par->state.vgabase);
  540. svga_wcrt_multi(par->state.vgabase, s3_line_compare_regs, 0xFFFFFFFF);
  541. svga_wcrt_multi(par->state.vgabase, s3_start_address_regs, 0);
  542. /* S3 specific initialization */
  543. svga_wcrt_mask(par->state.vgabase, 0x58, 0x10, 0x10); /* enable linear framebuffer */
  544. svga_wcrt_mask(par->state.vgabase, 0x31, 0x08, 0x08); /* enable sequencer access to framebuffer above 256 kB */
  545. /* svga_wcrt_mask(par->state.vgabase, 0x33, 0x08, 0x08); */ /* DDR ? */
  546. /* svga_wcrt_mask(par->state.vgabase, 0x43, 0x01, 0x01); */ /* DDR ? */
  547. svga_wcrt_mask(par->state.vgabase, 0x33, 0x00, 0x08); /* no DDR ? */
  548. svga_wcrt_mask(par->state.vgabase, 0x43, 0x00, 0x01); /* no DDR ? */
  549. svga_wcrt_mask(par->state.vgabase, 0x5D, 0x00, 0x28); /* Clear strange HSlen bits */
  550. /* svga_wcrt_mask(par->state.vgabase, 0x58, 0x03, 0x03); */
  551. /* svga_wcrt_mask(par->state.vgabase, 0x53, 0x12, 0x13); */ /* enable MMIO */
  552. /* svga_wcrt_mask(par->state.vgabase, 0x40, 0x08, 0x08); */ /* enable write buffer */
  553. /* Set the offset register */
  554. pr_debug("fb%d: offset register : %d\n", info->node, offset_value);
  555. svga_wcrt_multi(par->state.vgabase, s3_offset_regs, offset_value);
  556. if (par->chip != CHIP_357_VIRGE_GX2 &&
  557. par->chip != CHIP_359_VIRGE_GX2P &&
  558. par->chip != CHIP_360_TRIO3D_1X &&
  559. par->chip != CHIP_362_TRIO3D_2X &&
  560. par->chip != CHIP_368_TRIO3D_2X &&
  561. par->chip != CHIP_260_VIRGE_MX) {
  562. vga_wcrt(par->state.vgabase, 0x54, 0x18); /* M parameter */
  563. vga_wcrt(par->state.vgabase, 0x60, 0xff); /* N parameter */
  564. vga_wcrt(par->state.vgabase, 0x61, 0xff); /* L parameter */
  565. vga_wcrt(par->state.vgabase, 0x62, 0xff); /* L parameter */
  566. }
  567. vga_wcrt(par->state.vgabase, 0x3A, 0x35);
  568. svga_wattr(par->state.vgabase, 0x33, 0x00);
  569. if (info->var.vmode & FB_VMODE_DOUBLE)
  570. svga_wcrt_mask(par->state.vgabase, 0x09, 0x80, 0x80);
  571. else
  572. svga_wcrt_mask(par->state.vgabase, 0x09, 0x00, 0x80);
  573. if (info->var.vmode & FB_VMODE_INTERLACED)
  574. svga_wcrt_mask(par->state.vgabase, 0x42, 0x20, 0x20);
  575. else
  576. svga_wcrt_mask(par->state.vgabase, 0x42, 0x00, 0x20);
  577. /* Disable hardware graphics cursor */
  578. svga_wcrt_mask(par->state.vgabase, 0x45, 0x00, 0x01);
  579. /* Disable Streams engine */
  580. svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0x0C);
  581. mode = svga_match_format(s3fb_formats, &(info->var), &(info->fix));
  582. /* S3 virge DX hack */
  583. if (par->chip == CHIP_375_VIRGE_DX) {
  584. vga_wcrt(par->state.vgabase, 0x86, 0x80);
  585. vga_wcrt(par->state.vgabase, 0x90, 0x00);
  586. }
  587. /* S3 virge VX hack */
  588. if (par->chip == CHIP_988_VIRGE_VX) {
  589. vga_wcrt(par->state.vgabase, 0x50, 0x00);
  590. vga_wcrt(par->state.vgabase, 0x67, 0x50);
  591. msleep(10); /* screen remains blank sometimes without this */
  592. vga_wcrt(par->state.vgabase, 0x63, (mode <= 2) ? 0x90 : 0x09);
  593. vga_wcrt(par->state.vgabase, 0x66, 0x90);
  594. }
  595. if (par->chip == CHIP_357_VIRGE_GX2 ||
  596. par->chip == CHIP_359_VIRGE_GX2P ||
  597. par->chip == CHIP_360_TRIO3D_1X ||
  598. par->chip == CHIP_362_TRIO3D_2X ||
  599. par->chip == CHIP_368_TRIO3D_2X ||
  600. par->chip == CHIP_365_TRIO3D ||
  601. par->chip == CHIP_375_VIRGE_DX ||
  602. par->chip == CHIP_385_VIRGE_GX ||
  603. par->chip == CHIP_260_VIRGE_MX) {
  604. dbytes = info->var.xres * ((bpp+7)/8);
  605. vga_wcrt(par->state.vgabase, 0x91, (dbytes + 7) / 8);
  606. vga_wcrt(par->state.vgabase, 0x90, (((dbytes + 7) / 8) >> 8) | 0x80);
  607. vga_wcrt(par->state.vgabase, 0x66, 0x81);
  608. }
  609. if (par->chip == CHIP_357_VIRGE_GX2 ||
  610. par->chip == CHIP_359_VIRGE_GX2P ||
  611. par->chip == CHIP_360_TRIO3D_1X ||
  612. par->chip == CHIP_362_TRIO3D_2X ||
  613. par->chip == CHIP_368_TRIO3D_2X ||
  614. par->chip == CHIP_260_VIRGE_MX)
  615. vga_wcrt(par->state.vgabase, 0x34, 0x00);
  616. else /* enable Data Transfer Position Control (DTPC) */
  617. vga_wcrt(par->state.vgabase, 0x34, 0x10);
  618. svga_wcrt_mask(par->state.vgabase, 0x31, 0x00, 0x40);
  619. multiplex = 0;
  620. hmul = 1;
  621. /* Set mode-specific register values */
  622. switch (mode) {
  623. case 0:
  624. pr_debug("fb%d: text mode\n", info->node);
  625. svga_set_textmode_vga_regs(par->state.vgabase);
  626. /* Set additional registers like in 8-bit mode */
  627. svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
  628. svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
  629. /* Disable enhanced mode */
  630. svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30);
  631. if (fasttext) {
  632. pr_debug("fb%d: high speed text mode set\n", info->node);
  633. svga_wcrt_mask(par->state.vgabase, 0x31, 0x40, 0x40);
  634. }
  635. break;
  636. case 1:
  637. pr_debug("fb%d: 4 bit pseudocolor\n", info->node);
  638. vga_wgfx(par->state.vgabase, VGA_GFX_MODE, 0x40);
  639. /* Set additional registers like in 8-bit mode */
  640. svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
  641. svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
  642. /* disable enhanced mode */
  643. svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30);
  644. break;
  645. case 2:
  646. pr_debug("fb%d: 4 bit pseudocolor, planar\n", info->node);
  647. /* Set additional registers like in 8-bit mode */
  648. svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
  649. svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
  650. /* disable enhanced mode */
  651. svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30);
  652. break;
  653. case 3:
  654. pr_debug("fb%d: 8 bit pseudocolor\n", info->node);
  655. svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
  656. if (info->var.pixclock > 20000 ||
  657. par->chip == CHIP_357_VIRGE_GX2 ||
  658. par->chip == CHIP_359_VIRGE_GX2P ||
  659. par->chip == CHIP_360_TRIO3D_1X ||
  660. par->chip == CHIP_362_TRIO3D_2X ||
  661. par->chip == CHIP_368_TRIO3D_2X ||
  662. par->chip == CHIP_260_VIRGE_MX)
  663. svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
  664. else {
  665. svga_wcrt_mask(par->state.vgabase, 0x67, 0x10, 0xF0);
  666. multiplex = 1;
  667. }
  668. break;
  669. case 4:
  670. pr_debug("fb%d: 5/5/5 truecolor\n", info->node);
  671. if (par->chip == CHIP_988_VIRGE_VX) {
  672. if (info->var.pixclock > 20000)
  673. svga_wcrt_mask(par->state.vgabase, 0x67, 0x20, 0xF0);
  674. else
  675. svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0);
  676. } else if (par->chip == CHIP_365_TRIO3D) {
  677. svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
  678. if (info->var.pixclock > 8695) {
  679. svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0);
  680. hmul = 2;
  681. } else {
  682. svga_wcrt_mask(par->state.vgabase, 0x67, 0x20, 0xF0);
  683. multiplex = 1;
  684. }
  685. } else {
  686. svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
  687. svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0);
  688. if (par->chip != CHIP_357_VIRGE_GX2 &&
  689. par->chip != CHIP_359_VIRGE_GX2P &&
  690. par->chip != CHIP_360_TRIO3D_1X &&
  691. par->chip != CHIP_362_TRIO3D_2X &&
  692. par->chip != CHIP_368_TRIO3D_2X &&
  693. par->chip != CHIP_260_VIRGE_MX)
  694. hmul = 2;
  695. }
  696. break;
  697. case 5:
  698. pr_debug("fb%d: 5/6/5 truecolor\n", info->node);
  699. if (par->chip == CHIP_988_VIRGE_VX) {
  700. if (info->var.pixclock > 20000)
  701. svga_wcrt_mask(par->state.vgabase, 0x67, 0x40, 0xF0);
  702. else
  703. svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
  704. } else if (par->chip == CHIP_365_TRIO3D) {
  705. svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
  706. if (info->var.pixclock > 8695) {
  707. svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
  708. hmul = 2;
  709. } else {
  710. svga_wcrt_mask(par->state.vgabase, 0x67, 0x40, 0xF0);
  711. multiplex = 1;
  712. }
  713. } else {
  714. svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
  715. svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
  716. if (par->chip != CHIP_357_VIRGE_GX2 &&
  717. par->chip != CHIP_359_VIRGE_GX2P &&
  718. par->chip != CHIP_360_TRIO3D_1X &&
  719. par->chip != CHIP_362_TRIO3D_2X &&
  720. par->chip != CHIP_368_TRIO3D_2X &&
  721. par->chip != CHIP_260_VIRGE_MX)
  722. hmul = 2;
  723. }
  724. break;
  725. case 6:
  726. /* VIRGE VX case */
  727. pr_debug("fb%d: 8/8/8 truecolor\n", info->node);
  728. svga_wcrt_mask(par->state.vgabase, 0x67, 0xD0, 0xF0);
  729. break;
  730. case 7:
  731. pr_debug("fb%d: 8/8/8/8 truecolor\n", info->node);
  732. svga_wcrt_mask(par->state.vgabase, 0x50, 0x30, 0x30);
  733. svga_wcrt_mask(par->state.vgabase, 0x67, 0xD0, 0xF0);
  734. break;
  735. default:
  736. printk(KERN_ERR "fb%d: unsupported mode - bug\n", info->node);
  737. return -EINVAL;
  738. }
  739. if (par->chip != CHIP_988_VIRGE_VX) {
  740. svga_wseq_mask(par->state.vgabase, 0x15, multiplex ? 0x10 : 0x00, 0x10);
  741. svga_wseq_mask(par->state.vgabase, 0x18, multiplex ? 0x80 : 0x00, 0x80);
  742. }
  743. s3_set_pixclock(info, info->var.pixclock);
  744. svga_set_timings(par->state.vgabase, &s3_timing_regs, &(info->var), hmul, 1,
  745. (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1,
  746. (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1,
  747. hmul, info->node);
  748. /* Set interlaced mode start/end register */
  749. htotal = info->var.xres + info->var.left_margin + info->var.right_margin + info->var.hsync_len;
  750. htotal = ((htotal * hmul) / 8) - 5;
  751. vga_wcrt(par->state.vgabase, 0x3C, (htotal + 1) / 2);
  752. /* Set Data Transfer Position */
  753. hsstart = ((info->var.xres + info->var.right_margin) * hmul) / 8;
  754. /* + 2 is needed for Virge/VX, does no harm on other cards */
  755. value = clamp((htotal + hsstart + 1) / 2 + 2, hsstart + 4, htotal + 1);
  756. svga_wcrt_multi(par->state.vgabase, s3_dtpc_regs, value);
  757. memset_io(info->screen_base, 0x00, screen_size);
  758. /* Device and screen back on */
  759. svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80);
  760. svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
  761. return 0;
  762. }
  763. /* Set a colour register */
  764. static int s3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  765. u_int transp, struct fb_info *fb)
  766. {
  767. switch (fb->var.bits_per_pixel) {
  768. case 0:
  769. case 4:
  770. if (regno >= 16)
  771. return -EINVAL;
  772. if ((fb->var.bits_per_pixel == 4) &&
  773. (fb->var.nonstd == 0)) {
  774. outb(0xF0, VGA_PEL_MSK);
  775. outb(regno*16, VGA_PEL_IW);
  776. } else {
  777. outb(0x0F, VGA_PEL_MSK);
  778. outb(regno, VGA_PEL_IW);
  779. }
  780. outb(red >> 10, VGA_PEL_D);
  781. outb(green >> 10, VGA_PEL_D);
  782. outb(blue >> 10, VGA_PEL_D);
  783. break;
  784. case 8:
  785. if (regno >= 256)
  786. return -EINVAL;
  787. outb(0xFF, VGA_PEL_MSK);
  788. outb(regno, VGA_PEL_IW);
  789. outb(red >> 10, VGA_PEL_D);
  790. outb(green >> 10, VGA_PEL_D);
  791. outb(blue >> 10, VGA_PEL_D);
  792. break;
  793. case 16:
  794. if (regno >= 16)
  795. return 0;
  796. if (fb->var.green.length == 5)
  797. ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
  798. ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);
  799. else if (fb->var.green.length == 6)
  800. ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |
  801. ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
  802. else return -EINVAL;
  803. break;
  804. case 24:
  805. case 32:
  806. if (regno >= 16)
  807. return 0;
  808. ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) |
  809. (green & 0xFF00) | ((blue & 0xFF00) >> 8);
  810. break;
  811. default:
  812. return -EINVAL;
  813. }
  814. return 0;
  815. }
  816. /* Set the display blanking state */
  817. static int s3fb_blank(int blank_mode, struct fb_info *info)
  818. {
  819. struct s3fb_info *par = info->par;
  820. switch (blank_mode) {
  821. case FB_BLANK_UNBLANK:
  822. pr_debug("fb%d: unblank\n", info->node);
  823. svga_wcrt_mask(par->state.vgabase, 0x56, 0x00, 0x06);
  824. svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
  825. break;
  826. case FB_BLANK_NORMAL:
  827. pr_debug("fb%d: blank\n", info->node);
  828. svga_wcrt_mask(par->state.vgabase, 0x56, 0x00, 0x06);
  829. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  830. break;
  831. case FB_BLANK_HSYNC_SUSPEND:
  832. pr_debug("fb%d: hsync\n", info->node);
  833. svga_wcrt_mask(par->state.vgabase, 0x56, 0x02, 0x06);
  834. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  835. break;
  836. case FB_BLANK_VSYNC_SUSPEND:
  837. pr_debug("fb%d: vsync\n", info->node);
  838. svga_wcrt_mask(par->state.vgabase, 0x56, 0x04, 0x06);
  839. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  840. break;
  841. case FB_BLANK_POWERDOWN:
  842. pr_debug("fb%d: sync down\n", info->node);
  843. svga_wcrt_mask(par->state.vgabase, 0x56, 0x06, 0x06);
  844. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  845. break;
  846. }
  847. return 0;
  848. }
  849. /* Pan the display */
  850. static int s3fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  851. {
  852. struct s3fb_info *par = info->par;
  853. unsigned int offset;
  854. /* Calculate the offset */
  855. if (info->var.bits_per_pixel == 0) {
  856. offset = (var->yoffset / 16) * (info->var.xres_virtual / 2)
  857. + (var->xoffset / 2);
  858. offset = offset >> 2;
  859. } else {
  860. offset = (var->yoffset * info->fix.line_length) +
  861. (var->xoffset * info->var.bits_per_pixel / 8);
  862. offset = offset >> 2;
  863. }
  864. /* Set the offset */
  865. svga_wcrt_multi(par->state.vgabase, s3_start_address_regs, offset);
  866. return 0;
  867. }
  868. /* ------------------------------------------------------------------------- */
  869. /* Frame buffer operations */
  870. static struct fb_ops s3fb_ops = {
  871. .owner = THIS_MODULE,
  872. .fb_open = s3fb_open,
  873. .fb_release = s3fb_release,
  874. .fb_check_var = s3fb_check_var,
  875. .fb_set_par = s3fb_set_par,
  876. .fb_setcolreg = s3fb_setcolreg,
  877. .fb_blank = s3fb_blank,
  878. .fb_pan_display = s3fb_pan_display,
  879. .fb_fillrect = s3fb_fillrect,
  880. .fb_copyarea = cfb_copyarea,
  881. .fb_imageblit = s3fb_imageblit,
  882. .fb_get_caps = svga_get_caps,
  883. };
  884. /* ------------------------------------------------------------------------- */
  885. static int s3_identification(struct s3fb_info *par)
  886. {
  887. int chip = par->chip;
  888. if (chip == CHIP_XXX_TRIO) {
  889. u8 cr30 = vga_rcrt(par->state.vgabase, 0x30);
  890. u8 cr2e = vga_rcrt(par->state.vgabase, 0x2e);
  891. u8 cr2f = vga_rcrt(par->state.vgabase, 0x2f);
  892. if ((cr30 == 0xE0) || (cr30 == 0xE1)) {
  893. if (cr2e == 0x10)
  894. return CHIP_732_TRIO32;
  895. if (cr2e == 0x11) {
  896. if (! (cr2f & 0x40))
  897. return CHIP_764_TRIO64;
  898. else
  899. return CHIP_765_TRIO64VP;
  900. }
  901. }
  902. }
  903. if (chip == CHIP_XXX_TRIO64V2_DXGX) {
  904. u8 cr6f = vga_rcrt(par->state.vgabase, 0x6f);
  905. if (! (cr6f & 0x01))
  906. return CHIP_775_TRIO64V2_DX;
  907. else
  908. return CHIP_785_TRIO64V2_GX;
  909. }
  910. if (chip == CHIP_XXX_VIRGE_DXGX) {
  911. u8 cr6f = vga_rcrt(par->state.vgabase, 0x6f);
  912. if (! (cr6f & 0x01))
  913. return CHIP_375_VIRGE_DX;
  914. else
  915. return CHIP_385_VIRGE_GX;
  916. }
  917. if (chip == CHIP_36X_TRIO3D_1X_2X) {
  918. switch (vga_rcrt(par->state.vgabase, 0x2f)) {
  919. case 0x00:
  920. return CHIP_360_TRIO3D_1X;
  921. case 0x01:
  922. return CHIP_362_TRIO3D_2X;
  923. case 0x02:
  924. return CHIP_368_TRIO3D_2X;
  925. }
  926. }
  927. return CHIP_UNKNOWN;
  928. }
  929. /* PCI probe */
  930. static int s3_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  931. {
  932. struct pci_bus_region bus_reg;
  933. struct resource vga_res;
  934. struct fb_info *info;
  935. struct s3fb_info *par;
  936. int rc;
  937. u8 regval, cr38, cr39;
  938. bool found = false;
  939. /* Ignore secondary VGA device because there is no VGA arbitration */
  940. if (! svga_primary_device(dev)) {
  941. dev_info(&(dev->dev), "ignoring secondary device\n");
  942. return -ENODEV;
  943. }
  944. /* Allocate and fill driver data structure */
  945. info = framebuffer_alloc(sizeof(struct s3fb_info), &(dev->dev));
  946. if (!info) {
  947. dev_err(&(dev->dev), "cannot allocate memory\n");
  948. return -ENOMEM;
  949. }
  950. par = info->par;
  951. mutex_init(&par->open_lock);
  952. info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
  953. info->fbops = &s3fb_ops;
  954. /* Prepare PCI device */
  955. rc = pci_enable_device(dev);
  956. if (rc < 0) {
  957. dev_err(info->device, "cannot enable PCI device\n");
  958. goto err_enable_device;
  959. }
  960. rc = pci_request_regions(dev, "s3fb");
  961. if (rc < 0) {
  962. dev_err(info->device, "cannot reserve framebuffer region\n");
  963. goto err_request_regions;
  964. }
  965. info->fix.smem_start = pci_resource_start(dev, 0);
  966. info->fix.smem_len = pci_resource_len(dev, 0);
  967. /* Map physical IO memory address into kernel space */
  968. info->screen_base = pci_iomap(dev, 0, 0);
  969. if (! info->screen_base) {
  970. rc = -ENOMEM;
  971. dev_err(info->device, "iomap for framebuffer failed\n");
  972. goto err_iomap;
  973. }
  974. bus_reg.start = 0;
  975. bus_reg.end = 64 * 1024;
  976. vga_res.flags = IORESOURCE_IO;
  977. pcibios_bus_to_resource(dev, &vga_res, &bus_reg);
  978. par->state.vgabase = (void __iomem *) vga_res.start;
  979. /* Unlock regs */
  980. cr38 = vga_rcrt(par->state.vgabase, 0x38);
  981. cr39 = vga_rcrt(par->state.vgabase, 0x39);
  982. vga_wseq(par->state.vgabase, 0x08, 0x06);
  983. vga_wcrt(par->state.vgabase, 0x38, 0x48);
  984. vga_wcrt(par->state.vgabase, 0x39, 0xA5);
  985. /* Identify chip type */
  986. par->chip = id->driver_data & CHIP_MASK;
  987. par->rev = vga_rcrt(par->state.vgabase, 0x2f);
  988. if (par->chip & CHIP_UNDECIDED_FLAG)
  989. par->chip = s3_identification(par);
  990. /* Find how many physical memory there is on card */
  991. /* 0x36 register is accessible even if other registers are locked */
  992. regval = vga_rcrt(par->state.vgabase, 0x36);
  993. if (par->chip == CHIP_360_TRIO3D_1X ||
  994. par->chip == CHIP_362_TRIO3D_2X ||
  995. par->chip == CHIP_368_TRIO3D_2X ||
  996. par->chip == CHIP_365_TRIO3D) {
  997. switch ((regval & 0xE0) >> 5) {
  998. case 0: /* 8MB -- only 4MB usable for display */
  999. case 1: /* 4MB with 32-bit bus */
  1000. case 2: /* 4MB */
  1001. info->screen_size = 4 << 20;
  1002. break;
  1003. case 4: /* 2MB on 365 Trio3D */
  1004. case 6: /* 2MB */
  1005. info->screen_size = 2 << 20;
  1006. break;
  1007. }
  1008. } else if (par->chip == CHIP_357_VIRGE_GX2 ||
  1009. par->chip == CHIP_359_VIRGE_GX2P ||
  1010. par->chip == CHIP_260_VIRGE_MX) {
  1011. switch ((regval & 0xC0) >> 6) {
  1012. case 1: /* 4MB */
  1013. info->screen_size = 4 << 20;
  1014. break;
  1015. case 3: /* 2MB */
  1016. info->screen_size = 2 << 20;
  1017. break;
  1018. }
  1019. } else if (par->chip == CHIP_988_VIRGE_VX) {
  1020. switch ((regval & 0x60) >> 5) {
  1021. case 0: /* 2MB */
  1022. info->screen_size = 2 << 20;
  1023. break;
  1024. case 1: /* 4MB */
  1025. info->screen_size = 4 << 20;
  1026. break;
  1027. case 2: /* 6MB */
  1028. info->screen_size = 6 << 20;
  1029. break;
  1030. case 3: /* 8MB */
  1031. info->screen_size = 8 << 20;
  1032. break;
  1033. }
  1034. /* off-screen memory */
  1035. regval = vga_rcrt(par->state.vgabase, 0x37);
  1036. switch ((regval & 0x60) >> 5) {
  1037. case 1: /* 4MB */
  1038. info->screen_size -= 4 << 20;
  1039. break;
  1040. case 2: /* 2MB */
  1041. info->screen_size -= 2 << 20;
  1042. break;
  1043. }
  1044. } else
  1045. info->screen_size = s3_memsizes[regval >> 5] << 10;
  1046. info->fix.smem_len = info->screen_size;
  1047. /* Find MCLK frequency */
  1048. regval = vga_rseq(par->state.vgabase, 0x10);
  1049. par->mclk_freq = ((vga_rseq(par->state.vgabase, 0x11) + 2) * 14318) / ((regval & 0x1F) + 2);
  1050. par->mclk_freq = par->mclk_freq >> (regval >> 5);
  1051. /* Restore locks */
  1052. vga_wcrt(par->state.vgabase, 0x38, cr38);
  1053. vga_wcrt(par->state.vgabase, 0x39, cr39);
  1054. strcpy(info->fix.id, s3_names [par->chip]);
  1055. info->fix.mmio_start = 0;
  1056. info->fix.mmio_len = 0;
  1057. info->fix.type = FB_TYPE_PACKED_PIXELS;
  1058. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  1059. info->fix.ypanstep = 0;
  1060. info->fix.accel = FB_ACCEL_NONE;
  1061. info->pseudo_palette = (void*) (par->pseudo_palette);
  1062. info->var.bits_per_pixel = 8;
  1063. #ifdef CONFIG_FB_S3_DDC
  1064. /* Enable MMIO if needed */
  1065. if (s3fb_ddc_needs_mmio(par->chip)) {
  1066. par->mmio = ioremap(info->fix.smem_start + MMIO_OFFSET, MMIO_SIZE);
  1067. if (par->mmio)
  1068. svga_wcrt_mask(par->state.vgabase, 0x53, 0x08, 0x08); /* enable MMIO */
  1069. else
  1070. dev_err(info->device, "unable to map MMIO at 0x%lx, disabling DDC",
  1071. info->fix.smem_start + MMIO_OFFSET);
  1072. }
  1073. if (!s3fb_ddc_needs_mmio(par->chip) || par->mmio)
  1074. if (s3fb_setup_ddc_bus(info) == 0) {
  1075. u8 *edid = fb_ddc_read(&par->ddc_adapter);
  1076. par->ddc_registered = true;
  1077. if (edid) {
  1078. fb_edid_to_monspecs(edid, &info->monspecs);
  1079. kfree(edid);
  1080. if (!info->monspecs.modedb)
  1081. dev_err(info->device, "error getting mode database\n");
  1082. else {
  1083. const struct fb_videomode *m;
  1084. fb_videomode_to_modelist(info->monspecs.modedb,
  1085. info->monspecs.modedb_len,
  1086. &info->modelist);
  1087. m = fb_find_best_display(&info->monspecs, &info->modelist);
  1088. if (m) {
  1089. fb_videomode_to_var(&info->var, m);
  1090. /* fill all other info->var's fields */
  1091. if (s3fb_check_var(&info->var, info) == 0)
  1092. found = true;
  1093. }
  1094. }
  1095. }
  1096. }
  1097. #endif
  1098. if (!mode_option && !found)
  1099. mode_option = "640x480-8@60";
  1100. /* Prepare startup mode */
  1101. if (mode_option) {
  1102. rc = fb_find_mode(&info->var, info, mode_option,
  1103. info->monspecs.modedb, info->monspecs.modedb_len,
  1104. NULL, info->var.bits_per_pixel);
  1105. if (!rc || rc == 4) {
  1106. rc = -EINVAL;
  1107. dev_err(info->device, "mode %s not found\n", mode_option);
  1108. fb_destroy_modedb(info->monspecs.modedb);
  1109. info->monspecs.modedb = NULL;
  1110. goto err_find_mode;
  1111. }
  1112. }
  1113. fb_destroy_modedb(info->monspecs.modedb);
  1114. info->monspecs.modedb = NULL;
  1115. /* maximize virtual vertical size for fast scrolling */
  1116. info->var.yres_virtual = info->fix.smem_len * 8 /
  1117. (info->var.bits_per_pixel * info->var.xres_virtual);
  1118. if (info->var.yres_virtual < info->var.yres) {
  1119. dev_err(info->device, "virtual vertical size smaller than real\n");
  1120. goto err_find_mode;
  1121. }
  1122. /* maximize virtual vertical size for fast scrolling */
  1123. info->var.yres_virtual = info->fix.smem_len * 8 /
  1124. (info->var.bits_per_pixel * info->var.xres_virtual);
  1125. if (info->var.yres_virtual < info->var.yres) {
  1126. dev_err(info->device, "virtual vertical size smaller than real\n");
  1127. goto err_find_mode;
  1128. }
  1129. rc = fb_alloc_cmap(&info->cmap, 256, 0);
  1130. if (rc < 0) {
  1131. dev_err(info->device, "cannot allocate colormap\n");
  1132. goto err_alloc_cmap;
  1133. }
  1134. rc = register_framebuffer(info);
  1135. if (rc < 0) {
  1136. dev_err(info->device, "cannot register framebuffer\n");
  1137. goto err_reg_fb;
  1138. }
  1139. printk(KERN_INFO "fb%d: %s on %s, %d MB RAM, %d MHz MCLK\n", info->node, info->fix.id,
  1140. pci_name(dev), info->fix.smem_len >> 20, (par->mclk_freq + 500) / 1000);
  1141. if (par->chip == CHIP_UNKNOWN)
  1142. printk(KERN_INFO "fb%d: unknown chip, CR2D=%x, CR2E=%x, CRT2F=%x, CRT30=%x\n",
  1143. info->node, vga_rcrt(par->state.vgabase, 0x2d), vga_rcrt(par->state.vgabase, 0x2e),
  1144. vga_rcrt(par->state.vgabase, 0x2f), vga_rcrt(par->state.vgabase, 0x30));
  1145. /* Record a reference to the driver data */
  1146. pci_set_drvdata(dev, info);
  1147. #ifdef CONFIG_MTRR
  1148. if (mtrr) {
  1149. par->mtrr_reg = -1;
  1150. par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1);
  1151. }
  1152. #endif
  1153. return 0;
  1154. /* Error handling */
  1155. err_reg_fb:
  1156. fb_dealloc_cmap(&info->cmap);
  1157. err_alloc_cmap:
  1158. err_find_mode:
  1159. #ifdef CONFIG_FB_S3_DDC
  1160. if (par->ddc_registered)
  1161. i2c_del_adapter(&par->ddc_adapter);
  1162. if (par->mmio)
  1163. iounmap(par->mmio);
  1164. #endif
  1165. pci_iounmap(dev, info->screen_base);
  1166. err_iomap:
  1167. pci_release_regions(dev);
  1168. err_request_regions:
  1169. /* pci_disable_device(dev); */
  1170. err_enable_device:
  1171. framebuffer_release(info);
  1172. return rc;
  1173. }
  1174. /* PCI remove */
  1175. static void s3_pci_remove(struct pci_dev *dev)
  1176. {
  1177. struct fb_info *info = pci_get_drvdata(dev);
  1178. struct s3fb_info __maybe_unused *par = info->par;
  1179. if (info) {
  1180. #ifdef CONFIG_MTRR
  1181. if (par->mtrr_reg >= 0) {
  1182. mtrr_del(par->mtrr_reg, 0, 0);
  1183. par->mtrr_reg = -1;
  1184. }
  1185. #endif
  1186. unregister_framebuffer(info);
  1187. fb_dealloc_cmap(&info->cmap);
  1188. #ifdef CONFIG_FB_S3_DDC
  1189. if (par->ddc_registered)
  1190. i2c_del_adapter(&par->ddc_adapter);
  1191. if (par->mmio)
  1192. iounmap(par->mmio);
  1193. #endif
  1194. pci_iounmap(dev, info->screen_base);
  1195. pci_release_regions(dev);
  1196. /* pci_disable_device(dev); */
  1197. pci_set_drvdata(dev, NULL);
  1198. framebuffer_release(info);
  1199. }
  1200. }
  1201. /* PCI suspend */
  1202. static int s3_pci_suspend(struct pci_dev* dev, pm_message_t state)
  1203. {
  1204. struct fb_info *info = pci_get_drvdata(dev);
  1205. struct s3fb_info *par = info->par;
  1206. dev_info(info->device, "suspend\n");
  1207. console_lock();
  1208. mutex_lock(&(par->open_lock));
  1209. if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {
  1210. mutex_unlock(&(par->open_lock));
  1211. console_unlock();
  1212. return 0;
  1213. }
  1214. fb_set_suspend(info, 1);
  1215. pci_save_state(dev);
  1216. pci_disable_device(dev);
  1217. pci_set_power_state(dev, pci_choose_state(dev, state));
  1218. mutex_unlock(&(par->open_lock));
  1219. console_unlock();
  1220. return 0;
  1221. }
  1222. /* PCI resume */
  1223. static int s3_pci_resume(struct pci_dev* dev)
  1224. {
  1225. struct fb_info *info = pci_get_drvdata(dev);
  1226. struct s3fb_info *par = info->par;
  1227. int err;
  1228. dev_info(info->device, "resume\n");
  1229. console_lock();
  1230. mutex_lock(&(par->open_lock));
  1231. if (par->ref_count == 0) {
  1232. mutex_unlock(&(par->open_lock));
  1233. console_unlock();
  1234. return 0;
  1235. }
  1236. pci_set_power_state(dev, PCI_D0);
  1237. pci_restore_state(dev);
  1238. err = pci_enable_device(dev);
  1239. if (err) {
  1240. mutex_unlock(&(par->open_lock));
  1241. console_unlock();
  1242. dev_err(info->device, "error %d enabling device for resume\n", err);
  1243. return err;
  1244. }
  1245. pci_set_master(dev);
  1246. s3fb_set_par(info);
  1247. fb_set_suspend(info, 0);
  1248. mutex_unlock(&(par->open_lock));
  1249. console_unlock();
  1250. return 0;
  1251. }
  1252. /* List of boards that we are trying to support */
  1253. static struct pci_device_id s3_devices[] = {
  1254. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8810), .driver_data = CHIP_XXX_TRIO},
  1255. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8811), .driver_data = CHIP_XXX_TRIO},
  1256. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8812), .driver_data = CHIP_M65_AURORA64VP},
  1257. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8814), .driver_data = CHIP_767_TRIO64UVP},
  1258. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8901), .driver_data = CHIP_XXX_TRIO64V2_DXGX},
  1259. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8902), .driver_data = CHIP_551_PLATO_PX},
  1260. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x5631), .driver_data = CHIP_325_VIRGE},
  1261. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x883D), .driver_data = CHIP_988_VIRGE_VX},
  1262. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A01), .driver_data = CHIP_XXX_VIRGE_DXGX},
  1263. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A10), .driver_data = CHIP_357_VIRGE_GX2},
  1264. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A11), .driver_data = CHIP_359_VIRGE_GX2P},
  1265. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A12), .driver_data = CHIP_359_VIRGE_GX2P},
  1266. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A13), .driver_data = CHIP_36X_TRIO3D_1X_2X},
  1267. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8904), .driver_data = CHIP_365_TRIO3D},
  1268. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8C01), .driver_data = CHIP_260_VIRGE_MX},
  1269. {0, 0, 0, 0, 0, 0, 0}
  1270. };
  1271. MODULE_DEVICE_TABLE(pci, s3_devices);
  1272. static struct pci_driver s3fb_pci_driver = {
  1273. .name = "s3fb",
  1274. .id_table = s3_devices,
  1275. .probe = s3_pci_probe,
  1276. .remove = s3_pci_remove,
  1277. .suspend = s3_pci_suspend,
  1278. .resume = s3_pci_resume,
  1279. };
  1280. /* Parse user specified options */
  1281. #ifndef MODULE
  1282. static int __init s3fb_setup(char *options)
  1283. {
  1284. char *opt;
  1285. if (!options || !*options)
  1286. return 0;
  1287. while ((opt = strsep(&options, ",")) != NULL) {
  1288. if (!*opt)
  1289. continue;
  1290. #ifdef CONFIG_MTRR
  1291. else if (!strncmp(opt, "mtrr:", 5))
  1292. mtrr = simple_strtoul(opt + 5, NULL, 0);
  1293. #endif
  1294. else if (!strncmp(opt, "fasttext:", 9))
  1295. fasttext = simple_strtoul(opt + 9, NULL, 0);
  1296. else
  1297. mode_option = opt;
  1298. }
  1299. return 0;
  1300. }
  1301. #endif
  1302. /* Cleanup */
  1303. static void __exit s3fb_cleanup(void)
  1304. {
  1305. pr_debug("s3fb: cleaning up\n");
  1306. pci_unregister_driver(&s3fb_pci_driver);
  1307. }
  1308. /* Driver Initialisation */
  1309. static int __init s3fb_init(void)
  1310. {
  1311. #ifndef MODULE
  1312. char *option = NULL;
  1313. if (fb_get_options("s3fb", &option))
  1314. return -ENODEV;
  1315. s3fb_setup(option);
  1316. #endif
  1317. pr_debug("s3fb: initializing\n");
  1318. return pci_register_driver(&s3fb_pci_driver);
  1319. }
  1320. /* ------------------------------------------------------------------------- */
  1321. /* Modularization */
  1322. module_init(s3fb_init);
  1323. module_exit(s3fb_cleanup);