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/version.h>
32 #include <linux/module.h>
33 #include <linux/kernel.h>
35 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
36 #include <linux/console.h>
38 #include <linux/ioport.h>
39 #include <linux/types.h>
43 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
44 #include <video/fbcon.h>
45 #include <video/fbcon-cfb8.h>
46 #include <video/fbcon-cfb16.h>
47 #include <video/fbcon-cfb24.h>
48 #include <video/fbcon-cfb32.h>
52 #include "sis_accel.h"
54 static const u8 sisALUConv[] =
56 0x00, /* dest = 0; 0, GXclear, 0 */
57 0x88, /* dest &= src; DSa, GXand, 0x1 */
58 0x44, /* dest = src & ~dest; SDna, GXandReverse, 0x2 */
59 0xCC, /* dest = src; S, GXcopy, 0x3 */
60 0x22, /* dest &= ~src; DSna, GXandInverted, 0x4 */
61 0xAA, /* dest = dest; D, GXnoop, 0x5 */
62 0x66, /* dest = ^src; DSx, GXxor, 0x6 */
63 0xEE, /* dest |= src; DSo, GXor, 0x7 */
64 0x11, /* dest = ~src & ~dest; DSon, GXnor, 0x8 */
65 0x99, /* dest ^= ~src ; DSxn, GXequiv, 0x9 */
66 0x55, /* dest = ~dest; Dn, GXInvert, 0xA */
67 0xDD, /* dest = src|~dest ; SDno, GXorReverse, 0xB */
68 0x33, /* dest = ~src; Sn, GXcopyInverted, 0xC */
69 0xBB, /* dest |= ~src; DSno, GXorInverted, 0xD */
70 0x77, /* dest = ~src|~dest; DSan, GXnand, 0xE */
71 0xFF, /* dest = 0xFF; 1, GXset, 0xF */
73 /* same ROP but with Pattern as Source */
74 static const u8 sisPatALUConv[] =
76 0x00, /* dest = 0; 0, GXclear, 0 */
77 0xA0, /* dest &= src; DPa, GXand, 0x1 */
78 0x50, /* dest = src & ~dest; PDna, GXandReverse, 0x2 */
79 0xF0, /* dest = src; P, GXcopy, 0x3 */
80 0x0A, /* dest &= ~src; DPna, GXandInverted, 0x4 */
81 0xAA, /* dest = dest; D, GXnoop, 0x5 */
82 0x5A, /* dest = ^src; DPx, GXxor, 0x6 */
83 0xFA, /* dest |= src; DPo, GXor, 0x7 */
84 0x05, /* dest = ~src & ~dest; DPon, GXnor, 0x8 */
85 0xA5, /* dest ^= ~src ; DPxn, GXequiv, 0x9 */
86 0x55, /* dest = ~dest; Dn, GXInvert, 0xA */
87 0xF5, /* dest = src|~dest ; PDno, GXorReverse, 0xB */
88 0x0F, /* dest = ~src; Pn, GXcopyInverted, 0xC */
89 0xAF, /* dest |= ~src; DPno, GXorInverted, 0xD */
90 0x5F, /* dest = ~src|~dest; DPan, GXnand, 0xE */
91 0xFF, /* dest = 0xFF; 1, GXset, 0xF */
94 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,34)
95 static const int myrops[] = {
96 3, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
100 /* 300 series ----------------------------------------------------- */
101 #ifdef CONFIG_FB_SIS_300
103 SiS300Sync(struct sis_video_info *ivideo)
109 SiS300SetupForScreenToScreenCopy(struct sis_video_info *ivideo, int xdir, int ydir,
110 int rop, int trans_color)
112 SiS300SetupDSTColorDepth(ivideo->DstColor);
113 SiS300SetupSRCPitch(ivideo->video_linelength)
114 SiS300SetupDSTRect(ivideo->video_linelength, 0xffff)
116 if(trans_color != -1) {
118 SiS300SetupSRCTrans(trans_color)
119 SiS300SetupCMDFlag(TRANSPARENT_BITBLT)
121 SiS300SetupROP(sisALUConv[rop])
124 SiS300SetupCMDFlag(X_INC)
127 SiS300SetupCMDFlag(Y_INC)
132 SiS300SubsequentScreenToScreenCopy(struct sis_video_info *ivideo, int src_x,
133 int src_y, int dst_x, int dst_y, int width, int height)
135 u32 srcbase = 0, dstbase = 0;
138 srcbase = ivideo->video_linelength * src_y;
142 dstbase = ivideo->video_linelength * dst_y;
146 SiS300SetupSRCBase(srcbase);
147 SiS300SetupDSTBase(dstbase);
149 if(!(ivideo->CommandReg & X_INC)) {
153 if(!(ivideo->CommandReg & Y_INC)) {
157 SiS300SetupRect(width, height)
158 SiS300SetupSRCXY(src_x, src_y)
159 SiS300SetupDSTXY(dst_x, dst_y)
164 SiS300SetupForSolidFill(struct sis_video_info *ivideo, u32 color, int rop)
166 SiS300SetupPATFG(color)
167 SiS300SetupDSTRect(ivideo->video_linelength, 0xffff)
168 SiS300SetupDSTColorDepth(ivideo->DstColor);
169 SiS300SetupROP(sisPatALUConv[rop])
170 SiS300SetupCMDFlag(PATFG)
174 SiS300SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w, int h)
179 dstbase = ivideo->video_linelength * y;
182 SiS300SetupDSTBase(dstbase)
183 SiS300SetupDSTXY(x,y)
185 SiS300SetupCMDFlag(X_INC | Y_INC | BITBLT)
190 /* 315/330/340 series ---------------------------------------------- */
192 #ifdef CONFIG_FB_SIS_315
194 SiS310Sync(struct sis_video_info *ivideo)
200 SiS310SetupForScreenToScreenCopy(struct sis_video_info *ivideo, int rop, int trans_color)
202 SiS310SetupDSTColorDepth(ivideo->DstColor);
203 SiS310SetupSRCPitch(ivideo->video_linelength)
204 SiS310SetupDSTRect(ivideo->video_linelength, 0x0fff)
205 if(trans_color != -1) {
207 SiS310SetupSRCTrans(trans_color)
208 SiS310SetupCMDFlag(TRANSPARENT_BITBLT)
210 SiS310SetupROP(sisALUConv[rop])
211 /* Set command - not needed, both 0 */
212 /* SiSSetupCMDFlag(BITBLT | SRCVIDEO) */
214 SiS310SetupCMDFlag(ivideo->SiS310_AccelDepth)
215 /* The chip is smart enough to know the direction */
219 SiS310SubsequentScreenToScreenCopy(struct sis_video_info *ivideo, int src_x, int src_y,
220 int dst_x, int dst_y, int width, int height)
222 u32 srcbase = 0, dstbase = 0;
223 int mymin = min(src_y, dst_y);
224 int mymax = max(src_y, dst_y);
226 /* Although the chip knows the direction to use
227 * if the source and destination areas overlap,
228 * that logic fails if we fiddle with the bitmap
229 * addresses. Therefore, we check if the source
230 * and destination blitting areas overlap and
231 * adapt the bitmap addresses synchronously
232 * if the coordinates exceed the valid range.
233 * The the areas do not overlap, we do our
236 if((mymax - mymin) < height) {
237 if((src_y >= 2048) || (dst_y >= 2048)) {
238 srcbase = ivideo->video_linelength * mymin;
239 dstbase = ivideo->video_linelength * mymin;
245 srcbase = ivideo->video_linelength * src_y;
249 dstbase = ivideo->video_linelength * dst_y;
254 srcbase += ivideo->video_offset;
255 dstbase += ivideo->video_offset;
257 SiS310SetupSRCBase(srcbase);
258 SiS310SetupDSTBase(dstbase);
259 SiS310SetupRect(width, height)
260 SiS310SetupSRCXY(src_x, src_y)
261 SiS310SetupDSTXY(dst_x, dst_y)
266 SiS310SetupForSolidFill(struct sis_video_info *ivideo, u32 color, int rop)
268 SiS310SetupPATFG(color)
269 SiS310SetupDSTRect(ivideo->video_linelength, 0x0fff)
270 SiS310SetupDSTColorDepth(ivideo->DstColor);
271 SiS310SetupROP(sisPatALUConv[rop])
272 SiS310SetupCMDFlag(PATFG | ivideo->SiS310_AccelDepth)
276 SiS310SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w, int h)
281 dstbase = ivideo->video_linelength * y;
284 dstbase += ivideo->video_offset;
285 SiS310SetupDSTBase(dstbase)
286 SiS310SetupDSTXY(x,y)
288 SiS310SetupCMDFlag(BITBLT)
293 /* --------------------------------------------------------------------- */
295 /* The exported routines */
297 int sisfb_initaccel(struct sis_video_info *ivideo)
299 #ifdef SISFB_USE_SPINLOCKS
300 spin_lock_init(&ivideo->lockaccel);
305 void sisfb_syncaccel(struct sis_video_info *ivideo)
307 if(ivideo->sisvga_engine == SIS_300_VGA) {
308 #ifdef CONFIG_FB_SIS_300
312 #ifdef CONFIG_FB_SIS_315
318 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) /* --------------- 2.5 --------------- */
320 int fbcon_sis_sync(struct fb_info *info)
322 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
325 if((!ivideo->accel) || (!ivideo->engineok))
329 sisfb_syncaccel(ivideo);
335 void fbcon_sis_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
337 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
339 u32 vxres = info->var.xres_virtual;
340 u32 vyres = info->var.yres_virtual;
344 if(info->state != FBINFO_STATE_RUNNING)
347 if((!ivideo->accel) || (!ivideo->engineok)) {
348 cfb_fillrect(info, rect);
352 if(!rect->width || !rect->height || rect->dx >= vxres || rect->dy >= vyres)
356 width = ((rect->dx + rect->width) > vxres) ? (vxres - rect->dx) : rect->width;
357 height = ((rect->dy + rect->height) > vyres) ? (vyres - rect->dy) : rect->height;
359 switch(info->var.bits_per_pixel) {
360 case 8: col = rect->color;
363 case 32: col = ((u32 *)(info->pseudo_palette))[rect->color];
367 if(ivideo->sisvga_engine == SIS_300_VGA) {
368 #ifdef CONFIG_FB_SIS_300
370 SiS300SetupForSolidFill(ivideo, col, myrops[rect->rop]);
371 SiS300SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height);
375 #ifdef CONFIG_FB_SIS_315
377 SiS310SetupForSolidFill(ivideo, col, myrops[rect->rop]);
378 SiS310SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height);
383 sisfb_syncaccel(ivideo);
386 void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area)
388 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
389 u32 vxres = info->var.xres_virtual;
390 u32 vyres = info->var.yres_virtual;
391 int width = area->width;
392 int height = area->height;
395 if(info->state != FBINFO_STATE_RUNNING)
398 if((!ivideo->accel) || (!ivideo->engineok)) {
399 cfb_copyarea(info, area);
403 if(!width || !height ||
404 area->sx >= vxres || area->sy >= vyres ||
405 area->dx >= vxres || area->dy >= vyres)
409 if((area->sx + width) > vxres) width = vxres - area->sx;
410 if((area->dx + width) > vxres) width = vxres - area->dx;
411 if((area->sy + height) > vyres) height = vyres - area->sy;
412 if((area->dy + height) > vyres) height = vyres - area->dy;
414 if(ivideo->sisvga_engine == SIS_300_VGA) {
415 #ifdef CONFIG_FB_SIS_300
418 if(area->sx < area->dx) xdir = 0;
420 if(area->sy < area->dy) ydir = 0;
424 SiS300SetupForScreenToScreenCopy(ivideo, xdir, ydir, 3, -1);
425 SiS300SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy,
426 area->dx, area->dy, width, height);
430 #ifdef CONFIG_FB_SIS_315
432 SiS310SetupForScreenToScreenCopy(ivideo, 3, -1);
433 SiS310SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy,
434 area->dx, area->dy, width, height);
439 sisfb_syncaccel(ivideo);
444 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* -------------- 2.4 --------------- */
446 #include "sisfb_accel_2_4.h"
448 #endif /* KERNEL VERSION */