From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2197235CB98 for ; Mon, 19 Jan 2026 13:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768828722; cv=none; b=ilSYAOgu2gybTf21NL077VLH0hsCDx9TTZPhFv9q+ZsKYyEZ74RBGiRZEexEnUEWTx4tT/jU38Aj0ed5wsg6ged/dIjWUTlZKUz3jTp1bGRNGDhmio35IDF8bzPTZu13c5mhmSqApJHVHjFN538hKrHgB+D+arOw0C/a5SOwjPc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768828722; c=relaxed/simple; bh=mMG+Hn8BawRbQWK4kLNveOLJbx1FyWTF834qhx1Dno0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=LAVcNYQIccwAlXpLbIHkGX+a3csEs1ptgniPxDGPIy3zhhRVCdnR7wG+ftN/JUIjHYDp5eeoRM+5qbUF2HvBwlcXja+doldzM7z0+wb55NSSmXrWLhpvhITWBt2eJ4fivaOqMdIGf/ElRE92DJ2FVTLSk3aAWnFVYyZWa8vBLsY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=WzNr7Ihm; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="WzNr7Ihm" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-65089cebdb4so6649579a12.0 for ; Mon, 19 Jan 2026 05:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1768828719; x=1769433519; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=iRNnwiYKOAp913PL4zbruan81hvYhlt0XTNkvMtBRB0=; b=WzNr7IhmcQK5+McPG6RHnx/pdx7R06tY9VxXUo24DDix2KaYqVecSJ1RFTCu96nPTr 9LuaqIR6pPaabX2MF1uJ1kDx3eWSYKIVRrpvfq01rv8WYoOWtOX1sU2GkIFC0WWnjFUL 0+2ASMxd1IaRc1woO4tAOdjoy03sDtEpk9gpU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768828719; x=1769433519; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=iRNnwiYKOAp913PL4zbruan81hvYhlt0XTNkvMtBRB0=; b=muHczMlvrBTo+q/ulznEFS1CJPhXfajpTARhMt975sMhXr11lJoOLNzDP1F8upme3s 7YzXQTA9PL7ZYfQSu3gLSlk7Lvoho6OmRlNRVRTltjvDOdkjIf7yJxhVn+Uv8OugMmx6 DlV9texj4LgIt+BgyaKrCm9lAgDR6RKNWGRtJkgDsdv3f0GOklzPAcSNYoF3C4mxmLhx ZgNUSv9sbAinf5e0y+unl26aeYyNKhBQktJJ3MtbuftvY2ia4hFSajQQ6tfqLm1SZLfD /h5m/qk3O6mronk861NELgq90NBOl8Q9FFy2ifenRH4KCVOSLQNJSDLwIIcoC/DlJiQ3 A/ig== X-Forwarded-Encrypted: i=1; AJvYcCWgiA5qvNrIfErvCIrha4a6bwcGrq8NTUur2ut3nIpEctd8EaHueQa6HtLY/TGl/HV8Ro1Ie3IzgLNwbqU=@vger.kernel.org X-Gm-Message-State: AOJu0YxczcAbY2CMm/Vl1XbvyFYkC0M+lQ0d+fELTtK7TNdFIZc/7lv5 SRG4BdW6yTRW2zgTxk4bQGaUU8QKQz9whFxQvLhFASTcbbH9yWeK8QOK6XpLthI8Tg== X-Gm-Gg: AY/fxX6keYUijO/5bjhzPwGW0cGlmHIqT+2vabaVzpnNkGpz5uH2cx7qyE4lMWACHNN O0NGuVfxksmtY2tUiN56Cga34OoILQVj5kwPrWqrYEkN6A2ivSy4UBF8nAmXyfIuzY5UFxEdxSC sDn8wXpu7NcEm6J/A8Y0A6TdISYwcBxf02lU9S9YmiJh9PIXJJPWNGBFdu/0XBbJr3pzXWsuKYt wsSMZBzp+qvQH3ReyqZfUduz6CDGOSsUxNzjf8SEo2tcZCH7m9hgCqXq+8Yo8KwoHOzCmjkXP4O O4geFXjQpOJowDFJFUq9jPtFGAYW/u6zod5vHxu2QLjAp6Xj5vdUawjUhaaLDA05+txQghbsgYS 5X2v4MZsMcXYNmH2B0Pmdd2eqcTj0Ba9BnUsT7xdL00HQUHm09qrWYxtZK72lN2Rmlt+f0qu+tk h+aUo457inQUWLGJMILNUqZO0pemP1Akk2F77SZbeY2E/BGmkcLDSM8Jx/44xr3g+C3BTBSDP75 M2EhkaO X-Received: by 2002:a17:906:f5a2:b0:b87:b87:cdbf with SMTP id a640c23a62f3a-b8796b85d1bmr942630166b.53.1768828719421; Mon, 19 Jan 2026 05:18:39 -0800 (PST) Received: from akuchynski.c.googlers.com.com (150.230.32.34.bc.googleusercontent.com. [34.32.230.150]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b87959c9a14sm1078801866b.45.2026.01.19.05.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jan 2026 05:18:38 -0800 (PST) From: Andrei Kuchynski To: Heikki Krogerus , Abhishek Pandit-Subedi , Benson Leung , Jameson Thies , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev Cc: Tzung-Bi Shih , Guenter Roeck , Greg Kroah-Hartman , Dmitry Baryshkov , =?UTF-8?q?=C5=81ukasz=20Bartosik?= , Pooja Katiyar , Johan Hovold , Hsin-Te Yuan , Madhu M , Venkat Jayaraman , Andrei Kuchynski Subject: [PATCH v5 0/7] USB Type-C mode selection Date: Mon, 19 Jan 2026 13:18:17 +0000 Message-ID: <20260119131824.2529334-1-akuchynski@chromium.org> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 was tested on an Android OS device with kernel 6.19.0-rc4, PDC: TI TPS6699, Realtek RTS5453. Changes in V5: - Use the no_mode_control field instead of con->ucsi->cap.features & UCSI_CAP_ALT_MODE_OVERRIDE - Squash previous V4 patches 3/8 and 7/8 into a single patch - Adopt guard(mutex)(&sel->lock) in mode_selection_work_fn() - Use dev_err instead of dev_dbg, remove the error message when exiting the mode - Update typec_altmode_state_update() to only reschedule the mode_selection_work_fn task if it was successfully cancelled - Clean up code style and alignment issues Andrei Kuchynski (7): usb: typec: Add mode_control field to port property platform/chrome: cros_ec_typec: 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 | 283 ++++++++++++++++++++ drivers/usb/typec/ucsi/cros_ec_ucsi.c | 22 ++ 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, 483 insertions(+), 8 deletions(-) create mode 100644 drivers/usb/typec/mode_selection.c -- 2.52.0.457.g6b5491de43-goog