via_utility.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 "global.h"
  19. void viafb_get_device_support_state(u32 *support_state)
  20. {
  21. *support_state = CRT_Device;
  22. if (viaparinfo->chip_info->tmds_chip_info.tmds_chip_name == VT1632_TMDS)
  23. *support_state |= DVI_Device;
  24. if (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name == VT1631_LVDS)
  25. *support_state |= LCD_Device;
  26. }
  27. void viafb_get_device_connect_state(u32 *connect_state)
  28. {
  29. bool mobile = false;
  30. *connect_state = CRT_Device;
  31. if (viafb_dvi_sense())
  32. *connect_state |= DVI_Device;
  33. viafb_lcd_get_mobile_state(&mobile);
  34. if (mobile)
  35. *connect_state |= LCD_Device;
  36. }
  37. bool viafb_lcd_get_support_expand_state(u32 xres, u32 yres)
  38. {
  39. unsigned int support_state = 0;
  40. switch (viafb_lcd_panel_id) {
  41. case LCD_PANEL_ID0_640X480:
  42. if ((xres < 640) && (yres < 480))
  43. support_state = true;
  44. break;
  45. case LCD_PANEL_ID1_800X600:
  46. if ((xres < 800) && (yres < 600))
  47. support_state = true;
  48. break;
  49. case LCD_PANEL_ID2_1024X768:
  50. if ((xres < 1024) && (yres < 768))
  51. support_state = true;
  52. break;
  53. case LCD_PANEL_ID3_1280X768:
  54. if ((xres < 1280) && (yres < 768))
  55. support_state = true;
  56. break;
  57. case LCD_PANEL_ID4_1280X1024:
  58. if ((xres < 1280) && (yres < 1024))
  59. support_state = true;
  60. break;
  61. case LCD_PANEL_ID5_1400X1050:
  62. if ((xres < 1400) && (yres < 1050))
  63. support_state = true;
  64. break;
  65. case LCD_PANEL_ID6_1600X1200:
  66. if ((xres < 1600) && (yres < 1200))
  67. support_state = true;
  68. break;
  69. case LCD_PANEL_ID7_1366X768:
  70. if ((xres < 1366) && (yres < 768))
  71. support_state = true;
  72. break;
  73. case LCD_PANEL_ID8_1024X600:
  74. if ((xres < 1024) && (yres < 600))
  75. support_state = true;
  76. break;
  77. case LCD_PANEL_ID9_1280X800:
  78. if ((xres < 1280) && (yres < 800))
  79. support_state = true;
  80. break;
  81. case LCD_PANEL_IDA_800X480:
  82. if ((xres < 800) && (yres < 480))
  83. support_state = true;
  84. break;
  85. case LCD_PANEL_IDB_1360X768:
  86. if ((xres < 1360) && (yres < 768))
  87. support_state = true;
  88. break;
  89. case LCD_PANEL_IDC_480X640:
  90. if ((xres < 480) && (yres < 640))
  91. support_state = true;
  92. break;
  93. default:
  94. support_state = false;
  95. break;
  96. }
  97. return support_state;
  98. }
  99. /*====================================================================*/
  100. /* Gamma Function Implementation*/
  101. /*====================================================================*/
  102. void viafb_set_gamma_table(int bpp, unsigned int *gamma_table)
  103. {
  104. int i, sr1a;
  105. int active_device_amount = 0;
  106. int device_status = viafb_DeviceStatus;
  107. for (i = 0; i < sizeof(viafb_DeviceStatus) * 8; i++) {
  108. if (device_status & 1)
  109. active_device_amount++;
  110. device_status >>= 1;
  111. }
  112. /* 8 bpp mode can't adjust gamma */
  113. if (bpp == 8)
  114. return ;
  115. /* Enable Gamma */
  116. switch (viaparinfo->chip_info->gfx_chip_name) {
  117. case UNICHROME_CLE266:
  118. case UNICHROME_K400:
  119. viafb_write_reg_mask(SR16, VIASR, 0x80, BIT7);
  120. break;
  121. case UNICHROME_K800:
  122. case UNICHROME_PM800:
  123. case UNICHROME_CN700:
  124. case UNICHROME_CX700:
  125. case UNICHROME_K8M890:
  126. case UNICHROME_P4M890:
  127. case UNICHROME_P4M900:
  128. viafb_write_reg_mask(CR33, VIACR, 0x80, BIT7);
  129. break;
  130. }
  131. sr1a = (unsigned int)viafb_read_reg(VIASR, SR1A);
  132. viafb_write_reg_mask(SR1A, VIASR, 0x0, BIT0);
  133. /* Fill IGA1 Gamma Table */
  134. outb(0, LUT_INDEX_WRITE);
  135. for (i = 0; i < 256; i++) {
  136. outb(gamma_table[i] >> 16, LUT_DATA);
  137. outb(gamma_table[i] >> 8 & 0xFF, LUT_DATA);
  138. outb(gamma_table[i] & 0xFF, LUT_DATA);
  139. }
  140. /* If adjust Gamma value in SAMM, fill IGA1,
  141. IGA2 Gamma table simultanous. */
  142. /* Switch to IGA2 Gamma Table */
  143. if ((active_device_amount > 1) &&
  144. !((viaparinfo->chip_info->gfx_chip_name ==
  145. UNICHROME_CLE266) &&
  146. (viaparinfo->chip_info->gfx_chip_revision < 15))) {
  147. viafb_write_reg_mask(SR1A, VIASR, 0x01, BIT0);
  148. viafb_write_reg_mask(CR6A, VIACR, 0x02, BIT1);
  149. /* Fill IGA2 Gamma Table */
  150. outb(0, LUT_INDEX_WRITE);
  151. for (i = 0; i < 256; i++) {
  152. outb(gamma_table[i] >> 16, LUT_DATA);
  153. outb(gamma_table[i] >> 8 & 0xFF, LUT_DATA);
  154. outb(gamma_table[i] & 0xFF, LUT_DATA);
  155. }
  156. }
  157. viafb_write_reg(SR1A, VIASR, sr1a);
  158. }
  159. void viafb_get_gamma_table(unsigned int *gamma_table)
  160. {
  161. unsigned char color_r, color_g, color_b;
  162. unsigned char sr1a = 0;
  163. int i;
  164. /* Enable Gamma */
  165. switch (viaparinfo->chip_info->gfx_chip_name) {
  166. case UNICHROME_CLE266:
  167. case UNICHROME_K400:
  168. viafb_write_reg_mask(SR16, VIASR, 0x80, BIT7);
  169. break;
  170. case UNICHROME_K800:
  171. case UNICHROME_PM800:
  172. case UNICHROME_CN700:
  173. case UNICHROME_CX700:
  174. case UNICHROME_K8M890:
  175. case UNICHROME_P4M890:
  176. case UNICHROME_P4M900:
  177. viafb_write_reg_mask(CR33, VIACR, 0x80, BIT7);
  178. break;
  179. }
  180. sr1a = viafb_read_reg(VIASR, SR1A);
  181. viafb_write_reg_mask(SR1A, VIASR, 0x0, BIT0);
  182. /* Reading gamma table to get color value */
  183. outb(0, LUT_INDEX_READ);
  184. for (i = 0; i < 256; i++) {
  185. color_r = inb(LUT_DATA);
  186. color_g = inb(LUT_DATA);
  187. color_b = inb(LUT_DATA);
  188. gamma_table[i] =
  189. ((((u32) color_r) << 16) |
  190. (((u16) color_g) << 8)) | color_b;
  191. }
  192. viafb_write_reg(SR1A, VIASR, sr1a);
  193. }
  194. void viafb_get_gamma_support_state(int bpp, unsigned int *support_state)
  195. {
  196. if (bpp == 8)
  197. *support_state = None_Device;
  198. else
  199. *support_state = CRT_Device | DVI_Device | LCD_Device;
  200. }
  201. int viafb_input_parameter_converter(int parameter_value)
  202. {
  203. int result;
  204. if (parameter_value >= 1 && parameter_value <= 9)
  205. result = 1 << (parameter_value - 1);
  206. else
  207. result = 1;
  208. return result;
  209. }