linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rob Clark <robdclark@gmail.com>
To: Douglas Anderson <dianders@chromium.org>
Cc: Andrzej Hajda <a.hajda@samsung.com>,
	Neil Armstrong <narmstrong@baylibre.com>,
	Rob Clark <robdclark@chromium.org>,
	Jernej Skrabec <jernej.skrabec@siol.net>,
	Jonas Karlman <jonas@kwiboo.se>, David Airlie <airlied@linux.ie>,
	linux-arm-msm <linux-arm-msm@vger.kernel.org>,
	dri-devel <dri-devel@lists.freedesktop.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Sean Paul <seanpaul@chromium.org>,
	Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Daniel Vetter <daniel@ffwll.ch>
Subject: [PATCH 2/2] fixup! drm/bridge: ti-sn65dsi86: Skip non-standard DP rates
Date: Sun, 15 Dec 2019 12:06:32 -0800	[thread overview]
Message-ID: <20191215200632.1019065-1-robdclark@gmail.com> (raw)
In-Reply-To: <20191213154448.9.I1791f91dd22894da04f86699a7507d101d4385bc@changeid>

From: Rob Clark <robdclark@chromium.org>

---
Note however, the panel I have on the yoga c630 is not eDP 1.4+, so I
cannot test that path.  But I think it looks correct.

 drivers/gpu/drm/bridge/ti-sn65dsi86.c | 110 +++++++++++++++++++++-----
 1 file changed, 89 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
index 976f98991b3d..1cb53be7c9e9 100644
--- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c
+++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
@@ -102,6 +102,9 @@ struct ti_sn_bridge {
 	struct gpio_desc		*enable_gpio;
 	struct regulator_bulk_data	supplies[SN_REGULATOR_SUPPLY_NUM];
 	int				dp_lanes;
+	u8				edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE];
+	int				num_sink_rates;
+	int				sink_rate_idxs[DP_MAX_SUPPORTED_RATES];
 };
 
 static const struct regmap_range ti_sn_bridge_volatile_ranges[] = {
@@ -454,15 +457,6 @@ static const unsigned int ti_sn_bridge_dp_rate_lut[] = {
 	0, 1620, 2160, 2430, 2700, 3240, 4320, 5400
 };
 
-/**
- * A table indicating which of the rates in ti_sn_bridge_dp_rate_lut
- * is as per the DP spec (AKA a standard) as opposed to an intermediate
- * rate.
- */
-static const bool ti_sn_bridge_dp_rate_standard[] = {
-	false, true, false, false, true, false, false, true
-};
-
 static int ti_sn_bridge_calc_min_dp_rate_idx(struct ti_sn_bridge *pdata)
 {
 	unsigned int bit_rate_khz, dp_rate_mhz;
@@ -573,11 +567,95 @@ static unsigned int ti_sn_get_max_lanes(struct ti_sn_bridge *pdata)
 	return data & DP_LANE_COUNT_MASK;
 }
 
+/* TODO possibly fold ti_sn_get_max_lanes() into this? */
+static void ti_sn_read_sink_config(struct ti_sn_bridge *pdata)
+{
+	memset(pdata->edp_dpcd, 0, sizeof(pdata->edp_dpcd));
+
+	/*
+	 * Read the eDP display control registers.
+	 *
+	 * Do this independent of DP_DPCD_DISPLAY_CONTROL_CAPABLE bit in
+	 * DP_EDP_CONFIGURATION_CAP, because some buggy displays do not have it
+	 * set, but require eDP 1.4+ detection (e.g. for supported link rates
+	 * method). The display control registers should read zero if they're
+	 * not supported anyway.
+	 */
+	if (drm_dp_dpcd_read(&pdata->aux, DP_EDP_DPCD_REV,
+			     pdata->edp_dpcd, sizeof(pdata->edp_dpcd)) ==
+			     sizeof(pdata->edp_dpcd))
+		DRM_DEBUG_KMS("eDP DPCD: %*ph\n", (int) sizeof(pdata->edp_dpcd),
+			      pdata->edp_dpcd);
+
+	/* Read the eDP 1.4+ supported link rates. */
+	if (pdata->edp_dpcd[0] >= DP_EDP_14) {
+		__le16 sink_rates[DP_MAX_SUPPORTED_RATES];
+		int i, j;
+
+		drm_dp_dpcd_read(&pdata->aux, DP_SUPPORTED_LINK_RATES,
+				sink_rates, sizeof(sink_rates));
+
+		for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
+			int val = le16_to_cpu(sink_rates[i]);
+			int rate_mhz;
+
+			if (val == 0)
+				break;
+
+			/* Value read multiplied by 200kHz gives the per-lane
+			 * link rate in kHz. The source rates are, however,
+			 * stored in MHz
+			 */
+			rate_mhz = DIV_ROUND_UP(val * 200, 1000);
+
+			/* If the rate is also supported by the bridge, add it
+			 * to the table of supported rates:
+			 */
+			for (j = 1; j < ARRAY_SIZE(ti_sn_bridge_dp_rate_lut); j++) {
+				if (rate_mhz == ti_sn_bridge_dp_rate_lut[j]) {
+					pdata->sink_rate_idxs[pdata->num_sink_rates++] = j;
+					break;
+				}
+			}
+		}
+		pdata->num_sink_rates = i;
+	} else {
+		int i;
+
+		/**
+		 * A table indicating which of the rates in ti_sn_bridge_dp_rate_lut
+		 * is as per the DP spec (AKA a standard) as opposed to an intermediate
+		 * rate.
+		 */
+		static const bool ti_sn_bridge_dp_rate_standard[] = {
+			false, true, false, false, true, false, false, true
+		};
+
+		/* if prior to eDP 1.4, then just use the supported standard rates: */
+		for (i = 1; i < ARRAY_SIZE(ti_sn_bridge_dp_rate_lut); i++) {
+			if (!ti_sn_bridge_dp_rate_standard[i])
+				continue;
+			pdata->sink_rate_idxs[pdata->num_sink_rates++] = i;
+		}
+	}
+}
+
 static int ti_sn_link_training(struct ti_sn_bridge *pdata, int dp_rate_idx,
 			       const char **last_err_str)
 {
 	unsigned int val;
 	int ret;
+	int i;
+
+	/* check for supported rate: */
+	for (i = 0; i < pdata->num_sink_rates; i++)
+		if (pdata->sink_rate_idxs[i] == dp_rate_idx)
+			break;
+
+	if (i == pdata->num_sink_rates) {
+		*last_err_str = "Unsupported rate";
+		return -EINVAL;
+	}
 
 	/* set dp clk frequency value */
 	regmap_update_bits(pdata->regmap, SN_DATARATE_CONFIG_REG,
@@ -624,6 +702,8 @@ static void ti_sn_bridge_enable(struct drm_bridge *bridge)
 	unsigned int val;
 	int ret = -EINVAL;
 
+	ti_sn_read_sink_config(pdata);
+
 	/*
 	 * Run with the maximum number of lanes that the DP sink supports.
 	 *
@@ -669,18 +749,6 @@ static void ti_sn_bridge_enable(struct drm_bridge *bridge)
 	for (dp_rate_idx = ti_sn_bridge_calc_min_dp_rate_idx(pdata);
 	     dp_rate_idx <= max_dp_rate_idx;
 	     dp_rate_idx++) {
-		/*
-		 * To be on the safe side, we'll skip all non-standard
-		 * rates and move up to the next standard one.  This is
-		 * because some panels will pass link training with a non-
-		 * standard rate but just show garbage.  If the non-standard
-		 * rates are useful we should figure out how to enable them
-		 * through querying the panel, having a per-panel whitelist,
-		 * or adding a DT property.
-		 */
-		if (!ti_sn_bridge_dp_rate_standard[dp_rate_idx])
-			continue;
-
 		ret = ti_sn_link_training(pdata, dp_rate_idx, &last_err_str);
 		if (!ret)
 			break;
-- 
2.23.0


  parent reply	other threads:[~2019-12-15 20:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-13 23:45 [PATCH 0/9] drm/bridge: ti-sn65dsi86: Improve support for AUO B116XAK01 + other low res DP Douglas Anderson
2019-12-13 23:45 ` [PATCH 1/9] drm/bridge: ti-sn65dsi86: Split the setting of the dp and dsi rates Douglas Anderson
2019-12-13 23:45 ` [PATCH 2/9] drm/bridge: ti-sn65dsi86: zero is never greater than an unsigned int Douglas Anderson
2019-12-13 23:45 ` [PATCH 3/9] drm/bridge: ti-sn65dsi86: Don't use MIPI variables for DP link Douglas Anderson
2019-12-13 23:45 ` [PATCH 4/9] drm/bridge: ti-sn65dsi86: Config number of DP lanes Mo' Betta Douglas Anderson
2019-12-13 23:45 ` [PATCH 5/9] drm/bridge: ti-sn65dsi86: Read num lanes from the DP sink Douglas Anderson
2019-12-13 23:45 ` [PATCH 6/9] drm/bridge: ti-sn65dsi86: Use 18-bit DP if we can Douglas Anderson
2019-12-13 23:45 ` [PATCH 7/9] drm/bridge: ti-sn65dsi86: Group DP link training bits in a function Douglas Anderson
2019-12-13 23:45 ` [PATCH 8/9] drm/bridge: ti-sn65dsi86: Train at faster rates if slower ones fail Douglas Anderson
2019-12-15 20:04   ` [PATCH 1/2] fixup! " Rob Clark
2019-12-18  0:52     ` Doug Anderson
2019-12-13 23:45 ` [PATCH 9/9] drm/bridge: ti-sn65dsi86: Skip non-standard DP rates Douglas Anderson
2019-12-14  0:07   ` Daniel Vetter
2019-12-14  0:47     ` Doug Anderson
2019-12-16  1:19       ` Jeffrey Hugo
2019-12-17  0:31         ` Doug Anderson
2019-12-15 20:06   ` Rob Clark [this message]
2019-12-18  0:54     ` [PATCH 2/2] fixup! " Doug Anderson
2019-12-15 20:02 ` [PATCH 0/9] drm/bridge: ti-sn65dsi86: Improve support for AUO B116XAK01 + other low res DP Rob Clark

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191215200632.1019065-1-robdclark@gmail.com \
    --to=robdclark@gmail.com \
    --cc=Laurent.pinchart@ideasonboard.com \
    --cc=a.hajda@samsung.com \
    --cc=airlied@linux.ie \
    --cc=bjorn.andersson@linaro.org \
    --cc=daniel@ffwll.ch \
    --cc=dianders@chromium.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jernej.skrabec@siol.net \
    --cc=jonas@kwiboo.se \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=narmstrong@baylibre.com \
    --cc=robdclark@chromium.org \
    --cc=seanpaul@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).