From: Benson Leung <bleung@google.com>
To: Andrei Kuchynski <akuchynski@chromium.org>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 1/3] usb: typec: Add helper to check cable altmode support
Date: Thu, 11 Jun 2026 18:47:02 +0000 [thread overview]
Message-ID: <aisCpo9Zmdyo_ovx@google.com> (raw)
In-Reply-To: <20260611122146.262184-2-akuchynski@chromium.org>
[-- Attachment #1: Type: text/plain, Size: 4612 bytes --]
On Thu, Jun 11, 2026 at 12:21:44PM +0000, Andrei Kuchynski wrote:
> Introduce typec_cable_altmode_unsupported function to evaluate whether an
> alternate mode is restricted based on the connected cable's properties.
>
> Implement validation logic that parses the cable's identity to catch
> incompatible setups early. Alternate modes are restricted over:
I think I follow this logic, and it is correct, but it may be harder to
understand for a passing code observer who aren't deeply versed in how USB-C
cables work. I think maybe additional comments on each of these resolution
cases may be helpful.
> - cables lacking an identity header
Cable lacking an ID Header indicates a non-emarked cable, which in the case
of a detachable C-to-C cable, can only be guaranteed to have USB 2.0 data path
(D+ and D-).
> - passive cables with USB 2.0 speed
In this case, it's an affirmative confirmation from an e-marked cable
(ID Header present, rest of e-mark present), we are sure it's a USB 2.0-only
cable.
> - active cables unless they have corresponding plugs
This case is a little bit nuanced. The "corresponding plugs" means that this
cable has an e-marker, supports modal operation, and the SOP' alt mode nodes
are created. You're looking for a 1:1 match based on SVIDs that this cable
has support for the alt mode being queried here. If yes, then alt mode is
supported. If there's no match, then the alt mode is unsupported.
>
> The function returns false if the cable is not registered or the identifier
> is not set.
>
> Signed-off-by: Andrei Kuchynski <akuchynski@chromium.org>
> ---
> drivers/usb/typec/class.c | 35 +++++++++++++++++++++++++++++++++++
> include/linux/usb/typec.h | 1 +
> 2 files changed, 36 insertions(+)
>
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 0977581ad1b6e..f7f1adbaab7e6 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -1429,6 +1429,41 @@ int typec_cable_is_active(struct typec_cable *cable)
> }
> EXPORT_SYMBOL_GPL(typec_cable_is_active);
>
> +/**
> + * typec_cable_altmode_unsupported - Check if a cable restricts altmode
> + * @alt: The Alternate Mode to evaluate
> + *
> + * Returns true if the connected cable is incapable of handling the altmode.
> + */
> +bool typec_cable_altmode_unsupported(struct typec_altmode *alt)
> +{
> + struct typec_altmode *plug;
> + struct typec_cable *cable;
> + bool unsupported = false;
> +
> + plug = typec_altmode_get_plug(alt, TYPEC_PLUG_SOP_P);
> + if (plug) {
In this case, we have an affirmative match on alt mode
being queried, so the cable supports this alt mode, which is why you return
false, meaning alt mode is supported.
> + typec_altmode_put_plug(plug);
> + return false;
> + }
> +
Past this point, there is no SOP' alt mode object matching the alt mode.
The only way to return supported is if we find the cable is a passive cable
of at least USB3 Gen 1 or better speed.
> + cable = typec_cable_get(typec_altmode2port(alt));
> + if (cable && cable->identity) {
> + const u32 id_header = cable->identity->id_header;
> + const u32 speed = VDO_TYPEC_CABLE_SPEED(cable->identity->vdo[0]);
> +
> + if (!id_header || PD_IDH_PTYPE(id_header) == IDH_PTYPE_ACABLE)
> + unsupported = true;
> + else if (PD_IDH_PTYPE(id_header) == IDH_PTYPE_PCABLE)
> + unsupported = (speed == CABLE_USB2_ONLY);
This might be a little easier to follow if this was a switch statement on
PD_IDH_PTYPE(id_header) so the reader can see what different behavior is between
PCABLE and ACABLE.
> + }
> + if (cable)
> + typec_cable_put(cable);
> +
> + return unsupported;
> +}
> +EXPORT_SYMBOL_GPL(typec_cable_altmode_unsupported);
> +
> /**
> * typec_cable_set_identity - Report result from Discover Identity command
> * @cable: The cable updated identity values
> diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
> index d61ec38216fa9..10a783b738efd 100644
> --- a/include/linux/usb/typec.h
> +++ b/include/linux/usb/typec.h
> @@ -337,6 +337,7 @@ void typec_unregister_cable(struct typec_cable *cable);
> struct typec_cable *typec_cable_get(struct typec_port *port);
> void typec_cable_put(struct typec_cable *cable);
> int typec_cable_is_active(struct typec_cable *cable);
> +bool typec_cable_altmode_unsupported(struct typec_altmode *alt);
>
> struct typec_plug *typec_register_plug(struct typec_cable *cable,
> struct typec_plug_desc *desc);
> --
> 2.54.0.1099.g489fc7bff1-goog
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-06-11 18:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 12:21 [PATCH v1 0/3] Restrict alternate modes based on cable capabilities Andrei Kuchynski
2026-06-11 12:21 ` [PATCH v1 1/3] usb: typec: Add helper to check cable altmode support Andrei Kuchynski
2026-06-11 18:47 ` Benson Leung [this message]
2026-06-11 12:21 ` [PATCH v1 2/3] usb: typec: thunderbolt: Check " Andrei Kuchynski
2026-06-11 12:21 ` [PATCH v1 3/3] usb: typec: displayport: " Andrei Kuchynski
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=aisCpo9Zmdyo_ovx@google.com \
--to=bleung@google.com \
--cc=akuchynski@chromium.org \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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.