From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Andrei Kuchynski <akuchynski@chromium.org>
Cc: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>,
Benson Leung <bleung@chromium.org>,
Jameson Thies <jthies@google.com>,
Tzung-Bi Shih <tzungbi@kernel.org>,
linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev,
Guenter Roeck <groeck@chromium.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>,
"Christian A. Ehrhardt" <lk@c--e.de>,
Venkat Jayaraman <venkat.jayaraman@intel.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 5/5] usb: typec: Expose alternate mode priority via sysfs
Date: Thu, 21 Aug 2025 10:36:25 +0300 [thread overview]
Message-ID: <aKbMeSCHf-ZhbcvT@kuha.fi.intel.com> (raw)
In-Reply-To: <20250814184455.723170-6-akuchynski@chromium.org>
Hi Andrei,
On Thu, Aug 14, 2025 at 06:44:55PM +0000, Andrei Kuchynski wrote:
> This patch introduces a priority sysfs attribute to the USB Type-C
> alternate mode port interface. This new attribute allows user-space to
> configure the numeric priority of alternate modes managing their preferred
> order of operation.
>
> Signed-off-by: Andrei Kuchynski <akuchynski@chromium.org>
> ---
> Documentation/ABI/testing/sysfs-class-typec | 12 ++++++
> drivers/usb/typec/class.c | 47 ++++++++++++++++++++-
> 2 files changed, 58 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec
> index 38e101c17a00..001202d651fa 100644
> --- a/Documentation/ABI/testing/sysfs-class-typec
> +++ b/Documentation/ABI/testing/sysfs-class-typec
> @@ -162,6 +162,18 @@ Description: Lists the supported USB Modes. The default USB mode that is used
> - usb3 (USB 3.2)
> - usb4 (USB4)
>
> + What: /sys/class/typec/<port>/<alt-mode>/priority
> +Date: July 2025
> +Contact: Andrei Kuchynski <akuchynski@chromium.org>
> +Description:
> + Displays and allows setting the priority for a specific alt-mode.
> + When read, it shows the current integer priority value. Lower numerical
> + values indicate higher priority (0 is the highest priority).
> + If the new value is already in use by another mode, the priority of the
> + conflicting mode and any subsequent modes will be incremented until they
> + are all unique.
> + This attribute is visible only if the kernel supports mode selection.
I was expecting this to be already used in this series.
IMO this file should be the only thing the user space needs to use by
default at least.
> USB Type-C partner devices (eg. /sys/class/typec/port0-partner/)
>
> What: /sys/class/typec/<port>-partner/accessory_mode
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index a72325ff099a..708f3487222a 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -19,6 +19,7 @@
> #include "bus.h"
> #include "class.h"
> #include "pd.h"
> +#include "mode_selection.h"
>
> static DEFINE_IDA(typec_index_ida);
>
> @@ -445,11 +446,41 @@ svid_show(struct device *dev, struct device_attribute *attr, char *buf)
> }
> static DEVICE_ATTR_RO(svid);
>
> +static ssize_t priority_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t size)
> +{
> + unsigned int val;
> + int err = kstrtouint(buf, 10, &val);
> +
> + if (!err) {
> + err = typec_mode_set_priority(to_typec_altmode(dev), val);
> + if (!err)
> + return size;
> + }
> +
> + return err;
> +}
> +
> +static ssize_t priority_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + int val;
> + const int err = typec_mode_get_priority(to_typec_altmode(dev), &val);
> +
> + if (err)
> + return err;
> +
> + return sprintf(buf, "%d\n", val);
> +}
> +static DEVICE_ATTR_RW(priority);
> +
> static struct attribute *typec_altmode_attrs[] = {
> &dev_attr_active.attr,
> &dev_attr_mode.attr,
> &dev_attr_svid.attr,
> &dev_attr_vdo.attr,
> + &dev_attr_priority.attr,
> NULL
> };
>
> @@ -458,7 +489,7 @@ static umode_t typec_altmode_attr_is_visible(struct kobject *kobj,
> {
> struct typec_altmode *adev = to_typec_altmode(kobj_to_dev(kobj));
>
> - if (attr == &dev_attr_active.attr)
> + if (attr == &dev_attr_active.attr) {
> if (!is_typec_port(adev->dev.parent)) {
> struct typec_partner *partner =
> to_typec_partner(adev->dev.parent);
> @@ -469,6 +500,15 @@ static umode_t typec_altmode_attr_is_visible(struct kobject *kobj,
> !adev->ops->activate)
> return 0444;
> }
> + } else if (attr == &dev_attr_priority.attr) {
> + if (is_typec_port(adev->dev.parent)) {
> + struct typec_port *port = to_typec_port(adev->dev.parent);
> +
> + if (!port->alt_mode_override)
> + return 0;
> + } else
> + return 0;
> + }
If we have the local port variable, this should be enough:
if (!is_typec_port(adev->dev.parent) || !port->alt_mode_override)
return 0;
> return attr->mode;
> }
> @@ -2029,6 +2069,7 @@ static void typec_release(struct device *dev)
> typec_mux_put(port->mux);
> typec_retimer_put(port->retimer);
> kfree(port->cap);
> + typec_mode_selection_destroy(port);
> kfree(port);
> }
>
> @@ -2496,6 +2537,8 @@ typec_port_register_altmode(struct typec_port *port,
> to_altmode(adev)->retimer = retimer;
> }
>
> + typec_mode_set_priority(adev, -1);
This really should not be necessary. Why can't we set the priority
based on the order the drives registers the altmodes for the port?
> return adev;
> }
> EXPORT_SYMBOL_GPL(typec_port_register_altmode);
> @@ -2645,6 +2688,8 @@ struct typec_port *typec_register_port(struct device *parent,
> port->con.attach = typec_partner_attach;
> port->con.deattach = typec_partner_deattach;
>
> + INIT_LIST_HEAD(&port->mode_list);
> +
> if (cap->usb_capability & USB_CAPABILITY_USB4)
> port->usb_mode = USB_MODE_USB4;
> else if (cap->usb_capability & USB_CAPABILITY_USB3)
thanks,
--
heikki
next prev parent reply other threads:[~2025-08-21 7:36 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-14 18:44 [PATCH v1 0/5] USB Type-C alternate mode priorities Andrei Kuchynski
2025-08-14 18:44 ` [PATCH v1 1/5] usb: typec: Add alt_mode_override field to port property Andrei Kuchynski
2025-08-20 10:53 ` Heikki Krogerus
2025-08-21 14:19 ` Andrei Kuchynski
2025-08-14 18:44 ` [PATCH v1 2/5] platform/chrome: cros_ec_typec: Set alt_mode_override flag Andrei Kuchynski
2025-08-14 18:44 ` [PATCH v1 3/5] usb: typec: ucsi: " Andrei Kuchynski
2025-08-20 10:53 ` Heikki Krogerus
2025-08-14 18:44 ` [PATCH v1 4/5] usb: typec: Implement alternate mode priority handling Andrei Kuchynski
2025-08-21 10:09 ` Heikki Krogerus
2025-08-21 11:14 ` Heikki Krogerus
2025-08-22 12:52 ` Andrei Kuchynski
2025-08-14 18:44 ` [PATCH v1 5/5] usb: typec: Expose alternate mode priority via sysfs Andrei Kuchynski
2025-08-21 7:36 ` Heikki Krogerus [this message]
2025-08-21 14:44 ` 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=aKbMeSCHf-ZhbcvT@kuha.fi.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=abhishekpandit@chromium.org \
--cc=akuchynski@chromium.org \
--cc=bleung@chromium.org \
--cc=chrome-platform@lists.linux.dev \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=gregkh@linuxfoundation.org \
--cc=groeck@chromium.org \
--cc=jthies@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=lk@c--e.de \
--cc=tzungbi@kernel.org \
--cc=venkat.jayaraman@intel.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.