From: Benson Leung <bleung@google.com>
To: Andrei Kuchynski <akuchynski@chromium.org>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Benson Leung <bleung@chromium.org>,
Jameson Thies <jthies@google.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/3] usb: typec: Add helper to check cable altmode support
Date: Fri, 26 Jun 2026 18:34:45 +0000 [thread overview]
Message-ID: <aj7GRSeN1UrvtGdc@google.com> (raw)
In-Reply-To: <20260626142702.1941182-2-akuchynski@chromium.org>
[-- Attachment #1: Type: text/plain, Size: 4378 bytes --]
On Fri, Jun 26, 2026 at 02:27:00PM +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:
> - cables lacking an identity header
> - passive cables with USB 2.0 speed
> - active cables unless they have corresponding plugs
>
> The function returns false if the cable is not registered or the identifier
> is not set.
>
> Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Signed-off-by: Andrei Kuchynski <akuchynski@chromium.org>
Reviewed-by: Benson Leung <bleung@chromium.org>
> ---
> Changes in V3:
> - Extracted core verification logic into a static helper function
> - Added an enum to handle supported, unsupported, and unknown cable states
>
> drivers/usb/typec/class.c | 71 +++++++++++++++++++++++++++++++++++++++
> include/linux/usb/typec.h | 1 +
> 2 files changed, 72 insertions(+)
>
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 0977581ad1b6e..e9f34eb14ceff 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -1429,6 +1429,77 @@ int typec_cable_is_active(struct typec_cable *cable)
> }
> EXPORT_SYMBOL_GPL(typec_cable_is_active);
>
> +enum typec_cable_altmode_support {
> + CABLE_SUPPORT_UNKNOWN,
> + CABLE_SUPPORTED,
> + CABLE_NOT_SUPPORTED,
> +};
> +
> +static enum typec_cable_altmode_support
> +typec_cable_check_altmode_support(struct typec_cable *cable,
> + struct typec_altmode *alt)
> +{
> + struct typec_altmode *plug;
> + u32 speed;
> +
> + /*
> + * Check if the cable has an e-marker, supports modal operation, and the
> + * SOP' altmode nodes are created.
> + */
> + plug = typec_altmode_get_plug(alt, TYPEC_PLUG_SOP_P);
> + if (plug) {
> + typec_altmode_put_plug(plug);
> + return CABLE_SUPPORTED;
> + }
> +
> + /* The identity is not specified */
> + if (!cable->identity)
> + return CABLE_SUPPORT_UNKNOWN;
> +
> + /* Non-e-marked cable */
> + if (!cable->identity->id_header)
> + return CABLE_NOT_SUPPORTED;
> +
> + switch (PD_IDH_PTYPE(cable->identity->id_header)) {
> + case IDH_PTYPE_PCABLE:
> + speed = VDO_TYPEC_CABLE_SPEED(cable->identity->vdo[0]);
> + if (speed == CABLE_USB2_ONLY)
> + return CABLE_NOT_SUPPORTED;
> + return CABLE_SUPPORTED;
> + case IDH_PTYPE_ACABLE:
> + /*
> + * Active cables must establish an SOP' communication
> + * node. Since that check failed at the beginning of
> + * this function, this active cable does not support
> + * this specific altmode.
> + */
> + return CABLE_NOT_SUPPORTED;
> + }
> +
> + return CABLE_SUPPORT_UNKNOWN;
> +}
> +
> +/**
> + * 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)
> +{
> + enum typec_cable_altmode_support support = CABLE_SUPPORT_UNKNOWN;
> + struct typec_cable *cable;
> +
> + cable = typec_cable_get(typec_altmode2port(alt));
> + if (cable) {
> + support = typec_cable_check_altmode_support(cable, alt);
> + typec_cable_put(cable);
> + }
> +
> + return support == CABLE_NOT_SUPPORTED;
> +}
> +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.55.0.rc0.799.gd6f94ed593-goog
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-06-26 18:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-26 14:26 [PATCH v3 0/3] Restrict alternate modes based on cable capabilities Andrei Kuchynski
2026-06-26 14:27 ` [PATCH v3 1/3] usb: typec: Add helper to check cable altmode support Andrei Kuchynski
2026-06-26 18:34 ` Benson Leung [this message]
2026-06-26 14:27 ` [PATCH v3 2/3] usb: typec: thunderbolt: Check " Andrei Kuchynski
2026-06-26 14:27 ` [PATCH v3 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=aj7GRSeN1UrvtGdc@google.com \
--to=bleung@google.com \
--cc=akuchynski@chromium.org \
--cc=bleung@chromium.org \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=jthies@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox