adv7611.c 4.3 KB

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