1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * SiS 300/540/630[S]/730[S]
4 * SiS 315[E|PRO]/550/[M]65x/[M]66x[F|M|G]X/[M]74x[GX]/330/[M]76x[GX]
6 * frame buffer driver for Linux kernels >= 2.4.14 and >=2.6.3
8 * Linux kernel specific extensions to init.c/init301.c
10 * Copyright (C) 2001-2005 Thomas Winischhofer, Vienna, Austria.
12 * Author: Thomas Winischhofer <thomas@winischhofer.net>
19 #include <linux/types.h>
22 int sisfb_mode_rate_to_dclock(struct SiS_Private
*SiS_Pr
,
23 unsigned char modeno
, unsigned char rateindex
);
24 int sisfb_mode_rate_to_ddata(struct SiS_Private
*SiS_Pr
, unsigned char modeno
,
25 unsigned char rateindex
, struct fb_var_screeninfo
*var
);
26 bool sisfb_gettotalfrommode(struct SiS_Private
*SiS_Pr
, unsigned char modeno
,
27 int *htotal
, int *vtotal
, unsigned char rateindex
);
29 extern bool SiSInitPtr(struct SiS_Private
*SiS_Pr
);
30 extern bool SiS_SearchModeID(struct SiS_Private
*SiS_Pr
, unsigned short *ModeNo
,
31 unsigned short *ModeIdIndex
);
32 extern void SiS_Generic_ConvertCRData(struct SiS_Private
*SiS_Pr
, unsigned char *crdata
,
33 int xres
, int yres
, struct fb_var_screeninfo
*var
, bool writeres
);
36 sisfb_mode_rate_to_dclock(struct SiS_Private
*SiS_Pr
, unsigned char modeno
,
37 unsigned char rateindex
)
39 unsigned short ModeNo
= modeno
;
40 unsigned short ModeIdIndex
= 0, ClockIndex
= 0;
41 unsigned short RRTI
= 0;
44 if(!SiSInitPtr(SiS_Pr
)) return 65000;
46 if(rateindex
> 0) rateindex
--;
48 #ifdef CONFIG_FB_SIS_315
50 case 0x5a: ModeNo
= 0x50; break;
51 case 0x5b: ModeNo
= 0x56;
55 if(!(SiS_SearchModeID(SiS_Pr
, &ModeNo
, &ModeIdIndex
))) {
56 printk(KERN_ERR
"Could not find mode %x\n", ModeNo
);
60 RRTI
= SiS_Pr
->SiS_EModeIDTable
[ModeIdIndex
].REFindex
;
62 if(SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_InfoFlag
& HaveWideTiming
) {
63 if(SiS_Pr
->SiS_UseWide
== 1) {
64 /* Wide screen: Ignore rateindex */
65 ClockIndex
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRTVCLK_WIDE
;
68 ClockIndex
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRTVCLK_NORM
;
72 ClockIndex
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRTVCLK
;
75 Clock
= SiS_Pr
->SiS_VCLKData
[ClockIndex
].CLOCK
* 1000;
81 sisfb_mode_rate_to_ddata(struct SiS_Private
*SiS_Pr
, unsigned char modeno
,
82 unsigned char rateindex
, struct fb_var_screeninfo
*var
)
84 unsigned short ModeNo
= modeno
;
85 unsigned short ModeIdIndex
= 0, index
= 0, RRTI
= 0;
88 if(!SiSInitPtr(SiS_Pr
)) return 0;
90 if(rateindex
> 0) rateindex
--;
92 #ifdef CONFIG_FB_SIS_315
94 case 0x5a: ModeNo
= 0x50; break;
95 case 0x5b: ModeNo
= 0x56;
99 if(!(SiS_SearchModeID(SiS_Pr
, &ModeNo
, &ModeIdIndex
))) return 0;
101 RRTI
= SiS_Pr
->SiS_EModeIDTable
[ModeIdIndex
].REFindex
;
102 if(SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_InfoFlag
& HaveWideTiming
) {
103 if(SiS_Pr
->SiS_UseWide
== 1) {
104 /* Wide screen: Ignore rateindex */
105 index
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRT1CRTC_WIDE
;
108 index
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRT1CRTC_NORM
;
112 index
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRT1CRTC
;
115 SiS_Generic_ConvertCRData(SiS_Pr
,
116 (unsigned char *)&SiS_Pr
->SiS_CRT1Table
[index
].CR
[0],
117 SiS_Pr
->SiS_RefIndex
[RRTI
].XRes
,
118 SiS_Pr
->SiS_RefIndex
[RRTI
].YRes
,
121 if(SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_InfoFlag
& 0x8000)
122 var
->sync
&= ~FB_SYNC_VERT_HIGH_ACT
;
124 var
->sync
|= FB_SYNC_VERT_HIGH_ACT
;
126 if(SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_InfoFlag
& 0x4000)
127 var
->sync
&= ~FB_SYNC_HOR_HIGH_ACT
;
129 var
->sync
|= FB_SYNC_HOR_HIGH_ACT
;
131 var
->vmode
= FB_VMODE_NONINTERLACED
;
132 if(SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_InfoFlag
& 0x0080)
133 var
->vmode
= FB_VMODE_INTERLACED
;
136 while(SiS_Pr
->SiS_EModeIDTable
[j
].Ext_ModeID
!= 0xff) {
137 if(SiS_Pr
->SiS_EModeIDTable
[j
].Ext_ModeID
==
138 SiS_Pr
->SiS_RefIndex
[RRTI
].ModeID
) {
139 if(SiS_Pr
->SiS_EModeIDTable
[j
].Ext_ModeFlag
& DoubleScanMode
) {
140 var
->vmode
= FB_VMODE_DOUBLE
;
148 if((var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
) {
150 var
->upper_margin
<<= 1;
151 var
->lower_margin
<<= 1;
152 var
->vsync_len
<<= 1;
154 } else if((var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_DOUBLE
) {
155 var
->upper_margin
>>= 1;
156 var
->lower_margin
>>= 1;
157 var
->vsync_len
>>= 1;
164 sisfb_gettotalfrommode(struct SiS_Private
*SiS_Pr
, unsigned char modeno
, int *htotal
,
165 int *vtotal
, unsigned char rateindex
)
167 unsigned short ModeNo
= modeno
;
168 unsigned short ModeIdIndex
= 0, CRT1Index
= 0;
169 unsigned short RRTI
= 0;
170 unsigned char sr_data
, cr_data
, cr_data2
;
172 if(!SiSInitPtr(SiS_Pr
)) return false;
174 if(rateindex
> 0) rateindex
--;
176 #ifdef CONFIG_FB_SIS_315
178 case 0x5a: ModeNo
= 0x50; break;
179 case 0x5b: ModeNo
= 0x56;
183 if(!(SiS_SearchModeID(SiS_Pr
, &ModeNo
, &ModeIdIndex
))) return false;
185 RRTI
= SiS_Pr
->SiS_EModeIDTable
[ModeIdIndex
].REFindex
;
186 if(SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_InfoFlag
& HaveWideTiming
) {
187 if(SiS_Pr
->SiS_UseWide
== 1) {
188 /* Wide screen: Ignore rateindex */
189 CRT1Index
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRT1CRTC_WIDE
;
192 CRT1Index
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRT1CRTC_NORM
;
196 CRT1Index
= SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_CRT1CRTC
;
199 sr_data
= SiS_Pr
->SiS_CRT1Table
[CRT1Index
].CR
[14];
200 cr_data
= SiS_Pr
->SiS_CRT1Table
[CRT1Index
].CR
[0];
201 *htotal
= (((cr_data
& 0xff) | ((unsigned short) (sr_data
& 0x03) << 8)) + 5) * 8;
203 sr_data
= SiS_Pr
->SiS_CRT1Table
[CRT1Index
].CR
[13];
204 cr_data
= SiS_Pr
->SiS_CRT1Table
[CRT1Index
].CR
[6];
205 cr_data2
= SiS_Pr
->SiS_CRT1Table
[CRT1Index
].CR
[7];
206 *vtotal
= ((cr_data
& 0xFF) |
207 ((unsigned short)(cr_data2
& 0x01) << 8) |
208 ((unsigned short)(cr_data2
& 0x20) << 4) |
209 ((unsigned short)(sr_data
& 0x01) << 10)) + 2;
211 if(SiS_Pr
->SiS_RefIndex
[RRTI
].Ext_InfoFlag
& InterlaceMode
)