vt1636.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
  4. * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
  5. */
  6. #include <linux/via-core.h>
  7. #include <linux/via_i2c.h>
  8. #include "global.h"
  9. static const struct IODATA common_init_data[] = {
  10. /* Index, Mask, Value */
  11. /* Set panel power sequence timing */
  12. {0x10, 0xC0, 0x00},
  13. /* T1: VDD on - Data on. Each increment is 1 ms. (50ms = 031h) */
  14. {0x0B, 0xFF, 0x40},
  15. /* T2: Data on - Backlight on. Each increment is 2 ms. (210ms = 068h) */
  16. {0x0C, 0xFF, 0x31},
  17. /* T3: Backlight off -Data off. Each increment is 2 ms. (210ms = 068h)*/
  18. {0x0D, 0xFF, 0x31},
  19. /* T4: Data off - VDD off. Each increment is 1 ms. (50ms = 031h) */
  20. {0x0E, 0xFF, 0x68},
  21. /* T5: VDD off - VDD on. Each increment is 100 ms. (500ms = 04h) */
  22. {0x0F, 0xFF, 0x68},
  23. /* LVDS output power up */
  24. {0x09, 0xA0, 0xA0},
  25. /* turn on back light */
  26. {0x10, 0x33, 0x13}
  27. };
  28. /* Index, Mask, Value */
  29. static const struct IODATA dual_channel_enable_data = {0x08, 0xF0, 0xE0};
  30. static const struct IODATA single_channel_enable_data = {0x08, 0xF0, 0x00};
  31. static const struct IODATA dithering_enable_data = {0x0A, 0x70, 0x50};
  32. static const struct IODATA dithering_disable_data = {0x0A, 0x70, 0x00};
  33. static const struct IODATA vdd_on_data = {0x10, 0x20, 0x20};
  34. static const struct IODATA vdd_off_data = {0x10, 0x20, 0x00};
  35. u8 viafb_gpio_i2c_read_lvds(struct lvds_setting_information
  36. *plvds_setting_info, struct lvds_chip_information *plvds_chip_info,
  37. u8 index)
  38. {
  39. u8 data;
  40. viafb_i2c_readbyte(plvds_chip_info->i2c_port,
  41. plvds_chip_info->lvds_chip_target_addr, index, &data);
  42. return data;
  43. }
  44. void viafb_gpio_i2c_write_mask_lvds(struct lvds_setting_information
  45. *plvds_setting_info, struct lvds_chip_information
  46. *plvds_chip_info, struct IODATA io_data)
  47. {
  48. int index, data;
  49. index = io_data.Index;
  50. data = viafb_gpio_i2c_read_lvds(plvds_setting_info, plvds_chip_info,
  51. index);
  52. data = (data & (~io_data.Mask)) | io_data.Data;
  53. viafb_i2c_writebyte(plvds_chip_info->i2c_port,
  54. plvds_chip_info->lvds_chip_target_addr, index, data);
  55. }
  56. void viafb_init_lvds_vt1636(struct lvds_setting_information
  57. *plvds_setting_info, struct lvds_chip_information *plvds_chip_info)
  58. {
  59. int reg_num, i;
  60. /* Common settings: */
  61. reg_num = ARRAY_SIZE(common_init_data);
  62. for (i = 0; i < reg_num; i++)
  63. viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
  64. plvds_chip_info, common_init_data[i]);
  65. /* Input Data Mode Select */
  66. if (plvds_setting_info->device_lcd_dualedge)
  67. viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
  68. plvds_chip_info, dual_channel_enable_data);
  69. else
  70. viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
  71. plvds_chip_info, single_channel_enable_data);
  72. if (plvds_setting_info->LCDDithering)
  73. viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
  74. plvds_chip_info, dithering_enable_data);
  75. else
  76. viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
  77. plvds_chip_info, dithering_disable_data);
  78. }
  79. void viafb_enable_lvds_vt1636(struct lvds_setting_information
  80. *plvds_setting_info,
  81. struct lvds_chip_information *plvds_chip_info)
  82. {
  83. viafb_gpio_i2c_write_mask_lvds(plvds_setting_info, plvds_chip_info,
  84. vdd_on_data);
  85. }
  86. void viafb_disable_lvds_vt1636(struct lvds_setting_information
  87. *plvds_setting_info,
  88. struct lvds_chip_information *plvds_chip_info)
  89. {
  90. viafb_gpio_i2c_write_mask_lvds(plvds_setting_info, plvds_chip_info,
  91. vdd_off_data);
  92. }
  93. bool viafb_lvds_identify_vt1636(u8 i2c_adapter)
  94. {
  95. u8 Buffer[2];
  96. DEBUG_MSG(KERN_INFO "viafb_lvds_identify_vt1636.\n");
  97. /* Sense VT1636 LVDS Transmiter */
  98. viaparinfo->chip_info->lvds_chip_info.lvds_chip_target_addr =
  99. VT1636_LVDS_I2C_ADDR;
  100. /* Check vendor ID first: */
  101. if (viafb_i2c_readbyte(i2c_adapter, VT1636_LVDS_I2C_ADDR,
  102. 0x00, &Buffer[0]))
  103. return false;
  104. viafb_i2c_readbyte(i2c_adapter, VT1636_LVDS_I2C_ADDR, 0x01, &Buffer[1]);
  105. if (!((Buffer[0] == 0x06) && (Buffer[1] == 0x11)))
  106. return false;
  107. /* Check Chip ID: */
  108. viafb_i2c_readbyte(i2c_adapter, VT1636_LVDS_I2C_ADDR, 0x02, &Buffer[0]);
  109. viafb_i2c_readbyte(i2c_adapter, VT1636_LVDS_I2C_ADDR, 0x03, &Buffer[1]);
  110. if ((Buffer[0] == 0x45) && (Buffer[1] == 0x33)) {
  111. viaparinfo->chip_info->lvds_chip_info.lvds_chip_name =
  112. VT1636_LVDS;
  113. return true;
  114. }
  115. return false;
  116. }
  117. static int get_clk_range_index(u32 Clk)
  118. {
  119. if (Clk < DPA_CLK_30M)
  120. return DPA_CLK_RANGE_30M;
  121. else if (Clk < DPA_CLK_50M)
  122. return DPA_CLK_RANGE_30_50M;
  123. else if (Clk < DPA_CLK_70M)
  124. return DPA_CLK_RANGE_50_70M;
  125. else if (Clk < DPA_CLK_100M)
  126. return DPA_CLK_RANGE_70_100M;
  127. else if (Clk < DPA_CLK_150M)
  128. return DPA_CLK_RANGE_100_150M;
  129. else
  130. return DPA_CLK_RANGE_150M;
  131. }
  132. static void set_dpa_vt1636(struct lvds_setting_information
  133. *plvds_setting_info, struct lvds_chip_information *plvds_chip_info,
  134. struct VT1636_DPA_SETTING *p_vt1636_dpa_setting)
  135. {
  136. struct IODATA io_data;
  137. io_data.Index = 0x09;
  138. io_data.Mask = 0x1F;
  139. io_data.Data = p_vt1636_dpa_setting->CLK_SEL_ST1;
  140. viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
  141. plvds_chip_info, io_data);
  142. io_data.Index = 0x08;
  143. io_data.Mask = 0x0F;
  144. io_data.Data = p_vt1636_dpa_setting->CLK_SEL_ST2;
  145. viafb_gpio_i2c_write_mask_lvds(plvds_setting_info, plvds_chip_info,
  146. io_data);
  147. }
  148. void viafb_vt1636_patch_skew_on_vt3324(
  149. struct lvds_setting_information *plvds_setting_info,
  150. struct lvds_chip_information *plvds_chip_info)
  151. {
  152. struct VT1636_DPA_SETTING dpa = {0x00, 0x00}, dpa_16x12 = {0x0B, 0x03},
  153. *pdpa;
  154. int index;
  155. DEBUG_MSG(KERN_INFO "viafb_vt1636_patch_skew_on_vt3324.\n");
  156. /* Graphics DPA settings: */
  157. index = get_clk_range_index(plvds_setting_info->vclk);
  158. viafb_set_dpa_gfx(plvds_chip_info->output_interface,
  159. &GFX_DPA_SETTING_TBL_VT3324[index]);
  160. /* LVDS Transmitter DPA settings: */
  161. if (plvds_setting_info->lcd_panel_hres == 1600 &&
  162. plvds_setting_info->lcd_panel_vres == 1200)
  163. pdpa = &dpa_16x12;
  164. else
  165. pdpa = &dpa;
  166. set_dpa_vt1636(plvds_setting_info, plvds_chip_info, pdpa);
  167. }
  168. void viafb_vt1636_patch_skew_on_vt3327(
  169. struct lvds_setting_information *plvds_setting_info,
  170. struct lvds_chip_information *plvds_chip_info)
  171. {
  172. struct VT1636_DPA_SETTING dpa = {0x00, 0x00};
  173. int index;
  174. DEBUG_MSG(KERN_INFO "viafb_vt1636_patch_skew_on_vt3327.\n");
  175. /* Graphics DPA settings: */
  176. index = get_clk_range_index(plvds_setting_info->vclk);
  177. viafb_set_dpa_gfx(plvds_chip_info->output_interface,
  178. &GFX_DPA_SETTING_TBL_VT3327[index]);
  179. /* LVDS Transmitter DPA settings: */
  180. set_dpa_vt1636(plvds_setting_info, plvds_chip_info, &dpa);
  181. }
  182. void viafb_vt1636_patch_skew_on_vt3364(
  183. struct lvds_setting_information *plvds_setting_info,
  184. struct lvds_chip_information *plvds_chip_info)
  185. {
  186. int index;
  187. DEBUG_MSG(KERN_INFO "viafb_vt1636_patch_skew_on_vt3364.\n");
  188. /* Graphics DPA settings: */
  189. index = get_clk_range_index(plvds_setting_info->vclk);
  190. viafb_set_dpa_gfx(plvds_chip_info->output_interface,
  191. &GFX_DPA_SETTING_TBL_VT3364[index]);
  192. }