Skip to contentSkip to conversation

drm/bridge: Allow using fwnode API to get the next bridge

PATCH Superseded Sui Jingfeng 4 participants 21 messages Jan 22, 2024 – Mar 20, 2024

Subsystems (3)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover drm/bridge: Allow using fwnode API to get the next bridge

Make it possible to use drm-bridge drivers on non-DT based systems.

Sui Jingfeng (5):
drm/bridge: Add drm_bridge_find_by_fwnode() helper drm/bridge: simple-bridge: Extend match support for non-DT based
systems
drm/bridge: simple-bridge: Allow acquiring the next bridge with fwnode
API
drm/bridge: display-connector: Extend match support for non-DT based
systems
drm-bridge: display-connector: Switch to use fwnode API

 drivers/gpu/drm/bridge/display-connector.c | 46 +++++++++----
 drivers/gpu/drm/bridge/simple-bridge.c     | 75 +++++++++++++++++++---
 drivers/gpu/drm/drm_bridge.c               | 33 ++++++++++
 include/drm/drm_bridge.h                   |  4 ++
 4 files changed, 139 insertions(+), 19 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/5 drm/bridge: Add drm_bridge_find_by_fwnode() helper

Because ACPI based systems only has the fwnode associated, the of_node member of struct device is NULL. To order to move things forward, we add drm_bridge_find_by_fwnode() to extend the support.

---
 drivers/gpu/drm/drm_bridge.c | 33 +++++++++++++++++++++++++++++++++
 include/drm/drm_bridge.h     |  4 ++++
 2 files changed, 37 insertions(+)
drivers/gpu/drm/drm_bridge.c +33 -0
index cee3188adf3d..ffd969adc2fb 100644
@@ -1347,6 +1347,39 @@ struct drm_bridge *of_drm_find_bridge(struct device_node *np)
 EXPORT_SYMBOL(of_drm_find_bridge);
 #endif
 
+/**
+ * drm_bridge_find_by_fwnode - Find the bridge corresponding to the associated fwnode
+ *
+ * @fwnode: fwnode for which to find the matching drm_bridge
+ *
+ * This function looks up a drm_bridge based on its associated fwnode.
+ *
+ * RETURNS:
+ * A reference to the drm_bridge control structure if found, NULL on failure.
+ */
+struct drm_bridge *drm_bridge_find_by_fwnode(struct fwnode_handle *fwnode)
+{
+	struct drm_bridge *ret = NULL;
+	struct drm_bridge *bridge;
+
+	if (!fwnode)
+		return NULL;
+
+	mutex_lock(&bridge_lock);
+
+	list_for_each_entry(bridge, &bridge_list, list) {
+		if (bridge->fwnode == fwnode) {
+			ret = bridge;
+			break;
+		}
+	}
+
+	mutex_unlock(&bridge_lock);
+
+	return ret;
+}
+EXPORT_SYMBOL(drm_bridge_find_by_fwnode);
+
 MODULE_AUTHOR("Ajay Kumar <[email protected]>");
 MODULE_DESCRIPTION("DRM bridge infrastructure");
 MODULE_LICENSE("GPL and additional rights");
include/drm/drm_bridge.h +4 -0
index e39da5807ba7..fe3d5f4bf37f 100644
@@ -720,6 +720,8 @@ struct drm_bridge {
 	struct list_head chain_node;
 	/** @of_node: device node pointer to the bridge */
 	struct device_node *of_node;
+	/** @fwnode: associated fwnode supplied by platform firmware */
+	struct fwnode_handle *fwnode;
 	/** @list: to keep track of all added bridges */
 	struct list_head list;
 	/**
@@ -796,6 +798,8 @@ static inline struct drm_bridge *of_drm_find_bridge(struct device_node *np)
 }
 #endif
 
+struct drm_bridge *drm_bridge_find_by_fwnode(struct fwnode_handle *fwnode);
+
 /**
  * drm_bridge_get_next_bridge() - Get the next bridge in the chain
  * @bridge: bridge object
Signature · 1 line
2.25.1
#5 lore raw

PATCH 2/5 drm/bridge: simple-bridge: Extend match support for non-DT based systems

In reply to Sui Jingfeng

Which is intended to be used on non-DT environment, where the simple-bridge platform device is created by either the display controller driver side or platform firmware subsystem. To avoid duplication and to keep consistent, we choose to reuse the OF match tables. Because the potentional user may not has a of_node attached, nor a ACPI match id. If this is the case, a software node string property can be provide to fill the niche.

---
 drivers/gpu/drm/bridge/simple-bridge.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/simple-bridge.c +23 -1
index cbe8e778d7c7..595f672745b9 100644
@@ -166,6 +166,24 @@ static const struct drm_bridge_funcs simple_bridge_bridge_funcs = {
 	.disable	= simple_bridge_disable,
 };
 
+static const void *simple_bridge_get_match_data(const struct device *dev)
+{
+	const struct of_device_id *matches = dev->driver->of_match_table;
+
+	/* Try to get the match data by software node */
+	while (matches) {
+		if (!matches->compatible[0])
+			break;
+
+		if (device_is_compatible(dev, matches->compatible))
+			return matches->data;
+
+		matches++;
+	}
+
+	return NULL;
+}
+
 static int simple_bridge_probe(struct platform_device *pdev)
 {
 	struct simple_bridge *sbridge;
@@ -176,7 +194,10 @@ static int simple_bridge_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	platform_set_drvdata(pdev, sbridge);
 
-	sbridge->info = of_device_get_match_data(&pdev->dev);
+	if (pdev->dev.of_node)
+		sbridge->info = of_device_get_match_data(&pdev->dev);
+	else
+		sbridge->info = simple_bridge_get_match_data(&pdev->dev);
 
 	/* Get the next bridge in the pipeline. */
 	remote = of_graph_get_remote_node(pdev->dev.of_node, 1, -1);
@@ -309,3 +330,4 @@ module_platform_driver(simple_bridge_driver);
 MODULE_AUTHOR("Maxime Ripard <[email protected]>");
 MODULE_DESCRIPTION("Simple DRM bridge driver");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:simple-bridge");
Signature · 1 line
2.25.1
#11 lore raw

PATCH 3/5 drm/bridge: simple-bridge: Allow acquiring the next bridge with fwnode API

In reply to Sui Jingfeng

Which make it possible to use this driver on non-DT based systems, meanwhile, made no functional changes for DT based systems.

---
 drivers/gpu/drm/bridge/simple-bridge.c | 51 ++++++++++++++++++++++----
 1 file changed, 44 insertions(+), 7 deletions(-)
drivers/gpu/drm/bridge/simple-bridge.c +44 -7
index 595f672745b9..cfea5a67cc5b 100644
@@ -184,6 +184,39 @@ static const void *simple_bridge_get_match_data(const struct device *dev)
 	return NULL;
 }
 
+static int simple_bridge_get_next_bridge_by_fwnode(struct device *dev,
+						   struct drm_bridge **next_bridge)
+{
+	struct drm_bridge *bridge;
+	struct fwnode_handle *ep;
+	struct fwnode_handle *remote;
+
+	ep = fwnode_graph_get_endpoint_by_id(dev->fwnode, 1, 0, 0);
+	if (!ep) {
+		dev_err(dev, "The endpoint is unconnected\n");
+		return -EINVAL;
+	}
+
+	remote = fwnode_graph_get_remote_port_parent(ep);
+	fwnode_handle_put(ep);
+	if (!remote) {
+		dev_err(dev, "No valid remote node\n");
+		return -ENODEV;
+	}
+
+	bridge = drm_bridge_find_by_fwnode(remote);
+	fwnode_handle_put(remote);
+
+	if (!bridge) {
+		dev_warn(dev, "Next bridge not found, deferring probe\n");
+		return -EPROBE_DEFER;
+	}
+
+	*next_bridge = bridge;
+
+	return 0;
+}
+
 static int simple_bridge_probe(struct platform_device *pdev)
 {
 	struct simple_bridge *sbridge;
@@ -199,14 +232,17 @@ static int simple_bridge_probe(struct platform_device *pdev)
 	else
 		sbridge->info = simple_bridge_get_match_data(&pdev->dev);
 
-	/* Get the next bridge in the pipeline. */
-	remote = of_graph_get_remote_node(pdev->dev.of_node, 1, -1);
-	if (!remote)
-		return -EINVAL;
-
-	sbridge->next_bridge = of_drm_find_bridge(remote);
-	of_node_put(remote);
+	if (pdev->dev.of_node) {
+		/* Get the next bridge in the pipeline. */
+		remote = of_graph_get_remote_node(pdev->dev.of_node, 1, -1);
+		if (!remote)
+			return -EINVAL;
 
+		sbridge->next_bridge = of_drm_find_bridge(remote);
+		of_node_put(remote);
+	} else {
+		simple_bridge_get_next_bridge_by_fwnode(&pdev->dev, &sbridge->next_bridge);
+	}
 	if (!sbridge->next_bridge) {
 		dev_dbg(&pdev->dev, "Next bridge not found, deferring probe\n");
 		return -EPROBE_DEFER;
@@ -231,6 +267,7 @@ static int simple_bridge_probe(struct platform_device *pdev)
 	/* Register the bridge. */
 	sbridge->bridge.funcs = &simple_bridge_bridge_funcs;
 	sbridge->bridge.of_node = pdev->dev.of_node;
+	sbridge->bridge.fwnode = pdev->dev.fwnode;
 	sbridge->bridge.timings = sbridge->info->timings;
 
 	drm_bridge_add(&sbridge->bridge);
Signature · 1 line
2.25.1
#16 lore raw

PATCH 4/5 drm/bridge: display-connector: Extend match support for non-DT based systems

In reply to Sui Jingfeng

On which case the driver is not probed by OF, Instead, a fwnode is associated to the platform device before this driver is probed. The newly added code is intended to be used on non-DT environment. It is assumed that there is a string fwnode property associated with the platform device, the name of the string property is compatible, the value of the string property is used to get platform match data.

---
 drivers/gpu/drm/bridge/display-connector.c | 24 +++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/display-connector.c +23 -1
index 08bd5695ddae..eb7e194e7735 100644
@@ -202,6 +202,24 @@ static int display_connector_get_supply(struct platform_device *pdev,
 	return PTR_ERR_OR_ZERO(conn->supply);
 }
 
+static const void *display_connector_get_match_data(const struct device *dev)
+{
+	const struct of_device_id *matches = dev->driver->of_match_table;
+
+	/* Try to get the match data by software node */
+	while (matches) {
+		if (!matches->compatible[0])
+			break;
+
+		if (device_is_compatible(dev, matches->compatible))
+			return matches->data;
+
+		matches++;
+	}
+
+	return NULL;
+}
+
 static int display_connector_probe(struct platform_device *pdev)
 {
 	struct display_connector *conn;
@@ -215,7 +233,10 @@ static int display_connector_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, conn);
 
-	type = (uintptr_t)of_device_get_match_data(&pdev->dev);
+	if (pdev->dev.of_node)
+		type = (uintptr_t)of_device_get_match_data(&pdev->dev);
+	else
+		type = (uintptr_t)display_connector_get_match_data(&pdev->dev);
 
 	/* Get the exact connector type. */
 	switch (type) {
@@ -434,3 +455,4 @@ module_platform_driver(display_connector_driver);
 MODULE_AUTHOR("Laurent Pinchart <[email protected]>");
 MODULE_DESCRIPTION("Display connector driver");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:display-connector");
Signature · 1 line
2.25.1
#17 lore raw

PATCH 5/5 drm-bridge: display-connector: Switch to use fwnode API

In reply to Sui Jingfeng

From: Sui Jingfeng <[email protected]>

Because API has wider coverage, it can be used on non-DT systems as well.

---
 drivers/gpu/drm/bridge/display-connector.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/gpu/drm/bridge/display-connector.c +12 -10
index eb7e194e7735..2c3e54a458e8 100644
@@ -243,8 +243,8 @@ static int display_connector_probe(struct platform_device *pdev)
 	case DRM_MODE_CONNECTOR_DVII: {
 		bool analog, digital;
 
-		analog = of_property_read_bool(pdev->dev.of_node, "analog");
-		digital = of_property_read_bool(pdev->dev.of_node, "digital");
+		analog = fwnode_property_present(pdev->dev.fwnode, "analog");
+		digital = fwnode_property_present(pdev->dev.fwnode, "digital");
 		if (analog && !digital) {
 			conn->bridge.type = DRM_MODE_CONNECTOR_DVIA;
 		} else if (!analog && digital) {
@@ -261,8 +261,8 @@ static int display_connector_probe(struct platform_device *pdev)
 	case DRM_MODE_CONNECTOR_HDMIA: {
 		const char *hdmi_type;
 
-		ret = of_property_read_string(pdev->dev.of_node, "type",
-					      &hdmi_type);
+		ret = fwnode_property_read_string(pdev->dev.fwnode, "type",
+						  &hdmi_type);
 		if (ret < 0) {
 			dev_err(&pdev->dev, "HDMI connector with no type\n");
 			return -EINVAL;
@@ -292,7 +292,7 @@ static int display_connector_probe(struct platform_device *pdev)
 	conn->bridge.interlace_allowed = true;
 
 	/* Get the optional connector label. */
-	of_property_read_string(pdev->dev.of_node, "label", &label);
+	fwnode_property_read_string(pdev->dev.fwnode, "label", &label);
 
 	/*
 	 * Get the HPD GPIO for DVI, HDMI and DP connectors. If the GPIO can provide
@@ -330,12 +330,13 @@ static int display_connector_probe(struct platform_device *pdev)
 	if (type == DRM_MODE_CONNECTOR_DVII ||
 	    type == DRM_MODE_CONNECTOR_HDMIA ||
 	    type == DRM_MODE_CONNECTOR_VGA) {
-		struct device_node *phandle;
+		struct fwnode_handle *fwnode;
 
-		phandle = of_parse_phandle(pdev->dev.of_node, "ddc-i2c-bus", 0);
-		if (phandle) {
-			conn->bridge.ddc = of_get_i2c_adapter_by_node(phandle);
-			of_node_put(phandle);
+		fwnode = fwnode_find_reference(pdev->dev.fwnode, "ddc-i2c-bus", 0);
+		if (!IS_ERR_OR_NULL(fwnode)) {
+			dev_info(&pdev->dev, "has I2C bus property\n");
+			conn->bridge.ddc = i2c_get_adapter_by_fwnode(fwnode);
+			fwnode_handle_put(fwnode);
 			if (!conn->bridge.ddc)
 				return -EPROBE_DEFER;
 		} else {
@@ -380,6 +381,7 @@ static int display_connector_probe(struct platform_device *pdev)
 
 	conn->bridge.funcs = &display_connector_bridge_funcs;
 	conn->bridge.of_node = pdev->dev.of_node;
+	conn->bridge.fwnode = pdev->dev.fwnode;
 
 	if (conn->bridge.ddc)
 		conn->bridge.ops |= DRM_BRIDGE_OP_EDID
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 1/5] drm/bridge: Add drm_bridge_find_by_fwnode() helper

In reply to Sui Jingfeng

Hi Sui,

Thank you for the patch.

Quoted 5 lines · Sui Jingfeng

Because ACPI based systems only has the fwnode associated, the of_node member of struct device is NULL. To order to move things forward, we add drm_bridge_find_by_fwnode() to extend the support.

Could we switch completely to fwnode, instead of maintaining the fwnode and OF options side-by-side ?

Quoted 71 lines
---
 drivers/gpu/drm/drm_bridge.c | 33 +++++++++++++++++++++++++++++++++
 include/drm/drm_bridge.h     |  4 ++++
 2 files changed, 37 insertions(+)
drivers/gpu/drm/drm_bridge.c +33 -0
index cee3188adf3d..ffd969adc2fb 100644
@@ -1347,6 +1347,39 @@ struct drm_bridge *of_drm_find_bridge(struct device_node *np)
 EXPORT_SYMBOL(of_drm_find_bridge);
 #endif
 
+/**
+ * drm_bridge_find_by_fwnode - Find the bridge corresponding to the associated fwnode
+ *
+ * @fwnode: fwnode for which to find the matching drm_bridge
+ *
+ * This function looks up a drm_bridge based on its associated fwnode.
+ *
+ * RETURNS:
+ * A reference to the drm_bridge control structure if found, NULL on failure.
+ */
+struct drm_bridge *drm_bridge_find_by_fwnode(struct fwnode_handle *fwnode)
+{
+	struct drm_bridge *ret = NULL;
+	struct drm_bridge *bridge;
+
+	if (!fwnode)
+		return NULL;
+
+	mutex_lock(&bridge_lock);
+
+	list_for_each_entry(bridge, &bridge_list, list) {
+		if (bridge->fwnode == fwnode) {
+			ret = bridge;
+			break;
+		}
+	}
+
+	mutex_unlock(&bridge_lock);
+
+	return ret;
+}
+EXPORT_SYMBOL(drm_bridge_find_by_fwnode);
+
 MODULE_AUTHOR("Ajay Kumar <[email protected]>");
 MODULE_DESCRIPTION("DRM bridge infrastructure");
 MODULE_LICENSE("GPL and additional rights");
include/drm/drm_bridge.h +4 -0
index e39da5807ba7..fe3d5f4bf37f 100644
@@ -720,6 +720,8 @@ struct drm_bridge {
 	struct list_head chain_node;
 	/** @of_node: device node pointer to the bridge */
 	struct device_node *of_node;
+	/** @fwnode: associated fwnode supplied by platform firmware */
+	struct fwnode_handle *fwnode;
 	/** @list: to keep track of all added bridges */
 	struct list_head list;
 	/**
@@ -796,6 +798,8 @@ static inline struct drm_bridge *of_drm_find_bridge(struct device_node *np)
 }
 #endif
 
+struct drm_bridge *drm_bridge_find_by_fwnode(struct fwnode_handle *fwnode);
+
 /**
  * drm_bridge_get_next_bridge() - Get the next bridge in the chain
  * @bridge: bridge object
Signature · 3 lines
Regards,

Laurent Pinchart
#12 lore raw

Re: [PATCH 3/5] drm/bridge: simple-bridge: Allow acquiring the next bridge with fwnode API

In reply to Sui Jingfeng
Quoted 39 lines · Sui Jingfeng

Which make it possible to use this driver on non-DT based systems, meanwhile, made no functional changes for DT based systems.

---
 drivers/gpu/drm/bridge/simple-bridge.c | 51 ++++++++++++++++++++++----
 1 file changed, 44 insertions(+), 7 deletions(-)
drivers/gpu/drm/bridge/simple-bridge.c +23 -0
index 595f672745b9..cfea5a67cc5b 100644
@@ -184,6 +184,39 @@ static const void *simple_bridge_get_match_data(const struct device *dev)
 	return NULL;
 }
 
+static int simple_bridge_get_next_bridge_by_fwnode(struct device *dev,
+						   struct drm_bridge **next_bridge)
+{
+	struct drm_bridge *bridge;
+	struct fwnode_handle *ep;
+	struct fwnode_handle *remote;
+
+	ep = fwnode_graph_get_endpoint_by_id(dev->fwnode, 1, 0, 0);
+	if (!ep) {
+		dev_err(dev, "The endpoint is unconnected\n");
+		return -EINVAL;
+	}
+
+	remote = fwnode_graph_get_remote_port_parent(ep);
+	fwnode_handle_put(ep);
+	if (!remote) {
+		dev_err(dev, "No valid remote node\n");
+		return -ENODEV;
+	}
+
+	bridge = drm_bridge_find_by_fwnode(remote);
+	fwnode_handle_put(remote);
+

drivers/gpu/drm/bridge/simple-bridge.c static const void *simple_bridge_get_match_data(const struct device *dev) · line 219

Quoted 10 lines
drivers/gpu/drm/bridge/simple-bridge.c +10 -0
+	if (!bridge) {
+		dev_warn(dev, "Next bridge not found, deferring probe\n");
+		return -EPROBE_DEFER;
+	}
+
+	*next_bridge = bridge;
+
+	return 0;
+}
+

Hmmmm yes, this convinces me further that we should switch to fwnode, not implement fwnode and OF side-by-side.

Quoted 39 lines
drivers/gpu/drm/bridge/simple-bridge.c +11 -7
 static int simple_bridge_probe(struct platform_device *pdev)
 {
 	struct simple_bridge *sbridge;
@@ -199,14 +232,17 @@ static int simple_bridge_probe(struct platform_device *pdev)
 	else
 		sbridge->info = simple_bridge_get_match_data(&pdev->dev);
 
-	/* Get the next bridge in the pipeline. */
-	remote = of_graph_get_remote_node(pdev->dev.of_node, 1, -1);
-	if (!remote)
-		return -EINVAL;
-
-	sbridge->next_bridge = of_drm_find_bridge(remote);
-	of_node_put(remote);
+	if (pdev->dev.of_node) {
+		/* Get the next bridge in the pipeline. */
+		remote = of_graph_get_remote_node(pdev->dev.of_node, 1, -1);
+		if (!remote)
+			return -EINVAL;
 
+		sbridge->next_bridge = of_drm_find_bridge(remote);
+		of_node_put(remote);
+	} else {
+		simple_bridge_get_next_bridge_by_fwnode(&pdev->dev, &sbridge->next_bridge);
+	}
 	if (!sbridge->next_bridge) {
 		dev_dbg(&pdev->dev, "Next bridge not found, deferring probe\n");
 		return -EPROBE_DEFER;
@@ -231,6 +267,7 @@ static int simple_bridge_probe(struct platform_device *pdev)
 	/* Register the bridge. */
 	sbridge->bridge.funcs = &simple_bridge_bridge_funcs;
 	sbridge->bridge.of_node = pdev->dev.of_node;
+	sbridge->bridge.fwnode = pdev->dev.fwnode;
 	sbridge->bridge.timings = sbridge->info->timings;
 
 	drm_bridge_add(&sbridge->bridge);
Signature · 1 line
2.25.1
Signature · 3 lines
Regards,

Laurent Pinchart
#18 lore raw

Re: [PATCH 5/5] drm-bridge: display-connector: Switch to use fwnode API

In reply to Sui Jingfeng
Quoted 48 lines · Sui Jingfeng

From: Sui Jingfeng <[email protected]>

Because API has wider coverage, it can be used on non-DT systems as well.

---
 drivers/gpu/drm/bridge/display-connector.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/gpu/drm/bridge/display-connector.c +5 -5
index eb7e194e7735..2c3e54a458e8 100644
@@ -243,8 +243,8 @@ static int display_connector_probe(struct platform_device *pdev)
 	case DRM_MODE_CONNECTOR_DVII: {
 		bool analog, digital;
 
-		analog = of_property_read_bool(pdev->dev.of_node, "analog");
-		digital = of_property_read_bool(pdev->dev.of_node, "digital");
+		analog = fwnode_property_present(pdev->dev.fwnode, "analog");
+		digital = fwnode_property_present(pdev->dev.fwnode, "digital");
 		if (analog && !digital) {
 			conn->bridge.type = DRM_MODE_CONNECTOR_DVIA;
 		} else if (!analog && digital) {
@@ -261,8 +261,8 @@ static int display_connector_probe(struct platform_device *pdev)
 	case DRM_MODE_CONNECTOR_HDMIA: {
 		const char *hdmi_type;
 
-		ret = of_property_read_string(pdev->dev.of_node, "type",
-					      &hdmi_type);
+		ret = fwnode_property_read_string(pdev->dev.fwnode, "type",
+						  &hdmi_type);
 		if (ret < 0) {
 			dev_err(&pdev->dev, "HDMI connector with no type\n");
 			return -EINVAL;
@@ -292,7 +292,7 @@ static int display_connector_probe(struct platform_device *pdev)
 	conn->bridge.interlace_allowed = true;
 
 	/* Get the optional connector label. */
-	of_property_read_string(pdev->dev.of_node, "label", &label);
+	fwnode_property_read_string(pdev->dev.fwnode, "label", &label);
 
 	/*
 	 * Get the HPD GPIO for DVI, HDMI and DP connectors. If the GPIO can provide
@@ -330,12 +330,13 @@ static int display_connector_probe(struct platform_device *pdev)
 	if (type == DRM_MODE_CONNECTOR_DVII ||
 	    type == DRM_MODE_CONNECTOR_HDMIA ||
 	    type == DRM_MODE_CONNECTOR_VGA) {

drivers/gpu/drm/bridge/display-connector.c static int display_connector_probe(struct platform_device *pdev) · line 337

Quoted 10 lines
drivers/gpu/drm/bridge/display-connector.c +4 -5
-		struct device_node *phandle;
+		struct fwnode_handle *fwnode;
 
-		phandle = of_parse_phandle(pdev->dev.of_node, "ddc-i2c-bus", 0);
-		if (phandle) {
-			conn->bridge.ddc = of_get_i2c_adapter_by_node(phandle);
-			of_node_put(phandle);
+		fwnode = fwnode_find_reference(pdev->dev.fwnode, "ddc-i2c-bus", 0);
+		if (!IS_ERR_OR_NULL(fwnode)) {
+			dev_info(&pdev->dev, "has I2C bus property\n");

This looks like a debugging leftover.

drivers/gpu/drm/bridge/display-connector.c static int display_connector_probe(struct platform_device *pdev) · line 384

Quoted 10 lines
drivers/gpu/drm/bridge/display-connector.c +3 -0
+			conn->bridge.ddc = i2c_get_adapter_by_fwnode(fwnode);
+			fwnode_handle_put(fwnode);
 			if (!conn->bridge.ddc)
 				return -EPROBE_DEFER;
 		} else {
@@ -380,6 +381,7 @@ static int display_connector_probe(struct platform_device *pdev)
 
 	conn->bridge.funcs = &display_connector_bridge_funcs;
 	conn->bridge.of_node = pdev->dev.of_node;
+	conn->bridge.fwnode = pdev->dev.fwnode;

This goes in the right direction. Let's address the other drivers and drop the OF-based calls in the same series :-)

Quoted 3 lines
drivers/gpu/drm/bridge/display-connector.c +0 -0
 	if (conn->bridge.ddc)
 		conn->bridge.ops |= DRM_BRIDGE_OP_EDID
Signature · 3 lines
Regards,

Laurent Pinchart
#6 lore raw

Re: [PATCH 2/5] drm/bridge: simple-bridge: Extend match support for non-DT based systems

In reply to Sui Jingfeng
Quoted 3 lines · Sui Jingfeng

Which is intended to be used on non-DT environment, where the simple-bridge platform device is created by either the display controller driver side or platform firmware subsystem.

Could you give an example of a platform where you intend to use this ?

Quoted 4 lines

To avoid duplication and to keep consistent,
we choose to reuse the OF match tables. Because the potentional user may not has a of_node attached, nor a ACPI match id. If this is the case, a software node string property can be provide to fill the niche.

Shouldn't non-DT, non-ACPI platforms use swnodes ?

Quoted 47 lines
---
 drivers/gpu/drm/bridge/simple-bridge.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/simple-bridge.c +22 -1
index cbe8e778d7c7..595f672745b9 100644
@@ -166,6 +166,24 @@ static const struct drm_bridge_funcs simple_bridge_bridge_funcs = {
 	.disable	= simple_bridge_disable,
 };
 
+static const void *simple_bridge_get_match_data(const struct device *dev)
+{
+	const struct of_device_id *matches = dev->driver->of_match_table;
+
+	/* Try to get the match data by software node */
+	while (matches) {
+		if (!matches->compatible[0])
+			break;
+
+		if (device_is_compatible(dev, matches->compatible))
+			return matches->data;
+
+		matches++;
+	}
+
+	return NULL;
+}
+
 static int simple_bridge_probe(struct platform_device *pdev)
 {
 	struct simple_bridge *sbridge;
@@ -176,7 +194,10 @@ static int simple_bridge_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	platform_set_drvdata(pdev, sbridge);
 
-	sbridge->info = of_device_get_match_data(&pdev->dev);
+	if (pdev->dev.of_node)
+		sbridge->info = of_device_get_match_data(&pdev->dev);
+	else
+		sbridge->info = simple_bridge_get_match_data(&pdev->dev);
 
 	/* Get the next bridge in the pipeline. */
 	remote = of_graph_get_remote_node(pdev->dev.of_node, 1, -1);

drivers/gpu/drm/bridge/simple-bridge.c module_platform_driver(simple_bridge_driver); · line 333

Quoted 4 lines
drivers/gpu/drm/bridge/simple-bridge.c +1 -0
@@ -309,3 +330,4 @@ module_platform_driver(simple_bridge_driver);
 MODULE_AUTHOR("Maxime Ripard <[email protected]>");
 MODULE_DESCRIPTION("Simple DRM bridge driver");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:simple-bridge");

This is an unrelated change.

Signature · 3 lines
Regards,

Laurent Pinchart
#3 lore raw

Re: [PATCH 1/5] drm/bridge: Add drm_bridge_find_by_fwnode() helper

In reply to Laurent Pinchart

Hi,

Thanks a lot for your review :-)

Quoted 4 lines · Laurent Pinchart

Hi Sui,

Thank you for the patch.

Quoted 8 lines
Quoted 5 lines · Sui Jingfeng

Because ACPI based systems only has the fwnode associated, the of_node member of struct device is NULL. To order to move things forward, we add drm_bridge_find_by_fwnode() to extend the support.

Could we switch completely to fwnode, instead of maintaining the fwnode and OF options side-by-side ?

The side-by-side approach allow us to migrate smoothly, the main consideration is that the OF approach has been works very well, it is flexible and very successful in the embedded world.

It seems that the fwnode API could NOT replace the OF
options completely. For example, the'of_device_id' and 'of_match_table' related things are always there, there are large well-established helpers and subroutines and
already formed as a standard. Some part of it may suffer
from backward compatibility problems.

So I want to leave some space to other programmers. Maybe there are other programmers who feel that using OF alone is enough for a specific problem(domain).

#7 lore raw

Re: [PATCH 2/5] drm/bridge: simple-bridge: Extend match support for non-DT based systems

In reply to Laurent Pinchart

Hi,

Quoted 5 lines · Laurent Pinchart
Quoted 3 lines · Sui Jingfeng

Which is intended to be used on non-DT environment, where the simple-bridge platform device is created by either the display controller driver side or platform firmware subsystem.

Could you give an example of a platform where you intend to use this ?

For example:

1) USB based display adapter, such as FL2000DX[1] which use the it66121 HDMI transmitter to convert the RGB888 to HDMI.

2) Simple 2D PCIe display controller, such as SM750(EMPV-1201) which using sii9022 HDMI transmitter to convert the RGB888 to HDMI.

3) Some FPGA PCIe Board (sil9136)

4) Be able to run unit test of drm bridges on X86.

[1] https://github.com/FrescoLogic/FL2000

#13 lore raw

Re: [PATCH 3/5] drm/bridge: simple-bridge: Allow acquiring the next bridge with fwnode API

In reply to Laurent Pinchart

Hi,

Quoted 44 lines · Laurent Pinchart
Quoted 43 lines · Sui Jingfeng

Which make it possible to use this driver on non-DT based systems, meanwhile, made no functional changes for DT based systems.

---
  drivers/gpu/drm/bridge/simple-bridge.c | 51 ++++++++++++++++++++++----
  1 file changed, 44 insertions(+), 7 deletions(-)
drivers/gpu/drm/bridge/simple-bridge.c +27 -0
index 595f672745b9..cfea5a67cc5b 100644
@@ -184,6 +184,39 @@ static const void *simple_bridge_get_match_data(const struct device *dev)
  	return NULL;
  }
 
+static int simple_bridge_get_next_bridge_by_fwnode(struct device *dev,
+						   struct drm_bridge **next_bridge)
+{
+	struct drm_bridge *bridge;
+	struct fwnode_handle *ep;
+	struct fwnode_handle *remote;
+
+	ep = fwnode_graph_get_endpoint_by_id(dev->fwnode, 1, 0, 0);
+	if (!ep) {
+		dev_err(dev, "The endpoint is unconnected\n");
+		return -EINVAL;
+	}
+
+	remote = fwnode_graph_get_remote_port_parent(ep);
+	fwnode_handle_put(ep);
+	if (!remote) {
+		dev_err(dev, "No valid remote node\n");
+		return -ENODEV;
+	}
+
+	bridge = drm_bridge_find_by_fwnode(remote);
+	fwnode_handle_put(remote);
+
+	if (!bridge) {
+		dev_warn(dev, "Next bridge not found, deferring probe\n");
+		return -EPROBE_DEFER;
+	}
Quoted 9 lines

drivers/gpu/drm/bridge/simple-bridge.c static const void *simple_bridge_get_match_data(const struct device *dev) · line 219

Quoted 6 lines
drivers/gpu/drm/bridge/simple-bridge.c +6 -0
+
+	*next_bridge = bridge;
+
+	return 0;
+}
+

Hmmmm yes, this convinces me further that we should switch to fwnode, not implement fwnode and OF side-by-side.

OK, I'm agree with you.

But this means that I have to make the drm_bridge_find_by_fwnode() function works on both DT systems and non-DT systems. This is also means that we will no longer need to call of_drm_find_bridge() function anymore. This will eventually lead to completely remove of_drm_find_bridge()?

As far as I can see, if I follow you suggestion, drm/bridge subsystem will encountering a *big* refactor. My 'side-by-side' approach allows co-exist. It is not really meant to purge OF. I feel it is a little bit of aggressive.

hello Maxime, are you watching this? what do you think?

Quoted 39 lines
Quoted 39 lines
drivers/gpu/drm/bridge/simple-bridge.c +11 -7
  static int simple_bridge_probe(struct platform_device *pdev)
  {
  	struct simple_bridge *sbridge;
@@ -199,14 +232,17 @@ static int simple_bridge_probe(struct platform_device *pdev)
  	else
  		sbridge->info = simple_bridge_get_match_data(&pdev->dev);
 
-	/* Get the next bridge in the pipeline. */
-	remote = of_graph_get_remote_node(pdev->dev.of_node, 1, -1);
-	if (!remote)
-		return -EINVAL;
-
-	sbridge->next_bridge = of_drm_find_bridge(remote);
-	of_node_put(remote);
+	if (pdev->dev.of_node) {
+		/* Get the next bridge in the pipeline. */
+		remote = of_graph_get_remote_node(pdev->dev.of_node, 1, -1);
+		if (!remote)
+			return -EINVAL;
 
+		sbridge->next_bridge = of_drm_find_bridge(remote);
+		of_node_put(remote);
+	} else {
+		simple_bridge_get_next_bridge_by_fwnode(&pdev->dev, &sbridge->next_bridge);
+	}
  	if (!sbridge->next_bridge) {
  		dev_dbg(&pdev->dev, "Next bridge not found, deferring probe\n");
  		return -EPROBE_DEFER;
@@ -231,6 +267,7 @@ static int simple_bridge_probe(struct platform_device *pdev)
  	/* Register the bridge. */
  	sbridge->bridge.funcs = &simple_bridge_bridge_funcs;
  	sbridge->bridge.of_node = pdev->dev.of_node;
+	sbridge->bridge.fwnode = pdev->dev.fwnode;
  	sbridge->bridge.timings = sbridge->info->timings;
 
  	drm_bridge_add(&sbridge->bridge);
Signature · 1 line
2.25.1
#9 lore raw

Re: [PATCH 2/5] drm/bridge: simple-bridge: Extend match support for non-DT based systems

In reply to Laurent Pinchart

Hi,

Quoted 13 lines · Laurent Pinchart
Quoted 13 lines
  static int simple_bridge_probe(struct platform_device *pdev)
  {
  	struct simple_bridge *sbridge;
drivers/gpu/drm/bridge/simple-bridge.c +4 -1
@@ -176,7 +194,10 @@ static int simple_bridge_probe(struct platform_device *pdev)
  		return -ENOMEM;
  	platform_set_drvdata(pdev, sbridge);
 
-	sbridge->info = of_device_get_match_data(&pdev->dev);
+	if (pdev->dev.of_node)
+		sbridge->info = of_device_get_match_data(&pdev->dev);
+	else
+		sbridge->info = simple_bridge_get_match_data(&pdev->dev);
 
Quoted 8 lines

drivers/gpu/drm/bridge/simple-bridge.c module_platform_driver(simple_bridge_driver); · line 333

Quoted 7 lines
drivers/gpu/drm/bridge/simple-bridge.c +1 -0
  	/* Get the next bridge in the pipeline. */
  	remote = of_graph_get_remote_node(pdev->dev.of_node, 1, -1);
@@ -309,3 +330,4 @@ module_platform_driver(simple_bridge_driver);
  MODULE_AUTHOR("Maxime Ripard<[email protected]>");
  MODULE_DESCRIPTION("Simple DRM bridge driver");
  MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:simple-bridge");

This is an unrelated change.

Otherwise, this driver will not be probed when compiled as module on non-DT environment.

#19 lore raw

Re: [PATCH 5/5] drm-bridge: display-connector: Switch to use fwnode API

In reply to Laurent Pinchart

Hi,

Quoted 52 lines · Laurent Pinchart
Quoted 51 lines · Sui Jingfeng

From: Sui Jingfeng<[email protected]>

Because API has wider coverage, it can be used on non-DT systems as well.

---
  drivers/gpu/drm/bridge/display-connector.c | 22 ++++++++++++----------
  1 file changed, 12 insertions(+), 10 deletions(-)
drivers/gpu/drm/bridge/display-connector.c +6 -6
index eb7e194e7735..2c3e54a458e8 100644
@@ -243,8 +243,8 @@ static int display_connector_probe(struct platform_device *pdev)
  	case DRM_MODE_CONNECTOR_DVII: {
  		bool analog, digital;
 
-		analog = of_property_read_bool(pdev->dev.of_node, "analog");
-		digital = of_property_read_bool(pdev->dev.of_node, "digital");
+		analog = fwnode_property_present(pdev->dev.fwnode, "analog");
+		digital = fwnode_property_present(pdev->dev.fwnode, "digital");
  		if (analog && !digital) {
  			conn->bridge.type = DRM_MODE_CONNECTOR_DVIA;
  		} else if (!analog && digital) {
@@ -261,8 +261,8 @@ static int display_connector_probe(struct platform_device *pdev)
  	case DRM_MODE_CONNECTOR_HDMIA: {
  		const char *hdmi_type;
 
-		ret = of_property_read_string(pdev->dev.of_node, "type",
-					      &hdmi_type);
+		ret = fwnode_property_read_string(pdev->dev.fwnode, "type",
+						  &hdmi_type);
  		if (ret < 0) {
  			dev_err(&pdev->dev, "HDMI connector with no type\n");
  			return -EINVAL;
@@ -292,7 +292,7 @@ static int display_connector_probe(struct platform_device *pdev)
  	conn->bridge.interlace_allowed = true;
 
  	/* Get the optional connector label. */
-	of_property_read_string(pdev->dev.of_node, "label", &label);
+	fwnode_property_read_string(pdev->dev.fwnode, "label", &label);
 
  	/*
  	 * Get the HPD GPIO for DVI, HDMI and DP connectors. If the GPIO can provide
@@ -330,12 +330,13 @@ static int display_connector_probe(struct platform_device *pdev)
  	if (type == DRM_MODE_CONNECTOR_DVII ||
  	    type == DRM_MODE_CONNECTOR_HDMIA ||
  	    type == DRM_MODE_CONNECTOR_VGA) {
-		struct device_node *phandle;
+		struct fwnode_handle *fwnode;
 
Quoted 8 lines

drivers/gpu/drm/bridge/display-connector.c static int display_connector_probe(struct platform_device *pdev) · line 337

Quoted 7 lines
drivers/gpu/drm/bridge/display-connector.c +3 -4
-		phandle = of_parse_phandle(pdev->dev.of_node, "ddc-i2c-bus", 0);
-		if (phandle) {
-			conn->bridge.ddc = of_get_i2c_adapter_by_node(phandle);
-			of_node_put(phandle);
+		fwnode = fwnode_find_reference(pdev->dev.fwnode, "ddc-i2c-bus", 0);
+		if (!IS_ERR_OR_NULL(fwnode)) {
+			dev_info(&pdev->dev, "has I2C bus property\n");

This looks like a debugging leftover.

Yes, thanks a lot for reviewing.
I will pick up suggestions and go back to improve.

#4 lore raw

Re: [PATCH 1/5] drm/bridge: Add drm_bridge_find_by_fwnode() helper

In reply to Sui Jingfeng

Hi Sui,

Quoted 6 lines · Sui Jingfeng
Quoted 5 lines · Laurent Pinchart
Quoted 4 lines · Sui Jingfeng

Because ACPI based systems only has the fwnode associated, the of_node member of struct device is NULL. To order to move things forward, we add drm_bridge_find_by_fwnode() to extend the support.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Could we switch completely to fwnode, instead of maintaining the fwnode and OF options side-by-side ?

The side-by-side approach allow us to migrate smoothly,

But it increases the maintenance burden for the duration of the migration. I fear the migration would span years, with nobody really taking active care of it, and the OF and non-OF API will have a risk to diverge.

Quoted 3 lines

the main consideration is that the OF approach has been works very well, it is flexible and very successful in the embedded world.

fwnode is a superset of OF, so I don't expect issues switching from OF to fwnode. For the non-OF, non-fwnode users, that's possibly a different question.

Quoted 2 lines

It seems that the fwnode API could NOT replace the OF
options completely. For example, the'of_device_id' and 'of_match_table' related things are always there, there

Yes, and that's not a problem. OF drivers still use of_device_id and of_match_table, even if they use the fwnode API. No issue there.

Quoted 3 lines

are large well-established helpers and subroutines and already formed as a standard. Some part of it may suffer from backward compatibility problems.

fwnode has been designed to offer the same API as OF for drivers. If something is missing, it can be raised with the maintainers.

Quoted 3 lines

So I want to leave some space to other programmers. Maybe there are other programmers who feel that using OF alone is enough for a specific problem(domain).

Signature · 3 lines
Regards,

Laurent Pinchart
#8 lore raw

Re: [PATCH 2/5] drm/bridge: simple-bridge: Extend match support for non-DT based systems

In reply to Sui Jingfeng
Quoted 13 lines · Sui Jingfeng
Quoted 6 lines · Laurent Pinchart
Quoted 3 lines · Sui Jingfeng

Which is intended to be used on non-DT environment, where the simple-bridge platform device is created by either the display controller driver side or platform firmware subsystem.

Could you give an example of a platform where you intend to use this ?

For example:

1) USB based display adapter, such as FL2000DX[1] which use the it66121 HDMI transmitter to convert the RGB888 to HDMI.

Quoted 7 lines

2) Simple 2D PCIe display controller, such as SM750(EMPV-1201) which using sii9022 HDMI transmitter to convert the RGB888 to HDMI.

3) Some FPGA PCIe Board (sil9136)

4) Be able to run unit test of drm bridges on X86.

Thank you, those are useful examples. It would be nice to capture at least some of them (first instance the first two) to the commit message.

Quoted 1 line

[1] https://github.com/FrescoLogic/FL2000

Signature · 3 lines
Regards,

Laurent Pinchart
#14 lore raw

Re: [PATCH 3/5] drm/bridge: simple-bridge: Allow acquiring the next bridge with fwnode API

In reply to Sui Jingfeng

Hello Sui,

Quoted 55 lines · Sui Jingfeng
Quoted 45 lines · Laurent Pinchart
Quoted 44 lines · Sui Jingfeng

Which make it possible to use this driver on non-DT based systems, meanwhile, made no functional changes for DT based systems.

---
  drivers/gpu/drm/bridge/simple-bridge.c | 51 ++++++++++++++++++++++----
  1 file changed, 44 insertions(+), 7 deletions(-)
drivers/gpu/drm/bridge/simple-bridge.c +28 -0
index 595f672745b9..cfea5a67cc5b 100644
@@ -184,6 +184,39 @@ static const void *simple_bridge_get_match_data(const struct device *dev)
  	return NULL;
  }
 
+static int simple_bridge_get_next_bridge_by_fwnode(struct device *dev,
+						   struct drm_bridge **next_bridge)
+{
+	struct drm_bridge *bridge;
+	struct fwnode_handle *ep;
+	struct fwnode_handle *remote;
+
+	ep = fwnode_graph_get_endpoint_by_id(dev->fwnode, 1, 0, 0);
+	if (!ep) {
+		dev_err(dev, "The endpoint is unconnected\n");
+		return -EINVAL;
+	}
+
+	remote = fwnode_graph_get_remote_port_parent(ep);
+	fwnode_handle_put(ep);
+	if (!remote) {
+		dev_err(dev, "No valid remote node\n");
+		return -ENODEV;
+	}
+
+	bridge = drm_bridge_find_by_fwnode(remote);
+	fwnode_handle_put(remote);
+
+	if (!bridge) {
+		dev_warn(dev, "Next bridge not found, deferring probe\n");
+		return -EPROBE_DEFER;
+	}
+
Quoted 8 lines

drivers/gpu/drm/bridge/simple-bridge.c static const void *simple_bridge_get_match_data(const struct device *dev) · line 219

Quoted 5 lines
drivers/gpu/drm/bridge/simple-bridge.c +5 -0
+	*next_bridge = bridge;
+
+	return 0;
+}
+

Hmmmm yes, this convinces me further that we should switch to fwnode, not implement fwnode and OF side-by-side.

Quoted 6 lines

OK, I'm agree with you.

But this means that I have to make the drm_bridge_find_by_fwnode() function works on both DT systems and non-DT systems. This is also means that we will no longer need to call of_drm_find_bridge() function anymore. This will eventually lead to completely remove of_drm_find_bridge()?

It would be replaced by fwnode_drm_find_bridge(). Although, if we need to rename the function, I think it would be best to make have a drm_ prefix, maybe drm_bridge_find-by_fwnode() or something similar.

Quoted 42 lines

As far as I can see, if I follow you suggestion, drm/bridge subsystem will encountering a *big* refactor. My 'side-by-side' approach allows co-exist. It is not really meant to purge OF. I feel it is a little bit of aggressive.

hello Maxime, are you watching this? what do you think?

Quoted 36 lines
Quoted 36 lines
drivers/gpu/drm/bridge/simple-bridge.c +11 -7
  static int simple_bridge_probe(struct platform_device *pdev)
  {
  	struct simple_bridge *sbridge;
@@ -199,14 +232,17 @@ static int simple_bridge_probe(struct platform_device *pdev)
  	else
  		sbridge->info = simple_bridge_get_match_data(&pdev->dev);
 
-	/* Get the next bridge in the pipeline. */
-	remote = of_graph_get_remote_node(pdev->dev.of_node, 1, -1);
-	if (!remote)
-		return -EINVAL;
-
-	sbridge->next_bridge = of_drm_find_bridge(remote);
-	of_node_put(remote);
+	if (pdev->dev.of_node) {
+		/* Get the next bridge in the pipeline. */
+		remote = of_graph_get_remote_node(pdev->dev.of_node, 1, -1);
+		if (!remote)
+			return -EINVAL;
 
+		sbridge->next_bridge = of_drm_find_bridge(remote);
+		of_node_put(remote);
+	} else {
+		simple_bridge_get_next_bridge_by_fwnode(&pdev->dev, &sbridge->next_bridge);
+	}
  	if (!sbridge->next_bridge) {
  		dev_dbg(&pdev->dev, "Next bridge not found, deferring probe\n");
  		return -EPROBE_DEFER;
@@ -231,6 +267,7 @@ static int simple_bridge_probe(struct platform_device *pdev)
  	/* Register the bridge. */
  	sbridge->bridge.funcs = &simple_bridge_bridge_funcs;
  	sbridge->bridge.of_node = pdev->dev.of_node;
+	sbridge->bridge.fwnode = pdev->dev.fwnode;
  	sbridge->bridge.timings = sbridge->info->timings;
 
  	drm_bridge_add(&sbridge->bridge);
Signature · 3 lines
Regards,

Laurent Pinchart
maintainer
#15 lore raw

Re: Re: [PATCH 3/5] drm/bridge: simple-bridge: Allow acquiring the next bridge with fwnode API

In reply to Sui Jingfeng
Quoted 66 lines · Sui Jingfeng

Hi,

Quoted 43 lines · Laurent Pinchart
Quoted 42 lines · Sui Jingfeng

Which make it possible to use this driver on non-DT based systems, meanwhile, made no functional changes for DT based systems.

---
  drivers/gpu/drm/bridge/simple-bridge.c | 51 ++++++++++++++++++++++----
  1 file changed, 44 insertions(+), 7 deletions(-)
drivers/gpu/drm/bridge/simple-bridge.c +27 -0
index 595f672745b9..cfea5a67cc5b 100644
@@ -184,6 +184,39 @@ static const void *simple_bridge_get_match_data(const struct device *dev)
  	return NULL;
  }
+static int simple_bridge_get_next_bridge_by_fwnode(struct device *dev,
+						   struct drm_bridge **next_bridge)
+{
+	struct drm_bridge *bridge;
+	struct fwnode_handle *ep;
+	struct fwnode_handle *remote;
+
+	ep = fwnode_graph_get_endpoint_by_id(dev->fwnode, 1, 0, 0);
+	if (!ep) {
+		dev_err(dev, "The endpoint is unconnected\n");
+		return -EINVAL;
+	}
+
+	remote = fwnode_graph_get_remote_port_parent(ep);
+	fwnode_handle_put(ep);
+	if (!remote) {
+		dev_err(dev, "No valid remote node\n");
+		return -ENODEV;
+	}
+
+	bridge = drm_bridge_find_by_fwnode(remote);
+	fwnode_handle_put(remote);
+
+	if (!bridge) {
+		dev_warn(dev, "Next bridge not found, deferring probe\n");
+		return -EPROBE_DEFER;
+	}
Quoted 9 lines

drivers/gpu/drm/bridge/simple-bridge.c static const void *simple_bridge_get_match_data(const struct device *dev) · line 219

Quoted 6 lines
drivers/gpu/drm/bridge/simple-bridge.c +6 -0
+
+	*next_bridge = bridge;
+
+	return 0;
+}
+

Hmmmm yes, this convinces me further that we should switch to fwnode, not implement fwnode and OF side-by-side.

OK, I'm agree with you.

But this means that I have to make the drm_bridge_find_by_fwnode() function works on both DT systems and non-DT systems. This is also means that we will no longer need to call of_drm_find_bridge() function anymore. This will eventually lead to completely remove of_drm_find_bridge()?

Quoted 5 lines

As far as I can see, if I follow you suggestion, drm/bridge subsystem will encountering a *big* refactor. My 'side-by-side' approach allows co-exist. It is not really meant to purge OF. I feel it is a little bit of aggressive.

hello Maxime, are you watching this? what do you think?

It's indeed going to be a pretty big refactoring, but I agree with Laurent that we don't want to maintain both side by side.

Maxime

#20 lore raw

Re: [PATCH 5/5] drm-bridge: display-connector: Switch to use fwnode API

In reply to Laurent Pinchart
Quoted 1 line · Laurent Pinchart

On Tue, Jan 23, 2024 at 12:32:20AM +0800, Sui Jingfeng wrote:

...

Quoted 5 lines

drivers/gpu/drm/bridge/display-connector.c static int display_connector_probe(struct platform_device *pdev) · line 384

Quoted 2 lines
drivers/gpu/drm/bridge/display-connector.c +1 -0
 	conn->bridge.of_node = pdev->dev.of_node;
+	conn->bridge.fwnode = pdev->dev.fwnode;

This goes in the right direction. Let's address the other drivers and drop the OF-based calls in the same series :-)

+1. BUT, please use device_set_node() instead of both lines.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#10 lore raw

Re: [PATCH 2/5] drm/bridge: simple-bridge: Extend match support for non-DT based systems

In reply to Sui Jingfeng
Quoted 6 lines · Sui Jingfeng

Which is intended to be used on non-DT environment, where the simple-bridge platform device is created by either the display controller driver side or platform firmware subsystem. To avoid duplication and to keep consistent, we choose to reuse the OF match tables. Because the potentional user may not has a of_node attached, nor a ACPI match id. If this is the case, a software node string property can be provide to fill the niche.

...

drivers/gpu/drm/bridge/simple-bridge.c static int simple_bridge_probe(struct platform_device *pdev) · line 200

Quoted 5 lines
drivers/gpu/drm/bridge/simple-bridge.c +4 -1
-	sbridge->info = of_device_get_match_data(&pdev->dev);
+	if (pdev->dev.of_node)
+		sbridge->info = of_device_get_match_data(&pdev->dev);
+	else
+		sbridge->info = simple_bridge_get_match_data(&pdev->dev);

This is wrong. Just use device_get_match_data() instead of of_ counter part. The rest, if required, has to be addressed elsewhere.

So, formal NAK for the changes like above.

Signature · 2 lines
With Best Regards,
Andy Shevchenko