From nobody Mon Dec 1 22:03:18 2025 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (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 D982E30DEA5 for ; Mon, 1 Dec 2025 12:26:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764591985; cv=none; b=FJFsLQn7k1ogQ+kToCy7LSrvgZ8fVymSUpv07EUKkVFJ1EiH6JEhEpxhCvestyMEagzRIL7DyWyIsagZyCIP7mfSKZxyt9C+P7NneNN1MiUimz578/16wCQY62grZKQyJFomPghHN+2Auvs/etTlhBOjf8SzXSK28xkS00BGR9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764591985; c=relaxed/simple; bh=GLVgDEZR/yW+dPBnqZM2+KBG6I9egBK1BkHdtIV8Re0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ofnQ+KFR0DUWKLTvVqDY8mNecwD28iuYHnnFv6Qy2BujaYePSJ2TugAEPL+/5CYsLkzZEgTzjot32kaMEF2wXn9MuquDNjVAnP+a38nlEjQZO1apKVn3qvLuuC8AqQiAtPfK6/LvJ5Djrkuf/oU3CKJaSqQm6Nr1QYkvFEZ12WE= 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=PL6kwHBC; arc=none smtp.client-ip=209.85.208.44 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="PL6kwHBC" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-640a503fbe8so561467a12.1 for ; Mon, 01 Dec 2025 04:26:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1764591981; x=1765196781; 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=k5OrnZlcNOQDMQX5tOxuMnlnnAQiRlG+9PrDueeCn1s=; b=PL6kwHBCXaOG0GpyjSuR7vY3o72TK/qPdu4Vw7BpX/CxClIf2SLsfkMZB8d5sa80Cm XgY1fcfkuHn+QCihaVsVqQxKpYB4yTE5m86c/h/4J9Pm/EGtIzLCaPSlbE1iUpvJXn9j 8vkfiEQpeNWJ9p7bs7cnx91iYKJVX7jide8Zk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764591981; x=1765196781; 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=k5OrnZlcNOQDMQX5tOxuMnlnnAQiRlG+9PrDueeCn1s=; b=LZvp7zIRF1tWWNIHgv4Qzf1eTVuhcSe20RJyX9/pmU4qedd2Cwz796c+OeEqibx3mT RoFM3TY5SHp2jBP2V6sUOfXePix92ElT9tRiqB3L8cUkVZreIlxwAGdb6xNc5h04KZfF aYH5bdmCOI40i5qy3nZDQYZkhqE9AYoxxOY9W3Glf6kLFWHrxGBndkT0il9znljsb4lY tXrDehJGrCrbRi9PJJbhdTBysy1SXolxyG27OJbF8DNSycghA+CIWCqmc4iR3lUDm4hk OM0cHSPJT+XEbNNm+FD2INnXGBUF1IfgK5UKl1xPewRGERkKwlFLstPoghYo5t/0n5uC FqiQ== X-Forwarded-Encrypted: i=1; AJvYcCX45NuVqoEfTbPf/G/cXFKYiaWjfgI5RIV0inB/BvbyRzVYm4ayrwNPGqSZHzFuXN0OCkykXoWgVDStA5s=@vger.kernel.org X-Gm-Message-State: AOJu0YwFguExheWKrCkGALcHcTehIYE2jHkjAmjyWD9ysQxeXIBVMEVC 36aP/v4oKaHFmRY59h/9WPv/UlkLXUT7oPbJ6aJ8yKHX/OfsrrpTnuuJBeKaZzBYLQ== X-Gm-Gg: ASbGncujzE7wC4POp9+twooXnaO/PaNRlXz4K00XfyqyOmPgShVAg8+UzPZN1jEAyNG n0TkWuHYVIlXcjv209y5EzHirk4zGJU4LEGDg33aaBUpjnv6yNwof95uEoMUXo2XoncgIgfUT8A Tbarz8EQp2/Dq5bGnWosY87pWgkKH1Gg9eCBm31LdJF001d4fo2H1NJFoMjYhvSWuAgCp//ugcG FVPL8v7jkTCqLr+wYCNcNeyFHCLjrwJJwpna9Za7TNaBy3w/hvKG5/98L5Jk8eKHBbq1GryEEq6 TjL0BjjsnPYi2bh9XLEd7NlfGRuLM4oJV/OvIDzlmIJogLxB4OTKo5PPW8l+Ty18KXbxPK5IAtK c63CqSIWtGf/hv9BLv0Pv/prACG7Yda143rGpanU1s9u2it4Nr3JBXw3EGdJLvJlV5XmcCVJ3Nq 2sy/4ZrtqmTSqfFqDmwmUBPWEFHd+mNGTJZKTHtH3jlwjz4Ic2z/ggpaDRkchYS2zuV15M5B4wM a/Z3hp5WfjIq8/mzk8J3w== X-Google-Smtp-Source: AGHT+IHo6BcWEO8aAB6UKpwKa3lU4iaGYTslO6xLm3i1HGiV97D5oGlqLdkkc3mN0VhnSOUSh5Hb2g== X-Received: by 2002:a17:907:980a:b0:b71:ea7c:e4ff with SMTP id a640c23a62f3a-b76c546d949mr2614872766b.6.1764591981126; Mon, 01 Dec 2025 04:26:21 -0800 (PST) Received: from akuchynski.c.googlers.com.com (218.127.147.34.bc.googleusercontent.com. [34.147.127.218]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b76f519e331sm1229049266b.24.2025.12.01.04.26.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Dec 2025 04:26:20 -0800 (PST) From: Andrei Kuchynski To: Heikki Krogerus , Abhishek Pandit-Subedi , Benson Leung , Jameson Thies , Tzung-Bi Shih , linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: Guenter Roeck , Greg Kroah-Hartman , Dmitry Baryshkov , "Christian A. Ehrhardt" , Abel Vesa , Pooja Katiyar , Pavan Holla , Madhu M , Venkat Jayaraman , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH RFC 4/8] usb: typec: ucsi: Support mode selection to activate altmodes Date: Mon, 1 Dec 2025 12:26:00 +0000 Message-ID: <20251201122604.1268071-5-akuchynski@chromium.org> X-Mailer: git-send-email 2.52.0.158.g65b55ccf14-goog In-Reply-To: <20251201122604.1268071-1-akuchynski@chromium.org> References: <20251201122604.1268071-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 | 17 +++++++++++++++++ drivers/usb/typec/ucsi/ucsi.h | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 82c3efd72639..ee96c42e9e27 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -331,6 +331,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; @@ -355,6 +356,15 @@ 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 ((con->ucsi->version >=3D UCSI_VERSION_3_0 && + UCSI_CONSTAT(con, PARTNER_FLAG_USB4_GEN4)) || + (con->ucsi->version >=3D UCSI_VERSION_2_0 && + UCSI_CONSTAT(con, PARTNER_FLAG_USB4_GEN3))) + svid =3D USB_TYPEC_USB4_SID; + else 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) @@ -635,6 +645,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) @@ -858,6 +870,9 @@ static int ucsi_check_altmodes(struct ucsi_connector *c= on) "con%d: failed to register partner alt modes (%d)\n", con->num, ret); =20 + if (con->ucsi->ops->add_partner_altmodes) + con->ucsi->ops->add_partner_altmodes(con); + /* Ignoring the errors in this case. */ if (con->partner_altmode[0]) { num_partner_am =3D ucsi_get_num_altmode(con->partner_altmode); @@ -1154,6 +1169,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 f946b728c373..6e77bdbdaeae 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -75,6 +75,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 @@ -93,6 +95,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.158.g65b55ccf14-goog