Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/bridge: tc358767: Avoid drm_dp_link helpers

During the discussion of patches that enhance the drm_dp_link helpers it
was concluded that these helpers aren't very useful to begin with. Start
pushing the equivalent code into individual drivers to ultimately remove
them.

v3: make link rate unsigned int to avoid overflow

Signed-off-by: Thierry Reding <treding@nvidia.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20191021143437.1477719-10-thierry.reding@gmail.com

+41 -22
+41 -22
drivers/gpu/drm/bridge/tc358767.c
··· 229 229 module_param_named(test, tc_test_pattern, bool, 0644); 230 230 231 231 struct tc_edp_link { 232 - struct drm_dp_link base; 232 + u8 dpcd[DP_RECEIVER_CAP_SIZE]; 233 + unsigned int rate; 234 + u8 num_lanes; 233 235 u8 assr; 234 236 bool scrambler_dis; 235 237 bool spread; ··· 440 438 reg |= DP0_SRCCTRL_SCRMBLDIS; /* Scrambler Disabled */ 441 439 if (tc->link.spread) 442 440 reg |= DP0_SRCCTRL_SSCG; /* Spread Spectrum Enable */ 443 - if (tc->link.base.num_lanes == 2) 441 + if (tc->link.num_lanes == 2) 444 442 reg |= DP0_SRCCTRL_LANES_2; /* Two Main Channel Lanes */ 445 - if (tc->link.base.rate != 162000) 443 + if (tc->link.rate != 162000) 446 444 reg |= DP0_SRCCTRL_BW27; /* 2.7 Gbps link */ 447 445 return reg; 448 446 } ··· 665 663 666 664 static int tc_get_display_props(struct tc_data *tc) 667 665 { 666 + u8 revision, num_lanes; 667 + unsigned int rate; 668 668 int ret; 669 669 u8 reg; 670 670 671 671 /* Read DP Rx Link Capability */ 672 - ret = drm_dp_link_probe(&tc->aux, &tc->link.base); 672 + ret = drm_dp_dpcd_read(&tc->aux, DP_DPCD_REV, tc->link.dpcd, 673 + DP_RECEIVER_CAP_SIZE); 673 674 if (ret < 0) 674 675 goto err_dpcd_read; 675 - if (tc->link.base.rate != 162000 && tc->link.base.rate != 270000) { 676 + 677 + revision = tc->link.dpcd[DP_DPCD_REV]; 678 + rate = drm_dp_max_link_rate(tc->link.dpcd); 679 + num_lanes = drm_dp_max_lane_count(tc->link.dpcd); 680 + 681 + if (rate != 162000 && rate != 270000) { 676 682 dev_dbg(tc->dev, "Falling to 2.7 Gbps rate\n"); 677 - tc->link.base.rate = 270000; 683 + rate = 270000; 678 684 } 679 685 680 - if (tc->link.base.num_lanes > 2) { 686 + tc->link.rate = rate; 687 + 688 + if (num_lanes > 2) { 681 689 dev_dbg(tc->dev, "Falling to 2 lanes\n"); 682 - tc->link.base.num_lanes = 2; 690 + num_lanes = 2; 683 691 } 692 + 693 + tc->link.num_lanes = num_lanes; 684 694 685 695 ret = drm_dp_dpcd_readb(&tc->aux, DP_MAX_DOWNSPREAD, &reg); 686 696 if (ret < 0) ··· 711 697 tc->link.assr = reg & DP_ALTERNATE_SCRAMBLER_RESET_ENABLE; 712 698 713 699 dev_dbg(tc->dev, "DPCD rev: %d.%d, rate: %s, lanes: %d, framing: %s\n", 714 - tc->link.base.revision >> 4, tc->link.base.revision & 0x0f, 715 - (tc->link.base.rate == 162000) ? "1.62Gbps" : "2.7Gbps", 716 - tc->link.base.num_lanes, 717 - (tc->link.base.capabilities & DP_LINK_CAP_ENHANCED_FRAMING) ? 700 + revision >> 4, revision & 0x0f, 701 + (tc->link.rate == 162000) ? "1.62Gbps" : "2.7Gbps", 702 + tc->link.num_lanes, 703 + drm_dp_enhanced_frame_cap(tc->link.dpcd) ? 718 704 "enhanced" : "non-enhanced"); 719 705 dev_dbg(tc->dev, "Downspread: %s, scrambler: %s\n", 720 706 tc->link.spread ? "0.5%" : "0.0%", ··· 754 740 */ 755 741 756 742 in_bw = mode->clock * bits_per_pixel / 8; 757 - out_bw = tc->link.base.num_lanes * tc->link.base.rate; 743 + out_bw = tc->link.num_lanes * tc->link.rate; 758 744 max_tu_symbol = DIV_ROUND_UP(in_bw * TU_SIZE_RECOMMENDED, out_bw); 759 745 760 746 dev_dbg(tc->dev, "set mode %dx%d\n", ··· 916 902 /* SSCG and BW27 on DP1 must be set to the same as on DP0 */ 917 903 ret = regmap_write(tc->regmap, DP1_SRCCTRL, 918 904 (tc->link.spread ? DP0_SRCCTRL_SSCG : 0) | 919 - ((tc->link.base.rate != 162000) ? DP0_SRCCTRL_BW27 : 0)); 905 + ((tc->link.rate != 162000) ? DP0_SRCCTRL_BW27 : 0)); 920 906 if (ret) 921 907 return ret; 922 908 ··· 926 912 927 913 /* Setup Main Link */ 928 914 dp_phy_ctrl = BGREN | PWR_SW_EN | PHY_A0_EN | PHY_M0_EN; 929 - if (tc->link.base.num_lanes == 2) 915 + if (tc->link.num_lanes == 2) 930 916 dp_phy_ctrl |= PHY_2LANE; 931 917 932 918 ret = regmap_write(tc->regmap, DP_PHY_CTRL, dp_phy_ctrl); ··· 989 975 } 990 976 991 977 /* Setup Link & DPRx Config for Training */ 992 - ret = drm_dp_link_configure(aux, &tc->link.base); 978 + tmp[0] = drm_dp_link_rate_to_bw_code(tc->link.rate); 979 + tmp[1] = tc->link.num_lanes; 980 + 981 + if (drm_dp_enhanced_frame_cap(tc->link.dpcd)) 982 + tmp[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN; 983 + 984 + ret = drm_dp_dpcd_write(aux, DP_LINK_BW_SET, tmp, 2); 993 985 if (ret < 0) 994 986 goto err_dpcd_write; 995 987 ··· 1039 1019 1040 1020 /* Enable DP0 to start Link Training */ 1041 1021 ret = regmap_write(tc->regmap, DP0CTL, 1042 - ((tc->link.base.capabilities & 1043 - DP_LINK_CAP_ENHANCED_FRAMING) ? EF_EN : 0) | 1044 - DP_EN); 1022 + (drm_dp_enhanced_frame_cap(tc->link.dpcd) ? 1023 + EF_EN : 0) | DP_EN); 1045 1024 if (ret) 1046 1025 return ret; 1047 1026 ··· 1119 1100 ret = -ENODEV; 1120 1101 } 1121 1102 1122 - if (tc->link.base.num_lanes == 2) { 1103 + if (tc->link.num_lanes == 2) { 1123 1104 value = (tmp[0] >> 4) & DP_CHANNEL_EQ_BITS; 1124 1105 1125 1106 if (value != DP_CHANNEL_EQ_BITS) { ··· 1190 1171 return ret; 1191 1172 1192 1173 value = VID_MN_GEN | DP_EN; 1193 - if (tc->link.base.capabilities & DP_LINK_CAP_ENHANCED_FRAMING) 1174 + if (drm_dp_enhanced_frame_cap(tc->link.dpcd)) 1194 1175 value |= EF_EN; 1195 1176 ret = regmap_write(tc->regmap, DP0CTL, value); 1196 1177 if (ret) ··· 1316 1297 return MODE_CLOCK_HIGH; 1317 1298 1318 1299 req = mode->clock * bits_per_pixel / 8; 1319 - avail = tc->link.base.num_lanes * tc->link.base.rate; 1300 + avail = tc->link.num_lanes * tc->link.rate; 1320 1301 1321 1302 if (req > avail) 1322 1303 return MODE_BAD;