blob: d35aee0879fc793bb0b04c2b3489bf82123430f5 [file] [log] [blame]
Dirk Eibach762d3df2013-06-26 15:55:17 +02001/*
2 * (C) Copyright 2012
3 * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
4 *
Tom Rinibe314fa2013-07-26 15:32:59 -04005 * SPDX-License-Identifier: GPL-2.0+
Dirk Eibach762d3df2013-06-26 15:55:17 +02006 */
7
8/* Parade Technologies Inc. DP501 DisplayPort DVI/HDMI Transmitter */
9
10#include <common.h>
11#include <asm/io.h>
12#include <errno.h>
13#include <i2c.h>
14
15static void dp501_setbits(u8 addr, u8 reg, u8 mask)
16{
17 u8 val;
18
19 val = i2c_reg_read(addr, reg);
20 setbits_8(&val, mask);
21 i2c_reg_write(addr, reg, val);
22}
23
24static void dp501_clrbits(u8 addr, u8 reg, u8 mask)
25{
26 u8 val;
27
28 val = i2c_reg_read(addr, reg);
29 clrbits_8(&val, mask);
30 i2c_reg_write(addr, reg, val);
31}
32
33static int dp501_detect_cable_adapter(u8 addr)
34{
35 u8 val = i2c_reg_read(addr, 0x00);
36
37 return !(val & 0x04);
38}
39
40static void dp501_link_training(u8 addr)
41{
42 u8 val;
Dirk Eibacha1ea30a2015-10-28 11:46:27 +010043 u8 link_bw;
44 u8 max_lane_cnt;
45 u8 lane_cnt;
Dirk Eibach762d3df2013-06-26 15:55:17 +020046
47 val = i2c_reg_read(addr, 0x51);
Dirk Eibacha1ea30a2015-10-28 11:46:27 +010048 if (val >= 0x0a)
49 link_bw = 0x0a;
50 else
51 link_bw = 0x06;
52 if (link_bw != val)
53 printf("DP sink supports %d Mbps link rate, set to %d Mbps\n",
54 val * 270, link_bw * 270);
55 i2c_reg_write(addr, 0x5d, link_bw); /* set link_bw */
Dirk Eibach762d3df2013-06-26 15:55:17 +020056 val = i2c_reg_read(addr, 0x52);
Dirk Eibacha1ea30a2015-10-28 11:46:27 +010057 max_lane_cnt = val & 0x1f;
58 if (max_lane_cnt >= 4)
59 lane_cnt = 4;
60 else
61 lane_cnt = max_lane_cnt;
62 if (lane_cnt != max_lane_cnt)
63 printf("DP sink supports %d lanes, set to %d lanes\n",
64 max_lane_cnt, lane_cnt);
65 i2c_reg_write(addr, 0x5e, lane_cnt | (val & 0x80)); /* set lane_cnt */
Dirk Eibach762d3df2013-06-26 15:55:17 +020066 val = i2c_reg_read(addr, 0x53);
67 i2c_reg_write(addr, 0x5c, val); /* set downspread_ctl */
68
69 i2c_reg_write(addr, 0x5f, 0x0d); /* start training */
70}
71
72void dp501_powerup(u8 addr)
73{
74 dp501_clrbits(addr, 0x0a, 0x30); /* power on encoder */
Dirk Eibach9a5ee722014-07-03 09:28:21 +020075 dp501_setbits(addr, 0x0a, 0x0e); /* block HDCP and MCCS on I2C bride*/
Dirk Eibach762d3df2013-06-26 15:55:17 +020076 i2c_reg_write(addr, 0x27, 0x30); /* Hardware auto detect DVO timing */
77 dp501_setbits(addr, 0x72, 0x80); /* DPCD read enable */
78 dp501_setbits(addr, 0x30, 0x20); /* RS polynomial select */
79 i2c_reg_write(addr, 0x71, 0x20); /* Enable Aux burst write */
80 dp501_setbits(addr, 0x78, 0x30); /* Disable HPD2 IRQ */
81 dp501_clrbits(addr, 0x2f, 0x40); /* Link FIFO reset selection */
Dirk Eibachf5e157c2014-07-03 09:28:23 +020082 dp501_clrbits(addr, 0x60, 0x20); /* Enable scrambling */
Dirk Eibach4a3eae12014-07-03 09:28:17 +020083
84#ifdef CONFIG_SYS_DP501_VCAPCTRL0
85 i2c_reg_write(addr, 0x24, CONFIG_SYS_DP501_VCAPCTRL0);
86#else
Dirk Eibach762d3df2013-06-26 15:55:17 +020087 i2c_reg_write(addr, 0x24, 0xc0); /* SDR mode 0, ext. H/VSYNC */
Dirk Eibach4a3eae12014-07-03 09:28:17 +020088#endif
89
90#ifdef CONFIG_SYS_DP501_DIFFERENTIAL
91 i2c_reg_write(addr + 2, 0x24, 0x10); /* clock input differential */
92 i2c_reg_write(addr + 2, 0x25, 0x04);
93 i2c_reg_write(addr + 2, 0x26, 0x10);
94#else
Dirk Eibach762d3df2013-06-26 15:55:17 +020095 i2c_reg_write(addr + 2, 0x24, 0x02); /* clock input single ended */
Dirk Eibach4a3eae12014-07-03 09:28:17 +020096#endif
97
Dirk Eibach05fd4e12015-10-28 11:46:25 +010098 i2c_reg_write(addr + 2, 0x1a, 0x04); /* SPDIF input method TTL */
99
Dirk Eibach4a3eae12014-07-03 09:28:17 +0200100 i2c_reg_write(addr + 2, 0x00, 0x18); /* driving strength */
101 i2c_reg_write(addr + 2, 0x03, 0x06); /* driving strength */
102 i2c_reg_write(addr, 0x2c, 0x00); /* configure N value */
103 i2c_reg_write(addr, 0x2d, 0x00); /* configure N value */
104 i2c_reg_write(addr, 0x2e, 0x0c); /* configure N value */
105 i2c_reg_write(addr, 0x76, 0xff); /* clear all interrupt */
106 dp501_setbits(addr, 0x78, 0x03); /* clear all interrupt */
107 i2c_reg_write(addr, 0x75, 0xf8); /* aux channel reset */
108 i2c_reg_write(addr, 0x75, 0x00); /* clear aux channel reset */
Dirk Eibach8b0e98e2015-10-28 11:46:26 +0100109 i2c_reg_write(addr, 0x87, 0x7f); /* set retry counter as 7
110 retry interval 400us */
Dirk Eibach762d3df2013-06-26 15:55:17 +0200111
112 if (dp501_detect_cable_adapter(addr)) {
113 printf("DVI/HDMI cable adapter detected\n");
114 i2c_reg_write(addr, 0x5e, 0x04); /* enable 4 channel */
115 dp501_clrbits(addr, 0x00, 0x08); /* DVI/HDMI HDCP operation */
116 } else {
117 printf("no DVI/HDMI cable adapter detected\n");
Dirk Eibach762d3df2013-06-26 15:55:17 +0200118 dp501_setbits(addr, 0x00, 0x08); /* for DP HDCP operation */
119
120 dp501_link_training(addr);
121 }
122}
123
124void dp501_powerdown(u8 addr)
125{
126 dp501_setbits(addr, 0x0a, 0x30); /* power down encoder, standby mode */
127}