mbox series

[v1,0/3] usb: typec: USB Modes

Message ID 20241004140440.1882311-1-heikki.krogerus@linux.intel.com
Headers show
Series usb: typec: USB Modes | expand

Message

Heikki Krogerus Oct. 4, 2024, 2:04 p.m. UTC
Hi,

This was originally a proposal of mine that I posted back in 2019 as
an RFC [1].

The goal is to expose the USB Mode - USB Mode as defined in the USB
Type-C and USB Power Delivery specifications - to the user via sysfs.

With ports the mode will show the supported and the default USB Mode,
which is the mode that is (or should be) used in the next Enter_USB
Message.

With the partners the mode will show similarly the supported USB
modes, and also the active mode. Changing the active mode should cause
Data Reset (as described in the USB Power Delivery spec.). This should
happen even if there is no active USB Mode (in Alternate Mode).

I've modified the original RFC patches based on comments I've received
(offline). The major change is that I renamed the sysfs attribute file
for the port from "usb_mode" to "usb_capability".

I'm taking the USB mode in use in the UCSI driver with these, but I
did not add support for the "Set USB" UCSI command yet. I have no way
of testing it. Also, I don't really like that we have to construct the
Enter_USB Message from the abstracted information that UCSI supplies.
The interface should supply the Enter_USB Message that was used as is.

[1] https://lore.kernel.org/linux-usb/20191230152857.43917-1-heikki.krogerus@linux.intel.com/

Heikki Krogerus (4):
  usb: typec: Add attribute file showing the supported USB modes of the
    port
  usb: typec: Add attribute file showing the USB Modes of the partner
  usb: typec: ucsi: Supply the USB capabilities to the ports
  usb: typec: ucsi: Add support for the partner USB Modes

 Documentation/ABI/testing/sysfs-class-typec |  27 +++
 drivers/usb/typec/class.c                   | 204 +++++++++++++++++++-
 drivers/usb/typec/class.h                   |   3 +
 drivers/usb/typec/ucsi/ucsi.c               |  16 ++
 drivers/usb/typec/ucsi/ucsi.h               |  10 +
 include/linux/usb/typec.h                   |  22 +++
 6 files changed, 278 insertions(+), 4 deletions(-)

Comments

Dmitry Baryshkov Oct. 6, 2024, 4:35 p.m. UTC | #1
On Fri, Oct 04, 2024 at 05:04:36PM GMT, Heikki Krogerus wrote:
> This attribute file, named "usb_capability", will show the
> supported USB modes, which are USB 2.0, USB 3.2 and USB4.
> These modes are defined in the USB Type-C (R2.0) and USB
> Power Delivery (R3.0 V2.0) Specifications.
> 
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
>  Documentation/ABI/testing/sysfs-class-typec | 13 ++++
>  drivers/usb/typec/class.c                   | 81 +++++++++++++++++++++
>  drivers/usb/typec/class.h                   |  1 +
>  include/linux/usb/typec.h                   | 17 +++++
>  4 files changed, 112 insertions(+)
> 

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Tested-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org> # SM8450-HDK
Dmitry Baryshkov Oct. 6, 2024, 4:36 p.m. UTC | #2
On Fri, Oct 04, 2024 at 05:04:38PM GMT, Heikki Krogerus wrote:
> The USB capabilities can be extracted from the response to
> the Get Connector Capability command. USB2 and USB3 support
> can be checked from the Operation Mode field, and USB4
> support from the Extended Operation Mode field.
> 
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
>  drivers/usb/typec/ucsi/ucsi.c | 7 +++++++
>  drivers/usb/typec/ucsi/ucsi.h | 8 ++++++++
>  2 files changed, 15 insertions(+)
> 

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Tested-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org> # SM8450-HDK