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

drm/bridge: tc358767: clean-up link training

The current link training code does unnecessary retry-loops, and does
extra writes to the registers. It is easier to follow the flow and
ensure it's similar to Toshiba's documentation if we deal with LT inside
tc_main_link_enable() function.

This patch adds tc_wait_link_training() which handles waiting for the LT
phase to finish, and does the necessary LT register setups in
tc_main_link_enable, without extra loops.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>
Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190528082747.3631-17-tomi.valkeinen@ti.com

authored by

Tomi Valkeinen and committed by
Andrzej Hajda
f9538357 0bf25146

+59 -75
+59 -75
drivers/gpu/drm/bridge/tc358767.c
··· 740 740 return ret; 741 741 } 742 742 743 - static int tc_link_training(struct tc_data *tc, int pattern) 743 + static int tc_wait_link_training(struct tc_data *tc) 744 744 { 745 - const char * const *errors; 746 - u32 srcctrl = tc_srcctrl(tc) | DP0_SRCCTRL_SCRMBLDIS | 747 - DP0_SRCCTRL_AUTOCORRECT; 748 - int timeout; 749 - int retry; 745 + u32 timeout = 1000; 750 746 u32 value; 751 747 int ret; 752 748 753 - if (pattern == DP_TRAINING_PATTERN_1) { 754 - srcctrl |= DP0_SRCCTRL_TP1; 755 - errors = training_pattern1_errors; 756 - } else { 757 - srcctrl |= DP0_SRCCTRL_TP2; 758 - errors = training_pattern2_errors; 759 - } 760 - 761 - /* Set DPCD 0x102 for Training Part 1 or 2 */ 762 - tc_write(DP0_SNKLTCTRL, DP_LINK_SCRAMBLING_DISABLE | pattern); 763 - 764 - tc_write(DP0_LTLOOPCTRL, 765 - (0x0f << 28) | /* Defer Iteration Count */ 766 - (0x0f << 24) | /* Loop Iteration Count */ 767 - (0x0d << 0)); /* Loop Timer Delay */ 768 - 769 - retry = 5; 770 749 do { 771 - /* Set DP0 Training Pattern */ 772 - tc_write(DP0_SRCCTRL, srcctrl); 750 + udelay(1); 751 + tc_read(DP0_LTSTAT, &value); 752 + } while ((!(value & LT_LOOPDONE)) && (--timeout)); 773 753 774 - /* Enable DP0 to start Link Training */ 775 - tc_write(DP0CTL, DP_EN); 776 - 777 - /* wait */ 778 - timeout = 1000; 779 - do { 780 - tc_read(DP0_LTSTAT, &value); 781 - udelay(1); 782 - } while ((!(value & LT_LOOPDONE)) && (--timeout)); 783 - if (timeout == 0) { 784 - dev_err(tc->dev, "Link training timeout!\n"); 785 - } else { 786 - int pattern = (value >> 11) & 0x3; 787 - int error = (value >> 8) & 0x7; 788 - 789 - dev_dbg(tc->dev, 790 - "Link training phase %d done after %d uS: %s\n", 791 - pattern, 1000 - timeout, errors[error]); 792 - if (pattern == DP_TRAINING_PATTERN_1 && error == 0) 793 - break; 794 - if (pattern == DP_TRAINING_PATTERN_2) { 795 - value &= LT_CHANNEL1_EQ_BITS | 796 - LT_INTERLANE_ALIGN_DONE | 797 - LT_CHANNEL0_EQ_BITS; 798 - /* in case of two lanes */ 799 - if ((tc->link.base.num_lanes == 2) && 800 - (value == (LT_CHANNEL1_EQ_BITS | 801 - LT_INTERLANE_ALIGN_DONE | 802 - LT_CHANNEL0_EQ_BITS))) 803 - break; 804 - /* in case of one line */ 805 - if ((tc->link.base.num_lanes == 1) && 806 - (value == (LT_INTERLANE_ALIGN_DONE | 807 - LT_CHANNEL0_EQ_BITS))) 808 - break; 809 - } 810 - } 811 - /* restart */ 812 - tc_write(DP0CTL, 0); 813 - usleep_range(10, 20); 814 - } while (--retry); 815 - if (retry == 0) { 816 - dev_err(tc->dev, "Failed to finish training phase %d\n", 817 - pattern); 754 + if (timeout == 0) { 755 + dev_err(tc->dev, "Link training timeout waiting for LT_LOOPDONE!\n"); 756 + return -ETIMEDOUT; 818 757 } 819 758 820 - return 0; 759 + return (value >> 8) & 0x7; 760 + 821 761 err: 822 762 return ret; 823 763 } ··· 867 927 868 928 if (tmp[0] != tc->assr) { 869 929 dev_dbg(dev, "Failed to switch display ASSR to %d, falling back to unscrambled mode\n", 870 - tc->assr); 930 + tc->assr); 871 931 /* trying with disabled scrambler */ 872 932 tc->link.scrambler_dis = true; 873 933 } ··· 893 953 if (ret < 0) 894 954 goto err_dpcd_write; 895 955 896 - ret = tc_link_training(tc, DP_TRAINING_PATTERN_1); 897 - if (ret) 956 + /* Clock-Recovery */ 957 + 958 + /* Set DPCD 0x102 for Training Pattern 1 */ 959 + tc_write(DP0_SNKLTCTRL, DP_LINK_SCRAMBLING_DISABLE | 960 + DP_TRAINING_PATTERN_1); 961 + 962 + tc_write(DP0_LTLOOPCTRL, 963 + (15 << 28) | /* Defer Iteration Count */ 964 + (15 << 24) | /* Loop Iteration Count */ 965 + (0xd << 0)); /* Loop Timer Delay */ 966 + 967 + tc_write(DP0_SRCCTRL, tc_srcctrl(tc) | DP0_SRCCTRL_SCRMBLDIS | 968 + DP0_SRCCTRL_AUTOCORRECT | DP0_SRCCTRL_TP1); 969 + 970 + /* Enable DP0 to start Link Training */ 971 + tc_write(DP0CTL, 972 + ((tc->link.base.capabilities & DP_LINK_CAP_ENHANCED_FRAMING) ? EF_EN : 0) | 973 + DP_EN); 974 + 975 + /* wait */ 976 + ret = tc_wait_link_training(tc); 977 + if (ret < 0) 898 978 goto err; 899 979 900 - ret = tc_link_training(tc, DP_TRAINING_PATTERN_2); 901 - if (ret) 980 + if (ret) { 981 + dev_err(tc->dev, "Link training phase 1 failed: %s\n", 982 + training_pattern1_errors[ret]); 983 + ret = -ENODEV; 902 984 goto err; 985 + } 986 + 987 + /* Channel Equalization */ 988 + 989 + /* Set DPCD 0x102 for Training Pattern 2 */ 990 + tc_write(DP0_SNKLTCTRL, DP_LINK_SCRAMBLING_DISABLE | 991 + DP_TRAINING_PATTERN_2); 992 + 993 + tc_write(DP0_SRCCTRL, tc_srcctrl(tc) | DP0_SRCCTRL_SCRMBLDIS | 994 + DP0_SRCCTRL_AUTOCORRECT | DP0_SRCCTRL_TP2); 995 + 996 + /* wait */ 997 + ret = tc_wait_link_training(tc); 998 + if (ret < 0) 999 + goto err; 1000 + 1001 + if (ret) { 1002 + dev_err(tc->dev, "Link training phase 2 failed: %s\n", 1003 + training_pattern2_errors[ret]); 1004 + ret = -ENODEV; 1005 + goto err; 1006 + } 903 1007 904 1008 /* 905 1009 * Toshiba's documentation suggests to first clear DPCD 0x102, then