anx9804.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * (C) 2015 Hans de Goede <hdegoede@redhat.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. /*
  7. * Support for the ANX9804 bridge chip, which can take pixel data coming
  8. * from a parallel LCD interface and translate it on the flight into a DP
  9. * interface for driving eDP TFT displays.
  10. */
  11. #include <common.h>
  12. #include <i2c.h>
  13. #include "anx9804.h"
  14. /* Registers at i2c address 0x38 */
  15. #define ANX9804_HDCP_CONTROL_0_REG 0x01
  16. #define ANX9804_SYS_CTRL2_REG 0x81
  17. #define ANX9804_SYS_CTRL2_CHA_STA 0x04
  18. #define ANX9804_SYS_CTRL3_REG 0x82
  19. #define ANX9804_SYS_CTRL3_VALID_CTRL BIT(0)
  20. #define ANX9804_SYS_CTRL3_F_VALID BIT(1)
  21. #define ANX9804_SYS_CTRL3_HPD_CTRL BIT(4)
  22. #define ANX9804_SYS_CTRL3_F_HPD BIT(5)
  23. #define ANX9804_LINK_BW_SET_REG 0xa0
  24. #define ANX9804_LANE_COUNT_SET_REG 0xa1
  25. #define ANX9804_TRAINING_PTN_SET_REG 0xa2
  26. #define ANX9804_TRAINING_LANE0_SET_REG 0xa3
  27. #define ANX9804_TRAINING_LANE1_SET_REG 0xa4
  28. #define ANX9804_TRAINING_LANE2_SET_REG 0xa5
  29. #define ANX9804_TRAINING_LANE3_SET_REG 0xa6
  30. #define ANX9804_LINK_TRAINING_CTRL_REG 0xa8
  31. #define ANX9804_LINK_TRAINING_CTRL_EN BIT(0)
  32. #define ANX9804_LINK_DEBUG_REG 0xb8
  33. #define ANX9804_PLL_CTRL_REG 0xc7
  34. #define ANX9804_ANALOG_POWER_DOWN_REG 0xc8
  35. /* Registers at i2c address 0x39 */
  36. #define ANX9804_DEV_IDH_REG 0x03
  37. #define ANX9804_POWERD_CTRL_REG 0x05
  38. #define ANX9804_POWERD_AUDIO BIT(4)
  39. #define ANX9804_RST_CTRL_REG 0x06
  40. #define ANX9804_RST_CTRL2_REG 0x07
  41. #define ANX9804_RST_CTRL2_AUX BIT(2)
  42. #define ANX9804_RST_CTRL2_AC_MODE BIT(6)
  43. #define ANX9804_VID_CTRL1_REG 0x08
  44. #define ANX9804_VID_CTRL1_VID_EN BIT(7)
  45. #define ANX9804_VID_CTRL1_EDGE BIT(0)
  46. #define ANX9804_VID_CTRL2_REG 0x09
  47. #define ANX9804_ANALOG_DEBUG_REG1 0xdc
  48. #define ANX9804_ANALOG_DEBUG_REG3 0xde
  49. #define ANX9804_PLL_FILTER_CTRL1 0xdf
  50. #define ANX9804_PLL_FILTER_CTRL3 0xe1
  51. #define ANX9804_PLL_FILTER_CTRL 0xe2
  52. #define ANX9804_PLL_CTRL3 0xe6
  53. /**
  54. * anx9804_init() - Init anx9804 parallel lcd to edp bridge chip
  55. *
  56. * This function will init an anx9804 parallel lcd to dp bridge chip
  57. * using the passed in parameters.
  58. *
  59. * @i2c_bus: Number of the i2c bus to which the anx9804 is connected.
  60. * @lanes: Number of displayport lanes to use
  61. * @data_rate: Register value for the bandwidth reg 0x06: 1.62G, 0x0a: 2.7G
  62. * @bpp: Bits per pixel, must be 18 or 24
  63. */
  64. void anx9804_init(unsigned int i2c_bus, u8 lanes, u8 data_rate, int bpp)
  65. {
  66. unsigned int orig_i2c_bus = i2c_get_bus_num();
  67. u8 c, colordepth;
  68. int i;
  69. i2c_set_bus_num(i2c_bus);
  70. if (bpp == 18)
  71. colordepth = 0x00; /* 6 bit */
  72. else
  73. colordepth = 0x10; /* 8 bit */
  74. /* Reset */
  75. i2c_reg_write(0x39, ANX9804_RST_CTRL_REG, 1);
  76. mdelay(100);
  77. i2c_reg_write(0x39, ANX9804_RST_CTRL_REG, 0);
  78. /* Write 0 to the powerdown reg (powerup everything) */
  79. i2c_reg_write(0x39, ANX9804_POWERD_CTRL_REG, 0);
  80. c = i2c_reg_read(0x39, ANX9804_DEV_IDH_REG);
  81. if (c != 0x98) {
  82. printf("Error anx9804 chipid mismatch\n");
  83. i2c_set_bus_num(orig_i2c_bus);
  84. return;
  85. }
  86. for (i = 0; i < 100; i++) {
  87. c = i2c_reg_read(0x38, ANX9804_SYS_CTRL2_REG);
  88. i2c_reg_write(0x38, ANX9804_SYS_CTRL2_REG, c);
  89. c = i2c_reg_read(0x38, ANX9804_SYS_CTRL2_REG);
  90. if ((c & ANX9804_SYS_CTRL2_CHA_STA) == 0)
  91. break;
  92. mdelay(5);
  93. }
  94. if (i == 100)
  95. printf("Error anx9804 clock is not stable\n");
  96. i2c_reg_write(0x39, ANX9804_VID_CTRL2_REG, colordepth);
  97. /* Set a bunch of analog related register values */
  98. i2c_reg_write(0x38, ANX9804_PLL_CTRL_REG, 0x07);
  99. i2c_reg_write(0x39, ANX9804_PLL_FILTER_CTRL3, 0x19);
  100. i2c_reg_write(0x39, ANX9804_PLL_CTRL3, 0xd9);
  101. i2c_reg_write(0x39, ANX9804_RST_CTRL2_REG, ANX9804_RST_CTRL2_AC_MODE);
  102. i2c_reg_write(0x39, ANX9804_ANALOG_DEBUG_REG1, 0xf0);
  103. i2c_reg_write(0x39, ANX9804_ANALOG_DEBUG_REG3, 0x99);
  104. i2c_reg_write(0x39, ANX9804_PLL_FILTER_CTRL1, 0x7b);
  105. i2c_reg_write(0x38, ANX9804_LINK_DEBUG_REG, 0x30);
  106. i2c_reg_write(0x39, ANX9804_PLL_FILTER_CTRL, 0x06);
  107. /* Force HPD */
  108. i2c_reg_write(0x38, ANX9804_SYS_CTRL3_REG,
  109. ANX9804_SYS_CTRL3_F_HPD | ANX9804_SYS_CTRL3_HPD_CTRL);
  110. /* Power up and configure lanes */
  111. i2c_reg_write(0x38, ANX9804_ANALOG_POWER_DOWN_REG, 0x00);
  112. i2c_reg_write(0x38, ANX9804_TRAINING_LANE0_SET_REG, 0x00);
  113. i2c_reg_write(0x38, ANX9804_TRAINING_LANE1_SET_REG, 0x00);
  114. i2c_reg_write(0x38, ANX9804_TRAINING_LANE2_SET_REG, 0x00);
  115. i2c_reg_write(0x38, ANX9804_TRAINING_LANE3_SET_REG, 0x00);
  116. /* Reset AUX CH */
  117. i2c_reg_write(0x39, ANX9804_RST_CTRL2_REG,
  118. ANX9804_RST_CTRL2_AC_MODE | ANX9804_RST_CTRL2_AUX);
  119. i2c_reg_write(0x39, ANX9804_RST_CTRL2_REG,
  120. ANX9804_RST_CTRL2_AC_MODE);
  121. /* Powerdown audio and some other unused bits */
  122. i2c_reg_write(0x39, ANX9804_POWERD_CTRL_REG, ANX9804_POWERD_AUDIO);
  123. i2c_reg_write(0x38, ANX9804_HDCP_CONTROL_0_REG, 0x00);
  124. i2c_reg_write(0x38, 0xa7, 0x00);
  125. /* Set data-rate / lanes */
  126. i2c_reg_write(0x38, ANX9804_LINK_BW_SET_REG, data_rate);
  127. i2c_reg_write(0x38, ANX9804_LANE_COUNT_SET_REG, lanes);
  128. /* Link training */
  129. i2c_reg_write(0x38, ANX9804_LINK_TRAINING_CTRL_REG,
  130. ANX9804_LINK_TRAINING_CTRL_EN);
  131. mdelay(5);
  132. for (i = 0; i < 100; i++) {
  133. c = i2c_reg_read(0x38, ANX9804_LINK_TRAINING_CTRL_REG);
  134. if ((c & 0x01) == 0)
  135. break;
  136. mdelay(5);
  137. }
  138. if(i == 100) {
  139. printf("Error anx9804 link training timeout\n");
  140. i2c_set_bus_num(orig_i2c_bus);
  141. return;
  142. }
  143. /* Enable */
  144. i2c_reg_write(0x39, ANX9804_VID_CTRL1_REG,
  145. ANX9804_VID_CTRL1_VID_EN | ANX9804_VID_CTRL1_EDGE);
  146. /* Force stream valid */
  147. i2c_reg_write(0x38, ANX9804_SYS_CTRL3_REG,
  148. ANX9804_SYS_CTRL3_F_HPD | ANX9804_SYS_CTRL3_HPD_CTRL |
  149. ANX9804_SYS_CTRL3_F_VALID | ANX9804_SYS_CTRL3_VALID_CTRL);
  150. i2c_set_bus_num(orig_i2c_bus);
  151. }