initextlfb.c 7.2 KB

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