Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Samsung Electronics |
| 4 | * |
| 5 | * Author: Donghwa Lee <dh09.lee@samsung.com> |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Simon Glass | 51a3ec3 | 2017-05-17 17:18:07 -0600 | [diff] [blame] | 8 | #include <common.h> |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 9 | #include <dm.h> |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 10 | #include <common.h> |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 11 | #include <display.h> |
| 12 | #include <fdtdec.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 14 | #include <linux/delay.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 15 | #include <linux/libfdt.h> |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 16 | #include <malloc.h> |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 17 | #include <video_bridge.h> |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 18 | #include <linux/compat.h> |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 19 | #include <linux/err.h> |
| 20 | #include <asm/arch/clk.h> |
| 21 | #include <asm/arch/cpu.h> |
| 22 | #include <asm/arch/dp_info.h> |
| 23 | #include <asm/arch/dp.h> |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 24 | #include <asm/arch/pinmux.h> |
Simon Glass | bfd239c | 2016-02-21 21:08:57 -0700 | [diff] [blame] | 25 | #include <asm/arch/power.h> |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 26 | |
| 27 | #include "exynos_dp_lowlevel.h" |
| 28 | |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 31 | static void exynos_dp_disp_info(struct edp_disp_info *disp_info) |
| 32 | { |
| 33 | disp_info->h_total = disp_info->h_res + disp_info->h_sync_width + |
| 34 | disp_info->h_back_porch + disp_info->h_front_porch; |
| 35 | disp_info->v_total = disp_info->v_res + disp_info->v_sync_width + |
| 36 | disp_info->v_back_porch + disp_info->v_front_porch; |
| 37 | |
| 38 | return; |
| 39 | } |
| 40 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 41 | static int exynos_dp_init_dp(struct exynos_dp *regs) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 42 | { |
| 43 | int ret; |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 44 | exynos_dp_reset(regs); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 45 | |
| 46 | /* SW defined function Normal operation */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 47 | exynos_dp_enable_sw_func(regs, DP_ENABLE); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 48 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 49 | ret = exynos_dp_init_analog_func(regs); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 50 | if (ret != EXYNOS_DP_SUCCESS) |
| 51 | return ret; |
| 52 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 53 | exynos_dp_init_hpd(regs); |
| 54 | exynos_dp_init_aux(regs); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 55 | |
| 56 | return ret; |
| 57 | } |
| 58 | |
| 59 | static unsigned char exynos_dp_calc_edid_check_sum(unsigned char *edid_data) |
| 60 | { |
| 61 | int i; |
| 62 | unsigned char sum = 0; |
| 63 | |
| 64 | for (i = 0; i < EDID_BLOCK_LENGTH; i++) |
| 65 | sum = sum + edid_data[i]; |
| 66 | |
| 67 | return sum; |
| 68 | } |
| 69 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 70 | static unsigned int exynos_dp_read_edid(struct exynos_dp *regs) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 71 | { |
| 72 | unsigned char edid[EDID_BLOCK_LENGTH * 2]; |
| 73 | unsigned int extend_block = 0; |
| 74 | unsigned char sum; |
| 75 | unsigned char test_vector; |
| 76 | int retval; |
| 77 | |
| 78 | /* |
| 79 | * EDID device address is 0x50. |
| 80 | * However, if necessary, you must have set upper address |
| 81 | * into E-EDID in I2C device, 0x30. |
| 82 | */ |
| 83 | |
| 84 | /* Read Extension Flag, Number of 128-byte EDID extension blocks */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 85 | exynos_dp_read_byte_from_i2c(regs, I2C_EDID_DEVICE_ADDR, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 86 | EDID_EXTENSION_FLAG, &extend_block); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 87 | |
| 88 | if (extend_block > 0) { |
| 89 | printf("DP EDID data includes a single extension!\n"); |
| 90 | |
| 91 | /* Read EDID data */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 92 | retval = exynos_dp_read_bytes_from_i2c(regs, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 93 | I2C_EDID_DEVICE_ADDR, |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 94 | EDID_HEADER_PATTERN, |
| 95 | EDID_BLOCK_LENGTH, |
| 96 | &edid[EDID_HEADER_PATTERN]); |
| 97 | if (retval != 0) { |
| 98 | printf("DP EDID Read failed!\n"); |
| 99 | return -1; |
| 100 | } |
| 101 | sum = exynos_dp_calc_edid_check_sum(edid); |
| 102 | if (sum != 0) { |
| 103 | printf("DP EDID bad checksum!\n"); |
| 104 | return -1; |
| 105 | } |
| 106 | |
| 107 | /* Read additional EDID data */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 108 | retval = exynos_dp_read_bytes_from_i2c(regs, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 109 | I2C_EDID_DEVICE_ADDR, |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 110 | EDID_BLOCK_LENGTH, |
| 111 | EDID_BLOCK_LENGTH, |
| 112 | &edid[EDID_BLOCK_LENGTH]); |
| 113 | if (retval != 0) { |
| 114 | printf("DP EDID Read failed!\n"); |
| 115 | return -1; |
| 116 | } |
| 117 | sum = exynos_dp_calc_edid_check_sum(&edid[EDID_BLOCK_LENGTH]); |
| 118 | if (sum != 0) { |
| 119 | printf("DP EDID bad checksum!\n"); |
| 120 | return -1; |
| 121 | } |
| 122 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 123 | exynos_dp_read_byte_from_dpcd(regs, DPCD_TEST_REQUEST, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 124 | &test_vector); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 125 | if (test_vector & DPCD_TEST_EDID_READ) { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 126 | exynos_dp_write_byte_to_dpcd(regs, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 127 | DPCD_TEST_EDID_CHECKSUM, |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 128 | edid[EDID_BLOCK_LENGTH + EDID_CHECKSUM]); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 129 | exynos_dp_write_byte_to_dpcd(regs, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 130 | DPCD_TEST_RESPONSE, |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 131 | DPCD_TEST_EDID_CHECKSUM_WRITE); |
| 132 | } |
| 133 | } else { |
| 134 | debug("DP EDID data does not include any extensions.\n"); |
| 135 | |
| 136 | /* Read EDID data */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 137 | retval = exynos_dp_read_bytes_from_i2c(regs, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 138 | I2C_EDID_DEVICE_ADDR, |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 139 | EDID_HEADER_PATTERN, |
| 140 | EDID_BLOCK_LENGTH, |
| 141 | &edid[EDID_HEADER_PATTERN]); |
| 142 | |
| 143 | if (retval != 0) { |
| 144 | printf("DP EDID Read failed!\n"); |
| 145 | return -1; |
| 146 | } |
| 147 | sum = exynos_dp_calc_edid_check_sum(edid); |
| 148 | if (sum != 0) { |
| 149 | printf("DP EDID bad checksum!\n"); |
| 150 | return -1; |
| 151 | } |
| 152 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 153 | exynos_dp_read_byte_from_dpcd(regs, DPCD_TEST_REQUEST, |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 154 | &test_vector); |
| 155 | if (test_vector & DPCD_TEST_EDID_READ) { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 156 | exynos_dp_write_byte_to_dpcd(regs, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 157 | DPCD_TEST_EDID_CHECKSUM, edid[EDID_CHECKSUM]); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 158 | exynos_dp_write_byte_to_dpcd(regs, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 159 | DPCD_TEST_RESPONSE, |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 160 | DPCD_TEST_EDID_CHECKSUM_WRITE); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | debug("DP EDID Read success!\n"); |
| 165 | |
| 166 | return 0; |
| 167 | } |
| 168 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 169 | static unsigned int exynos_dp_handle_edid(struct exynos_dp *regs, |
| 170 | struct exynos_dp_priv *priv) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 171 | { |
| 172 | unsigned char buf[12]; |
| 173 | unsigned int ret; |
| 174 | unsigned char temp; |
| 175 | unsigned char retry_cnt; |
| 176 | unsigned char dpcd_rev[16]; |
| 177 | unsigned char lane_bw[16]; |
| 178 | unsigned char lane_cnt[16]; |
| 179 | |
| 180 | memset(dpcd_rev, 0, 16); |
| 181 | memset(lane_bw, 0, 16); |
| 182 | memset(lane_cnt, 0, 16); |
| 183 | memset(buf, 0, 12); |
| 184 | |
| 185 | retry_cnt = 5; |
| 186 | while (retry_cnt) { |
| 187 | /* Read DPCD 0x0000-0x000b */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 188 | ret = exynos_dp_read_bytes_from_dpcd(regs, DPCD_DPCD_REV, 12, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 189 | buf); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 190 | if (ret != EXYNOS_DP_SUCCESS) { |
| 191 | if (retry_cnt == 0) { |
| 192 | printf("DP read_byte_from_dpcd() failed\n"); |
| 193 | return ret; |
| 194 | } |
| 195 | retry_cnt--; |
| 196 | } else |
| 197 | break; |
| 198 | } |
| 199 | |
| 200 | /* */ |
| 201 | temp = buf[DPCD_DPCD_REV]; |
| 202 | if (temp == DP_DPCD_REV_10 || temp == DP_DPCD_REV_11) |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 203 | priv->dpcd_rev = temp; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 204 | else { |
| 205 | printf("DP Wrong DPCD Rev : %x\n", temp); |
| 206 | return -ENODEV; |
| 207 | } |
| 208 | |
| 209 | temp = buf[DPCD_MAX_LINK_RATE]; |
| 210 | if (temp == DP_LANE_BW_1_62 || temp == DP_LANE_BW_2_70) |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 211 | priv->lane_bw = temp; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 212 | else { |
| 213 | printf("DP Wrong MAX LINK RATE : %x\n", temp); |
| 214 | return -EINVAL; |
| 215 | } |
| 216 | |
Robert P. J. Day | 971abcd | 2015-12-16 11:31:23 -0500 | [diff] [blame] | 217 | /* Refer VESA Display Port Standard Ver1.1a Page 120 */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 218 | if (priv->dpcd_rev == DP_DPCD_REV_11) { |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 219 | temp = buf[DPCD_MAX_LANE_COUNT] & 0x1f; |
| 220 | if (buf[DPCD_MAX_LANE_COUNT] & 0x80) |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 221 | priv->dpcd_efc = 1; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 222 | else |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 223 | priv->dpcd_efc = 0; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 224 | } else { |
| 225 | temp = buf[DPCD_MAX_LANE_COUNT]; |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 226 | priv->dpcd_efc = 0; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | if (temp == DP_LANE_CNT_1 || temp == DP_LANE_CNT_2 || |
| 230 | temp == DP_LANE_CNT_4) { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 231 | priv->lane_cnt = temp; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 232 | } else { |
| 233 | printf("DP Wrong MAX LANE COUNT : %x\n", temp); |
| 234 | return -EINVAL; |
| 235 | } |
| 236 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 237 | ret = exynos_dp_read_edid(regs); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 238 | if (ret != EXYNOS_DP_SUCCESS) { |
| 239 | printf("DP exynos_dp_read_edid() failed\n"); |
| 240 | return -EINVAL; |
| 241 | } |
| 242 | |
| 243 | return ret; |
| 244 | } |
| 245 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 246 | static void exynos_dp_init_training(struct exynos_dp *regs) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 247 | { |
| 248 | /* |
| 249 | * MACRO_RST must be applied after the PLL_LOCK to avoid |
| 250 | * the DP inter pair skew issue for at least 10 us |
| 251 | */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 252 | exynos_dp_reset_macro(regs); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 253 | |
| 254 | /* All DP analog module power up */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 255 | exynos_dp_set_analog_power_down(regs, POWER_ALL, 0); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 258 | static unsigned int exynos_dp_link_start(struct exynos_dp *regs, |
| 259 | struct exynos_dp_priv *priv) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 260 | { |
| 261 | unsigned char buf[5]; |
| 262 | unsigned int ret = 0; |
| 263 | |
| 264 | debug("DP: %s was called\n", __func__); |
| 265 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 266 | priv->lt_info.lt_status = DP_LT_CR; |
| 267 | priv->lt_info.ep_loop = 0; |
| 268 | priv->lt_info.cr_loop[0] = 0; |
| 269 | priv->lt_info.cr_loop[1] = 0; |
| 270 | priv->lt_info.cr_loop[2] = 0; |
| 271 | priv->lt_info.cr_loop[3] = 0; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 272 | |
| 273 | /* Set sink to D0 (Sink Not Ready) mode. */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 274 | ret = exynos_dp_write_byte_to_dpcd(regs, DPCD_SINK_POWER_STATE, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 275 | DPCD_SET_POWER_STATE_D0); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 276 | if (ret != EXYNOS_DP_SUCCESS) { |
| 277 | printf("DP write_dpcd_byte failed\n"); |
| 278 | return ret; |
| 279 | } |
| 280 | |
Robert P. J. Day | 971abcd | 2015-12-16 11:31:23 -0500 | [diff] [blame] | 281 | /* Set link rate and count as you want to establish */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 282 | exynos_dp_set_link_bandwidth(regs, priv->lane_bw); |
| 283 | exynos_dp_set_lane_count(regs, priv->lane_cnt); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 284 | |
| 285 | /* Setup RX configuration */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 286 | buf[0] = priv->lane_bw; |
| 287 | buf[1] = priv->lane_cnt; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 288 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 289 | ret = exynos_dp_write_bytes_to_dpcd(regs, DPCD_LINK_BW_SET, 2, buf); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 290 | if (ret != EXYNOS_DP_SUCCESS) { |
| 291 | printf("DP write_dpcd_byte failed\n"); |
| 292 | return ret; |
| 293 | } |
| 294 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 295 | exynos_dp_set_lane_pre_emphasis(regs, PRE_EMPHASIS_LEVEL_0, |
| 296 | priv->lane_cnt); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 297 | |
| 298 | /* Set training pattern 1 */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 299 | exynos_dp_set_training_pattern(regs, TRAINING_PTN1); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 300 | |
| 301 | /* Set RX training pattern */ |
| 302 | buf[0] = DPCD_SCRAMBLING_DISABLED | DPCD_TRAINING_PATTERN_1; |
| 303 | |
| 304 | buf[1] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 | |
| 305 | DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0; |
| 306 | buf[2] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 | |
| 307 | DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0; |
| 308 | buf[3] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 | |
| 309 | DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0; |
| 310 | buf[4] = DPCD_PRE_EMPHASIS_SET_PATTERN_2_LEVEL_0 | |
| 311 | DPCD_VOLTAGE_SWING_SET_PATTERN_1_LEVEL_0; |
| 312 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 313 | ret = exynos_dp_write_bytes_to_dpcd(regs, DPCD_TRAINING_PATTERN_SET, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 314 | 5, buf); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 315 | if (ret != EXYNOS_DP_SUCCESS) { |
| 316 | printf("DP write_dpcd_byte failed\n"); |
| 317 | return ret; |
| 318 | } |
| 319 | |
| 320 | return ret; |
| 321 | } |
| 322 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 323 | static unsigned int exynos_dp_training_pattern_dis(struct exynos_dp *regs) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 324 | { |
Heinrich Schuchardt | 67be5d7 | 2018-03-19 07:46:08 +0100 | [diff] [blame] | 325 | unsigned int ret; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 326 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 327 | exynos_dp_set_training_pattern(regs, DP_NONE); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 328 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 329 | ret = exynos_dp_write_byte_to_dpcd(regs, DPCD_TRAINING_PATTERN_SET, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 330 | DPCD_TRAINING_PATTERN_DISABLED); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 331 | if (ret != EXYNOS_DP_SUCCESS) { |
Robert P. J. Day | 971abcd | 2015-12-16 11:31:23 -0500 | [diff] [blame] | 332 | printf("DP request_link_training_req failed\n"); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 333 | return -EAGAIN; |
| 334 | } |
| 335 | |
| 336 | return ret; |
| 337 | } |
| 338 | |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 339 | static unsigned int exynos_dp_enable_rx_to_enhanced_mode( |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 340 | struct exynos_dp *regs, unsigned char enable) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 341 | { |
| 342 | unsigned char data; |
Heinrich Schuchardt | 67be5d7 | 2018-03-19 07:46:08 +0100 | [diff] [blame] | 343 | unsigned int ret; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 344 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 345 | ret = exynos_dp_read_byte_from_dpcd(regs, DPCD_LANE_COUNT_SET, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 346 | &data); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 347 | if (ret != EXYNOS_DP_SUCCESS) { |
| 348 | printf("DP read_from_dpcd failed\n"); |
| 349 | return -EAGAIN; |
| 350 | } |
| 351 | |
| 352 | if (enable) |
| 353 | data = DPCD_ENHANCED_FRAME_EN | DPCD_LN_COUNT_SET(data); |
| 354 | else |
| 355 | data = DPCD_LN_COUNT_SET(data); |
| 356 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 357 | ret = exynos_dp_write_byte_to_dpcd(regs, DPCD_LANE_COUNT_SET, data); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 358 | if (ret != EXYNOS_DP_SUCCESS) { |
| 359 | printf("DP write_to_dpcd failed\n"); |
| 360 | return -EAGAIN; |
| 361 | |
| 362 | } |
| 363 | |
| 364 | return ret; |
| 365 | } |
| 366 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 367 | static unsigned int exynos_dp_set_enhanced_mode(struct exynos_dp *regs, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 368 | unsigned char enhance_mode) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 369 | { |
Heinrich Schuchardt | 67be5d7 | 2018-03-19 07:46:08 +0100 | [diff] [blame] | 370 | unsigned int ret; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 371 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 372 | ret = exynos_dp_enable_rx_to_enhanced_mode(regs, enhance_mode); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 373 | if (ret != EXYNOS_DP_SUCCESS) { |
| 374 | printf("DP rx_enhance_mode failed\n"); |
| 375 | return -EAGAIN; |
| 376 | } |
| 377 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 378 | exynos_dp_enable_enhanced_mode(regs, enhance_mode); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 379 | |
| 380 | return ret; |
| 381 | } |
| 382 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 383 | static int exynos_dp_read_dpcd_lane_stat(struct exynos_dp *regs, |
| 384 | struct exynos_dp_priv *priv, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 385 | unsigned char *status) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 386 | { |
| 387 | unsigned int ret, i; |
| 388 | unsigned char buf[2]; |
| 389 | unsigned char lane_stat[DP_LANE_CNT_4] = {0,}; |
| 390 | unsigned char shift_val[DP_LANE_CNT_4] = {0,}; |
| 391 | |
| 392 | shift_val[0] = 0; |
| 393 | shift_val[1] = 4; |
| 394 | shift_val[2] = 0; |
| 395 | shift_val[3] = 4; |
| 396 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 397 | ret = exynos_dp_read_bytes_from_dpcd(regs, DPCD_LANE0_1_STATUS, 2, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 398 | buf); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 399 | if (ret != EXYNOS_DP_SUCCESS) { |
| 400 | printf("DP read lane status failed\n"); |
| 401 | return ret; |
| 402 | } |
| 403 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 404 | for (i = 0; i < priv->lane_cnt; i++) { |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 405 | lane_stat[i] = (buf[(i / 2)] >> shift_val[i]) & 0x0f; |
| 406 | if (lane_stat[0] != lane_stat[i]) { |
| 407 | printf("Wrong lane status\n"); |
| 408 | return -EINVAL; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | *status = lane_stat[0]; |
| 413 | |
| 414 | return ret; |
| 415 | } |
| 416 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 417 | static unsigned int exynos_dp_read_dpcd_adj_req(struct exynos_dp *regs, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 418 | unsigned char lane_num, unsigned char *sw, unsigned char *em) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 419 | { |
Heinrich Schuchardt | 67be5d7 | 2018-03-19 07:46:08 +0100 | [diff] [blame] | 420 | unsigned int ret; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 421 | unsigned char buf; |
| 422 | unsigned int dpcd_addr; |
| 423 | unsigned char shift_val[DP_LANE_CNT_4] = {0, 4, 0, 4}; |
| 424 | |
Robert P. J. Day | 971abcd | 2015-12-16 11:31:23 -0500 | [diff] [blame] | 425 | /* lane_num value is used as array index, so this range 0 ~ 3 */ |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 426 | dpcd_addr = DPCD_ADJUST_REQUEST_LANE0_1 + (lane_num / 2); |
| 427 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 428 | ret = exynos_dp_read_byte_from_dpcd(regs, dpcd_addr, &buf); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 429 | if (ret != EXYNOS_DP_SUCCESS) { |
| 430 | printf("DP read adjust request failed\n"); |
| 431 | return -EAGAIN; |
| 432 | } |
| 433 | |
| 434 | *sw = ((buf >> shift_val[lane_num]) & 0x03); |
| 435 | *em = ((buf >> shift_val[lane_num]) & 0x0c) >> 2; |
| 436 | |
| 437 | return ret; |
| 438 | } |
| 439 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 440 | static int exynos_dp_equalizer_err_link(struct exynos_dp *regs, |
| 441 | struct exynos_dp_priv *priv) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 442 | { |
| 443 | int ret; |
| 444 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 445 | ret = exynos_dp_training_pattern_dis(regs); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 446 | if (ret != EXYNOS_DP_SUCCESS) { |
Robert P. J. Day | 971abcd | 2015-12-16 11:31:23 -0500 | [diff] [blame] | 447 | printf("DP training_pattern_disable() failed\n"); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 448 | priv->lt_info.lt_status = DP_LT_FAIL; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 451 | ret = exynos_dp_set_enhanced_mode(regs, priv->dpcd_efc); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 452 | if (ret != EXYNOS_DP_SUCCESS) { |
| 453 | printf("DP set_enhanced_mode() failed\n"); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 454 | priv->lt_info.lt_status = DP_LT_FAIL; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | return ret; |
| 458 | } |
| 459 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 460 | static int exynos_dp_reduce_link_rate(struct exynos_dp *regs, |
| 461 | struct exynos_dp_priv *priv) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 462 | { |
| 463 | int ret; |
| 464 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 465 | if (priv->lane_bw == DP_LANE_BW_2_70) { |
| 466 | priv->lane_bw = DP_LANE_BW_1_62; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 467 | printf("DP Change lane bw to 1.62Gbps\n"); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 468 | priv->lt_info.lt_status = DP_LT_START; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 469 | ret = EXYNOS_DP_SUCCESS; |
| 470 | } else { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 471 | ret = exynos_dp_training_pattern_dis(regs); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 472 | if (ret != EXYNOS_DP_SUCCESS) |
| 473 | printf("DP training_patter_disable() failed\n"); |
| 474 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 475 | ret = exynos_dp_set_enhanced_mode(regs, priv->dpcd_efc); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 476 | if (ret != EXYNOS_DP_SUCCESS) |
| 477 | printf("DP set_enhanced_mode() failed\n"); |
| 478 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 479 | priv->lt_info.lt_status = DP_LT_FAIL; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | return ret; |
| 483 | } |
| 484 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 485 | static unsigned int exynos_dp_process_clock_recovery(struct exynos_dp *regs, |
| 486 | struct exynos_dp_priv *priv) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 487 | { |
Heinrich Schuchardt | 67be5d7 | 2018-03-19 07:46:08 +0100 | [diff] [blame] | 488 | unsigned int ret; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 489 | unsigned char lane_stat; |
| 490 | unsigned char lt_ctl_val[DP_LANE_CNT_4] = {0, }; |
| 491 | unsigned int i; |
| 492 | unsigned char adj_req_sw; |
| 493 | unsigned char adj_req_em; |
| 494 | unsigned char buf[5]; |
| 495 | |
| 496 | debug("DP: %s was called\n", __func__); |
| 497 | mdelay(1); |
| 498 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 499 | ret = exynos_dp_read_dpcd_lane_stat(regs, priv, &lane_stat); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 500 | if (ret != EXYNOS_DP_SUCCESS) { |
| 501 | printf("DP read lane status failed\n"); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 502 | priv->lt_info.lt_status = DP_LT_FAIL; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 503 | return ret; |
| 504 | } |
| 505 | |
| 506 | if (lane_stat & DP_LANE_STAT_CR_DONE) { |
| 507 | debug("DP clock Recovery training succeed\n"); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 508 | exynos_dp_set_training_pattern(regs, TRAINING_PTN2); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 509 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 510 | for (i = 0; i < priv->lane_cnt; i++) { |
| 511 | ret = exynos_dp_read_dpcd_adj_req(regs, i, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 512 | &adj_req_sw, &adj_req_em); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 513 | if (ret != EXYNOS_DP_SUCCESS) { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 514 | priv->lt_info.lt_status = DP_LT_FAIL; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 515 | return ret; |
| 516 | } |
| 517 | |
| 518 | lt_ctl_val[i] = 0; |
| 519 | lt_ctl_val[i] = adj_req_em << 3 | adj_req_sw; |
| 520 | |
| 521 | if ((adj_req_sw == VOLTAGE_LEVEL_3) |
| 522 | || (adj_req_em == PRE_EMPHASIS_LEVEL_3)) { |
| 523 | lt_ctl_val[i] |= MAX_DRIVE_CURRENT_REACH_3 | |
| 524 | MAX_PRE_EMPHASIS_REACH_3; |
| 525 | } |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 526 | exynos_dp_set_lanex_pre_emphasis(regs, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 527 | lt_ctl_val[i], i); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | buf[0] = DPCD_SCRAMBLING_DISABLED | DPCD_TRAINING_PATTERN_2; |
| 531 | buf[1] = lt_ctl_val[0]; |
| 532 | buf[2] = lt_ctl_val[1]; |
| 533 | buf[3] = lt_ctl_val[2]; |
| 534 | buf[4] = lt_ctl_val[3]; |
| 535 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 536 | ret = exynos_dp_write_bytes_to_dpcd(regs, |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 537 | DPCD_TRAINING_PATTERN_SET, 5, buf); |
| 538 | if (ret != EXYNOS_DP_SUCCESS) { |
Robert P. J. Day | 971abcd | 2015-12-16 11:31:23 -0500 | [diff] [blame] | 539 | printf("DP write training pattern1 failed\n"); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 540 | priv->lt_info.lt_status = DP_LT_FAIL; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 541 | return ret; |
| 542 | } else |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 543 | priv->lt_info.lt_status = DP_LT_ET; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 544 | } else { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 545 | for (i = 0; i < priv->lane_cnt; i++) { |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 546 | lt_ctl_val[i] = exynos_dp_get_lanex_pre_emphasis( |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 547 | regs, i); |
| 548 | ret = exynos_dp_read_dpcd_adj_req(regs, i, |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 549 | &adj_req_sw, &adj_req_em); |
| 550 | if (ret != EXYNOS_DP_SUCCESS) { |
| 551 | printf("DP read adj req failed\n"); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 552 | priv->lt_info.lt_status = DP_LT_FAIL; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 553 | return ret; |
| 554 | } |
| 555 | |
| 556 | if ((adj_req_sw == VOLTAGE_LEVEL_3) || |
| 557 | (adj_req_em == PRE_EMPHASIS_LEVEL_3)) |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 558 | ret = exynos_dp_reduce_link_rate(regs, |
| 559 | priv); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 560 | |
| 561 | if ((DRIVE_CURRENT_SET_0_GET(lt_ctl_val[i]) == |
| 562 | adj_req_sw) && |
| 563 | (PRE_EMPHASIS_SET_0_GET(lt_ctl_val[i]) == |
| 564 | adj_req_em)) { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 565 | priv->lt_info.cr_loop[i]++; |
| 566 | if (priv->lt_info.cr_loop[i] == MAX_CR_LOOP) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 567 | ret = exynos_dp_reduce_link_rate( |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 568 | regs, priv); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | lt_ctl_val[i] = 0; |
| 572 | lt_ctl_val[i] = adj_req_em << 3 | adj_req_sw; |
| 573 | |
| 574 | if ((adj_req_sw == VOLTAGE_LEVEL_3) || |
| 575 | (adj_req_em == PRE_EMPHASIS_LEVEL_3)) { |
| 576 | lt_ctl_val[i] |= MAX_DRIVE_CURRENT_REACH_3 | |
| 577 | MAX_PRE_EMPHASIS_REACH_3; |
| 578 | } |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 579 | exynos_dp_set_lanex_pre_emphasis(regs, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 580 | lt_ctl_val[i], i); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 581 | } |
| 582 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 583 | ret = exynos_dp_write_bytes_to_dpcd(regs, |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 584 | DPCD_TRAINING_LANE0_SET, 4, lt_ctl_val); |
| 585 | if (ret != EXYNOS_DP_SUCCESS) { |
Robert P. J. Day | 971abcd | 2015-12-16 11:31:23 -0500 | [diff] [blame] | 586 | printf("DP write training pattern2 failed\n"); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 587 | priv->lt_info.lt_status = DP_LT_FAIL; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 588 | return ret; |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | return ret; |
| 593 | } |
| 594 | |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 595 | static unsigned int exynos_dp_process_equalizer_training( |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 596 | struct exynos_dp *regs, struct exynos_dp_priv *priv) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 597 | { |
Heinrich Schuchardt | 67be5d7 | 2018-03-19 07:46:08 +0100 | [diff] [blame] | 598 | unsigned int ret; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 599 | unsigned char lane_stat, adj_req_sw, adj_req_em, i; |
| 600 | unsigned char lt_ctl_val[DP_LANE_CNT_4] = {0,}; |
| 601 | unsigned char interlane_aligned = 0; |
| 602 | unsigned char f_bw; |
| 603 | unsigned char f_lane_cnt; |
| 604 | unsigned char sink_stat; |
| 605 | |
| 606 | mdelay(1); |
| 607 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 608 | ret = exynos_dp_read_dpcd_lane_stat(regs, priv, &lane_stat); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 609 | if (ret != EXYNOS_DP_SUCCESS) { |
| 610 | printf("DP read lane status failed\n"); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 611 | priv->lt_info.lt_status = DP_LT_FAIL; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 612 | return ret; |
| 613 | } |
| 614 | |
| 615 | debug("DP lane stat : %x\n", lane_stat); |
| 616 | |
| 617 | if (lane_stat & DP_LANE_STAT_CR_DONE) { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 618 | ret = exynos_dp_read_byte_from_dpcd(regs, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 619 | DPCD_LN_ALIGN_UPDATED, |
| 620 | &sink_stat); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 621 | if (ret != EXYNOS_DP_SUCCESS) { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 622 | priv->lt_info.lt_status = DP_LT_FAIL; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 623 | |
| 624 | return ret; |
| 625 | } |
| 626 | |
| 627 | interlane_aligned = (sink_stat & DPCD_INTERLANE_ALIGN_DONE); |
| 628 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 629 | for (i = 0; i < priv->lane_cnt; i++) { |
| 630 | ret = exynos_dp_read_dpcd_adj_req(regs, i, |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 631 | &adj_req_sw, &adj_req_em); |
| 632 | if (ret != EXYNOS_DP_SUCCESS) { |
| 633 | printf("DP read adj req 1 failed\n"); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 634 | priv->lt_info.lt_status = DP_LT_FAIL; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 635 | |
| 636 | return ret; |
| 637 | } |
| 638 | |
| 639 | lt_ctl_val[i] = 0; |
| 640 | lt_ctl_val[i] = adj_req_em << 3 | adj_req_sw; |
| 641 | |
| 642 | if ((adj_req_sw == VOLTAGE_LEVEL_3) || |
| 643 | (adj_req_em == PRE_EMPHASIS_LEVEL_3)) { |
| 644 | lt_ctl_val[i] |= MAX_DRIVE_CURRENT_REACH_3; |
| 645 | lt_ctl_val[i] |= MAX_PRE_EMPHASIS_REACH_3; |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | if (((lane_stat&DP_LANE_STAT_CE_DONE) && |
| 650 | (lane_stat&DP_LANE_STAT_SYM_LOCK)) |
| 651 | && (interlane_aligned == DPCD_INTERLANE_ALIGN_DONE)) { |
| 652 | debug("DP Equalizer training succeed\n"); |
| 653 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 654 | f_bw = exynos_dp_get_link_bandwidth(regs); |
| 655 | f_lane_cnt = exynos_dp_get_lane_count(regs); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 656 | |
| 657 | debug("DP final BandWidth : %x\n", f_bw); |
| 658 | debug("DP final Lane Count : %x\n", f_lane_cnt); |
| 659 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 660 | priv->lt_info.lt_status = DP_LT_FINISHED; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 661 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 662 | exynos_dp_equalizer_err_link(regs, priv); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 663 | |
| 664 | } else { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 665 | priv->lt_info.ep_loop++; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 666 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 667 | if (priv->lt_info.ep_loop > MAX_EQ_LOOP) { |
| 668 | if (priv->lane_bw == DP_LANE_BW_2_70) { |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 669 | ret = exynos_dp_reduce_link_rate( |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 670 | regs, priv); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 671 | } else { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 672 | priv->lt_info.lt_status = |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 673 | DP_LT_FAIL; |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 674 | exynos_dp_equalizer_err_link(regs, |
| 675 | priv); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 676 | } |
| 677 | } else { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 678 | for (i = 0; i < priv->lane_cnt; i++) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 679 | exynos_dp_set_lanex_pre_emphasis( |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 680 | regs, lt_ctl_val[i], i); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 681 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 682 | ret = exynos_dp_write_bytes_to_dpcd(regs, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 683 | DPCD_TRAINING_LANE0_SET, |
| 684 | 4, lt_ctl_val); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 685 | if (ret != EXYNOS_DP_SUCCESS) { |
| 686 | printf("DP set lt pattern failed\n"); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 687 | priv->lt_info.lt_status = |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 688 | DP_LT_FAIL; |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 689 | exynos_dp_equalizer_err_link(regs, |
| 690 | priv); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | } |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 694 | } else if (priv->lane_bw == DP_LANE_BW_2_70) { |
| 695 | ret = exynos_dp_reduce_link_rate(regs, priv); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 696 | } else { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 697 | priv->lt_info.lt_status = DP_LT_FAIL; |
| 698 | exynos_dp_equalizer_err_link(regs, priv); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | return ret; |
| 702 | } |
| 703 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 704 | static unsigned int exynos_dp_sw_link_training(struct exynos_dp *regs, |
| 705 | struct exynos_dp_priv *priv) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 706 | { |
| 707 | unsigned int ret = 0; |
| 708 | int training_finished; |
| 709 | |
| 710 | /* Turn off unnecessary lane */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 711 | if (priv->lane_cnt == 1) |
| 712 | exynos_dp_set_analog_power_down(regs, CH1_BLOCK, 1); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 713 | |
| 714 | training_finished = 0; |
| 715 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 716 | priv->lt_info.lt_status = DP_LT_START; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 717 | |
| 718 | /* Process here */ |
| 719 | while (!training_finished) { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 720 | switch (priv->lt_info.lt_status) { |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 721 | case DP_LT_START: |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 722 | ret = exynos_dp_link_start(regs, priv); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 723 | if (ret != EXYNOS_DP_SUCCESS) { |
| 724 | printf("DP LT:link start failed\n"); |
| 725 | return ret; |
| 726 | } |
| 727 | break; |
| 728 | case DP_LT_CR: |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 729 | ret = exynos_dp_process_clock_recovery(regs, |
| 730 | priv); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 731 | if (ret != EXYNOS_DP_SUCCESS) { |
| 732 | printf("DP LT:clock recovery failed\n"); |
| 733 | return ret; |
| 734 | } |
| 735 | break; |
| 736 | case DP_LT_ET: |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 737 | ret = exynos_dp_process_equalizer_training(regs, |
| 738 | priv); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 739 | if (ret != EXYNOS_DP_SUCCESS) { |
| 740 | printf("DP LT:equalizer training failed\n"); |
| 741 | return ret; |
| 742 | } |
| 743 | break; |
| 744 | case DP_LT_FINISHED: |
| 745 | training_finished = 1; |
| 746 | break; |
| 747 | case DP_LT_FAIL: |
| 748 | return -1; |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | return ret; |
| 753 | } |
| 754 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 755 | static unsigned int exynos_dp_set_link_train(struct exynos_dp *regs, |
| 756 | struct exynos_dp_priv *priv) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 757 | { |
| 758 | unsigned int ret; |
| 759 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 760 | exynos_dp_init_training(regs); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 761 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 762 | ret = exynos_dp_sw_link_training(regs, priv); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 763 | if (ret != EXYNOS_DP_SUCCESS) |
Robert P. J. Day | 971abcd | 2015-12-16 11:31:23 -0500 | [diff] [blame] | 764 | printf("DP dp_sw_link_training() failed\n"); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 765 | |
| 766 | return ret; |
| 767 | } |
| 768 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 769 | static void exynos_dp_enable_scramble(struct exynos_dp *regs, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 770 | unsigned int enable) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 771 | { |
| 772 | unsigned char data; |
| 773 | |
| 774 | if (enable) { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 775 | exynos_dp_enable_scrambling(regs, DP_ENABLE); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 776 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 777 | exynos_dp_read_byte_from_dpcd(regs, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 778 | DPCD_TRAINING_PATTERN_SET, &data); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 779 | exynos_dp_write_byte_to_dpcd(regs, DPCD_TRAINING_PATTERN_SET, |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 780 | (u8)(data & ~DPCD_SCRAMBLING_DISABLED)); |
| 781 | } else { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 782 | exynos_dp_enable_scrambling(regs, DP_DISABLE); |
| 783 | exynos_dp_read_byte_from_dpcd(regs, |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 784 | DPCD_TRAINING_PATTERN_SET, &data); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 785 | exynos_dp_write_byte_to_dpcd(regs, DPCD_TRAINING_PATTERN_SET, |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 786 | (u8)(data | DPCD_SCRAMBLING_DISABLED)); |
| 787 | } |
| 788 | } |
| 789 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 790 | static unsigned int exynos_dp_config_video(struct exynos_dp *regs, |
| 791 | struct exynos_dp_priv *priv) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 792 | { |
| 793 | unsigned int ret = 0; |
| 794 | unsigned int retry_cnt; |
| 795 | |
| 796 | mdelay(1); |
| 797 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 798 | if (priv->video_info.master_mode) { |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 799 | printf("DP does not support master mode\n"); |
| 800 | return -ENODEV; |
| 801 | } else { |
| 802 | /* debug slave */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 803 | exynos_dp_config_video_slave_mode(regs, |
| 804 | &priv->video_info); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 807 | exynos_dp_set_video_color_format(regs, &priv->video_info); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 808 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 809 | if (priv->video_info.bist_mode) { |
| 810 | if (exynos_dp_config_video_bist(regs, priv) != 0) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 811 | return -1; |
| 812 | } |
| 813 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 814 | ret = exynos_dp_get_pll_lock_status(regs); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 815 | if (ret != PLL_LOCKED) { |
| 816 | printf("DP PLL is not locked yet\n"); |
| 817 | return -EIO; |
| 818 | } |
| 819 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 820 | if (priv->video_info.master_mode == 0) { |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 821 | retry_cnt = 10; |
| 822 | while (retry_cnt) { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 823 | ret = exynos_dp_is_slave_video_stream_clock_on(regs); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 824 | if (ret != EXYNOS_DP_SUCCESS) { |
| 825 | if (retry_cnt == 0) { |
| 826 | printf("DP stream_clock_on failed\n"); |
| 827 | return ret; |
| 828 | } |
| 829 | retry_cnt--; |
| 830 | mdelay(1); |
| 831 | } else |
| 832 | break; |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | /* Set to use the register calculated M/N video */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 837 | exynos_dp_set_video_cr_mn(regs, CALCULATED_M, 0, 0); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 838 | |
| 839 | /* For video bist, Video timing must be generated by register */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 840 | exynos_dp_set_video_timing_mode(regs, VIDEO_TIMING_FROM_CAPTURE); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 841 | |
| 842 | /* Enable video bist */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 843 | if (priv->video_info.bist_pattern != COLOR_RAMP && |
| 844 | priv->video_info.bist_pattern != BALCK_WHITE_V_LINES && |
| 845 | priv->video_info.bist_pattern != COLOR_SQUARE) |
| 846 | exynos_dp_enable_video_bist(regs, |
| 847 | priv->video_info.bist_mode); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 848 | else |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 849 | exynos_dp_enable_video_bist(regs, DP_DISABLE); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 850 | |
| 851 | /* Disable video mute */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 852 | exynos_dp_enable_video_mute(regs, DP_DISABLE); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 853 | |
| 854 | /* Configure video Master or Slave mode */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 855 | exynos_dp_enable_video_master(regs, |
| 856 | priv->video_info.master_mode); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 857 | |
| 858 | /* Enable video */ |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 859 | exynos_dp_start_video(regs); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 860 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 861 | if (priv->video_info.master_mode == 0) { |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 862 | retry_cnt = 100; |
| 863 | while (retry_cnt) { |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 864 | ret = exynos_dp_is_video_stream_on(regs); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 865 | if (ret != EXYNOS_DP_SUCCESS) { |
| 866 | if (retry_cnt == 0) { |
| 867 | printf("DP Timeout of video stream\n"); |
| 868 | return ret; |
| 869 | } |
| 870 | retry_cnt--; |
| 871 | mdelay(5); |
| 872 | } else |
| 873 | break; |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | return ret; |
| 878 | } |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 879 | |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 880 | static int exynos_dp_ofdata_to_platdata(struct udevice *dev) |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 881 | { |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 882 | struct exynos_dp_priv *priv = dev_get_priv(dev); |
| 883 | const void *blob = gd->fdt_blob; |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 884 | unsigned int node = dev_of_offset(dev); |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 885 | fdt_addr_t addr; |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 886 | |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 887 | addr = dev_read_addr(dev); |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 888 | if (addr == FDT_ADDR_T_NONE) { |
| 889 | debug("Can't get the DP base address\n"); |
| 890 | return -EINVAL; |
| 891 | } |
| 892 | priv->regs = (struct exynos_dp *)addr; |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 893 | priv->disp_info.h_res = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 894 | "samsung,h-res", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 895 | priv->disp_info.h_sync_width = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 896 | "samsung,h-sync-width", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 897 | priv->disp_info.h_back_porch = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 898 | "samsung,h-back-porch", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 899 | priv->disp_info.h_front_porch = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 900 | "samsung,h-front-porch", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 901 | priv->disp_info.v_res = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 902 | "samsung,v-res", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 903 | priv->disp_info.v_sync_width = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 904 | "samsung,v-sync-width", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 905 | priv->disp_info.v_back_porch = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 906 | "samsung,v-back-porch", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 907 | priv->disp_info.v_front_porch = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 908 | "samsung,v-front-porch", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 909 | priv->disp_info.v_sync_rate = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 910 | "samsung,v-sync-rate", 0); |
| 911 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 912 | priv->lt_info.lt_status = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 913 | "samsung,lt-status", 0); |
| 914 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 915 | priv->video_info.master_mode = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 916 | "samsung,master-mode", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 917 | priv->video_info.bist_mode = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 918 | "samsung,bist-mode", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 919 | priv->video_info.bist_pattern = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 920 | "samsung,bist-pattern", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 921 | priv->video_info.h_sync_polarity = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 922 | "samsung,h-sync-polarity", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 923 | priv->video_info.v_sync_polarity = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 924 | "samsung,v-sync-polarity", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 925 | priv->video_info.interlaced = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 926 | "samsung,interlaced", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 927 | priv->video_info.color_space = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 928 | "samsung,color-space", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 929 | priv->video_info.dynamic_range = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 930 | "samsung,dynamic-range", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 931 | priv->video_info.ycbcr_coeff = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 932 | "samsung,ycbcr-coeff", 0); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 933 | priv->video_info.color_depth = fdtdec_get_int(blob, node, |
Ajay Kumar | 65f50f9 | 2013-02-21 23:53:06 +0000 | [diff] [blame] | 934 | "samsung,color-depth", 0); |
| 935 | return 0; |
| 936 | } |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 937 | |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 938 | static int exynos_dp_bridge_init(struct udevice *dev) |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 939 | { |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 940 | const int max_tries = 10; |
| 941 | int num_tries; |
| 942 | int ret; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 943 | |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 944 | debug("%s\n", __func__); |
| 945 | ret = video_bridge_attach(dev); |
| 946 | if (ret) { |
| 947 | debug("video bridge init failed: %d\n", ret); |
| 948 | return ret; |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 949 | } |
| 950 | |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 951 | /* |
| 952 | * We need to wait for 90ms after bringing up the bridge since there |
| 953 | * is a phantom "high" on the HPD chip during its bootup. The phantom |
| 954 | * high comes within 7ms of de-asserting PD and persists for at least |
| 955 | * 15ms. The real high comes roughly 50ms after PD is de-asserted. The |
| 956 | * phantom high makes it hard for us to know when the NXP chip is up. |
| 957 | */ |
| 958 | mdelay(90); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 959 | |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 960 | for (num_tries = 0; num_tries < max_tries; num_tries++) { |
| 961 | /* Check HPD. If it's high, or we don't have it, all is well */ |
| 962 | ret = video_bridge_check_attached(dev); |
| 963 | if (!ret || ret == -ENOENT) |
| 964 | return 0; |
Simon Glass | 0de7089 | 2016-02-21 21:08:44 -0700 | [diff] [blame] | 965 | |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 966 | debug("%s: eDP bridge failed to come up; try %d of %d\n", |
| 967 | __func__, num_tries, max_tries); |
| 968 | } |
Ajay Kumar | ca7c3e1 | 2013-02-21 23:53:04 +0000 | [diff] [blame] | 969 | |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 970 | /* Immediately go into bridge reset if the hp line is not high */ |
| 971 | return -EIO; |
| 972 | } |
| 973 | |
| 974 | static int exynos_dp_bridge_setup(const void *blob) |
| 975 | { |
| 976 | const int max_tries = 2; |
| 977 | int num_tries; |
| 978 | struct udevice *dev; |
| 979 | int ret; |
| 980 | |
| 981 | /* Configure I2C registers for Parade bridge */ |
| 982 | ret = uclass_get_device(UCLASS_VIDEO_BRIDGE, 0, &dev); |
| 983 | if (ret) { |
| 984 | debug("video bridge init failed: %d\n", ret); |
| 985 | return ret; |
| 986 | } |
| 987 | |
| 988 | if (strncmp(dev->driver->name, "parade", 6)) { |
| 989 | /* Mux HPHPD to the special hotplug detect mode */ |
| 990 | exynos_pinmux_config(PERIPH_ID_DPHPD, 0); |
| 991 | } |
| 992 | |
| 993 | for (num_tries = 0; num_tries < max_tries; num_tries++) { |
| 994 | ret = exynos_dp_bridge_init(dev); |
| 995 | if (!ret) |
| 996 | return 0; |
| 997 | if (num_tries == max_tries - 1) |
| 998 | break; |
| 999 | |
| 1000 | /* |
| 1001 | * If we're here, the bridge chip failed to initialise. |
| 1002 | * Power down the bridge in an attempt to reset. |
| 1003 | */ |
| 1004 | video_bridge_set_active(dev, false); |
| 1005 | |
| 1006 | /* |
| 1007 | * Arbitrarily wait 300ms here with DP_N low. Don't know for |
| 1008 | * sure how long we should wait, but we're being paranoid. |
| 1009 | */ |
| 1010 | mdelay(300); |
| 1011 | } |
| 1012 | |
| 1013 | return ret; |
| 1014 | } |
| 1015 | int exynos_dp_enable(struct udevice *dev, int panel_bpp, |
| 1016 | const struct display_timing *timing) |
| 1017 | { |
| 1018 | struct exynos_dp_priv *priv = dev_get_priv(dev); |
| 1019 | struct exynos_dp *regs = priv->regs; |
| 1020 | unsigned int ret; |
| 1021 | |
| 1022 | debug("%s: start\n", __func__); |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 1023 | exynos_dp_disp_info(&priv->disp_info); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 1024 | |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 1025 | ret = exynos_dp_bridge_setup(gd->fdt_blob); |
| 1026 | if (ret && ret != -ENODEV) |
| 1027 | printf("LCD bridge failed to enable: %d\n", ret); |
| 1028 | |
Simon Glass | bfd239c | 2016-02-21 21:08:57 -0700 | [diff] [blame] | 1029 | exynos_dp_phy_ctrl(1); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 1030 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 1031 | ret = exynos_dp_init_dp(regs); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 1032 | if (ret != EXYNOS_DP_SUCCESS) { |
| 1033 | printf("DP exynos_dp_init_dp() failed\n"); |
| 1034 | return ret; |
| 1035 | } |
| 1036 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 1037 | ret = exynos_dp_handle_edid(regs, priv); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 1038 | if (ret != EXYNOS_DP_SUCCESS) { |
| 1039 | printf("EDP handle_edid fail\n"); |
| 1040 | return ret; |
| 1041 | } |
| 1042 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 1043 | ret = exynos_dp_set_link_train(regs, priv); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 1044 | if (ret != EXYNOS_DP_SUCCESS) { |
| 1045 | printf("DP link training fail\n"); |
| 1046 | return ret; |
| 1047 | } |
| 1048 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 1049 | exynos_dp_enable_scramble(regs, DP_ENABLE); |
| 1050 | exynos_dp_enable_rx_to_enhanced_mode(regs, DP_ENABLE); |
| 1051 | exynos_dp_enable_enhanced_mode(regs, DP_ENABLE); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 1052 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 1053 | exynos_dp_set_link_bandwidth(regs, priv->lane_bw); |
| 1054 | exynos_dp_set_lane_count(regs, priv->lane_cnt); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 1055 | |
Simon Glass | 305f581 | 2016-02-21 21:09:00 -0700 | [diff] [blame] | 1056 | exynos_dp_init_video(regs); |
| 1057 | ret = exynos_dp_config_video(regs, priv); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 1058 | if (ret != EXYNOS_DP_SUCCESS) { |
| 1059 | printf("Exynos DP init failed\n"); |
| 1060 | return ret; |
| 1061 | } |
| 1062 | |
Simon Glass | 5e7ab07 | 2015-07-02 18:16:14 -0600 | [diff] [blame] | 1063 | debug("Exynos DP init done\n"); |
Donghwa Lee | b73a88b | 2012-07-02 01:16:02 +0000 | [diff] [blame] | 1064 | |
| 1065 | return ret; |
| 1066 | } |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 1067 | |
| 1068 | |
| 1069 | static const struct dm_display_ops exynos_dp_ops = { |
| 1070 | .enable = exynos_dp_enable, |
| 1071 | }; |
| 1072 | |
| 1073 | static const struct udevice_id exynos_dp_ids[] = { |
| 1074 | { .compatible = "samsung,exynos5-dp" }, |
| 1075 | { } |
| 1076 | }; |
| 1077 | |
| 1078 | U_BOOT_DRIVER(exynos_dp) = { |
Dongjin Kim | e51b777 | 2017-10-27 23:08:51 -0400 | [diff] [blame] | 1079 | .name = "exynos_dp", |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 1080 | .id = UCLASS_DISPLAY, |
| 1081 | .of_match = exynos_dp_ids, |
| 1082 | .ops = &exynos_dp_ops, |
| 1083 | .ofdata_to_platdata = exynos_dp_ofdata_to_platdata, |
| 1084 | .priv_auto_alloc_size = sizeof(struct exynos_dp_priv), |
| 1085 | }; |