via_utility.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
  3. * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License as published by the Free Software Foundation;
  7. * either version 2, or (at your option) any later version.
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
  10. * the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. * A PARTICULAR PURPOSE.See the GNU General Public License
  12. * for more details.
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc.,
  16. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include <linux/via-core.h>
  19. #include "global.h"
  20. void viafb_get_device_support_state(u32 *support_state)
  21. {
  22. *support_state = CRT_Device;
  23. if (viaparinfo->chip_info->tmds_chip_info.tmds_chip_name == VT1632_TMDS)
  24. *support_state |= DVI_Device;
  25. if (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name == VT1631_LVDS)
  26. *support_state |= LCD_Device;
  27. }
  28. void viafb_get_device_connect_state(u32 *connect_state)
  29. {
  30. bool mobile = false;
  31. *connect_state = CRT_Device;
  32. if (viafb_dvi_sense())
  33. *connect_state |= DVI_Device;
  34. viafb_lcd_get_mobile_state(&mobile);
  35. if (mobile)
  36. *connect_state |= LCD_Device;
  37. }
  38. bool viafb_lcd_get_support_expand_state(u32 xres, u32 yres)
  39. {
  40. unsigned int support_state = 0;
  41. switch (viafb_lcd_panel_id) {
  42. case LCD_PANEL_ID0_640X480:
  43. if ((xres < 640) && (yres < 480))
  44. support_state = true;
  45. break;
  46. case LCD_PANEL_ID1_800X600:
  47. if ((xres < 800) && (yres < 600))
  48. support_state = true;
  49. break;
  50. case LCD_PANEL_ID2_1024X768:
  51. if ((xres < 1024) && (yres < 768))
  52. support_state = true;
  53. break;
  54. case LCD_PANEL_ID3_1280X768:
  55. if ((xres < 1280) && (yres < 768))
  56. support_state = true;
  57. break;
  58. case LCD_PANEL_ID4_1280X1024:
  59. if ((xres < 1280) && (yres < 1024))
  60. support_state = true;
  61. break;
  62. case LCD_PANEL_ID5_1400X1050:
  63. if ((xres < 1400) && (yres < 1050))
  64. support_state = true;
  65. break;
  66. case LCD_PANEL_ID6_1600X1200:
  67. if ((xres < 1600) && (yres < 1200))
  68. support_state = true;
  69. break;
  70. case LCD_PANEL_ID7_1366X768:
  71. if ((xres < 1366) && (yres < 768))
  72. support_state = true;
  73. break;
  74. case LCD_PANEL_ID8_1024X600:
  75. if ((xres < 1024) && (yres < 600))
  76. support_state = true;
  77. break;
  78. case LCD_PANEL_ID9_1280X800:
  79. if ((xres < 1280) && (yres < 800))
  80. support_state = true;
  81. break;
  82. case LCD_PANEL_IDA_800X480:
  83. if ((xres < 800) && (yres < 480))
  84. support_state = true;
  85. break;
  86. case LCD_PANEL_IDB_1360X768:
  87. if ((xres < 1360) && (yres < 768))
  88. support_state = true;
  89. break;
  90. case LCD_PANEL_IDC_480X640:
  91. if ((xres < 480) && (yres < 640))
  92. support_state = true;
  93. break;
  94. default:
  95. support_state = false;
  96. break;
  97. }
  98. return support_state;
  99. }
  100. /*====================================================================*/
  101. /* Gamma Function Implementation*/
  102. /*====================================================================*/
  103. void viafb_set_gamma_table(int bpp, unsigned int *gamma_table)
  104. {
  105. int i, sr1a;
  106. int active_device_amount = 0;
  107. int device_status = viafb_DeviceStatus;
  108. for (i = 0; i < sizeof(viafb_DeviceStatus) * 8; i++) {
  109. if (device_status & 1)
  110. active_device_amount++;
  111. device_status >>= 1;
  112. }
  113. /* 8 bpp mode can't adjust gamma */
  114. if (bpp == 8)
  115. return ;
  116. /* Enable Gamma */
  117. switch (viaparinfo->chip_info->gfx_chip_name) {
  118. case UNICHROME_CLE266:
  119. case UNICHROME_K400:
  120. viafb_write_reg_mask(SR16, VIASR, 0x80, BIT7);
  121. break;
  122. case UNICHROME_K800:
  123. case UNICHROME_PM800:
  124. case UNICHROME_CN700:
  125. case UNICHROME_CX700:
  126. case UNICHROME_K8M890:
  127. case UNICHROME_P4M890:
  128. case UNICHROME_P4M900:
  129. viafb_write_reg_mask(CR33, VIACR, 0x80, BIT7);
  130. break;
  131. }
  132. sr1a = (unsigned int)viafb_read_reg(VIASR, SR1A);
  133. viafb_write_reg_mask(SR1A, VIASR, 0x0, BIT0);
  134. /* Fill IGA1 Gamma Table */
  135. outb(0, LUT_INDEX_WRITE);
  136. for (i = 0; i < 256; i++) {
  137. outb(gamma_table[i] >> 16, LUT_DATA);
  138. outb(gamma_table[i] >> 8 & 0xFF, LUT_DATA);
  139. outb(gamma_table[i] & 0xFF, LUT_DATA);
  140. }
  141. /* If adjust Gamma value in SAMM, fill IGA1,
  142. IGA2 Gamma table simultaneous. */
  143. /* Switch to IGA2 Gamma Table */
  144. if ((active_device_amount > 1) &&
  145. !((viaparinfo->chip_info->gfx_chip_name ==
  146. UNICHROME_CLE266) &&
  147. (viaparinfo->chip_info->gfx_chip_revision < 15))) {
  148. viafb_write_reg_mask(SR1A, VIASR, 0x01, BIT0);
  149. viafb_write_reg_mask(CR6A, VIACR, 0x02, BIT1);
  150. /* Fill IGA2 Gamma Table */
  151. outb(0, LUT_INDEX_WRITE);
  152. for (i = 0; i < 256; i++) {
  153. outb(gamma_table[i] >> 16, LUT_DATA);
  154. outb(gamma_table[i] >> 8 & 0xFF, LUT_DATA);
  155. outb(gamma_table[i] & 0xFF, LUT_DATA);
  156. }
  157. }
  158. viafb_write_reg(SR1A, VIASR, sr1a);
  159. }
  160. void viafb_get_gamma_table(unsigned int *gamma_table)
  161. {
  162. unsigned char color_r, color_g, color_b;
  163. unsigned char sr1a = 0;
  164. int i;
  165. /* Enable Gamma */
  166. switch (viaparinfo->chip_info->gfx_chip_name) {
  167. case UNICHROME_CLE266:
  168. case UNICHROME_K400:
  169. viafb_write_reg_mask(SR16, VIASR, 0x80, BIT7);
  170. break;
  171. case UNICHROME_K800:
  172. case UNICHROME_PM800:
  173. case UNICHROME_CN700:
  174. case UNICHROME_CX700:
  175. case UNICHROME_K8M890:
  176. case UNICHROME_P4M890:
  177. case UNICHROME_P4M900:
  178. viafb_write_reg_mask(CR33, VIACR, 0x80, BIT7);
  179. break;
  180. }
  181. sr1a = viafb_read_reg(VIASR, SR1A);
  182. viafb_write_reg_mask(SR1A, VIASR, 0x0, BIT0);
  183. /* Reading gamma table to get color value */
  184. outb(0, LUT_INDEX_READ);
  185. for (i = 0; i < 256; i++) {
  186. color_r = inb(LUT_DATA);
  187. color_g = inb(LUT_DATA);
  188. color_b = inb(LUT_DATA);
  189. gamma_table[i] =
  190. ((((u32) color_r) << 16) |
  191. (((u16) color_g) << 8)) | color_b;
  192. }
  193. viafb_write_reg(SR1A, VIASR, sr1a);
  194. }
  195. void viafb_get_gamma_support_state(int bpp, unsigned int *support_state)
  196. {
  197. if (bpp == 8)
  198. *support_state = None_Device;
  199. else
  200. *support_state = CRT_Device | DVI_Device | LCD_Device;
  201. }