initextlfb.c 7.0 KB

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