adv7611.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * (C) Copyright 2014
  3. * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <i2c.h>
  9. #define ADV7611_I2C_ADDR 0x4c
  10. #define ADV7611_RDINFO 0x2051
  11. /*
  12. * ADV7611 I2C Addresses in u-boot notation
  13. */
  14. enum {
  15. CP_I2C_ADDR = 0x22,
  16. DPLL_I2C_ADDR = 0x26,
  17. KSV_I2C_ADDR = 0x32,
  18. HDMI_I2C_ADDR = 0x34,
  19. EDID_I2C_ADDR = 0x36,
  20. INFOFRAME_I2C_ADDR = 0x3e,
  21. CEC_I2C_ADDR = 0x40,
  22. IO_I2C_ADDR = ADV7611_I2C_ADDR,
  23. };
  24. /*
  25. * Global Control Registers
  26. */
  27. enum {
  28. IO_RD_INFO_MSB = 0xea,
  29. IO_RD_INFO_LSB = 0xeb,
  30. IO_CEC_ADDR = 0xf4,
  31. IO_INFOFRAME_ADDR = 0xf5,
  32. IO_DPLL_ADDR = 0xf8,
  33. IO_KSV_ADDR = 0xf9,
  34. IO_EDID_ADDR = 0xfa,
  35. IO_HDMI_ADDR = 0xfb,
  36. IO_CP_ADDR = 0xfd,
  37. };
  38. int adv7611_i2c[] = CONFIG_SYS_ADV7611_I2C;
  39. int adv7611_probe(unsigned int screen)
  40. {
  41. int old_bus = i2c_get_bus_num();
  42. unsigned int rd_info;
  43. int res = 0;
  44. i2c_set_bus_num(adv7611_i2c[screen]);
  45. rd_info = (i2c_reg_read(IO_I2C_ADDR, IO_RD_INFO_MSB) << 8)
  46. | i2c_reg_read(IO_I2C_ADDR, IO_RD_INFO_LSB);
  47. if (rd_info != ADV7611_RDINFO) {
  48. res = -1;
  49. goto out;
  50. }
  51. /*
  52. * set I2C addresses to default values
  53. */
  54. i2c_reg_write(IO_I2C_ADDR, IO_CEC_ADDR, CEC_I2C_ADDR << 1);
  55. i2c_reg_write(IO_I2C_ADDR, IO_INFOFRAME_ADDR, INFOFRAME_I2C_ADDR << 1);
  56. i2c_reg_write(IO_I2C_ADDR, IO_DPLL_ADDR, DPLL_I2C_ADDR << 1);
  57. i2c_reg_write(IO_I2C_ADDR, IO_KSV_ADDR, KSV_I2C_ADDR << 1);
  58. i2c_reg_write(IO_I2C_ADDR, IO_EDID_ADDR, EDID_I2C_ADDR << 1);
  59. i2c_reg_write(IO_I2C_ADDR, IO_HDMI_ADDR, HDMI_I2C_ADDR << 1);
  60. i2c_reg_write(IO_I2C_ADDR, IO_CP_ADDR, CP_I2C_ADDR << 1);
  61. /*
  62. * do magic initialization sequence from
  63. * "ADV7611 Register Settings Recommendations Revision 1.5"
  64. * with most registers undocumented
  65. */
  66. i2c_reg_write(CP_I2C_ADDR, 0x6c, 0x00);
  67. i2c_reg_write(HDMI_I2C_ADDR, 0x9b, 0x03);
  68. i2c_reg_write(HDMI_I2C_ADDR, 0x6f, 0x08);
  69. i2c_reg_write(HDMI_I2C_ADDR, 0x85, 0x1f);
  70. i2c_reg_write(HDMI_I2C_ADDR, 0x87, 0x70);
  71. i2c_reg_write(HDMI_I2C_ADDR, 0x57, 0xda);
  72. i2c_reg_write(HDMI_I2C_ADDR, 0x58, 0x01);
  73. i2c_reg_write(HDMI_I2C_ADDR, 0x03, 0x98);
  74. i2c_reg_write(HDMI_I2C_ADDR, 0x4c, 0x44);
  75. /*
  76. * IO_REG_02, default 0xf0
  77. *
  78. * INP_COLOR_SPACE (IO, Address 0x02[7:4])
  79. * default: 0b1111 auto
  80. * set to : 0b0001 force RGB (range 0 to 255) input
  81. *
  82. * RGB_OUT (IO, Address 0x02[1])
  83. * default: 0 YPbPr color space output
  84. * set to : 1 RGB color space output
  85. */
  86. i2c_reg_write(IO_I2C_ADDR, 0x02, 0x12);
  87. /*
  88. * IO_REG_03, default 0x00
  89. *
  90. * OP_FORMAT_SEL (IO, Address 0x03[7:0])
  91. * default: 0x00 8-bit SDR ITU-656 mode
  92. * set to : 0x40 24-bit 4:4:4 SDR mode
  93. */
  94. i2c_reg_write(IO_I2C_ADDR, 0x03, 0x40);
  95. /*
  96. * IO_REG_05, default 0x2c
  97. *
  98. * AVCODE_INSERT_EN (IO, Address 0x05[2])
  99. * default: 1 insert AV codes into data stream
  100. * set to : 0 do not insert AV codes into data stream
  101. */
  102. i2c_reg_write(IO_I2C_ADDR, 0x05, 0x28);
  103. /*
  104. * IO_REG_0C, default 0x62
  105. *
  106. * POWER_DOWN (IO, Address 0x0C[5])
  107. * default: 1 chip is powered down
  108. * set to : 0 chip is operational
  109. */
  110. i2c_reg_write(IO_I2C_ADDR, 0x0c, 0x42);
  111. /*
  112. * IO_REG_15, default 0xbe
  113. *
  114. * TRI_SYNCS (IO, Address 0x15[3)
  115. * TRI_LLC (IO, Address 0x15[2])
  116. * TRI_PIX (IO, Address 0x15[1])
  117. * default: 1 video output pins are tristate
  118. * set to : 0 video output pins are active
  119. */
  120. i2c_reg_write(IO_I2C_ADDR, 0x15, 0xb0);
  121. /*
  122. * HDMI_REGISTER_02H, default 0xff
  123. *
  124. * CLOCK_TERMA_DISABLE (HDMI, Address 0x83[0])
  125. * default: 1 disable termination
  126. * set to : 0 enable termination
  127. * Future options are:
  128. * - use the chips automatic termination control
  129. * - set this manually on cable detect
  130. * but at the moment this seems a safe default.
  131. */
  132. i2c_reg_write(HDMI_I2C_ADDR, 0x83, 0xfe);
  133. /*
  134. * HDMI_CP_CNTRL_1, default 0x01
  135. *
  136. * HDMI_FRUN_EN (CP, Address 0xBA[0])
  137. * default: 1 Enable the free run feature in HDMI mode
  138. * set to : 0 Disable the free run feature in HDMI mode
  139. */
  140. i2c_reg_write(CP_I2C_ADDR, 0xba, 0x00);
  141. /*
  142. * INT1_CONFIGURATION, default 0x20
  143. *
  144. * INTRQ_DUR_SEL[1:0] (IO, Address 0x40[7:6])
  145. * default: 00 Interrupt signal is active for 4 Xtal periods
  146. * set to : 11 Active until cleared
  147. *
  148. * INTRQ_OP_SEL[1:0] (IO, Address 0x40[1:0])
  149. * default: 00 Open drain
  150. * set to : 10 Drives high when active
  151. */
  152. i2c_reg_write(IO_I2C_ADDR, 0x40, 0xc2);
  153. out:
  154. i2c_set_bus_num(old_bus);
  155. return res;
  156. }