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 #include <linux/ioport.h>
36 #include <linux/types.h>
40 #include "sis_accel.h"
42 static const u8 sisALUConv[] =
44 0x00, /* dest = 0; 0, GXclear, 0 */
45 0x88, /* dest &= src; DSa, GXand, 0x1 */
46 0x44, /* dest = src & ~dest; SDna, GXandReverse, 0x2 */
47 0xCC, /* dest = src; S, GXcopy, 0x3 */
48 0x22, /* dest &= ~src; DSna, GXandInverted, 0x4 */
49 0xAA, /* dest = dest; D, GXnoop, 0x5 */
50 0x66, /* dest = ^src; DSx, GXxor, 0x6 */
51 0xEE, /* dest |= src; DSo, GXor, 0x7 */
52 0x11, /* dest = ~src & ~dest; DSon, GXnor, 0x8 */
53 0x99, /* dest ^= ~src ; DSxn, GXequiv, 0x9 */
54 0x55, /* dest = ~dest; Dn, GXInvert, 0xA */
55 0xDD, /* dest = src|~dest ; SDno, GXorReverse, 0xB */
56 0x33, /* dest = ~src; Sn, GXcopyInverted, 0xC */
57 0xBB, /* dest |= ~src; DSno, GXorInverted, 0xD */
58 0x77, /* dest = ~src|~dest; DSan, GXnand, 0xE */
59 0xFF, /* dest = 0xFF; 1, GXset, 0xF */
61 /* same ROP but with Pattern as Source */
62 static const u8 sisPatALUConv[] =
64 0x00, /* dest = 0; 0, GXclear, 0 */
65 0xA0, /* dest &= src; DPa, GXand, 0x1 */
66 0x50, /* dest = src & ~dest; PDna, GXandReverse, 0x2 */
67 0xF0, /* dest = src; P, GXcopy, 0x3 */
68 0x0A, /* dest &= ~src; DPna, GXandInverted, 0x4 */
69 0xAA, /* dest = dest; D, GXnoop, 0x5 */
70 0x5A, /* dest = ^src; DPx, GXxor, 0x6 */
71 0xFA, /* dest |= src; DPo, GXor, 0x7 */
72 0x05, /* dest = ~src & ~dest; DPon, GXnor, 0x8 */
73 0xA5, /* dest ^= ~src ; DPxn, GXequiv, 0x9 */
74 0x55, /* dest = ~dest; Dn, GXInvert, 0xA */
75 0xF5, /* dest = src|~dest ; PDno, GXorReverse, 0xB */
76 0x0F, /* dest = ~src; Pn, GXcopyInverted, 0xC */
77 0xAF, /* dest |= ~src; DPno, GXorInverted, 0xD */
78 0x5F, /* dest = ~src|~dest; DPan, GXnand, 0xE */
79 0xFF, /* dest = 0xFF; 1, GXset, 0xF */
82 static const int myrops[] = {
83 3, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
86 /* 300 series ----------------------------------------------------- */
87 #ifdef CONFIG_FB_SIS_300
89 SiS300Sync(struct sis_video_info *ivideo)
95 SiS300SetupForScreenToScreenCopy(struct sis_video_info *ivideo, int xdir, int ydir,
96 int rop, int trans_color)
98 SiS300SetupDSTColorDepth(ivideo->DstColor);
99 SiS300SetupSRCPitch(ivideo->video_linelength)
100 SiS300SetupDSTRect(ivideo->video_linelength, 0xffff)
102 if(trans_color != -1) {
104 SiS300SetupSRCTrans(trans_color)
105 SiS300SetupCMDFlag(TRANSPARENT_BITBLT)
107 SiS300SetupROP(sisALUConv[rop])
110 SiS300SetupCMDFlag(X_INC)
113 SiS300SetupCMDFlag(Y_INC)
118 SiS300SubsequentScreenToScreenCopy(struct sis_video_info *ivideo, int src_x,
119 int src_y, int dst_x, int dst_y, int width, int height)
121 u32 srcbase = 0, dstbase = 0;
124 srcbase = ivideo->video_linelength * src_y;
128 dstbase = ivideo->video_linelength * dst_y;
132 SiS300SetupSRCBase(srcbase);
133 SiS300SetupDSTBase(dstbase);
135 if(!(ivideo->CommandReg & X_INC)) {
139 if(!(ivideo->CommandReg & Y_INC)) {
143 SiS300SetupRect(width, height)
144 SiS300SetupSRCXY(src_x, src_y)
145 SiS300SetupDSTXY(dst_x, dst_y)
150 SiS300SetupForSolidFill(struct sis_video_info *ivideo, u32 color, int rop)
152 SiS300SetupPATFG(color)
153 SiS300SetupDSTRect(ivideo->video_linelength, 0xffff)
154 SiS300SetupDSTColorDepth(ivideo->DstColor);
155 SiS300SetupROP(sisPatALUConv[rop])
156 SiS300SetupCMDFlag(PATFG)
160 SiS300SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w, int h)
165 dstbase = ivideo->video_linelength * y;
168 SiS300SetupDSTBase(dstbase)
169 SiS300SetupDSTXY(x,y)
171 SiS300SetupCMDFlag(X_INC | Y_INC | BITBLT)
176 /* 315/330/340 series ---------------------------------------------- */
178 #ifdef CONFIG_FB_SIS_315
180 SiS310Sync(struct sis_video_info *ivideo)
186 SiS310SetupForScreenToScreenCopy(struct sis_video_info *ivideo, int rop, int trans_color)
188 SiS310SetupDSTColorDepth(ivideo->DstColor);
189 SiS310SetupSRCPitch(ivideo->video_linelength)
190 SiS310SetupDSTRect(ivideo->video_linelength, 0x0fff)
191 if(trans_color != -1) {
193 SiS310SetupSRCTrans(trans_color)
194 SiS310SetupCMDFlag(TRANSPARENT_BITBLT)
196 SiS310SetupROP(sisALUConv[rop])
197 /* Set command - not needed, both 0 */
198 /* SiSSetupCMDFlag(BITBLT | SRCVIDEO) */
200 SiS310SetupCMDFlag(ivideo->SiS310_AccelDepth)
201 /* The chip is smart enough to know the direction */
205 SiS310SubsequentScreenToScreenCopy(struct sis_video_info *ivideo, int src_x, int src_y,
206 int dst_x, int dst_y, int width, int height)
208 u32 srcbase = 0, dstbase = 0;
209 int mymin = min(src_y, dst_y);
210 int mymax = max(src_y, dst_y);
212 /* Although the chip knows the direction to use
213 * if the source and destination areas overlap,
214 * that logic fails if we fiddle with the bitmap
215 * addresses. Therefore, we check if the source
216 * and destination blitting areas overlap and
217 * adapt the bitmap addresses synchronously
218 * if the coordinates exceed the valid range.
219 * The the areas do not overlap, we do our
222 if((mymax - mymin) < height) {
223 if((src_y >= 2048) || (dst_y >= 2048)) {
224 srcbase = ivideo->video_linelength * mymin;
225 dstbase = ivideo->video_linelength * mymin;
231 srcbase = ivideo->video_linelength * src_y;
235 dstbase = ivideo->video_linelength * dst_y;
240 srcbase += ivideo->video_offset;
241 dstbase += ivideo->video_offset;
243 SiS310SetupSRCBase(srcbase);
244 SiS310SetupDSTBase(dstbase);
245 SiS310SetupRect(width, height)
246 SiS310SetupSRCXY(src_x, src_y)
247 SiS310SetupDSTXY(dst_x, dst_y)
252 SiS310SetupForSolidFill(struct sis_video_info *ivideo, u32 color, int rop)
254 SiS310SetupPATFG(color)
255 SiS310SetupDSTRect(ivideo->video_linelength, 0x0fff)
256 SiS310SetupDSTColorDepth(ivideo->DstColor);
257 SiS310SetupROP(sisPatALUConv[rop])
258 SiS310SetupCMDFlag(PATFG | ivideo->SiS310_AccelDepth)
262 SiS310SubsequentSolidFillRect(struct sis_video_info *ivideo, int x, int y, int w, int h)
267 dstbase = ivideo->video_linelength * y;
270 dstbase += ivideo->video_offset;
271 SiS310SetupDSTBase(dstbase)
272 SiS310SetupDSTXY(x,y)
274 SiS310SetupCMDFlag(BITBLT)
279 /* --------------------------------------------------------------------- */
281 /* The exported routines */
283 int sisfb_initaccel(struct sis_video_info *ivideo)
285 #ifdef SISFB_USE_SPINLOCKS
286 spin_lock_init(&ivideo->lockaccel);
291 void sisfb_syncaccel(struct sis_video_info *ivideo)
293 if(ivideo->sisvga_engine == SIS_300_VGA) {
294 #ifdef CONFIG_FB_SIS_300
298 #ifdef CONFIG_FB_SIS_315
304 int fbcon_sis_sync(struct fb_info *info)
306 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
309 if((!ivideo->accel) || (!ivideo->engineok))
313 sisfb_syncaccel(ivideo);
319 void fbcon_sis_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
321 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
323 u32 vxres = info->var.xres_virtual;
324 u32 vyres = info->var.yres_virtual;
328 if(info->state != FBINFO_STATE_RUNNING)
331 if((!ivideo->accel) || (!ivideo->engineok)) {
332 cfb_fillrect(info, rect);
336 if(!rect->width || !rect->height || rect->dx >= vxres || rect->dy >= vyres)
340 width = ((rect->dx + rect->width) > vxres) ? (vxres - rect->dx) : rect->width;
341 height = ((rect->dy + rect->height) > vyres) ? (vyres - rect->dy) : rect->height;
343 switch(info->var.bits_per_pixel) {
344 case 8: col = rect->color;
347 case 32: col = ((u32 *)(info->pseudo_palette))[rect->color];
351 if(ivideo->sisvga_engine == SIS_300_VGA) {
352 #ifdef CONFIG_FB_SIS_300
354 SiS300SetupForSolidFill(ivideo, col, myrops[rect->rop]);
355 SiS300SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height);
359 #ifdef CONFIG_FB_SIS_315
361 SiS310SetupForSolidFill(ivideo, col, myrops[rect->rop]);
362 SiS310SubsequentSolidFillRect(ivideo, rect->dx, rect->dy, width, height);
367 sisfb_syncaccel(ivideo);
370 void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area)
372 struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
373 u32 vxres = info->var.xres_virtual;
374 u32 vyres = info->var.yres_virtual;
375 int width = area->width;
376 int height = area->height;
379 if(info->state != FBINFO_STATE_RUNNING)
382 if((!ivideo->accel) || (!ivideo->engineok)) {
383 cfb_copyarea(info, area);
387 if(!width || !height ||
388 area->sx >= vxres || area->sy >= vyres ||
389 area->dx >= vxres || area->dy >= vyres)
393 if((area->sx + width) > vxres) width = vxres - area->sx;
394 if((area->dx + width) > vxres) width = vxres - area->dx;
395 if((area->sy + height) > vyres) height = vyres - area->sy;
396 if((area->dy + height) > vyres) height = vyres - area->dy;
398 if(ivideo->sisvga_engine == SIS_300_VGA) {
399 #ifdef CONFIG_FB_SIS_300
402 if(area->sx < area->dx) xdir = 0;
404 if(area->sy < area->dy) ydir = 0;
408 SiS300SetupForScreenToScreenCopy(ivideo, xdir, ydir, 3, -1);
409 SiS300SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy,
410 area->dx, area->dy, width, height);
414 #ifdef CONFIG_FB_SIS_315
416 SiS310SetupForScreenToScreenCopy(ivideo, 3, -1);
417 SiS310SubsequentScreenToScreenCopy(ivideo, area->sx, area->sy,
418 area->dx, area->dy, width, height);
423 sisfb_syncaccel(ivideo);