[PATCH] Add initalization of the RDTSCP auxilliary values
[linux-2.6/verdex.git] / drivers / video / sis / initextlfb.c
blob09f5d758b6c02b79d3aab802698664c949f9de0d
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
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>
28 #include "osdef.h"
29 #include "initdef.h"
30 #include "vgatypes.h"
31 #include "vstruct.h"
33 #include <linux/version.h>
34 #include <linux/types.h>
35 #include <linux/fb.h>
37 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
38 int sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr,
39 unsigned char modeno, unsigned char rateindex);
40 int sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno,
41 unsigned char rateindex, struct fb_var_screeninfo *var);
42 #endif
43 BOOLEAN sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno,
44 int *htotal, int *vtotal, unsigned char rateindex);
46 extern BOOLEAN SiSInitPtr(struct SiS_Private *SiS_Pr);
47 extern BOOLEAN SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
48 unsigned short *ModeIdIndex);
49 extern void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata,
50 int xres, int yres, struct fb_var_screeninfo *var, BOOLEAN writeres);
52 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
53 int
54 sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr, unsigned char modeno,
55 unsigned char rateindex)
57 unsigned short ModeNo = modeno;
58 unsigned short ModeIdIndex = 0, ClockIndex = 0;
59 unsigned short RRTI = 0;
60 int Clock;
62 if(!SiSInitPtr(SiS_Pr)) return 65000;
64 if(rateindex > 0) rateindex--;
66 #ifdef SIS315H
67 switch(ModeNo) {
68 case 0x5a: ModeNo = 0x50; break;
69 case 0x5b: ModeNo = 0x56;
71 #endif
73 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) {;
74 printk(KERN_ERR "Could not find mode %x\n", ModeNo);
75 return 65000;
78 RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
80 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & HaveWideTiming) {
81 if(SiS_Pr->SiS_UseWide == 1) {
82 /* Wide screen: Ignore rateindex */
83 ClockIndex = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRTVCLK_WIDE;
84 } else {
85 RRTI += rateindex;
86 ClockIndex = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRTVCLK_NORM;
88 } else {
89 RRTI += rateindex;
90 ClockIndex = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRTVCLK;
93 Clock = SiS_Pr->SiS_VCLKData[ClockIndex].CLOCK * 1000;
95 return Clock;
98 int
99 sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno,
100 unsigned char rateindex, struct fb_var_screeninfo *var)
102 unsigned short ModeNo = modeno;
103 unsigned short ModeIdIndex = 0, index = 0, RRTI = 0;
104 int j;
106 if(!SiSInitPtr(SiS_Pr)) return 0;
108 if(rateindex > 0) rateindex--;
110 #ifdef SIS315H
111 switch(ModeNo) {
112 case 0x5a: ModeNo = 0x50; break;
113 case 0x5b: ModeNo = 0x56;
115 #endif
117 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return 0;
119 RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
120 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & HaveWideTiming) {
121 if(SiS_Pr->SiS_UseWide == 1) {
122 /* Wide screen: Ignore rateindex */
123 index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC_WIDE;
124 } else {
125 RRTI += rateindex;
126 index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC_NORM;
128 } else {
129 RRTI += rateindex;
130 index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC;
133 SiS_Generic_ConvertCRData(SiS_Pr,
134 (unsigned char *)&SiS_Pr->SiS_CRT1Table[index].CR[0],
135 SiS_Pr->SiS_RefIndex[RRTI].XRes,
136 SiS_Pr->SiS_RefIndex[RRTI].YRes,
137 var, FALSE);
139 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & 0x8000)
140 var->sync &= ~FB_SYNC_VERT_HIGH_ACT;
141 else
142 var->sync |= FB_SYNC_VERT_HIGH_ACT;
144 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & 0x4000)
145 var->sync &= ~FB_SYNC_HOR_HIGH_ACT;
146 else
147 var->sync |= FB_SYNC_HOR_HIGH_ACT;
149 var->vmode = FB_VMODE_NONINTERLACED;
150 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & 0x0080)
151 var->vmode = FB_VMODE_INTERLACED;
152 else {
153 j = 0;
154 while(SiS_Pr->SiS_EModeIDTable[j].Ext_ModeID != 0xff) {
155 if(SiS_Pr->SiS_EModeIDTable[j].Ext_ModeID ==
156 SiS_Pr->SiS_RefIndex[RRTI].ModeID) {
157 if(SiS_Pr->SiS_EModeIDTable[j].Ext_ModeFlag & DoubleScanMode) {
158 var->vmode = FB_VMODE_DOUBLE;
160 break;
162 j++;
166 if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
167 #if 0 /* Do this? */
168 var->upper_margin <<= 1;
169 var->lower_margin <<= 1;
170 var->vsync_len <<= 1;
171 #endif
172 } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {
173 var->upper_margin >>= 1;
174 var->lower_margin >>= 1;
175 var->vsync_len >>= 1;
178 return 1;
180 #endif /* Linux >= 2.5 */
182 BOOLEAN
183 sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, int *htotal,
184 int *vtotal, unsigned char rateindex)
186 unsigned short ModeNo = modeno;
187 unsigned short ModeIdIndex = 0, CRT1Index = 0;
188 unsigned short RRTI = 0;
189 unsigned char sr_data, cr_data, cr_data2;
191 if(!SiSInitPtr(SiS_Pr)) return FALSE;
193 if(rateindex > 0) rateindex--;
195 #ifdef SIS315H
196 switch(ModeNo) {
197 case 0x5a: ModeNo = 0x50; break;
198 case 0x5b: ModeNo = 0x56;
200 #endif
202 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return FALSE;
204 RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
205 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & HaveWideTiming) {
206 if(SiS_Pr->SiS_UseWide == 1) {
207 /* Wide screen: Ignore rateindex */
208 CRT1Index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC_WIDE;
209 } else {
210 RRTI += rateindex;
211 CRT1Index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC_NORM;
213 } else {
214 RRTI += rateindex;
215 CRT1Index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC;
218 sr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14];
219 cr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[0];
220 *htotal = (((cr_data & 0xff) | ((unsigned short) (sr_data & 0x03) << 8)) + 5) * 8;
222 sr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13];
223 cr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[6];
224 cr_data2 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7];
225 *vtotal = ((cr_data & 0xFF) |
226 ((unsigned short)(cr_data2 & 0x01) << 8) |
227 ((unsigned short)(cr_data2 & 0x20) << 4) |
228 ((unsigned short)(sr_data & 0x01) << 10)) + 2;
230 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & InterlaceMode)
231 *vtotal *= 2;
233 return TRUE;