2 * linux/drivers/video/S3Triofb.c -- Open Firmware based frame buffer device
4 * Copyright (C) 1997 Peter De Schrijver
6 * This driver is partly based on the PowerMac console driver:
8 * Copyright (C) 1996 Paul Mackerras
10 * and on the Open Firmware based frame buffer device:
12 * Copyright (C) 1997 Geert Uytterhoeven
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
20 Bugs : + OF dependencies should be removed.
21 + This driver should be merged with the CyberVision driver. The
22 CyberVision is a Zorro III implementation of the S3Trio64 chip.
26 #include <linux/config.h>
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/errno.h>
30 #include <linux/string.h>
32 #include <linux/tty.h>
33 #include <linux/malloc.h>
34 #include <linux/vmalloc.h>
35 #include <linux/delay.h>
36 #include <linux/interrupt.h>
38 #include <linux/init.h>
39 #include <linux/selection.h>
42 #include <asm/pci-bridge.h>
43 #include <linux/pci.h>
44 #ifdef CONFIG_FB_COMPAT_XPMAC
45 #include <asm/vc_ioctl.h>
49 #include "fbcon-cfb8.h"
53 #define mem_in8(addr) in_8((void *)(addr))
54 #define mem_in16(addr) in_le16((void *)(addr))
55 #define mem_in32(addr) in_le32((void *)(addr))
57 #define mem_out8(val, addr) out_8((void *)(addr), val)
58 #define mem_out16(val, addr) out_le16((void *)(addr), val)
59 #define mem_out32(val, addr) out_le32((void *)(addr), val)
61 #define IO_OUT16VAL(v, r) (((v) << 8) | (r))
63 #define arraysize(x) (sizeof(x)/sizeof(*(x)))
65 static int currcon
= 0;
66 static struct display disp
;
67 static struct fb_info fb_info
;
68 static struct { u_char red
, green
, blue
, pad
; } palette
[256];
69 static char s3trio_name
[16] = "S3Trio ";
70 static char *s3trio_base
;
72 static struct fb_fix_screeninfo fb_fix
;
73 static struct fb_var_screeninfo fb_var
= { 0, };
77 * Interface used by the world
80 static int s3trio_open(struct fb_info
*info
, int user
);
81 static int s3trio_release(struct fb_info
*info
, int user
);
82 static int s3trio_get_fix(struct fb_fix_screeninfo
*fix
, int con
,
83 struct fb_info
*info
);
84 static int s3trio_get_var(struct fb_var_screeninfo
*var
, int con
,
85 struct fb_info
*info
);
86 static int s3trio_set_var(struct fb_var_screeninfo
*var
, int con
,
87 struct fb_info
*info
);
88 static int s3trio_get_cmap(struct fb_cmap
*cmap
, int kspc
, int con
,
89 struct fb_info
*info
);
90 static int s3trio_set_cmap(struct fb_cmap
*cmap
, int kspc
, int con
,
91 struct fb_info
*info
);
92 static int s3trio_pan_display(struct fb_var_screeninfo
*var
, int con
,
93 struct fb_info
*info
);
94 static int s3trio_ioctl(struct inode
*inode
, struct file
*file
, u_int cmd
,
95 u_long arg
, int con
, struct fb_info
*info
);
97 #ifdef CONFIG_FB_COMPAT_XPMAC
98 extern struct vc_mode display_info
;
99 extern struct fb_info
*console_fb_info
;
100 extern int (*console_setmode_ptr
)(struct vc_mode
*, int);
101 extern int (*console_set_cmap_ptr
)(struct fb_cmap
*, int, int,
103 static int s3trio_console_setmode(struct vc_mode
*mode
, int doit
);
104 #endif /* CONFIG_FB_COMPAT_XPMAC */
107 * Interface to the low level console driver
110 void s3triofb_init(void);
111 static int s3triofbcon_switch(int con
, struct fb_info
*info
);
112 static int s3triofbcon_updatevar(int con
, struct fb_info
*info
);
113 static void s3triofbcon_blank(int blank
, struct fb_info
*info
);
115 static int s3triofbcon_setcmap(struct fb_cmap
*cmap
, int con
);
119 * Text console acceleration
122 #ifdef CONFIG_FBCON_CFB8
123 static struct display_switch fbcon_trio8
;
127 * Accelerated Functions used by the low level console driver
130 static void Trio_WaitQueue(u_short fifo
);
131 static void Trio_WaitBlit(void);
132 static void Trio_BitBLT(u_short curx
, u_short cury
, u_short destx
,
133 u_short desty
, u_short width
, u_short height
,
135 static void Trio_RectFill(u_short x
, u_short y
, u_short width
, u_short height
,
136 u_short mode
, u_short color
);
137 static void Trio_MoveCursor(u_short x
, u_short y
);
144 static int s3trio_getcolreg(u_int regno
, u_int
*red
, u_int
*green
, u_int
*blue
,
145 u_int
*transp
, struct fb_info
*info
);
146 static int s3trio_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
147 u_int transp
, struct fb_info
*info
);
148 static void do_install_cmap(int con
, struct fb_info
*info
);
151 static struct fb_ops s3trio_ops
= {
152 s3trio_open
, s3trio_release
, s3trio_get_fix
, s3trio_get_var
, s3trio_set_var
,
153 s3trio_get_cmap
, s3trio_set_cmap
, s3trio_pan_display
, s3trio_ioctl
158 * Open/Release the frame buffer device
161 static int s3trio_open(struct fb_info
*info
, int user
)
164 * Nothing, only a usage count for the moment
171 static int s3trio_release(struct fb_info
*info
, int user
)
179 * Get the Fixed Part of the Display
182 static int s3trio_get_fix(struct fb_fix_screeninfo
*fix
, int con
,
183 struct fb_info
*info
)
185 memcpy(fix
, &fb_fix
, sizeof(fb_fix
));
191 * Get the User Defined Part of the Display
194 static int s3trio_get_var(struct fb_var_screeninfo
*var
, int con
,
195 struct fb_info
*info
)
197 memcpy(var
, &fb_var
, sizeof(fb_var
));
203 * Set the User Defined Part of the Display
206 static int s3trio_set_var(struct fb_var_screeninfo
*var
, int con
,
207 struct fb_info
*info
)
209 if (var
->xres
> fb_var
.xres
|| var
->yres
> fb_var
.yres
||
210 var
->bits_per_pixel
> fb_var
.bits_per_pixel
)
211 /* || var->nonstd || var->vmode != FB_VMODE_NONINTERLACED) */
213 if (var
->xres_virtual
> fb_var
.xres_virtual
) {
214 outw(IO_OUT16VAL((var
->xres_virtual
/8) & 0xff, 0x13), 0x3d4);
215 outw(IO_OUT16VAL(((var
->xres_virtual
/8 ) & 0x300) >> 3, 0x51), 0x3d4);
216 fb_var
.xres_virtual
= var
->xres_virtual
;
217 fb_fix
.line_length
= var
->xres_virtual
;
219 fb_var
.yres_virtual
= var
->yres_virtual
;
220 memcpy(var
, &fb_var
, sizeof(fb_var
));
226 * Pan or Wrap the Display
228 * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
231 static int s3trio_pan_display(struct fb_var_screeninfo
*var
, int con
,
232 struct fb_info
*info
)
236 if (var
->xoffset
> (var
->xres_virtual
- var
->xres
))
238 if (var
->yoffset
> (var
->yres_virtual
- var
->yres
))
241 fb_var
.xoffset
= var
->xoffset
;
242 fb_var
.yoffset
= var
->yoffset
;
244 base
= var
->yoffset
* fb_fix
.line_length
+ var
->xoffset
;
246 outw(IO_OUT16VAL((base
>> 8) & 0xff, 0x0c),0x03D4);
247 outw(IO_OUT16VAL(base
& 0xff, 0x0d),0x03D4);
248 outw(IO_OUT16VAL((base
>> 16) & 0xf, 0x69),0x03D4);
257 static int s3trio_get_cmap(struct fb_cmap
*cmap
, int kspc
, int con
,
258 struct fb_info
*info
)
260 if (con
== currcon
) /* current console? */
261 return fb_get_cmap(cmap
, &fb_display
[con
].var
, kspc
, s3trio_getcolreg
,
263 else if (fb_display
[con
].cmap
.len
) /* non default colormap? */
264 fb_copy_cmap(&fb_display
[con
].cmap
, cmap
, kspc
? 0 : 2);
266 fb_copy_cmap(fb_default_cmap(1 << fb_display
[con
].var
.bits_per_pixel
),
275 static int s3trio_set_cmap(struct fb_cmap
*cmap
, int kspc
, int con
,
276 struct fb_info
*info
)
281 if (!fb_display
[con
].cmap
.len
) { /* no colormap allocated? */
282 if ((err
= fb_alloc_cmap(&fb_display
[con
].cmap
,
283 1<<fb_display
[con
].var
.bits_per_pixel
, 0)))
286 if (con
== currcon
) /* current console? */
287 return fb_set_cmap(cmap
, &fb_display
[con
].var
, kspc
, s3trio_setcolreg
,
290 fb_copy_cmap(cmap
, &fb_display
[con
].cmap
, kspc
? 0 : 1);
295 static int s3trio_ioctl(struct inode
*inode
, struct file
*file
, u_int cmd
,
296 u_long arg
, int con
, struct fb_info
*info
)
301 __initfunc(void s3triofb_init(void))
304 /* We don't want to be called like this. */
305 /* We rely on Open Firmware (offb) instead. */
306 #else /* !__powerpc__ */
307 /* To be merged with cybervision */
308 #endif /* !__powerpc__ */
311 __initfunc(void s3trio_resetaccel(void)) {
314 #define EC01_ENH_ENB 0x0005
315 #define EC01_LAW_ENB 0x0010
316 #define EC01_MMIO_ENB 0x0020
318 #define EC00_RESET 0x8000
319 #define EC00_ENABLE 0x4000
320 #define MF_MULT_MISC 0xE000
321 #define SRC_FOREGROUND 0x0020
322 #define SRC_BACKGROUND 0x0000
323 #define MIX_SRC 0x0007
324 #define MF_T_CLIP 0x1000
325 #define MF_L_CLIP 0x2000
326 #define MF_B_CLIP 0x3000
327 #define MF_R_CLIP 0x4000
328 #define MF_PIX_CONTROL 0xA000
329 #define MFA_SRC_FOREGR_MIX 0x0000
330 #define MF_PIX_CONTROL 0xA000
332 outw(EC00_RESET
, 0x42e8);
334 outw(EC00_ENABLE
, 0x42e8);
336 outw(EC01_ENH_ENB
| EC01_LAW_ENB
,
338 outw(MF_MULT_MISC
, 0xbee8); /* 16 bit I/O registers */
340 /* Now set some basic accelerator registers */
341 Trio_WaitQueue(0x0400);
342 outw(SRC_FOREGROUND
| MIX_SRC
, 0xbae8);
343 outw(SRC_BACKGROUND
| MIX_SRC
, 0xb6e8);/* direct color*/
344 outw(MF_T_CLIP
| 0, 0xbee8 ); /* clip virtual area */
345 outw(MF_L_CLIP
| 0, 0xbee8 );
346 outw(MF_R_CLIP
| (640 - 1), 0xbee8);
347 outw(MF_B_CLIP
| (480 - 1), 0xbee8);
348 Trio_WaitQueue(0x0400);
349 outw(0xffff, 0xaae8); /* Enable all planes */
350 outw(0xffff, 0xaae8); /* Enable all planes */
351 outw( MF_PIX_CONTROL
| MFA_SRC_FOREGR_MIX
, 0xbee8);
354 __initfunc(int s3trio_init(struct device_node
*dp
)) {
360 pci_device_loc(dp
,&bus
,&dev
);
361 pcibios_read_config_dword(bus
, dev
, PCI_VENDOR_ID
, &t32
);
362 if(t32
== (PCI_DEVICE_ID_S3_TRIO
<< 16) + PCI_VENDOR_ID_S3
) {
363 pcibios_read_config_dword(bus
, dev
, PCI_BASE_ADDRESS_0
, &t32
);
364 pcibios_read_config_dword(bus
, dev
, PCI_BASE_ADDRESS_1
, &t32
);
365 pcibios_read_config_word(bus
, dev
, PCI_COMMAND
,&cmd
);
367 pcibios_write_config_word(bus
, dev
, PCI_COMMAND
, PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
);
369 pcibios_write_config_dword(bus
, dev
, PCI_BASE_ADDRESS_0
,0xffffffff);
370 pcibios_read_config_dword(bus
, dev
, PCI_BASE_ADDRESS_0
, &t32
);
372 /* This is a gross hack as OF only maps enough memory for the framebuffer and
373 we want to use MMIO too. We should find out which chunk of address space
375 pcibios_write_config_dword(bus
,dev
,PCI_BASE_ADDRESS_0
,0xc6000000);
381 outb(inb(0x03CC) | 1, 0x3c2);
383 outw(IO_OUT16VAL(0x48, 0x38),0x03D4);
384 outw(IO_OUT16VAL(0xA0, 0x39),0x03D4);
386 outw(IO_OUT16VAL((inb(0x3d5) & ~(0x2 | 0x10 | 0x40)) |
389 outw(IO_OUT16VAL(0x6, 0x8), 0x3c4);
391 /* switch to MMIO only mode */
394 outw(IO_OUT16VAL(inb(0x3d5) | 3 | 0x10, 0x58), 0x3d4);
395 outw(IO_OUT16VAL(8, 0x53), 0x3d4);
397 /* switch off I/O accesses */
400 pcibios_write_config_word(bus
, dev
, PCI_COMMAND
,
401 PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
);
412 * We heavily rely on OF for the moment. This needs fixing.
415 __initfunc(void s3triofb_init_of(struct device_node
*dp
))
418 unsigned long address
;
421 strncat(s3trio_name
, dp
->name
, sizeof(s3trio_name
));
422 s3trio_name
[sizeof(s3trio_name
)-1] = '\0';
423 strcpy(fb_fix
.id
, s3trio_name
);
425 if((pp
= (int *)get_property(dp
, "vendor-id", &len
)) != NULL
426 && *pp
!=PCI_VENDOR_ID_S3
) {
427 printk("%s: can't find S3 Trio board\n", dp
->full_name
);
431 if((pp
= (int *)get_property(dp
, "device-id", &len
)) != NULL
432 && *pp
!=PCI_DEVICE_ID_S3_TRIO
) {
433 printk("%s: can't find S3 Trio board\n", dp
->full_name
);
437 if ((pp
= (int *)get_property(dp
, "depth", &len
)) != NULL
438 && len
== sizeof(int) && *pp
!= 8) {
439 printk("%s: can't use depth = %d\n", dp
->full_name
, *pp
);
442 if ((pp
= (int *)get_property(dp
, "width", &len
)) != NULL
443 && len
== sizeof(int))
444 fb_var
.xres
= fb_var
.xres_virtual
= *pp
;
445 if ((pp
= (int *)get_property(dp
, "height", &len
)) != NULL
446 && len
== sizeof(int))
447 fb_var
.yres
= fb_var
.yres_virtual
= *pp
;
448 if ((pp
= (int *)get_property(dp
, "linebytes", &len
)) != NULL
449 && len
== sizeof(int))
450 fb_fix
.line_length
= *pp
;
452 fb_fix
.line_length
= fb_var
.xres_virtual
;
453 fb_fix
.smem_len
= fb_fix
.line_length
*fb_var
.yres
;
456 address
= 0xc6000000;
457 s3trio_base
= ioremap(address
,64*1024*1024);
458 fb_fix
.smem_start
= (char *)address
;
459 fb_fix
.type
= FB_TYPE_PACKED_PIXELS
;
461 fb_fix
.accel
= FB_ACCEL_S3_TRIO64
;
462 fb_fix
.mmio_start
= (char *)address
+0x1000000;
463 fb_fix
.mmio_len
= 0x1000000;
470 mem_out8(0x30, s3trio_base
+0x1008000 + 0x03D4);
471 mem_out8(0x2d, s3trio_base
+0x1008000 + 0x03D4);
472 mem_out8(0x2e, s3trio_base
+0x1008000 + 0x03D4);
474 mem_out8(0x50, s3trio_base
+0x1008000 + 0x03D4);
476 /* disable HW cursor */
478 mem_out8(0x39, s3trio_base
+0x1008000 + 0x03D4);
479 mem_out8(0xa0, s3trio_base
+0x1008000 + 0x03D5);
481 mem_out8(0x45, s3trio_base
+0x1008000 + 0x03D4);
482 mem_out8(0, s3trio_base
+0x1008000 + 0x03D5);
484 mem_out8(0x4e, s3trio_base
+0x1008000 + 0x03D4);
485 mem_out8(0, s3trio_base
+0x1008000 + 0x03D5);
487 mem_out8(0x4f, s3trio_base
+0x1008000 + 0x03D4);
488 mem_out8(0, s3trio_base
+0x1008000 + 0x03D5);
492 CursorBase
= (u_long
*)(s3trio_base
+ 2*1024*1024 - 0x400);
493 for (i
= 0; i
< 8; i
++) {
494 *(CursorBase
+(i
*4)) = 0xffffff00;
495 *(CursorBase
+1+(i
*4)) = 0xffff0000;
496 *(CursorBase
+2+(i
*4)) = 0xffff0000;
497 *(CursorBase
+3+(i
*4)) = 0xffff0000;
499 for (i
= 8; i
< 64; i
++) {
500 *(CursorBase
+(i
*4)) = 0xffff0000;
501 *(CursorBase
+1+(i
*4)) = 0xffff0000;
502 *(CursorBase
+2+(i
*4)) = 0xffff0000;
503 *(CursorBase
+3+(i
*4)) = 0xffff0000;
507 mem_out8(0x4c, s3trio_base
+0x1008000 + 0x03D4);
508 mem_out8(((2*1024 - 1)&0xf00)>>8, s3trio_base
+0x1008000 + 0x03D5);
510 mem_out8(0x4d, s3trio_base
+0x1008000 + 0x03D4);
511 mem_out8((2*1024 - 1) & 0xff, s3trio_base
+0x1008000 + 0x03D5);
513 mem_out8(0x45, s3trio_base
+0x1008000 + 0x03D4);
514 mem_in8(s3trio_base
+0x1008000 + 0x03D4);
516 mem_out8(0x4a, s3trio_base
+0x1008000 + 0x03D4);
517 mem_out8(0x80, s3trio_base
+0x1008000 + 0x03D5);
518 mem_out8(0x80, s3trio_base
+0x1008000 + 0x03D5);
519 mem_out8(0x80, s3trio_base
+0x1008000 + 0x03D5);
521 mem_out8(0x4b, s3trio_base
+0x1008000 + 0x03D4);
522 mem_out8(0x00, s3trio_base
+0x1008000 + 0x03D5);
523 mem_out8(0x00, s3trio_base
+0x1008000 + 0x03D5);
524 mem_out8(0x00, s3trio_base
+0x1008000 + 0x03D5);
526 mem_out8(0x45, s3trio_base
+0x1008000 + 0x03D4);
527 mem_out8(0, s3trio_base
+0x1008000 + 0x03D5);
529 /* setup default color table */
531 for(i
= 0; i
< 16; i
++) {
532 int j
= color_table
[i
];
533 palette
[i
].red
=default_red
[j
];
534 palette
[i
].green
=default_grn
[j
];
535 palette
[i
].blue
=default_blu
[j
];
538 s3trio_setcolreg(255, 56, 100, 160, 0, NULL
/* not used */);
539 s3trio_setcolreg(254, 0, 0, 0, 0, NULL
/* not used */);
540 memset((char *)s3trio_base
, 0, 640*480);
543 Trio_RectFill(0, 0, 90, 90, 7, 1);
546 fb_fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
547 fb_var
.xoffset
= fb_var
.yoffset
= 0;
548 fb_var
.bits_per_pixel
= 8;
549 fb_var
.grayscale
= 0;
550 fb_var
.red
.offset
= fb_var
.green
.offset
= fb_var
.blue
.offset
= 0;
551 fb_var
.red
.length
= fb_var
.green
.length
= fb_var
.blue
.length
= 8;
552 fb_var
.red
.msb_right
= fb_var
.green
.msb_right
= fb_var
.blue
.msb_right
= 0;
553 fb_var
.transp
.offset
= fb_var
.transp
.length
= fb_var
.transp
.msb_right
= 0;
556 fb_var
.height
= fb_var
.width
= -1;
557 fb_var
.accel_flags
= FB_ACCELF_TEXT
;
558 #warning FIXME: always obey fb_var.accel_flags
560 fb_var
.left_margin
= fb_var
.right_margin
= 0;
561 fb_var
.upper_margin
= fb_var
.lower_margin
= 0;
562 fb_var
.hsync_len
= fb_var
.vsync_len
= 0;
564 fb_var
.vmode
= FB_VMODE_NONINTERLACED
;
569 disp
.cmap
.red
= disp
.cmap
.green
= disp
.cmap
.blue
= disp
.cmap
.transp
= NULL
;
570 disp
.screen_base
= s3trio_base
;
571 disp
.visual
= fb_fix
.visual
;
572 disp
.type
= fb_fix
.type
;
573 disp
.type_aux
= fb_fix
.type_aux
;
576 disp
.line_length
= fb_fix
.line_length
;
577 disp
.can_soft_blank
= 1;
579 #ifdef CONFIG_FBCON_CFB8
580 if (fb_var
.accel_flags
& FB_ACCELF_TEXT
)
581 disp
.dispsw
= &fbcon_trio8
;
583 disp
.dispsw
= &fbcon_cfb8
;
588 strcpy(fb_info
.modename
, "Trio64 ");
589 strncat(fb_info
.modename
, dp
->full_name
, sizeof(fb_info
.modename
));
591 fb_info
.fbops
= &s3trio_ops
;
593 fb_info
.fbvar_num
= 1;
594 fb_info
.fbvar
= &fb_var
;
596 fb_info
.disp
= &disp
;
597 fb_info
.fontname
[0] = '\0';
598 fb_info
.changevar
= NULL
;
599 fb_info
.switch_con
= &s3triofbcon_switch
;
600 fb_info
.updatevar
= &s3triofbcon_updatevar
;
601 fb_info
.blank
= &s3triofbcon_blank
;
603 fb_info
.setcmap
= &s3triofbcon_setcmap
;
606 #ifdef CONFIG_FB_COMPAT_XPMAC
607 if (!console_fb_info
) {
608 display_info
.height
= fb_var
.yres
;
609 display_info
.width
= fb_var
.xres
;
610 display_info
.depth
= 8;
611 display_info
.pitch
= fb_fix
.line_length
;
612 display_info
.mode
= 0;
613 strncpy(display_info
.name
, dp
->name
, sizeof(display_info
.name
));
614 display_info
.fb_address
= (unsigned long)fb_fix
.smem_start
;
615 display_info
.disp_reg_address
= address
+ 0x1008000;
616 display_info
.cmap_adr_address
= address
+ 0x1008000 + 0x3c8;
617 display_info
.cmap_data_address
= address
+ 0x1008000 + 0x3c9;
618 console_fb_info
= &fb_info
;
619 console_setmode_ptr
= s3trio_console_setmode
;
620 console_set_cmap_ptr
= s3trio_set_cmap
;
622 #endif /* CONFIG_FB_COMPAT_XPMAC) */
624 if (register_framebuffer(&fb_info
) < 0)
627 printk("fb%d: S3 Trio frame buffer device on %s\n",
628 GET_FB_IDX(fb_info
.node
), dp
->full_name
);
632 static int s3triofbcon_switch(int con
, struct fb_info
*info
)
634 /* Do we have to save the colormap? */
635 if (fb_display
[currcon
].cmap
.len
)
636 fb_get_cmap(&fb_display
[currcon
].cmap
, &fb_display
[currcon
].var
, 1,
637 s3trio_getcolreg
, info
);
640 /* Install new colormap */
641 do_install_cmap(con
,info
);
646 * Update the `var' structure (called by fbcon.c)
649 static int s3triofbcon_updatevar(int con
, struct fb_info
*info
)
659 static void s3triofbcon_blank(int blank
, struct fb_info
*info
)
663 mem_out8(0x1, s3trio_base
+0x1008000 + 0x03c4);
664 x
= mem_in8(s3trio_base
+0x1008000 + 0x03c5);
665 mem_out8((x
& (~0x20)) | (blank
<< 5), s3trio_base
+0x1008000 + 0x03c5);
673 static int s3triofbcon_setcmap(struct fb_cmap
*cmap
, int con
)
675 return(s3trio_set_cmap(cmap
, 1, con
, &fb_info
));
681 * Read a single color register and split it into
682 * colors/transparent. Return != 0 for invalid regno.
685 static int s3trio_getcolreg(u_int regno
, u_int
*red
, u_int
*green
, u_int
*blue
,
686 u_int
*transp
, struct fb_info
*info
)
690 *red
= palette
[regno
].red
;
691 *green
= palette
[regno
].green
;
692 *blue
= palette
[regno
].blue
;
698 * Set a single color register. The values supplied are already
699 * rounded down to the hardware's capabilities (according to the
700 * entries in the var structure). Return != 0 for invalid regno.
703 static int s3trio_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
704 u_int transp
, struct fb_info
*info
)
708 palette
[regno
].red
= red
;
709 palette
[regno
].green
= green
;
710 palette
[regno
].blue
= blue
;
712 mem_out8(regno
,s3trio_base
+0x1008000 + 0x3c8);
713 mem_out8((red
& 0xff) >> 2,s3trio_base
+0x1008000 + 0x3c9);
714 mem_out8((green
& 0xff) >> 2,s3trio_base
+0x1008000 + 0x3c9);
715 mem_out8((blue
& 0xff) >> 2,s3trio_base
+0x1008000 + 0x3c9);
721 static void do_install_cmap(int con
, struct fb_info
*info
)
725 if (fb_display
[con
].cmap
.len
)
726 fb_set_cmap(&fb_display
[con
].cmap
, &fb_display
[con
].var
, 1,
727 s3trio_setcolreg
, &fb_info
);
729 fb_set_cmap(fb_default_cmap(fb_display
[con
].var
.bits_per_pixel
),
730 &fb_display
[con
].var
, 1, s3trio_setcolreg
, &fb_info
);
733 #ifdef CONFIG_FB_COMPAT_XPMAC
736 * Backward compatibility mode for Xpmac
739 static int s3trio_console_setmode(struct vc_mode
*mode
, int doit
)
745 struct fb_var_screeninfo var
;
746 struct s3trio_par par
;
748 if (mode
->mode
<= 0 || mode
->mode
> VMODE_MAX
)
750 par
.video_mode
= mode
->mode
;
752 switch (mode
->depth
) {
755 par
.color_mode
= CMODE_32
;
758 par
.color_mode
= CMODE_16
;
761 case 0: /* (default) */
762 par
.color_mode
= CMODE_8
;
767 encode_var(&var
, &par
);
768 if ((err
= decode_var(&var
, &par
)))
771 s3trio_set_var(&var
, currcon
, 0);
776 #endif /* CONFIG_FB_COMPAT_XPMAC */
778 void s3triofb_setup(char *options
, int *ints
) {
784 static void Trio_WaitQueue(u_short fifo
) {
790 status
= mem_in16(s3trio_base
+ 0x1000000 + 0x9AE8);
791 } while (!(status
& fifo
));
795 static void Trio_WaitBlit(void) {
801 status
= mem_in16(s3trio_base
+ 0x1000000 + 0x9AE8);
802 } while (status
& 0x200);
806 static void Trio_BitBLT(u_short curx
, u_short cury
, u_short destx
,
807 u_short desty
, u_short width
, u_short height
,
810 u_short blitcmd
= 0xc011;
812 /* Set drawing direction */
813 /* -Y, X maj, -X (default) */
816 blitcmd
|= 0x0020; /* Drawing direction +X */
819 destx
+= (width
- 1);
823 blitcmd
|= 0x0080; /* Drawing direction +Y */
825 cury
+= (height
- 1);
826 desty
+= (height
- 1);
829 Trio_WaitQueue(0x0400);
831 outw(0xa000, 0xBEE8);
832 outw(0x60 | mode
, 0xBAE8);
840 outw(height
- 1, 0xBEE8);
841 outw(width
- 1, 0x96E8);
843 outw(blitcmd
, 0x9AE8);
847 static void Trio_RectFill(u_short x
, u_short y
, u_short width
, u_short height
,
848 u_short mode
, u_short color
) {
850 u_short blitcmd
= 0x40b1;
852 Trio_WaitQueue(0x0400);
854 outw(0xa000, 0xBEE8);
855 outw((0x20 | mode
), 0xBAE8);
856 outw(0xe000, 0xBEE8);
860 outw((height
- 1), 0xBEE8);
861 outw((width
- 1), 0x96E8);
862 outw(blitcmd
, 0x9AE8);
867 static void Trio_MoveCursor(u_short x
, u_short y
) {
869 mem_out8(0x39, s3trio_base
+ 0x1008000 + 0x3d4);
870 mem_out8(0xa0, s3trio_base
+ 0x1008000 + 0x3d5);
872 mem_out8(0x46, s3trio_base
+ 0x1008000 + 0x3d4);
873 mem_out8((x
& 0x0700) >> 8, s3trio_base
+ 0x1008000 + 0x3d5);
874 mem_out8(0x47, s3trio_base
+ 0x1008000 + 0x3d4);
875 mem_out8(x
& 0x00ff, s3trio_base
+ 0x1008000 + 0x3d5);
877 mem_out8(0x48, s3trio_base
+ 0x1008000 + 0x3d4);
878 mem_out8((y
& 0x0700) >> 8, s3trio_base
+ 0x1008000 + 0x3d5);
879 mem_out8(0x49, s3trio_base
+ 0x1008000 + 0x3d4);
880 mem_out8(y
& 0x00ff, s3trio_base
+ 0x1008000 + 0x3d5);
886 * Text console acceleration
889 #ifdef CONFIG_FBCON_CFB8
890 static void fbcon_trio8_bmove(struct display
*p
, int sy
, int sx
, int dy
,
891 int dx
, int height
, int width
)
893 sx
*= 8; dx
*= 8; width
*= 8;
894 Trio_BitBLT((u_short
)sx
, (u_short
)(sy
*p
->fontheight
), (u_short
)dx
,
895 (u_short
)(dy
*p
->fontheight
), (u_short
)width
,
896 (u_short
)(height
*p
->fontheight
), (u_short
)S3_NEW
);
899 static void fbcon_trio8_clear(struct vc_data
*conp
, struct display
*p
, int sy
,
900 int sx
, int height
, int width
)
905 bg
= attr_bgcol_ec(p
,conp
);
906 Trio_RectFill((u_short
)sx
,
907 (u_short
)(sy
*p
->fontheight
),
909 (u_short
)(height
*p
->fontheight
),
914 static void fbcon_trio8_putc(struct vc_data
*conp
, struct display
*p
, int c
,
918 fbcon_cfb8_putc(conp
, p
, c
, yy
, xx
);
921 static void fbcon_trio8_putcs(struct vc_data
*conp
, struct display
*p
,
922 const unsigned short *s
, int count
, int yy
, int xx
)
925 fbcon_cfb8_putcs(conp
, p
, s
, count
, yy
, xx
);
928 static void fbcon_trio8_revc(struct display
*p
, int xx
, int yy
)
931 fbcon_cfb8_revc(p
, xx
, yy
);
934 static struct display_switch fbcon_trio8
= {
935 fbcon_cfb8_setup
, fbcon_trio8_bmove
, fbcon_trio8_clear
, fbcon_trio8_putc
,
936 fbcon_trio8_putcs
, fbcon_trio8_revc
, NULL