Thomas Winischhofer | 544393f | 2005-09-09 13:04:45 -0700 | [diff] [blame] | 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 | |
Thomas Winischhofer | 544393f | 2005-09-09 13:04:45 -0700 | [diff] [blame] | 33 | #include <linux/version.h> |
| 34 | #include <linux/types.h> |
| 35 | #include <linux/fb.h> |
| 36 | |
Thomas Winischhofer | 544393f | 2005-09-09 13:04:45 -0700 | [diff] [blame] | 37 | int sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr, |
| 38 | unsigned char modeno, unsigned char rateindex); |
| 39 | int sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno, |
| 40 | unsigned char rateindex, struct fb_var_screeninfo *var); |
Richard Knutsson | c30660e | 2007-02-12 00:55:06 -0800 | [diff] [blame] | 41 | bool sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, |
Thomas Winischhofer | 544393f | 2005-09-09 13:04:45 -0700 | [diff] [blame] | 42 | int *htotal, int *vtotal, unsigned char rateindex); |
| 43 | |
Richard Knutsson | c30660e | 2007-02-12 00:55:06 -0800 | [diff] [blame] | 44 | extern bool SiSInitPtr(struct SiS_Private *SiS_Pr); |
| 45 | extern bool SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo, |
Thomas Winischhofer | 544393f | 2005-09-09 13:04:45 -0700 | [diff] [blame] | 46 | unsigned short *ModeIdIndex); |
| 47 | extern void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata, |
Richard Knutsson | c30660e | 2007-02-12 00:55:06 -0800 | [diff] [blame] | 48 | int xres, int yres, struct fb_var_screeninfo *var, bool writeres); |
Thomas Winischhofer | 544393f | 2005-09-09 13:04:45 -0700 | [diff] [blame] | 49 | |
Thomas Winischhofer | 544393f | 2005-09-09 13:04:45 -0700 | [diff] [blame] | 50 | int |
| 51 | sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr, unsigned char modeno, |
| 52 | unsigned char rateindex) |
| 53 | { |
| 54 | unsigned short ModeNo = modeno; |
| 55 | unsigned short ModeIdIndex = 0, ClockIndex = 0; |
| 56 | unsigned short RRTI = 0; |
| 57 | int Clock; |
| 58 | |
| 59 | if(!SiSInitPtr(SiS_Pr)) return 65000; |
| 60 | |
| 61 | if(rateindex > 0) rateindex--; |
| 62 | |
| 63 | #ifdef SIS315H |
| 64 | switch(ModeNo) { |
| 65 | case 0x5a: ModeNo = 0x50; break; |
| 66 | case 0x5b: ModeNo = 0x56; |
| 67 | } |
| 68 | #endif |
| 69 | |
| 70 | if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) {; |
| 71 | printk(KERN_ERR "Could not find mode %x\n", ModeNo); |
| 72 | return 65000; |
| 73 | } |
| 74 | |
| 75 | RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex; |
| 76 | |
| 77 | if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & HaveWideTiming) { |
| 78 | if(SiS_Pr->SiS_UseWide == 1) { |
| 79 | /* Wide screen: Ignore rateindex */ |
| 80 | ClockIndex = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRTVCLK_WIDE; |
| 81 | } else { |
| 82 | RRTI += rateindex; |
| 83 | ClockIndex = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRTVCLK_NORM; |
| 84 | } |
| 85 | } else { |
| 86 | RRTI += rateindex; |
| 87 | ClockIndex = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRTVCLK; |
| 88 | } |
| 89 | |
| 90 | Clock = SiS_Pr->SiS_VCLKData[ClockIndex].CLOCK * 1000; |
| 91 | |
| 92 | return Clock; |
| 93 | } |
| 94 | |
| 95 | int |
| 96 | sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno, |
| 97 | unsigned char rateindex, struct fb_var_screeninfo *var) |
| 98 | { |
| 99 | unsigned short ModeNo = modeno; |
| 100 | unsigned short ModeIdIndex = 0, index = 0, RRTI = 0; |
| 101 | int j; |
| 102 | |
| 103 | if(!SiSInitPtr(SiS_Pr)) return 0; |
| 104 | |
| 105 | if(rateindex > 0) rateindex--; |
| 106 | |
| 107 | #ifdef SIS315H |
| 108 | switch(ModeNo) { |
| 109 | case 0x5a: ModeNo = 0x50; break; |
| 110 | case 0x5b: ModeNo = 0x56; |
| 111 | } |
| 112 | #endif |
| 113 | |
| 114 | if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return 0; |
| 115 | |
| 116 | RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex; |
| 117 | if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & HaveWideTiming) { |
| 118 | if(SiS_Pr->SiS_UseWide == 1) { |
| 119 | /* Wide screen: Ignore rateindex */ |
| 120 | index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC_WIDE; |
| 121 | } else { |
| 122 | RRTI += rateindex; |
| 123 | index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC_NORM; |
| 124 | } |
| 125 | } else { |
| 126 | RRTI += rateindex; |
| 127 | index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC; |
| 128 | } |
| 129 | |
| 130 | SiS_Generic_ConvertCRData(SiS_Pr, |
| 131 | (unsigned char *)&SiS_Pr->SiS_CRT1Table[index].CR[0], |
| 132 | SiS_Pr->SiS_RefIndex[RRTI].XRes, |
| 133 | SiS_Pr->SiS_RefIndex[RRTI].YRes, |
Richard Knutsson | c30660e | 2007-02-12 00:55:06 -0800 | [diff] [blame] | 134 | var, false); |
Thomas Winischhofer | 544393f | 2005-09-09 13:04:45 -0700 | [diff] [blame] | 135 | |
| 136 | if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & 0x8000) |
| 137 | var->sync &= ~FB_SYNC_VERT_HIGH_ACT; |
| 138 | else |
| 139 | var->sync |= FB_SYNC_VERT_HIGH_ACT; |
| 140 | |
| 141 | if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & 0x4000) |
| 142 | var->sync &= ~FB_SYNC_HOR_HIGH_ACT; |
| 143 | else |
| 144 | var->sync |= FB_SYNC_HOR_HIGH_ACT; |
| 145 | |
| 146 | var->vmode = FB_VMODE_NONINTERLACED; |
| 147 | if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & 0x0080) |
| 148 | var->vmode = FB_VMODE_INTERLACED; |
| 149 | else { |
| 150 | j = 0; |
| 151 | while(SiS_Pr->SiS_EModeIDTable[j].Ext_ModeID != 0xff) { |
| 152 | if(SiS_Pr->SiS_EModeIDTable[j].Ext_ModeID == |
| 153 | SiS_Pr->SiS_RefIndex[RRTI].ModeID) { |
| 154 | if(SiS_Pr->SiS_EModeIDTable[j].Ext_ModeFlag & DoubleScanMode) { |
| 155 | var->vmode = FB_VMODE_DOUBLE; |
| 156 | } |
| 157 | break; |
| 158 | } |
| 159 | j++; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) { |
| 164 | #if 0 /* Do this? */ |
| 165 | var->upper_margin <<= 1; |
| 166 | var->lower_margin <<= 1; |
| 167 | var->vsync_len <<= 1; |
| 168 | #endif |
| 169 | } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) { |
| 170 | var->upper_margin >>= 1; |
| 171 | var->lower_margin >>= 1; |
| 172 | var->vsync_len >>= 1; |
| 173 | } |
| 174 | |
| 175 | return 1; |
| 176 | } |
Thomas Winischhofer | 544393f | 2005-09-09 13:04:45 -0700 | [diff] [blame] | 177 | |
Richard Knutsson | c30660e | 2007-02-12 00:55:06 -0800 | [diff] [blame] | 178 | bool |
Thomas Winischhofer | 544393f | 2005-09-09 13:04:45 -0700 | [diff] [blame] | 179 | sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, int *htotal, |
| 180 | int *vtotal, unsigned char rateindex) |
| 181 | { |
| 182 | unsigned short ModeNo = modeno; |
| 183 | unsigned short ModeIdIndex = 0, CRT1Index = 0; |
| 184 | unsigned short RRTI = 0; |
| 185 | unsigned char sr_data, cr_data, cr_data2; |
| 186 | |
Richard Knutsson | c30660e | 2007-02-12 00:55:06 -0800 | [diff] [blame] | 187 | if(!SiSInitPtr(SiS_Pr)) return false; |
Thomas Winischhofer | 544393f | 2005-09-09 13:04:45 -0700 | [diff] [blame] | 188 | |
| 189 | if(rateindex > 0) rateindex--; |
| 190 | |
| 191 | #ifdef SIS315H |
| 192 | switch(ModeNo) { |
| 193 | case 0x5a: ModeNo = 0x50; break; |
| 194 | case 0x5b: ModeNo = 0x56; |
| 195 | } |
| 196 | #endif |
| 197 | |
Richard Knutsson | c30660e | 2007-02-12 00:55:06 -0800 | [diff] [blame] | 198 | if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return false; |
Thomas Winischhofer | 544393f | 2005-09-09 13:04:45 -0700 | [diff] [blame] | 199 | |
| 200 | RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex; |
| 201 | if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & HaveWideTiming) { |
| 202 | if(SiS_Pr->SiS_UseWide == 1) { |
| 203 | /* Wide screen: Ignore rateindex */ |
| 204 | CRT1Index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC_WIDE; |
| 205 | } else { |
| 206 | RRTI += rateindex; |
| 207 | CRT1Index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC_NORM; |
| 208 | } |
| 209 | } else { |
| 210 | RRTI += rateindex; |
| 211 | CRT1Index = SiS_Pr->SiS_RefIndex[RRTI].Ext_CRT1CRTC; |
| 212 | } |
| 213 | |
| 214 | sr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14]; |
| 215 | cr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[0]; |
| 216 | *htotal = (((cr_data & 0xff) | ((unsigned short) (sr_data & 0x03) << 8)) + 5) * 8; |
| 217 | |
| 218 | sr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13]; |
| 219 | cr_data = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[6]; |
| 220 | cr_data2 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7]; |
| 221 | *vtotal = ((cr_data & 0xFF) | |
| 222 | ((unsigned short)(cr_data2 & 0x01) << 8) | |
| 223 | ((unsigned short)(cr_data2 & 0x20) << 4) | |
| 224 | ((unsigned short)(sr_data & 0x01) << 10)) + 2; |
| 225 | |
| 226 | if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & InterlaceMode) |
| 227 | *vtotal *= 2; |
| 228 | |
Richard Knutsson | c30660e | 2007-02-12 00:55:06 -0800 | [diff] [blame] | 229 | return true; |
Thomas Winischhofer | 544393f | 2005-09-09 13:04:45 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | |
| 233 | |