diff options
Diffstat (limited to 'drivers/video/sis/initextlfb.c')
-rw-r--r-- | drivers/video/sis/initextlfb.c | 238 |
1 files changed, 238 insertions, 0 deletions
diff --git a/drivers/video/sis/initextlfb.c b/drivers/video/sis/initextlfb.c new file mode 100644 index 000000000000..cc856d90903c --- /dev/null +++ b/drivers/video/sis/initextlfb.c | |||
@@ -0,0 +1,238 @@ | |||
1 | /* | ||
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] | ||
4 | * XGI V3XT/V5/V8, Z7 | ||
5 | * frame buffer driver for Linux kernels >= 2.4.14 and >=2.6.3 | ||
6 | * | ||
7 | * Linux kernel specific extensions to init.c/init301.c | ||
8 | * | ||
9 | * Copyright (C) 2001-2005 Thomas Winischhofer, Vienna, Austria. | ||
10 | * | ||
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. | ||
15 | * | ||
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. | ||
20 | * | ||
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 | ||
24 | * | ||
25 | * Author: Thomas Winischhofer <thomas@winischhofer.net> | ||
26 | */ | ||
27 | |||
28 | #include "osdef.h" | ||
29 | #include "initdef.h" | ||
30 | #include "vgatypes.h" | ||
31 | #include "vstruct.h" | ||
32 | |||
33 | #include <linux/config.h> | ||
34 | #include <linux/version.h> | ||
35 | #include <linux/types.h> | ||
36 | #include <linux/fb.h> | ||
37 | |||
38 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) | ||
39 | int sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr, | ||
40 | unsigned char modeno, unsigned char rateindex); | ||
41 | int sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno, | ||
42 | unsigned char rateindex, struct fb_var_screeninfo *var); | ||
43 | #endif | ||
44 | BOOLEAN sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, | ||
45 | int *htotal, int *vtotal, unsigned char rateindex); | ||
46 | |||
47 | extern BOOLEAN SiSInitPtr(struct SiS_Private *SiS_Pr); | ||
48 | extern BOOLEAN SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo, | ||
49 | unsigned short *ModeIdIndex); | ||
50 | extern void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata, | ||
51 | int xres, int yres, struct fb_var_screeninfo *var, BOOLEAN writeres); | ||
52 | |||
53 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) | ||
54 | int | ||
55 | sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr, unsigned char modeno, | ||
56 | unsigned char rateindex) | ||
57 | { | ||
58 | unsigned short ModeNo = modeno; | ||
59 | unsigned short ModeIdIndex = 0, ClockIndex = 0; | ||
60 | unsigned short RRTI = 0; | ||
61 | int Clock; | ||
62 | |||
63 | if(!SiSInitPtr(SiS_Pr)) return 65000; | ||
64 | |||
65 | if(rateindex > 0) rateindex--; | ||
66 | |||
67 | #ifdef SIS315H | ||
68 | switch(ModeNo) { | ||
69 | case 0x5a: ModeNo = 0x50; break; | ||
70 | case 0x5b: ModeNo = 0x56; | ||
71 | } | ||
72 | #endif | ||
73 | |||
74 | if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) {; | ||
75 | printk(KERN_ERR "Could not find mode %x\n", ModeNo); | ||
76 | return 65000; | ||
77 | } | ||
78 | |||
79 | RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex; | ||
80 | |||
81 | if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & HaveWideTiming) { | ||
82 | if(SiS_Pr->SiS_UseWide == 1) { | ||
83 | /* Wide screen: Ignore rateindex */ | ||
84 | ClockIndex = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRTVCLK_WIDE; | ||
85 | } else { | ||
86 | RRTI += rateindex; | ||
87 | ClockIndex = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRTVCLK_NORM; | ||
88 | } | ||
89 | } else { | ||
90 | RRTI += rateindex; | ||
91 | ClockIndex = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRTVCLK; | ||
92 | } | ||
93 | |||
94 | Clock = SiS_Pr->SiS_VCLKData[ClockIndex].CLOCK * 1000; | ||
95 | |||
96 | return Clock; | ||
97 | } | ||
98 | |||
99 | int | ||
100 | sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno, | ||
101 | unsigned char rateindex, struct fb_var_screeninfo *var) | ||
102 | { | ||
103 | unsigned short ModeNo = modeno; | ||
104 | unsigned short ModeIdIndex = 0, index = 0, RRTI = 0; | ||
105 | int j; | ||
106 | |||
107 | if(!SiSInitPtr(SiS_Pr)) return 0; | ||
108 | |||
109 | if(rateindex > 0) rateindex--; | ||
110 | |||
111 | #ifdef SIS315H | ||
112 | switch(ModeNo) { | ||
113 | case 0x5a: ModeNo = 0x50; break; | ||
114 | case 0x5b: ModeNo = 0x56; | ||
115 | } | ||
116 | #endif | ||
117 | |||
118 | if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return 0; | ||
119 | |||
120 | RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex; | ||
121 | if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & HaveWideTiming) { | ||
122 | if(SiS_Pr->SiS_UseWide == 1) { | ||
123 | /* Wide screen: Ignore rateindex */ | ||
124 | index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC_WIDE; | ||
125 | } else { | ||
126 | RRTI += rateindex; | ||
127 | index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC_NORM; | ||
128 | } | ||
129 | } else { | ||
130 | RRTI += rateindex; | ||
131 | index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC; | ||
132 | } | ||
133 | |||
134 | SiS_Generic_ConvertCRData(SiS_Pr, | ||
135 | (unsigned char *)&SiS_Pr->SiS_CRT1Table[index].CR[0], | ||
136 | SiS_Pr->SiS_RefIndex[RRTI].XRes, | ||
137 | SiS_Pr->SiS_RefIndex[RRTI].YRes, | ||
138 | var, FALSE); | ||
139 | |||
140 | if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & 0x8000) | ||
141 | var->sync &= ~FB_SYNC_VERT_HIGH_ACT; | ||
142 | else | ||
143 | var->sync |= FB_SYNC_VERT_HIGH_ACT; | ||
144 | |||
145 | if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & 0x4000) | ||
146 | var->sync &= ~FB_SYNC_HOR_HIGH_ACT; | ||
147 | else | ||
148 | var->sync |= FB_SYNC_HOR_HIGH_ACT; | ||
149 | |||
150 | var->vmode = FB_VMODE_NONINTERLACED; | ||
151 | if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & 0x0080) | ||
152 | var->vmode = FB_VMODE_INTERLACED; | ||
153 | else { | ||
154 | j = 0; | ||
155 | while(SiS_Pr->SiS_EModeIDTable[j].Ext_ModeID != 0xff) { | ||
156 | if(SiS_Pr->SiS_EModeIDTable[j].Ext_ModeID == | ||
157 | SiS_Pr->SiS_RefIndex[RRTI].ModeID) { | ||
158 | if(SiS_Pr->SiS_EModeIDTable[j].Ext_ModeFlag & DoubleScanMode) { | ||
159 | var->vmode = FB_VMODE_DOUBLE; | ||
160 | } | ||
161 | break; | ||
162 | } | ||
163 | j++; | ||
164 | } | ||
165 | } | ||
166 | |||
167 | if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) { | ||
168 | #if 0 /* Do this? */ | ||
169 | var->upper_margin <<= 1; | ||
170 | var->lower_margin <<= 1; | ||
171 | var->vsync_len <<= 1; | ||
172 | #endif | ||
173 | } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) { | ||
174 | var->upper_margin >>= 1; | ||
175 | var->lower_margin >>= 1; | ||
176 | var->vsync_len >>= 1; | ||
177 | } | ||
178 | |||
179 | return 1; | ||
180 | } | ||
181 | #endif /* Linux >= 2.5 */ | ||
182 | |||
183 | BOOLEAN | ||
184 | sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, int *htotal, | ||
185 | int *vtotal, unsigned char rateindex) | ||
186 | { | ||
187 | unsigned short ModeNo = modeno; | ||
188 | unsigned short ModeIdIndex = 0, CRT1Index = 0; | ||
189 | unsigned short RRTI = 0; | ||
190 | unsigned char sr_data, cr_data, cr_data2; | ||
191 | |||
192 | if(!SiSInitPtr(SiS_Pr)) return FALSE; | ||
193 | |||
194 | if(rateindex > 0) rateindex--; | ||
195 | |||
196 | #ifdef SIS315H | ||
197 | switch(ModeNo) { | ||
198 | case 0x5a: ModeNo = 0x50; break; | ||
199 | case 0x5b: ModeNo = 0x56; | ||
200 | } | ||
201 | #endif | ||
202 | |||
203 | if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return FALSE; | ||
204 | |||
205 | RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex; | ||
206 | if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & HaveWideTiming) { | ||
207 | if(SiS_Pr->SiS_UseWide == 1) { | ||
208 | /* Wide screen: Ignore rateindex */ | ||
209 | CRT1Index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC_WIDE; | ||
210 | } else { | ||
211 | RRTI += rateindex; | ||
212 | CRT1Index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC_NORM; | ||
213 | } | ||
214 | } else { | ||
215 | RRTI += rateindex; | ||
216 | CRT1Index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC; | ||
217 | } | ||
218 | |||
219 | sr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14]; | ||
220 | cr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[0]; | ||
221 | *htotal = (((cr_data & 0xff) | ((unsigned short) (sr_data & 0x03) << 8)) + 5) * 8; | ||
222 | |||
223 | sr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13]; | ||
224 | cr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[6]; | ||
225 | cr_data2 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7]; | ||
226 | *vtotal = ((cr_data & 0xFF) | | ||
227 | ((unsigned short)(cr_data2 & 0x01) << 8) | | ||
228 | ((unsigned short)(cr_data2 & 0x20) << 4) | | ||
229 | ((unsigned short)(sr_data & 0x01) << 10)) + 2; | ||
230 | |||
231 | if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & InterlaceMode) | ||
232 | *vtotal *= 2; | ||
233 | |||
234 | return TRUE; | ||
235 | } | ||
236 | |||
237 | |||
238 | |||