All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Sebastian Reichel <sebastian.reichel@collabora.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-rockchip@lists.infradead.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel@collabora.com
Subject: Re: [PATCH 1/2] usb: typec: mux: avoid duplicated orientation switches
Date: Mon, 23 Feb 2026 16:54:44 +0200	[thread overview]
Message-ID: <aZxqNJCsUMaBlMmB@kuha> (raw)
In-Reply-To: <20260213-typec-mux-duplication-fix-v1-1-70076a7c5691@collabora.com>

Hi Sebastian,

Fri, Feb 13, 2026 at 08:23:28PM +0100, Sebastian Reichel wrote:
> 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 | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
> index 182c902c42f6..db35b7398343 100644
> --- a/drivers/usb/typec/mux.c
> +++ b/drivers/usb/typec/mux.c
> @@ -72,9 +72,9 @@ struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode)
>  {
>  	struct typec_switch_dev *sw_devs[TYPEC_MUX_MAX_DEVS];
>  	struct typec_switch *sw;
> +	int i, j, k;
>  	int count;
>  	int err;
> -	int i;
>  
>  	sw = kzalloc(sizeof(*sw), GFP_KERNEL);
>  	if (!sw)
> @@ -96,6 +96,18 @@ struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode)
>  		}
>  	}
>  
> +	/* eliminate duplicates */
> +	for (i = 0; i < count; i++) {
> +		for (j = i + 1; j < count; j++) {
> +			if (sw_devs[j] == sw_devs[i]) {
> +				put_device(&sw_devs[j]->dev);
> +				for (k = j; k < count; k++)
> +					sw_devs[k] = sw_devs[k+1];
> +				count--;
> +			}
> +		}
> +	}

I think that check could be done in typec_switch_match(). Just pass
that sw_devs to it as "data":

        -        count = fwnode_connection_find_matches(fwnode, "orientation-switch", NULL,
        +        count = fwnode_connection_find_matches(fwnode, "orientation-switch", sw_devs,

And then in typec_switch_match(), probable as the second last step:

         static void *typec_switch_match(const struct fwnode_handle *fwnode,
                                         const char *id, void *data)
         {
        +       struct typec_switch_dev *sw_devs = data;
        +       int i;
                ...
                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);
         }

thanks,

-- 
heikki

_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

WARNING: multiple messages have this Message-ID (diff)
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Sebastian Reichel <sebastian.reichel@collabora.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-rockchip@lists.infradead.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel@collabora.com
Subject: Re: [PATCH 1/2] usb: typec: mux: avoid duplicated orientation switches
Date: Mon, 23 Feb 2026 16:54:44 +0200	[thread overview]
Message-ID: <aZxqNJCsUMaBlMmB@kuha> (raw)
In-Reply-To: <20260213-typec-mux-duplication-fix-v1-1-70076a7c5691@collabora.com>

Hi Sebastian,

Fri, Feb 13, 2026 at 08:23:28PM +0100, Sebastian Reichel wrote:
> 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 | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
> index 182c902c42f6..db35b7398343 100644
> --- a/drivers/usb/typec/mux.c
> +++ b/drivers/usb/typec/mux.c
> @@ -72,9 +72,9 @@ struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode)
>  {
>  	struct typec_switch_dev *sw_devs[TYPEC_MUX_MAX_DEVS];
>  	struct typec_switch *sw;
> +	int i, j, k;
>  	int count;
>  	int err;
> -	int i;
>  
>  	sw = kzalloc(sizeof(*sw), GFP_KERNEL);
>  	if (!sw)
> @@ -96,6 +96,18 @@ struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode)
>  		}
>  	}
>  
> +	/* eliminate duplicates */
> +	for (i = 0; i < count; i++) {
> +		for (j = i + 1; j < count; j++) {
> +			if (sw_devs[j] == sw_devs[i]) {
> +				put_device(&sw_devs[j]->dev);
> +				for (k = j; k < count; k++)
> +					sw_devs[k] = sw_devs[k+1];
> +				count--;
> +			}
> +		}
> +	}

I think that check could be done in typec_switch_match(). Just pass
that sw_devs to it as "data":

        -        count = fwnode_connection_find_matches(fwnode, "orientation-switch", NULL,
        +        count = fwnode_connection_find_matches(fwnode, "orientation-switch", sw_devs,

And then in typec_switch_match(), probable as the second last step:

         static void *typec_switch_match(const struct fwnode_handle *fwnode,
                                         const char *id, void *data)
         {
        +       struct typec_switch_dev *sw_devs = data;
        +       int i;
                ...
                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);
         }

thanks,

-- 
heikki

  reply	other threads:[~2026-02-23 14:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-13 19:23 [PATCH 0/2] usb: typec: mux: avoid duplicated mux switches Sebastian Reichel
2026-02-13 19:23 ` Sebastian Reichel
2026-02-13 19:23 ` [PATCH 1/2] usb: typec: mux: avoid duplicated orientation switches Sebastian Reichel
2026-02-13 19:23   ` Sebastian Reichel
2026-02-23 14:54   ` Heikki Krogerus [this message]
2026-02-23 14:54     ` Heikki Krogerus
2026-02-13 19:23 ` [PATCH 2/2] usb: typec: mux: avoid duplicated mux switches Sebastian Reichel
2026-02-13 19:23   ` Sebastian Reichel
2026-02-23 15:02   ` Heikki Krogerus
2026-02-23 15:02     ` Heikki Krogerus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aZxqNJCsUMaBlMmB@kuha \
    --to=heikki.krogerus@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=sebastian.reichel@collabora.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.