S3triofb.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. /*
  2. * linux/drivers/video/S3Triofb.c -- Open Firmware based frame buffer device
  3. *
  4. * Copyright (C) 1997 Peter De Schrijver
  5. *
  6. * This driver is partly based on the PowerMac console driver:
  7. *
  8. * Copyright (C) 1996 Paul Mackerras
  9. *
  10. * and on the Open Firmware based frame buffer device:
  11. *
  12. * Copyright (C) 1997 Geert Uytterhoeven
  13. *
  14. * This file is subject to the terms and conditions of the GNU General Public
  15. * License. See the file COPYING in the main directory of this archive for
  16. * more details.
  17. */
  18. /*
  19. Bugs : + OF dependencies should be removed.
  20. + This driver should be merged with the CyberVision driver. The
  21. CyberVision is a Zorro III implementation of the S3Trio64 chip.
  22. */
  23. #include <linux/config.h>
  24. #include <linux/kernel.h>
  25. #include <linux/module.h>
  26. #include <linux/errno.h>
  27. #include <linux/string.h>
  28. #include <linux/mm.h>
  29. #include <linux/tty.h>
  30. #include <linux/slab.h>
  31. #include <linux/vmalloc.h>
  32. #include <linux/delay.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/fb.h>
  35. #include <linux/init.h>
  36. #include <linux/selection.h>
  37. #include <asm/io.h>
  38. #include <asm/prom.h>
  39. #include <asm/pci-bridge.h>
  40. #include <linux/pci.h>
  41. #include <video/fbcon.h>
  42. #include <video/fbcon-cfb8.h>
  43. #include <video/s3blit.h>
  44. #define mem_in8(addr) in_8((void *)(addr))
  45. #define mem_in16(addr) in_le16((void *)(addr))
  46. #define mem_in32(addr) in_le32((void *)(addr))
  47. #define mem_out8(val, addr) out_8((void *)(addr), val)
  48. #define mem_out16(val, addr) out_le16((void *)(addr), val)
  49. #define mem_out32(val, addr) out_le32((void *)(addr), val)
  50. #define IO_OUT16VAL(v, r) (((v) << 8) | (r))
  51. static struct display disp;
  52. static struct fb_info fb_info;
  53. static struct { u_char red, green, blue, pad; } palette[256];
  54. static char s3trio_name[16] = "S3Trio ";
  55. static char *s3trio_base;
  56. static struct fb_fix_screeninfo fb_fix;
  57. static struct fb_var_screeninfo fb_var = { 0, };
  58. /*
  59. * Interface used by the world
  60. */
  61. static void __init s3triofb_of_init(struct device_node *dp);
  62. static int s3trio_get_fix(struct fb_fix_screeninfo *fix, int con,
  63. struct fb_info *info);
  64. static int s3trio_get_var(struct fb_var_screeninfo *var, int con,
  65. struct fb_info *info);
  66. static int s3trio_set_var(struct fb_var_screeninfo *var, int con,
  67. struct fb_info *info);
  68. static int s3trio_get_cmap(struct fb_cmap *cmap, int kspc, int con,
  69. struct fb_info *info);
  70. static int s3trio_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  71. u_int transp, struct fb_info *info);
  72. static int s3trio_pan_display(struct fb_var_screeninfo *var, int con,
  73. struct fb_info *info);
  74. static void s3triofb_blank(int blank, struct fb_info *info);
  75. /*
  76. * Interface to the low level console driver
  77. */
  78. int s3triofb_init(void);
  79. static int s3triofbcon_switch(int con, struct fb_info *info);
  80. static int s3triofbcon_updatevar(int con, struct fb_info *info);
  81. /*
  82. * Text console acceleration
  83. */
  84. #ifdef FBCON_HAS_CFB8
  85. static struct display_switch fbcon_trio8;
  86. #endif
  87. /*
  88. * Accelerated Functions used by the low level console driver
  89. */
  90. static void Trio_WaitQueue(u_short fifo);
  91. static void Trio_WaitBlit(void);
  92. static void Trio_BitBLT(u_short curx, u_short cury, u_short destx,
  93. u_short desty, u_short width, u_short height,
  94. u_short mode);
  95. static void Trio_RectFill(u_short x, u_short y, u_short width, u_short height,
  96. u_short mode, u_short color);
  97. static void Trio_MoveCursor(u_short x, u_short y);
  98. /*
  99. * Internal routines
  100. */
  101. static int s3trio_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
  102. u_int *transp, struct fb_info *info);
  103. static struct fb_ops s3trio_ops = {
  104. .owner = THIS_MODULE,
  105. .fb_get_fix = s3trio_get_fix,
  106. .fb_get_var = s3trio_get_var,
  107. .fb_set_var = s3trio_set_var,
  108. .fb_get_cmap = s3trio_get_cmap,
  109. .fb_set_cmap = gen_set_cmap,
  110. .fb_setcolreg = s3trio_setcolreg,
  111. .fb_pan_display =s3trio_pan_display,
  112. .fb_blank = s3triofb_blank,
  113. };
  114. /*
  115. * Get the Fixed Part of the Display
  116. */
  117. static int s3trio_get_fix(struct fb_fix_screeninfo *fix, int con,
  118. struct fb_info *info)
  119. {
  120. memcpy(fix, &fb_fix, sizeof(fb_fix));
  121. return 0;
  122. }
  123. /*
  124. * Get the User Defined Part of the Display
  125. */
  126. static int s3trio_get_var(struct fb_var_screeninfo *var, int con,
  127. struct fb_info *info)
  128. {
  129. memcpy(var, &fb_var, sizeof(fb_var));
  130. return 0;
  131. }
  132. /*
  133. * Set the User Defined Part of the Display
  134. */
  135. static int s3trio_set_var(struct fb_var_screeninfo *var, int con,
  136. struct fb_info *info)
  137. {
  138. if (var->xres > fb_var.xres || var->yres > fb_var.yres ||
  139. var->bits_per_pixel > fb_var.bits_per_pixel )
  140. /* || var->nonstd || var->vmode != FB_VMODE_NONINTERLACED) */
  141. return -EINVAL;
  142. if (var->xres_virtual > fb_var.xres_virtual) {
  143. outw(IO_OUT16VAL((var->xres_virtual /8) & 0xff, 0x13), 0x3d4);
  144. outw(IO_OUT16VAL(((var->xres_virtual /8 ) & 0x300) >> 3, 0x51), 0x3d4);
  145. fb_var.xres_virtual = var->xres_virtual;
  146. fb_fix.line_length = var->xres_virtual;
  147. }
  148. fb_var.yres_virtual = var->yres_virtual;
  149. memcpy(var, &fb_var, sizeof(fb_var));
  150. return 0;
  151. }
  152. /*
  153. * Pan or Wrap the Display
  154. *
  155. * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
  156. */
  157. static int s3trio_pan_display(struct fb_var_screeninfo *var, int con,
  158. struct fb_info *info)
  159. {
  160. unsigned int base;
  161. if (var->xoffset > (var->xres_virtual - var->xres))
  162. return -EINVAL;
  163. if (var->yoffset > (var->yres_virtual - var->yres))
  164. return -EINVAL;
  165. fb_var.xoffset = var->xoffset;
  166. fb_var.yoffset = var->yoffset;
  167. base = var->yoffset * fb_fix.line_length + var->xoffset;
  168. outw(IO_OUT16VAL((base >> 8) & 0xff, 0x0c),0x03D4);
  169. outw(IO_OUT16VAL(base & 0xff, 0x0d),0x03D4);
  170. outw(IO_OUT16VAL((base >> 16) & 0xf, 0x69),0x03D4);
  171. return 0;
  172. }
  173. /*
  174. * Get the Colormap
  175. */
  176. static int s3trio_get_cmap(struct fb_cmap *cmap, int kspc, int con,
  177. struct fb_info *info)
  178. {
  179. if (con == info->currcon) /* current console? */
  180. return fb_get_cmap(cmap, kspc, s3trio_getcolreg, info);
  181. else if (fb_display[con].cmap.len) /* non default colormap? */
  182. fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
  183. else
  184. fb_copy_cmap(fb_default_cmap(1 << fb_display[con].var.bits_per_pixel),
  185. cmap, kspc ? 0 : 2);
  186. return 0;
  187. }
  188. int __init s3triofb_init(void)
  189. {
  190. struct device_node *dp;
  191. dp = find_devices("S3Trio");
  192. if (dp != 0)
  193. s3triofb_of_init(dp);
  194. return 0;
  195. }
  196. void __init s3trio_resetaccel(void){
  197. #define EC01_ENH_ENB 0x0005
  198. #define EC01_LAW_ENB 0x0010
  199. #define EC01_MMIO_ENB 0x0020
  200. #define EC00_RESET 0x8000
  201. #define EC00_ENABLE 0x4000
  202. #define MF_MULT_MISC 0xE000
  203. #define SRC_FOREGROUND 0x0020
  204. #define SRC_BACKGROUND 0x0000
  205. #define MIX_SRC 0x0007
  206. #define MF_T_CLIP 0x1000
  207. #define MF_L_CLIP 0x2000
  208. #define MF_B_CLIP 0x3000
  209. #define MF_R_CLIP 0x4000
  210. #define MF_PIX_CONTROL 0xA000
  211. #define MFA_SRC_FOREGR_MIX 0x0000
  212. #define MF_PIX_CONTROL 0xA000
  213. outw(EC00_RESET, 0x42e8);
  214. inw( 0x42e8);
  215. outw(EC00_ENABLE, 0x42e8);
  216. inw( 0x42e8);
  217. outw(EC01_ENH_ENB | EC01_LAW_ENB,
  218. 0x4ae8);
  219. outw(MF_MULT_MISC, 0xbee8); /* 16 bit I/O registers */
  220. /* Now set some basic accelerator registers */
  221. Trio_WaitQueue(0x0400);
  222. outw(SRC_FOREGROUND | MIX_SRC, 0xbae8);
  223. outw(SRC_BACKGROUND | MIX_SRC, 0xb6e8);/* direct color*/
  224. outw(MF_T_CLIP | 0, 0xbee8 ); /* clip virtual area */
  225. outw(MF_L_CLIP | 0, 0xbee8 );
  226. outw(MF_R_CLIP | (640 - 1), 0xbee8);
  227. outw(MF_B_CLIP | (480 - 1), 0xbee8);
  228. Trio_WaitQueue(0x0400);
  229. outw(0xffff, 0xaae8); /* Enable all planes */
  230. outw(0xffff, 0xaae8); /* Enable all planes */
  231. outw( MF_PIX_CONTROL | MFA_SRC_FOREGR_MIX, 0xbee8);
  232. }
  233. int __init s3trio_init(struct device_node *dp){
  234. u_char bus, dev;
  235. unsigned int t32;
  236. unsigned short cmd;
  237. pci_device_loc(dp,&bus,&dev);
  238. pcibios_read_config_dword(bus, dev, PCI_VENDOR_ID, &t32);
  239. if(t32 == (PCI_DEVICE_ID_S3_TRIO << 16) + PCI_VENDOR_ID_S3) {
  240. pcibios_read_config_dword(bus, dev, PCI_BASE_ADDRESS_0, &t32);
  241. pcibios_read_config_dword(bus, dev, PCI_BASE_ADDRESS_1, &t32);
  242. pcibios_read_config_word(bus, dev, PCI_COMMAND,&cmd);
  243. pcibios_write_config_word(bus, dev, PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
  244. pcibios_write_config_dword(bus, dev, PCI_BASE_ADDRESS_0,0xffffffff);
  245. pcibios_read_config_dword(bus, dev, PCI_BASE_ADDRESS_0, &t32);
  246. /* This is a gross hack as OF only maps enough memory for the framebuffer and
  247. we want to use MMIO too. We should find out which chunk of address space
  248. we can use here */
  249. pcibios_write_config_dword(bus,dev,PCI_BASE_ADDRESS_0,0xc6000000);
  250. /* unlock s3 */
  251. outb(0x01, 0x3C3);
  252. outb(inb(0x03CC) | 1, 0x3c2);
  253. outw(IO_OUT16VAL(0x48, 0x38),0x03D4);
  254. outw(IO_OUT16VAL(0xA0, 0x39),0x03D4);
  255. outb(0x33,0x3d4);
  256. outw(IO_OUT16VAL((inb(0x3d5) & ~(0x2 | 0x10 | 0x40)) |
  257. 0x20, 0x33), 0x3d4);
  258. outw(IO_OUT16VAL(0x6, 0x8), 0x3c4);
  259. /* switch to MMIO only mode */
  260. outb(0x58, 0x3d4);
  261. outw(IO_OUT16VAL(inb(0x3d5) | 3 | 0x10, 0x58), 0x3d4);
  262. outw(IO_OUT16VAL(8, 0x53), 0x3d4);
  263. /* switch off I/O accesses */
  264. #if 0
  265. pcibios_write_config_word(bus, dev, PCI_COMMAND,
  266. PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
  267. #endif
  268. return 1;
  269. }
  270. return 0;
  271. }
  272. /*
  273. * Initialisation
  274. * We heavily rely on OF for the moment. This needs fixing.
  275. */
  276. static void __init s3triofb_of_init(struct device_node *dp)
  277. {
  278. int i, *pp, len;
  279. unsigned long address, size;
  280. u_long *CursorBase;
  281. strncat(s3trio_name, dp->name, sizeof(s3trio_name));
  282. s3trio_name[sizeof(s3trio_name)-1] = '\0';
  283. strcpy(fb_fix.id, s3trio_name);
  284. if((pp = (int *)get_property(dp, "vendor-id", &len)) != NULL
  285. && *pp!=PCI_VENDOR_ID_S3) {
  286. printk("%s: can't find S3 Trio board\n", dp->full_name);
  287. return;
  288. }
  289. if((pp = (int *)get_property(dp, "device-id", &len)) != NULL
  290. && *pp!=PCI_DEVICE_ID_S3_TRIO) {
  291. printk("%s: can't find S3 Trio board\n", dp->full_name);
  292. return;
  293. }
  294. if ((pp = (int *)get_property(dp, "depth", &len)) != NULL
  295. && len == sizeof(int) && *pp != 8) {
  296. printk("%s: can't use depth = %d\n", dp->full_name, *pp);
  297. return;
  298. }
  299. if ((pp = (int *)get_property(dp, "width", &len)) != NULL
  300. && len == sizeof(int))
  301. fb_var.xres = fb_var.xres_virtual = *pp;
  302. if ((pp = (int *)get_property(dp, "height", &len)) != NULL
  303. && len == sizeof(int))
  304. fb_var.yres = fb_var.yres_virtual = *pp;
  305. if ((pp = (int *)get_property(dp, "linebytes", &len)) != NULL
  306. && len == sizeof(int))
  307. fb_fix.line_length = *pp;
  308. else
  309. fb_fix.line_length = fb_var.xres_virtual;
  310. fb_fix.smem_len = fb_fix.line_length*fb_var.yres;
  311. address = 0xc6000000;
  312. size = 64*1024*1024;
  313. if (!request_mem_region(address, size, "S3triofb"))
  314. return;
  315. s3trio_init(dp);
  316. s3trio_base = ioremap(address, size);
  317. fb_fix.smem_start = address;
  318. fb_fix.type = FB_TYPE_PACKED_PIXELS;
  319. fb_fix.type_aux = 0;
  320. fb_fix.accel = FB_ACCEL_S3_TRIO64;
  321. fb_fix.mmio_start = address+0x1000000;
  322. fb_fix.mmio_len = 0x1000000;
  323. fb_fix.xpanstep = 1;
  324. fb_fix.ypanstep = 1;
  325. s3trio_resetaccel();
  326. mem_out8(0x30, s3trio_base+0x1008000 + 0x03D4);
  327. mem_out8(0x2d, s3trio_base+0x1008000 + 0x03D4);
  328. mem_out8(0x2e, s3trio_base+0x1008000 + 0x03D4);
  329. mem_out8(0x50, s3trio_base+0x1008000 + 0x03D4);
  330. /* disable HW cursor */
  331. mem_out8(0x39, s3trio_base+0x1008000 + 0x03D4);
  332. mem_out8(0xa0, s3trio_base+0x1008000 + 0x03D5);
  333. mem_out8(0x45, s3trio_base+0x1008000 + 0x03D4);
  334. mem_out8(0, s3trio_base+0x1008000 + 0x03D5);
  335. mem_out8(0x4e, s3trio_base+0x1008000 + 0x03D4);
  336. mem_out8(0, s3trio_base+0x1008000 + 0x03D5);
  337. mem_out8(0x4f, s3trio_base+0x1008000 + 0x03D4);
  338. mem_out8(0, s3trio_base+0x1008000 + 0x03D5);
  339. /* init HW cursor */
  340. CursorBase = (u_long *)(s3trio_base + 2*1024*1024 - 0x400);
  341. for (i = 0; i < 8; i++) {
  342. *(CursorBase +(i*4)) = 0xffffff00;
  343. *(CursorBase+1+(i*4)) = 0xffff0000;
  344. *(CursorBase+2+(i*4)) = 0xffff0000;
  345. *(CursorBase+3+(i*4)) = 0xffff0000;
  346. }
  347. for (i = 8; i < 64; i++) {
  348. *(CursorBase +(i*4)) = 0xffff0000;
  349. *(CursorBase+1+(i*4)) = 0xffff0000;
  350. *(CursorBase+2+(i*4)) = 0xffff0000;
  351. *(CursorBase+3+(i*4)) = 0xffff0000;
  352. }
  353. mem_out8(0x4c, s3trio_base+0x1008000 + 0x03D4);
  354. mem_out8(((2*1024 - 1)&0xf00)>>8, s3trio_base+0x1008000 + 0x03D5);
  355. mem_out8(0x4d, s3trio_base+0x1008000 + 0x03D4);
  356. mem_out8((2*1024 - 1) & 0xff, s3trio_base+0x1008000 + 0x03D5);
  357. mem_out8(0x45, s3trio_base+0x1008000 + 0x03D4);
  358. mem_in8(s3trio_base+0x1008000 + 0x03D4);
  359. mem_out8(0x4a, s3trio_base+0x1008000 + 0x03D4);
  360. mem_out8(0x80, s3trio_base+0x1008000 + 0x03D5);
  361. mem_out8(0x80, s3trio_base+0x1008000 + 0x03D5);
  362. mem_out8(0x80, s3trio_base+0x1008000 + 0x03D5);
  363. mem_out8(0x4b, s3trio_base+0x1008000 + 0x03D4);
  364. mem_out8(0x00, s3trio_base+0x1008000 + 0x03D5);
  365. mem_out8(0x00, s3trio_base+0x1008000 + 0x03D5);
  366. mem_out8(0x00, s3trio_base+0x1008000 + 0x03D5);
  367. mem_out8(0x45, s3trio_base+0x1008000 + 0x03D4);
  368. mem_out8(0, s3trio_base+0x1008000 + 0x03D5);
  369. /* setup default color table */
  370. for(i = 0; i < 16; i++) {
  371. int j = color_table[i];
  372. palette[i].red=default_red[j];
  373. palette[i].green=default_grn[j];
  374. palette[i].blue=default_blu[j];
  375. }
  376. s3trio_setcolreg(255, 56, 100, 160, 0, NULL /* not used */);
  377. s3trio_setcolreg(254, 0, 0, 0, 0, NULL /* not used */);
  378. memset((char *)s3trio_base, 0, 640*480);
  379. #if 0
  380. Trio_RectFill(0, 0, 90, 90, 7, 1);
  381. #endif
  382. fb_fix.visual = FB_VISUAL_PSEUDOCOLOR ;
  383. fb_var.xoffset = fb_var.yoffset = 0;
  384. fb_var.bits_per_pixel = 8;
  385. fb_var.grayscale = 0;
  386. fb_var.red.offset = fb_var.green.offset = fb_var.blue.offset = 0;
  387. fb_var.red.length = fb_var.green.length = fb_var.blue.length = 8;
  388. fb_var.red.msb_right = fb_var.green.msb_right = fb_var.blue.msb_right = 0;
  389. fb_var.transp.offset = fb_var.transp.length = fb_var.transp.msb_right = 0;
  390. fb_var.nonstd = 0;
  391. fb_var.activate = 0;
  392. fb_var.height = fb_var.width = -1;
  393. fb_var.accel_flags = FB_ACCELF_TEXT;
  394. #warning FIXME: always obey fb_var.accel_flags
  395. fb_var.pixclock = 1;
  396. fb_var.left_margin = fb_var.right_margin = 0;
  397. fb_var.upper_margin = fb_var.lower_margin = 0;
  398. fb_var.hsync_len = fb_var.vsync_len = 0;
  399. fb_var.sync = 0;
  400. fb_var.vmode = FB_VMODE_NONINTERLACED;
  401. disp.var = fb_var;
  402. disp.cmap.start = 0;
  403. disp.cmap.len = 0;
  404. disp.cmap.red = disp.cmap.green = disp.cmap.blue = disp.cmap.transp = NULL;
  405. disp.visual = fb_fix.visual;
  406. disp.type = fb_fix.type;
  407. disp.type_aux = fb_fix.type_aux;
  408. disp.ypanstep = 0;
  409. disp.ywrapstep = 0;
  410. disp.line_length = fb_fix.line_length;
  411. disp.can_soft_blank = 1;
  412. disp.inverse = 0;
  413. #ifdef FBCON_HAS_CFB8
  414. if (fb_var.accel_flags & FB_ACCELF_TEXT)
  415. disp.dispsw = &fbcon_trio8;
  416. else
  417. disp.dispsw = &fbcon_cfb8;
  418. #else
  419. disp.dispsw = &fbcon_dummy;
  420. #endif
  421. disp.scrollmode = fb_var.accel_flags & FB_ACCELF_TEXT ? 0 : SCROLL_YREDRAW;
  422. strcpy(fb_info.modename, "Trio64 ");
  423. strncat(fb_info.modename, dp->full_name, sizeof(fb_info.modename));
  424. fb_info.currcon = -1;
  425. fb_info.fbops = &s3trio_ops;
  426. fb_info.screen_base = s3trio_base;
  427. #if 0
  428. fb_info.fbvar_num = 1;
  429. fb_info.fbvar = &fb_var;
  430. #endif
  431. fb_info.disp = &disp;
  432. fb_info.fontname[0] = '\0';
  433. fb_info.changevar = NULL;
  434. fb_info.switch_con = &s3triofbcon_switch;
  435. fb_info.updatevar = &s3triofbcon_updatevar;
  436. #if 0
  437. fb_info.setcmap = &s3triofbcon_setcmap;
  438. #endif
  439. fb_info.flags = FBINFO_FLAG_DEFAULT;
  440. if (register_framebuffer(&fb_info) < 0)
  441. return;
  442. printk("fb%d: S3 Trio frame buffer device on %s\n",
  443. fb_info.node, dp->full_name);
  444. }
  445. static int s3triofbcon_switch(int con, struct fb_info *info)
  446. {
  447. /* Do we have to save the colormap? */
  448. if (fb_display[info->currcon].cmap.len)
  449. fb_get_cmap(&fb_display[info->currcon].cmap, 1, s3trio_getcolreg, info);
  450. info->currcon = con;
  451. /* Install new colormap */
  452. do_install_cmap(con,info);
  453. return 0;
  454. }
  455. /*
  456. * Update the `var' structure (called by fbcon.c)
  457. */
  458. static int s3triofbcon_updatevar(int con, struct fb_info *info)
  459. {
  460. /* Nothing */
  461. return 0;
  462. }
  463. /*
  464. * Blank the display.
  465. */
  466. static int s3triofb_blank(int blank, struct fb_info *info)
  467. {
  468. unsigned char x;
  469. mem_out8(0x1, s3trio_base+0x1008000 + 0x03c4);
  470. x = mem_in8(s3trio_base+0x1008000 + 0x03c5);
  471. mem_out8((x & (~0x20)) | (blank << 5), s3trio_base+0x1008000 + 0x03c5);
  472. return 0;
  473. }
  474. /*
  475. * Read a single color register and split it into
  476. * colors/transparent. Return != 0 for invalid regno.
  477. */
  478. static int s3trio_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
  479. u_int *transp, struct fb_info *info)
  480. {
  481. if (regno > 255)
  482. return 1;
  483. *red = (palette[regno].red << 8) | palette[regno].red;
  484. *green = (palette[regno].green << 8) | palette[regno].green;
  485. *blue = (palette[regno].blue << 8) | palette[regno].blue;
  486. *transp = 0;
  487. return 0;
  488. }
  489. /*
  490. * Set a single color register. Return != 0 for invalid regno.
  491. */
  492. static int s3trio_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  493. u_int transp, struct fb_info *info)
  494. {
  495. if (regno > 255)
  496. return 1;
  497. red >>= 8;
  498. green >>= 8;
  499. blue >>= 8;
  500. palette[regno].red = red;
  501. palette[regno].green = green;
  502. palette[regno].blue = blue;
  503. mem_out8(regno,s3trio_base+0x1008000 + 0x3c8);
  504. mem_out8((red & 0xff) >> 2,s3trio_base+0x1008000 + 0x3c9);
  505. mem_out8((green & 0xff) >> 2,s3trio_base+0x1008000 + 0x3c9);
  506. mem_out8((blue & 0xff) >> 2,s3trio_base+0x1008000 + 0x3c9);
  507. return 0;
  508. }
  509. static void Trio_WaitQueue(u_short fifo) {
  510. u_short status;
  511. do
  512. {
  513. status = mem_in16(s3trio_base + 0x1000000 + 0x9AE8);
  514. } while (!(status & fifo));
  515. }
  516. static void Trio_WaitBlit(void) {
  517. u_short status;
  518. do
  519. {
  520. status = mem_in16(s3trio_base + 0x1000000 + 0x9AE8);
  521. } while (status & 0x200);
  522. }
  523. static void Trio_BitBLT(u_short curx, u_short cury, u_short destx,
  524. u_short desty, u_short width, u_short height,
  525. u_short mode) {
  526. u_short blitcmd = 0xc011;
  527. /* Set drawing direction */
  528. /* -Y, X maj, -X (default) */
  529. if (curx > destx)
  530. blitcmd |= 0x0020; /* Drawing direction +X */
  531. else {
  532. curx += (width - 1);
  533. destx += (width - 1);
  534. }
  535. if (cury > desty)
  536. blitcmd |= 0x0080; /* Drawing direction +Y */
  537. else {
  538. cury += (height - 1);
  539. desty += (height - 1);
  540. }
  541. Trio_WaitQueue(0x0400);
  542. outw(0xa000, 0xBEE8);
  543. outw(0x60 | mode, 0xBAE8);
  544. outw(curx, 0x86E8);
  545. outw(cury, 0x82E8);
  546. outw(destx, 0x8EE8);
  547. outw(desty, 0x8AE8);
  548. outw(height - 1, 0xBEE8);
  549. outw(width - 1, 0x96E8);
  550. outw(blitcmd, 0x9AE8);
  551. }
  552. static void Trio_RectFill(u_short x, u_short y, u_short width, u_short height,
  553. u_short mode, u_short color) {
  554. u_short blitcmd = 0x40b1;
  555. Trio_WaitQueue(0x0400);
  556. outw(0xa000, 0xBEE8);
  557. outw((0x20 | mode), 0xBAE8);
  558. outw(0xe000, 0xBEE8);
  559. outw(color, 0xA6E8);
  560. outw(x, 0x86E8);
  561. outw(y, 0x82E8);
  562. outw((height - 1), 0xBEE8);
  563. outw((width - 1), 0x96E8);
  564. outw(blitcmd, 0x9AE8);
  565. }
  566. static void Trio_MoveCursor(u_short x, u_short y) {
  567. mem_out8(0x39, s3trio_base + 0x1008000 + 0x3d4);
  568. mem_out8(0xa0, s3trio_base + 0x1008000 + 0x3d5);
  569. mem_out8(0x46, s3trio_base + 0x1008000 + 0x3d4);
  570. mem_out8((x & 0x0700) >> 8, s3trio_base + 0x1008000 + 0x3d5);
  571. mem_out8(0x47, s3trio_base + 0x1008000 + 0x3d4);
  572. mem_out8(x & 0x00ff, s3trio_base + 0x1008000 + 0x3d5);
  573. mem_out8(0x48, s3trio_base + 0x1008000 + 0x3d4);
  574. mem_out8((y & 0x0700) >> 8, s3trio_base + 0x1008000 + 0x3d5);
  575. mem_out8(0x49, s3trio_base + 0x1008000 + 0x3d4);
  576. mem_out8(y & 0x00ff, s3trio_base + 0x1008000 + 0x3d5);
  577. }
  578. /*
  579. * Text console acceleration
  580. */
  581. #ifdef FBCON_HAS_CFB8
  582. static void fbcon_trio8_bmove(struct display *p, int sy, int sx, int dy,
  583. int dx, int height, int width)
  584. {
  585. sx *= 8; dx *= 8; width *= 8;
  586. Trio_BitBLT((u_short)sx, (u_short)(sy*fontheight(p)), (u_short)dx,
  587. (u_short)(dy*fontheight(p)), (u_short)width,
  588. (u_short)(height*fontheight(p)), (u_short)S3_NEW);
  589. }
  590. static void fbcon_trio8_clear(struct vc_data *conp, struct display *p, int sy,
  591. int sx, int height, int width)
  592. {
  593. unsigned char bg;
  594. sx *= 8; width *= 8;
  595. bg = attr_bgcol_ec(p,conp);
  596. Trio_RectFill((u_short)sx,
  597. (u_short)(sy*fontheight(p)),
  598. (u_short)width,
  599. (u_short)(height*fontheight(p)),
  600. (u_short)S3_NEW,
  601. (u_short)bg);
  602. }
  603. static void fbcon_trio8_putc(struct vc_data *conp, struct display *p, int c,
  604. int yy, int xx)
  605. {
  606. Trio_WaitBlit();
  607. fbcon_cfb8_putc(conp, p, c, yy, xx);
  608. }
  609. static void fbcon_trio8_putcs(struct vc_data *conp, struct display *p,
  610. const unsigned short *s, int count, int yy, int xx)
  611. {
  612. Trio_WaitBlit();
  613. fbcon_cfb8_putcs(conp, p, s, count, yy, xx);
  614. }
  615. static void fbcon_trio8_revc(struct display *p, int xx, int yy)
  616. {
  617. Trio_WaitBlit();
  618. fbcon_cfb8_revc(p, xx, yy);
  619. }
  620. static struct display_switch fbcon_trio8 = {
  621. .setup = fbcon_cfb8_setup,
  622. .bmove = fbcon_trio8_bmove,
  623. .clear = fbcon_trio8_clear,
  624. .putc = fbcon_trio8_putc,
  625. .putcs = fbcon_trio8_putcs,
  626. .revc = fbcon_trio8_revc,
  627. .clear_margins = fbcon_cfb8_clear_margins,
  628. .fontwidthmask = FONTWIDTH(8)
  629. };
  630. #endif
  631. MODULE_LICENSE("GPL");