2 * SiS 300/630/730/540/315/550/650/651/M650/661FX/M661FX/740/741/330/760
3 * frame buffer driver for Linux kernels >=2.4.14 and >=2.6.3
5 * Copyright (C) 2001-2004 Thomas Winischhofer, Vienna, Austria.
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
25 #include <linux/config.h>
26 #include <linux/version.h>
29 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
30 #include <video/sisfb.h>
32 #include <linux/sisfb.h>
42 #undef SIS_CONFIG_COMPAT
44 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
45 #include <linux/spinlock.h>
47 #include <linux/ioctl32.h>
48 #define SIS_CONFIG_COMPAT
50 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19)
52 /* Shouldn't we check for CONFIG_IA32_EMULATION here? */
53 #include <asm/ioctl32.h>
54 #define SIS_CONFIG_COMPAT
61 #define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
62 #define TWDEBUG(x) printk(KERN_INFO x "\n");
64 #define DPRINTK(fmt, args...)
68 #define SISFAIL(x) do { printk(x "\n"); return -EINVAL; } while(0)
70 /* To be included in pci_ids.h */
71 #ifndef PCI_DEVICE_ID_SI_650_VGA
72 #define PCI_DEVICE_ID_SI_650_VGA 0x6325
74 #ifndef PCI_DEVICE_ID_SI_650
75 #define PCI_DEVICE_ID_SI_650 0x0650
77 #ifndef PCI_DEVICE_ID_SI_651
78 #define PCI_DEVICE_ID_SI_651 0x0651
80 #ifndef PCI_DEVICE_ID_SI_740
81 #define PCI_DEVICE_ID_SI_740 0x0740
83 #ifndef PCI_DEVICE_ID_SI_330
84 #define PCI_DEVICE_ID_SI_330 0x0330
86 #ifndef PCI_DEVICE_ID_SI_660_VGA
87 #define PCI_DEVICE_ID_SI_660_VGA 0x6330
89 #ifndef PCI_DEVICE_ID_SI_661
90 #define PCI_DEVICE_ID_SI_661 0x0661
92 #ifndef PCI_DEVICE_ID_SI_741
93 #define PCI_DEVICE_ID_SI_741 0x0741
95 #ifndef PCI_DEVICE_ID_SI_660
96 #define PCI_DEVICE_ID_SI_660 0x0660
98 #ifndef PCI_DEVICE_ID_SI_760
99 #define PCI_DEVICE_ID_SI_760 0x0760
102 /* To be included in fb.h */
103 #ifndef FB_ACCEL_SIS_GLAMOUR_2
104 #define FB_ACCEL_SIS_GLAMOUR_2 40 /* SiS 315, 65x, 740, 661, 741 */
106 #ifndef FB_ACCEL_SIS_XABRE
107 #define FB_ACCEL_SIS_XABRE 41 /* SiS 330 ("Xabre"), 760 */
110 #define MAX_ROM_SCAN 0x10000
113 #define HW_CURSOR_CAP 0x80
114 #define TURBO_QUEUE_CAP 0x40
115 #define AGP_CMD_QUEUE_CAP 0x20
116 #define VM_CMD_QUEUE_CAP 0x10
117 #define MMIO_CMD_QUEUE_CAP 0x08
120 #define TURBO_QUEUE_AREA_SIZE 0x80000 /* 512K */
121 #define HW_CURSOR_AREA_SIZE_300 0x1000 /* 4K */
123 /* For 315/Xabre series */
124 #define COMMAND_QUEUE_AREA_SIZE 0x80000 /* 512K */
125 #define COMMAND_QUEUE_THRESHOLD 0x1F
126 #define HW_CURSOR_AREA_SIZE_315 0x4000 /* 16K */
128 #define SIS_OH_ALLOC_SIZE 4000
129 #define SENTINEL 0x7fffffff
132 #define SEQ_DATA 0x15
134 #define DAC_DATA 0x19
135 #define CRTC_ADR 0x24
136 #define CRTC_DATA 0x25
137 #define DAC2_ADR (0x16-0x30)
138 #define DAC2_DATA (0x17-0x30)
139 #define VB_PART1_ADR (0x04-0x30)
140 #define VB_PART1_DATA (0x05-0x30)
141 #define VB_PART2_ADR (0x10-0x30)
142 #define VB_PART2_DATA (0x11-0x30)
143 #define VB_PART3_ADR (0x12-0x30)
144 #define VB_PART3_DATA (0x13-0x30)
145 #define VB_PART4_ADR (0x14-0x30)
146 #define VB_PART4_DATA (0x15-0x30)
148 #define SISSR ivideo->SiS_Pr.SiS_P3c4
149 #define SISCR ivideo->SiS_Pr.SiS_P3d4
150 #define SISDACA ivideo->SiS_Pr.SiS_P3c8
151 #define SISDACD ivideo->SiS_Pr.SiS_P3c9
152 #define SISPART1 ivideo->SiS_Pr.SiS_Part1Port
153 #define SISPART2 ivideo->SiS_Pr.SiS_Part2Port
154 #define SISPART3 ivideo->SiS_Pr.SiS_Part3Port
155 #define SISPART4 ivideo->SiS_Pr.SiS_Part4Port
156 #define SISPART5 ivideo->SiS_Pr.SiS_Part5Port
157 #define SISDAC2A SISPART5
158 #define SISDAC2D (SISPART5 + 1)
159 #define SISMISCR (ivideo->SiS_Pr.RelIO + 0x1c)
160 #define SISMISCW ivideo->SiS_Pr.SiS_P3c2
161 #define SISINPSTAT (ivideo->SiS_Pr.RelIO + 0x2a)
162 #define SISPEL ivideo->SiS_Pr.SiS_P3c6
164 #define IND_SIS_PASSWORD 0x05 /* SRs */
165 #define IND_SIS_COLOR_MODE 0x06
166 #define IND_SIS_RAMDAC_CONTROL 0x07
167 #define IND_SIS_DRAM_SIZE 0x14
168 #define IND_SIS_MODULE_ENABLE 0x1E
169 #define IND_SIS_PCI_ADDRESS_SET 0x20
170 #define IND_SIS_TURBOQUEUE_ADR 0x26
171 #define IND_SIS_TURBOQUEUE_SET 0x27
172 #define IND_SIS_POWER_ON_TRAP 0x38
173 #define IND_SIS_POWER_ON_TRAP2 0x39
174 #define IND_SIS_CMDQUEUE_SET 0x26
175 #define IND_SIS_CMDQUEUE_THRESHOLD 0x27
177 #define IND_SIS_AGP_IO_PAD 0x48
179 #define SIS_CRT2_WENABLE_300 0x24 /* Part1 */
180 #define SIS_CRT2_WENABLE_315 0x2F
182 #define SIS_PASSWORD 0x86 /* SR05 */
183 #define SIS_INTERLACED_MODE 0x20 /* SR06 */
184 #define SIS_8BPP_COLOR_MODE 0x0
185 #define SIS_15BPP_COLOR_MODE 0x1
186 #define SIS_16BPP_COLOR_MODE 0x2
187 #define SIS_32BPP_COLOR_MODE 0x4
189 #define SIS_ENABLE_2D 0x40 /* SR1E */
191 #define SIS_MEM_MAP_IO_ENABLE 0x01 /* SR20 */
192 #define SIS_PCI_ADDR_ENABLE 0x80
194 #define SIS_AGP_CMDQUEUE_ENABLE 0x80 /* 315/330 series SR26 */
195 #define SIS_VRAM_CMDQUEUE_ENABLE 0x40
196 #define SIS_MMIO_CMD_ENABLE 0x20
197 #define SIS_CMD_QUEUE_SIZE_512k 0x00
198 #define SIS_CMD_QUEUE_SIZE_1M 0x04
199 #define SIS_CMD_QUEUE_SIZE_2M 0x08
200 #define SIS_CMD_QUEUE_SIZE_4M 0x0C
201 #define SIS_CMD_QUEUE_RESET 0x01
202 #define SIS_CMD_AUTO_CORR 0x02
204 #define SIS_SIMULTANEOUS_VIEW_ENABLE 0x01 /* CR30 */
205 #define SIS_MODE_SELECT_CRT2 0x02
206 #define SIS_VB_OUTPUT_COMPOSITE 0x04
207 #define SIS_VB_OUTPUT_SVIDEO 0x08
208 #define SIS_VB_OUTPUT_SCART 0x10
209 #define SIS_VB_OUTPUT_LCD 0x20
210 #define SIS_VB_OUTPUT_CRT2 0x40
211 #define SIS_VB_OUTPUT_HIVISION 0x80
213 #define SIS_VB_OUTPUT_DISABLE 0x20 /* CR31 */
214 #define SIS_DRIVER_MODE 0x40
216 #define SIS_VB_COMPOSITE 0x01 /* CR32 */
217 #define SIS_VB_SVIDEO 0x02
218 #define SIS_VB_SCART 0x04
219 #define SIS_VB_LCD 0x08
220 #define SIS_VB_CRT2 0x10
221 #define SIS_CRT1 0x20
222 #define SIS_VB_HIVISION 0x40
223 #define SIS_VB_YPBPR 0x80
224 #define SIS_VB_TV (SIS_VB_COMPOSITE | SIS_VB_SVIDEO | \
225 SIS_VB_SCART | SIS_VB_HIVISION | SIS_VB_YPBPR)
227 #define SIS_EXTERNAL_CHIP_MASK 0x0E /* CR37 (< SiS 660) */
228 #define SIS_EXTERNAL_CHIP_SIS301 0x01 /* in CR37 << 1 ! */
229 #define SIS_EXTERNAL_CHIP_LVDS 0x02
230 #define SIS_EXTERNAL_CHIP_TRUMPION 0x03
231 #define SIS_EXTERNAL_CHIP_LVDS_CHRONTEL 0x04
232 #define SIS_EXTERNAL_CHIP_CHRONTEL 0x05
233 #define SIS310_EXTERNAL_CHIP_LVDS 0x02
234 #define SIS310_EXTERNAL_CHIP_LVDS_CHRONTEL 0x03
236 #define SIS_AGP_2X 0x20 /* CR48 */
238 #define HW_DEVICE_EXTENSION SIS_HW_INFO
239 #define PHW_DEVICE_EXTENSION PSIS_HW_INFO
242 #define inSISREG(base) inb(base)
243 #define outSISREG(base,val) outb(val,base)
244 #define orSISREG(base,val) do { \
245 u8 __Temp = inb(base); \
246 outSISREG(base, __Temp | (val)); \
248 #define andSISREG(base,val) do { \
249 u8 __Temp = inb(base); \
250 outSISREG(base, __Temp & (val)); \
252 #define inSISIDXREG(base,idx,var) do { \
253 outb(idx,base); var=inb((base)+1); \
255 #define outSISIDXREG(base,idx,val) do { \
256 outb(idx,base); outb((val),(base)+1); \
258 #define orSISIDXREG(base,idx,val) do { \
261 __Temp = inb((base)+1)|(val); \
262 outSISIDXREG(base,idx,__Temp); \
264 #define andSISIDXREG(base,idx,and) do { \
267 __Temp = inb((base)+1)&(and); \
268 outSISIDXREG(base,idx,__Temp); \
270 #define setSISIDXREG(base,idx,and,or) do { \
273 __Temp = (inb((base)+1)&(and))|(or); \
274 outSISIDXREG(base,idx,__Temp); \
277 /* MMIO access macros */
278 #define MMIO_IN8(base, offset) readb((base+offset))
279 #define MMIO_IN16(base, offset) readw((base+offset))
280 #define MMIO_IN32(base, offset) readl((base+offset))
282 #define MMIO_OUT8(base, offset, val) writeb(((u8)(val)), (base+offset))
283 #define MMIO_OUT16(base, offset, val) writew(((u16)(val)), (base+offset))
284 #define MMIO_OUT32(base, offset, val) writel(((u32)(val)), (base+offset))
286 /* Queue control MMIO registers */
287 #define Q_BASE_ADDR 0x85C0 /* Base address of software queue */
288 #define Q_WRITE_PTR 0x85C4 /* Current write pointer */
289 #define Q_READ_PTR 0x85C8 /* Current read pointer */
290 #define Q_STATUS 0x85CC /* queue status */
292 #define MMIO_QUEUE_PHYBASE Q_BASE_ADDR
293 #define MMIO_QUEUE_WRITEPORT Q_WRITE_PTR
294 #define MMIO_QUEUE_READPORT Q_READ_PTR
301 typedef unsigned int SIS_CMDTYPE
;
304 struct sis_video_info
{
306 struct fb_info
*memyselfandi
;
308 SIS_HW_INFO sishw_ext
;
311 sisfb_info sisfbinfo
; /* For ioctl SISFB_GET_INFO */
313 struct fb_var_screeninfo default_var
;
315 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
316 struct fb_fix_screeninfo sisfb_fix
;
317 u32 pseudo_palette
[17];
320 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
321 struct display sis_disp
;
322 struct display_switch sisfb_sw
;
324 u16 red
, green
, blue
, pad
;
327 #ifdef FBCON_HAS_CFB16
330 #ifdef FBCON_HAS_CFB32
336 struct sisfb_monitor
{
349 struct pci_dev
*nbridge
;
351 int mni
; /* Mode number index */
353 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
357 unsigned long video_size
;
358 unsigned long video_base
;
359 unsigned long mmio_size
;
360 unsigned long mmio_base
;
361 unsigned long vga_base
;
363 void __iomem
* video_vbase
;
364 void __iomem
* mmio_vbase
;
365 void __iomem
* bios_vbase
;
389 int sisfb_nocrt2rate
;
390 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
394 u32 heapstart
; /* offset */
395 void __iomem
* sisfb_heap_start
; /* address */
396 void __iomem
* sisfb_heap_end
; /* address */
408 unsigned int refresh_rate
;
413 int video_linelength
; /* real pitch */
414 int scrnpitchCRT1
; /* pitch regarding interlace */
416 u16 DstColor
; /* For 2d acceleration */
417 u32 SiS310_AccelDepth
;
421 spinlock_t lockaccel
; /* Do not use outside of kernel! */
424 unsigned int pcislot
;
425 unsigned int pcifunc
;
432 u32 vbflags
; /* Replacing deprecated stuff from above */
435 int lcdxres
, lcdyres
;
436 int lcddefmodeidx
, tvdefmodeidx
, defmodeidx
;
443 int current_linelength
;
444 __u32 current_pixclock
;
445 int current_refresh_rate
;
450 unsigned char modeprechange
;
452 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
453 u8 sisfb_lastrates
[128];
458 #ifdef SIS_CONFIG_COMPAT
459 int ioctl32registered
;
460 int ioctl32vblankregistered
;
465 int CRT2_write_enable
;
472 void __iomem
* hwcursor_vbase
;
476 u8 p2_1f
,p2_20
,p2_2b
,p2_42
,p2_43
,p2_01
,p2_02
;
481 struct sis_video_info
*next
;
484 typedef struct _SIS_OH
{
485 struct _SIS_OH
*poh_next
;
486 struct _SIS_OH
*poh_prev
;
491 typedef struct _SIS_OHALLOC
{
492 struct _SIS_OHALLOC
*poha_next
;
496 typedef struct _SIS_HEAP
{
499 SIS_OH
*poh_freelist
;
500 SIS_OHALLOC
*poha_chain
;
502 struct sis_video_info
*vinfo
;