usb: typec: mux: avoid duplicated mux switches
Subsystems (3)
PATCH 1/1 usb: typec: mux: avoid duplicated mux switches
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() .
---
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Heikki Krogerus <[email protected]>
Cc: Jens Glathe <[email protected]>
Cc: Sebastian Reichel <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
- Extensive test by Jens https://lore.kernel.org/all/[email protected]/
--- drivers/usb/typec/mux.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/usb/typec/mux.c +15 -2
@@ -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 ) {
Signature · 1 line
2.53.0
Hi Marek,
Quoted 7 lines · Marek Vasut
This is a re-application of
b145c3f29d62("usb: typec: mux: avoid duplicated mux switches"), with fix derived from usb: typec: mux:
Fixtypec_switch_match().Fixes f576c75f95a5 ("Revert "usb: typec: mux: avoid duplicated mux switches"")- Extensive test by Jens https://lore.kernel.org/all/[email protected]/
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:
with best regards
Jens
On 8/22/26 9:47 AM, Jens Glathe wrote:
Hello Jens,
Quoted 9 lines · Marek Vasut
Quoted 8 lines
This is a re-application of
b145c3f29d62("usb: typec: mux: avoid duplicated mux switches"), with fix derived from usb: typec: mux:
Fixtypec_switch_match().Fixes f576c75f95a5 ("Revert "usb: typec: mux: avoid duplicated mux switches"")- Extensive test by Jens https://lore.kernel.org/
all/[email protected]/
Quoted 5 lines
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 <[email protected]>with best regards
Thank you !
Signature · 2 lines
Best regards, Marek Vasut
Hi,
Quoted 5 lines · Jens Glathe
Quoted 4 lines · Marek Vasut
This is a re-application of
b145c3f29d62("usb: typec: mux: avoid duplicated mux switches"), with fix derived from usb: typec: mux:
Fixtypec_switch_match().
Quoted 8 lines
Quoted 3 lines
Fixes f576c75f95a5 ("Revert "usb: typec: mux: avoid duplicated mux switches"")- Extensive test by Jens https://lore.kernel.org/all/[email protected]/
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 <[email protected]>
Thanks!
-- Sebastian
Quoted 10 lines · Marek Vasut
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:
Fixtypec_switch_match().
Quoted 5 lines
Fixes f576c75f95a5 ("Revert "usb: typec: mux: avoid duplicated mux switches"")Signed-off-by Sebastian Reichel <[email protected]>Co-developed-by Sebastian Reichel <[email protected]>Signed-off-by Marek Vasut <[email protected]>
Quoted 60 lines
---
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Heikki Krogerus <[email protected]>
Cc: Jens Glathe <[email protected]>
Cc: Sebastian Reichel <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
- Extensive test by Jens https://lore.kernel.org/all/[email protected]/--- drivers/usb/typec/mux.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)drivers/usb/typec/mux.c +15
-2@@ -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 ) {Signature · 1 line
2.53.0
Signature · 1 line
heikki
Hi,
Quoted 15 lines · Marek Vasut
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:
Fixtypec_switch_match().Fixes f576c75f95a5 ("Revert "usb: typec: mux: avoid duplicated mux switches"")Signed-off-by Sebastian Reichel <[email protected]>Co-developed-by Sebastian Reichel <[email protected]>Signed-off-by Marek Vasut <[email protected]>
Quoted 10 lines
---
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Heikki Krogerus <[email protected]>
Cc: Jens Glathe <[email protected]>
Cc: Sebastian Reichel <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
- Extensive test by Jens https://lore.kernel.org/all/[email protected]/
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/[email protected]/
Greetings,
-- Sebastian
Quoted 51 lines
--- drivers/usb/typec/mux.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)drivers/usb/typec/mux.c +15
-2@@ -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 ) {Signature · 1 line
2.53.0