initextlfb.c 7.0 KB

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