2 * SiS 300/540/630[S]/730[S]
3 * SiS 315[E|PRO]/550/[M]65x/[M]66x[F|M|G]X/[M]74x[GX]/330/[M]76x[GX]
5 * frame buffer driver for Linux kernels >= 2.4.14 and >=2.6.3
7 * Linux kernel specific extensions to init.c/init301.c
9 * Copyright (C) 2001-2005 Thomas Winischhofer, Vienna, Austria.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the named License,
14 * or any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
25 * Author: Thomas Winischhofer <thomas@winischhofer.net>
32 #include <linux/types.h>
35 int sisfb_mode_rate_to_dclock(struct SiS_Private
*SiS_Pr
,
36 unsigned char modeno
, unsigned char rateindex
);
37 int sisfb_mode_rate_to_ddata(struct SiS_Private
*SiS_Pr
, unsigned char modeno
,
38 unsigned char rateindex
, struct fb_var_screeninfo
*var
);
39 bool sisfb_gettotalfrommode(struct SiS_Private
*SiS_Pr
, unsigned char modeno
,
40 int *htotal
, int *vtotal
, unsigned char rateindex
);
42 extern bool SiSInitPtr(struct SiS_Private
*SiS_Pr
);
43 extern bool SiS_SearchModeID(struct SiS_Private
*SiS_Pr
, unsigned short *ModeNo
,
44 unsigned short *ModeIdIndex
);
45 extern void SiS_Generic_ConvertCRData(struct SiS_Private
*SiS_Pr
, unsigned char *crdata
,
46 int xres
, int yres
, struct fb_var_screeninfo
*var
, bool writeres
);
49 sisfb_mode_rate_to_dclock(struct SiS_Private
*SiS_Pr
, unsigned char modeno
,
50 unsigned char rateindex
)
52 unsigned short ModeNo
= modeno
;
53 unsigned short ModeIdIndex
= 0, ClockIndex
= 0;
54 unsigned short RRTI
= 0;
57 if(!SiSInitPtr(SiS_Pr
)) return 65000;
59 if(rateindex
> 0) rateindex
--;
61 #ifdef CONFIG_FB_SIS_315
63 case 0x5a: ModeNo
= 0x50; break;
64 case 0x5b: ModeNo
= 0x56;
68 if(!(SiS_SearchModeID(SiS_Pr
, &ModeNo
, &ModeIdIndex
))) {;
69 printk(KERN_ERR
"Could not find mode %x\n", ModeNo
);
73 RRTI
= SiS_Pr
->SiS_EModeIDTable
[ModeIdIndex
].REFindex
;
75 if(SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_InfoFlag
& HaveWideTiming
) {
76 if(SiS_Pr
->SiS_UseWide
== 1) {
77 /* Wide screen: Ignore rateindex */
78 ClockIndex
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRTVCLK_WIDE
;
81 ClockIndex
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRTVCLK_NORM
;
85 ClockIndex
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRTVCLK
;
88 Clock
= SiS_Pr
->SiS_VCLKData
[ClockIndex
].CLOCK
* 1000;
94 sisfb_mode_rate_to_ddata(struct SiS_Private
*SiS_Pr
, unsigned char modeno
,
95 unsigned char rateindex
, struct fb_var_screeninfo
*var
)
97 unsigned short ModeNo
= modeno
;
98 unsigned short ModeIdIndex
= 0, index
= 0, RRTI
= 0;
101 if(!SiSInitPtr(SiS_Pr
)) return 0;
103 if(rateindex
> 0) rateindex
--;
105 #ifdef CONFIG_FB_SIS_315
107 case 0x5a: ModeNo
= 0x50; break;
108 case 0x5b: ModeNo
= 0x56;
112 if(!(SiS_SearchModeID(SiS_Pr
, &ModeNo
, &ModeIdIndex
))) return 0;
114 RRTI
= SiS_Pr
->SiS_EModeIDTable
[ModeIdIndex
].REFindex
;
115 if(SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_InfoFlag
& HaveWideTiming
) {
116 if(SiS_Pr
->SiS_UseWide
== 1) {
117 /* Wide screen: Ignore rateindex */
118 index
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRT1CRTC_WIDE
;
121 index
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRT1CRTC_NORM
;
125 index
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRT1CRTC
;
128 SiS_Generic_ConvertCRData(SiS_Pr
,
129 (unsigned char *)&SiS_Pr
->SiS_CRT1Table
[index
].CR
[0],
130 SiS_Pr
->SiS_RefIndex
[RRTI
].XRes
,
131 SiS_Pr
->SiS_RefIndex
[RRTI
].YRes
,
134 if(SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_InfoFlag
& 0x8000)
135 var
->sync
&= ~FB_SYNC_VERT_HIGH_ACT
;
137 var
->sync
|= FB_SYNC_VERT_HIGH_ACT
;
139 if(SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_InfoFlag
& 0x4000)
140 var
->sync
&= ~FB_SYNC_HOR_HIGH_ACT
;
142 var
->sync
|= FB_SYNC_HOR_HIGH_ACT
;
144 var
->vmode
= FB_VMODE_NONINTERLACED
;
145 if(SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_InfoFlag
& 0x0080)
146 var
->vmode
= FB_VMODE_INTERLACED
;
149 while(SiS_Pr
->SiS_EModeIDTable
[j
].Ext_ModeID
!= 0xff) {
150 if(SiS_Pr
->SiS_EModeIDTable
[j
].Ext_ModeID
==
151 SiS_Pr
->SiS_RefIndex
[RRTI
].ModeID
) {
152 if(SiS_Pr
->SiS_EModeIDTable
[j
].Ext_ModeFlag
& DoubleScanMode
) {
153 var
->vmode
= FB_VMODE_DOUBLE
;
161 if((var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
) {
163 var
->upper_margin
<<= 1;
164 var
->lower_margin
<<= 1;
165 var
->vsync_len
<<= 1;
167 } else if((var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_DOUBLE
) {
168 var
->upper_margin
>>= 1;
169 var
->lower_margin
>>= 1;
170 var
->vsync_len
>>= 1;
177 sisfb_gettotalfrommode(struct SiS_Private
*SiS_Pr
, unsigned char modeno
, int *htotal
,
178 int *vtotal
, unsigned char rateindex
)
180 unsigned short ModeNo
= modeno
;
181 unsigned short ModeIdIndex
= 0, CRT1Index
= 0;
182 unsigned short RRTI
= 0;
183 unsigned char sr_data
, cr_data
, cr_data2
;
185 if(!SiSInitPtr(SiS_Pr
)) return false;
187 if(rateindex
> 0) rateindex
--;
189 #ifdef CONFIG_FB_SIS_315
191 case 0x5a: ModeNo
= 0x50; break;
192 case 0x5b: ModeNo
= 0x56;
196 if(!(SiS_SearchModeID(SiS_Pr
, &ModeNo
, &ModeIdIndex
))) return false;
198 RRTI
= SiS_Pr
->SiS_EModeIDTable
[ModeIdIndex
].REFindex
;
199 if(SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_InfoFlag
& HaveWideTiming
) {
200 if(SiS_Pr
->SiS_UseWide
== 1) {
201 /* Wide screen: Ignore rateindex */
202 CRT1Index
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRT1CRTC_WIDE
;
205 CRT1Index
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRT1CRTC_NORM
;
209 CRT1Index
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRT1CRTC
;
212 sr_data
= SiS_Pr
->SiS_CRT1Table
[CRT1Index
].CR
[14];
213 cr_data
= SiS_Pr
->SiS_CRT1Table
[CRT1Index
].CR
[0];
214 *htotal
= (((cr_data
& 0xff) | ((unsigned short) (sr_data
& 0x03) << 8)) + 5) * 8;
216 sr_data
= SiS_Pr
->SiS_CRT1Table
[CRT1Index
].CR
[13];
217 cr_data
= SiS_Pr
->SiS_CRT1Table
[CRT1Index
].CR
[6];
218 cr_data2
= SiS_Pr
->SiS_CRT1Table
[CRT1Index
].CR
[7];
219 *vtotal
= ((cr_data
& 0xFF) |
220 ((unsigned short)(cr_data2
& 0x01) << 8) |
221 ((unsigned short)(cr_data2
& 0x20) << 4) |
222 ((unsigned short)(sr_data
& 0x01) << 10)) + 2;
224 if(SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_InfoFlag
& InterlaceMode
)