public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] usb: typec: mux: avoid duplicated mux switches
@ 2026-02-23 18:27 Sebastian Reichel
  2026-02-23 18:27 ` [PATCH v2 1/2] usb: typec: mux: avoid duplicated orientation switches Sebastian Reichel
  2026-02-23 18:27 ` [PATCH v2 2/2] usb: typec: mux: avoid duplicated mux switches Sebastian Reichel
  0 siblings, 2 replies; 5+ messages in thread
From: Sebastian Reichel @ 2026-02-23 18:27 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-rockchip, linux-usb, linux-kernel, kernel,
	Sebastian Reichel

Recent Rockchip SoCs (e.g. RK3588, RK3576) have a PHY, which
handles USB3 and DisplayPort as well as orientation and lane
muxing. By setting up the DT graph from the USB-C connector
for the SuperSpeed and SBU lanes to the PHY all mux/orientation
operations are applied twice.

I did not add any Fixes tag, since applying the settings twice
is not breaking anything. But it's confusing when debugging
USB-C issues and obviously wastes some CPU cycles.

Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
Changes in v2:
- Link to v1: https://lore.kernel.org/r/20260213-typec-mux-duplication-fix-v1-0-70076a7c5691@collabora.com
- move the dropping logic into typec_*_match() functions (Heikki Krogerus)
- rebase to v7.0-rc1

---
Sebastian Reichel (2):
      usb: typec: mux: avoid duplicated orientation switches
      usb: typec: mux: avoid duplicated mux switches

 drivers/usb/typec/mux.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
---
base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
change-id: 20260213-typec-mux-duplication-fix-ba5e58f6576a

Best regards,
-- 
Sebastian Reichel <sebastian.reichel@collabora.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] usb: typec: mux: avoid duplicated orientation switches
  2026-02-23 18:27 [PATCH v2 0/2] usb: typec: mux: avoid duplicated mux switches Sebastian Reichel
@ 2026-02-23 18:27 ` Sebastian Reichel
  2026-02-24  9:50   ` Heikki Krogerus
  2026-02-23 18:27 ` [PATCH v2 2/2] usb: typec: mux: avoid duplicated mux switches Sebastian Reichel
  1 sibling, 1 reply; 5+ messages in thread
From: Sebastian Reichel @ 2026-02-23 18:27 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-rockchip, linux-usb, linux-kernel, kernel,
	Sebastian Reichel

Some devices use combo PHYs (i.e. USB3 + DisplayPort), which also
handle the orientation mux. These PHYs are referenced twice from
the USB-C connector (USB super-speed lines and SBU/AUX lines)
resulting in the switch being configured twice. Avoid this by
dropping duplicates.

Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 drivers/usb/typec/mux.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
index 58fb97ea6877..9b908c46bd7d 100644
--- a/drivers/usb/typec/mux.c
+++ b/drivers/usb/typec/mux.c
@@ -35,7 +35,9 @@ static int switch_fwnode_match(struct device *dev, const void *fwnode)
 static void *typec_switch_match(const struct fwnode_handle *fwnode,
 				const char *id, void *data)
 {
+	struct typec_switch_dev **sw_devs = data;
 	struct device *dev;
+	int i;
 
 	/*
 	 * Device graph (OF graph) does not give any means to identify the
@@ -56,6 +58,13 @@ static void *typec_switch_match(const struct fwnode_handle *fwnode,
 	dev = class_find_device(&typec_mux_class, NULL, fwnode,
 				switch_fwnode_match);
 
+	/* Skip duplicates */
+	for (i = 0; i < TYPEC_MUX_MAX_DEVS; i++)
+		if (to_typec_switch_dev(dev) == sw_devs[i]) {
+			put_device(dev);
+			return NULL;
+		}
+
 	return dev ? to_typec_switch_dev(dev) : ERR_PTR(-EPROBE_DEFER);
 }
 
@@ -80,7 +89,8 @@ struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode)
 	if (!sw)
 		return ERR_PTR(-ENOMEM);
 
-	count = fwnode_connection_find_matches(fwnode, "orientation-switch", NULL,
+	count = fwnode_connection_find_matches(fwnode, "orientation-switch",
+					       (void **)sw_devs,
 					       typec_switch_match,
 					       (void **)sw_devs,
 					       ARRAY_SIZE(sw_devs));

-- 
2.51.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] usb: typec: mux: avoid duplicated mux switches
  2026-02-23 18:27 [PATCH v2 0/2] usb: typec: mux: avoid duplicated mux switches Sebastian Reichel
  2026-02-23 18:27 ` [PATCH v2 1/2] usb: typec: mux: avoid duplicated orientation switches Sebastian Reichel
@ 2026-02-23 18:27 ` Sebastian Reichel
  2026-02-24  9:51   ` Heikki Krogerus
  1 sibling, 1 reply; 5+ messages in thread
From: Sebastian Reichel @ 2026-02-23 18:27 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-rockchip, linux-usb, linux-kernel, kernel,
	Sebastian Reichel

Some devices use combo PHYs (i.e. USB3 + DisplayPort), which also
handle the lane muxing. These PHYs are referenced twice from
the USB-C connector (USB super-speed lines and SBU/AUX lines)
resulting in the mux being configured twice. Avoid this by
dropping duplicates.

Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 drivers/usb/typec/mux.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
index 9b908c46bd7d..db5e4a4c0a99 100644
--- a/drivers/usb/typec/mux.c
+++ b/drivers/usb/typec/mux.c
@@ -275,7 +275,9 @@ static int mux_fwnode_match(struct device *dev, const void *fwnode)
 static void *typec_mux_match(const struct fwnode_handle *fwnode,
 			     const char *id, void *data)
 {
+	struct typec_mux_dev **mux_devs = data;
 	struct device *dev;
+	int i;
 
 	/*
 	 * Device graph (OF graph) does not give any means to identify the
@@ -291,6 +293,14 @@ static void *typec_mux_match(const struct fwnode_handle *fwnode,
 	dev = class_find_device(&typec_mux_class, NULL, fwnode,
 				mux_fwnode_match);
 
+	/* Skip duplicates */
+	for (i = 0; i < TYPEC_MUX_MAX_DEVS; i++)
+		if (to_typec_mux_dev(dev) == mux_devs[i]) {
+			put_device(dev);
+			return NULL;
+		}
+
+
 	return dev ? to_typec_mux_dev(dev) : ERR_PTR(-EPROBE_DEFER);
 }
 
@@ -316,7 +326,8 @@ struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode)
 		return ERR_PTR(-ENOMEM);
 
 	count = fwnode_connection_find_matches(fwnode, "mode-switch",
-					       NULL, typec_mux_match,
+					       (void **)mux_devs,
+					       typec_mux_match,
 					       (void **)mux_devs,
 					       ARRAY_SIZE(mux_devs));
 	if (count <= 0) {

-- 
2.51.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] usb: typec: mux: avoid duplicated orientation switches
  2026-02-23 18:27 ` [PATCH v2 1/2] usb: typec: mux: avoid duplicated orientation switches Sebastian Reichel
@ 2026-02-24  9:50   ` Heikki Krogerus
  0 siblings, 0 replies; 5+ messages in thread
From: Heikki Krogerus @ 2026-02-24  9:50 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Greg Kroah-Hartman, linux-rockchip, linux-usb, linux-kernel,
	kernel

Mon, Feb 23, 2026 at 07:27:38PM +0100, Sebastian Reichel kirjoitti:
> Some devices use combo PHYs (i.e. USB3 + DisplayPort), which also
> handle the orientation mux. These PHYs are referenced twice from
> the USB-C connector (USB super-speed lines and SBU/AUX lines)
> resulting in the switch being configured twice. Avoid this by
> dropping duplicates.
> 
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/mux.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
> index 58fb97ea6877..9b908c46bd7d 100644
> --- a/drivers/usb/typec/mux.c
> +++ b/drivers/usb/typec/mux.c
> @@ -35,7 +35,9 @@ static int switch_fwnode_match(struct device *dev, const void *fwnode)
>  static void *typec_switch_match(const struct fwnode_handle *fwnode,
>  				const char *id, void *data)
>  {
> +	struct typec_switch_dev **sw_devs = data;
>  	struct device *dev;
> +	int i;
>  
>  	/*
>  	 * Device graph (OF graph) does not give any means to identify the
> @@ -56,6 +58,13 @@ static void *typec_switch_match(const struct fwnode_handle *fwnode,
>  	dev = class_find_device(&typec_mux_class, NULL, fwnode,
>  				switch_fwnode_match);
>  
> +	/* Skip duplicates */
> +	for (i = 0; i < TYPEC_MUX_MAX_DEVS; i++)
> +		if (to_typec_switch_dev(dev) == sw_devs[i]) {
> +			put_device(dev);
> +			return NULL;
> +		}
> +
>  	return dev ? to_typec_switch_dev(dev) : ERR_PTR(-EPROBE_DEFER);
>  }
>  
> @@ -80,7 +89,8 @@ struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode)
>  	if (!sw)
>  		return ERR_PTR(-ENOMEM);
>  
> -	count = fwnode_connection_find_matches(fwnode, "orientation-switch", NULL,
> +	count = fwnode_connection_find_matches(fwnode, "orientation-switch",
> +					       (void **)sw_devs,
>  					       typec_switch_match,
>  					       (void **)sw_devs,
>  					       ARRAY_SIZE(sw_devs));
> 
> -- 
> 2.51.0

-- 
heikki

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] usb: typec: mux: avoid duplicated mux switches
  2026-02-23 18:27 ` [PATCH v2 2/2] usb: typec: mux: avoid duplicated mux switches Sebastian Reichel
@ 2026-02-24  9:51   ` Heikki Krogerus
  0 siblings, 0 replies; 5+ messages in thread
From: Heikki Krogerus @ 2026-02-24  9:51 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: Greg Kroah-Hartman, linux-rockchip, linux-usb, linux-kernel,
	kernel

Mon, Feb 23, 2026 at 07:27:39PM +0100, Sebastian Reichel wrote:
> Some devices use combo PHYs (i.e. USB3 + DisplayPort), which also
> handle the lane muxing. These PHYs are referenced twice from
> the USB-C connector (USB super-speed lines and SBU/AUX lines)
> resulting in the mux being configured twice. Avoid this by
> dropping duplicates.
> 
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/mux.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
> index 9b908c46bd7d..db5e4a4c0a99 100644
> --- a/drivers/usb/typec/mux.c
> +++ b/drivers/usb/typec/mux.c
> @@ -275,7 +275,9 @@ static int mux_fwnode_match(struct device *dev, const void *fwnode)
>  static void *typec_mux_match(const struct fwnode_handle *fwnode,
>  			     const char *id, void *data)
>  {
> +	struct typec_mux_dev **mux_devs = data;
>  	struct device *dev;
> +	int i;
>  
>  	/*
>  	 * Device graph (OF graph) does not give any means to identify the
> @@ -291,6 +293,14 @@ static void *typec_mux_match(const struct fwnode_handle *fwnode,
>  	dev = class_find_device(&typec_mux_class, NULL, fwnode,
>  				mux_fwnode_match);
>  
> +	/* Skip duplicates */
> +	for (i = 0; i < TYPEC_MUX_MAX_DEVS; i++)
> +		if (to_typec_mux_dev(dev) == mux_devs[i]) {
> +			put_device(dev);
> +			return NULL;
> +		}
> +
> +
>  	return dev ? to_typec_mux_dev(dev) : ERR_PTR(-EPROBE_DEFER);
>  }
>  
> @@ -316,7 +326,8 @@ struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode)
>  		return ERR_PTR(-ENOMEM);
>  
>  	count = fwnode_connection_find_matches(fwnode, "mode-switch",
> -					       NULL, typec_mux_match,
> +					       (void **)mux_devs,
> +					       typec_mux_match,
>  					       (void **)mux_devs,
>  					       ARRAY_SIZE(mux_devs));
>  	if (count <= 0) {
> 
> -- 
> 2.51.0

-- 
heikki

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-02-24  9:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-23 18:27 [PATCH v2 0/2] usb: typec: mux: avoid duplicated mux switches Sebastian Reichel
2026-02-23 18:27 ` [PATCH v2 1/2] usb: typec: mux: avoid duplicated orientation switches Sebastian Reichel
2026-02-24  9:50   ` Heikki Krogerus
2026-02-23 18:27 ` [PATCH v2 2/2] usb: typec: mux: avoid duplicated mux switches Sebastian Reichel
2026-02-24  9:51   ` Heikki Krogerus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox