s3fb.c 47 KB

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