parade.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. /*
  7. * This file is a driver for Parade dP<->LVDS bridges. The original submission
  8. * is for the ps8625 chip.
  9. */
  10. #include <config.h>
  11. #include <common.h>
  12. #include <i2c.h>
  13. #include <fdtdec.h>
  14. /*
  15. * Initialization of the chip is a process of writing certaing values into
  16. * certain registers over i2c bus. The chip in fact responds to a range of
  17. * addresses on the i2c bus, so for each written value three parameters are
  18. * required: i2c address, register address and the actual value.
  19. *
  20. * The base address is derived from the device tree, only address offset is
  21. * stored in the table below.
  22. */
  23. /**
  24. * struct reg_data() - data for a parade register write
  25. *
  26. * @addr_off offset from the i2c base address for parade
  27. * @reg_addr register address to write
  28. * @value value to be written
  29. */
  30. struct reg_data {
  31. uint8_t addr_off;
  32. uint8_t reg;
  33. uint8_t value;
  34. } _packed;
  35. #define END_OF_TABLE 0xff /* Ficticious offset */
  36. static const struct reg_data parade_values[] = {
  37. {0x02, 0xa1, 0x01}, /* HPD low */
  38. /*
  39. * SW setting
  40. * [1:0] SW output 1.2V voltage is lower to 96%
  41. */
  42. {0x04, 0x14, 0x01},
  43. /*
  44. * RCO SS setting
  45. * [5:4] = b01 0.5%, b10 1%, b11 1.5%
  46. */
  47. {0x04, 0xe3, 0x20},
  48. {0x04, 0xe2, 0x80}, /* [7] RCO SS enable */
  49. /*
  50. * RPHY Setting
  51. * [3:2] CDR tune wait cycle before
  52. * measure for fine tune b00: 1us,
  53. * 01: 0.5us, 10:2us, 11:4us.
  54. */
  55. {0x04, 0x8a, 0x0c},
  56. {0x04, 0x89, 0x08}, /* [3] RFD always on */
  57. /*
  58. * CTN lock in/out:
  59. * 20000ppm/80000ppm. Lock out 2
  60. * times.
  61. */
  62. {0x04, 0x71, 0x2d},
  63. /*
  64. * 2.7G CDR settings
  65. * NOF=40LSB for HBR CDR setting
  66. */
  67. {0x04, 0x7d, 0x07},
  68. {0x04, 0x7b, 0x00}, /* [1:0] Fmin=+4bands */
  69. {0x04, 0x7a, 0xfd}, /* [7:5] DCO_FTRNG=+-40% */
  70. /*
  71. * 1.62G CDR settings
  72. * [5:2]NOF=64LSB [1:0]DCO scale is 2/5
  73. */
  74. {0x04, 0xc0, 0x12},
  75. {0x04, 0xc1, 0x92}, /* Gitune=-37% */
  76. {0x04, 0xc2, 0x1c}, /* Fbstep=100% */
  77. {0x04, 0x32, 0x80}, /* [7] LOS signal disable */
  78. /*
  79. * RPIO Setting
  80. * [7:4] LVDS driver bias current :
  81. * 75% (250mV swing)
  82. */
  83. {0x04, 0x00, 0xb0},
  84. /*
  85. * [7:6] Right-bar GPIO output strength is 8mA
  86. */
  87. {0x04, 0x15, 0x40},
  88. /* EQ Training State Machine Setting */
  89. {0x04, 0x54, 0x10}, /* RCO calibration start */
  90. /* [4:0] MAX_LANE_COUNT set to one lane */
  91. {0x01, 0x02, 0x81},
  92. /* [4:0] LANE_COUNT_SET set to one lane */
  93. {0x01, 0x21, 0x81},
  94. {0x00, 0x52, 0x20},
  95. {0x00, 0xf1, 0x03}, /* HPD CP toggle enable */
  96. {0x00, 0x62, 0x41},
  97. /* Counter number, add 1ms counter delay */
  98. {0x00, 0xf6, 0x01},
  99. /*
  100. * [6]PWM function control by
  101. * DPCD0040f[7], default is PWM
  102. * block always works.
  103. */
  104. {0x00, 0x77, 0x06},
  105. /*
  106. * 04h Adjust VTotal tolerance to
  107. * fix the 30Hz no display issue
  108. */
  109. {0x00, 0x4c, 0x04},
  110. /* DPCD00400='h00, Parade OUI = 'h001cf8 */
  111. {0x01, 0xc0, 0x00},
  112. {0x01, 0xc1, 0x1c}, /* DPCD00401='h1c */
  113. {0x01, 0xc2, 0xf8}, /* DPCD00402='hf8 */
  114. /*
  115. * DPCD403~408 = ASCII code
  116. * D2SLV5='h4432534c5635
  117. */
  118. {0x01, 0xc3, 0x44},
  119. {0x01, 0xc4, 0x32}, /* DPCD404 */
  120. {0x01, 0xc5, 0x53}, /* DPCD405 */
  121. {0x01, 0xc6, 0x4c}, /* DPCD406 */
  122. {0x01, 0xc7, 0x56}, /* DPCD407 */
  123. {0x01, 0xc8, 0x35}, /* DPCD408 */
  124. /*
  125. * DPCD40A, Initial Code major revision
  126. * '01'
  127. */
  128. {0x01, 0xca, 0x01},
  129. /* DPCD40B, Initial Code minor revision '05' */
  130. {0x01, 0xcb, 0x05},
  131. /* DPCD720, Select internal PWM */
  132. {0x01, 0xa5, 0xa0},
  133. /*
  134. * FFh for 100% PWM of brightness, 0h for 0%
  135. * brightness
  136. */
  137. {0x01, 0xa7, 0xff},
  138. /*
  139. * Set LVDS output as 6bit-VESA mapping,
  140. * single LVDS channel
  141. */
  142. {0x01, 0xcc, 0x13},
  143. /* Enable SSC set by register */
  144. {0x02, 0xb1, 0x20},
  145. /*
  146. * Set SSC enabled and +/-1% central
  147. * spreading
  148. */
  149. {0x04, 0x10, 0x16},
  150. /* MPU Clock source: LC => RCO */
  151. {0x04, 0x59, 0x60},
  152. {0x04, 0x54, 0x14}, /* LC -> RCO */
  153. {0x02, 0xa1, 0x91}, /* HPD high */
  154. {END_OF_TABLE}
  155. };
  156. /**
  157. * Write values table into the Parade eDP bridge
  158. *
  159. * @return 0 on success, non-0 on failure
  160. */
  161. static int parade_write_regs(int base_addr, const struct reg_data *table)
  162. {
  163. int ret = 0;
  164. while (!ret && (table->addr_off != END_OF_TABLE)) {
  165. ret = i2c_write(base_addr + table->addr_off,
  166. table->reg, 1,
  167. (uint8_t *)&table->value,
  168. sizeof(table->value));
  169. table++;
  170. }
  171. return ret;
  172. }
  173. int parade_init(const void *blob)
  174. {
  175. int bus, old_bus;
  176. int parent;
  177. int node;
  178. int addr;
  179. int ret;
  180. node = fdtdec_next_compatible(blob, 0, COMPAT_PARADE_PS8625);
  181. if (node < 0)
  182. return 0;
  183. parent = fdt_parent_offset(blob, node);
  184. if (parent < 0) {
  185. debug("%s: Could not find parent i2c node\n", __func__);
  186. return -1;
  187. }
  188. addr = fdtdec_get_int(blob, node, "reg", -1);
  189. if (addr < 0) {
  190. debug("%s: Could not find i2c address\n", __func__);
  191. return -1;
  192. }
  193. bus = i2c_get_bus_num_fdt(parent);
  194. old_bus = i2c_get_bus_num();
  195. debug("%s: Using i2c bus %d\n", __func__, bus);
  196. /*
  197. * TODO(sjg@chromium.org): Hmmm we seem to need some sort of delay
  198. * here.
  199. */
  200. mdelay(40);
  201. i2c_set_bus_num(bus);
  202. ret = parade_write_regs(addr, parade_values);
  203. i2c_set_bus_num(old_bus);
  204. return ret;
  205. }