Skip to contentSkip to conversation

drm/bridge: dw-mipi-dsi: Find the possible DSI devices

PATCH Applied Jagan Teki 5 participants 8 messages Jul 4, 2021 – Oct 19, 2021

Subsystems (5)

v1 of 4 Applied Latest is v4 →

lore
Share & tools
lore

Jagan Teki

author
#0 lore raw

PATCH 1/1 drm/bridge: dw-mipi-dsi: Find the possible DSI devices

Finding panel_or_bridge might vary based on associated DSI devices like DSI panel, bridge, and I2C based DSI bridge.

1. DSI panels and bridges will invoke the host attach from probe in order to find the panel_or_bridge.

chipone_probe()

       dw_mipi_dsi_host_attach().start
	   dw_mipi_dsi_panel_or_bridge()
		...found the panel_or_bridge...

ltdc_encoder_init().start
dw_mipi_dsi_bridge_attach().start
dw_mipi_dsi_host_attach().start
chipone_attach(). start

chipone_attach(). done
dw_mipi_dsi_host_attach().done
dw_mipi_dsi_bridge_attach(). done
ltdc_encoder_init().done

2. I2C based DSI bridge will invoke the drm_bridge_attach from bridge attach in order to find the panel_or_bridge.

ltdc_encoder_init().start

       dw_mipi_dsi_bridge_attach().start
	   dw_mipi_dsi_panel_or_bridge()
		...found the panel_or_bridge...
		   dw_mipi_dsi_host_attach().start
		       sn65dsi83_attach(). start

	               sn65dsi83_attach(). done
		   dw_mipi_dsi_host_attach().done
       dw_mipi_dsi_bridge_attach(). done

ltdc_encoder_init().done

So, invoke the panel_or_bridge from host attach and bridge attach in order to find all possible DSI devices.

---
 drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 58 ++++++++++++++-----
 1 file changed, 43 insertions(+), 15 deletions(-)
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +43 -15
index 6b268f9445b3..45f4515dda00 100644
@@ -246,6 +246,7 @@ struct dw_mipi_dsi {
 
 	struct clk *pclk;
 
+	bool device_found;
 	unsigned int lane_mbps; /* per lane */
 	u32 channel;
 	u32 lanes;
@@ -309,13 +310,37 @@ static inline u32 dsi_read(struct dw_mipi_dsi *dsi, u32 reg)
 	return readl(dsi->base + reg);
 }
 
+static int dw_mipi_dsi_panel_or_bridge(struct dw_mipi_dsi *dsi,
+				       struct device_node *node)
+{
+	struct drm_bridge *bridge;
+	struct drm_panel *panel;
+	int ret;
+
+	ret = drm_of_find_panel_or_bridge(node, 1, 0, &panel, &bridge);
+	if (ret)
+		return ret;
+
+	if (panel) {
+		bridge = drm_panel_bridge_add_typed(panel,
+						    DRM_MODE_CONNECTOR_DSI);
+		if (IS_ERR(bridge))
+			return PTR_ERR(bridge);
+	}
+
+	dsi->panel_bridge = bridge;
+
+	if (!dsi->panel_bridge)
+		return -EPROBE_DEFER;
+
+	return 0;
+}
+
 static int dw_mipi_dsi_host_attach(struct mipi_dsi_host *host,
 				   struct mipi_dsi_device *device)
 {
 	struct dw_mipi_dsi *dsi = host_to_dsi(host);
 	const struct dw_mipi_dsi_plat_data *pdata = dsi->plat_data;
-	struct drm_bridge *bridge;
-	struct drm_panel *panel;
 	int ret;
 
 	if (device->lanes > dsi->plat_data->max_data_lanes) {
@@ -329,22 +354,14 @@ static int dw_mipi_dsi_host_attach(struct mipi_dsi_host *host,
 	dsi->format = device->format;
 	dsi->mode_flags = device->mode_flags;
 
-	ret = drm_of_find_panel_or_bridge(host->dev->of_node, 1, 0,
-					  &panel, &bridge);
-	if (ret)
-		return ret;
+	if (!dsi->device_found) {
+		ret = dw_mipi_dsi_panel_or_bridge(dsi, host->dev->of_node);
+		if (ret)
+			return ret;
 
-	if (panel) {
-		bridge = drm_panel_bridge_add_typed(panel,
-						    DRM_MODE_CONNECTOR_DSI);
-		if (IS_ERR(bridge))
-			return PTR_ERR(bridge);
+		dsi->device_found = true;
 	}
 
-	dsi->panel_bridge = bridge;
-
-	drm_bridge_add(&dsi->bridge);
-
 	if (pdata->host_ops && pdata->host_ops->attach) {
 		ret = pdata->host_ops->attach(pdata->priv_data, device);
 		if (ret < 0)
@@ -999,6 +1016,16 @@ static int dw_mipi_dsi_bridge_attach(struct drm_bridge *bridge,
 	/* Set the encoder type as caller does not know it */
 	bridge->encoder->encoder_type = DRM_MODE_ENCODER_DSI;
 
+	if (!dsi->device_found) {
+		int ret;
+
+		ret = dw_mipi_dsi_panel_or_bridge(dsi, dsi->dev->of_node);
+		if (ret)
+			return ret;
+
+		dsi->device_found = true;
+	}
+
 	/* Attach the panel-bridge to the dsi bridge */
 	return drm_bridge_attach(bridge->encoder, dsi->panel_bridge, bridge,
 				 flags);
@@ -1181,6 +1208,7 @@ __dw_mipi_dsi_probe(struct platform_device *pdev,
 #ifdef CONFIG_OF
 	dsi->bridge.of_node = pdev->dev.of_node;
 #endif
+	drm_bridge_add(&dsi->bridge);
 
 	return dsi;
 }
Signature · 1 line
2.25.1
Tested-by on v1 1/1
#1 lore raw

Hi Jagan,

Sorry for the delay. Thanks for the patch.

Quoted 151 lines · Jagan Teki

Finding panel_or_bridge might vary based on associated DSI devices like DSI panel, bridge, and I2C based DSI bridge.

1. DSI panels and bridges will invoke the host attach from probe in order to find the panel_or_bridge.

chipone_probe()
dw_mipi_dsi_host_attach().start
dw_mipi_dsi_panel_or_bridge()
...found the panel_or_bridge...

ltdc_encoder_init().start
dw_mipi_dsi_bridge_attach().start
dw_mipi_dsi_host_attach().start
chipone_attach(). start

chipone_attach(). done
dw_mipi_dsi_host_attach().done
dw_mipi_dsi_bridge_attach(). done
ltdc_encoder_init().done

2. I2C based DSI bridge will invoke the drm_bridge_attach

    from bridge attach in order to find the panel_or_bridge.

    ltdc_encoder_init().start
        dw_mipi_dsi_bridge_attach().start
	   dw_mipi_dsi_panel_or_bridge()
		...found the panel_or_bridge...
		   dw_mipi_dsi_host_attach().start
		       sn65dsi83_attach(). start

	               sn65dsi83_attach(). done
		   dw_mipi_dsi_host_attach().done
        dw_mipi_dsi_bridge_attach(). done
    ltdc_encoder_init().done

So, invoke the panel_or_bridge from host attach and bridge attach in order to find all possible DSI devices.

---
  drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 58 ++++++++++++++-----
  1 file changed, 43 insertions(+), 15 deletions(-)
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +43 -15
index 6b268f9445b3..45f4515dda00 100644
@@ -246,6 +246,7 @@ struct dw_mipi_dsi {
 
  	struct clk *pclk;
 
+	bool device_found;
  	unsigned int lane_mbps; /* per lane */
  	u32 channel;
  	u32 lanes;
@@ -309,13 +310,37 @@ static inline u32 dsi_read(struct dw_mipi_dsi *dsi, u32 reg)
  	return readl(dsi->base + reg);
  }
 
+static int dw_mipi_dsi_panel_or_bridge(struct dw_mipi_dsi *dsi,
+				       struct device_node *node)
+{
+	struct drm_bridge *bridge;
+	struct drm_panel *panel;
+	int ret;
+
+	ret = drm_of_find_panel_or_bridge(node, 1, 0, &panel, &bridge);
+	if (ret)
+		return ret;
+
+	if (panel) {
+		bridge = drm_panel_bridge_add_typed(panel,
+						    DRM_MODE_CONNECTOR_DSI);
+		if (IS_ERR(bridge))
+			return PTR_ERR(bridge);
+	}
+
+	dsi->panel_bridge = bridge;
+
+	if (!dsi->panel_bridge)
+		return -EPROBE_DEFER;
+
+	return 0;
+}
+
  static int dw_mipi_dsi_host_attach(struct mipi_dsi_host *host,
  				   struct mipi_dsi_device *device)
  {
  	struct dw_mipi_dsi *dsi = host_to_dsi(host);
  	const struct dw_mipi_dsi_plat_data *pdata = dsi->plat_data;
-	struct drm_bridge *bridge;
-	struct drm_panel *panel;
  	int ret;
 
  	if (device->lanes > dsi->plat_data->max_data_lanes) {
@@ -329,22 +354,14 @@ static int dw_mipi_dsi_host_attach(struct mipi_dsi_host *host,
  	dsi->format = device->format;
  	dsi->mode_flags = device->mode_flags;
 
-	ret = drm_of_find_panel_or_bridge(host->dev->of_node, 1, 0,
-					  &panel, &bridge);
-	if (ret)
-		return ret;
+	if (!dsi->device_found) {
+		ret = dw_mipi_dsi_panel_or_bridge(dsi, host->dev->of_node);
+		if (ret)
+			return ret;
 
-	if (panel) {
-		bridge = drm_panel_bridge_add_typed(panel,
-						    DRM_MODE_CONNECTOR_DSI);
-		if (IS_ERR(bridge))
-			return PTR_ERR(bridge);
+		dsi->device_found = true;
  	}
 
-	dsi->panel_bridge = bridge;
-
-	drm_bridge_add(&dsi->bridge);
-
  	if (pdata->host_ops && pdata->host_ops->attach) {
  		ret = pdata->host_ops->attach(pdata->priv_data, device);
  		if (ret < 0)
@@ -999,6 +1016,16 @@ static int dw_mipi_dsi_bridge_attach(struct drm_bridge *bridge,
  	/* Set the encoder type as caller does not know it */
  	bridge->encoder->encoder_type = DRM_MODE_ENCODER_DSI;
 
+	if (!dsi->device_found) {
+		int ret;
+
+		ret = dw_mipi_dsi_panel_or_bridge(dsi, dsi->dev->of_node);
+		if (ret)
+			return ret;
+
+		dsi->device_found = true;
+	}
+
  	/* Attach the panel-bridge to the dsi bridge */
  	return drm_bridge_attach(bridge->encoder, dsi->panel_bridge, bridge,
  				 flags);
@@ -1181,6 +1208,7 @@ __dw_mipi_dsi_probe(struct platform_device *pdev,
  #ifdef CONFIG_OF
  	dsi->bridge.of_node = pdev->dev.of_node;
  #endif
+	drm_bridge_add(&dsi->bridge);
 
  	return dsi;
  }
maintainer Tested-by on v1 1/1
#3 lore raw
In reply to Jagan Teki

Am Sonntag, 4. Juli 2021, 16:03:09 CEST schrieb Jagan Teki:

Quoted 37 lines

Finding panel_or_bridge might vary based on associated DSI devices like DSI panel, bridge, and I2C based DSI bridge.

1. DSI panels and bridges will invoke the host attach from probe in order to find the panel_or_bridge.

   chipone_probe()
       dw_mipi_dsi_host_attach().start
	   dw_mipi_dsi_panel_or_bridge()
		...found the panel_or_bridge...

   ltdc_encoder_init().start
       dw_mipi_dsi_bridge_attach().start
		   dw_mipi_dsi_host_attach().start
		       chipone_attach(). start

	               chipone_attach(). done
		   dw_mipi_dsi_host_attach().done
       dw_mipi_dsi_bridge_attach(). done
   ltdc_encoder_init().done

2. I2C based DSI bridge will invoke the drm_bridge_attach from bridge attach in order to find the panel_or_bridge.

   ltdc_encoder_init().start
       dw_mipi_dsi_bridge_attach().start
	   dw_mipi_dsi_panel_or_bridge()
		...found the panel_or_bridge...
		   dw_mipi_dsi_host_attach().start
		       sn65dsi83_attach(). start

	               sn65dsi83_attach(). done
		   dw_mipi_dsi_host_attach().done
       dw_mipi_dsi_bridge_attach(). done
   ltdc_encoder_init().done
Quoted 4 lines

So, invoke the panel_or_bridge from host attach and bridge attach in order to find all possible DSI devices.

On px30 with a dsi-display and rk3399 with my csi-phy patches hooking into the rockchip-dsi

Quoted 110 lines
---
 drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 58 ++++++++++++++-----
 1 file changed, 43 insertions(+), 15 deletions(-)
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +43 -15
index 6b268f9445b3..45f4515dda00 100644
@@ -246,6 +246,7 @@ struct dw_mipi_dsi {
 
 	struct clk *pclk;
 
+	bool device_found;
 	unsigned int lane_mbps; /* per lane */
 	u32 channel;
 	u32 lanes;
@@ -309,13 +310,37 @@ static inline u32 dsi_read(struct dw_mipi_dsi *dsi, u32 reg)
 	return readl(dsi->base + reg);
 }
 
+static int dw_mipi_dsi_panel_or_bridge(struct dw_mipi_dsi *dsi,
+				       struct device_node *node)
+{
+	struct drm_bridge *bridge;
+	struct drm_panel *panel;
+	int ret;
+
+	ret = drm_of_find_panel_or_bridge(node, 1, 0, &panel, &bridge);
+	if (ret)
+		return ret;
+
+	if (panel) {
+		bridge = drm_panel_bridge_add_typed(panel,
+						    DRM_MODE_CONNECTOR_DSI);
+		if (IS_ERR(bridge))
+			return PTR_ERR(bridge);
+	}
+
+	dsi->panel_bridge = bridge;
+
+	if (!dsi->panel_bridge)
+		return -EPROBE_DEFER;
+
+	return 0;
+}
+
 static int dw_mipi_dsi_host_attach(struct mipi_dsi_host *host,
 				   struct mipi_dsi_device *device)
 {
 	struct dw_mipi_dsi *dsi = host_to_dsi(host);
 	const struct dw_mipi_dsi_plat_data *pdata = dsi->plat_data;
-	struct drm_bridge *bridge;
-	struct drm_panel *panel;
 	int ret;
 
 	if (device->lanes > dsi->plat_data->max_data_lanes) {
@@ -329,22 +354,14 @@ static int dw_mipi_dsi_host_attach(struct mipi_dsi_host *host,
 	dsi->format = device->format;
 	dsi->mode_flags = device->mode_flags;
 
-	ret = drm_of_find_panel_or_bridge(host->dev->of_node, 1, 0,
-					  &panel, &bridge);
-	if (ret)
-		return ret;
+	if (!dsi->device_found) {
+		ret = dw_mipi_dsi_panel_or_bridge(dsi, host->dev->of_node);
+		if (ret)
+			return ret;
 
-	if (panel) {
-		bridge = drm_panel_bridge_add_typed(panel,
-						    DRM_MODE_CONNECTOR_DSI);
-		if (IS_ERR(bridge))
-			return PTR_ERR(bridge);
+		dsi->device_found = true;
 	}
 
-	dsi->panel_bridge = bridge;
-
-	drm_bridge_add(&dsi->bridge);
-
 	if (pdata->host_ops && pdata->host_ops->attach) {
 		ret = pdata->host_ops->attach(pdata->priv_data, device);
 		if (ret < 0)
@@ -999,6 +1016,16 @@ static int dw_mipi_dsi_bridge_attach(struct drm_bridge *bridge,
 	/* Set the encoder type as caller does not know it */
 	bridge->encoder->encoder_type = DRM_MODE_ENCODER_DSI;
 
+	if (!dsi->device_found) {
+		int ret;
+
+		ret = dw_mipi_dsi_panel_or_bridge(dsi, dsi->dev->of_node);
+		if (ret)
+			return ret;
+
+		dsi->device_found = true;
+	}
+
 	/* Attach the panel-bridge to the dsi bridge */
 	return drm_bridge_attach(bridge->encoder, dsi->panel_bridge, bridge,
 				 flags);
@@ -1181,6 +1208,7 @@ __dw_mipi_dsi_probe(struct platform_device *pdev,
 #ifdef CONFIG_OF
 	dsi->bridge.of_node = pdev->dev.of_node;
 #endif
+	drm_bridge_add(&dsi->bridge);
 
 	return dsi;
 }
#5 lore raw
In reply to Jagan Teki

Hi

Quoted 37 lines · Jagan Teki

Finding panel_or_bridge might vary based on associated DSI devices like DSI panel, bridge, and I2C based DSI bridge.

1. DSI panels and bridges will invoke the host attach from probe in order to find the panel_or_bridge.

   chipone_probe()
       dw_mipi_dsi_host_attach().start
	   dw_mipi_dsi_panel_or_bridge()
		...found the panel_or_bridge...

   ltdc_encoder_init().start
       dw_mipi_dsi_bridge_attach().start
		   dw_mipi_dsi_host_attach().start
		       chipone_attach(). start

	               chipone_attach(). done
		   dw_mipi_dsi_host_attach().done
       dw_mipi_dsi_bridge_attach(). done
   ltdc_encoder_init().done

2. I2C based DSI bridge will invoke the drm_bridge_attach from bridge attach in order to find the panel_or_bridge.

   ltdc_encoder_init().start
       dw_mipi_dsi_bridge_attach().start
	   dw_mipi_dsi_panel_or_bridge()
		...found the panel_or_bridge...
		   dw_mipi_dsi_host_attach().start
		       sn65dsi83_attach(). start

	               sn65dsi83_attach(). done
		   dw_mipi_dsi_host_attach().done
       dw_mipi_dsi_bridge_attach(). done
   ltdc_encoder_init().done
Quoted 3 lines

So, invoke the panel_or_bridge from host attach and bridge attach in order to find all possible DSI devices.

Working on linux-next-5.14-rc4 on px30-evb rockchip board. On top of this patch for px30 dsi I need to add:

From a0e0344b4cb4df3d97fac0e27e0aa76a2a191b0e Mon Sep 17 00:00:00 2001
From: Michael Trimarchi <[email protected]>
Date: Sun, 10 Oct 2021 23:56:20 +0200
Subject: [PATCH] drm: dw-mipi-dsi-rockchip: Avoid the attach before probe is
completed

---
 drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c   |  8 +++++++-
 drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c | 12 ++++++++----
 include/drm/bridge/dw_mipi_dsi.h                |  2 +-
 3 files changed, 16 insertions(+), 6 deletions(-)
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +7 -1
index 45f4515dda00..a5535f183af3 100644
@@ -362,8 +362,14 @@ static int dw_mipi_dsi_host_attach(struct mipi_dsi_host *host,
 		dsi->device_found = true;
 	}
 
+	/*
+	 * NOTE: the dsi registration is implemented in
+	 * platform driver, that to say dsi would be exist after
+	 * probe is terminated. The call is done before the end of probe
+	 * so we need to pass the dsi to the platform driver.
+	 */
 	if (pdata->host_ops && pdata->host_ops->attach) {
-		ret = pdata->host_ops->attach(pdata->priv_data, device);
+		ret = pdata->host_ops->attach(pdata->priv_data, device, dsi);
 		if (ret < 0)
 			return ret;
 	}
drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c +8 -4
index ec7729d18cb8..cf7c9cf11c9e 100644
@@ -972,12 +972,15 @@ static const struct component_ops dw_mipi_dsi_rockchip_ops = {
 };
 
 static int dw_mipi_dsi_rockchip_host_attach(void *priv_data,
-					    struct mipi_dsi_device *device)
+					    struct mipi_dsi_device *device,
+					    struct dw_mipi_dsi *dmd)
 {
 	struct dw_mipi_dsi_rockchip *dsi = priv_data;
 	struct device *second;
 	int ret;
 
+	dsi->dmd = dmd;
+
 	ret = component_add(dsi->dev, &dw_mipi_dsi_rockchip_ops);
 	if (ret) {
 		DRM_DEV_ERROR(dsi->dev, "Failed to register component: %d\n",
@@ -1027,6 +1030,7 @@ static int dw_mipi_dsi_rockchip_probe(struct platform_device *pdev)
 	struct device_node *np = dev->of_node;
 	struct dw_mipi_dsi_rockchip *dsi;
 	struct resource *res;
+	struct dw_mipi_dsi *dmd;
 	const struct rockchip_dw_dsi_chip_data *cdata =
 				of_device_get_match_data(dev);
 	int ret, i;
@@ -1115,9 +1119,9 @@ static int dw_mipi_dsi_rockchip_probe(struct platform_device *pdev)
 	dsi->pdata.priv_data = dsi;
 	platform_set_drvdata(pdev, dsi);
 
-	dsi->dmd = dw_mipi_dsi_probe(pdev, &dsi->pdata);
-	if (IS_ERR(dsi->dmd)) {
-		ret = PTR_ERR(dsi->dmd);
+	dmd = dw_mipi_dsi_probe(pdev, &dsi->pdata);
+	if (IS_ERR(dmd)) {
+		ret = PTR_ERR(dmd);
 		if (ret != -EPROBE_DEFER)
 			DRM_DEV_ERROR(dev,
 				      "Failed to probe dw_mipi_dsi: %d\n", ret);
include/drm/bridge/dw_mipi_dsi.h +1 -1
index bda8aa7c2280..cf81f19806ad 100644
@@ -41,7 +41,7 @@ struct dw_mipi_dsi_phy_ops {
 
 struct dw_mipi_dsi_host_ops {
 	int (*attach)(void *priv_data,
-		      struct mipi_dsi_device *dsi);
+		      struct mipi_dsi_device *dsi, struct dw_mipi_dsi *dmd);
 	int (*detach)(void *priv_data,
 		      struct mipi_dsi_device *dsi);
 };

During the probing the sequence let arrive to attach before the rockchip driver terminate to be registered. Anyway the panel is not working at the moment for some timing issue

Michael

Signature · 1 line
2.25.1
Quoted 114 lines
---
 drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 58 ++++++++++++++-----
 1 file changed, 43 insertions(+), 15 deletions(-)
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +43 -15
index 6b268f9445b3..45f4515dda00 100644
@@ -246,6 +246,7 @@ struct dw_mipi_dsi {
 
 	struct clk *pclk;
 
+	bool device_found;
 	unsigned int lane_mbps; /* per lane */
 	u32 channel;
 	u32 lanes;
@@ -309,13 +310,37 @@ static inline u32 dsi_read(struct dw_mipi_dsi *dsi, u32 reg)
 	return readl(dsi->base + reg);
 }
 
+static int dw_mipi_dsi_panel_or_bridge(struct dw_mipi_dsi *dsi,
+				       struct device_node *node)
+{
+	struct drm_bridge *bridge;
+	struct drm_panel *panel;
+	int ret;
+
+	ret = drm_of_find_panel_or_bridge(node, 1, 0, &panel, &bridge);
+	if (ret)
+		return ret;
+
+	if (panel) {
+		bridge = drm_panel_bridge_add_typed(panel,
+						    DRM_MODE_CONNECTOR_DSI);
+		if (IS_ERR(bridge))
+			return PTR_ERR(bridge);
+	}
+
+	dsi->panel_bridge = bridge;
+
+	if (!dsi->panel_bridge)
+		return -EPROBE_DEFER;
+
+	return 0;
+}
+
 static int dw_mipi_dsi_host_attach(struct mipi_dsi_host *host,
 				   struct mipi_dsi_device *device)
 {
 	struct dw_mipi_dsi *dsi = host_to_dsi(host);
 	const struct dw_mipi_dsi_plat_data *pdata = dsi->plat_data;
-	struct drm_bridge *bridge;
-	struct drm_panel *panel;
 	int ret;
 
 	if (device->lanes > dsi->plat_data->max_data_lanes) {
@@ -329,22 +354,14 @@ static int dw_mipi_dsi_host_attach(struct mipi_dsi_host *host,
 	dsi->format = device->format;
 	dsi->mode_flags = device->mode_flags;
 
-	ret = drm_of_find_panel_or_bridge(host->dev->of_node, 1, 0,
-					  &panel, &bridge);
-	if (ret)
-		return ret;
+	if (!dsi->device_found) {
+		ret = dw_mipi_dsi_panel_or_bridge(dsi, host->dev->of_node);
+		if (ret)
+			return ret;
 
-	if (panel) {
-		bridge = drm_panel_bridge_add_typed(panel,
-						    DRM_MODE_CONNECTOR_DSI);
-		if (IS_ERR(bridge))
-			return PTR_ERR(bridge);
+		dsi->device_found = true;
 	}
 
-	dsi->panel_bridge = bridge;
-
-	drm_bridge_add(&dsi->bridge);
-
 	if (pdata->host_ops && pdata->host_ops->attach) {
 		ret = pdata->host_ops->attach(pdata->priv_data, device);
 		if (ret < 0)
@@ -999,6 +1016,16 @@ static int dw_mipi_dsi_bridge_attach(struct drm_bridge *bridge,
 	/* Set the encoder type as caller does not know it */
 	bridge->encoder->encoder_type = DRM_MODE_ENCODER_DSI;
 
+	if (!dsi->device_found) {
+		int ret;
+
+		ret = dw_mipi_dsi_panel_or_bridge(dsi, dsi->dev->of_node);
+		if (ret)
+			return ret;
+
+		dsi->device_found = true;
+	}
+
 	/* Attach the panel-bridge to the dsi bridge */
 	return drm_bridge_attach(bridge->encoder, dsi->panel_bridge, bridge,
 				 flags);
@@ -1181,6 +1208,7 @@ __dw_mipi_dsi_probe(struct platform_device *pdev,
 #ifdef CONFIG_OF
 	dsi->bridge.of_node = pdev->dev.of_node;
 #endif
+	drm_bridge_add(&dsi->bridge);
 
 	return dsi;
 }
Signature · 1 line
2.25.1
#6 lore raw
Quoted 41 lines · Michael Trimarchi

Hi

Quoted 37 lines · Jagan Teki

Finding panel_or_bridge might vary based on associated DSI devices like DSI panel, bridge, and I2C based DSI bridge.

1. DSI panels and bridges will invoke the host attach from probe in order to find the panel_or_bridge.

   chipone_probe()
       dw_mipi_dsi_host_attach().start
         dw_mipi_dsi_panel_or_bridge()
              ...found the panel_or_bridge...

   ltdc_encoder_init().start
       dw_mipi_dsi_bridge_attach().start
                 dw_mipi_dsi_host_attach().start
                     chipone_attach(). start

                     chipone_attach(). done
                 dw_mipi_dsi_host_attach().done
       dw_mipi_dsi_bridge_attach(). done
   ltdc_encoder_init().done

2. I2C based DSI bridge will invoke the drm_bridge_attach from bridge attach in order to find the panel_or_bridge.

   ltdc_encoder_init().start
       dw_mipi_dsi_bridge_attach().start
         dw_mipi_dsi_panel_or_bridge()
              ...found the panel_or_bridge...
                 dw_mipi_dsi_host_attach().start
                     sn65dsi83_attach(). start

                     sn65dsi83_attach(). done
                 dw_mipi_dsi_host_attach().done
       dw_mipi_dsi_bridge_attach(). done
   ltdc_encoder_init().done
Quoted 7 lines
Quoted 3 lines

So, invoke the panel_or_bridge from host attach and bridge attach in order to find all possible DSI devices.

Working on linux-next-5.14-rc4 on px30-evb rockchip board. On top of this patch for px30 dsi I need to add:

I wrote the driver for evb px30 v11. I just need to clean up a bit. Anyway the video is correct.
Using my patch. The display is not a module

Module                  Size  Used by
bluetooth             438272  2
ecdh_generic           16384  1 bluetooth
ecc                    36864  1 ecdh_generic
brcmfmac              249856  0
crct10dif_ce           20480  1
brcmutil               20480  1 brcmfmac
dwmac_rk               28672  0
stmmac_platform        20480  1 dwmac_rk
cfg80211              360448  1 brcmfmac
rfkill                 36864  3 bluetooth,cfg80211
stmmac                217088  2 stmmac_platform,dwmac_rk
rockchip_saradc        16384  0
pcs_xpcs               24576  1 stmmac
industrialio_triggered_buffer    16384  1 rockchip_saradc
rockchip_thermal       24576  0
kfifo_buf              16384  1 industrialio_triggered_buffer
rtc_rk808              16384  1
goodix                 24576  0
snd_soc_rockchip_i2s    16384  0
snd_soc_rockchip_pcm    16384  1 snd_soc_rockchip_i2s
adc_keys               16384  0
fuse                  131072  1
ipv6                  446464  36

Michael

Quoted 207 lines

From a0e0344b4cb4df3d97fac0e27e0aa76a2a191b0e Mon Sep 17 00:00:00 2001
From: Michael Trimarchi <[email protected]>
Date: Sun, 10 Oct 2021 23:56:20 +0200
Subject: [PATCH] drm: dw-mipi-dsi-rockchip: Avoid the attach before probe is
completed

---
 drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c   |  8 +++++++-
 drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c | 12 ++++++++----
 include/drm/bridge/dw_mipi_dsi.h                |  2 +-
 3 files changed, 16 insertions(+), 6 deletions(-)
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +7 -1
index 45f4515dda00..a5535f183af3 100644
@@ -362,8 +362,14 @@ static int dw_mipi_dsi_host_attach(struct mipi_dsi_host *host,
                dsi->device_found = true;
        }
 
+       /*
+        * NOTE: the dsi registration is implemented in
+        * platform driver, that to say dsi would be exist after
+        * probe is terminated. The call is done before the end of probe
+        * so we need to pass the dsi to the platform driver.
+        */
        if (pdata->host_ops && pdata->host_ops->attach) {
-               ret = pdata->host_ops->attach(pdata->priv_data, device);
+               ret = pdata->host_ops->attach(pdata->priv_data, device, dsi);
                if (ret < 0)
                        return ret;
        }
drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c +8 -4
index ec7729d18cb8..cf7c9cf11c9e 100644
@@ -972,12 +972,15 @@ static const struct component_ops dw_mipi_dsi_rockchip_ops = {
 };
 
 static int dw_mipi_dsi_rockchip_host_attach(void *priv_data,
-                                           struct mipi_dsi_device *device)
+                                           struct mipi_dsi_device *device,
+                                           struct dw_mipi_dsi *dmd)
 {
        struct dw_mipi_dsi_rockchip *dsi = priv_data;
        struct device *second;
        int ret;
 
+       dsi->dmd = dmd;
+
        ret = component_add(dsi->dev, &dw_mipi_dsi_rockchip_ops);
        if (ret) {
                DRM_DEV_ERROR(dsi->dev, "Failed to register component: %d\n",
@@ -1027,6 +1030,7 @@ static int dw_mipi_dsi_rockchip_probe(struct platform_device *pdev)
        struct device_node *np = dev->of_node;
        struct dw_mipi_dsi_rockchip *dsi;
        struct resource *res;
+       struct dw_mipi_dsi *dmd;
        const struct rockchip_dw_dsi_chip_data *cdata =
                                of_device_get_match_data(dev);
        int ret, i;
@@ -1115,9 +1119,9 @@ static int dw_mipi_dsi_rockchip_probe(struct platform_device *pdev)
        dsi->pdata.priv_data = dsi;
        platform_set_drvdata(pdev, dsi);
 
-       dsi->dmd = dw_mipi_dsi_probe(pdev, &dsi->pdata);
-       if (IS_ERR(dsi->dmd)) {
-               ret = PTR_ERR(dsi->dmd);
+       dmd = dw_mipi_dsi_probe(pdev, &dsi->pdata);
+       if (IS_ERR(dmd)) {
+               ret = PTR_ERR(dmd);
                if (ret != -EPROBE_DEFER)
                        DRM_DEV_ERROR(dev,
                                      "Failed to probe dw_mipi_dsi: %d\n", ret);
include/drm/bridge/dw_mipi_dsi.h +1 -1
index bda8aa7c2280..cf81f19806ad 100644
@@ -41,7 +41,7 @@ struct dw_mipi_dsi_phy_ops {
 
 struct dw_mipi_dsi_host_ops {
        int (*attach)(void *priv_data,
-                     struct mipi_dsi_device *dsi);
+                     struct mipi_dsi_device *dsi, struct dw_mipi_dsi *dmd);
        int (*detach)(void *priv_data,
                      struct mipi_dsi_device *dsi);
 };

During the probing the sequence let arrive to attach before the rockchip driver terminate to be registered. Anyway the panel is not working at the moment for some timing issue

Michael

--
2.25.1

Quoted 108 lines
---
 drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 58 ++++++++++++++-----
 1 file changed, 43 insertions(+), 15 deletions(-)
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +43 -15
index 6b268f9445b3..45f4515dda00 100644
@@ -246,6 +246,7 @@ struct dw_mipi_dsi {
 
      struct clk *pclk;
 
+     bool device_found;
      unsigned int lane_mbps; /* per lane */
      u32 channel;
      u32 lanes;
@@ -309,13 +310,37 @@ static inline u32 dsi_read(struct dw_mipi_dsi *dsi, u32 reg)
      return readl(dsi->base + reg);
 }
 
+static int dw_mipi_dsi_panel_or_bridge(struct dw_mipi_dsi *dsi,
+                                    struct device_node *node)
+{
+     struct drm_bridge *bridge;
+     struct drm_panel *panel;
+     int ret;
+
+     ret = drm_of_find_panel_or_bridge(node, 1, 0, &panel, &bridge);
+     if (ret)
+             return ret;
+
+     if (panel) {
+             bridge = drm_panel_bridge_add_typed(panel,
+                                                 DRM_MODE_CONNECTOR_DSI);
+             if (IS_ERR(bridge))
+                     return PTR_ERR(bridge);
+     }
+
+     dsi->panel_bridge = bridge;
+
+     if (!dsi->panel_bridge)
+             return -EPROBE_DEFER;
+
+     return 0;
+}
+
 static int dw_mipi_dsi_host_attach(struct mipi_dsi_host *host,
                                 struct mipi_dsi_device *device)
 {
      struct dw_mipi_dsi *dsi = host_to_dsi(host);
      const struct dw_mipi_dsi_plat_data *pdata = dsi->plat_data;
-     struct drm_bridge *bridge;
-     struct drm_panel *panel;
      int ret;
 
      if (device->lanes > dsi->plat_data->max_data_lanes) {
@@ -329,22 +354,14 @@ static int dw_mipi_dsi_host_attach(struct mipi_dsi_host *host,
      dsi->format = device->format;
      dsi->mode_flags = device->mode_flags;
 
-     ret = drm_of_find_panel_or_bridge(host->dev->of_node, 1, 0,
-                                       &panel, &bridge);
-     if (ret)
-             return ret;
+     if (!dsi->device_found) {
+             ret = dw_mipi_dsi_panel_or_bridge(dsi, host->dev->of_node);
+             if (ret)
+                     return ret;
 
-     if (panel) {
-             bridge = drm_panel_bridge_add_typed(panel,
-                                                 DRM_MODE_CONNECTOR_DSI);
-             if (IS_ERR(bridge))
-                     return PTR_ERR(bridge);
+             dsi->device_found = true;
      }
 
-     dsi->panel_bridge = bridge;
-
-     drm_bridge_add(&dsi->bridge);
-
      if (pdata->host_ops && pdata->host_ops->attach) {
              ret = pdata->host_ops->attach(pdata->priv_data, device);
              if (ret < 0)
@@ -999,6 +1016,16 @@ static int dw_mipi_dsi_bridge_attach(struct drm_bridge *bridge,
      /* Set the encoder type as caller does not know it */
      bridge->encoder->encoder_type = DRM_MODE_ENCODER_DSI;
 
+     if (!dsi->device_found) {
+             int ret;
+
+             ret = dw_mipi_dsi_panel_or_bridge(dsi, dsi->dev->of_node);
+             if (ret)
+                     return ret;
+
+             dsi->device_found = true;
+     }
+
      /* Attach the panel-bridge to the dsi bridge */
      return drm_bridge_attach(bridge->encoder, dsi->panel_bridge, bridge,
                               flags);
@@ -1181,6 +1208,7 @@ __dw_mipi_dsi_probe(struct platform_device *pdev,
 #ifdef CONFIG_OF
      dsi->bridge.of_node = pdev->dev.of_node;
 #endif
+     drm_bridge_add(&dsi->bridge);
 
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +0 -1
      return dsi;
 }
--

2.25.1

--
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com

Acked-by
#7 lore raw

Thanks for catching this Michael.

Quoted 33 lines
Quoted 3 lines

Working on linux-next-5.14-rc4 on px30-evb rockchip board. On top of this patch for px30 dsi I need to add:

I wrote the driver for evb px30 v11. I just need to clean up a bit. Anyway the video is correct.
Using my patch. The display is not a module

Module                  Size  Used by
bluetooth             438272  2
ecdh_generic           16384  1 bluetooth
ecc                    36864  1 ecdh_generic
brcmfmac              249856  0
crct10dif_ce           20480  1
brcmutil               20480  1 brcmfmac
dwmac_rk               28672  0
stmmac_platform        20480  1 dwmac_rk
cfg80211              360448  1 brcmfmac
rfkill                 36864  3 bluetooth,cfg80211
stmmac                217088  2 stmmac_platform,dwmac_rk
rockchip_saradc        16384  0
pcs_xpcs               24576  1 stmmac
industrialio_triggered_buffer    16384  1 rockchip_saradc
rockchip_thermal       24576  0
kfifo_buf              16384  1 industrialio_triggered_buffer
rtc_rk808              16384  1
goodix                 24576  0
snd_soc_rockchip_i2s    16384  0
snd_soc_rockchip_pcm    16384  1 snd_soc_rockchip_i2s
adc_keys               16384  0
fuse                  131072  1
ipv6                  446464  36
Quoted 1 line

Michael

Can you submit this patch separately and add a Fixes tag to it?

With the above fixed, the drm-misc related changes have my ack.

Quoted 95 lines
Quoted 95 lines

From a0e0344b4cb4df3d97fac0e27e0aa76a2a191b0e Mon Sep 17 00:00:00 2001
From: Michael Trimarchi <[email protected]>
Date: Sun, 10 Oct 2021 23:56:20 +0200
Subject: [PATCH] drm: dw-mipi-dsi-rockchip: Avoid the attach before probe is
completed

---
 drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c   |  8 +++++++-
 drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c | 12 ++++++++----
 include/drm/bridge/dw_mipi_dsi.h                |  2 +-
 3 files changed, 16 insertions(+), 6 deletions(-)
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +7 -1
index 45f4515dda00..a5535f183af3 100644
@@ -362,8 +362,14 @@ static int dw_mipi_dsi_host_attach(struct mipi_dsi_host *host,
                dsi->device_found = true;
        }
 
+       /*
+        * NOTE: the dsi registration is implemented in
+        * platform driver, that to say dsi would be exist after
+        * probe is terminated. The call is done before the end of probe
+        * so we need to pass the dsi to the platform driver.
+        */
        if (pdata->host_ops && pdata->host_ops->attach) {
-               ret = pdata->host_ops->attach(pdata->priv_data, device);
+               ret = pdata->host_ops->attach(pdata->priv_data, device, dsi);
                if (ret < 0)
                        return ret;
        }
drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c +8 -4
index ec7729d18cb8..cf7c9cf11c9e 100644
@@ -972,12 +972,15 @@ static const struct component_ops dw_mipi_dsi_rockchip_ops = {
 };
 
 static int dw_mipi_dsi_rockchip_host_attach(void *priv_data,
-                                           struct mipi_dsi_device *device)
+                                           struct mipi_dsi_device *device,
+                                           struct dw_mipi_dsi *dmd)
 {
        struct dw_mipi_dsi_rockchip *dsi = priv_data;
        struct device *second;
        int ret;
 
+       dsi->dmd = dmd;
+
        ret = component_add(dsi->dev, &dw_mipi_dsi_rockchip_ops);
        if (ret) {
                DRM_DEV_ERROR(dsi->dev, "Failed to register component: %d\n",
@@ -1027,6 +1030,7 @@ static int dw_mipi_dsi_rockchip_probe(struct platform_device *pdev)
        struct device_node *np = dev->of_node;
        struct dw_mipi_dsi_rockchip *dsi;
        struct resource *res;
+       struct dw_mipi_dsi *dmd;
        const struct rockchip_dw_dsi_chip_data *cdata =
                                of_device_get_match_data(dev);
        int ret, i;
@@ -1115,9 +1119,9 @@ static int dw_mipi_dsi_rockchip_probe(struct platform_device *pdev)
        dsi->pdata.priv_data = dsi;
        platform_set_drvdata(pdev, dsi);
 
-       dsi->dmd = dw_mipi_dsi_probe(pdev, &dsi->pdata);
-       if (IS_ERR(dsi->dmd)) {
-               ret = PTR_ERR(dsi->dmd);
+       dmd = dw_mipi_dsi_probe(pdev, &dsi->pdata);
+       if (IS_ERR(dmd)) {
+               ret = PTR_ERR(dmd);
                if (ret != -EPROBE_DEFER)
                        DRM_DEV_ERROR(dev,
                                      "Failed to probe dw_mipi_dsi: %d\n", ret);
include/drm/bridge/dw_mipi_dsi.h +1 -1
index bda8aa7c2280..cf81f19806ad 100644
@@ -41,7 +41,7 @@ struct dw_mipi_dsi_phy_ops {
 
 struct dw_mipi_dsi_host_ops {
        int (*attach)(void *priv_data,
-                     struct mipi_dsi_device *dsi);
+                     struct mipi_dsi_device *dsi, struct dw_mipi_dsi *dmd);
        int (*detach)(void *priv_data,
                      struct mipi_dsi_device *dsi);
 };

During the probing the sequence let arrive to attach before the rockchip driver terminate to be registered. Anyway the panel is not working at the moment for some timing issue