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