Skip to contentSkip to conversation

drm/bridge: Implement generic USB Type-C DP HPD bridge

PATCH In review Chaoyi Chen 5 participants 17 messages May 21 – Jun 2

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover drm/bridge: Implement generic USB Type-C DP HPD bridge

From: Chaoyi Chen <[email protected]>

This series is split from the v15 "Add Type-C DP support for RK3399 EVB IND board" series [1]. It focuses on the DRM bridge and Rockchip platform CDN-DP controller changes.

[1] https://lore.kernel.org/all/[email protected]/

====
1. Generic Type-C DP HPD bridge

Currently, several USB-C controller drivers register their own DP HPD bridge via aux-hpd-bridge.c, each duplicating the same logic. For devicetree based platforms, the USB-C controller may vary across boards, and not every USB-C controller driver implements this feature. Patch 1 implements a generic DP HPD bridge that monitors Type-C bus events and automatically creates an HPD bridge when a Type-C port device with DP SVID is registered.

2. Multiple bridge model for CDN-DP

The RK3399 has two USB/DP combo PHY and one CDN-DP controller. Patch 5 introduces a multi-bridge model where each PHY port gets a separate encoder and bridge, allowing flexible selection of the output PHY port. This is based on the DRM AUX HPD bridge rather than extcon.

====
Patch 1 adds generic USB Type-C DP HPD bridge (Dmitry, Heikki). Patch 2 adds new API drm_aux_bridge_register_from_node() (Neil). Patch 3 adds DRM AUX bridge support for RK3399 USBDP PHY (Neil). Patch 4 drops CDN-DP's extcon dependency when Type-C is present (Dmitry). Patch 5 adds multiple bridges to support PHY port selection (Dmitry, Luca).

Chaoyi Chen (5):
drm/bridge: Implement generic USB Type-C DP HPD bridge drm/bridge: aux: Add drm_aux_bridge_register_from_node()
phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge drm/rockchip: cdn-dp: Support handle lane info without extcon drm/rockchip: cdn-dp: Add multiple bridges to support PHY port
selection

 drivers/gpu/drm/bridge/Kconfig                |  10 +
 drivers/gpu/drm/bridge/Makefile               |   1 +
 drivers/gpu/drm/bridge/aux-bridge.c           |  24 +-
 .../gpu/drm/bridge/aux-hpd-typec-dp-bridge.c  |  49 +++
 drivers/gpu/drm/rockchip/Kconfig              |   1 +
 drivers/gpu/drm/rockchip/cdn-dp-core.c        | 349 ++++++++++++++----
 drivers/gpu/drm/rockchip/cdn-dp-core.h        |  18 +-
 drivers/phy/rockchip/Kconfig                  |   2 +
 drivers/phy/rockchip/phy-rockchip-typec.c     |  13 +-
 include/drm/bridge/aux-bridge.h               |   6 +
 10 files changed, 404 insertions(+), 69 deletions(-)
 create mode 100644 drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/5 drm/bridge: Implement generic USB Type-C DP HPD bridge

From: Chaoyi Chen <[email protected]>

The HPD function of Type-C DP is implemented through drm_connector_oob_hotplug_event(). For embedded DP, it is required that the DRM connector fwnode corresponds to the Type-C port fwnode.

To describe the relationship between the DP controller and the Type-C port device, we usually using drm_bridge to build a bridge chain.

Now several USB-C controller drivers have already implemented the DP HPD bridge function provided by aux-hpd-bridge.c, it will build a DP HPD bridge on USB-C connector port device.

But this requires the USB-C controller driver to manually register the HPD bridge. If the driver does not implement this feature, the bridge will not be create.

So this patch implements a generic DP HPD bridge based on aux-hpd-bridge.c. It will monitor Type-C bus events, and when a Type-C port device containing the DP svid is registered, it will create an HPD bridge for it without the need for the USB-C controller driver to implement it.

---
 drivers/gpu/drm/bridge/Kconfig                | 10 ++++
 drivers/gpu/drm/bridge/Makefile               |  1 +
 .../gpu/drm/bridge/aux-hpd-typec-dp-bridge.c  | 49 +++++++++++++++++++
 3 files changed, 60 insertions(+)
 create mode 100644 drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c
drivers/gpu/drm/bridge/Kconfig +10 -0
index c3209b0f4678..d92e93875793 100644
@@ -30,6 +30,16 @@ config DRM_AUX_HPD_BRIDGE
 	  Simple bridge that terminates the bridge chain and provides HPD
 	  support.
 
+if DRM_AUX_HPD_BRIDGE
+config DRM_AUX_HPD_TYPEC_BRIDGE
+	tristate
+	depends on TYPEC || !TYPEC
+	default TYPEC
+	help
+	  Simple bridge that terminates the bridge chain and provides HPD
+	  support. It build bridge on each USB-C connector device node.
+endif
+
 menu "Display Interface Bridges"
 	depends on DRM && DRM_BRIDGE
 
drivers/gpu/drm/bridge/Makefile +1 -0
index beab5b695a6e..c4761526ba0a 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_DRM_AUX_BRIDGE) += aux-bridge.o
 obj-$(CONFIG_DRM_AUX_HPD_BRIDGE) += aux-hpd-bridge.o
+obj-$(CONFIG_DRM_AUX_HPD_TYPEC_BRIDGE) += aux-hpd-typec-dp-bridge.o
 obj-$(CONFIG_DRM_CHIPONE_ICN6211) += chipone-icn6211.o
 obj-$(CONFIG_DRM_CHRONTEL_CH7033) += chrontel-ch7033.o
 obj-$(CONFIG_DRM_CROS_EC_ANX7688) += cros-ec-anx7688.o
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
2.53.0
#5 lore raw

PATCH 2/5 drm/bridge: aux: Add drm_aux_bridge_register_from_node()

In reply to Chaoyi Chen

From: Chaoyi Chen <[email protected]>

The drm_aux_bridge_register() uses the device->of_node as the bridge->of_node.

This patch adds drm_aux_bridge_register_from_node() to allow specifying the of_node corresponding to the bridge.

---
 drivers/gpu/drm/bridge/aux-bridge.c | 24 ++++++++++++++++++++++--
 include/drm/bridge/aux-bridge.h     |  6 ++++++
 2 files changed, 28 insertions(+), 2 deletions(-)
drivers/gpu/drm/bridge/aux-bridge.c +22 -2
index 1ed21a8713bf..f50283abed5f 100644
@@ -35,6 +35,7 @@ static void drm_aux_bridge_unregister_adev(void *_adev)
 /**
  * drm_aux_bridge_register - Create a simple bridge device to link the chain
  * @parent: device instance providing this bridge
+ * @np: device node pointer corresponding to this bridge instance
  *
  * Creates a simple DRM bridge that doesn't implement any drm_bridge
  * operations. Such bridges merely fill a place in the bridge chain linking
@@ -42,7 +43,7 @@ static void drm_aux_bridge_unregister_adev(void *_adev)
  *
  * Return: zero on success, negative error code on failure
  */
-int drm_aux_bridge_register(struct device *parent)
+int drm_aux_bridge_register_from_node(struct device *parent, struct device_node *np)
 {
 	struct auxiliary_device *adev;
 	int ret;
@@ -62,7 +63,10 @@ int drm_aux_bridge_register(struct device *parent)
 	adev->dev.parent = parent;
 	adev->dev.release = drm_aux_bridge_release;
 
-	device_set_of_node_from_dev(&adev->dev, parent);
+	if (np)
+		device_set_node(&adev->dev, of_fwnode_handle(np));
+	else
+		device_set_of_node_from_dev(&adev->dev, parent);
 
 	ret = auxiliary_device_init(adev);
 	if (ret) {
@@ -80,6 +84,22 @@ int drm_aux_bridge_register(struct device *parent)
 
 	return devm_add_action_or_reset(parent, drm_aux_bridge_unregister_adev, adev);
 }
+EXPORT_SYMBOL_GPL(drm_aux_bridge_register_from_node);
+
+/**
+ * drm_aux_bridge_register - Create a simple bridge device to link the chain
+ * @parent: device instance providing this bridge
+ *
+ * Creates a simple DRM bridge that doesn't implement any drm_bridge
+ * operations. Such bridges merely fill a place in the bridge chain linking
+ * surrounding DRM bridges.
+ *
+ * Return: zero on success, negative error code on failure
+ */
+int drm_aux_bridge_register(struct device *parent)
+{
+	return drm_aux_bridge_register_from_node(parent, NULL);
+}
 EXPORT_SYMBOL_GPL(drm_aux_bridge_register);
 
 struct drm_aux_bridge_data {
include/drm/bridge/aux-bridge.h +6 -0
index c2f5a855512f..7dd1f17a1354 100644
@@ -13,11 +13,17 @@ struct auxiliary_device;
 
 #if IS_ENABLED(CONFIG_DRM_AUX_BRIDGE)
 int drm_aux_bridge_register(struct device *parent);
+int drm_aux_bridge_register_from_node(struct device *parent, struct device_node *np);
 #else
 static inline int drm_aux_bridge_register(struct device *parent)
 {
 	return 0;
 }
+
+static inline int drm_aux_bridge_register_from_node(struct device *parent, struct device_node *np)
+{
+	return 0;
+}
 #endif
 
 #if IS_ENABLED(CONFIG_DRM_AUX_HPD_BRIDGE)
Signature · 1 line
2.53.0
#8 lore raw

PATCH 3/5 phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge

In reply to Chaoyi Chen

From: Chaoyi Chen <[email protected]>

Using the DRM_AUX_BRIDGE helper to create the transparent DRM bridge device.

---
 drivers/phy/rockchip/Kconfig              |  2 ++
 drivers/phy/rockchip/phy-rockchip-typec.c | 13 +++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/phy/rockchip/Kconfig +2 -0
index 14698571b607..9173d3b4fef4 100644
@@ -119,6 +119,8 @@ config PHY_ROCKCHIP_SNPS_PCIE3
 config PHY_ROCKCHIP_TYPEC
 	tristate "Rockchip TYPEC PHY Driver"
 	depends on OF && (ARCH_ROCKCHIP || COMPILE_TEST)
+	depends on DRM || DRM=n
+	select DRM_AUX_BRIDGE if DRM_BRIDGE
 	select EXTCON
 	select GENERIC_PHY
 	select RESET_CONTROLLER
drivers/phy/rockchip/phy-rockchip-typec.c +11 -2
index d9701b6106d5..48070b50416e 100644
@@ -54,6 +54,7 @@
 
 #include <linux/mfd/syscon.h>
 #include <linux/phy/phy.h>
+#include <drm/bridge/aux-bridge.h>
 
 #define CMN_SSM_BANDGAP			(0x21 << 2)
 #define CMN_SSM_BIAS			(0x22 << 2)
@@ -1162,16 +1163,24 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev)
 
 	for_each_available_child_of_node(np, child_np) {
 		struct phy *phy;
+		ret = 0;
 
-		if (of_node_name_eq(child_np, "dp-port"))
+		if (of_node_name_eq(child_np, "dp-port")) {
 			phy = devm_phy_create(dev, child_np,
 					      &rockchip_dp_phy_ops);
-		else if (of_node_name_eq(child_np, "usb3-port"))
+			ret = drm_aux_bridge_register_from_node(dev, child_np);
+		} else if (of_node_name_eq(child_np, "usb3-port"))
 			phy = devm_phy_create(dev, child_np,
 					      &rockchip_usb3_phy_ops);
 		else
 			continue;
 
+		if (ret) {
+			pm_runtime_disable(dev);
+			of_node_put(child_np);
+			return ret;
+		}
+
 		if (IS_ERR(phy)) {
 			dev_err(dev, "failed to create phy: %pOFn\n",
 				child_np);
Signature · 1 line
2.53.0
#12 lore raw

PATCH 4/5 drm/rockchip: cdn-dp: Support handle lane info without extcon

In reply to Chaoyi Chen

From: Chaoyi Chen <[email protected]>

This patch add support for get PHY lane info without help of extcon.

There is no extcon needed if the Type-C controller is present. In this case, the lane info can be get from PHY instead of extcon.

The extcon device should still be supported if Type-C controller is not present.

---
 drivers/gpu/drm/rockchip/cdn-dp-core.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/gpu/drm/rockchip/cdn-dp-core.c +17 -8
index 177e30445ee8..9068118859e2 100644
@@ -157,6 +157,9 @@ static int cdn_dp_get_port_lanes(struct cdn_dp_port *port)
 	int dptx;
 	u8 lanes;
 
+	if (!edev)
+		return phy_get_bus_width(port->phy);
+
 	dptx = extcon_get_state(edev, EXTCON_DISP_DP);
 	if (dptx > 0) {
 		extcon_get_property(edev, EXTCON_DISP_DP,
@@ -220,7 +223,7 @@ static bool cdn_dp_check_sink_connection(struct cdn_dp_device *dp)
 	 * some docks need more time to power up.
 	 */
 	while (time_before(jiffies, timeout)) {
-		if (!extcon_get_state(port->extcon, EXTCON_DISP_DP))
+		if (port->extcon && !extcon_get_state(port->extcon, EXTCON_DISP_DP))
 			return false;
 
 		if (!cdn_dp_get_sink_count(dp, &sink_count))
@@ -386,11 +389,14 @@ static int cdn_dp_enable_phy(struct cdn_dp_device *dp, struct cdn_dp_port *port)
 		goto err_power_on;
 	}
 
-	ret = extcon_get_property(port->extcon, EXTCON_DISP_DP,
-				  EXTCON_PROP_USB_TYPEC_POLARITY, &property);
-	if (ret) {
-		DRM_DEV_ERROR(dp->dev, "get property failed\n");
-		goto err_power_on;
+	property.intval = 0;
+	if (port->extcon) {
+		ret = extcon_get_property(port->extcon, EXTCON_DISP_DP,
+					  EXTCON_PROP_USB_TYPEC_POLARITY, &property);
+		if (ret) {
+			DRM_DEV_ERROR(dp->dev, "get property failed\n");
+			goto err_power_on;
+		}
 	}
 
 	port->lanes = cdn_dp_get_port_lanes(port);
@@ -1029,6 +1035,9 @@ static int cdn_dp_bind(struct device *dev, struct device *master, void *data)
 	for (i = 0; i < dp->ports; i++) {
 		port = dp->port[i];
 
+		if (!port->extcon)
+			continue;
+
 		port->event_nb.notifier_call = cdn_dp_pd_event;
 		ret = devm_extcon_register_notifier(dp->dev, port->extcon,
 						    EXTCON_DISP_DP,
@@ -1121,14 +1130,14 @@ static int cdn_dp_probe(struct platform_device *pdev)
 		    PTR_ERR(phy) == -EPROBE_DEFER)
 			return -EPROBE_DEFER;
 
-		if (IS_ERR(extcon) || IS_ERR(phy))
+		if (IS_ERR(phy) || PTR_ERR(extcon) != -ENODEV)
 			continue;
 
 		port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
 		if (!port)
 			return -ENOMEM;
 
-		port->extcon = extcon;
+		port->extcon = IS_ERR(extcon) ? NULL : extcon;
 		port->phy = phy;
 		port->dp = dp;
 		port->id = i;
Signature · 1 line
2.53.0
#14 lore raw

PATCH 5/5 drm/rockchip: cdn-dp: Add multiple bridges to support PHY port selection

In reply to Chaoyi Chen

From: Chaoyi Chen <[email protected]>

The RK3399 has two USB/DP combo PHY and one CDN-DP controller. And the CDN-DP can be switched to output to one of the PHYs. If both ports are plugged into DP, DP will select the first port for output.

This patch adds support for multiple bridges, enabling users to flexibly select the output port. For each PHY port, a separate encoder and bridge are registered.

The change is based on the DRM AUX HPD bridge, rather than the extcon approach. This requires the DT to correctly describe the connections between the first bridge in bridge chain and DP controller. For example, the bridge chain may be like this:

PHY aux birdge -> fsa4480 analog audio switch bridge -> onnn,nb7vpq904m USB reminder bridge -> USB-C controller AUX HPD bridge

In this case, the connection relationships among the PHY aux bridge and the DP contorller need to be described in DT.

In addition, the cdn_dp_parse_next_bridge_dt() will parses it and determines whether to register one or two bridges.

Since there is only one DP controller, only one of the PHY ports can output at a time. The key is how to switch between different PHYs, which is handled by cdn_dp_switch_port() and cdn_dp_enable().

There are two cases:

1. Neither bridge is enabled. In this case, both bridges can independently read the EDID, and the PHY port may switch before reading the EDID.

2. One bridge is already enabled. In this case, other bridges are not allowed to read the EDID. So we will try to return the cached EDID.

Since the scenario of two ports plug in at the same time is rare, I don't have a board which support two TypeC connector to test this. Therefore, I tested forced switching on a single PHY port, as well as output using a fake PHY port alongside a real PHY port.

---
 drivers/gpu/drm/rockchip/Kconfig       |   1 +
 drivers/gpu/drm/rockchip/cdn-dp-core.c | 324 ++++++++++++++++++++-----
 drivers/gpu/drm/rockchip/cdn-dp-core.h |  18 +-
 3 files changed, 286 insertions(+), 57 deletions(-)
drivers/gpu/drm/rockchip/Kconfig +1 -0
index 1479b8c4ed40..cb97690c5a5d 100644
@@ -59,6 +59,7 @@ config ROCKCHIP_CDN_DP
 	select DRM_DISPLAY_HELPER
 	select DRM_BRIDGE_CONNECTOR
 	select DRM_DISPLAY_DP_HELPER
+	select DRM_AUX_HPD_BRIDGE
 	help
 	  This selects support for Rockchip SoC specific extensions
 	  for the cdn DP driver. If you want to enable Dp on
drivers/gpu/drm/rockchip/cdn-dp-core.c +269 -55

473 lines not on this page · raw message

drivers/gpu/drm/rockchip/cdn-dp-core.h +16 -2
index e9c30b9fd543..c10e423bbf06 100644
@@ -38,6 +38,8 @@ enum vic_pxl_encoding_format {
 	Y_ONLY = 0x10,
 };
 
+struct cdn_dp_device;
+
 struct video_info {
 	bool h_sync_polarity;
 	bool v_sync_polarity;
@@ -63,16 +65,28 @@ struct cdn_dp_port {
 	u8 id;
 };
 
+struct cdn_dp_bridge {
+	struct cdn_dp_device *parent;
+	struct drm_bridge bridge;
+	struct rockchip_encoder encoder;
+	bool connected;
+	bool enabled;
+	int id;
+};
+
 struct cdn_dp_device {
 	struct device *dev;
 	struct drm_device *drm_dev;
-	struct drm_bridge bridge;
-	struct rockchip_encoder encoder;
+	int bridge_count;
+	struct cdn_dp_bridge *bridge_list[MAX_PHY];
+	struct drm_bridge *next_bridge_list[MAX_PHY];
+	const struct drm_edid *edid_cache[MAX_PHY];
 	struct drm_display_mode mode;
 	struct platform_device *audio_pdev;
 	struct work_struct event_work;
 
 	struct mutex lock;
+	bool next_bridge_valid;
 	bool connected;
 	bool active;
 	bool suspended;
Signature · 1 line
2.53.0
#2 lore raw
In reply to Chaoyi Chen
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [High] Module initialization misses Type-C ports that are already registered. - [High] Missing…

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] Module initialization misses Type-C ports that are already registered.
- [High] Missing BUS_NOTIFY_DEL_DEVICE handling and incorrect devm usage leads to memory leaks and use-after-free on module unload.
- [High] Generic notifier blindly creates duplicate bridges for controllers that already register them natively.
- [High] Blind use of alt->dev.parent->parent causes NULL pointer dereference in devm_ functions if the port lacks a parent.
- [Medium] Kconfig entry lacks a prompt string and has an incorrect dependency structure.
--

commit 6278338190ad225c12a2042f8bb6669eb188e362
Author: Chaoyi Chen <[email protected]>

drm/bridge: Implement generic USB Type-C DP HPD bridge

This patch implements a generic DP HPD bridge based on aux-hpd-bridge.c. It monitors Type-C bus events, and when a Type-C port device containing the DP svid is registered, it automatically creates an HPD bridge.

drivers/gpu/drm/bridge/Kconfig config DRM_AUX_HPD_BRIDGE · line 36

Quoted 12 lines
drivers/gpu/drm/bridge/Kconfig +4 -0
index c3209b0f46786..d92e938757931 100644
@@ -30,6 +30,16 @@ config DRM_AUX_HPD_BRIDGE
 	  Simple bridge that terminates the bridge chain and provides HPD
 	  support.
 
+if DRM_AUX_HPD_BRIDGE
+config DRM_AUX_HPD_TYPEC_BRIDGE
+	tristate
+	depends on TYPEC || !TYPEC

[Severity: Medium]
Is there a missing prompt string for this tristate? Without it, the option is invisible in menuconfig.

Also, since this module directly uses symbols like typec_bus, won't depends on TYPEC || !TYPEC cause a build failure when CONFIG_TYPEC=n since the dependency evaluates to true?

Quoted 5 lines
drivers/gpu/drm/bridge/Kconfig +5 -0
+	default TYPEC
+	help
+	  Simple bridge that terminates the bridge chain and provides HPD
+	  support. It build bridge on each USB-C connector device node.
+endif

[ ... ]

Quoted 11 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +5 -0
new file mode 100644
index 0000000000000..d915e0fb0668c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0+
+#include <linux/of.h>
+#include <linux/usb/typec_altmode.h>
+#include <linux/usb/typec_dp.h>
+

drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c line 15

Quoted 10 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +10 -0
+#include <drm/bridge/aux-bridge.h>
+
+static int drm_typec_bus_event(struct notifier_block *nb,
+			       unsigned long action, void *data)
+{
+	struct device *dev = (struct device *)data;
+	struct typec_altmode *alt = to_typec_altmode(dev);
+
+	if (action != BUS_NOTIFY_ADD_DEVICE)
+		goto done;

[Severity: High]
What happens when a port is unregistered? Since drm_dp_hpd_bridge_register() allocates resources using devm tied to the controller device, ignoring BUS_NOTIFY_DEL_DEVICE means the bridge won't be freed if the port altmode is dynamically unregistered, leading to duplicate bridges and memory leaks on re-registration.

If this module is unloaded, the devres callbacks remain attached to the controller. Will that cause a use-after-free kernel panic when the controller is unbound later?

drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c line 23

Quoted 8 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +8 -0
+
+	/*
+	 * alt->dev.parent->parent : USB-C controller device
+	 * alt->dev.parent         : USB-C connector device
+	 */
+	if (is_typec_port_altmode(&alt->dev) && alt->svid == USB_TYPEC_DP_SID)
+		drm_dp_hpd_bridge_register(alt->dev.parent->parent,
+					   to_of_node(alt->dev.parent->fwnode));

[Severity: High]
Can alt->dev.parent be NULL here? The Type-C subsystem allows ports to be registered without a parent. If so, dereferencing alt->dev.parent->parent will cause a NULL pointer dereference.

[Severity: High]
Several Type-C controller drivers already register their own DP HPD bridges. Does this unconditionally create a second bridge for those ports?

If two bridges are registered for the same device node, the controller driver will route HPD events to its native bridge, while the DRM driver might bind to this generic one, breaking hotplug detection.

Quoted 10 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +10 -0
+
+done:
+	return NOTIFY_OK;
+}
+
+static struct notifier_block drm_typec_event_nb = {
+	.notifier_call = drm_typec_bus_event,
+};
+
+static void drm_aux_hpd_typec_dp_bridge_module_exit(void)

drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c line 43

Quoted 10 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +10 -0
+{
+	bus_unregister_notifier(&typec_bus, &drm_typec_event_nb);
+}
+
+static int __init drm_aux_hpd_typec_dp_bridge_module_init(void)
+{
+	bus_register_notifier(&typec_bus, &drm_typec_event_nb);
+
+	return 0;
+}

[Severity: High]
If this module is loaded after Type-C port controllers have already probed, will it miss the existing ports?

Calling bus_register_notifier() only catches new BUS_NOTIFY_ADD_DEVICE events, so bridges wouldn't be created for devices already on the bus.

Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#6 lore raw

Re: [PATCH 2/5] drm/bridge: aux: Add drm_aux_bridge_register_from_node()

In reply to Chaoyi Chen
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Critical] The `drm_aux_bridge_register_from_node()` function fails to acquire a reference to the…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] The drm_aux_bridge_register_from_node() function fails to acquire a reference to the provided device_node (np), leading to a reference count underflow and potential use-after-free during cleanup.
- [Low] The kernel-doc comment for drm_aux_bridge_register_from_node() retains the old function name, causing a documentation build warning.
--

commit a4484cec194d2731c92e629a32b7e17a725601d7
Author: Chaoyi Chen <[email protected]>

drm/bridge: aux: Add drm_aux_bridge_register_from_node()

This patch adds drm_aux_bridge_register_from_node() to allow specifying the of_node corresponding to the bridge.

drivers/gpu/drm/bridge/aux-bridge.c static void drm_aux_bridge_unregister_adev(void *_adev) · line 36

Quoted 7 lines
drivers/gpu/drm/bridge/aux-bridge.c +0 -0
index 1ed21a8713bfd..f50283abed5f6 100644
@@ -35,6 +35,7 @@ static void drm_aux_bridge_unregister_adev(void *_adev)
 /**
  * drm_aux_bridge_register - Create a simple bridge device to link the chain

[Severity: Low]
This isn't a bug, but there's a mismatch between the kernel-doc identifier and the new function name. Should this be updated to drm_aux_bridge_register_from_node?

Quoted 2 lines
drivers/gpu/drm/bridge/aux-bridge.c +1 -0
  * @parent: device instance providing this bridge
+ * @np: device node pointer corresponding to this bridge instance

[ ... ]

drivers/gpu/drm/bridge/aux-bridge.c int drm_aux_bridge_register(struct device *parent) · line 67

Quoted 7 lines
drivers/gpu/drm/bridge/aux-bridge.c +2 -1
@@ -62,7 +63,10 @@ int drm_aux_bridge_register(struct device *parent)
 	adev->dev.parent = parent;
 	adev->dev.release = drm_aux_bridge_release;
 
-	device_set_of_node_from_dev(&adev->dev, parent);
+	if (np)
+		device_set_node(&adev->dev, of_fwnode_handle(np));

[Severity: Critical]
Will this cause a reference count underflow on the device node?

If np is provided, device_set_node() assigns the fwnode without incrementing the device node's reference count.

However, both the auxiliary_device_init() error path (shown below) and the device's release callback drm_aux_bridge_release() unconditionally call of_node_put(adev->dev.of_node).

Since there is no matching of_node_get(), this could corrupt the reference count and lead to a use-after-free. Should we call of_node_get(np) here?

Quoted 6 lines
drivers/gpu/drm/bridge/aux-bridge.c +2 -0
+	else
+		device_set_of_node_from_dev(&adev->dev, parent);
 
 	ret = auxiliary_device_init(adev);
 	if (ret) {

of_node_put(adev->dev.of_node);

Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#9 lore raw

Re: [PATCH 3/5] phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge

In reply to Chaoyi Chen
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Double-free of the `child_np` device node reference leading to a Use-After-Free. - [Medium]…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Double-free of the child_np device node reference leading to a Use-After-Free.
- [Medium] Incorrect error check ordering masks devm_phy_create failures and attempts bridge registration on invalid PHY pointers. --

commit 83430d0b883e6ab3238d19fd9d398fef26aa6ab7
Author: Chaoyi Chen <[email protected]>

phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge

Using the DRM_AUX_BRIDGE helper to create the transparent DRM bridge device.

Quoted 4 lines
drivers/phy/rockchip/phy-rockchip-typec.c +0 -0
index d9701b6106d55..48070b50416e5 100644

[ ... ]

drivers/phy/rockchip/phy-rockchip-typec.c static int rockchip_typec_phy_probe(struct platform_device *pdev) · line 1171

Quoted 12 lines
drivers/phy/rockchip/phy-rockchip-typec.c +3 -2
@@ -1162,16 +1163,24 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev)
 
 	for_each_available_child_of_node(np, child_np) {
 		struct phy *phy;
+		ret = 0;
 
-		if (of_node_name_eq(child_np, "dp-port"))
+		if (of_node_name_eq(child_np, "dp-port")) {
 			phy = devm_phy_create(dev, child_np,
 					      &rockchip_dp_phy_ops);
-		else if (of_node_name_eq(child_np, "usb3-port"))
+			ret = drm_aux_bridge_register_from_node(dev, child_np);

[Severity: High]
Does this code result in a double-free of the child_np device node reference?

The macro for_each_available_child_of_node() automatically manages the reference count for child_np, acquiring it for the current iteration and dropping it when advancing.

drm_aux_bridge_register_from_node() assigns the node to the auxiliary bridge device, and the auxiliary bridge assumes ownership of a reference (calling of_node_put() in its error paths and release callback).

Because an additional reference is not acquired via of_node_get() before passing it, the reference is decremented twice, which can lead to a use-after-free.

drivers/phy/rockchip/phy-rockchip-typec.c static int rockchip_typec_phy_probe(struct platform_device *pdev) · line 1184

Quoted 13 lines
drivers/phy/rockchip/phy-rockchip-typec.c +7 -0
+		} else if (of_node_name_eq(child_np, "usb3-port"))
 			phy = devm_phy_create(dev, child_np,
 					      &rockchip_usb3_phy_ops);
 		else
 			continue;
 
+		if (ret) {
+			pm_runtime_disable(dev);
+			of_node_put(child_np);
+			return ret;
+		}
+
 		if (IS_ERR(phy)) {

[Severity: Medium]
Will this error check ordering mask devm_phy_create() failures?

The check for bridge registration failure (if (ret)) happens before the check for PHY creation failure (if (IS_ERR(phy))). If devm_phy_create() fails (e.g., returning -EPROBE_DEFER) and the subsequent bridge registration also fails, the function will return the bridge error and mask the PHY error.

Additionally, this attempts to register the auxiliary bridge even after the underlying PHY creation has already failed. Should IS_ERR(phy) be checked before calling drm_aux_bridge_register_from_node(), or at least before checking ret?

Quoted 2 lines
drivers/phy/rockchip/phy-rockchip-typec.c +0 -0
 			dev_err(dev, "failed to create phy: %pOFn\n",
 				child_np);
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#13 lore raw

Re: [PATCH 4/5] drm/rockchip: cdn-dp: Support handle lane info without extcon

In reply to Chaoyi Chen
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The condition `PTR_ERR(extcon) != -ENODEV` in `cdn_dp_probe()` evaluates to true for valid…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The condition PTR_ERR(extcon) != -ENODEV in cdn_dp_probe() evaluates to true for valid extcon pointers, breaking initialization for devices with extcon. --

commit 1c12cc989734f906a15b7d45d90d57d21f55c2d3
Author: Chaoyi Chen <[email protected]>

drm/rockchip: cdn-dp: Support handle lane info without extcon

This commit adds support for getting PHY lane information directly from the PHY instead of relying on extcon when a Type-C controller is present. It updates the probe, bind, and phy enable paths to allow operation without an extcon device, while intending to keep extcon supported for older setups.

Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0 -0
index 177e30445ee83..9068118859e21 100644

[ ... ]

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_probe(struct platform_device *pdev) · line 1133

Quoted 6 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +1 -1
@@ -1121,14 +1130,14 @@ static int cdn_dp_probe(struct platform_device *pdev)
 		    PTR_ERR(phy) == -EPROBE_DEFER)
 			return -EPROBE_DEFER;
 
-		if (IS_ERR(extcon) || IS_ERR(phy))
+		if (IS_ERR(phy) || PTR_ERR(extcon) != -ENODEV)

[Severity: High]
Does this condition inadvertently skip port initialization for valid extcon devices?

When extcon_get_edev_by_phandle() successfully returns a valid pointer, PTR_ERR(extcon) evaluates to the pointer's memory address. Since a valid pointer address is not equal to -ENODEV, this condition will evaluate to true and trigger the continue statement.

This appears to break enumeration for all existing devices that use an extcon by unconditionally skipping their setup.

Would it be better to ensure we only check the error code when the pointer is actually an error?

		if (IS_ERR(phy) || (IS_ERR(extcon) && PTR_ERR(extcon) != -ENODEV))
Quoted 11 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +1 -1
 			continue;
 
 		port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
 		if (!port)
 			return -ENOMEM;
 
-		port->extcon = extcon;
+		port->extcon = IS_ERR(extcon) ? NULL : extcon;
 		port->phy = phy;
 		port->dp = dp;
 		port->id = i;
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#15 lore raw

Re: [PATCH 5/5] drm/rockchip: cdn-dp: Add multiple bridges to support PHY port selection

In reply to Chaoyi Chen
Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider: - [High] Prematurely dropping the reference count of the last bridge in `cdn_bridge_add()` will cause a…

Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider:
- [High] Prematurely dropping the reference count of the last bridge in cdn_bridge_add() will cause a use-after-free.
- [High] The prev_port pointer is used uninitialized in cdn_dp_bridge_edid_read(), leading to a kernel crash.
- [High] cdn_dp_connected_port() ignores connection status for extcon configurations, breaking hotplug detection.
- [High] Missing bounds check in cdn_dp_parse_next_bridge_dt() allows an out-of-bounds write to the next_bridge_list array.
- [High] The lanes stack array is read out-of-bounds or uninitialized in cdn_dp_connected_port().
- [High] DRM bridge references are leaked on error paths during DT parsing and driver binding.
- [High] If link training fails in cdn_dp_switch_port(), it returns an error but leaves the DP controller erroneously marked as active.
- [High] cdn_dp_switch_port() incorrectly aborts hardware switching when the DP controller is active, causing EDID reads from the wrong port.
- [High] Disabling an inactive bridge erroneously disables the active DP controller for another bridge.
- [Medium] Overwriting connector->fwnode in cdn_bridge_add() causes a memory leak.
- [Medium] Incorrect check for the active port treats valid index 0 as invalid.
--

Hi,

I have reviewed the patch and found some potential issues to share.

commit 082c705aa7547b521ad9df20ac76e0592b41864f
Author: Chaoyi Chen <[email protected]>

drm/rockchip: cdn-dp: Add multiple bridges to support PHY port selection

This commit adds support for multiple bridges to the Rockchip cdn-dp driver to allow switching between two USB/DP combo PHYs. It changes the driver to use the DRM AUX HPD bridge and adds DT parsing logic to register multiple bridges.

Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0 -0
@@ -192,14 +193,27 @@ static int cdn_dp_get_sink_count(struct cdn_dp_device *dp, u8 *sink_count)
 static struct cdn_dp_port *cdn_dp_connected_port(struct cdn_dp_device *dp)
 {
 	struct cdn_dp_port *port;

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_get_sink_count(struct cdn_dp_device *dp, u8 *sink_count) · line 202

Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +3 -3
-	int i, lanes;
+	int i, lanes[MAX_PHY];
 
 	for (i = 0; i < dp->ports; i++) {
 		port = dp->port[i];
-		lanes = cdn_dp_get_port_lanes(port);
-		if (lanes)
+		lanes[i] = cdn_dp_get_port_lanes(port);
+		if (!dp->next_bridge_valid)
 			return port;

[Severity: High]
Does this unconditionally return the first port without checking if it is actually connected? If dp->next_bridge_valid is false (which is the case for extcon setups), it appears to return port on the first iteration regardless of lanes[i], completely breaking hotplug detection.

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_get_sink_count(struct cdn_dp_device *dp, u8 *sink_count) · line 207

Quoted 5 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +4 -0
 	}
+
+	if (dp->next_bridge_valid) {
+		/* If more than one port is available, pick the last active port */
+		if (dp->active_port > 0 && lanes[dp->active_port])

[Severity: Medium]
Since dp->active_port is initialized to -1, valid port indices are 0 and 1. Does the check dp->active_port > 0 incorrectly evaluate to false when the active port is 0, skipping the active port?

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_get_sink_count(struct cdn_dp_device *dp, u8 *sink_count) · line 212

Quoted 5 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +5 -0
+			return dp->port[dp->active_port];
+
+		/* If the last active port is not available, pick an available port in order */
+		for (i = 0; i < dp->bridge_count; i++) {
+			if (lanes[i])

[Severity: High]
Can this read uninitialized stack memory? The lanes stack array is populated in a loop bounded by dp->ports, but accessed here in a loop bounded by dp->bridge_count.

If dp->bridge_count > dp->ports, this will read uninitialized values. Furthermore, since lanes is sized to MAX_PHY, if dp->bridge_count > MAX_PHY, it will perform an out-of-bounds stack read.

Quoted 6 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +4 -0
+				return dp->port[i];
+		}
+	}
+
 	return NULL;
 }

[ ... ]

Quoted 16 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +8 -1
@@ -254,12 +268,45 @@ static const struct drm_edid *
 cdn_dp_bridge_edid_read(struct drm_bridge *bridge, struct drm_connector *connector)
 {
 	struct cdn_dp_device *dp = bridge_to_dp(bridge);
-	const struct drm_edid *drm_edid;
+	struct cdn_dp_bridge *dp_bridge = bridge_to_dp_bridge(bridge);
+	struct cdn_dp_port *port = dp->port[dp_bridge->id];
+	struct cdn_dp_port *prev_port;
+	const struct drm_edid *drm_edid = NULL;
 	int i, ret;
 
 	mutex_lock(&dp->lock);
+
+	/* More than one port is available */
+	if (dp->bridge_count > 1 && !port->phy_enabled) {
+		for (i = 0; i < dp->bridge_count; i++) {

drivers/gpu/drm/rockchip/cdn-dp-core.c static const struct drm_edid * · line 291

Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +10 -0
+			/* Another port already enable */
+			if (dp->bridge_list[i] != dp_bridge && dp->bridge_list[i]->enabled)
+				goto get_cache;
+			/* Find already enabled port */
+			if (dp->port[i]->phy_enabled)
+				prev_port = dp->port[i];
+		}
+
+		/* Switch to current port */
+		if (prev_port) {

[Severity: High]
Can this lead to a kernel crash by dereferencing an uninitialized pointer? The prev_port variable is not initialized. If no ports are currently enabled (which is common at boot), the for loop will complete without assigning anything to prev_port.

Then if (prev_port) evaluates garbage memory, and calling cdn_dp_switch_port with it will cause a kernel panic.

Quoted 5 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +5 -0
+			ret = cdn_dp_switch_port(dp, prev_port, port);
+			if (ret)
+				goto get_cache;
+		}
+	}

[ ... ]

drivers/gpu/drm/rockchip/cdn-dp-core.c static bool cdn_dp_check_link_status(struct cdn_dp_device *dp) · line 608

Quoted 11 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +7 -0
@@ -551,6 +599,54 @@ static bool cdn_dp_check_link_status(struct cdn_dp_device *dp)
 	return drm_dp_channel_eq_ok(link_status, min(port->lanes, sink_lanes));
 }
 
+static int cdn_dp_switch_port(struct cdn_dp_device *dp, struct cdn_dp_port *prev_port,
+			      struct cdn_dp_port *port)
+{
+	int ret;
+
+	if (dp->active)
+		return 0;

[Severity: High]
Does this incorrectly abort hardware switching? If the DP controller is already active but currently on a different port, returning 0 skips the actual port switch. The caller cdn_dp_bridge_edid_read() will proceed with reading EDID from the wrong (already-active) port and caching it for the new port.

Quoted 14 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +14 -0
+
+	ret = cdn_dp_disable_phy(dp, prev_port);
+	if (ret)
+		goto out;
+	ret = cdn_dp_enable_phy(dp, port);
+	if (ret)
+		goto out;
+
+	ret = cdn_dp_get_sink_capability(dp);
+	if (ret) {
+		cdn_dp_disable_phy(dp, port);
+		goto out;
+	}
+

drivers/gpu/drm/rockchip/cdn-dp-core.c static bool cdn_dp_check_link_status(struct cdn_dp_device *dp) · line 632

Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +10 -0
+	dp->active = true;
+	dp->lanes = port->lanes;
+
+	if (!cdn_dp_check_link_status(dp)) {
+		dev_info(dp->dev, "Connected with sink; re-train link\n");
+
+		ret = cdn_dp_train_link(dp);
+		if (ret) {
+			dev_err(dp->dev, "Training link failed: %d\n", ret);
+			goto out;

[Severity: High]
If link training fails, this jumps to out and returns the error code, but leaves dp->active = true. Does this trap the port in a permanently broken, untrained state since subsequent calls to cdn_dp_switch_port() will immediately return 0?

Quoted 1 line
(quoted diff) +1 -0
+		}

[ ... ]

drivers/gpu/drm/rockchip/cdn-dp-core.c static void cdn_dp_bridge_atomic_enable(struct drm_bridge *bridge, struct drm_at · line 750

Quoted 12 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +2 -0
@@ -639,9 +740,11 @@ static void cdn_dp_bridge_atomic_enable(struct drm_bridge *bridge, struct drm_at
 static void cdn_dp_bridge_atomic_disable(struct drm_bridge *bridge, struct drm_atomic_state *state)
 {
 	struct cdn_dp_device *dp = bridge_to_dp(bridge);
+	struct cdn_dp_bridge *dp_bridge = bridge_to_dp_bridge(bridge);
 	int ret;
 
 	mutex_lock(&dp->lock);
+	dp_bridge->enabled = false;
 
 	if (dp->active) {
 		ret = cdn_dp_disable(dp);

[Severity: High]
Does this accidentally disable the active DP controller when another inactive bridge is disabled? If dp->active is true, the entire DP controller is disabled, without checking if the bridge being disabled (dp_bridge) is actually the one driving the active DP port. This would break an active Bridge A if userspace disables an inactive Bridge B.

[ ... ]

Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0 -0
@@ -967,28 +1085,16 @@ static int cdn_dp_pd_event(struct notifier_block *nb,
 	return NOTIFY_DONE;
 }
 

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_pd_event(struct notifier_block *nb, · line 1095

Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +6 -2
-static int cdn_dp_bind(struct device *dev, struct device *master, void *data)
+static int cdn_bridge_add(struct device *dev,
+			  struct drm_bridge *bridge,
+			  struct drm_bridge *next_bridge,
+			  struct drm_encoder *encoder)
 {
 	struct cdn_dp_device *dp = dev_get_drvdata(dev);
-	struct drm_encoder *encoder;
+	struct drm_device *drm_dev = dp->drm_dev;
+	struct drm_bridge *last_bridge __free(drm_bridge_put) = NULL;

[Severity: High]
Will this cause a reference count underflow and a use-after-free vulnerability? The last_bridge pointer is populated by drm_bridge_chain_get_last_bridge(), which returns a raw pointer without incrementing the bridge's reference count. When last_bridge goes out of scope, the automatic drm_bridge_put() will prematurely decrement the refcount.

Quoted 5 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0 -4
 	struct drm_connector *connector;
-	struct cdn_dp_port *port;
-	struct drm_device *drm_dev = data;
-	int ret, i;
-

[ ... ]

Quoted 13 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +9 -0
+	if (next_bridge) {
+		ret = drm_bridge_attach(encoder, next_bridge, bridge,
+					DRM_BRIDGE_ATTACH_NO_CONNECTOR);
+		if (ret)
+			return ret;
+
+		last_bridge = drm_bridge_chain_get_last_bridge(bridge->encoder);
+	}
+
 	connector = drm_bridge_connector_init(drm_dev, encoder);
 	if (IS_ERR(connector)) {
 		ret = PTR_ERR(connector);

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_bind(struct device *dev, struct device *master, void *data) · line 1149

Quoted 5 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +2 -0
@@ -1030,8 +1145,99 @@ static int cdn_dp_bind(struct device *dev, struct device *master, void *data)
 		return ret;
 	}
 
+	if (last_bridge)
+		connector->fwnode = fwnode_handle_get(of_fwnode_handle(last_bridge->of_node));

[Severity: Medium]
Is this assignment leaking an fwnode reference? drm_bridge_connector_init() automatically sets connector->fwnode using the of_node of the last bridge and acquires a reference via fwnode_handle_get(). Overwriting it here without dropping the original reference will cause a memory leak.

Quoted 22 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +20 -0
+
 	drm_connector_attach_encoder(connector, encoder);
 
+	return 0;
+}
+
+static int cdn_dp_parse_next_bridge_dt(struct cdn_dp_device *dp)
+{
+	struct device_node *np = dp->dev->of_node;
+	struct device_node *port __free(device_node) = of_graph_get_port_by_id(np, 1);
+	struct drm_bridge *bridge;
+	int count = 0;
+	int ret = 0;
+	int i;
+
+	/* If device use extcon, do not use hpd bridge */
+	for (i = 0; i < dp->ports; i++) {
+		if (dp->port[i]->extcon) {
+			dp->bridge_count = 1;
+			return 0;
+		}
+	}

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_bind(struct device *dev, struct device *master, void *data) · line 1181

Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +10 -0
+
+	/* One endpoint may correspond to one next bridge. */
+	for_each_of_graph_port_endpoint(port, dp_ep) {
+		struct device_node *next_bridge_node __free(device_node) =
+			of_graph_get_remote_port_parent(dp_ep);
+
+		bridge = of_drm_find_bridge(next_bridge_node);
+		if (!bridge) {
+			ret = -EPROBE_DEFER;
+			goto out;

[Severity: High]
Does this leak the DRM bridge references acquired in earlier loop iterations? If of_drm_find_bridge() returns NULL on a subsequent iteration, it jumps to out and returns -EPROBE_DEFER without releasing the references previously obtained with drm_bridge_get().

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_bind(struct device *dev, struct device *master, void *data) · line 1186

Quoted 5 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +5 -0
+		}
+
+		dp->next_bridge_valid = true;
+		dp->next_bridge_list[count] = drm_bridge_get(bridge);
+		count++;

[Severity: High]
Could this overflow the next_bridge_list array? next_bridge_list is sized to MAX_PHY (2). If a device tree specifies more than two endpoints, count will exceed the array bounds and corrupt adjacent fields in the cdn_dp_device struct.

Quoted 9 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +9 -0
+	}
+
+out:
+	dp->bridge_count = count ? count : 1;
+	return ret;
+}
+
+static int cdn_dp_bind(struct device *dev, struct device *master, void *data)
+{

[ ... ]

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_bind(struct device *dev, struct device *master, void *data) · line 1236

Quoted 7 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +7 -0
+	for (i = 0; i < dp->bridge_count; i++) {
+		encoder = &dp->bridge_list[i]->encoder.encoder;
+		bridge = &dp->bridge_list[i]->bridge;
+		next_bridge = dp->next_bridge_list[i];
+		ret = cdn_bridge_add(dev, bridge, next_bridge, encoder);
+		if (ret)
+			return ret;

[Severity: High]
Does this leak the bridge references acquired in cdn_dp_parse_next_bridge_dt if cdn_bridge_add() fails? Returning directly without a cleanup path means drm_bridge_put() is never called for dp->next_bridge_list.

Quoted 1 line
(quoted diff) +1 -0
+	}
Signature · 6 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
maintainer Reviewed-by on v1 3/5
#10 lore raw

Re: [PATCH 3/5] phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge

In reply to Chaoyi Chen

Hi,

Am Donnerstag, 21. Mai 2026, 05:28:52 Mitteleuropäische Sommerzeit schrieb Chaoyi Chen:

Quoted 7 lines

From: Chaoyi Chen <[email protected]>

Using the DRM_AUX_BRIDGE helper to create the transparent DRM bridge device.

@Vinod:
could you give this patch an Ack to go through the DRM tree please?

It is independent of any other phy changes, but needs the drm-patches 1+2 from this series, so ideally would go through the drm tree together with them.

Thanks a lot
Heiko

Quoted 58 lines
---
 drivers/phy/rockchip/Kconfig              |  2 ++
 drivers/phy/rockchip/phy-rockchip-typec.c | 13 +++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/phy/rockchip/Kconfig +2 -0
index 14698571b607..9173d3b4fef4 100644
@@ -119,6 +119,8 @@ config PHY_ROCKCHIP_SNPS_PCIE3
 config PHY_ROCKCHIP_TYPEC
 	tristate "Rockchip TYPEC PHY Driver"
 	depends on OF && (ARCH_ROCKCHIP || COMPILE_TEST)
+	depends on DRM || DRM=n
+	select DRM_AUX_BRIDGE if DRM_BRIDGE
 	select EXTCON
 	select GENERIC_PHY
 	select RESET_CONTROLLER
drivers/phy/rockchip/phy-rockchip-typec.c +11 -2
index d9701b6106d5..48070b50416e 100644
@@ -54,6 +54,7 @@
 
 #include <linux/mfd/syscon.h>
 #include <linux/phy/phy.h>
+#include <drm/bridge/aux-bridge.h>
 
 #define CMN_SSM_BANDGAP			(0x21 << 2)
 #define CMN_SSM_BIAS			(0x22 << 2)
@@ -1162,16 +1163,24 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev)
 
 	for_each_available_child_of_node(np, child_np) {
 		struct phy *phy;
+		ret = 0;
 
-		if (of_node_name_eq(child_np, "dp-port"))
+		if (of_node_name_eq(child_np, "dp-port")) {
 			phy = devm_phy_create(dev, child_np,
 					      &rockchip_dp_phy_ops);
-		else if (of_node_name_eq(child_np, "usb3-port"))
+			ret = drm_aux_bridge_register_from_node(dev, child_np);
+		} else if (of_node_name_eq(child_np, "usb3-port"))
 			phy = devm_phy_create(dev, child_np,
 					      &rockchip_usb3_phy_ops);
 		else
 			continue;
 
+		if (ret) {
+			pm_runtime_disable(dev);
+			of_node_put(child_np);
+			return ret;
+		}
+
 		if (IS_ERR(phy)) {
 			dev_err(dev, "failed to create phy: %pOFn\n",
 				child_np);
#16 lore raw

Re: [PATCH 5/5] drm/rockchip: cdn-dp: Add multiple bridges to support PHY port selection

In reply to [email protected]

Oh! Interesting AI. It really did uncover some issues.

Quoted 35 lines · On 5/21/2026 2:22 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider:
- [High] Prematurely dropping the reference count of the last bridge in cdn_bridge_add() will cause a use-after-free.
- [High] The prev_port pointer is used uninitialized in cdn_dp_bridge_edid_read(), leading to a kernel crash.
- [High] cdn_dp_connected_port() ignores connection status for extcon configurations, breaking hotplug detection.
- [High] Missing bounds check in cdn_dp_parse_next_bridge_dt() allows an out-of-bounds write to the next_bridge_list array.
- [High] The lanes stack array is read out-of-bounds or uninitialized in cdn_dp_connected_port().
- [High] DRM bridge references are leaked on error paths during DT parsing and driver binding.
- [High] If link training fails in cdn_dp_switch_port(), it returns an error but leaves the DP controller erroneously marked as active.
- [High] cdn_dp_switch_port() incorrectly aborts hardware switching when the DP controller is active, causing EDID reads from the wrong port.
- [High] Disabling an inactive bridge erroneously disables the active DP controller for another bridge.
- [Medium] Overwriting connector->fwnode in cdn_bridge_add() causes a memory leak.
- [Medium] Incorrect check for the active port treats valid index 0 as invalid.
--

Hi,

I have reviewed the patch and found some potential issues to share.

commit 082c705aa7547b521ad9df20ac76e0592b41864f
Author: Chaoyi Chen <[email protected]>

drm/rockchip: cdn-dp: Add multiple bridges to support PHY port selection

This commit adds support for multiple bridges to the Rockchip cdn-dp driver to allow switching between two USB/DP combo PHYs. It changes the driver to use the DRM AUX HPD bridge and adds DT parsing logic to register multiple bridges.

Quoted 7 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +1 -1
@@ -192,14 +193,27 @@ static int cdn_dp_get_sink_count(struct cdn_dp_device *dp, u8 *sink_count)
 static struct cdn_dp_port *cdn_dp_connected_port(struct cdn_dp_device *dp)
 {
 	struct cdn_dp_port *port;
-	int i, lanes;
+	int i, lanes[MAX_PHY];
 
Quoted 15 lines

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_get_sink_count(struct cdn_dp_device *dp, u8 *sink_count) · line 202

Quoted 7 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +2 -2
 	for (i = 0; i < dp->ports; i++) {
 		port = dp->port[i];
-		lanes = cdn_dp_get_port_lanes(port);
-		if (lanes)
+		lanes[i] = cdn_dp_get_port_lanes(port);
+		if (!dp->next_bridge_valid)
 			return port;

[Severity: High]
Does this unconditionally return the first port without checking if it is actually connected? If dp->next_bridge_valid is false (which is the case for extcon setups), it appears to return port on the first iteration regardless of lanes[i], completely breaking hotplug detection.

Quoted 1 line
(quoted diff) +0 -0
 	}

No.

Quoted 10 lines

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_get_sink_count(struct cdn_dp_device *dp, u8 *sink_count) · line 207

Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +4 -0
+
+	if (dp->next_bridge_valid) {
+		/* If more than one port is available, pick the last active port */
+		if (dp->active_port > 0 && lanes[dp->active_port])

[Severity: Medium]
Since dp->active_port is initialized to -1, valid port indices are 0 and 1. Does the check dp->active_port > 0 incorrectly evaluate to false when the active port is 0, skipping the active port?

That's right. Will fix in v2.

Quoted 11 lines

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_get_sink_count(struct cdn_dp_device *dp, u8 *sink_count) · line 212

Quoted 5 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +5 -0
+			return dp->port[dp->active_port];
+
+		/* If the last active port is not available, pick an available port in order */
+		for (i = 0; i < dp->bridge_count; i++) {
+			if (lanes[i])

[Severity: High]
Can this read uninitialized stack memory? The lanes stack array is populated in a loop bounded by dp->ports, but accessed here in a loop bounded by dp->bridge_count.

Quoted 4 lines

If dp->bridge_count > dp->ports, this will read uninitialized values. Furthermore, since lanes is sized to MAX_PHY, if dp->bridge_count > MAX_PHY, it will perform an out-of-bounds stack read.

No.

Quoted 42 lines
Quoted 6 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +4 -0
+				return dp->port[i];
+		}
+	}
+
 	return NULL;
 }

[ ... ]

Quoted 16 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +8 -1
@@ -254,12 +268,45 @@ static const struct drm_edid *
 cdn_dp_bridge_edid_read(struct drm_bridge *bridge, struct drm_connector *connector)
 {
 	struct cdn_dp_device *dp = bridge_to_dp(bridge);
-	const struct drm_edid *drm_edid;
+	struct cdn_dp_bridge *dp_bridge = bridge_to_dp_bridge(bridge);
+	struct cdn_dp_port *port = dp->port[dp_bridge->id];
+	struct cdn_dp_port *prev_port;
+	const struct drm_edid *drm_edid = NULL;
 	int i, ret;
 
 	mutex_lock(&dp->lock);
+
+	/* More than one port is available */
+	if (dp->bridge_count > 1 && !port->phy_enabled) {
+		for (i = 0; i < dp->bridge_count; i++) {

drivers/gpu/drm/rockchip/cdn-dp-core.c static const struct drm_edid * · line 291

Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +10 -0
+			/* Another port already enable */
+			if (dp->bridge_list[i] != dp_bridge && dp->bridge_list[i]->enabled)
+				goto get_cache;
+			/* Find already enabled port */
+			if (dp->port[i]->phy_enabled)
+				prev_port = dp->port[i];
+		}
+
+		/* Switch to current port */
+		if (prev_port) {

[Severity: High]
Can this lead to a kernel crash by dereferencing an uninitialized pointer? The prev_port variable is not initialized. If no ports are currently enabled (which is common at boot), the for loop will complete without assigning anything to prev_port.

Quoted 3 lines

Then if (prev_port) evaluates garbage memory, and calling cdn_dp_switch_port with it will cause a kernel panic.

No.

Quoted 12 lines
Quoted 5 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +5 -0
+			ret = cdn_dp_switch_port(dp, prev_port, port);
+			if (ret)
+				goto get_cache;
+		}
+	}

[ ... ]

Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0 -0
@@ -551,6 +599,54 @@ static bool cdn_dp_check_link_status(struct cdn_dp_device *dp)
 	return drm_dp_channel_eq_ok(link_status, min(port->lanes, sink_lanes));
 }
 
Quoted 15 lines

drivers/gpu/drm/rockchip/cdn-dp-core.c static bool cdn_dp_check_link_status(struct cdn_dp_device *dp) · line 608

Quoted 7 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +7 -0
+static int cdn_dp_switch_port(struct cdn_dp_device *dp, struct cdn_dp_port *prev_port,
+			      struct cdn_dp_port *port)
+{
+	int ret;
+
+	if (dp->active)
+		return 0;

[Severity: High]
Does this incorrectly abort hardware switching? If the DP controller is already active but currently on a different port, returning 0 skips the actual port switch. The caller cdn_dp_bridge_edid_read() will proceed with reading EDID from the wrong (already-active) port and caching it for the new port.

Actually, this is a redundant check. When dp->active is true, this function is never called at all.

Quoted 22 lines
Quoted 22 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +22 -0
+
+	ret = cdn_dp_disable_phy(dp, prev_port);
+	if (ret)
+		goto out;
+	ret = cdn_dp_enable_phy(dp, port);
+	if (ret)
+		goto out;
+
+	ret = cdn_dp_get_sink_capability(dp);
+	if (ret) {
+		cdn_dp_disable_phy(dp, port);
+		goto out;
+	}
+
+	dp->active = true;
+	dp->lanes = port->lanes;
+
+	if (!cdn_dp_check_link_status(dp)) {
+		dev_info(dp->dev, "Connected with sink; re-train link\n");
+
+		ret = cdn_dp_train_link(dp);
+		if (ret) {
Quoted 9 lines

Review static bool cdn_dp_check_link_status(struct cdn_dp_device *dp) · line 632

Quoted 2 lines
(quoted diff) +2 -0
+			dev_err(dp->dev, "Training link failed: %d\n", ret);
+			goto out;

[Severity: High]
If link training fails, this jumps to out and returns the error code, but leaves dp->active = true. Does this trap the port in a permanently broken, untrained state since subsequent calls to cdn_dp_switch_port() will immediately return 0?

The redundant assignment, as mentioned above, should be removed.

Quoted 24 lines
Quoted 1 line
(quoted diff) +1 -0
+		}

[ ... ]

drivers/gpu/drm/rockchip/cdn-dp-core.c static void cdn_dp_bridge_atomic_enable(struct drm_bridge *bridge, struct drm_at · line 750

Quoted 12 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +2 -0
@@ -639,9 +740,11 @@ static void cdn_dp_bridge_atomic_enable(struct drm_bridge *bridge, struct drm_at
 static void cdn_dp_bridge_atomic_disable(struct drm_bridge *bridge, struct drm_atomic_state *state)
 {
 	struct cdn_dp_device *dp = bridge_to_dp(bridge);
+	struct cdn_dp_bridge *dp_bridge = bridge_to_dp_bridge(bridge);
 	int ret;
 
 	mutex_lock(&dp->lock);
+	dp_bridge->enabled = false;
 
 	if (dp->active) {
 		ret = cdn_dp_disable(dp);

[Severity: High]
Does this accidentally disable the active DP controller when another inactive bridge is disabled? If dp->active is true, the entire DP controller is disabled, without checking if the bridge being disabled (dp_bridge) is actually the one driving the active DP port. This would break an active Bridge A if userspace disables an inactive Bridge B.

Quoted 2 lines

[ ... ]

No.

Quoted 15 lines
Quoted 4 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0 -0
@@ -967,28 +1085,16 @@ static int cdn_dp_pd_event(struct notifier_block *nb,
 	return NOTIFY_DONE;
 }
 

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_pd_event(struct notifier_block *nb, · line 1095

Quoted 10 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +6 -2
-static int cdn_dp_bind(struct device *dev, struct device *master, void *data)
+static int cdn_bridge_add(struct device *dev,
+			  struct drm_bridge *bridge,
+			  struct drm_bridge *next_bridge,
+			  struct drm_encoder *encoder)
 {
 	struct cdn_dp_device *dp = dev_get_drvdata(dev);
-	struct drm_encoder *encoder;
+	struct drm_device *drm_dev = dp->drm_dev;
+	struct drm_bridge *last_bridge __free(drm_bridge_put) = NULL;
Quoted 8 lines

[Severity: High]
Will this cause a reference count underflow and a use-after-free vulnerability? The last_bridge pointer is populated by drm_bridge_chain_get_last_bridge(), which returns a raw pointer without incrementing the bridge's reference count. When last_bridge goes out of scope, the automatic drm_bridge_put() will prematurely decrement the refcount.

No.

Quoted 24 lines
Quoted 5 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +0 -4
 	struct drm_connector *connector;
-	struct cdn_dp_port *port;
-	struct drm_device *drm_dev = data;
-	int ret, i;
-

[ ... ]

Quoted 16 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +9 -0
+	if (next_bridge) {
+		ret = drm_bridge_attach(encoder, next_bridge, bridge,
+					DRM_BRIDGE_ATTACH_NO_CONNECTOR);
+		if (ret)
+			return ret;
+
+		last_bridge = drm_bridge_chain_get_last_bridge(bridge->encoder);
+	}
+
 	connector = drm_bridge_connector_init(drm_dev, encoder);
 	if (IS_ERR(connector)) {
 		ret = PTR_ERR(connector);
@@ -1030,8 +1145,99 @@ static int cdn_dp_bind(struct device *dev, struct device *master, void *data)
 		return ret;
 	}
 
Quoted 9 lines

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_bind(struct device *dev, struct device *master, void *data) · line 1149

Quoted 2 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +2 -0
+	if (last_bridge)
+		connector->fwnode = fwnode_handle_get(of_fwnode_handle(last_bridge->of_node));

[Severity: Medium]
Is this assignment leaking an fwnode reference? drm_bridge_connector_init() automatically sets connector->fwnode using the of_node of the last bridge and acquires a reference via fwnode_handle_get(). Overwriting it here without dropping the original reference will cause a memory leak.

Yes, the old fwnode should be put.

Quoted 30 lines
Quoted 30 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +28 -0
+
 	drm_connector_attach_encoder(connector, encoder);
 
+	return 0;
+}
+
+static int cdn_dp_parse_next_bridge_dt(struct cdn_dp_device *dp)
+{
+	struct device_node *np = dp->dev->of_node;
+	struct device_node *port __free(device_node) = of_graph_get_port_by_id(np, 1);
+	struct drm_bridge *bridge;
+	int count = 0;
+	int ret = 0;
+	int i;
+
+	/* If device use extcon, do not use hpd bridge */
+	for (i = 0; i < dp->ports; i++) {
+		if (dp->port[i]->extcon) {
+			dp->bridge_count = 1;
+			return 0;
+		}
+	}
+
+	/* One endpoint may correspond to one next bridge. */
+	for_each_of_graph_port_endpoint(port, dp_ep) {
+		struct device_node *next_bridge_node __free(device_node) =
+			of_graph_get_remote_port_parent(dp_ep);
+
+		bridge = of_drm_find_bridge(next_bridge_node);
+		if (!bridge) {
Quoted 9 lines

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_bind(struct device *dev, struct device *master, void *data) · line 1181

Quoted 2 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +2 -0
+			ret = -EPROBE_DEFER;
+			goto out;

[Severity: High]
Does this leak the DRM bridge references acquired in earlier loop iterations? If of_drm_find_bridge() returns NULL on a subsequent iteration, it jumps to out and returns -EPROBE_DEFER without releasing the references previously obtained with drm_bridge_get().

Yes, it should be put.

Quoted 12 lines

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_bind(struct device *dev, struct device *master, void *data) · line 1186

Quoted 5 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +5 -0
+		}
+
+		dp->next_bridge_valid = true;
+		dp->next_bridge_list[count] = drm_bridge_get(bridge);
+		count++;

[Severity: High]
Could this overflow the next_bridge_list array? next_bridge_list is sized to MAX_PHY (2). If a device tree specifies more than two endpoints, count will exceed the array bounds and corrupt adjacent fields in the cdn_dp_device struct.

No.

Quoted 25 lines
Quoted 9 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +9 -0
+	}
+
+out:
+	dp->bridge_count = count ? count : 1;
+	return ret;
+}
+
+static int cdn_dp_bind(struct device *dev, struct device *master, void *data)
+{

[ ... ]

drivers/gpu/drm/rockchip/cdn-dp-core.c static int cdn_dp_bind(struct device *dev, struct device *master, void *data) · line 1236

Quoted 7 lines
drivers/gpu/drm/rockchip/cdn-dp-core.c +7 -0
+	for (i = 0; i < dp->bridge_count; i++) {
+		encoder = &dp->bridge_list[i]->encoder.encoder;
+		bridge = &dp->bridge_list[i]->bridge;
+		next_bridge = dp->next_bridge_list[i];
+		ret = cdn_bridge_add(dev, bridge, next_bridge, encoder);
+		if (ret)
+			return ret;

[Severity: High]
Does this leak the bridge references acquired in cdn_dp_parse_next_bridge_dt if cdn_bridge_add() fails? Returning directly without a cleanup path means drm_bridge_put() is never called for dp->next_bridge_list.

Quoted 2 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	}

Yes, it should be put.

Signature · 7 lines
Best, 
Chaoyi

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#3 lore raw
In reply to Chaoyi Chen

Hi,

Quoted 23 lines · Chaoyi Chen

From: Chaoyi Chen <[email protected]>

The HPD function of Type-C DP is implemented through drm_connector_oob_hotplug_event(). For embedded DP, it is required that the DRM connector fwnode corresponds to the Type-C port fwnode.

To describe the relationship between the DP controller and the Type-C port device, we usually using drm_bridge to build a bridge chain.

Now several USB-C controller drivers have already implemented the DP HPD bridge function provided by aux-hpd-bridge.c, it will build a DP HPD bridge on USB-C connector port device.

But this requires the USB-C controller driver to manually register the HPD bridge. If the driver does not implement this feature, the bridge will not be create.

So this patch implements a generic DP HPD bridge based on aux-hpd-bridge.c. It will monitor Type-C bus events, and when a Type-C port device containing the DP svid is registered, it will create an HPD bridge for it without the need for the USB-C controller driver to implement it.

Quoted 6 lines
---
 drivers/gpu/drm/bridge/Kconfig                | 10 ++++
 drivers/gpu/drm/bridge/Makefile               |  1 +
 .../gpu/drm/bridge/aux-hpd-typec-dp-bridge.c  | 49 +++++++++++++++++++

Doesn't this require removing the manual registration of the HPD auxillary bridge in the USB-C controller drivers to avoid that two bridges are registered for them?

Quoted 55 lines
 3 files changed, 60 insertions(+)
 create mode 100644 drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c
drivers/gpu/drm/bridge/Kconfig +10 -0
index c3209b0f4678..d92e93875793 100644
@@ -30,6 +30,16 @@ config DRM_AUX_HPD_BRIDGE
 	  Simple bridge that terminates the bridge chain and provides HPD
 	  support.
 
+if DRM_AUX_HPD_BRIDGE
+config DRM_AUX_HPD_TYPEC_BRIDGE
+	tristate
+	depends on TYPEC || !TYPEC
+	default TYPEC
+	help
+	  Simple bridge that terminates the bridge chain and provides HPD
+	  support. It build bridge on each USB-C connector device node.
+endif
+
 menu "Display Interface Bridges"
 	depends on DRM && DRM_BRIDGE
 
drivers/gpu/drm/bridge/Makefile +1 -0
index beab5b695a6e..c4761526ba0a 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_DRM_AUX_BRIDGE) += aux-bridge.o
 obj-$(CONFIG_DRM_AUX_HPD_BRIDGE) += aux-hpd-bridge.o
+obj-$(CONFIG_DRM_AUX_HPD_TYPEC_BRIDGE) += aux-hpd-typec-dp-bridge.o
 obj-$(CONFIG_DRM_CHIPONE_ICN6211) += chipone-icn6211.o
 obj-$(CONFIG_DRM_CHRONTEL_CH7033) += chrontel-ch7033.o
 obj-$(CONFIG_DRM_CROS_EC_ANX7688) += cros-ec-anx7688.o
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +13 -0
new file mode 100644
index 000000000000..d915e0fb0668
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0+
+#include <linux/of.h>
+#include <linux/usb/typec_altmode.h>
+#include <linux/usb/typec_dp.h>
+
+#include <drm/bridge/aux-bridge.h>
+
+static int drm_typec_bus_event(struct notifier_block *nb,
+			       unsigned long action, void *data)
+{
+	struct device *dev = (struct device *)data;
+	struct typec_altmode *alt = to_typec_altmode(dev);
+

drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c line 23

Quoted 10 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +10 -0
+	if (action != BUS_NOTIFY_ADD_DEVICE)
+		goto done;
+
+	/*
+	 * alt->dev.parent->parent : USB-C controller device
+	 * alt->dev.parent         : USB-C connector device
+	 */
+	if (is_typec_port_altmode(&alt->dev) && alt->svid == USB_TYPEC_DP_SID)
+		drm_dp_hpd_bridge_register(alt->dev.parent->parent,
+					   to_of_node(alt->dev.parent->fwnode));

IIUIC this is called when the USB-C controller spawns a sub-device for the DP AltMode and then registers a HPD bridge to the USB-C controller itself. Wouldn't that register new HPD bridges on every USB-C replug?

Also doesn't this result in the bridge not being registered when nothing is plugged and thus the DRM pipeline not being able to bind properly?

Greetings,

-- Sebastian

Quoted 30 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +26 -0
+
+done:
+	return NOTIFY_OK;
+}
+
+static struct notifier_block drm_typec_event_nb = {
+	.notifier_call = drm_typec_bus_event,
+};
+
+static void drm_aux_hpd_typec_dp_bridge_module_exit(void)
+{
+	bus_unregister_notifier(&typec_bus, &drm_typec_event_nb);
+}
+
+static int __init drm_aux_hpd_typec_dp_bridge_module_init(void)
+{
+	bus_register_notifier(&typec_bus, &drm_typec_event_nb);
+
+	return 0;
+}
+
+module_init(drm_aux_hpd_typec_dp_bridge_module_init);
+module_exit(drm_aux_hpd_typec_dp_bridge_module_exit);
+
+MODULE_DESCRIPTION("DRM TYPEC DP HPD BRIDGE");
+MODULE_LICENSE("GPL");
Signature · 1 line
2.53.0
Reviewed-by on v1 2/5
#7 lore raw

Re: [PATCH 2/5] drm/bridge: aux: Add drm_aux_bridge_register_from_node()

In reply to Chaoyi Chen

Hi,

Quoted 11 lines · Chaoyi Chen

From: Chaoyi Chen <[email protected]>

The drm_aux_bridge_register() uses the device->of_node as the bridge->of_node.

This patch adds drm_aux_bridge_register_from_node() to allow specifying the of_node corresponding to the bridge.

---

Greetings,

-- Sebastian

Quoted 86 lines
 drivers/gpu/drm/bridge/aux-bridge.c | 24 ++++++++++++++++++++++--
 include/drm/bridge/aux-bridge.h     |  6 ++++++
 2 files changed, 28 insertions(+), 2 deletions(-)
drivers/gpu/drm/bridge/aux-bridge.c +22 -2
index 1ed21a8713bf..f50283abed5f 100644
@@ -35,6 +35,7 @@ static void drm_aux_bridge_unregister_adev(void *_adev)
 /**
  * drm_aux_bridge_register - Create a simple bridge device to link the chain
  * @parent: device instance providing this bridge
+ * @np: device node pointer corresponding to this bridge instance
  *
  * Creates a simple DRM bridge that doesn't implement any drm_bridge
  * operations. Such bridges merely fill a place in the bridge chain linking
@@ -42,7 +43,7 @@ static void drm_aux_bridge_unregister_adev(void *_adev)
  *
  * Return: zero on success, negative error code on failure
  */
-int drm_aux_bridge_register(struct device *parent)
+int drm_aux_bridge_register_from_node(struct device *parent, struct device_node *np)
 {
 	struct auxiliary_device *adev;
 	int ret;
@@ -62,7 +63,10 @@ int drm_aux_bridge_register(struct device *parent)
 	adev->dev.parent = parent;
 	adev->dev.release = drm_aux_bridge_release;
 
-	device_set_of_node_from_dev(&adev->dev, parent);
+	if (np)
+		device_set_node(&adev->dev, of_fwnode_handle(np));
+	else
+		device_set_of_node_from_dev(&adev->dev, parent);
 
 	ret = auxiliary_device_init(adev);
 	if (ret) {
@@ -80,6 +84,22 @@ int drm_aux_bridge_register(struct device *parent)
 
 	return devm_add_action_or_reset(parent, drm_aux_bridge_unregister_adev, adev);
 }
+EXPORT_SYMBOL_GPL(drm_aux_bridge_register_from_node);
+
+/**
+ * drm_aux_bridge_register - Create a simple bridge device to link the chain
+ * @parent: device instance providing this bridge
+ *
+ * Creates a simple DRM bridge that doesn't implement any drm_bridge
+ * operations. Such bridges merely fill a place in the bridge chain linking
+ * surrounding DRM bridges.
+ *
+ * Return: zero on success, negative error code on failure
+ */
+int drm_aux_bridge_register(struct device *parent)
+{
+	return drm_aux_bridge_register_from_node(parent, NULL);
+}
 EXPORT_SYMBOL_GPL(drm_aux_bridge_register);
 
 struct drm_aux_bridge_data {
include/drm/bridge/aux-bridge.h +6 -0
index c2f5a855512f..7dd1f17a1354 100644
@@ -13,11 +13,17 @@ struct auxiliary_device;
 
 #if IS_ENABLED(CONFIG_DRM_AUX_BRIDGE)
 int drm_aux_bridge_register(struct device *parent);
+int drm_aux_bridge_register_from_node(struct device *parent, struct device_node *np);
 #else
 static inline int drm_aux_bridge_register(struct device *parent)
 {
 	return 0;
 }
+
+static inline int drm_aux_bridge_register_from_node(struct device *parent, struct device_node *np)
+{
+	return 0;
+}
 #endif
 
 #if IS_ENABLED(CONFIG_DRM_AUX_HPD_BRIDGE)
Signature · 1 line
2.53.0
Reviewed-by on v1 3/5
#11 lore raw

Re: [PATCH 3/5] phy: rockchip: phy-rockchip-typec: Add DRM AUX bridge

In reply to Chaoyi Chen

Hi,

Quoted 8 lines · Chaoyi Chen

From: Chaoyi Chen <[email protected]>

Using the DRM_AUX_BRIDGE helper to create the transparent DRM bridge device.

---

Greetings,

-- Sebastian

Quoted 60 lines
 drivers/phy/rockchip/Kconfig              |  2 ++
 drivers/phy/rockchip/phy-rockchip-typec.c | 13 +++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/phy/rockchip/Kconfig +2 -0
index 14698571b607..9173d3b4fef4 100644
@@ -119,6 +119,8 @@ config PHY_ROCKCHIP_SNPS_PCIE3
 config PHY_ROCKCHIP_TYPEC
 	tristate "Rockchip TYPEC PHY Driver"
 	depends on OF && (ARCH_ROCKCHIP || COMPILE_TEST)
+	depends on DRM || DRM=n
+	select DRM_AUX_BRIDGE if DRM_BRIDGE
 	select EXTCON
 	select GENERIC_PHY
 	select RESET_CONTROLLER
drivers/phy/rockchip/phy-rockchip-typec.c +11 -2
index d9701b6106d5..48070b50416e 100644
@@ -54,6 +54,7 @@
 
 #include <linux/mfd/syscon.h>
 #include <linux/phy/phy.h>
+#include <drm/bridge/aux-bridge.h>
 
 #define CMN_SSM_BANDGAP			(0x21 << 2)
 #define CMN_SSM_BIAS			(0x22 << 2)
@@ -1162,16 +1163,24 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev)
 
 	for_each_available_child_of_node(np, child_np) {
 		struct phy *phy;
+		ret = 0;
 
-		if (of_node_name_eq(child_np, "dp-port"))
+		if (of_node_name_eq(child_np, "dp-port")) {
 			phy = devm_phy_create(dev, child_np,
 					      &rockchip_dp_phy_ops);
-		else if (of_node_name_eq(child_np, "usb3-port"))
+			ret = drm_aux_bridge_register_from_node(dev, child_np);
+		} else if (of_node_name_eq(child_np, "usb3-port"))
 			phy = devm_phy_create(dev, child_np,
 					      &rockchip_usb3_phy_ops);
 		else
 			continue;
 
+		if (ret) {
+			pm_runtime_disable(dev);
+			of_node_put(child_np);
+			return ret;
+		}
+
 		if (IS_ERR(phy)) {
 			dev_err(dev, "failed to create phy: %pOFn\n",
 				child_np);
Signature · 1 line
2.53.0
#4 lore raw
In reply to Sebastian Reichel

Hi Sebastian,

Quoted 33 lines · Sebastian Reichel

Hi,

Quoted 23 lines · Chaoyi Chen

From: Chaoyi Chen <[email protected]>

The HPD function of Type-C DP is implemented through drm_connector_oob_hotplug_event(). For embedded DP, it is required that the DRM connector fwnode corresponds to the Type-C port fwnode.

To describe the relationship between the DP controller and the Type-C port device, we usually using drm_bridge to build a bridge chain.

Now several USB-C controller drivers have already implemented the DP HPD bridge function provided by aux-hpd-bridge.c, it will build a DP HPD bridge on USB-C connector port device.

But this requires the USB-C controller driver to manually register the HPD bridge. If the driver does not implement this feature, the bridge will not be create.

So this patch implements a generic DP HPD bridge based on aux-hpd-bridge.c. It will monitor Type-C bus events, and when a Type-C port device containing the DP svid is registered, it will create an HPD bridge for it without the need for the USB-C controller driver to implement it.

Quoted 6 lines
---
 drivers/gpu/drm/bridge/Kconfig                | 10 ++++
 drivers/gpu/drm/bridge/Makefile               |  1 +
 .../gpu/drm/bridge/aux-hpd-typec-dp-bridge.c  | 49 +++++++++++++++++++
Quoted 4 lines

Doesn't this require removing the manual registration of the HPD auxillary bridge in the USB-C controller drivers to avoid that two bridges are registered for them?

I believe this will not affect existing controller drivers, as they call drm_bridge_attach during registration. Of course, while it won't affect the main bridge chain, you'll still see an additional HPD bridge.

Quoted 71 lines
Quoted 55 lines
 3 files changed, 60 insertions(+)
 create mode 100644 drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c
drivers/gpu/drm/bridge/Kconfig +10 -0
index c3209b0f4678..d92e93875793 100644
@@ -30,6 +30,16 @@ config DRM_AUX_HPD_BRIDGE
 	  Simple bridge that terminates the bridge chain and provides HPD
 	  support.
 
+if DRM_AUX_HPD_BRIDGE
+config DRM_AUX_HPD_TYPEC_BRIDGE
+	tristate
+	depends on TYPEC || !TYPEC
+	default TYPEC
+	help
+	  Simple bridge that terminates the bridge chain and provides HPD
+	  support. It build bridge on each USB-C connector device node.
+endif
+
 menu "Display Interface Bridges"
 	depends on DRM && DRM_BRIDGE
 
drivers/gpu/drm/bridge/Makefile +1 -0
index beab5b695a6e..c4761526ba0a 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_DRM_AUX_BRIDGE) += aux-bridge.o
 obj-$(CONFIG_DRM_AUX_HPD_BRIDGE) += aux-hpd-bridge.o
+obj-$(CONFIG_DRM_AUX_HPD_TYPEC_BRIDGE) += aux-hpd-typec-dp-bridge.o
 obj-$(CONFIG_DRM_CHIPONE_ICN6211) += chipone-icn6211.o
 obj-$(CONFIG_DRM_CHRONTEL_CH7033) += chrontel-ch7033.o
 obj-$(CONFIG_DRM_CROS_EC_ANX7688) += cros-ec-anx7688.o
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +13 -0
new file mode 100644
index 000000000000..d915e0fb0668
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0+
+#include <linux/of.h>
+#include <linux/usb/typec_altmode.h>
+#include <linux/usb/typec_dp.h>
+
+#include <drm/bridge/aux-bridge.h>
+
+static int drm_typec_bus_event(struct notifier_block *nb,
+			       unsigned long action, void *data)
+{
+	struct device *dev = (struct device *)data;
+	struct typec_altmode *alt = to_typec_altmode(dev);
+

drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c line 23

Quoted 10 lines
drivers/gpu/drm/bridge/aux-hpd-typec-dp-bridge.c new file +10 -0
+	if (action != BUS_NOTIFY_ADD_DEVICE)
+		goto done;
+
+	/*
+	 * alt->dev.parent->parent : USB-C controller device
+	 * alt->dev.parent         : USB-C connector device
+	 */
+	if (is_typec_port_altmode(&alt->dev) && alt->svid == USB_TYPEC_DP_SID)
+		drm_dp_hpd_bridge_register(alt->dev.parent->parent,
+					   to_of_node(alt->dev.parent->fwnode));

IIUIC this is called when the USB-C controller spawns a sub-device for the DP AltMode and then registers a HPD bridge to the USB-C controller itself. Wouldn't that register new HPD bridges on every USB-C replug?

Quoted 4 lines

Also doesn't this result in the bridge not being registered when nothing is plugged and thus the DRM pipeline not being able to bind properly?

That's a good question. The port altmode device here is only registered once during initialization. While the parnter altmode device will register and unregister during the plugging and unplugging process. So you don't need to worry about that :)

https://lore.kernel.org/all/[email protected]/

Signature · 7 lines
Best, 
Chaoyi

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy