2 * SiS 300/540/630[S]/730[S],
3 * SiS 315[E|PRO]/550/[M]650/651/[M]661[F|M]X/740/[M]741[GX]/330/[M]760[GX],
5 * frame buffer driver for Linux kernels >= 2.4.14 and >=2.6.3
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the named License,
12 * or any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
23 * Based on the XFree86/X.org driver which is
24 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
26 * Author: Thomas Winischhofer <thomas@winischhofer.net>
27 * (see http://www.winischhofer.net/
28 * for more information and updates)
31 #include <linux/config.h>
32 #include <linux/version.h>
33 #include <linux/module.h>
34 #include <linux/kernel.h>
36 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
37 #include <linux/console.h>
39 #include <linux/ioport.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/340 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
, 0x0fff)
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 chip 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 srcbase
+= ivideo
->video_offset
;
256 dstbase
+= ivideo
->video_offset
;
258 SiS310SetupSRCBase(srcbase
);
259 SiS310SetupDSTBase(dstbase
);
260 SiS310SetupRect(width
, height
)
261 SiS310SetupSRCXY(src_x
, src_y
)
262 SiS310SetupDSTXY(dst_x
, dst_y
)
267 SiS310SetupForSolidFill(struct sis_video_info
*ivideo
, u32 color
, int rop
)
269 SiS310SetupPATFG(color
)
270 SiS310SetupDSTRect(ivideo
->video_linelength
, 0x0fff)
271 SiS310SetupDSTColorDepth(ivideo
->DstColor
);
272 SiS310SetupROP(sisPatALUConv
[rop
])
273 SiS310SetupCMDFlag(PATFG
| ivideo
->SiS310_AccelDepth
)
277 SiS310SubsequentSolidFillRect(struct sis_video_info
*ivideo
, int x
, int y
, int w
, int h
)
282 dstbase
= ivideo
->video_linelength
* y
;
285 dstbase
+= ivideo
->video_offset
;
286 SiS310SetupDSTBase(dstbase
)
287 SiS310SetupDSTXY(x
,y
)
289 SiS310SetupCMDFlag(BITBLT
)
294 /* --------------------------------------------------------------------- */
296 /* The exported routines */
298 int sisfb_initaccel(struct sis_video_info
*ivideo
)
300 #ifdef SISFB_USE_SPINLOCKS
301 spin_lock_init(&ivideo
->lockaccel
);
306 void sisfb_syncaccel(struct sis_video_info
*ivideo
)
308 if(ivideo
->sisvga_engine
== SIS_300_VGA
) {
309 #ifdef CONFIG_FB_SIS_300
313 #ifdef CONFIG_FB_SIS_315
319 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) /* --------------- 2.5 --------------- */
321 int fbcon_sis_sync(struct fb_info
*info
)
323 struct sis_video_info
*ivideo
= (struct sis_video_info
*)info
->par
;
326 if((!ivideo
->accel
) || (!ivideo
->engineok
))
330 sisfb_syncaccel(ivideo
);
336 void fbcon_sis_fillrect(struct fb_info
*info
, const struct fb_fillrect
*rect
)
338 struct sis_video_info
*ivideo
= (struct sis_video_info
*)info
->par
;
340 u32 vxres
= info
->var
.xres_virtual
;
341 u32 vyres
= info
->var
.yres_virtual
;
345 if(info
->state
!= FBINFO_STATE_RUNNING
)
348 if((!ivideo
->accel
) || (!ivideo
->engineok
)) {
349 cfb_fillrect(info
, rect
);
353 if(!rect
->width
|| !rect
->height
|| rect
->dx
>= vxres
|| rect
->dy
>= vyres
)
357 width
= ((rect
->dx
+ rect
->width
) > vxres
) ? (vxres
- rect
->dx
) : rect
->width
;
358 height
= ((rect
->dy
+ rect
->height
) > vyres
) ? (vyres
- rect
->dy
) : rect
->height
;
360 switch(info
->var
.bits_per_pixel
) {
361 case 8: col
= rect
->color
;
364 case 32: col
= ((u32
*)(info
->pseudo_palette
))[rect
->color
];
368 if(ivideo
->sisvga_engine
== SIS_300_VGA
) {
369 #ifdef CONFIG_FB_SIS_300
371 SiS300SetupForSolidFill(ivideo
, col
, myrops
[rect
->rop
]);
372 SiS300SubsequentSolidFillRect(ivideo
, rect
->dx
, rect
->dy
, width
, height
);
376 #ifdef CONFIG_FB_SIS_315
378 SiS310SetupForSolidFill(ivideo
, col
, myrops
[rect
->rop
]);
379 SiS310SubsequentSolidFillRect(ivideo
, rect
->dx
, rect
->dy
, width
, height
);
384 sisfb_syncaccel(ivideo
);
387 void fbcon_sis_copyarea(struct fb_info
*info
, const struct fb_copyarea
*area
)
389 struct sis_video_info
*ivideo
= (struct sis_video_info
*)info
->par
;
390 u32 vxres
= info
->var
.xres_virtual
;
391 u32 vyres
= info
->var
.yres_virtual
;
392 int width
= area
->width
;
393 int height
= area
->height
;
396 if(info
->state
!= FBINFO_STATE_RUNNING
)
399 if((!ivideo
->accel
) || (!ivideo
->engineok
)) {
400 cfb_copyarea(info
, area
);
404 if(!width
|| !height
||
405 area
->sx
>= vxres
|| area
->sy
>= vyres
||
406 area
->dx
>= vxres
|| area
->dy
>= vyres
)
410 if((area
->sx
+ width
) > vxres
) width
= vxres
- area
->sx
;
411 if((area
->dx
+ width
) > vxres
) width
= vxres
- area
->dx
;
412 if((area
->sy
+ height
) > vyres
) height
= vyres
- area
->sy
;
413 if((area
->dy
+ height
) > vyres
) height
= vyres
- area
->dy
;
415 if(ivideo
->sisvga_engine
== SIS_300_VGA
) {
416 #ifdef CONFIG_FB_SIS_300
419 if(area
->sx
< area
->dx
) xdir
= 0;
421 if(area
->sy
< area
->dy
) ydir
= 0;
425 SiS300SetupForScreenToScreenCopy(ivideo
, xdir
, ydir
, 3, -1);
426 SiS300SubsequentScreenToScreenCopy(ivideo
, area
->sx
, area
->sy
,
427 area
->dx
, area
->dy
, width
, height
);
431 #ifdef CONFIG_FB_SIS_315
433 SiS310SetupForScreenToScreenCopy(ivideo
, 3, -1);
434 SiS310SubsequentScreenToScreenCopy(ivideo
, area
->sx
, area
->sy
,
435 area
->dx
, area
->dy
, width
, height
);
440 sisfb_syncaccel(ivideo
);
445 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* -------------- 2.4 --------------- */
447 #include "sisfb_accel_2_4.h"
449 #endif /* KERNEL VERSION */