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