2 * SiS 300/630/730/540/315/550/65x/74x/330/760 frame buffer driver
3 * for Linux kernels 2.4.x and 2.6.x
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the named License,
10 * or any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
21 * Based on the XFree86/X.org driver which is
22 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria
24 * Author: Thomas Winischhofer <thomas@winischhofer.net>
25 * (see http://www.winischhofer.net/
26 * for more information and updates)
29 #include <linux/config.h>
30 #include <linux/version.h>
31 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/errno.h>
35 #include <linux/console.h>
36 #include <linux/selection.h>
37 #include <linux/ioport.h>
38 #include <linux/capability.h>
40 #include <linux/types.h>
44 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
45 #include <video/fbcon.h>
46 #include <video/fbcon-cfb8.h>
47 #include <video/fbcon-cfb16.h>
48 #include <video/fbcon-cfb24.h>
49 #include <video/fbcon-cfb32.h>
53 #include "sis_accel.h"
55 static const u8 sisALUConv
[] =
57 0x00, /* dest = 0; 0, GXclear, 0 */
58 0x88, /* dest &= src; DSa, GXand, 0x1 */
59 0x44, /* dest = src & ~dest; SDna, GXandReverse, 0x2 */
60 0xCC, /* dest = src; S, GXcopy, 0x3 */
61 0x22, /* dest &= ~src; DSna, GXandInverted, 0x4 */
62 0xAA, /* dest = dest; D, GXnoop, 0x5 */
63 0x66, /* dest = ^src; DSx, GXxor, 0x6 */
64 0xEE, /* dest |= src; DSo, GXor, 0x7 */
65 0x11, /* dest = ~src & ~dest; DSon, GXnor, 0x8 */
66 0x99, /* dest ^= ~src ; DSxn, GXequiv, 0x9 */
67 0x55, /* dest = ~dest; Dn, GXInvert, 0xA */
68 0xDD, /* dest = src|~dest ; SDno, GXorReverse, 0xB */
69 0x33, /* dest = ~src; Sn, GXcopyInverted, 0xC */
70 0xBB, /* dest |= ~src; DSno, GXorInverted, 0xD */
71 0x77, /* dest = ~src|~dest; DSan, GXnand, 0xE */
72 0xFF, /* dest = 0xFF; 1, GXset, 0xF */
74 /* same ROP but with Pattern as Source */
75 static const u8 sisPatALUConv
[] =
77 0x00, /* dest = 0; 0, GXclear, 0 */
78 0xA0, /* dest &= src; DPa, GXand, 0x1 */
79 0x50, /* dest = src & ~dest; PDna, GXandReverse, 0x2 */
80 0xF0, /* dest = src; P, GXcopy, 0x3 */
81 0x0A, /* dest &= ~src; DPna, GXandInverted, 0x4 */
82 0xAA, /* dest = dest; D, GXnoop, 0x5 */
83 0x5A, /* dest = ^src; DPx, GXxor, 0x6 */
84 0xFA, /* dest |= src; DPo, GXor, 0x7 */
85 0x05, /* dest = ~src & ~dest; DPon, GXnor, 0x8 */
86 0xA5, /* dest ^= ~src ; DPxn, GXequiv, 0x9 */
87 0x55, /* dest = ~dest; Dn, GXInvert, 0xA */
88 0xF5, /* dest = src|~dest ; PDno, GXorReverse, 0xB */
89 0x0F, /* dest = ~src; Pn, GXcopyInverted, 0xC */
90 0xAF, /* dest |= ~src; DPno, GXorInverted, 0xD */
91 0x5F, /* dest = ~src|~dest; DPan, GXnand, 0xE */
92 0xFF, /* dest = 0xFF; 1, GXset, 0xF */
95 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,34)
96 static const int myrops
[] = {
97 3, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
101 /* 300 series ----------------------------------------------------- */
102 #ifdef CONFIG_FB_SIS_300
104 SiS300Sync(struct sis_video_info
*ivideo
)
110 SiS300SetupForScreenToScreenCopy(struct sis_video_info
*ivideo
, int xdir
, int ydir
,
111 int rop
, int trans_color
)
113 SiS300SetupDSTColorDepth(ivideo
->DstColor
);
114 SiS300SetupSRCPitch(ivideo
->video_linelength
)
115 SiS300SetupDSTRect(ivideo
->video_linelength
, 0xffff)
117 if(trans_color
!= -1) {
119 SiS300SetupSRCTrans(trans_color
)
120 SiS300SetupCMDFlag(TRANSPARENT_BITBLT
)
122 SiS300SetupROP(sisALUConv
[rop
])
125 SiS300SetupCMDFlag(X_INC
)
128 SiS300SetupCMDFlag(Y_INC
)
133 SiS300SubsequentScreenToScreenCopy(struct sis_video_info
*ivideo
, int src_x
,
134 int src_y
, int dst_x
, int dst_y
, int width
, int height
)
136 u32 srcbase
= 0, dstbase
= 0;
139 srcbase
= ivideo
->video_linelength
* src_y
;
143 dstbase
= ivideo
->video_linelength
* dst_y
;
147 SiS300SetupSRCBase(srcbase
);
148 SiS300SetupDSTBase(dstbase
);
150 if(!(ivideo
->CommandReg
& X_INC
)) {
154 if(!(ivideo
->CommandReg
& Y_INC
)) {
158 SiS300SetupRect(width
, height
)
159 SiS300SetupSRCXY(src_x
, src_y
)
160 SiS300SetupDSTXY(dst_x
, dst_y
)
165 SiS300SetupForSolidFill(struct sis_video_info
*ivideo
, u32 color
, int rop
)
167 SiS300SetupPATFG(color
)
168 SiS300SetupDSTRect(ivideo
->video_linelength
, 0xffff)
169 SiS300SetupDSTColorDepth(ivideo
->DstColor
);
170 SiS300SetupROP(sisPatALUConv
[rop
])
171 SiS300SetupCMDFlag(PATFG
)
175 SiS300SubsequentSolidFillRect(struct sis_video_info
*ivideo
, int x
, int y
, int w
, int h
)
180 dstbase
= ivideo
->video_linelength
* y
;
183 SiS300SetupDSTBase(dstbase
)
184 SiS300SetupDSTXY(x
,y
)
186 SiS300SetupCMDFlag(X_INC
| Y_INC
| BITBLT
)
191 /* 315/330 series ------------------------------------------------- */
193 #ifdef CONFIG_FB_SIS_315
195 SiS310Sync(struct sis_video_info
*ivideo
)
201 SiS310SetupForScreenToScreenCopy(struct sis_video_info
*ivideo
, int rop
, int trans_color
)
203 SiS310SetupDSTColorDepth(ivideo
->DstColor
);
204 SiS310SetupSRCPitch(ivideo
->video_linelength
)
205 SiS310SetupDSTRect(ivideo
->video_linelength
, 0xffff)
206 if(trans_color
!= -1) {
208 SiS310SetupSRCTrans(trans_color
)
209 SiS310SetupCMDFlag(TRANSPARENT_BITBLT
)
211 SiS310SetupROP(sisALUConv
[rop
])
212 /* Set command - not needed, both 0 */
213 /* SiSSetupCMDFlag(BITBLT | SRCVIDEO) */
215 SiS310SetupCMDFlag(ivideo
->SiS310_AccelDepth
)
216 /* The 315 series is smart enough to know the direction */
220 SiS310SubsequentScreenToScreenCopy(struct sis_video_info
*ivideo
, int src_x
, int src_y
,
221 int dst_x
, int dst_y
, int width
, int height
)
223 u32 srcbase
= 0, dstbase
= 0;
224 int mymin
= min(src_y
, dst_y
);
225 int mymax
= max(src_y
, dst_y
);
227 /* Although the chip knows the direction to use
228 * if the source and destination areas overlap,
229 * that logic fails if we fiddle with the bitmap
230 * addresses. Therefore, we check if the source
231 * and destination blitting areas overlap and
232 * adapt the bitmap addresses synchronously
233 * if the coordinates exceed the valid range.
234 * The the areas do not overlap, we do our
237 if((mymax
- mymin
) < height
) {
238 if((src_y
>= 2048) || (dst_y
>= 2048)) {
239 srcbase
= ivideo
->video_linelength
* mymin
;
240 dstbase
= ivideo
->video_linelength
* mymin
;
246 srcbase
= ivideo
->video_linelength
* src_y
;
250 dstbase
= ivideo
->video_linelength
* dst_y
;
255 SiS310SetupSRCBase(srcbase
);
256 SiS310SetupDSTBase(dstbase
);
257 SiS310SetupRect(width
, height
)
258 SiS310SetupSRCXY(src_x
, src_y
)
259 SiS310SetupDSTXY(dst_x
, dst_y
)
264 SiS310SetupForSolidFill(struct sis_video_info
*ivideo
, u32 color
, int rop
)
266 SiS310SetupPATFG(color
)
267 SiS310SetupDSTRect(ivideo
->video_linelength
, 0xffff)
268 SiS310SetupDSTColorDepth(ivideo
->DstColor
);
269 SiS310SetupROP(sisPatALUConv
[rop
])
270 SiS310SetupCMDFlag(PATFG
| ivideo
->SiS310_AccelDepth
)
274 SiS310SubsequentSolidFillRect(struct sis_video_info
*ivideo
, int x
, int y
, int w
, int h
)
279 dstbase
= ivideo
->video_linelength
* y
;
282 SiS310SetupDSTBase(dstbase
)
283 SiS310SetupDSTXY(x
,y
)
285 SiS310SetupCMDFlag(BITBLT
)
290 /* --------------------------------------------------------------------- */
292 /* The exported routines */
294 int sisfb_initaccel(struct sis_video_info
*ivideo
)
296 #ifdef SISFB_USE_SPINLOCKS
297 spin_lock_init(&ivideo
->lockaccel
);
302 void sisfb_syncaccel(struct sis_video_info
*ivideo
)
304 if(ivideo
->sisvga_engine
== SIS_300_VGA
) {
305 #ifdef CONFIG_FB_SIS_300
309 #ifdef CONFIG_FB_SIS_315
315 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) /* --------------- 2.5 --------------- */
317 int fbcon_sis_sync(struct fb_info
*info
)
319 struct sis_video_info
*ivideo
= (struct sis_video_info
*)info
->par
;
325 if(ivideo
->sisvga_engine
== SIS_300_VGA
) {
326 #ifdef CONFIG_FB_SIS_300
330 #ifdef CONFIG_FB_SIS_315
338 void fbcon_sis_fillrect(struct fb_info
*info
, const struct fb_fillrect
*rect
)
340 struct sis_video_info
*ivideo
= (struct sis_video_info
*)info
->par
;
342 u32 vxres
= info
->var
.xres_virtual
;
343 u32 vyres
= info
->var
.yres_virtual
;
347 if(info
->state
!= FBINFO_STATE_RUNNING
) {
352 cfb_fillrect(info
, rect
);
356 if(!rect
->width
|| !rect
->height
|| rect
->dx
>= vxres
|| rect
->dy
>= vyres
) {
361 width
= ((rect
->dx
+ rect
->width
) > vxres
) ? (vxres
- rect
->dx
) : rect
->width
;
362 height
= ((rect
->dy
+ rect
->height
) > vyres
) ? (vyres
- rect
->dy
) : rect
->height
;
364 switch(info
->var
.bits_per_pixel
) {
365 case 8: col
= rect
->color
;
368 case 32: col
= ((u32
*)(info
->pseudo_palette
))[rect
->color
];
372 if(ivideo
->sisvga_engine
== SIS_300_VGA
) {
373 #ifdef CONFIG_FB_SIS_300
375 SiS300SetupForSolidFill(ivideo
, col
, myrops
[rect
->rop
]);
376 SiS300SubsequentSolidFillRect(ivideo
, rect
->dx
, rect
->dy
, width
, height
);
381 #ifdef CONFIG_FB_SIS_315
383 SiS310SetupForSolidFill(ivideo
, col
, myrops
[rect
->rop
]);
384 SiS310SubsequentSolidFillRect(ivideo
, rect
->dx
, rect
->dy
, width
, height
);
392 void fbcon_sis_copyarea(struct fb_info
*info
, const struct fb_copyarea
*area
)
394 struct sis_video_info
*ivideo
= (struct sis_video_info
*)info
->par
;
395 u32 vxres
= info
->var
.xres_virtual
;
396 u32 vyres
= info
->var
.yres_virtual
;
397 int width
= area
->width
;
398 int height
= area
->height
;
401 if(info
->state
!= FBINFO_STATE_RUNNING
) {
406 cfb_copyarea(info
, area
);
410 if(!width
|| !height
||
411 area
->sx
>= vxres
|| area
->sy
>= vyres
||
412 area
->dx
>= vxres
|| area
->dy
>= vyres
) {
417 if((area
->sx
+ width
) > vxres
) width
= vxres
- area
->sx
;
418 if((area
->dx
+ width
) > vxres
) width
= vxres
- area
->dx
;
419 if((area
->sy
+ height
) > vyres
) height
= vyres
- area
->sy
;
420 if((area
->dy
+ height
) > vyres
) height
= vyres
- area
->dy
;
422 if(ivideo
->sisvga_engine
== SIS_300_VGA
) {
423 #ifdef CONFIG_FB_SIS_300
426 if(area
->sx
< area
->dx
) xdir
= 0;
428 if(area
->sy
< area
->dy
) ydir
= 0;
432 SiS300SetupForScreenToScreenCopy(ivideo
, xdir
, ydir
, 3, -1);
433 SiS300SubsequentScreenToScreenCopy(ivideo
, area
->sx
, area
->sy
, area
->dx
, area
->dy
,
439 #ifdef CONFIG_FB_SIS_315
441 SiS310SetupForScreenToScreenCopy(ivideo
, 3, -1);
442 SiS310SubsequentScreenToScreenCopy(ivideo
, area
->sx
, area
->sy
, area
->dx
, area
->dy
,
452 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* -------------- 2.4 --------------- */
454 void fbcon_sis_bmove(struct display
*p
, int srcy
, int srcx
,
455 int dsty
, int dstx
, int height
, int width
)
457 struct sis_video_info
*ivideo
= (struct sis_video_info
*)p
->fb_info
->par
;
462 switch(ivideo
->video_bpp
) {
464 #ifdef FBCON_HAS_CFB8
465 fbcon_cfb8_bmove(p
, srcy
, srcx
, dsty
, dstx
, height
, width
);
469 #ifdef FBCON_HAS_CFB16
470 fbcon_cfb16_bmove(p
, srcy
, srcx
, dsty
, dstx
, height
, width
);
474 #ifdef FBCON_HAS_CFB32
475 fbcon_cfb32_bmove(p
, srcy
, srcx
, dsty
, dstx
, height
, width
);
482 srcx
*= fontwidth(p
);
483 srcy
*= fontheight(p
);
484 dstx
*= fontwidth(p
);
485 dsty
*= fontheight(p
);
486 width
*= fontwidth(p
);
487 height
*= fontheight(p
);
489 if(ivideo
->sisvga_engine
== SIS_300_VGA
) {
490 #ifdef CONFIG_FB_SIS_300
493 if(srcx
< dstx
) xdir
= 0;
495 if(srcy
< dsty
) ydir
= 0;
499 SiS300SetupForScreenToScreenCopy(ivideo
, xdir
, ydir
, 3, -1);
500 SiS300SubsequentScreenToScreenCopy(ivideo
, srcx
, srcy
, dstx
, dsty
, width
, height
);
505 #ifdef CONFIG_FB_SIS_315
507 SiS310SetupForScreenToScreenCopy(ivideo
, 3, -1);
508 SiS310SubsequentScreenToScreenCopy(ivideo
, srcx
, srcy
, dstx
, dsty
, width
, height
);
515 static void fbcon_sis_clear(struct vc_data
*conp
, struct display
*p
,
516 int srcy
, int srcx
, int height
, int width
, int color
)
518 struct sis_video_info
*ivideo
= (struct sis_video_info
*)p
->fb_info
->par
;
521 srcx
*= fontwidth(p
);
522 srcy
*= fontheight(p
);
523 width
*= fontwidth(p
);
524 height
*= fontheight(p
);
526 if(ivideo
->sisvga_engine
== SIS_300_VGA
) {
527 #ifdef CONFIG_FB_SIS_300
529 SiS300SetupForSolidFill(ivideo
, color
, 3);
530 SiS300SubsequentSolidFillRect(ivideo
, srcx
, srcy
, width
, height
);
535 #ifdef CONFIG_FB_SIS_315
537 SiS310SetupForSolidFill(ivideo
, color
, 3);
538 SiS310SubsequentSolidFillRect(ivideo
, srcx
, srcy
, width
, height
);
545 void fbcon_sis_clear8(struct vc_data
*conp
, struct display
*p
,
546 int srcy
, int srcx
, int height
, int width
)
548 struct sis_video_info
*ivideo
= (struct sis_video_info
*)p
->fb_info
->par
;
552 #ifdef FBCON_HAS_CFB8
553 fbcon_cfb8_clear(conp
, p
, srcy
, srcx
, height
, width
);
558 bgx
= attr_bgcol_ec(p
, conp
);
559 fbcon_sis_clear(conp
, p
, srcy
, srcx
, height
, width
, bgx
);
562 void fbcon_sis_clear16(struct vc_data
*conp
, struct display
*p
,
563 int srcy
, int srcx
, int height
, int width
)
565 struct sis_video_info
*ivideo
= (struct sis_video_info
*)p
->fb_info
->par
;
569 #ifdef FBCON_HAS_CFB16
570 fbcon_cfb16_clear(conp
, p
, srcy
, srcx
, height
, width
);
575 bgx
= ((u_int16_t
*)p
->dispsw_data
)[attr_bgcol_ec(p
, conp
)];
576 fbcon_sis_clear(conp
, p
, srcy
, srcx
, height
, width
, bgx
);
579 void fbcon_sis_clear32(struct vc_data
*conp
, struct display
*p
,
580 int srcy
, int srcx
, int height
, int width
)
582 struct sis_video_info
*ivideo
= (struct sis_video_info
*)p
->fb_info
->par
;
586 #ifdef FBCON_HAS_CFB32
587 fbcon_cfb32_clear(conp
, p
, srcy
, srcx
, height
, width
);
592 bgx
= ((u_int32_t
*)p
->dispsw_data
)[attr_bgcol_ec(p
, conp
)];
593 fbcon_sis_clear(conp
, p
, srcy
, srcx
, height
, width
, bgx
);
596 void fbcon_sis_revc(struct display
*p
, int srcx
, int srcy
)
598 struct sis_video_info
*ivideo
= (struct sis_video_info
*)p
->fb_info
->par
;
602 switch(ivideo
->video_bpp
) {
604 #ifdef FBCON_HAS_CFB16
605 fbcon_cfb16_revc(p
, srcx
, srcy
);
609 #ifdef FBCON_HAS_CFB32
610 fbcon_cfb32_revc(p
, srcx
, srcy
);
617 srcx
*= fontwidth(p
);
618 srcy
*= fontheight(p
);
620 if(ivideo
->sisvga_engine
== SIS_300_VGA
) {
621 #ifdef CONFIG_FB_SIS_300
623 SiS300SetupForSolidFill(ivideo
, 0, 0x0a);
624 SiS300SubsequentSolidFillRect(ivideo
, srcx
, srcy
, fontwidth(p
), fontheight(p
));
629 #ifdef CONFIG_FB_SIS_315
631 SiS310SetupForSolidFill(ivideo
, 0, 0x0a);
632 SiS310SubsequentSolidFillRect(ivideo
, srcx
, srcy
, fontwidth(p
), fontheight(p
));
639 #ifdef FBCON_HAS_CFB8
640 struct display_switch fbcon_sis8
= {
641 .setup
= fbcon_cfb8_setup
,
642 .bmove
= fbcon_sis_bmove
,
643 .clear
= fbcon_sis_clear8
,
644 .putc
= fbcon_cfb8_putc
,
645 .putcs
= fbcon_cfb8_putcs
,
646 .revc
= fbcon_cfb8_revc
,
647 .clear_margins
= fbcon_cfb8_clear_margins
,
648 .fontwidthmask
= FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
651 #ifdef FBCON_HAS_CFB16
652 struct display_switch fbcon_sis16
= {
653 .setup
= fbcon_cfb16_setup
,
654 .bmove
= fbcon_sis_bmove
,
655 .clear
= fbcon_sis_clear16
,
656 .putc
= fbcon_cfb16_putc
,
657 .putcs
= fbcon_cfb16_putcs
,
658 .revc
= fbcon_sis_revc
,
659 .clear_margins
= fbcon_cfb16_clear_margins
,
660 .fontwidthmask
= FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
663 #ifdef FBCON_HAS_CFB32
664 struct display_switch fbcon_sis32
= {
665 .setup
= fbcon_cfb32_setup
,
666 .bmove
= fbcon_sis_bmove
,
667 .clear
= fbcon_sis_clear32
,
668 .putc
= fbcon_cfb32_putc
,
669 .putcs
= fbcon_cfb32_putcs
,
670 .revc
= fbcon_sis_revc
,
671 .clear_margins
= fbcon_cfb32_clear_margins
,
672 .fontwidthmask
= FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
676 #endif /* KERNEL VERSION */