|
|
Log in / Subscribe / Register

USB Type-C mode selection

From:  Andrei Kuchynski <akuchynski-AT-chromium.org>
To:  Heikki Krogerus <heikki.krogerus-AT-linux.intel.com>, Abhishek Pandit-Subedi <abhishekpandit-AT-chromium.org>, Benson Leung <bleung-AT-chromium.org>, Jameson Thies <jthies-AT-google.com>, linux-usb-AT-vger.kernel.org, linux-kernel-AT-vger.kernel.org, chrome-platform-AT-lists.linux.dev
Subject:  [PATCH v4 0/8] USB Type-C mode selection
Date:  Tue, 13 Jan 2026 13:05:28 +0000
Message-ID:  <20260113130536.3068311-1-akuchynski@chromium.org>
Cc:  Tzung-Bi Shih <tzungbi-AT-kernel.org>, Guenter Roeck <groeck-AT-chromium.org>, Greg Kroah-Hartman <gregkh-AT-linuxfoundation.org>, Dmitry Baryshkov <dmitry.baryshkov-AT-oss.qualcomm.com>, Ɓukasz Bartosik <ukaszb-AT-chromium.org>, Abel Vesa <abel.vesa-AT-linaro.org>, Pooja Katiyar <pooja.katiyar-AT-intel.com>, Johan Hovold <johan-AT-kernel.org>, Hsin-Te Yuan <yuanhsinte-AT-chromium.org>, Madhu M <madhu.m-AT-intel.com>, Venkat Jayaraman <venkat.jayaraman-AT-intel.com>, Andrei Kuchynski <akuchynski-AT-chromium.org>
Archive-link:  Article

This patch series introduces functionality to the USB Type-C Alternate Mode
negotiation process by implementing a priority-based selection mechanism.

Currently, DisplayPort and Thunderbolt drivers initiate a mode entry
separately within their respective probe functions. The Power Delivery
Controller (PDC) retains the ability to activate either USB4 mode or
Alternate Modes based on its internal policy.
The mode selection mechanism disables Alternate Modes to be entered by
their respective drivers and the PDC. Instead, a priority-ordered approach
is used to activate the most desirable mode.

A new `priority` field is added to the `typec_altmode` structure to store
a numerical priority value, with all priorities being unique.
If the port driver supports the mode selection feature, it must set the
`mode_selection` boolean field within the `typec_altmode` structure. This
indicates to the alternate mode drivers that they are not to activate the
altmode separately.

The mode selection process is managed by three API functions:
- `typec_mode_selection_start`
- `typec_altmode_state_update`
- `typec_mode_selection_delete`

When a partner device is connected, the `typec_mode_selection_start`
function executes the following steps:
- It compiles a priority-ordered list of Alternate Modes that are mutually
supported by both the port and the partner.
- A dedicated mode selection task is subsequently initiated on the Work
Queue.
- This task attempts to activate a mode by starting with the
highest-priority altmode on the list. Alternate modes are identified with
their SVIDs. Activation/Deactivation performed via `activate` typec_altmode
operation. The process stops as soon as a mode is successfully entered.
Otherwise, after a timeout or if an error occurs, the next alternative mode
will be activated.

The `typec_altmode_state_update` function is invoked by the port driver to
communicate the current mode of the Type-C connector.

The `typec_mode_selection_delete` function is responsible for stopping the
currently running mode selection process and releasing all associated
system resources.

Mode selection is initiated only once during partner registration, and only
if the port driver provides support for this feature. Subsequent
mode-switching activities can be managed via existing sysfs entries. Any
modifications to altmode priorities are relevant only to future
connections.

This series is based on the RFC discussed here -
https://lore.kernel.org/all/20251201122604.1268071-1-akuc...
It incorporates the 'v5 USB Type-C alternate mode priorities' patches,
reflecting the change of the is_typec_altmode macro to
is_typec_port_altmode -
https://lore.kernel.org/all/20251124124639.1101335-1-akuc...

This series was tested on an Android OS device with kernel 6.19.0-rc4,
PDC: TI TPS6699, Realtek RTS5453.

Andrei Kuchynski (8):
  usb: typec: Add mode_control field to port property
  platform/chrome: cros_ec_typec: Set no_mode_control flag
  usb: typec: ucsi: Set no_mode_control flag
  usb: typec: Expose alternate mode priority via sysfs
  usb: typec: Implement mode selection
  usb: typec: Introduce mode_selection bit
  usb: typec: ucsi: Support mode selection to activate altmodes
  usb: typec: ucsi: Enforce mode selection for cros_ec_ucsi

 Documentation/ABI/testing/sysfs-class-typec |  11 +
 drivers/platform/chrome/cros_ec_typec.c     |   1 +
 drivers/usb/typec/Makefile                  |   2 +-
 drivers/usb/typec/altmodes/displayport.c    |   6 +-
 drivers/usb/typec/altmodes/thunderbolt.c    |   2 +-
 drivers/usb/typec/class.c                   | 100 ++++++-
 drivers/usb/typec/class.h                   |   3 +
 drivers/usb/typec/mode_selection.c          | 288 ++++++++++++++++++++
 drivers/usb/typec/ucsi/cros_ec_ucsi.c       |  21 ++
 drivers/usb/typec/ucsi/ucsi.c               |  12 +
 drivers/usb/typec/ucsi/ucsi.h               |   4 +
 include/linux/usb/typec.h                   |   3 +
 include/linux/usb/typec_altmode.h           |  42 +++
 13 files changed, 487 insertions(+), 8 deletions(-)
 create mode 100644 drivers/usb/typec/mode_selection.c

-- 
2.52.0.457.g6b5491de43-goog




Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds