Skip to contentSkip to conversation

Add eDP lane mapping support

PATCH Applied Damon Ding 3 participants 10 messages Aug 28 – Sep 9

Subsystems (7)
lore
Share & tools
lore

Damon Ding

author
#0 lore raw

v8 cover Add eDP lane mapping support

This series adds configurable eDP physical lane mapping support via device tree data-lanes property.

Lane mapping is mainly used for below scenarios:
1. Correct PCB lane swap and differential line routing crossover without hardware changes;
2. Adapt mismatched lane pin definitions between SoC and eDP panel;
3. Support multiple panel hardware variants on the same board by configuring data-lanes in device tree only.

The series includes driver implementation and device tree binding updates to support custom lane mapping configuration from endpoint node, and keeps default linear lane order if no configuration is given.

Patch 1: Add endpoint data-lanes property to analogix-dp binding Patch 2: Add DRM DP helper API to validate DP lane counts Patch 3: Restore mandatory for samsung,link-rate and samsung,lane-count
properties
Patch 4: Add validation for samsung,lane-count property as preparation Patch 5: Implement lane mapping in analogix_dp driver

Damon Ding (5):
dt-bindings: display: bridge: analogix-dp: Add data-lanes support for
endpoint
drm/dp: Add helper to validate DP lane counts
drm/bridge: analogix_dp: Restore mandatory samsung DP DT properties drm/bridge: analogix_dp: Add validation for samsung,lane-count
property
drm/bridge: analogix_dp: Add support for optional data-lanes mapping

 .../bindings/display/bridge/analogix,dp.yaml  | 19 +++--
 .../rockchip/rockchip,analogix-dp.yaml        |   1 +
 .../drm/bridge/analogix/analogix_dp_core.c    | 84 ++++++++++++++++++-
 .../drm/bridge/analogix/analogix_dp_core.h    |  4 +-
 .../gpu/drm/bridge/analogix/analogix_dp_reg.c | 15 ++--
 .../gpu/drm/bridge/analogix/analogix_dp_reg.h |  4 +
 include/drm/display/drm_dp_helper.h           |   6 ++
 7 files changed, 115 insertions(+), 18 deletions(-)

---

Changes in v2:
- Add lane mapping application scenarios in commit message.
- Remove redundant deprecated property 'data-lanes' for eDP node.
- Update port@1 $ref to /schemas/graph.yaml#/$defs/port-base.

Changes in v3:
- Squash [PATCH v2 2/3] into [PATCH v2 1/3].
- Add unevaluatedProperties: false to both the port@1 and endpoint nodes.

Changes in v4:
- Add validation for samsung,lane-count property as preparation.

Changes in v5:
- Add DRM DP helper API to validate DP lane counts.
- Apply DRM DP helper API to check the validity of samsung,lane-count property.
- Add Acked-by and Reviewed-by tags.

Changes in v6:
- Add a separate commit to restore mandatory samsung DP DT properties.
- Add Reviewed-by tag.

Changes in v7:
- Add Reviewed-by tag.

Changes in v8:
- Expand the commit message of [PATCH v7 3/5] with the detailed link training failure analysis, and add 'Cc: stable'.
- Fix reg parameter of of_graph_get_endpoint_by_regs() from -1 to 0 in [PATCH v7 5/5].
- Rename 'tmp' to 'lane_idx' and add comment to explain the lane map fill loop in [PATCH v7 5/5].
- Add Reviewed-by tags.

Signature · 7 lines
2.34.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
author
#1 lore raw

PATCH v8 1/5 dt-bindings: display: bridge: analogix-dp: Add data-lanes support for endpoint

Add data-lanes property support to the port@1 endpoint for physical lane mapping configuration.

Lane mapping is mainly used for below scenarios:
1. Correct PCB lane swap and differential line routing crossover without hardware changes;
2. Adapt mismatched lane pin definitions between SoC and eDP panel;
3. Support multiple panel hardware variants on the same board by configuring data-lanes in device tree only.

Additionally, add data-lanes setting in Rockchip eDP DT node example to show actual lane mapping usage.

---

Changes in v2:
- Add lane mapping application scenarios in commit message.
- Remove redundant deprecated property 'data-lanes' for eDP node.
- Update port@1 $ref to /schemas/graph.yaml#/$defs/port-base.

Changes in v3:
- Squash data-lanes adjustment of Rockchip eDP DT example into this commit.
- Add unevaluatedProperties: false to both the port@1 and endpoint nodes.

Changes in v5
- Add Acked-by and Reviewed-by tags.

Changes in v8
- Add Reviewed-by tags.

---
 .../bindings/display/bridge/analogix,dp.yaml  | 19 ++++++++++++++-----
 .../rockchip/rockchip,analogix-dp.yaml        |  1 +
 2 files changed, 15 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/display/bridge/analogix,dp.yaml +14 -5
index 62f0521b0924..ecf206871cdd 100644
@@ -42,13 +42,22 @@ properties:
     properties:
       port@0:
         $ref: /schemas/graph.yaml#/properties/port
-        description:
-          Input node to receive pixel data.
+        description: Input node to receive pixel data.
 
       port@1:
-        $ref: /schemas/graph.yaml#/properties/port
-        description:
-          Port node with one endpoint connected to a dp-connector node.
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: Port node with one endpoint connected to sink device node.
+        properties:
+          endpoint:
+            $ref: /schemas/media/video-interfaces.yaml#
+            unevaluatedProperties: false
+            properties:
+              data-lanes:
+                minItems: 1
+                maxItems: 4
+                items:
+                  enum: [ 0, 1, 2, 3 ]
 
     required:
       - port@0
Documentation/devicetree/bindings/display/rockchip/rockchip,analogix-dp.yaml +1 -0
index 6548f157fd96..39dafe75a680 100644
@@ -160,6 +160,7 @@ examples:
           reg = <1>;
 
           edp_out_panel: endpoint {
+            data-lanes = <0 1>;
             remote-endpoint = <&panel_in_edp>;
           };
         };
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v8 2/5 drm/dp: Add helper to validate DP lane counts

In reply to Damon Ding

Add a generic helper function drm_dp_lane_count_is_valid() to check if a DisplayPort lane count is valid. According to the DP specification, only 1, 2, or 4 lanes are supported.

This helper avoids duplicating DP lane count validation logic across individual DisplayPort drivers.

---

Changes in v6:
- Add Reviewed-by tag.

---
 include/drm/display/drm_dp_helper.h | 6 ++++++
 1 file changed, 6 insertions(+)
include/drm/display/drm_dp_helper.h +6 -0
index ab16c1be3900..5b05a7fbe174 100644
@@ -139,6 +139,12 @@ bool drm_dp_as_sdp_supported(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_C
 
 int drm_dp_psr_setup_time(const u8 psr_cap[EDP_PSR_RECEIVER_CAP_SIZE]);
 
+static inline bool
+drm_dp_lane_count_is_valid(int lane_count)
+{
+	return lane_count == 1 || lane_count == 2 || lane_count == 4;
+}
+
 static inline int
 drm_dp_max_link_rate(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
 {
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH v8 3/5 drm/bridge: analogix_dp: Restore mandatory samsung DP DT properties

In reply to Damon Ding

Revert the change that made samsung,link-rate and samsung,lane-count optional for Exynos DP. Add error checking to fail probe early if the required DT properties are missing.

If these properties are missing, video_info->max_link_rate and video_info->max_lane_count remain zero, and so do link_train.link_rate and link_train.lane_count used in the subsequent link training flow, resulting in link training failure.

There is no way at all a device can work without these properties. Here is the code flow when either max_link_rate or max_lane_count is 0:

analogix_dp_commit()

    -> analogix_dp_full_link_train(dp, max_lanes = 0, max_rate = 0)

analogix_dp_full_link_train(max_lanes, max_rate):

      // Read sink capabilities via DPCD and sanitize them
      link_rate  = read_dpcd(DP_MAX_LINK_RATE);  // >= 0x06 after fixup
      lane_count = read_dpcd(DP_MAX_LANE_COUNT); // >= 1 after fixup

      // Clamp by the limits from DT
      if (link_rate > max_rate)    // 0x06 > 0, always true
          link_rate = max_rate;    // link_rate = 0
      if (lane_count > max_lanes)  // 1 > 0, always true
          lane_count = max_lanes;  // lane_count = 0

      // Configure TX with the zeroed values
      set_link_bandwidth(link_rate = 0)
          // writel() is only executed for bwtype == 0x06/0x0a,
          // so LINK_BW_SET is never written and stays at
          // reset value; phy_configure() gets link_rate = 0.

      set_lane_count(lane_count = 0)
          // writel(0, ANALOGIX_DP_LANE_COUNT_SET) enables 0 lanes;
          // phy_configure() is called with lanes = 0.

      // Program sink for link training
      drm_dp_dpcd_write(DP_LINK_BW_SET, {link_rate = 0/lane_count = 0})
          // DP spec requires link rate in {0x06, 0x0a, 0x14} and
          // lane count in {1, 2, 4}. Writing zeros is illegal, so
          // the sink cannot enter the training state.

      // Training loop
      for (lane = 0; lane < lane_count /* 0 */; lane++)
          // loop body never executes; training_lane[] stays
          // uninitialized and no training register is programmed

Since the sanitized sink values are always non-zero (link_rate >= 0x06, lane_count >= 1), the clamping with a zero maximum unconditionally forces the training parameters to zero. Clock recovery can never be achieved, so link training fails deterministically.

Consequently, making these properties mandatory again cannot break any existing device: a DT without them could never have worked in the first place. Failing probe early with a clear error message is more helpful than a silent link training failure at runtime.

Fixes 0d0abd894ead ("drm: bridge: analogix/dp: add max link rate and lane count limit for RK3288")

---

Changes in v8:
- Expand the commit message with the detailed link training failure analysis,
- Add Reviewed-by tag.

---
 drivers/gpu/drm/bridge/analogix/analogix_dp_core.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpu/drm/bridge/analogix/analogix_dp_core.c +9 -4
index 566f1e5eb8cd..ddb15d6de05f 100644
@@ -1248,6 +1248,7 @@ static int analogix_dp_dt_parse_pdata(struct analogix_dp_device *dp)
 {
 	struct device_node *dp_node = dp->dev->of_node;
 	struct video_info *video_info = &dp->video_info;
+	u32 val;
 
 	switch (dp->plat_data->dev_type) {
 	case RK3288_DP:
@@ -1269,10 +1270,14 @@ static int analogix_dp_dt_parse_pdata(struct analogix_dp_device *dp)
 		 * NOTE: those property parseing code is used for
 		 * providing backward compatibility for samsung platform.
 		 */
-		of_property_read_u32(dp_node, "samsung,link-rate",
-				     &video_info->max_link_rate);
-		of_property_read_u32(dp_node, "samsung,lane-count",
-				     &video_info->max_lane_count);
+		if (of_property_read_u32(dp_node, "samsung,link-rate", &val))
+			return dev_err_probe(dp->dev, -EINVAL,
+					     "Failed to get samsung,link-rate\n");
+		video_info->max_link_rate = val;
+		if (of_property_read_u32(dp_node, "samsung,lane-count", &val))
+			return dev_err_probe(dp->dev, -EINVAL,
+					     "Failed to get samsung,lane-count\n");
+		video_info->max_lane_count = val;
 		break;
 	}
 
Signature · 7 lines
2.34.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
author
#4 lore raw

PATCH v8 4/5 drm/bridge: analogix_dp: Add validation for samsung,lane-count property

In reply to Damon Ding

Add validity check for samsung,lane-count to ensure DT-provided lane count values are specification-compliant.

---

Changes in v5:
- Apply DRM DP helper API to check the validity of DP lane count.

Changes in v6:
- Rebase after the new commit for restoring mandatory properties samsung,link-rate and samsung,lane-count.

Changes in v7:
- Add Reviewed-by tag.

---
 drivers/gpu/drm/bridge/analogix/analogix_dp_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/analogix/analogix_dp_core.c +2 -1
index ddb15d6de05f..a74c855936b2 100644
@@ -1274,7 +1274,8 @@ static int analogix_dp_dt_parse_pdata(struct analogix_dp_device *dp)
 			return dev_err_probe(dp->dev, -EINVAL,
 					     "Failed to get samsung,link-rate\n");
 		video_info->max_link_rate = val;
-		if (of_property_read_u32(dp_node, "samsung,lane-count", &val))
+		if (of_property_read_u32(dp_node, "samsung,lane-count", &val) ||
+		    !drm_dp_lane_count_is_valid(val))
 			return dev_err_probe(dp->dev, -EINVAL,
 					     "Failed to get samsung,lane-count\n");
 		video_info->max_lane_count = val;
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v8 4/5] drm/bridge: analogix_dp: Add validation for samsung,lane-count property

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] devm_drm_bridge_add() is used inside a component bind callback, causing devres leakage and double-add on re-bind.
- [High] Missing analogix_dp_unbind() and encoder cleanup in component bind error paths.
--

commit 3586f9db6c3c7447ea980ac18be62fa966e709ae
Author: Damon Ding <[email protected]>

drm/bridge: analogix_dp: Add validation for samsung,lane-count property

Add validity check for samsung,lane-count to ensure DT-provided lane count values are specification-compliant.

drivers/gpu/drm/bridge/analogix/analogix_dp_core.c

Quoted 4 lines
drivers/gpu/drm/bridge/analogix/analogix_dp_core.c +0 -0
index 4213cd68d5a0d..ba12fde8accde 100644

[ ... ]

This isn't a bug introduced by this patch, but I noticed an issue in the analogix_dp_bind() component bind flow:

drivers/gpu/drm/bridge/analogix/analogix_dp_core.c:analogix_dp_bind() {
	...
	bridge->type = DRM_MODE_CONNECTOR_eDP;
	ret = devm_drm_bridge_add(dp->dev, &dp->bridge);
	if (ret)
		goto err_unregister_aux;
	...
}

[Severity: High]
Since devm_drm_bridge_add() is called in a component bind function, does it tie the bridge registration lifetime to the platform device rather than the component?

If the master DRM device defers, unbinds, and later rebinds, analogix_dp_bind() executes again. Because the devres actions are not cleaned up during component unbind, would this trigger duplicate devres additions, list corruption via double list_add_tail() in drm_bridge_add(), and double initialization of the bridge's hpd_mutex?

This is also a pre-existing issue, but I noticed the error paths in the component bind functions seem to be missing cleanup steps:

drivers/gpu/drm/rockchip/analogix_dp-rockchip.c:rockchip_dp_bind() {
	...
	connector = drm_bridge_connector_init(dp->drm_dev,
					      dp->plat_data.encoder);
	if (IS_ERR(connector)) {
		ret = PTR_ERR(connector);
		dev_err(dp->dev, "Failed to initialize bridge_connector\n");
		goto err_cleanup_encoder;
	}

	return 0;
err_cleanup_encoder:
	dp->encoder.encoder.funcs->destroy(&dp->encoder.encoder);
	return ret;
}

[Severity: High]
If drm_bridge_connector_init() fails, does this error path skip calling analogix_dp_unbind()?

This would leave the DP AUX device registered. If component binding is retried, would drm_dp_aux_register() be called again on the same device, causing a sysfs duplicate name error and preventing the display from ever initializing?

A similar issue appears in exynos_dp.c:

drivers/gpu/drm/exynos/exynos_dp.c:exynos_dp_bind() {
	...
	connector = drm_bridge_connector_init(dp->drm_dev,
					      dp->plat_data.encoder);
	if (IS_ERR(connector)) {
		ret = PTR_ERR(connector);
		dev_err(dp->dev, "Failed to initialize bridge_connector\n");
		return ret;
	}

	return 0;
}

[Severity: High]
If drm_bridge_connector_init() fails here, does the error path miss cleaning up the resources by skipping both analogix_dp_unbind() and the encoder destruction?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
author
#6 lore raw

PATCH v8 5/5 drm/bridge: analogix_dp: Add support for optional data-lanes mapping

In reply to Damon Ding

Parse the optional 'data-lanes' device tree property to support custom physical lane mapping configuration.

If no valid configuration is found, fall back to the default lane map (0, 1, 2, 3) automatically and keep the driver running.

Lane mapping is mainly used for below scenarios:
1. Correct PCB lane swap and differential line routing crossover without hardware changes;
2. Adapt mismatched lane pin definitions between SoC and eDP panel;
3. Support multiple panel hardware variants on the same board by configuring data-lanes in device tree only.

---

Changes in v2:
- Add lane mapping application scenarios in commit message.

Changes in v5:
- Add Reviewed-by tag.

Changes in v8:
- Fix reg parameter of of_graph_get_endpoint_by_regs() for parsing "data-lanes" endpoint from -1 to 0.
- Fix the 'tmp' name in analogix_dp_dt_parse_lanes_map() to understandable 'lane_idx'.
- Add comment to explain the lane map fill loop.

---
 .../drm/bridge/analogix/analogix_dp_core.c    | 70 +++++++++++++++++++
 .../drm/bridge/analogix/analogix_dp_core.h    |  4 +-
 .../gpu/drm/bridge/analogix/analogix_dp_reg.c | 15 ++--
 .../gpu/drm/bridge/analogix/analogix_dp_reg.h |  4 ++
 4 files changed, 84 insertions(+), 9 deletions(-)
drivers/gpu/drm/bridge/analogix/analogix_dp_core.c +70 -0
index a74c855936b2..18e76d1e78e1 100644
@@ -1244,6 +1244,73 @@ static const struct drm_bridge_funcs analogix_dp_bridge_funcs = {
 	.detect = analogix_dp_bridge_detect,
 };
 
+static int analogix_dp_dt_parse_lanes_map(struct analogix_dp_device *dp)
+{
+	struct video_info *video_info = &dp->video_info;
+	struct device_node *endpoint;
+	u32 lane_idx[LANE_COUNT4];
+	u32 map[LANE_COUNT4] = {0, 1, 2, 3};
+	bool used[LANE_COUNT4] = {false};
+	int num_lanes;
+	int ret, i;
+
+	memcpy(video_info->lane_map, map, sizeof(map));
+
+	num_lanes = drm_of_get_data_lanes_count_ep(dp->dev->of_node, 1, 0, 1,
+						   video_info->max_lane_count);
+	if (num_lanes < 0)
+		return -EINVAL;
+
+	endpoint = of_graph_get_endpoint_by_regs(dp->dev->of_node, 1, 0);
+	if (!endpoint)
+		return -EINVAL;
+
+	ret = of_property_read_u32_array(endpoint, "data-lanes", lane_idx, num_lanes);
+	of_node_put(endpoint);
+	if (ret)
+		return -EINVAL;
+
+	for (i = 0; i < num_lanes; i++) {
+		if (lane_idx[i] >= LANE_COUNT4) {
+			dev_dbg(dp->dev, "data-lanes[%d] = %u is out of range\n", i, lane_idx[i]);
+			return -EINVAL;
+		}
+
+		if (used[lane_idx[i]]) {
+			dev_dbg(dp->dev, "data-lanes[%d] = %u is duplicate\n", i, lane_idx[i]);
+			return -EINVAL;
+		}
+
+		used[lane_idx[i]] = true;
+		map[i] = lane_idx[i];
+	}
+
+	/*
+	 * Fill the map[] entries not described by 'data-lanes' with the
+	 * lane indices not used so far, e.g. for 'data-lanes = <3 1>':
+	 *
+	 *	used[]       = {0, 1, 0, 1}  // only lanes 1 and 3 are used
+	 *	map[] before = {3, 1, x, x}  // x = unassigned
+	 *	map[] after  = {3, 1, 0, 2}
+	 *
+	 * Unused entries have no effect on the current link with fewer
+	 * lanes in use, but filling them with distinct indices keeps the
+	 * LANE_MAP register holding a valid permutation, just like its
+	 * reset value (0xe4), so the mapping remains sane if a sink with
+	 * a different lane count is connected later, e.g. via DP hot-plug.
+	 */
+	for (i = 0; i < LANE_COUNT4 && num_lanes < LANE_COUNT4; i++) {
+		if (!used[i])
+			map[num_lanes++] = i;
+	}
+
+	dev_dbg(dp->dev, "Using parsed lane map: <%u %u %u %u>\n", map[0], map[1], map[2], map[3]);
+
+	memcpy(video_info->lane_map, map, sizeof(map));
+
+	return 0;
+}
+
 static int analogix_dp_dt_parse_pdata(struct analogix_dp_device *dp)
 {
 	struct device_node *dp_node = dp->dev->of_node;
@@ -1282,6 +1349,9 @@ static int analogix_dp_dt_parse_pdata(struct analogix_dp_device *dp)
 		break;
 	}
 
+	if (analogix_dp_dt_parse_lanes_map(dp))
+		dev_dbg(dp->dev, "No valid data-lanes found, using default lane map\n");
+
 	return 0;
 }
 
drivers/gpu/drm/bridge/analogix/analogix_dp_core.h +3 -1
index c7997677a286..4560597604ad 100644
@@ -137,6 +137,8 @@ struct video_info {
 
 	int max_link_rate;
 	enum link_lane_count_type max_lane_count;
+
+	u32 lane_map[LANE_COUNT4];
 };
 
 struct link_train {
@@ -177,7 +179,7 @@ struct analogix_dp_device {
 /* analogix_dp_reg.c */
 void analogix_dp_enable_video_mute(struct analogix_dp_device *dp, bool enable);
 void analogix_dp_stop_video(struct analogix_dp_device *dp);
-void analogix_dp_lane_swap(struct analogix_dp_device *dp, bool enable);
+void analogix_dp_lane_mapping(struct analogix_dp_device *dp);
 void analogix_dp_init_analog_param(struct analogix_dp_device *dp);
 void analogix_dp_init_interrupt(struct analogix_dp_device *dp);
 void analogix_dp_reset(struct analogix_dp_device *dp);
drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c +7 -8
index ea8401293a23..c1344a3f013a 100644
@@ -48,16 +48,15 @@ void analogix_dp_stop_video(struct analogix_dp_device *dp)
 	writel(reg, dp->reg_base + ANALOGIX_DP_VIDEO_CTL_1);
 }
 
-void analogix_dp_lane_swap(struct analogix_dp_device *dp, bool enable)
+void analogix_dp_lane_mapping(struct analogix_dp_device *dp)
 {
+	u32 *lane_map = dp->video_info.lane_map;
 	u32 reg;
 
-	if (enable)
-		reg = LANE3_MAP_LOGIC_LANE_0 | LANE2_MAP_LOGIC_LANE_1 |
-		      LANE1_MAP_LOGIC_LANE_2 | LANE0_MAP_LOGIC_LANE_3;
-	else
-		reg = LANE3_MAP_LOGIC_LANE_3 | LANE2_MAP_LOGIC_LANE_2 |
-		      LANE1_MAP_LOGIC_LANE_1 | LANE0_MAP_LOGIC_LANE_0;
+	reg = lane_map[0] << LANE0_MAP_SHIFT;
+	reg |= lane_map[1] << LANE1_MAP_SHIFT;
+	reg |= lane_map[2] << LANE2_MAP_SHIFT;
+	reg |= lane_map[3] << LANE3_MAP_SHIFT;
 
 	writel(reg, dp->reg_base + ANALOGIX_DP_LANE_MAP);
 }
@@ -140,7 +139,7 @@ void analogix_dp_reset(struct analogix_dp_device *dp)
 
 	usleep_range(20, 30);
 
-	analogix_dp_lane_swap(dp, 0);
+	analogix_dp_lane_mapping(dp);
 
 	writel(0x0, dp->reg_base + ANALOGIX_DP_SYS_CTL_1);
 	writel(0x40, dp->reg_base + ANALOGIX_DP_SYS_CTL_2);
drivers/gpu/drm/bridge/analogix/analogix_dp_reg.h +4 -0
index 12735139046c..ac914e37089b 100644
@@ -209,6 +209,10 @@
 #define LANE0_MAP_LOGIC_LANE_1			(0x1 << 0)
 #define LANE0_MAP_LOGIC_LANE_2			(0x2 << 0)
 #define LANE0_MAP_LOGIC_LANE_3			(0x3 << 0)
+#define LANE3_MAP_SHIFT				(6)
+#define LANE2_MAP_SHIFT				(4)
+#define LANE1_MAP_SHIFT				(2)
+#define LANE0_MAP_SHIFT				(0)
 
 /* ANALOGIX_DP_ANALOG_CTL_1 */
 #define TX_TERMINAL_CTRL_50_OHM			(0x1 << 4)
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH v8 5/5] drm/bridge: analogix_dp: Add support for optional data-lanes mapping

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Incorrect hardware lane mapping due to logic-to-physical vs physical-to-logic mismatch…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Incorrect hardware lane mapping due to logic-to-physical vs physical-to-logic mismatch, effectively programming the inverse of the intended mapping. --

commit 83b65668f019b59b41d7d71bc5a8a34dd644922a
Author: Damon Ding <[email protected]> drm/bridge: analogix_dp: Add support for optional data-lanes mapping

This commit parses the optional 'data-lanes' device tree property to support custom physical lane mapping configurations. If no valid configuration is found, it automatically falls back to a default lane map.

Quoted 4 lines
drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c +0 -0
index ea8401293a23a..c1344a3f013ab 100644

[ ... ]

Quoted 10 lines
drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c +2 -1
@@ -48,16 +48,15 @@ void analogix_dp_stop_video(struct analogix_dp_device *dp)
 	writel(reg, dp->reg_base + ANALOGIX_DP_VIDEO_CTL_1);
 }
 
-void analogix_dp_lane_swap(struct analogix_dp_device *dp, bool enable)
+void analogix_dp_lane_mapping(struct analogix_dp_device *dp)
 {
+	u32 *lane_map = dp->video_info.lane_map;
 	u32 reg;
 

drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c void analogix_dp_stop_video(struct analogix_dp_device *dp) · line 59

Quoted 10 lines
drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c +4 -6
-	if (enable)
-		reg = LANE3_MAP_LOGIC_LANE_0 | LANE2_MAP_LOGIC_LANE_1 |
-		      LANE1_MAP_LOGIC_LANE_2 | LANE0_MAP_LOGIC_LANE_3;
-	else
-		reg = LANE3_MAP_LOGIC_LANE_3 | LANE2_MAP_LOGIC_LANE_2 |
-		      LANE1_MAP_LOGIC_LANE_1 | LANE0_MAP_LOGIC_LANE_0;
+	reg = lane_map[0] << LANE0_MAP_SHIFT;
+	reg |= lane_map[1] << LANE1_MAP_SHIFT;
+	reg |= lane_map[2] << LANE2_MAP_SHIFT;
+	reg |= lane_map[3] << LANE3_MAP_SHIFT;

[Severity: High]
Does this logic unintentionally program the inverse of the intended lane mapping?

The data-lanes device tree property specifies the physical lane for each logical lane, where lane_map[logical_index] = physical_index. However, the ANALOGIX_DP_LANE_MAP register is structured to select a logical lane for each physical lane.

In analogix_dp_lane_mapping(), the code uses the logical lane index to select the shift mask (e.g., LANE0_MAP_SHIFT) and assigns the physical lane index (lane_map[0]) as the value. This configures physical lane 0 to output logical lane lane_map[0], which results in the inverse of the intended mapping when an asymmetric configuration is used.

Would it be more appropriate to write the logical lane index into the shift corresponding to the physical lane? For example, by doing something like:

    reg |= logical_index << (lane_map[logical_index] * 2);
Quoted 3 lines
drivers/gpu/drm/bridge/analogix/analogix_dp_reg.c +0 -0
 	writel(reg, dp->reg_base + ANALOGIX_DP_LANE_MAP);
 }

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
reviewer Reviewed-by on v8 5/5
#8 lore raw

Re: [PATCH v8 5/5] drm/bridge: analogix_dp: Add support for optional data-lanes mapping

In reply to Damon Ding
Quoted 6 lines · Damon Ding

Parse the optional 'data-lanes' device tree property to support custom physical lane mapping configuration.

If no valid configuration is found, fall back to the default lane map (0, 1, 2, 3) automatically and keep the driver running.

Quoted 8 lines

Lane mapping is mainly used for below scenarios:
1. Correct PCB lane swap and differential line routing crossover without hardware changes;
2. Adapt mismatched lane pin definitions between SoC and eDP panel;
3. Support multiple panel hardware variants on the same board by configuring data-lanes in device tree only.

[...]

Signature · 3 lines
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
reviewer Applied
#9 lore raw
In reply to Damon Ding
Quoted 11 lines · Damon Ding

This series adds configurable eDP physical lane mapping support via device tree data-lanes property.

Lane mapping is mainly used for below scenarios:
1. Correct PCB lane swap and differential line routing crossover without hardware changes;
2. Adapt mismatched lane pin definitions between SoC and eDP panel;
3. Support multiple panel hardware variants on the same board by configuring data-lanes in device tree only.

[...]

Applied, thanks!

[1/5] dt-bindings: display: bridge: analogix-dp: Add data-lanes support for endpoint

      commit: af9b0fc07000db17656580fd38e5ff27c36c2ab9
[2/5] drm/dp: Add helper to validate DP lane counts
      commit: 6eac4c8bb10302abc0ea0bd1d506c46ec789ce2b
[3/5] drm/bridge: analogix_dp: Restore mandatory samsung DP DT properties
      commit: 02f569dd66c94dd67b2586f776235cf4177409ed
[4/5] drm/bridge: analogix_dp: Add validation for samsung,lane-count property
      commit: 4ff2f941b7828042feb2971c7039c8f790a105a4
[5/5] drm/bridge: analogix_dp: Add support for optional data-lanes mapping
      commit: bf63a72ea005d5e1cc12a9ad5e228c4b44246b0f

Best regards,

Signature · 3 lines
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com