s3fb.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599
  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. fb_err(info, "unsupported font parameters: width %d, height %d, depth %d, length %d\n",
  252. 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. fb_err(info, "cannot set requested pixclock, keeping old value\n");
  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. fb_err(info, "unsupported mode requested\n");
  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. fb_err(info, "not enough framebuffer memory (%d kB requested , %u kB available)\n",
  479. 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. fb_err(info, "invalid timings requested\n");
  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. fb_err(info, "invalid pixclock value requested\n");
  491. return rv;
  492. }
  493. return 0;
  494. }
  495. /* Set video mode from par */
  496. static int s3fb_set_par(struct fb_info *info)
  497. {
  498. struct s3fb_info *par = info->par;
  499. u32 value, mode, hmul, offset_value, screen_size, multiplex, dbytes;
  500. u32 bpp = info->var.bits_per_pixel;
  501. u32 htotal, hsstart;
  502. if (bpp != 0) {
  503. info->fix.ypanstep = 1;
  504. info->fix.line_length = (info->var.xres_virtual * bpp) / 8;
  505. info->flags &= ~FBINFO_MISC_TILEBLITTING;
  506. info->tileops = NULL;
  507. /* in 4bpp supports 8p wide tiles only, any tiles otherwise */
  508. info->pixmap.blit_x = (bpp == 4) ? (1 << (8 - 1)) : (~(u32)0);
  509. info->pixmap.blit_y = ~(u32)0;
  510. offset_value = (info->var.xres_virtual * bpp) / 64;
  511. screen_size = info->var.yres_virtual * info->fix.line_length;
  512. } else {
  513. info->fix.ypanstep = 16;
  514. info->fix.line_length = 0;
  515. info->flags |= FBINFO_MISC_TILEBLITTING;
  516. info->tileops = fasttext ? &s3fb_fast_tile_ops : &s3fb_tile_ops;
  517. /* supports 8x16 tiles only */
  518. info->pixmap.blit_x = 1 << (8 - 1);
  519. info->pixmap.blit_y = 1 << (16 - 1);
  520. offset_value = info->var.xres_virtual / 16;
  521. screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
  522. }
  523. info->var.xoffset = 0;
  524. info->var.yoffset = 0;
  525. info->var.activate = FB_ACTIVATE_NOW;
  526. /* Unlock registers */
  527. vga_wcrt(par->state.vgabase, 0x38, 0x48);
  528. vga_wcrt(par->state.vgabase, 0x39, 0xA5);
  529. vga_wseq(par->state.vgabase, 0x08, 0x06);
  530. svga_wcrt_mask(par->state.vgabase, 0x11, 0x00, 0x80);
  531. /* Blank screen and turn off sync */
  532. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  533. svga_wcrt_mask(par->state.vgabase, 0x17, 0x00, 0x80);
  534. /* Set default values */
  535. svga_set_default_gfx_regs(par->state.vgabase);
  536. svga_set_default_atc_regs(par->state.vgabase);
  537. svga_set_default_seq_regs(par->state.vgabase);
  538. svga_set_default_crt_regs(par->state.vgabase);
  539. svga_wcrt_multi(par->state.vgabase, s3_line_compare_regs, 0xFFFFFFFF);
  540. svga_wcrt_multi(par->state.vgabase, s3_start_address_regs, 0);
  541. /* S3 specific initialization */
  542. svga_wcrt_mask(par->state.vgabase, 0x58, 0x10, 0x10); /* enable linear framebuffer */
  543. svga_wcrt_mask(par->state.vgabase, 0x31, 0x08, 0x08); /* enable sequencer access to framebuffer above 256 kB */
  544. /* svga_wcrt_mask(par->state.vgabase, 0x33, 0x08, 0x08); */ /* DDR ? */
  545. /* svga_wcrt_mask(par->state.vgabase, 0x43, 0x01, 0x01); */ /* DDR ? */
  546. svga_wcrt_mask(par->state.vgabase, 0x33, 0x00, 0x08); /* no DDR ? */
  547. svga_wcrt_mask(par->state.vgabase, 0x43, 0x00, 0x01); /* no DDR ? */
  548. svga_wcrt_mask(par->state.vgabase, 0x5D, 0x00, 0x28); /* Clear strange HSlen bits */
  549. /* svga_wcrt_mask(par->state.vgabase, 0x58, 0x03, 0x03); */
  550. /* svga_wcrt_mask(par->state.vgabase, 0x53, 0x12, 0x13); */ /* enable MMIO */
  551. /* svga_wcrt_mask(par->state.vgabase, 0x40, 0x08, 0x08); */ /* enable write buffer */
  552. /* Set the offset register */
  553. fb_dbg(info, "offset register : %d\n", offset_value);
  554. svga_wcrt_multi(par->state.vgabase, s3_offset_regs, offset_value);
  555. if (par->chip != CHIP_357_VIRGE_GX2 &&
  556. par->chip != CHIP_359_VIRGE_GX2P &&
  557. par->chip != CHIP_360_TRIO3D_1X &&
  558. par->chip != CHIP_362_TRIO3D_2X &&
  559. par->chip != CHIP_368_TRIO3D_2X &&
  560. par->chip != CHIP_260_VIRGE_MX) {
  561. vga_wcrt(par->state.vgabase, 0x54, 0x18); /* M parameter */
  562. vga_wcrt(par->state.vgabase, 0x60, 0xff); /* N parameter */
  563. vga_wcrt(par->state.vgabase, 0x61, 0xff); /* L parameter */
  564. vga_wcrt(par->state.vgabase, 0x62, 0xff); /* L parameter */
  565. }
  566. vga_wcrt(par->state.vgabase, 0x3A, 0x35);
  567. svga_wattr(par->state.vgabase, 0x33, 0x00);
  568. if (info->var.vmode & FB_VMODE_DOUBLE)
  569. svga_wcrt_mask(par->state.vgabase, 0x09, 0x80, 0x80);
  570. else
  571. svga_wcrt_mask(par->state.vgabase, 0x09, 0x00, 0x80);
  572. if (info->var.vmode & FB_VMODE_INTERLACED)
  573. svga_wcrt_mask(par->state.vgabase, 0x42, 0x20, 0x20);
  574. else
  575. svga_wcrt_mask(par->state.vgabase, 0x42, 0x00, 0x20);
  576. /* Disable hardware graphics cursor */
  577. svga_wcrt_mask(par->state.vgabase, 0x45, 0x00, 0x01);
  578. /* Disable Streams engine */
  579. svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0x0C);
  580. mode = svga_match_format(s3fb_formats, &(info->var), &(info->fix));
  581. /* S3 virge DX hack */
  582. if (par->chip == CHIP_375_VIRGE_DX) {
  583. vga_wcrt(par->state.vgabase, 0x86, 0x80);
  584. vga_wcrt(par->state.vgabase, 0x90, 0x00);
  585. }
  586. /* S3 virge VX hack */
  587. if (par->chip == CHIP_988_VIRGE_VX) {
  588. vga_wcrt(par->state.vgabase, 0x50, 0x00);
  589. vga_wcrt(par->state.vgabase, 0x67, 0x50);
  590. msleep(10); /* screen remains blank sometimes without this */
  591. vga_wcrt(par->state.vgabase, 0x63, (mode <= 2) ? 0x90 : 0x09);
  592. vga_wcrt(par->state.vgabase, 0x66, 0x90);
  593. }
  594. if (par->chip == CHIP_357_VIRGE_GX2 ||
  595. par->chip == CHIP_359_VIRGE_GX2P ||
  596. par->chip == CHIP_360_TRIO3D_1X ||
  597. par->chip == CHIP_362_TRIO3D_2X ||
  598. par->chip == CHIP_368_TRIO3D_2X ||
  599. par->chip == CHIP_365_TRIO3D ||
  600. par->chip == CHIP_375_VIRGE_DX ||
  601. par->chip == CHIP_385_VIRGE_GX ||
  602. par->chip == CHIP_260_VIRGE_MX) {
  603. dbytes = info->var.xres * ((bpp+7)/8);
  604. vga_wcrt(par->state.vgabase, 0x91, (dbytes + 7) / 8);
  605. vga_wcrt(par->state.vgabase, 0x90, (((dbytes + 7) / 8) >> 8) | 0x80);
  606. vga_wcrt(par->state.vgabase, 0x66, 0x81);
  607. }
  608. if (par->chip == CHIP_357_VIRGE_GX2 ||
  609. par->chip == CHIP_359_VIRGE_GX2P ||
  610. par->chip == CHIP_360_TRIO3D_1X ||
  611. par->chip == CHIP_362_TRIO3D_2X ||
  612. par->chip == CHIP_368_TRIO3D_2X ||
  613. par->chip == CHIP_260_VIRGE_MX)
  614. vga_wcrt(par->state.vgabase, 0x34, 0x00);
  615. else /* enable Data Transfer Position Control (DTPC) */
  616. vga_wcrt(par->state.vgabase, 0x34, 0x10);
  617. svga_wcrt_mask(par->state.vgabase, 0x31, 0x00, 0x40);
  618. multiplex = 0;
  619. hmul = 1;
  620. /* Set mode-specific register values */
  621. switch (mode) {
  622. case 0:
  623. fb_dbg(info, "text mode\n");
  624. svga_set_textmode_vga_regs(par->state.vgabase);
  625. /* Set additional registers like in 8-bit mode */
  626. svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
  627. svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
  628. /* Disable enhanced mode */
  629. svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30);
  630. if (fasttext) {
  631. fb_dbg(info, "high speed text mode set\n");
  632. svga_wcrt_mask(par->state.vgabase, 0x31, 0x40, 0x40);
  633. }
  634. break;
  635. case 1:
  636. fb_dbg(info, "4 bit pseudocolor\n");
  637. vga_wgfx(par->state.vgabase, VGA_GFX_MODE, 0x40);
  638. /* Set additional registers like in 8-bit mode */
  639. svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
  640. svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
  641. /* disable enhanced mode */
  642. svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30);
  643. break;
  644. case 2:
  645. fb_dbg(info, "4 bit pseudocolor, planar\n");
  646. /* Set additional registers like in 8-bit mode */
  647. svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
  648. svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
  649. /* disable enhanced mode */
  650. svga_wcrt_mask(par->state.vgabase, 0x3A, 0x00, 0x30);
  651. break;
  652. case 3:
  653. fb_dbg(info, "8 bit pseudocolor\n");
  654. svga_wcrt_mask(par->state.vgabase, 0x50, 0x00, 0x30);
  655. if (info->var.pixclock > 20000 ||
  656. par->chip == CHIP_357_VIRGE_GX2 ||
  657. par->chip == CHIP_359_VIRGE_GX2P ||
  658. par->chip == CHIP_360_TRIO3D_1X ||
  659. par->chip == CHIP_362_TRIO3D_2X ||
  660. par->chip == CHIP_368_TRIO3D_2X ||
  661. par->chip == CHIP_260_VIRGE_MX)
  662. svga_wcrt_mask(par->state.vgabase, 0x67, 0x00, 0xF0);
  663. else {
  664. svga_wcrt_mask(par->state.vgabase, 0x67, 0x10, 0xF0);
  665. multiplex = 1;
  666. }
  667. break;
  668. case 4:
  669. fb_dbg(info, "5/5/5 truecolor\n");
  670. if (par->chip == CHIP_988_VIRGE_VX) {
  671. if (info->var.pixclock > 20000)
  672. svga_wcrt_mask(par->state.vgabase, 0x67, 0x20, 0xF0);
  673. else
  674. svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0);
  675. } else if (par->chip == CHIP_365_TRIO3D) {
  676. svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
  677. if (info->var.pixclock > 8695) {
  678. svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0);
  679. hmul = 2;
  680. } else {
  681. svga_wcrt_mask(par->state.vgabase, 0x67, 0x20, 0xF0);
  682. multiplex = 1;
  683. }
  684. } else {
  685. svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
  686. svga_wcrt_mask(par->state.vgabase, 0x67, 0x30, 0xF0);
  687. if (par->chip != CHIP_357_VIRGE_GX2 &&
  688. par->chip != CHIP_359_VIRGE_GX2P &&
  689. par->chip != CHIP_360_TRIO3D_1X &&
  690. par->chip != CHIP_362_TRIO3D_2X &&
  691. par->chip != CHIP_368_TRIO3D_2X &&
  692. par->chip != CHIP_260_VIRGE_MX)
  693. hmul = 2;
  694. }
  695. break;
  696. case 5:
  697. fb_dbg(info, "5/6/5 truecolor\n");
  698. if (par->chip == CHIP_988_VIRGE_VX) {
  699. if (info->var.pixclock > 20000)
  700. svga_wcrt_mask(par->state.vgabase, 0x67, 0x40, 0xF0);
  701. else
  702. svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
  703. } else if (par->chip == CHIP_365_TRIO3D) {
  704. svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
  705. if (info->var.pixclock > 8695) {
  706. svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
  707. hmul = 2;
  708. } else {
  709. svga_wcrt_mask(par->state.vgabase, 0x67, 0x40, 0xF0);
  710. multiplex = 1;
  711. }
  712. } else {
  713. svga_wcrt_mask(par->state.vgabase, 0x50, 0x10, 0x30);
  714. svga_wcrt_mask(par->state.vgabase, 0x67, 0x50, 0xF0);
  715. if (par->chip != CHIP_357_VIRGE_GX2 &&
  716. par->chip != CHIP_359_VIRGE_GX2P &&
  717. par->chip != CHIP_360_TRIO3D_1X &&
  718. par->chip != CHIP_362_TRIO3D_2X &&
  719. par->chip != CHIP_368_TRIO3D_2X &&
  720. par->chip != CHIP_260_VIRGE_MX)
  721. hmul = 2;
  722. }
  723. break;
  724. case 6:
  725. /* VIRGE VX case */
  726. fb_dbg(info, "8/8/8 truecolor\n");
  727. svga_wcrt_mask(par->state.vgabase, 0x67, 0xD0, 0xF0);
  728. break;
  729. case 7:
  730. fb_dbg(info, "8/8/8/8 truecolor\n");
  731. svga_wcrt_mask(par->state.vgabase, 0x50, 0x30, 0x30);
  732. svga_wcrt_mask(par->state.vgabase, 0x67, 0xD0, 0xF0);
  733. break;
  734. default:
  735. fb_err(info, "unsupported mode - bug\n");
  736. return -EINVAL;
  737. }
  738. if (par->chip != CHIP_988_VIRGE_VX) {
  739. svga_wseq_mask(par->state.vgabase, 0x15, multiplex ? 0x10 : 0x00, 0x10);
  740. svga_wseq_mask(par->state.vgabase, 0x18, multiplex ? 0x80 : 0x00, 0x80);
  741. }
  742. s3_set_pixclock(info, info->var.pixclock);
  743. svga_set_timings(par->state.vgabase, &s3_timing_regs, &(info->var), hmul, 1,
  744. (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1,
  745. (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1,
  746. hmul, info->node);
  747. /* Set interlaced mode start/end register */
  748. htotal = info->var.xres + info->var.left_margin + info->var.right_margin + info->var.hsync_len;
  749. htotal = ((htotal * hmul) / 8) - 5;
  750. vga_wcrt(par->state.vgabase, 0x3C, (htotal + 1) / 2);
  751. /* Set Data Transfer Position */
  752. hsstart = ((info->var.xres + info->var.right_margin) * hmul) / 8;
  753. /* + 2 is needed for Virge/VX, does no harm on other cards */
  754. value = clamp((htotal + hsstart + 1) / 2 + 2, hsstart + 4, htotal + 1);
  755. svga_wcrt_multi(par->state.vgabase, s3_dtpc_regs, value);
  756. memset_io(info->screen_base, 0x00, screen_size);
  757. /* Device and screen back on */
  758. svga_wcrt_mask(par->state.vgabase, 0x17, 0x80, 0x80);
  759. svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
  760. return 0;
  761. }
  762. /* Set a colour register */
  763. static int s3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  764. u_int transp, struct fb_info *fb)
  765. {
  766. switch (fb->var.bits_per_pixel) {
  767. case 0:
  768. case 4:
  769. if (regno >= 16)
  770. return -EINVAL;
  771. if ((fb->var.bits_per_pixel == 4) &&
  772. (fb->var.nonstd == 0)) {
  773. outb(0xF0, VGA_PEL_MSK);
  774. outb(regno*16, VGA_PEL_IW);
  775. } else {
  776. outb(0x0F, VGA_PEL_MSK);
  777. outb(regno, VGA_PEL_IW);
  778. }
  779. outb(red >> 10, VGA_PEL_D);
  780. outb(green >> 10, VGA_PEL_D);
  781. outb(blue >> 10, VGA_PEL_D);
  782. break;
  783. case 8:
  784. if (regno >= 256)
  785. return -EINVAL;
  786. outb(0xFF, VGA_PEL_MSK);
  787. outb(regno, VGA_PEL_IW);
  788. outb(red >> 10, VGA_PEL_D);
  789. outb(green >> 10, VGA_PEL_D);
  790. outb(blue >> 10, VGA_PEL_D);
  791. break;
  792. case 16:
  793. if (regno >= 16)
  794. return 0;
  795. if (fb->var.green.length == 5)
  796. ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
  797. ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);
  798. else if (fb->var.green.length == 6)
  799. ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |
  800. ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
  801. else return -EINVAL;
  802. break;
  803. case 24:
  804. case 32:
  805. if (regno >= 16)
  806. return 0;
  807. ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) |
  808. (green & 0xFF00) | ((blue & 0xFF00) >> 8);
  809. break;
  810. default:
  811. return -EINVAL;
  812. }
  813. return 0;
  814. }
  815. /* Set the display blanking state */
  816. static int s3fb_blank(int blank_mode, struct fb_info *info)
  817. {
  818. struct s3fb_info *par = info->par;
  819. switch (blank_mode) {
  820. case FB_BLANK_UNBLANK:
  821. fb_dbg(info, "unblank\n");
  822. svga_wcrt_mask(par->state.vgabase, 0x56, 0x00, 0x06);
  823. svga_wseq_mask(par->state.vgabase, 0x01, 0x00, 0x20);
  824. break;
  825. case FB_BLANK_NORMAL:
  826. fb_dbg(info, "blank\n");
  827. svga_wcrt_mask(par->state.vgabase, 0x56, 0x00, 0x06);
  828. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  829. break;
  830. case FB_BLANK_HSYNC_SUSPEND:
  831. fb_dbg(info, "hsync\n");
  832. svga_wcrt_mask(par->state.vgabase, 0x56, 0x02, 0x06);
  833. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  834. break;
  835. case FB_BLANK_VSYNC_SUSPEND:
  836. fb_dbg(info, "vsync\n");
  837. svga_wcrt_mask(par->state.vgabase, 0x56, 0x04, 0x06);
  838. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  839. break;
  840. case FB_BLANK_POWERDOWN:
  841. fb_dbg(info, "sync down\n");
  842. svga_wcrt_mask(par->state.vgabase, 0x56, 0x06, 0x06);
  843. svga_wseq_mask(par->state.vgabase, 0x01, 0x20, 0x20);
  844. break;
  845. }
  846. return 0;
  847. }
  848. /* Pan the display */
  849. static int s3fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
  850. {
  851. struct s3fb_info *par = info->par;
  852. unsigned int offset;
  853. /* Calculate the offset */
  854. if (info->var.bits_per_pixel == 0) {
  855. offset = (var->yoffset / 16) * (info->var.xres_virtual / 2)
  856. + (var->xoffset / 2);
  857. offset = offset >> 2;
  858. } else {
  859. offset = (var->yoffset * info->fix.line_length) +
  860. (var->xoffset * info->var.bits_per_pixel / 8);
  861. offset = offset >> 2;
  862. }
  863. /* Set the offset */
  864. svga_wcrt_multi(par->state.vgabase, s3_start_address_regs, offset);
  865. return 0;
  866. }
  867. /* ------------------------------------------------------------------------- */
  868. /* Frame buffer operations */
  869. static struct fb_ops s3fb_ops = {
  870. .owner = THIS_MODULE,
  871. .fb_open = s3fb_open,
  872. .fb_release = s3fb_release,
  873. .fb_check_var = s3fb_check_var,
  874. .fb_set_par = s3fb_set_par,
  875. .fb_setcolreg = s3fb_setcolreg,
  876. .fb_blank = s3fb_blank,
  877. .fb_pan_display = s3fb_pan_display,
  878. .fb_fillrect = s3fb_fillrect,
  879. .fb_copyarea = cfb_copyarea,
  880. .fb_imageblit = s3fb_imageblit,
  881. .fb_get_caps = svga_get_caps,
  882. };
  883. /* ------------------------------------------------------------------------- */
  884. static int s3_identification(struct s3fb_info *par)
  885. {
  886. int chip = par->chip;
  887. if (chip == CHIP_XXX_TRIO) {
  888. u8 cr30 = vga_rcrt(par->state.vgabase, 0x30);
  889. u8 cr2e = vga_rcrt(par->state.vgabase, 0x2e);
  890. u8 cr2f = vga_rcrt(par->state.vgabase, 0x2f);
  891. if ((cr30 == 0xE0) || (cr30 == 0xE1)) {
  892. if (cr2e == 0x10)
  893. return CHIP_732_TRIO32;
  894. if (cr2e == 0x11) {
  895. if (! (cr2f & 0x40))
  896. return CHIP_764_TRIO64;
  897. else
  898. return CHIP_765_TRIO64VP;
  899. }
  900. }
  901. }
  902. if (chip == CHIP_XXX_TRIO64V2_DXGX) {
  903. u8 cr6f = vga_rcrt(par->state.vgabase, 0x6f);
  904. if (! (cr6f & 0x01))
  905. return CHIP_775_TRIO64V2_DX;
  906. else
  907. return CHIP_785_TRIO64V2_GX;
  908. }
  909. if (chip == CHIP_XXX_VIRGE_DXGX) {
  910. u8 cr6f = vga_rcrt(par->state.vgabase, 0x6f);
  911. if (! (cr6f & 0x01))
  912. return CHIP_375_VIRGE_DX;
  913. else
  914. return CHIP_385_VIRGE_GX;
  915. }
  916. if (chip == CHIP_36X_TRIO3D_1X_2X) {
  917. switch (vga_rcrt(par->state.vgabase, 0x2f)) {
  918. case 0x00:
  919. return CHIP_360_TRIO3D_1X;
  920. case 0x01:
  921. return CHIP_362_TRIO3D_2X;
  922. case 0x02:
  923. return CHIP_368_TRIO3D_2X;
  924. }
  925. }
  926. return CHIP_UNKNOWN;
  927. }
  928. /* PCI probe */
  929. static int s3_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
  930. {
  931. struct pci_bus_region bus_reg;
  932. struct resource vga_res;
  933. struct fb_info *info;
  934. struct s3fb_info *par;
  935. int rc;
  936. u8 regval, cr38, cr39;
  937. bool found = false;
  938. /* Ignore secondary VGA device because there is no VGA arbitration */
  939. if (! svga_primary_device(dev)) {
  940. dev_info(&(dev->dev), "ignoring secondary device\n");
  941. return -ENODEV;
  942. }
  943. /* Allocate and fill driver data structure */
  944. info = framebuffer_alloc(sizeof(struct s3fb_info), &(dev->dev));
  945. if (!info) {
  946. dev_err(&(dev->dev), "cannot allocate memory\n");
  947. return -ENOMEM;
  948. }
  949. par = info->par;
  950. mutex_init(&par->open_lock);
  951. info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
  952. info->fbops = &s3fb_ops;
  953. /* Prepare PCI device */
  954. rc = pci_enable_device(dev);
  955. if (rc < 0) {
  956. dev_err(info->device, "cannot enable PCI device\n");
  957. goto err_enable_device;
  958. }
  959. rc = pci_request_regions(dev, "s3fb");
  960. if (rc < 0) {
  961. dev_err(info->device, "cannot reserve framebuffer region\n");
  962. goto err_request_regions;
  963. }
  964. info->fix.smem_start = pci_resource_start(dev, 0);
  965. info->fix.smem_len = pci_resource_len(dev, 0);
  966. /* Map physical IO memory address into kernel space */
  967. info->screen_base = pci_iomap(dev, 0, 0);
  968. if (! info->screen_base) {
  969. rc = -ENOMEM;
  970. dev_err(info->device, "iomap for framebuffer failed\n");
  971. goto err_iomap;
  972. }
  973. bus_reg.start = 0;
  974. bus_reg.end = 64 * 1024;
  975. vga_res.flags = IORESOURCE_IO;
  976. pcibios_bus_to_resource(dev->bus, &vga_res, &bus_reg);
  977. par->state.vgabase = (void __iomem *) (unsigned long) vga_res.start;
  978. /* Unlock regs */
  979. cr38 = vga_rcrt(par->state.vgabase, 0x38);
  980. cr39 = vga_rcrt(par->state.vgabase, 0x39);
  981. vga_wseq(par->state.vgabase, 0x08, 0x06);
  982. vga_wcrt(par->state.vgabase, 0x38, 0x48);
  983. vga_wcrt(par->state.vgabase, 0x39, 0xA5);
  984. /* Identify chip type */
  985. par->chip = id->driver_data & CHIP_MASK;
  986. par->rev = vga_rcrt(par->state.vgabase, 0x2f);
  987. if (par->chip & CHIP_UNDECIDED_FLAG)
  988. par->chip = s3_identification(par);
  989. /* Find how many physical memory there is on card */
  990. /* 0x36 register is accessible even if other registers are locked */
  991. regval = vga_rcrt(par->state.vgabase, 0x36);
  992. if (par->chip == CHIP_360_TRIO3D_1X ||
  993. par->chip == CHIP_362_TRIO3D_2X ||
  994. par->chip == CHIP_368_TRIO3D_2X ||
  995. par->chip == CHIP_365_TRIO3D) {
  996. switch ((regval & 0xE0) >> 5) {
  997. case 0: /* 8MB -- only 4MB usable for display */
  998. case 1: /* 4MB with 32-bit bus */
  999. case 2: /* 4MB */
  1000. info->screen_size = 4 << 20;
  1001. break;
  1002. case 4: /* 2MB on 365 Trio3D */
  1003. case 6: /* 2MB */
  1004. info->screen_size = 2 << 20;
  1005. break;
  1006. }
  1007. } else if (par->chip == CHIP_357_VIRGE_GX2 ||
  1008. par->chip == CHIP_359_VIRGE_GX2P ||
  1009. par->chip == CHIP_260_VIRGE_MX) {
  1010. switch ((regval & 0xC0) >> 6) {
  1011. case 1: /* 4MB */
  1012. info->screen_size = 4 << 20;
  1013. break;
  1014. case 3: /* 2MB */
  1015. info->screen_size = 2 << 20;
  1016. break;
  1017. }
  1018. } else if (par->chip == CHIP_988_VIRGE_VX) {
  1019. switch ((regval & 0x60) >> 5) {
  1020. case 0: /* 2MB */
  1021. info->screen_size = 2 << 20;
  1022. break;
  1023. case 1: /* 4MB */
  1024. info->screen_size = 4 << 20;
  1025. break;
  1026. case 2: /* 6MB */
  1027. info->screen_size = 6 << 20;
  1028. break;
  1029. case 3: /* 8MB */
  1030. info->screen_size = 8 << 20;
  1031. break;
  1032. }
  1033. /* off-screen memory */
  1034. regval = vga_rcrt(par->state.vgabase, 0x37);
  1035. switch ((regval & 0x60) >> 5) {
  1036. case 1: /* 4MB */
  1037. info->screen_size -= 4 << 20;
  1038. break;
  1039. case 2: /* 2MB */
  1040. info->screen_size -= 2 << 20;
  1041. break;
  1042. }
  1043. } else
  1044. info->screen_size = s3_memsizes[regval >> 5] << 10;
  1045. info->fix.smem_len = info->screen_size;
  1046. /* Find MCLK frequency */
  1047. regval = vga_rseq(par->state.vgabase, 0x10);
  1048. par->mclk_freq = ((vga_rseq(par->state.vgabase, 0x11) + 2) * 14318) / ((regval & 0x1F) + 2);
  1049. par->mclk_freq = par->mclk_freq >> (regval >> 5);
  1050. /* Restore locks */
  1051. vga_wcrt(par->state.vgabase, 0x38, cr38);
  1052. vga_wcrt(par->state.vgabase, 0x39, cr39);
  1053. strcpy(info->fix.id, s3_names [par->chip]);
  1054. info->fix.mmio_start = 0;
  1055. info->fix.mmio_len = 0;
  1056. info->fix.type = FB_TYPE_PACKED_PIXELS;
  1057. info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
  1058. info->fix.ypanstep = 0;
  1059. info->fix.accel = FB_ACCEL_NONE;
  1060. info->pseudo_palette = (void*) (par->pseudo_palette);
  1061. info->var.bits_per_pixel = 8;
  1062. #ifdef CONFIG_FB_S3_DDC
  1063. /* Enable MMIO if needed */
  1064. if (s3fb_ddc_needs_mmio(par->chip)) {
  1065. par->mmio = ioremap(info->fix.smem_start + MMIO_OFFSET, MMIO_SIZE);
  1066. if (par->mmio)
  1067. svga_wcrt_mask(par->state.vgabase, 0x53, 0x08, 0x08); /* enable MMIO */
  1068. else
  1069. dev_err(info->device, "unable to map MMIO at 0x%lx, disabling DDC",
  1070. info->fix.smem_start + MMIO_OFFSET);
  1071. }
  1072. if (!s3fb_ddc_needs_mmio(par->chip) || par->mmio)
  1073. if (s3fb_setup_ddc_bus(info) == 0) {
  1074. u8 *edid = fb_ddc_read(&par->ddc_adapter);
  1075. par->ddc_registered = true;
  1076. if (edid) {
  1077. fb_edid_to_monspecs(edid, &info->monspecs);
  1078. kfree(edid);
  1079. if (!info->monspecs.modedb)
  1080. dev_err(info->device, "error getting mode database\n");
  1081. else {
  1082. const struct fb_videomode *m;
  1083. fb_videomode_to_modelist(info->monspecs.modedb,
  1084. info->monspecs.modedb_len,
  1085. &info->modelist);
  1086. m = fb_find_best_display(&info->monspecs, &info->modelist);
  1087. if (m) {
  1088. fb_videomode_to_var(&info->var, m);
  1089. /* fill all other info->var's fields */
  1090. if (s3fb_check_var(&info->var, info) == 0)
  1091. found = true;
  1092. }
  1093. }
  1094. }
  1095. }
  1096. #endif
  1097. if (!mode_option && !found)
  1098. mode_option = "640x480-8@60";
  1099. /* Prepare startup mode */
  1100. if (mode_option) {
  1101. rc = fb_find_mode(&info->var, info, mode_option,
  1102. info->monspecs.modedb, info->monspecs.modedb_len,
  1103. NULL, info->var.bits_per_pixel);
  1104. if (!rc || rc == 4) {
  1105. rc = -EINVAL;
  1106. dev_err(info->device, "mode %s not found\n", mode_option);
  1107. fb_destroy_modedb(info->monspecs.modedb);
  1108. info->monspecs.modedb = NULL;
  1109. goto err_find_mode;
  1110. }
  1111. }
  1112. fb_destroy_modedb(info->monspecs.modedb);
  1113. info->monspecs.modedb = NULL;
  1114. /* maximize virtual vertical size for fast scrolling */
  1115. info->var.yres_virtual = info->fix.smem_len * 8 /
  1116. (info->var.bits_per_pixel * info->var.xres_virtual);
  1117. if (info->var.yres_virtual < info->var.yres) {
  1118. dev_err(info->device, "virtual vertical size smaller than real\n");
  1119. rc = -EINVAL;
  1120. goto err_find_mode;
  1121. }
  1122. rc = fb_alloc_cmap(&info->cmap, 256, 0);
  1123. if (rc < 0) {
  1124. dev_err(info->device, "cannot allocate colormap\n");
  1125. goto err_alloc_cmap;
  1126. }
  1127. rc = register_framebuffer(info);
  1128. if (rc < 0) {
  1129. dev_err(info->device, "cannot register framebuffer\n");
  1130. goto err_reg_fb;
  1131. }
  1132. fb_info(info, "%s on %s, %d MB RAM, %d MHz MCLK\n",
  1133. info->fix.id, pci_name(dev),
  1134. info->fix.smem_len >> 20, (par->mclk_freq + 500) / 1000);
  1135. if (par->chip == CHIP_UNKNOWN)
  1136. fb_info(info, "unknown chip, CR2D=%x, CR2E=%x, CRT2F=%x, CRT30=%x\n",
  1137. vga_rcrt(par->state.vgabase, 0x2d),
  1138. vga_rcrt(par->state.vgabase, 0x2e),
  1139. vga_rcrt(par->state.vgabase, 0x2f),
  1140. vga_rcrt(par->state.vgabase, 0x30));
  1141. /* Record a reference to the driver data */
  1142. pci_set_drvdata(dev, info);
  1143. #ifdef CONFIG_MTRR
  1144. if (mtrr) {
  1145. par->mtrr_reg = -1;
  1146. par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1);
  1147. }
  1148. #endif
  1149. return 0;
  1150. /* Error handling */
  1151. err_reg_fb:
  1152. fb_dealloc_cmap(&info->cmap);
  1153. err_alloc_cmap:
  1154. err_find_mode:
  1155. #ifdef CONFIG_FB_S3_DDC
  1156. if (par->ddc_registered)
  1157. i2c_del_adapter(&par->ddc_adapter);
  1158. if (par->mmio)
  1159. iounmap(par->mmio);
  1160. #endif
  1161. pci_iounmap(dev, info->screen_base);
  1162. err_iomap:
  1163. pci_release_regions(dev);
  1164. err_request_regions:
  1165. /* pci_disable_device(dev); */
  1166. err_enable_device:
  1167. framebuffer_release(info);
  1168. return rc;
  1169. }
  1170. /* PCI remove */
  1171. static void s3_pci_remove(struct pci_dev *dev)
  1172. {
  1173. struct fb_info *info = pci_get_drvdata(dev);
  1174. struct s3fb_info __maybe_unused *par;
  1175. if (info) {
  1176. par = info->par;
  1177. #ifdef CONFIG_MTRR
  1178. if (par->mtrr_reg >= 0) {
  1179. mtrr_del(par->mtrr_reg, 0, 0);
  1180. par->mtrr_reg = -1;
  1181. }
  1182. #endif
  1183. unregister_framebuffer(info);
  1184. fb_dealloc_cmap(&info->cmap);
  1185. #ifdef CONFIG_FB_S3_DDC
  1186. if (par->ddc_registered)
  1187. i2c_del_adapter(&par->ddc_adapter);
  1188. if (par->mmio)
  1189. iounmap(par->mmio);
  1190. #endif
  1191. pci_iounmap(dev, info->screen_base);
  1192. pci_release_regions(dev);
  1193. /* pci_disable_device(dev); */
  1194. framebuffer_release(info);
  1195. }
  1196. }
  1197. /* PCI suspend */
  1198. static int s3_pci_suspend(struct pci_dev* dev, pm_message_t state)
  1199. {
  1200. struct fb_info *info = pci_get_drvdata(dev);
  1201. struct s3fb_info *par = info->par;
  1202. dev_info(info->device, "suspend\n");
  1203. console_lock();
  1204. mutex_lock(&(par->open_lock));
  1205. if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {
  1206. mutex_unlock(&(par->open_lock));
  1207. console_unlock();
  1208. return 0;
  1209. }
  1210. fb_set_suspend(info, 1);
  1211. pci_save_state(dev);
  1212. pci_disable_device(dev);
  1213. pci_set_power_state(dev, pci_choose_state(dev, state));
  1214. mutex_unlock(&(par->open_lock));
  1215. console_unlock();
  1216. return 0;
  1217. }
  1218. /* PCI resume */
  1219. static int s3_pci_resume(struct pci_dev* dev)
  1220. {
  1221. struct fb_info *info = pci_get_drvdata(dev);
  1222. struct s3fb_info *par = info->par;
  1223. int err;
  1224. dev_info(info->device, "resume\n");
  1225. console_lock();
  1226. mutex_lock(&(par->open_lock));
  1227. if (par->ref_count == 0) {
  1228. mutex_unlock(&(par->open_lock));
  1229. console_unlock();
  1230. return 0;
  1231. }
  1232. pci_set_power_state(dev, PCI_D0);
  1233. pci_restore_state(dev);
  1234. err = pci_enable_device(dev);
  1235. if (err) {
  1236. mutex_unlock(&(par->open_lock));
  1237. console_unlock();
  1238. dev_err(info->device, "error %d enabling device for resume\n", err);
  1239. return err;
  1240. }
  1241. pci_set_master(dev);
  1242. s3fb_set_par(info);
  1243. fb_set_suspend(info, 0);
  1244. mutex_unlock(&(par->open_lock));
  1245. console_unlock();
  1246. return 0;
  1247. }
  1248. /* List of boards that we are trying to support */
  1249. static struct pci_device_id s3_devices[] = {
  1250. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8810), .driver_data = CHIP_XXX_TRIO},
  1251. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8811), .driver_data = CHIP_XXX_TRIO},
  1252. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8812), .driver_data = CHIP_M65_AURORA64VP},
  1253. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8814), .driver_data = CHIP_767_TRIO64UVP},
  1254. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8901), .driver_data = CHIP_XXX_TRIO64V2_DXGX},
  1255. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8902), .driver_data = CHIP_551_PLATO_PX},
  1256. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x5631), .driver_data = CHIP_325_VIRGE},
  1257. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x883D), .driver_data = CHIP_988_VIRGE_VX},
  1258. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A01), .driver_data = CHIP_XXX_VIRGE_DXGX},
  1259. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A10), .driver_data = CHIP_357_VIRGE_GX2},
  1260. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A11), .driver_data = CHIP_359_VIRGE_GX2P},
  1261. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A12), .driver_data = CHIP_359_VIRGE_GX2P},
  1262. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A13), .driver_data = CHIP_36X_TRIO3D_1X_2X},
  1263. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8904), .driver_data = CHIP_365_TRIO3D},
  1264. {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8C01), .driver_data = CHIP_260_VIRGE_MX},
  1265. {0, 0, 0, 0, 0, 0, 0}
  1266. };
  1267. MODULE_DEVICE_TABLE(pci, s3_devices);
  1268. static struct pci_driver s3fb_pci_driver = {
  1269. .name = "s3fb",
  1270. .id_table = s3_devices,
  1271. .probe = s3_pci_probe,
  1272. .remove = s3_pci_remove,
  1273. .suspend = s3_pci_suspend,
  1274. .resume = s3_pci_resume,
  1275. };
  1276. /* Parse user specified options */
  1277. #ifndef MODULE
  1278. static int __init s3fb_setup(char *options)
  1279. {
  1280. char *opt;
  1281. if (!options || !*options)
  1282. return 0;
  1283. while ((opt = strsep(&options, ",")) != NULL) {
  1284. if (!*opt)
  1285. continue;
  1286. #ifdef CONFIG_MTRR
  1287. else if (!strncmp(opt, "mtrr:", 5))
  1288. mtrr = simple_strtoul(opt + 5, NULL, 0);
  1289. #endif
  1290. else if (!strncmp(opt, "fasttext:", 9))
  1291. fasttext = simple_strtoul(opt + 9, NULL, 0);
  1292. else
  1293. mode_option = opt;
  1294. }
  1295. return 0;
  1296. }
  1297. #endif
  1298. /* Cleanup */
  1299. static void __exit s3fb_cleanup(void)
  1300. {
  1301. pr_debug("s3fb: cleaning up\n");
  1302. pci_unregister_driver(&s3fb_pci_driver);
  1303. }
  1304. /* Driver Initialisation */
  1305. static int __init s3fb_init(void)
  1306. {
  1307. #ifndef MODULE
  1308. char *option = NULL;
  1309. if (fb_get_options("s3fb", &option))
  1310. return -ENODEV;
  1311. s3fb_setup(option);
  1312. #endif
  1313. pr_debug("s3fb: initializing\n");
  1314. return pci_register_driver(&s3fb_pci_driver);
  1315. }
  1316. /* ------------------------------------------------------------------------- */
  1317. /* Modularization */
  1318. module_init(s3fb_init);
  1319. module_exit(s3fb_cleanup);