initextlfb.c 7.1 KB

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