initextlfb.c 7.0 KB

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