From nobody Tue Feb 10 01:59:30 2026 Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) (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 2CC5F3904C0 for ; Tue, 13 Jan 2026 13:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.65 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309568; cv=none; b=FcODHN7PkBIK4p2c/0leDq3av6gylG7AJGao0oFMQ0QY7lRnjGMF7HLqohNBb0GHwSxxgn5WTy5oIkxchfUu/TSD2BlWVy2EJVD/9ZIFgTUInOQy2mF6dUhCGoi96aybzp1Su5TtiHK6vgt3dJ4C7rbHIZPZH6N58e2IIrf3Ico= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309568; c=relaxed/simple; bh=6hB4iSeTY2hzXYn/hNKQEX6mOmgcsDLZ9qXbHlBnfpY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FnCwJ1rvClFGJ1rVK95wk6u2X76/3nhvrpcV3MuTwcoUJgsyxt3QYjD1M4R4SEihymXDfOYbdZcBW0j/RjvvN4x9ycLjRR/KTkH/sCF7w0NPM51Jfms7H1fZSJZ3TtPDh0fcqoLw9hicLlo13IN7ZWWBh8HDvRVa/ytmDqPSNJY= 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=FS7YHlSR; arc=none smtp.client-ip=209.85.218.65 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="FS7YHlSR" Received: by mail-ej1-f65.google.com with SMTP id a640c23a62f3a-b7cf4a975d2so1268428766b.2 for ; Tue, 13 Jan 2026 05:06:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1768309558; x=1768914358; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eS7Tohll2AatkB2QR0zQdrnu+HLuQcgbP0c4r4Qs4pE=; b=FS7YHlSRHAyhRgjZXAF6hl8ctVeleFFidIDy0fMFA2cr0mc8wHWziSsJ9faVsyBQQW EDmEmMUodrTdtFX67/Guxk/24bLLPmUFscwlMEstuq/r0BwnvmZ7QKR6QZ6lawgDISUM ZFwW3Xh7ZP2VCFCxIIzZZDT7FAaAL3opzX8I0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768309558; x=1768914358; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=eS7Tohll2AatkB2QR0zQdrnu+HLuQcgbP0c4r4Qs4pE=; b=LeYt3XGqNE3sVbo6qwpv/ezgrJrL8st2+WPCWSR61+fhxF8klsISXtMPIUB2KfQhKF WRCIiZpimCL9wKtUkPaBTrhrdXP1xec52qXL4Svm34dN4gcIqHkTIUfj0X28xEKnEf/q 6tNO+FbIYnrKDfMZSSzPePnoj3DvHvsxOfp5kagFIi7njfkH5tKno0xsEbqAlkLkUfZj xCAWLuSBbfuoWJ/0sdJ9ndKMhf911LrlNQOE3Yl2nVZlQEi2GfVhk0JvNmZtrNcXtSwh 53X5jfJzBa+gsFJcB1IvxIUyY9p3VrSjey3wN51TKpr2jVpzkiH0w0prHb2TG2+xKBQo mEog== X-Forwarded-Encrypted: i=1; AJvYcCWDB3MmR1rA+uQ5xhtxa8wGzecB6OzIG4W98N+pGmSbx25umW2xH9PCN1TLDx+jOLUbo2RbhBXdiZ1L7HY=@vger.kernel.org X-Gm-Message-State: AOJu0YyOsQxjWW1X/EWhoQUKY4zHUAyaksdwzQ60U7r6R0FIkujBC1hw q8T1VRmlIfQFYe7klO48EFoW1GMI/tbT8Zwax/LVma6YWXivvPefyHVm0YuA5IDXqA== X-Gm-Gg: AY/fxX4D71EF87uZnqgJsNKWR1zisD4n74WRKF8R1hw3djH/OFQ/C1Xspz+zmZAH6Rk yzRJO0A48QDaRXCY94nnom3cSaG/5LjHiR+D/1z3FdiaZ8cOt8/r9gJ6kmjh720+MG35DcpIBUj YmUapF303D1m3E9MJQtcZV3DYAdrVhz6gqUGGZ4i4Edqe/O5xqdjgKTHaSxWYN1n03JznS+t68r iN5IEiOTYVvrxa6hpOMfSBN+nO5Q/hVb06vL4QaVTBi3QrKr+vN7oBmT5q22aAfGRSac1OFOzAa 2cYL/MWb7sqjvVSnNHK29ye0AUVjQ2AxOu3X7qL9A9NTq3bQ/W8PruxilDHei0jWjuWl/FXrFyY ywVlI72kGgT6xqDXkCZTSUr4dOeXWxT0rMjgqr1N1aBD1PMCPUvhWdKpgVBst3hQhYTrjznhNkm CbJJIGKNWghMYXzSRMgCZJty3wh3ADCsq8GBtHHliujckBhelTF67hGAZfLoATbLJ/7WwsEele4 LsIm7XV X-Google-Smtp-Source: AGHT+IEWEpGJiEQBgSnQWIA4jUcOfUJbtgXrpOmBZHg9hM//JfV9vU4aw1fOZirNoGXoiYkOTCOCwg== X-Received: by 2002:a17:907:e110:b0:b87:5433:9067 with SMTP id a640c23a62f3a-b8754339594mr23487366b.29.1768309558272; Tue, 13 Jan 2026 05:05:58 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jan 2026 05:05:57 -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 7/8] usb: typec: ucsi: Support mode selection to activate altmodes Date: Tue, 13 Jan 2026 13:05:35 +0000 Message-ID: <20260113130536.3068311-8-akuchynski@chromium.org> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog In-Reply-To: <20260113130536.3068311-1-akuchynski@chromium.org> References: <20260113130536.3068311-1-akuchynski@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If the ucsi port driver supports modes selection, it should implement `add_partner_altmodes` and `remove_partner_altmodes` ucsi operations. With these operations the driver can manage the mode selection process. Once partner altmodes are registered, `add_partner_altmodes` is called to start the mode selection. When the partner is unregistered, `remove_partner_altmodes` is supposed to stop any ongoing processes and clean up the resources. `typec_altmode_state_update` informes mode selection about the current mode of the Type-C connector. Signed-off-by: Andrei Kuchynski --- drivers/usb/typec/ucsi/ucsi.c | 11 +++++++++++ drivers/usb/typec/ucsi/ucsi.h | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index deb210c066cb5..4a6e23b55b10c 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -314,6 +314,7 @@ void ucsi_altmode_update_active(struct ucsi_connector *= con) { const struct typec_altmode *altmode =3D NULL; u64 command; + u16 svid =3D 0; int ret; u8 cur; int i; @@ -335,6 +336,10 @@ void ucsi_altmode_update_active(struct ucsi_connector = *con) for (i =3D 0; con->partner_altmode[i]; i++) typec_altmode_update_active(con->partner_altmode[i], con->partner_altmode[i] =3D=3D altmode); + + if (altmode) + svid =3D altmode->svid; + typec_altmode_state_update(con->partner, svid, 0); } =20 static int ucsi_altmode_next_mode(struct typec_altmode **alt, u16 svid) @@ -609,6 +614,8 @@ static int ucsi_register_altmodes(struct ucsi_connector= *con, u8 recipient) desc.vdo =3D alt[j].mid; desc.svid =3D alt[j].svid; desc.roles =3D TYPEC_PORT_DRD; + desc.mode_selection =3D con->ucsi->ops->add_partner_altmodes && + con->ucsi->cap.features & UCSI_CAP_ALT_MODE_OVERRIDE; =20 ret =3D ucsi_register_altmode(con, &desc, recipient); if (ret) @@ -831,6 +838,8 @@ static int ucsi_check_altmodes(struct ucsi_connector *c= on) if (con->partner_altmode[0]) { num_partner_am =3D ucsi_get_num_altmode(con->partner_altmode); typec_partner_set_num_altmodes(con->partner, num_partner_am); + if (con->ucsi->ops->add_partner_altmodes) + con->ucsi->ops->add_partner_altmodes(con); ucsi_altmode_update_active(con); return 0; } else { @@ -1119,6 +1128,8 @@ static void ucsi_unregister_partner(struct ucsi_conne= ctor *con) return; =20 typec_set_mode(con->port, TYPEC_STATE_SAFE); + if (con->ucsi->ops->remove_partner_altmodes) + con->ucsi->ops->remove_partner_altmodes(con); =20 typec_partner_set_usb_power_delivery(con->partner, NULL); ucsi_unregister_partner_pdos(con); diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 410389ef173ab..4797b4aa1e35b 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -70,6 +70,8 @@ struct dentry; * @update_altmodes: Squashes duplicate DP altmodes * @update_connector: Update connector capabilities before registering * @connector_status: Updates connector status, called holding connector l= ock + * @add_partner_altmodes: Start mode selection + * @remove_partner_altmodes: Clean mode selection * * Read and write routines for UCSI interface. @sync_write must wait for t= he * Command Completion Event from the PPM before returning, and @async_writ= e must @@ -88,6 +90,8 @@ struct ucsi_operations { struct ucsi_altmode *updated); void (*update_connector)(struct ucsi_connector *con); void (*connector_status)(struct ucsi_connector *con); + void (*add_partner_altmodes)(struct ucsi_connector *con); + void (*remove_partner_altmodes)(struct ucsi_connector *con); }; =20 struct ucsi *ucsi_create(struct device *dev, const struct ucsi_operations = *ops); --=20 2.52.0.457.g6b5491de43-goog