| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved. |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 5 | | - * it under the terms of the GNU General Public License version 2 and |
|---|
| 6 | | - * only version 2 as published by the Free Software Foundation. |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 9 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | | - * GNU General Public License for more details. |
|---|
| 12 | 4 | */ |
|---|
| 13 | 5 | |
|---|
| 14 | 6 | #include <linux/clk.h> |
|---|
| .. | .. |
|---|
| 97 | 89 | /* edid raw data */ |
|---|
| 98 | 90 | struct edid *edid; |
|---|
| 99 | 91 | |
|---|
| 100 | | - struct drm_dp_link dp_link; |
|---|
| 101 | 92 | struct drm_dp_aux *drm_aux; |
|---|
| 102 | 93 | |
|---|
| 103 | 94 | /* dpcd raw data */ |
|---|
| .. | .. |
|---|
| 411 | 402 | u32 prate; |
|---|
| 412 | 403 | u32 lrate; |
|---|
| 413 | 404 | u32 bpp; |
|---|
| 414 | | - u8 max_lane = ctrl->dp_link.num_lanes; |
|---|
| 405 | + u8 max_lane = drm_dp_max_lane_count(ctrl->dpcd); |
|---|
| 415 | 406 | u8 lane; |
|---|
| 416 | 407 | |
|---|
| 417 | 408 | prate = ctrl->pixel_rate; |
|---|
| .. | .. |
|---|
| 421 | 412 | * By default, use the maximum link rate and minimum lane count, |
|---|
| 422 | 413 | * so that we can do rate down shift during link training. |
|---|
| 423 | 414 | */ |
|---|
| 424 | | - ctrl->link_rate = drm_dp_link_rate_to_bw_code(ctrl->dp_link.rate); |
|---|
| 415 | + ctrl->link_rate = ctrl->dpcd[DP_MAX_LINK_RATE]; |
|---|
| 425 | 416 | |
|---|
| 426 | 417 | prate *= bpp; |
|---|
| 427 | 418 | prate /= 8; /* in kByte */ |
|---|
| .. | .. |
|---|
| 447 | 438 | |
|---|
| 448 | 439 | data = EDP_CONFIGURATION_CTRL_LANES(ctrl->lane_cnt - 1); |
|---|
| 449 | 440 | |
|---|
| 450 | | - if (ctrl->dp_link.capabilities & DP_LINK_CAP_ENHANCED_FRAMING) |
|---|
| 441 | + if (drm_dp_enhanced_frame_cap(ctrl->dpcd)) |
|---|
| 451 | 442 | data |= EDP_CONFIGURATION_CTRL_ENHANCED_FRAMING; |
|---|
| 452 | 443 | |
|---|
| 453 | 444 | depth = EDP_6BIT; |
|---|
| .. | .. |
|---|
| 709 | 700 | |
|---|
| 710 | 701 | rate = ctrl->link_rate; |
|---|
| 711 | 702 | lane = ctrl->lane_cnt; |
|---|
| 712 | | - max_lane = ctrl->dp_link.num_lanes; |
|---|
| 703 | + max_lane = drm_dp_max_lane_count(ctrl->dpcd); |
|---|
| 713 | 704 | |
|---|
| 714 | 705 | bpp = ctrl->color_depth * 3; |
|---|
| 715 | 706 | prate = ctrl->pixel_rate; |
|---|
| .. | .. |
|---|
| 759 | 750 | |
|---|
| 760 | 751 | static int edp_do_link_train(struct edp_ctrl *ctrl) |
|---|
| 761 | 752 | { |
|---|
| 753 | + u8 values[2]; |
|---|
| 762 | 754 | int ret; |
|---|
| 763 | | - struct drm_dp_link dp_link; |
|---|
| 764 | 755 | |
|---|
| 765 | 756 | DBG(""); |
|---|
| 766 | 757 | /* |
|---|
| 767 | 758 | * Set the current link rate and lane cnt to panel. They may have been |
|---|
| 768 | 759 | * adjusted and the values are different from them in DPCD CAP |
|---|
| 769 | 760 | */ |
|---|
| 770 | | - dp_link.num_lanes = ctrl->lane_cnt; |
|---|
| 771 | | - dp_link.rate = drm_dp_bw_code_to_link_rate(ctrl->link_rate); |
|---|
| 772 | | - dp_link.capabilities = ctrl->dp_link.capabilities; |
|---|
| 773 | | - if (drm_dp_link_configure(ctrl->drm_aux, &dp_link) < 0) |
|---|
| 761 | + values[0] = ctrl->lane_cnt; |
|---|
| 762 | + values[1] = ctrl->link_rate; |
|---|
| 763 | + |
|---|
| 764 | + if (drm_dp_enhanced_frame_cap(ctrl->dpcd)) |
|---|
| 765 | + values[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN; |
|---|
| 766 | + |
|---|
| 767 | + if (drm_dp_dpcd_write(ctrl->drm_aux, DP_LINK_BW_SET, values, |
|---|
| 768 | + sizeof(values)) < 0) |
|---|
| 774 | 769 | return EDP_TRAIN_FAIL; |
|---|
| 775 | 770 | |
|---|
| 776 | 771 | ctrl->v_level = 0; /* start from default level */ |
|---|
| .. | .. |
|---|
| 960 | 955 | { |
|---|
| 961 | 956 | struct edp_ctrl *ctrl = container_of( |
|---|
| 962 | 957 | work, struct edp_ctrl, on_work); |
|---|
| 958 | + u8 value; |
|---|
| 963 | 959 | int ret; |
|---|
| 964 | 960 | |
|---|
| 965 | 961 | mutex_lock(&ctrl->dev_mutex); |
|---|
| .. | .. |
|---|
| 973 | 969 | edp_ctrl_link_enable(ctrl, 1); |
|---|
| 974 | 970 | |
|---|
| 975 | 971 | edp_ctrl_irq_enable(ctrl, 1); |
|---|
| 976 | | - ret = drm_dp_link_power_up(ctrl->drm_aux, &ctrl->dp_link); |
|---|
| 977 | | - if (ret) |
|---|
| 978 | | - goto fail; |
|---|
| 972 | + |
|---|
| 973 | + /* DP_SET_POWER register is only available on DPCD v1.1 and later */ |
|---|
| 974 | + if (ctrl->dpcd[DP_DPCD_REV] >= 0x11) { |
|---|
| 975 | + ret = drm_dp_dpcd_readb(ctrl->drm_aux, DP_SET_POWER, &value); |
|---|
| 976 | + if (ret < 0) |
|---|
| 977 | + goto fail; |
|---|
| 978 | + |
|---|
| 979 | + value &= ~DP_SET_POWER_MASK; |
|---|
| 980 | + value |= DP_SET_POWER_D0; |
|---|
| 981 | + |
|---|
| 982 | + ret = drm_dp_dpcd_writeb(ctrl->drm_aux, DP_SET_POWER, value); |
|---|
| 983 | + if (ret < 0) |
|---|
| 984 | + goto fail; |
|---|
| 985 | + |
|---|
| 986 | + /* |
|---|
| 987 | + * According to the DP 1.1 specification, a "Sink Device must |
|---|
| 988 | + * exit the power saving state within 1 ms" (Section 2.5.3.1, |
|---|
| 989 | + * Table 5-52, "Sink Control Field" (register 0x600). |
|---|
| 990 | + */ |
|---|
| 991 | + usleep_range(1000, 2000); |
|---|
| 992 | + } |
|---|
| 979 | 993 | |
|---|
| 980 | 994 | ctrl->power_on = true; |
|---|
| 981 | 995 | |
|---|
| .. | .. |
|---|
| 1019 | 1033 | |
|---|
| 1020 | 1034 | edp_state_ctrl(ctrl, 0); |
|---|
| 1021 | 1035 | |
|---|
| 1022 | | - drm_dp_link_power_down(ctrl->drm_aux, &ctrl->dp_link); |
|---|
| 1036 | + /* DP_SET_POWER register is only available on DPCD v1.1 and later */ |
|---|
| 1037 | + if (ctrl->dpcd[DP_DPCD_REV] >= 0x11) { |
|---|
| 1038 | + u8 value; |
|---|
| 1039 | + int ret; |
|---|
| 1040 | + |
|---|
| 1041 | + ret = drm_dp_dpcd_readb(ctrl->drm_aux, DP_SET_POWER, &value); |
|---|
| 1042 | + if (ret > 0) { |
|---|
| 1043 | + value &= ~DP_SET_POWER_MASK; |
|---|
| 1044 | + value |= DP_SET_POWER_D3; |
|---|
| 1045 | + |
|---|
| 1046 | + drm_dp_dpcd_writeb(ctrl->drm_aux, DP_SET_POWER, value); |
|---|
| 1047 | + } |
|---|
| 1048 | + } |
|---|
| 1023 | 1049 | |
|---|
| 1024 | 1050 | edp_ctrl_irq_enable(ctrl, 0); |
|---|
| 1025 | 1051 | |
|---|
| .. | .. |
|---|
| 1234 | 1260 | edp_ctrl_irq_enable(ctrl, 1); |
|---|
| 1235 | 1261 | } |
|---|
| 1236 | 1262 | |
|---|
| 1237 | | - ret = drm_dp_link_probe(ctrl->drm_aux, &ctrl->dp_link); |
|---|
| 1238 | | - if (ret) { |
|---|
| 1239 | | - pr_err("%s: read dpcd cap failed, %d\n", __func__, ret); |
|---|
| 1240 | | - goto disable_ret; |
|---|
| 1241 | | - } |
|---|
| 1242 | | - |
|---|
| 1243 | 1263 | /* Initialize link rate as panel max link rate */ |
|---|
| 1244 | | - ctrl->link_rate = drm_dp_link_rate_to_bw_code(ctrl->dp_link.rate); |
|---|
| 1264 | + ctrl->link_rate = ctrl->dpcd[DP_MAX_LINK_RATE]; |
|---|
| 1245 | 1265 | |
|---|
| 1246 | 1266 | ctrl->edid = drm_get_edid(connector, &ctrl->drm_aux->ddc); |
|---|
| 1247 | 1267 | if (!ctrl->edid) { |
|---|