From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 46C9016DEB0 for ; Tue, 13 Jan 2026 13:05:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309544; cv=none; b=kP6FXuSB7BpAw+XbMFmbtQUz21wzTvYaGMNNxj8yP5kSsFI5m/Waw04cyxicIuHuCdoUB1oyKFgKaf9uOnVfOHHU9A504hc9l13cNqTVp1o8DzIOD0P7TA2Zs0i7gX14+nNAn6Fl+RR5eTw05wdJvVF9LTb8oZgoILYJaPFWvCA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309544; c=relaxed/simple; bh=fwUzfC2xTG6i2MQ2ip8x5FilPTF7hu2g+bnWM4R+rkQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=h/vzpxxSwTOme7pT/dyo+Ef9j2FN4O9bicmb3jrtSu0tJb+m4i9FgV8MA8xv7lvhSHRhGTvKYxoBjQPb6NSDQT1LpC5MkkPY9/yHEThBlO0AffVOgaLh+HWtZKg9P78FSUBlWjrizxu/kJ6DTZW1vR0Nsi3vfPjUSGbhcKlMTKw= 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=AG9CYmkz; arc=none smtp.client-ip=209.85.208.49 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="AG9CYmkz" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-64b8123c333so11965505a12.3 for ; Tue, 13 Jan 2026 05:05:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1768309542; x=1768914342; 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=dlFZOR9bPvQSMDUQEj/b/JXXSikTf4KnUZzPY79O4dk=; b=AG9CYmkzU+wdqkYowj/oxjmQUI2uIokWqY3+V/KCV3WMqE+YtFxyGiHTy4ZlRJp5c7 2BzTmejoGgCDmQ4zOKA5UYJsveTRueDewgsuxgr4hupjPFT95M6/Xo04CUGzpjcqaoAW 78QA7NFeESlAjriRiKjbAPWG8YRRUy1viNnog= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768309542; x=1768914342; 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=dlFZOR9bPvQSMDUQEj/b/JXXSikTf4KnUZzPY79O4dk=; b=Mlpsn6R4TbtqIfDQfyytNNAgvKIUrPQ/uU21oRwR9ELb7sCiASCe97b/GSVhU2teje d+X/aaeX6WuaVjqTd9Ak7Qz4YkttWpyo99jwt46RFbXwwwbSGA+FPWKd2HnfgDgfQFsC i76cV9DrMnP2yixoCufzz54vjF4XXnE1V7/hLY01JxC/BSvL57usIbX9ijbpryfxgAHz pSibT0l+s8bzBBj/mccV0s+ct3zvOnpmN2cM98ZUH92QiaFs62PYNeH8MvUBXybcRhYx C5J5uacbJ+HdEpST/f8uy6BXUW69Jw4V53W0PC9Re077TxAJhJfUR9Ds9n02k23LZCZZ yrBg== X-Forwarded-Encrypted: i=1; AJvYcCWHqVDgP/ovnG1MBSdCBR0Han+4HuSA2fyX5QzE9nu2kBg71TEwkdhnR2jw0GPX93DnCBxt4lsjGVjOEfY=@vger.kernel.org X-Gm-Message-State: AOJu0YxT8BuEjwbdL1v9qOvOCVh6RS8koCRJGzAcl37ueMUkMEVwiQYQ 50h2mHlvoJQQllU99ovmKObdeulKH0wZftGmTZliQ71MH4p4Q/xHUycQMSxcNBYVMQ== X-Gm-Gg: AY/fxX7xHFY2MbXQI+ktZZiv0fV0ty9d956wsl9ovNRqlt6H/gFvChbtQaAsfSUXBBW hfLgSW2cRbqWeE1F5Lj60I1GdcHQmZIWaKknRGJmOi2houOew8lkTt5C8iMKNu/7iIl6Ud3dK12 IklYznG5dRC43xAK88VFTATUyj1YW7SBrpLtCBfPVd2JoQoVZHdt+3dg+Pb0QeVy/wh7R4oxcD3 PEPElucra4vntH/8ritCoW7WG89rKkHYezIvg1ipKNMTVYATfosC0SPukbiC9ud94EziMFX3wJ+ U1Ax6x8DkXX7OA+BdZuNgXLxerUmVFrm+HHtVojJPjNVu7UWIUju6/BuxFz8Ny/dBM5QeVj6zsw XtWsi3ZJoA/oq1P28spAQl77B9GVowfEoFmwxIMOG7ocwEYOfAzygLlqBQGZfKiEJC9MA0dh+NB 1jk+SPX0zW/+o/KBojg5BcENSB+Zk0rrgJpvkqlpTkZDHtYrEjxfoq1OznQlrq9YgYwUyNyB4I5 YukUOti X-Google-Smtp-Source: AGHT+IGRI9YhixtELVuz80DZdKhv617FozvgQfzvl6i67vy1UXB7yEw95GJgE2A7sinO3f5EEbChAQ== X-Received: by 2002:a17:907:9727:b0:b87:6ce:1267 with SMTP id a640c23a62f3a-b8706ce1943mr751779966b.64.1768309541641; Tue, 13 Jan 2026 05:05:41 -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-b871b5e60dasm586217266b.63.2026.01.13.05.05.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jan 2026 05:05:40 -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?= , Abel Vesa , Pooja Katiyar , Johan Hovold , Hsin-Te Yuan , Madhu M , Venkat Jayaraman , Andrei Kuchynski 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> 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 is based on the RFC discussed here - https://lore.kernel.org/all/20251201122604.1268071-1-akuchynski@chromium.org/ 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-akuchynski@chromium.org/ 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