mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: typec: mux: avoid duplicated mux switches
@ 2026-08-22  7:24 Marek Vasut
  2026-08-22  7:47 ` Jens Glathe
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Marek Vasut @ 2026-08-22  7:24 UTC (permalink / raw)
  To: linux-usb
  Cc: Marek Vasut, stable, Sebastian Reichel, Greg Kroah-Hartman,
	Heikki Krogerus, Jens Glathe, kernel, linux-kernel

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.

This is a re-application of b145c3f29d62 ("usb: typec: mux: avoid
duplicated mux switches"), with fix derived from usb: typec: mux:
Fix typec_switch_match() .

Fixes: f576c75f95a5 ("Revert "usb: typec: mux: avoid duplicated mux switches"")
Cc: stable@vger.kernel.org
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Co-developed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Marek Vasut <marex@nabladev.com>
---
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Jens Glathe <jens.glathe@oldschoolsolutions.biz>
Cc: Sebastian Reichel <sebastian.reichel@collabora.com>
Cc: kernel@dh-electronics.com
Cc: linux-kernel@vger.kernel.org
Cc: linux-usb@vger.kernel.org
---
- Extensive test by Jens https://lore.kernel.org/all/8bdf6062-8ec2-4c30-8463-0368d3a0f1ce@oldschoolsolutions.biz/
---
 drivers/usb/typec/mux.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
index 2bc7e8edb3cbd..afa6fc1813978 100644
--- a/drivers/usb/typec/mux.c
+++ b/drivers/usb/typec/mux.c
@@ -277,7 +277,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
@@ -292,8 +294,18 @@ static void *typec_mux_match(const struct fwnode_handle *fwnode,
 
 	dev = class_find_device(&typec_mux_class, NULL, fwnode,
 				mux_fwnode_match);
+	if (!dev)
+		return ERR_PTR(-EPROBE_DEFER);
 
-	return dev ? to_typec_mux_dev(dev) : ERR_PTR(-EPROBE_DEFER);
+	/* 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 to_typec_mux_dev(dev);
 }
 
 /**
@@ -318,7 +330,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.53.0


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

* Re: [PATCH] usb: typec: mux: avoid duplicated mux switches
  2026-08-22  7:24 [PATCH] usb: typec: mux: avoid duplicated mux switches Marek Vasut
@ 2026-08-22  7:47 ` Jens Glathe
  2026-08-22  8:06   ` Marek Vasut
  2026-08-24 12:18   ` Sebastian Reichel
  2026-08-24 12:01 ` Heikki Krogerus
  2026-08-24 12:30 ` Sebastian Reichel
  2 siblings, 2 replies; 6+ messages in thread
From: Jens Glathe @ 2026-08-22  7:47 UTC (permalink / raw)
  To: Marek Vasut, linux-usb
  Cc: stable, Sebastian Reichel, Greg Kroah-Hartman, Heikki Krogerus,
	kernel, linux-kernel

Hi Marek,

On 8/22/26 09:24, Marek Vasut wrote:
> This is a re-application of b145c3f29d62 ("usb: typec: mux: avoid
> duplicated mux switches"), with fix derived from usb: typec: mux:
> Fix typec_switch_match() .
>
> Fixes: f576c75f95a5 ("Revert "usb: typec: mux: avoid duplicated mux switches"")
> - Extensive test by Jens https://lore.kernel.org/all/8bdf6062-8ec2-4c30-8463-0368d3a0f1ce@oldschoolsolutions.biz/
>
I applied both patches and compared to my tip of tree, same except for a 
newline. Also did a test on the Lenovo X13s (sc8280xp, gpio mux). 
Therefore justified:

Tested-by: Jens Glathe <jens.glathe@oldschoolsolutions.biz>

with best regards

Jens



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

* Re: [PATCH] usb: typec: mux: avoid duplicated mux switches
  2026-08-22  7:47 ` Jens Glathe
@ 2026-08-22  8:06   ` Marek Vasut
  2026-08-24 12:18   ` Sebastian Reichel
  1 sibling, 0 replies; 6+ messages in thread
From: Marek Vasut @ 2026-08-22  8:06 UTC (permalink / raw)
  To: Jens Glathe, linux-usb
  Cc: stable, Sebastian Reichel, Greg Kroah-Hartman, Heikki Krogerus,
	kernel, linux-kernel

On 8/22/26 9:47 AM, Jens Glathe wrote:

Hello Jens,

> On 8/22/26 09:24, Marek Vasut wrote:
>> This is a re-application of b145c3f29d62 ("usb: typec: mux: avoid
>> duplicated mux switches"), with fix derived from usb: typec: mux:
>> Fix typec_switch_match() .
>>
>> Fixes: f576c75f95a5 ("Revert "usb: typec: mux: avoid duplicated mux 
>> switches"")
>> - Extensive test by Jens https://lore.kernel.org/ 
>> all/8bdf6062-8ec2-4c30-8463-0368d3a0f1ce@oldschoolsolutions.biz/
>>
> I applied both patches and compared to my tip of tree, same except for a 
> newline. Also did a test on the Lenovo X13s (sc8280xp, gpio mux). 
> Therefore justified:
> 
> Tested-by: Jens Glathe <jens.glathe@oldschoolsolutions.biz>
> 
> with best regards

Thank you !

-- 
Best regards,
Marek Vasut

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

* Re: [PATCH] usb: typec: mux: avoid duplicated mux switches
  2026-08-22  7:24 [PATCH] usb: typec: mux: avoid duplicated mux switches Marek Vasut
  2026-08-22  7:47 ` Jens Glathe
@ 2026-08-24 12:01 ` Heikki Krogerus
  2026-08-24 12:30 ` Sebastian Reichel
  2 siblings, 0 replies; 6+ messages in thread
From: Heikki Krogerus @ 2026-08-24 12:01 UTC (permalink / raw)
  To: Marek Vasut
  Cc: linux-usb, stable, Sebastian Reichel, Greg Kroah-Hartman,
	Jens Glathe, kernel, linux-kernel

On Sat, Aug 22, 2026 at 09:24:58AM +0200, Marek Vasut 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.
> 
> This is a re-application of b145c3f29d62 ("usb: typec: mux: avoid
> duplicated mux switches"), with fix derived from usb: typec: mux:
> Fix typec_switch_match() .
> 
> Fixes: f576c75f95a5 ("Revert "usb: typec: mux: avoid duplicated mux switches"")
> Cc: stable@vger.kernel.org
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> Co-developed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> Signed-off-by: Marek Vasut <marex@nabladev.com>

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

> ---
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Jens Glathe <jens.glathe@oldschoolsolutions.biz>
> Cc: Sebastian Reichel <sebastian.reichel@collabora.com>
> Cc: kernel@dh-electronics.com
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-usb@vger.kernel.org
> ---
> - Extensive test by Jens https://lore.kernel.org/all/8bdf6062-8ec2-4c30-8463-0368d3a0f1ce@oldschoolsolutions.biz/
> ---
>  drivers/usb/typec/mux.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
> index 2bc7e8edb3cbd..afa6fc1813978 100644
> --- a/drivers/usb/typec/mux.c
> +++ b/drivers/usb/typec/mux.c
> @@ -277,7 +277,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
> @@ -292,8 +294,18 @@ static void *typec_mux_match(const struct fwnode_handle *fwnode,
>  
>  	dev = class_find_device(&typec_mux_class, NULL, fwnode,
>  				mux_fwnode_match);
> +	if (!dev)
> +		return ERR_PTR(-EPROBE_DEFER);
>  
> -	return dev ? to_typec_mux_dev(dev) : ERR_PTR(-EPROBE_DEFER);
> +	/* 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 to_typec_mux_dev(dev);
>  }
>  
>  /**
> @@ -318,7 +330,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.53.0

-- 
heikki

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

* Re: [PATCH] usb: typec: mux: avoid duplicated mux switches
  2026-08-22  7:47 ` Jens Glathe
  2026-08-22  8:06   ` Marek Vasut
@ 2026-08-24 12:18   ` Sebastian Reichel
  1 sibling, 0 replies; 6+ messages in thread
From: Sebastian Reichel @ 2026-08-24 12:18 UTC (permalink / raw)
  To: Jens Glathe
  Cc: Marek Vasut, linux-usb, stable, Greg Kroah-Hartman,
	Heikki Krogerus, kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 762 bytes --]

Hi,

On Sat, Aug 22, 2026 at 09:47:33AM +0200, Jens Glathe wrote:
> On 8/22/26 09:24, Marek Vasut wrote:
> > This is a re-application of b145c3f29d62 ("usb: typec: mux: avoid
> > duplicated mux switches"), with fix derived from usb: typec: mux:
> > Fix typec_switch_match() .
> > 
> > Fixes: f576c75f95a5 ("Revert "usb: typec: mux: avoid duplicated mux switches"")
> > - Extensive test by Jens https://lore.kernel.org/all/8bdf6062-8ec2-4c30-8463-0368d3a0f1ce@oldschoolsolutions.biz/
> > 
> I applied both patches and compared to my tip of tree, same except for a
> newline. Also did a test on the Lenovo X13s (sc8280xp, gpio mux). Therefore
> justified:
> 
> Tested-by: Jens Glathe <jens.glathe@oldschoolsolutions.biz>

Thanks!

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] usb: typec: mux: avoid duplicated mux switches
  2026-08-22  7:24 [PATCH] usb: typec: mux: avoid duplicated mux switches Marek Vasut
  2026-08-22  7:47 ` Jens Glathe
  2026-08-24 12:01 ` Heikki Krogerus
@ 2026-08-24 12:30 ` Sebastian Reichel
  2 siblings, 0 replies; 6+ messages in thread
From: Sebastian Reichel @ 2026-08-24 12:30 UTC (permalink / raw)
  To: Marek Vasut
  Cc: linux-usb, stable, Greg Kroah-Hartman, Heikki Krogerus,
	Jens Glathe, kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3196 bytes --]

Hi,

On Sat, Aug 22, 2026 at 09:24:58AM +0200, Marek Vasut 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.
> 
> This is a re-application of b145c3f29d62 ("usb: typec: mux: avoid
> duplicated mux switches"), with fix derived from usb: typec: mux:
> Fix typec_switch_match() .
> 
> Fixes: f576c75f95a5 ("Revert "usb: typec: mux: avoid duplicated mux switches"")
> Cc: stable@vger.kernel.org
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> Co-developed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> Signed-off-by: Marek Vasut <marex@nabladev.com>
> ---
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Cc: Jens Glathe <jens.glathe@oldschoolsolutions.biz>
> Cc: Sebastian Reichel <sebastian.reichel@collabora.com>
> Cc: kernel@dh-electronics.com
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-usb@vger.kernel.org
> ---
> - Extensive test by Jens https://lore.kernel.org/all/8bdf6062-8ec2-4c30-8463-0368d3a0f1ce@oldschoolsolutions.biz/

Thanks for the fixed version. It looks mostly good to me, but it
should also take the other fix into account and initialize
mux_devs to {} in fwnode_typec_mux_get():

https://lore.kernel.org/linux-usb/20260804083434.20885-1-i@4t.pw/

Greetings,

-- Sebastian

> ---
>  drivers/usb/typec/mux.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
> index 2bc7e8edb3cbd..afa6fc1813978 100644
> --- a/drivers/usb/typec/mux.c
> +++ b/drivers/usb/typec/mux.c
> @@ -277,7 +277,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
> @@ -292,8 +294,18 @@ static void *typec_mux_match(const struct fwnode_handle *fwnode,
>  
>  	dev = class_find_device(&typec_mux_class, NULL, fwnode,
>  				mux_fwnode_match);
> +	if (!dev)
> +		return ERR_PTR(-EPROBE_DEFER);
>  
> -	return dev ? to_typec_mux_dev(dev) : ERR_PTR(-EPROBE_DEFER);
> +	/* 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 to_typec_mux_dev(dev);
>  }
>  
>  /**
> @@ -318,7 +330,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.53.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2026-08-24 12:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-22  7:24 [PATCH] usb: typec: mux: avoid duplicated mux switches Marek Vasut
2026-08-22  7:47 ` Jens Glathe
2026-08-22  8:06   ` Marek Vasut
2026-08-24 12:18   ` Sebastian Reichel
2026-08-24 12:01 ` Heikki Krogerus
2026-08-24 12:30 ` Sebastian Reichel

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

all inboxes | Powered by JetHome®