From nobody Mon Dec 1 22:03:48 2025 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 CB65F30E0D8 for ; Mon, 1 Dec 2025 12:26:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764591986; cv=none; b=sR7gy6ZNu3QhmJ3oWtBJ9o05A+4rBPjWJOdti1qO6ah4PYJTBjgTaCBftpJ4LMw+vVU4UJBf+T1e56wasWkL8PSUz33s1nruTyQVWGo10BUAPvSYN7JMUU7ZHjSo477nJp46Okglr3jpfrMtLxSrzyjqBOjIRr/o7d4Ipria6+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764591986; c=relaxed/simple; bh=EjyjRDZ14jo9PQ2gU5QebdkTOWDTQZAHb1P+d2FyXxY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z25xz05Rq1Uapo1X9X+sT+w41t4pKzhWe8VuPKuMuqnVKkpTq+/EfMUbBYeJ/NHQ4MRxqRFUHWMJF7Lqfzm3gtLjQHxUVcXDxeUplNLp0UA6d4FRr360mcVozKtVoBcUcULX61OBuz143GNnkTgI3tgbMzE0CXf8REd+MNnJZGk= 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=L7xOPtmb; arc=none smtp.client-ip=209.85.218.54 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="L7xOPtmb" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-b7355f6ef12so820968966b.3 for ; Mon, 01 Dec 2025 04:26:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1764591983; x=1765196783; 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=w3siUDoeibOS44ZiVJ7r4alLl9iFlDQ+/+PWsVjixhQ=; b=L7xOPtmbT670qlMGzeURDqdGIq++hu1bLeI6jSNk/5KGw27xXSwpxIMbKAXV40Gxez zPxh2+lpR+XNDd0viiB7dcrTh++KBpxIDE9NtDtGoI6yAKqQZhYMW8jER5r7svFUk4bu 5zTcxLcvEESP99+dkjixIC8lbtmiGF2M9DEyQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764591983; x=1765196783; 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=w3siUDoeibOS44ZiVJ7r4alLl9iFlDQ+/+PWsVjixhQ=; b=UI1IJjOBKHprBTcerr/4/+ALDZl3I+qcsMdWBUN4VywxEGPdMrEWxmrP2pxcgRqGb4 8+4nRkQ7CKTxGW3sewkfc0rCd0i7XOxvVyQBWkOAp4w49CISadgAqJ7t0Z6Ude5nSuOU als426cBIeNHPDSETF/RP8Z+yFO98wJcH6/tageSqDt8tQkR0buEpG0ruRlag9m2Wpxt 48otoLfgd5/LOcEdloLVQfh0gDzcXiwoYXiAd4fPcCDkQgoo4dxK4KwgTM+tWL/rOcFy RpOYQ+uGOMyG9J6kN4gEOcUOpL8nxUwSxqlCqtZQ9k/VlmPSkvU+RnRyvT29OmhPF4mm 821w== X-Forwarded-Encrypted: i=1; AJvYcCWuQnnsW9uwzTTJjzhHCKBWkpZxGgjAuNVSGAZUERUYsqKi6sBddHI8Zt8qRaQxEuIla5ljHGsJeHL2jxE=@vger.kernel.org X-Gm-Message-State: AOJu0YwphxS5wll8+A47zDaLCHFpETfYmlbu7lMSYpGsiF/zX68IIXGo oKnMvJJv1QCu05bSAvB3wW6aRpTEhWLkqH0+yhOwmaRbUe3v+sJBm5BeObi8ENXpGA== X-Gm-Gg: ASbGncvqzybwyg4R4s/5up4HRIKho3ZUmqdbeKVW9Vd5wjImsT09d5Dm6ZB/40oRZob i216A+tsKtkljuwX4xc6r3LMpMLumZOAPYFo5onqsGvstoPorO8OvVcLfkbbeJzt//5voT1hudY izTaVNXYB7DjQaEtVYxOQ74MnnQxuNmQ2a93kIG+UXzITc58w9qx7NLRkWCyutHkVv0AsGH08Hb x1lePqFbc7K7Oz7Ew4jJKBrVg/b2UvwTJsuG9jS4IvwmVPSau1KFaMQtmdL48rNF3k2NLcy46de LX1QRzMf/DIcNLxufgHGRKRgJfdxUHoX56upEG6RdyV7L+kVcWbp8ChlbQ0GUl9QZUI71UlF7TQ 3QbLO76duS/zSbr6FE7rlXCtBAc0KIf39D2SrZ97tJiOmPaBCE2+OqcmLvO11BJGKiFvRu+Kft6 IJQfqqgamHQ9Ms2xE8ynT59uFPWv8NrTJ3NaC1SSgGLkjk1bm8SGH8oddGDhUUlxiMOKxLV4n87 5l7J6nK4YE= X-Google-Smtp-Source: AGHT+IGdIbQA5fN2pjwFCGt2uQXmBVTAC2xTd2yjO+gh50cAVKF7tAIvotcRnv9TG3dRpl06Kz7Dmw== X-Received: by 2002:a17:906:fe08:b0:b72:a5bd:c585 with SMTP id a640c23a62f3a-b7671732667mr4428434466b.46.1764591983127; Mon, 01 Dec 2025 04:26:23 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Dec 2025 04:26:22 -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 5/8] usb: typec: ucsi: Enforce mode selection for cros_ec_ucsi Date: Mon, 1 Dec 2025 12:26:01 +0000 Message-ID: <20251201122604.1268071-6-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" The mode selection sequence is initiated by the driver after all partner alternate modes have been successfully registered. To prevent the Power Delivery Controller (PDC) from activating alternate modes, the driver disables all alternate modes on the connector: - During the connector registration - Upon partner disconnection When a partner is disconnected, the driver also stops the mode selection process and releases resources via `typec_mode_selection_delete`. Signed-off-by: Andrei Kuchynski --- drivers/usb/typec/ucsi/cros_ec_ucsi.c | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/usb/typec/ucsi/cros_ec_ucsi.c b/drivers/usb/typec/ucsi= /cros_ec_ucsi.c index d753f2188e25..988a159ed778 100644 --- a/drivers/usb/typec/ucsi/cros_ec_ucsi.c +++ b/drivers/usb/typec/ucsi/cros_ec_ucsi.c @@ -16,6 +16,7 @@ #include #include #include +#include =20 #include "ucsi.h" =20 @@ -33,6 +34,11 @@ /* Number of times to attempt recovery from a write timeout before giving = up. */ #define WRITE_TMO_CTR_MAX 5 =20 +/* Delay between mode entry/exit attempts, ms */ +static const unsigned int mode_selection_delay =3D 1000; +/* Timeout for a mode entry attempt, ms */ +static const unsigned int mode_selection_timeout =3D 4000; + struct cros_ucsi_data { struct device *dev; struct ucsi *ucsi; @@ -133,6 +139,41 @@ static int cros_ucsi_sync_control(struct ucsi *ucsi, u= 64 cmd, u32 *cci) return ret; } =20 +static void cros_ucsi_disable_altmodes(struct ucsi_connector *con) +{ + struct cros_ucsi_data *udata =3D ucsi_get_drvdata(con->ucsi); + u64 command =3D UCSI_SET_NEW_CAM | UCSI_CONNECTOR_NUMBER(con->num) | + UCSI_SET_NEW_CAM_SET_AM((u64)0xFF); + int ret; + + con->ucsi->message_in_size =3D 0; + ret =3D ucsi_send_command(con->ucsi, command); + if (ret < 0) + dev_err(udata->dev, + "Unable to disable alt-modes on port %d\n", con->num); +} + +static void cros_ucsi_update_connector(struct ucsi_connector *con) +{ + if (con->ucsi->cap.features & UCSI_CAP_ALT_MODE_OVERRIDE) + cros_ucsi_disable_altmodes(con); +} + +static void cros_ucsi_add_partner_altmodes(struct ucsi_connector *con) +{ + if (con->ucsi->cap.features & UCSI_CAP_ALT_MODE_OVERRIDE) + typec_mode_selection_start(con->partner, + mode_selection_delay, mode_selection_timeout); +} + +static void cros_ucsi_remove_partner_altmodes(struct ucsi_connector *con) +{ + if (con->ucsi->cap.features & UCSI_CAP_ALT_MODE_OVERRIDE) { + typec_mode_selection_delete(con->partner); + cros_ucsi_disable_altmodes(con); + } +} + static const struct ucsi_operations cros_ucsi_ops =3D { .read_version =3D cros_ucsi_read_version, .read_cci =3D cros_ucsi_read_cci, @@ -140,6 +181,9 @@ static const struct ucsi_operations cros_ucsi_ops =3D { .read_message_in =3D cros_ucsi_read_message_in, .async_control =3D cros_ucsi_async_control, .sync_control =3D cros_ucsi_sync_control, + .update_connector =3D cros_ucsi_update_connector, + .add_partner_altmodes =3D cros_ucsi_add_partner_altmodes, + .remove_partner_altmodes =3D cros_ucsi_remove_partner_altmodes, }; =20 static void cros_ucsi_work(struct work_struct *work) --=20 2.52.0.158.g65b55ccf14-goog