From nobody Sun Feb 8 23:37:03 2026 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.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 3278138FF16 for ; Tue, 13 Jan 2026 13:05:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309550; cv=none; b=ZzXhRLJKH9/5+Go8I8SmmXhF2Rk+iDmjHvK0z7FayywkktWfdZbkTcE0kxd/4RSuMAJ0fey316EQSZLdHlMcgXE9bcqy96QodgB5/C18WEGc3dqywmiC9VcIpm0iGQ/K2lwOula6iHV/NCQwALpwikwwQmqX/28J5/xMRMYczrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309550; c=relaxed/simple; bh=V1jmUzlQs0mqeDEI06ZenpYXU3urQAv3hO+yVPpB20c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fjIqSfvXarGtMcPuf8kII0wq2+YqacnOC1XscYSEWJBVA1wOwsXNCD8Yx89IIKwrrfbnSW+FXXJ53D7KfHkoeJAPuPn2mzRFJgKOWy480D+b6ZnIW1BuEdgOets1oUGw+MxuVSyXDhufuxdwtUfEHSZE3FLTsD3R1h8/OSrXt0M= 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=drw4+QxY; arc=none smtp.client-ip=209.85.218.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="drw4+QxY" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-b86f3e88d4dso389268866b.0 for ; Tue, 13 Jan 2026 05:05:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1768309544; x=1768914344; 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=cLqa5LSPMe82XqVLviPNjog13TrBNYmx2vAnL8Z9NGE=; b=drw4+QxYOHZyNPKk4rMAhGLBNy6+KgtAZYmdtTGuFNzvPT1LrWQiKLQaxe65VE8c8C Q0da9kwBo0smGgBHRGRvsUB6STznfHeOf+TdlOKmIEcFUc3v4qFxYEha9yKKP4SCjAAh 6H9qmfzQsOH/YPlU9eBKNiTg+zMjvgj+b3WMU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768309544; x=1768914344; 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=cLqa5LSPMe82XqVLviPNjog13TrBNYmx2vAnL8Z9NGE=; b=MjrtRvtsWYelj2c4Qre4Y/mD3KRWiF9RDy/GcPsWVThteIUyBwt25gm8qfWOhM/ljy uTnkX+6I2Jo0KWm4Ccbu1ajt30E9yNWbNlgouUVJV6MaKf2EqxYHIKnVmmXfNqyCsJml uWOPEAfINrtN2qbdooKmwzjweVmNf02jlI8XrZ0G3KdtHuwNAUexYDyRovitWUJavS83 OpaLJyvB71TqgrKEfKtdOCviTgPOsRnte7KuF+pK5ywY/4YWbglppHBeEJhhTstT4OIz o4nXmsG/9lODvdp/XXJ7KZjWWfkjhDeNqyVF9188vquDAB2dDOIPSaqRmeUgGv3v2faX eYvA== X-Forwarded-Encrypted: i=1; AJvYcCW6z+171WvgjywYVzsQ0zNPA+QQCBe/+fDkxonvW0RiWgGdBTZ1FWnmd+JtZ06AfELFzDyDe8h/Z0IPPNw=@vger.kernel.org X-Gm-Message-State: AOJu0YyYo2pbKepciGFtr9HrXvplv+Ciu3GW5IJedGtCnZ5J3v0dsYSr /kWC92WwoC0XNpdJ6EiUe8kPkopzEFE2XOtWO0ZJGjVLQz7yWEU0mljq4FTGPIyVWA== X-Gm-Gg: AY/fxX6luGva1claqUJ91celh0DWzAg4KeLlafZbwS3s9Us/jGaAAhDdHd8Mtmke94J 9QmdskYbvdZMT4DXyS4x5X1t7PeMiacFsLKyjQQyOngxdr5DbbLV7MohqQimGEgy6p5xOPfeD4Z vYQeXX0TkOFGGTg2qTNeOC/4CztclJepD6tAuFjXCyi0iMfTSA9vRbEd62gn/gTXdwlZP8gujOJ qPsO2qB9c3ZDNL6C1ax6eQM1SCigDzAX7Hv2Tbi6ZA/vzCFwgNIr+qPc0SzygHWn7orUpn1YJBk gMXKvH7ymHEadCKUXGPdD/6TRwoJWmoivpbWPcbnx9w5V+OS6ybjGI3py7BdbbAVgI0kRPNCVIf g7QH/PGxiLLBxk+pGzdpecSqWameuzZ/0WBVPcX8F6M5tT/DOWvnrgp+OQTeAXRTvWWpdTahoQU YR+JNPZb6xdV1LpljV7J8bkISo37QEGEqqeVLELmuDON4UciO7P9lspxaUwLIyvsCPbLiDWbBYC aivuLOQ+uhAzCt6gLI= X-Google-Smtp-Source: AGHT+IH9fdlAcsYdBhHsm3MzZdhegh+CqE1dU7+aUp1J6imJDfwNUKifMVZoBAGXlrQ1du/vBUGWRQ== X-Received: by 2002:a17:907:9691:b0:b87:51d6:22fd with SMTP id a640c23a62f3a-b8751d62cacmr45371966b.4.1768309544446; Tue, 13 Jan 2026 05:05:44 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jan 2026 05:05:43 -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 1/8] usb: typec: Add mode_control field to port property Date: Tue, 13 Jan 2026 13:05:29 +0000 Message-ID: <20260113130536.3068311-2-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" This new field in the port properties dictates whether the Platform Policy Manager (PPM) allows the OS Policy Manager (OPM) to change the currently active, negotiated alternate mode. Signed-off-by: Andrei Kuchynski Reviewed-by: Heikki Krogerus Reviewed-by: Benson Leung --- drivers/usb/typec/class.c | 9 ++++++--- drivers/usb/typec/class.h | 1 + include/linux/usb/typec.h | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index c4ff4310ff58a..0f12d6120511b 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -457,11 +457,13 @@ static umode_t typec_altmode_attr_is_visible(struct k= object *kobj, struct attribute *attr, int n) { struct typec_altmode *adev =3D to_typec_altmode(kobj_to_dev(kobj)); + struct typec_port *port =3D typec_altmode2port(adev); =20 if (attr =3D=3D &dev_attr_active.attr) - if (!is_typec_port(adev->dev.parent) && - (!adev->ops || !adev->ops->activate)) - return 0444; + if (!is_typec_port(adev->dev.parent)) { + if (!port->mode_control || !adev->ops || !adev->ops->activate) + return 0444; + } =20 return attr->mode; } @@ -2708,6 +2710,7 @@ struct typec_port *typec_register_port(struct device = *parent, } =20 port->pd =3D cap->pd; + port->mode_control =3D !cap->no_mode_control; =20 ret =3D device_add(&port->dev); if (ret) { diff --git a/drivers/usb/typec/class.h b/drivers/usb/typec/class.h index db2fe96c48ff0..2e89a83c2eb70 100644 --- a/drivers/usb/typec/class.h +++ b/drivers/usb/typec/class.h @@ -62,6 +62,7 @@ struct typec_port { struct mutex partner_link_lock; =20 enum typec_orientation orientation; + bool mode_control; struct typec_switch *sw; struct typec_mux *mux; struct typec_retimer *retimer; diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index c6fd46902fce7..dbb259d885266 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -290,6 +290,7 @@ enum usb_pd_svdm_ver { * @prefer_role: Initial role preference (DRP ports). * @accessory: Supported Accessory Modes * @usb_capability: Supported USB Modes + * @no_mode_control: Ability to manage Alternate Modes * @fwnode: Optional fwnode of the port * @driver_data: Private pointer for driver specific info * @pd: Optional USB Power Delivery Support @@ -307,6 +308,7 @@ struct typec_capability { enum typec_accessory accessory[TYPEC_MAX_ACCESSORY]; unsigned int orientation_aware:1; u8 usb_capability; + bool no_mode_control; =20 struct fwnode_handle *fwnode; void *driver_data; --=20 2.52.0.457.g6b5491de43-goog From nobody Sun Feb 8 23:37:03 2026 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (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 8392838FEF9 for ; Tue, 13 Jan 2026 13:05:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309550; cv=none; b=hEwTs2oF9VecpgtpvhlTE2/3z2bFN8+1eV18TD4dSMgAlHwY0KH4hy+tycb4YyYRida4wC25YnfohOuAQw39rleK18iVr9VILRHI2ughEHM8KHC+psQGDzUji5TKnb93hcYX78FCTa4svxfsI8arah9Flq6WLzAxUWwxmxNdJM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309550; c=relaxed/simple; bh=aP2YFO92lDva0e1jN3T5U5hBf2PD7EyvHXkgrzxR9eA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q+L7DpvoLkpq+dXL/qXsST4Z3K6uP87pJTJG7JxmrZPudj2jX0eDqFQIBWcBNs7656eeCJpytk+wNC6fKu2yflDZkKaHeKSS2qQZQvRVlrO49ZFTlCwiV1H/2EGm5m1paPsBIRWYXTsbbKDMjoSBny1hYg+IBROWXPelufo1+Ek= 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=De2kmwwX; arc=none smtp.client-ip=209.85.218.46 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="De2kmwwX" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-b8715a4d9fdso294198766b.0 for ; Tue, 13 Jan 2026 05:05:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1768309547; x=1768914347; 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=KHMLWRy5Z3mpMYGMUoVXUolvpCNuwJWbgQEgoyJgmAk=; b=De2kmwwXdl9FURki92S72lqBibreJyUKP3L5vtje2JEdMrijy7EmsPu7xKbbQ3vs4i lJn3lKXf8+WK8O/pVb4T3NthHD82RIp4bXx4eHU1a7VXcMWh9lvvh0UehkahlzhzbOqV pd8ys9jDo1bQ9DJbT3QJAUSFhFhPBedYu+x9g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768309547; x=1768914347; 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=KHMLWRy5Z3mpMYGMUoVXUolvpCNuwJWbgQEgoyJgmAk=; b=Y4HwTw+QUSfnQHJO04osUGWwrWfx01NYDfjMX82i8ynsKku7tKA28Vh+KAUAtBFJX9 pIHxIN4OiO4nB1hmKjDBHeKJ9aNklG+gFSWElFuKi4aEUgTNW5uiM2/GtuZ97LcdSOUN uLF09/lVTrxqIGSwgS1DekHPI/mbHcDdW3yfIrz64edEh8U7hNkAecnqfphB1stysuLh Vod3P8G7mx0VzV7KFKFIvO/x+YqLrTVN4MjhTQF9ugxd7DhkXTG4cCVTnCRYatA5emYv C/BJwFnMG6JdH+ILa2BpCKD5Ptf0Cey7R22/BA4kR9G/fU4UuHUKRaB4L/mKOA56l7W6 Vi9g== X-Forwarded-Encrypted: i=1; AJvYcCWkdMvakiFwwbTVf/Je+N+9Ib3mTfeuTd/UEDdiQ4hOLjw+cg/Y73AESaVDsX1SIBhghm5hV4fPuSIKXlM=@vger.kernel.org X-Gm-Message-State: AOJu0YziNBu3HaeoYMbPDrXcHLorO+5r2JKy+8riwbptakvbYlNzrke2 Yj9B6/9lZdXQ2MDTOMZQc/2s3mtyiYjXnLuajkrtP/zMnxM8VYOgyxMMc1uBbi3oGQ== X-Gm-Gg: AY/fxX7/Y/u6lLG7RTOGBKGacZNBl1h2uvrYVbfvPqDftCmzKpUsnKRh/0CHIScASgX CZpViXvusWDxovzldEHrdZJgLyXryumOJDLnyEFG5oxIoEme7hk87girn5jVeLjytZXVa7KWbzT wuMSPuwRvo3+FRi7q8RK2Z+MCUH5Ch4MhLvaaPCzLxKLlaDVARr2zMWsGdatIaDYP4Llo7XuGj2 0GQJiX90dqxKw7eZn763nGJB6hMg/Cl0Fr8TgnaWtYHBy+RKH9o8/O8FsNoUctn1uGYPcG9H2sw 7O+2WmVZYt5fmFBNfuUhJq0vYrB6jnFJzClIicALgIiKkfMxauQgznDXuozzJiuJyiHoSZN3YJW xq6PIfqtuMJ33h4ITJEmg/o6PjkNdv4tmNgppn4lOfwkc3HpU9bEDDmyX+OZPOVTYEX7YiazhES gQ922fm2Gq5CzwEcwRE/oXJLsYU2AIE6yIX47BIU4qldEbO3+VFIStaC17qP9gCTyJTtKCLts7o f2ftP1P X-Google-Smtp-Source: AGHT+IGYDiJcte/TlGQ/Kqo75hJm6ijsCffQe6+xWAOzGZVEzXJ6AGMRNDBXwFdbt04+YpVYAKbzhg== X-Received: by 2002:a17:907:3c94:b0:b77:1233:6f32 with SMTP id a640c23a62f3a-b844539fbf5mr2233587966b.48.1768309546845; Tue, 13 Jan 2026 05:05:46 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jan 2026 05:05:46 -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 2/8] platform/chrome: cros_ec_typec: Set no_mode_control flag Date: Tue, 13 Jan 2026 13:05:30 +0000 Message-ID: <20260113130536.3068311-3-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" This flag specifies that the Embedded Controller (EC) must receive explicit approval from the Application Processor (AP) before initiating Type-C alternate modes or USB4 mode. Signed-off-by: Andrei Kuchynski Reviewed-by: Heikki Krogerus Acked-by: Tzung-Bi Shih Reviewed-by: Benson Leung --- drivers/platform/chrome/cros_ec_typec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chr= ome/cros_ec_typec.c index b712bcff6fb26..c0806c562bb93 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -491,6 +491,7 @@ static int cros_typec_init_ports(struct cros_typec_data= *typec) =20 cap->driver_data =3D cros_port; cap->ops =3D &cros_typec_usb_mode_ops; + cap->no_mode_control =3D !typec->ap_driven_altmode; =20 cros_port->port =3D typec_register_port(dev, cap); if (IS_ERR(cros_port->port)) { --=20 2.52.0.457.g6b5491de43-goog From nobody Sun Feb 8 23:37:03 2026 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.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 0DB0138FF1A for ; Tue, 13 Jan 2026 13:05:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309554; cv=none; b=TZT+eOLLN1OzCpt3m3Rrhv9vjgJwQo8EK8OSp2nE8l8+Dsh/pKtm1EzYi346VMQezDLl0aRUZtUGBtuypBNDPhXXrd8vwZoNop9nVvEypMyYJYk94eT/JLDUUy+yEqJoxCcy+0dH02/2OycTsn8rn9MO1sOVQjal5rrzkHAcdv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309554; c=relaxed/simple; bh=+JaIC+XYxgvHZoYamzUQwiwiebl7OEagOKElTNuRHxU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j1lcsgm5Ks1z5UeUAiC/2et5+F6ACS/0XOia6WeKpbeqJQFQN15Cvjy1vYYHXvpH80pTKRox+V2EApVUDwqYAjgkUdH2ZKnBpIpGvuJZbIHXR2/t2TXX26Ys3fp88zattNkyeqZZUB78OYKeTelB+5SQZa5sfuDOYCAB9lY3Yq8= 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=lULCgikZ; arc=none smtp.client-ip=209.85.218.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="lULCgikZ" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-b872cf905d3so282987366b.2 for ; Tue, 13 Jan 2026 05:05:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1768309549; x=1768914349; 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=ZCVsnNiF9taQOhEY911oRHXRaOv1GHlaDH7WrNRKjM0=; b=lULCgikZ9xqriZz3C2Un6O7XdKXUaexBb7HBb+v80iI8ry373rORO23kvuqv9DAl09 LoenkHcq73pfZIgD1B5qwEcN8jWHhrWmWMHh/Cl8Fs11Kqo4N6kZquFIpi+pyG3xqpfF KfgigfrxwYJipvF5ioEeHjBD+Nu6zp1agymRo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768309549; x=1768914349; 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=ZCVsnNiF9taQOhEY911oRHXRaOv1GHlaDH7WrNRKjM0=; b=qefiG9zmCCUMz9Qcst7icB4vYRuiG2l8FBFyv42iRBVfPIuBGtwI3Lg3a91xEIAdgm FDDKI8BMw5lohW/EeL7w7szgKrFUTZ/2ZVkhJn64CtMg3NFvd08HUSR5tHKcz296+TZF KH1NXNC5MlSt05Ya+znXh1Jj398N4YVsbPjzCcz+XV4bMICvGmYB09wOky735X8fsuav QMGawvyTN1nIs7ku6AYFB+LaBB8UmKOHgo1Wz+YpMKg9JbCCHOm7yIf3frSbwxMHjNxp rRgMjsotHRq1hu5EzeCZtehfnUsnVnG35gtRjt0fpPpcjNyjCpO1QCLLhuV1BsjLczSt s2Dg== X-Forwarded-Encrypted: i=1; AJvYcCVIpFP4tEfY4na9pDmxtt1bQ1vuSHbfaqGxRLz8qf1kqUFMKUkRvcsZvtEQXdsuAxIieIXz7PMDiZUAwNU=@vger.kernel.org X-Gm-Message-State: AOJu0YxcJI9Er70sSZZOQMvQsBcBCWNpMHH4DB9ANRiHNh+FNn/MVS1o Faq7ln5bd0NQeCKRiDWmBrWC5tX/RejiFsF2ggZxmPMP/uj0A8W/P6utaMmzO1M8zQ== X-Gm-Gg: AY/fxX5DFIEc2li+8/JU9z0xsgnI46KShUoC8Db3Ucsngzo4Mun2tPHu4x4OcLDb1FF VPq6Ft8saA08ULfYOSuEDF/Y71w+c8qikb27l/vq79+G9jUSR2mE9u+g/odgds605JIH3dEUyAk KMVJjdq/BDJWdtbKXIgei5NKjFUJr9EQaCOAUI++KJQC6Yopvl/kPzAaw6u0dK4JJ7ABHeMXSMW ccdu+6jDnxprhVmnLVQH4oLJmdmI5oTJWNJQJ25ViVq6jmcWoE5uYzf7H8Xqrc61JCJE2IB86rX /mAjbqVcLs694MtYne/WWJ8BYpieRu+t1kIhyqI5Lk7nJsK7oBrHuoDywjMmzjrlJ23luDxaXQ6 ewQ6tFqqwsp9YPyOaFY/OGs2b6PFG8ccorZ7Vl8TQtrqaqvG+IxVP0Foffo6lcg4Vu1Ker21ZEp QfH9QAclagWVq9qLjYwD5Guo71Up+FB0Y4xwzwI35/Ml7hKH8Uo2WeGgpzPecPW8jQyjC/JD2zR FxIYSVt X-Google-Smtp-Source: AGHT+IHQrZeQ/CRIvkRFs9Xv/iIOSXPTXMS2jM8rkvlNg8AKY+SdRTPp2Q3LTRtbojrFp7c5Z7Rq6g== X-Received: by 2002:a17:907:7b88:b0:b87:892:f43f with SMTP id a640c23a62f3a-b870893074dmr819575266b.29.1768309549279; Tue, 13 Jan 2026 05:05:49 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jan 2026 05:05:48 -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 3/8] usb: typec: ucsi: Set no_mode_control flag Date: Tue, 13 Jan 2026 13:05:31 +0000 Message-ID: <20260113130536.3068311-4-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" This flag indicates that the PPM allows the OPM to change the currently negotiated alternate mode using the SET_NEW_CAM command. Signed-off-by: Andrei Kuchynski Reviewed-by: Benson Leung --- drivers/usb/typec/ucsi/ucsi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index a7b388dc7fa0f..deb210c066cb5 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -1659,6 +1659,7 @@ static int ucsi_register_port(struct ucsi *ucsi, stru= ct ucsi_connector *con) =20 cap->driver_data =3D con; cap->ops =3D &ucsi_ops; + cap->no_mode_control =3D !(con->ucsi->cap.features & UCSI_CAP_ALT_MODE_OV= ERRIDE); =20 if (ucsi->version >=3D UCSI_VERSION_2_0) con->typec_cap.orientation_aware =3D true; --=20 2.52.0.457.g6b5491de43-goog From nobody Sun Feb 8 23:37:03 2026 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.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 45CA338FF0B for ; Tue, 13 Jan 2026 13:05:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309557; cv=none; b=BKz0XXEOY9z8UWLlhFn8WBeYVB5xtDetWN985UZHuNljelipuLUpbpRlTbSJRR2OGS6RqyOTW0jAaT/I7UxkRNoPyTxMsN7MhJZ+EEEbvQzz+W1QTvjV9Q1/tUvAPDU/15tBl1Qr5fBJ2Ky9x1FrPLqnhPmhjbUxamz+iswuwjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309557; c=relaxed/simple; bh=bVUhc7VpDUnDxfDtkHva6EQ2YfFZC4bpqm5zztp0T64=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VKD+aeJR0oVqBFPLYOPXFmhzfZRdHeBf5Uq+ejuY5YL8ULnLxwc7gJNwStMxBvHUAweiaDpjqmHQM2wSR5K+RBS2WKcUdkviJqtgUKwF4PUyJA7kz8z1tYdHDVDOQAth8LE7ngcLP85IqNDkFk663WyVpgJdwNj/GFIhn1XaS6o= 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=TN34hk0P; arc=none smtp.client-ip=209.85.218.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="TN34hk0P" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-b8718187eb6so312178666b.2 for ; Tue, 13 Jan 2026 05:05:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1768309552; x=1768914352; 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=afo50+aNolz/eyc+FXJYc+MI5yPdVLIkEoTPV8JfhIk=; b=TN34hk0PfI2JYr960/J31pLy3pTkNcdlemMfMfu+4REc+BioKJf3Vv0xhY8hF8Od07 H5CXZQVKFeCrHmBQGNjsPTuos5zWryYjlK0vDTcHQP5yVq2+I9TwY9VdnuGeMaOFZ2b/ 304XuDOcTfWmILX5QzZk6BFDCRwo+0Sh7uF8M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768309552; x=1768914352; 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=afo50+aNolz/eyc+FXJYc+MI5yPdVLIkEoTPV8JfhIk=; b=fQihT1demEp2ULkWUU22zMhYMtR+RD35pl0KEcPm5npTCNIVCfTLOmVGo3or78X2A+ zn54j36OjQQMvsc4RpnEGdOTmoUUnw0zWLAnUpdMlYx2o+W06LttfTLVfYLvAjks0ldH uJzELgue1rjS7mMkVm9EIQ7QWa8Zjdi1Wlvntd81dVm2NAxUtNfR0togI/0iuBhi5rln jnUvG/D9VxGoXLoVYC+u19xt7RXM+6kj3jaze+1eHW7i3WXZwwpPDl+ybUp5r1N1kF8D yBgIWs+/H5DDQCYIZYpPbSffUULlLN7OSodBralfKd/pjiOihk8Eb8VJL9wRq3Hjsod9 L/ww== X-Forwarded-Encrypted: i=1; AJvYcCUcGDSV1lOE+EBosElLg5XqVTIhmTaEUCEPztYTHKzyVzVT/Xg76FtgQ9IU57N1hXJJXSWqSblSue8+rMg=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9Qj3eakoaPZwgtf9uk6AAlYiPhbuAYl2GDnbfh4CVtJI/anfp KreWN3Oe2R48jnnz679YkFV15tBI5HbOeaM23RywZr468+CCSkG6LvBlZEBs5M76yQ== X-Gm-Gg: AY/fxX7kMi5G/FLFt1xiDENZHOsVoFa/9d/uj7jRJvxT/QcwGca/RuLCVt8FO4xCz3D M2Hxb26HCsq0ILVGMN+t/yUoaNudFC35mnHiQx+Yb4PVjCWwIJHFy77/g6dfI2YhZYVQYD9sHMj ozArfcoczon5AiDPzzfeCPunskCydv52ByBbSty3pR3t7wpFLZadqmfxMcn8VEGTvyqc5PLuf1r aL/TFdx/TOaNV20IxsI94C+0jUaiSVj74qHh/3E7Vr4SxvNHmFUDGjj3s9Fl1JUeuGn1VltFigC eILFxs4wRsXbyc3++eZzJc63JlxCeOM7N0ui4aq6tCONeSuEhDf0X69IM9VqLlD/loTUDzXR2au 2pGmIoRK23Q2q2NRhChhxlwRESSAnvC0qr8fxOYKpwqxUteoElFhWFI9cuKEsASOqNHx+F7MGnI xyIX4ZlRvNqsl1ExwV8f4Bl42YWkdS4IbfDFXVhPX5VBgdjZtRXnasn1Ni8otvCRvD/Utr5HQk8 7/u5j/n X-Google-Smtp-Source: AGHT+IGIDWcZoX/igewBnXumY61TFpoC2nj6Rw8tc/gyULQtX23Kl7iOBicSZMG61hMYbEOewkNWZw== X-Received: by 2002:a17:907:6e92:b0:b87:1a26:3672 with SMTP id a640c23a62f3a-b871a265b10mr652150866b.57.1768309551621; Tue, 13 Jan 2026 05:05:51 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jan 2026 05:05:51 -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 4/8] usb: typec: Expose alternate mode priority via sysfs Date: Tue, 13 Jan 2026 13:05:32 +0000 Message-ID: <20260113130536.3068311-5-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" This patch introduces a priority sysfs attribute to the USB Type-C alternate mode port interface. This new attribute allows user-space to configure the numeric priority of alternate modes managing their preferred order of operation. If a new priority value conflicts with an existing mode's priority, the priorities of the conflicting mode and all subsequent modes are automatically incremented to ensure uniqueness. Signed-off-by: Andrei Kuchynski Reviewed-by: Benson Leung --- Documentation/ABI/testing/sysfs-class-typec | 11 +++ drivers/usb/typec/class.c | 90 ++++++++++++++++++++- include/linux/usb/typec_altmode.h | 1 + 3 files changed, 101 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/AB= I/testing/sysfs-class-typec index 38e101c17a004..737b76828b509 100644 --- a/Documentation/ABI/testing/sysfs-class-typec +++ b/Documentation/ABI/testing/sysfs-class-typec @@ -162,6 +162,17 @@ Description: Lists the supported USB Modes. The defaul= t USB mode that is used - usb3 (USB 3.2) - usb4 (USB4) =20 +What: /sys/class/typec///priority +Date: July 2025 +Contact: Andrei Kuchynski +Description: + Displays and allows setting the priority for a specific alternate mode. + The priority is an integer in the range 0-255. A lower numerical value + indicates a higher priority (0 is the highest). + If the new value is already in use by another mode, the priority of the + conflicting mode and any subsequent modes will be incremented until they + are all unique. + USB Type-C partner devices (eg. /sys/class/typec/port0-partner/) =20 What: /sys/class/typec/-partner/accessory_mode diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 0f12d6120511b..1fb5450c0a2f2 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -445,11 +445,88 @@ svid_show(struct device *dev, struct device_attribute= *attr, char *buf) } static DEVICE_ATTR_RO(svid); =20 +static int increment_duplicated_priority(struct device *dev, void *data) +{ + if (is_typec_port_altmode(dev)) { + struct typec_altmode **alt_target =3D (struct typec_altmode **)data; + struct typec_altmode *alt =3D to_typec_altmode(dev); + + if (alt !=3D *alt_target && alt->priority =3D=3D (*alt_target)->priority= ) { + alt->priority++; + *alt_target =3D alt; + return 1; + } + } + return 0; +} + +static int find_duplicated_priority(struct device *dev, void *data) +{ + if (is_typec_port_altmode(dev)) { + struct typec_altmode **alt_target =3D (struct typec_altmode **)data; + struct typec_altmode *alt =3D to_typec_altmode(dev); + + if (alt !=3D *alt_target && alt->priority =3D=3D (*alt_target)->priority) + return 1; + } + return 0; +} + +static int typec_mode_set_priority(struct typec_altmode *alt, const u8 pri= ority) +{ + struct typec_port *port =3D to_typec_port(alt->dev.parent); + const u8 old_priority =3D alt->priority; + int res =3D 1; + + alt->priority =3D priority; + while (res) { + res =3D device_for_each_child(&port->dev, &alt, find_duplicated_priority= ); + if (res) { + alt->priority++; + if (alt->priority =3D=3D 0) { + alt->priority =3D old_priority; + return -EOVERFLOW; + } + } + } + + res =3D 1; + alt->priority =3D priority; + while (res) + res =3D device_for_each_child(&port->dev, &alt, + increment_duplicated_priority); + + return 0; +} + +static ssize_t priority_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + u8 val; + int err =3D kstrtou8(buf, 10, &val); + + if (!err) + err =3D typec_mode_set_priority(to_typec_altmode(dev), val); + + if (!err) + return size; + return err; +} + +static ssize_t priority_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%u\n", to_typec_altmode(dev)->priority); +} +static DEVICE_ATTR_RW(priority); + static struct attribute *typec_altmode_attrs[] =3D { &dev_attr_active.attr, &dev_attr_mode.attr, &dev_attr_svid.attr, &dev_attr_vdo.attr, + &dev_attr_priority.attr, NULL }; =20 @@ -459,11 +536,15 @@ static umode_t typec_altmode_attr_is_visible(struct k= object *kobj, struct typec_altmode *adev =3D to_typec_altmode(kobj_to_dev(kobj)); struct typec_port *port =3D typec_altmode2port(adev); =20 - if (attr =3D=3D &dev_attr_active.attr) + if (attr =3D=3D &dev_attr_active.attr) { if (!is_typec_port(adev->dev.parent)) { if (!port->mode_control || !adev->ops || !adev->ops->activate) return 0444; } + } else if (attr =3D=3D &dev_attr_priority.attr) { + if (!is_typec_port(adev->dev.parent) || !port->mode_control) + return 0; + } =20 return attr->mode; } @@ -2498,6 +2579,7 @@ typec_port_register_altmode(struct typec_port *port, struct typec_altmode *adev; struct typec_mux *mux; struct typec_retimer *retimer; + int ret; =20 mux =3D typec_mux_get(&port->dev); if (IS_ERR(mux)) @@ -2516,6 +2598,12 @@ typec_port_register_altmode(struct typec_port *port, } else { to_altmode(adev)->mux =3D mux; to_altmode(adev)->retimer =3D retimer; + + ret =3D typec_mode_set_priority(adev, 0); + if (ret) { + typec_unregister_altmode(adev); + return ERR_PTR(ret); + } } =20 return adev; diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_al= tmode.h index 9197a4637a938..7e6c02d74b54f 100644 --- a/include/linux/usb/typec_altmode.h +++ b/include/linux/usb/typec_altmode.h @@ -36,6 +36,7 @@ struct typec_altmode { int mode; u32 vdo; unsigned int active:1; + u8 priority; =20 char *desc; const struct typec_altmode_ops *ops; --=20 2.52.0.457.g6b5491de43-goog From nobody Sun Feb 8 23:37:03 2026 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 6B63638BF71 for ; Tue, 13 Jan 2026 13:05:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309563; cv=none; b=FuNeTrhoJwE9XpkG+7JXS10kW5UHV3gNT4cexFhWK6wnTHM2EBhAwXWpYSyNX3sOa9mKoF6UurE1DdEU9Jlv0/qXGCZJ/rTVEjuCvx9RK1uIf09Ts/8n3O5J4l9SGr6Y66PWbMnNjJ/lpGT9MdLfHhaXfBAVPwpQ49dS+xRF44Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309563; c=relaxed/simple; bh=4K8L+sg/AxECo3YT9rAvmZH6JXAMom1NPRXFdioQ0zU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AGkrdCOwK/hN0QtNknzqY9q65t7mcz8vhSQ0j38ouSDLUyr6yDKIGe4FDM2tlwQd+J/h+tiRhL2YrV0g+oKL2+DMS3gcK4G9F9CAk05w0/D4FdyQQOGsy9NN/S03rQTYbqDBbBJagEFDpdNtEvf/OOQ+t1Z11zhKtrxEgWJtyRI= 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=gQ8T1yvg; arc=none smtp.client-ip=209.85.208.53 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="gQ8T1yvg" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-64b921d9e67so12924473a12.3 for ; Tue, 13 Jan 2026 05:05:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1768309554; x=1768914354; 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=gU3mGY4lL4B7xDRlGz3LAk90x1yvcCvHRV7BoGEJ4RA=; b=gQ8T1yvg8iiaXCTW8cYp520pnGLfomvNVlTXCIyqfABK/5i5piBnuwsXI0veu6L12o qgH7lPo2BH5Cc6N+1cGWNsLudUwk6J69lpdsKDvz64MRqv4tMIFzTCPMWADms+mhTcVo TgrSaD3q3SqoBU0pnZVXrl3P5YaMSEw7/rOxw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768309554; x=1768914354; 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=gU3mGY4lL4B7xDRlGz3LAk90x1yvcCvHRV7BoGEJ4RA=; b=KUmvFdcLzJoeK50C5D0CmPCczvPSXd7CybhcNGxAp4fe6r3FGicnUJAQtNN3ryPM5q FrEjYFeg+d+Q4r8/7xtb36PQ1TK4tlksnRi1gBHLH1L4XVq7oeHpXgtteItHmB3PUVsl ZqXdycUalZIruqh6zb5ItzxdijQiLw12ataL28K5k1oGMViLnfiPrPDifbnlGK5nlvW7 qmJMAUT/N//TFDY4wv6CocN0AdxmGHEs5UfNkFeRA3gd7fCmU6Ed9EsYksMxBX0V8Nq1 l8g6TyA8jj4XeNbBvxSl1sASBIn5Vg4Q8/t7pDGENhwZIR4T88LCTciZ0iCKMtz5CRRo hSNA== X-Forwarded-Encrypted: i=1; AJvYcCVifvpNZbZ/rm2pk2wtbndWObLAzMQEya5uaE39fLBJTDe1JV01b7rrVEqu/v9KShUKLInkyoiB1hoFZlw=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9njlTbQPD/i6Ku2anHPUM0JBSSudYQYuGgqcmDb5HMPvMSZXG we6oiseTJqDSUct13cwkZV/RiEYO0AwgJwpdQzlPzVR+EvBxY/X20gLxN2Ds7hvPpA== X-Gm-Gg: AY/fxX7eD85I9WU9MuViESmI3eaPjfemvVuStFHxKVPjAXxhA4PpAMv/ZyeKofdC9pN bVruXoqAcluryr079LYoZjh1hO2keacAZqR0rQnquf1TdcOhes/XUtOpvBeShpiYrCxbOPqeAuu GilQvy+6czKHhj3D69vCBQMuaAl2qG5yX8deYSD+zG3HkH+iXnpNHypH6zvwlVnZP1QjIbXEyV4 mwsE4Q19iVG7ZXxoFmEJESWSCd9VFHo0ULtb2FtcCkJ3XCKQwhEalgU+tp8lEOYkXffe32I07rw IGRf5xFA7uYwVme5HA7lXiNmSVYEJWFkKg3QbL+5z4yUFPQ6mR4jy30qYULf8bbRIDDxFA61qs7 PVzgeXBkoXgFGHTWVVpVXB0gY7RE+fil/mJN9NuU4ewx2xKAw4T0HcXmAF6uAag1TyxLnwW7ycS aG6+8zIRSgGkMvF2efbSXhZlFKjp3VPjOtUvF/nX/bVYvEmQMMqYoda9v1sGftf1IkF8/vZo/bO WI32B2w X-Google-Smtp-Source: AGHT+IFE+2vYAPRyK361Ox6jLvRq+jbgJkbDVGscv0Kw5AJddEe5asVEPIYrqMGODYFmUO3ousLj3A== X-Received: by 2002:a17:907:928a:b0:b73:278a:a499 with SMTP id a640c23a62f3a-b84451c66a2mr2109372766b.15.1768309553669; Tue, 13 Jan 2026 05:05:53 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jan 2026 05:05:53 -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 5/8] usb: typec: Implement mode selection Date: Tue, 13 Jan 2026 13:05:33 +0000 Message-ID: <20260113130536.3068311-6-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" The mode selection process is controlled by the following API functions, which allow to initiate and complete mode entry based on the priority of each mode: `typec_mode_selection_start` function compiles a priority list of supported Alternate Modes. `typec_altmode_state_update` function is invoked by the port driver to communicate the current mode of the Type-C connector. `typec_mode_selection_delete` function stops the currently running mode selection process and releases all associated system resources. `mode_selection_work_fn` task attempts to activate modes. The process stops on success; otherwise, it proceeds to the next mode after a timeout or error. Signed-off-by: Andrei Kuchynski --- drivers/usb/typec/Makefile | 2 +- drivers/usb/typec/class.h | 2 + drivers/usb/typec/mode_selection.c | 288 +++++++++++++++++++++++++++++ include/linux/usb/typec_altmode.h | 40 ++++ 4 files changed, 331 insertions(+), 1 deletion(-) create mode 100644 drivers/usb/typec/mode_selection.c diff --git a/drivers/usb/typec/Makefile b/drivers/usb/typec/Makefile index 7a368fea61bc9..8a6a1c663eb69 100644 --- a/drivers/usb/typec/Makefile +++ b/drivers/usb/typec/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_TYPEC) +=3D typec.o -typec-y :=3D class.o mux.o bus.o pd.o retimer.o +typec-y :=3D class.o mux.o bus.o pd.o retimer.o mode_selection.o typec-$(CONFIG_ACPI) +=3D port-mapper.o obj-$(CONFIG_TYPEC) +=3D altmodes/ obj-$(CONFIG_TYPEC_TCPM) +=3D tcpm/ diff --git a/drivers/usb/typec/class.h b/drivers/usb/typec/class.h index 2e89a83c2eb70..d3435936ee7c8 100644 --- a/drivers/usb/typec/class.h +++ b/drivers/usb/typec/class.h @@ -9,6 +9,7 @@ struct typec_mux; struct typec_switch; struct usb_device; +struct mode_selection; =20 struct typec_plug { struct device dev; @@ -39,6 +40,7 @@ struct typec_partner { u8 usb_capability; =20 struct usb_power_delivery *pd; + struct mode_selection *sel; =20 void (*attach)(struct typec_partner *partner, struct device *dev); void (*deattach)(struct typec_partner *partner, struct device *dev); diff --git a/drivers/usb/typec/mode_selection.c b/drivers/usb/typec/mode_se= lection.c new file mode 100644 index 0000000000000..63a1d251c72b4 --- /dev/null +++ b/drivers/usb/typec/mode_selection.c @@ -0,0 +1,288 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2025 Google LLC. + */ + +#include +#include +#include +#include +#include +#include + +#include "class.h" + +/** + * struct mode_state - State tracking for a specific Type-C alternate mode + * @svid: Standard or Vendor ID of the Alternate Mode + * @priority: Mode priority + * @error: Outcome of the last attempt to enter the mode + * @list: List head to link this mode state into a prioritized list + */ +struct mode_state { + u16 svid; + u8 priority; + int error; + struct list_head list; +}; + +/** + * struct mode_selection - Manages the selection and state of Alternate Mo= des + * @mode_list: Prioritized list of available Alternate Modes + * @lock: Mutex to protect mode_list + * @work: Work structure + * @partner: Handle to the Type-C partner device + * @active_svid: svid of currently active mode + * @timeout: Timeout for a mode entry attempt, ms + * @delay: Delay between mode entry/exit attempts, ms + */ +struct mode_selection { + struct list_head mode_list; + struct mutex lock; + struct delayed_work work; + struct typec_partner *partner; + u16 active_svid; + unsigned int timeout; + unsigned int delay; +}; + +/** + * struct mode_order - Mode activation tracking + * @svid: Standard or Vendor ID of the Alternate Mode + * @enter: Flag indicating if the driver is currently attempting to enter = or + * exit the mode + * @result: Outcome of the attempt to activate the mode + */ +struct mode_order { + u16 svid; + int enter; + int result; +}; + +static int activate_altmode(struct device *dev, void *data) +{ + if (is_typec_partner_altmode(dev)) { + struct typec_altmode *alt =3D to_typec_altmode(dev); + struct mode_order *order =3D (struct mode_order *)data; + + if (order->svid =3D=3D alt->svid) { + if (alt->ops && alt->ops->activate) + order->result =3D alt->ops->activate(alt, order->enter); + else + order->result =3D -EOPNOTSUPP; + return 1; + } + } + return 0; +} + +static int mode_selection_activate(struct mode_selection *sel, + const u16 svid, const int enter) + + __must_hold(&sel->lock) +{ + struct mode_order order =3D {.svid =3D svid, .enter =3D enter, .result = =3D -ENODEV}; + + /* + * The port driver may acquire its internal mutex during alternate mode + * activation. Since this is the same mutex that may be held during the + * execution of typec_altmode_state_update(), it is crucial to release + * sel->mutex before activation to avoid potential deadlock. + * Note that sel->mode_list must remain invariant throughout this unlocked + * interval. + */ + mutex_unlock(&sel->lock); + device_for_each_child(&sel->partner->dev, &order, activate_altmode); + mutex_lock(&sel->lock); + + return order.result; +} + +static void mode_list_clean(struct mode_selection *sel) +{ + struct mode_state *ms, *tmp; + + list_for_each_entry_safe(ms, tmp, &sel->mode_list, list) { + list_del(&ms->list); + kfree(ms); + } +} + +/** + * mode_selection_work_fn() - Alternate mode activation task + * @work: work structure + * + * - If the Alternate Mode currently prioritized at the top of the list is= already + * active, the entire selection process is considered finished. + * - If a different Alternate Mode is currently active, the system must ex= it that + * active mode first before attempting any new entry. + * + * The function then checks the result of the attempt to entre the current= mode, + * stored in the `ms->error` field: + * - if the attempt FAILED, the mode is deactivated and removed from the l= ist. + * - `ms->error` value of 0 signifies that the mode has not yet been activ= ated. + * + * Once successfully activated, the task is scheduled for subsequent entry= after + * a timeout period. The alternate mode driver is expected to call back wi= th the + * actual mode entry result via `typec_altmode_state_update()`. + */ +static void mode_selection_work_fn(struct work_struct *work) +{ + struct mode_selection *sel =3D container_of(work, + struct mode_selection, work.work); + struct mode_state *ms; + unsigned int delay =3D sel->delay; + int result; + + mutex_lock(&sel->lock); + + ms =3D list_first_entry_or_null(&sel->mode_list, struct mode_state, list); + if (!ms) { + mutex_unlock(&sel->lock); + return; + } + + if (sel->active_svid =3D=3D ms->svid) { + dev_dbg(&sel->partner->dev, "%x altmode is active\n", ms->svid); + mode_list_clean(sel); + } else if (sel->active_svid !=3D 0) { + result =3D mode_selection_activate(sel, sel->active_svid, 0); + if (result) { + dev_dbg(&sel->partner->dev, "enable to exit %x altmode\n", + sel->active_svid); + mode_list_clean(sel); + } else { + sel->active_svid =3D 0; + } + } else if (ms->error) { + dev_dbg(&sel->partner->dev, "%x: entry error %pe\n", + ms->svid, ERR_PTR(ms->error)); + mode_selection_activate(sel, ms->svid, 0); + list_del(&ms->list); + kfree(ms); + } else { + result =3D mode_selection_activate(sel, ms->svid, 1); + if (result) { + dev_dbg(&sel->partner->dev, "%x: activation error %pe\n", + ms->svid, ERR_PTR(result)); + list_del(&ms->list); + kfree(ms); + } else { + delay =3D sel->timeout; + ms->error =3D -ETIMEDOUT; + } + } + + if (!list_empty(&sel->mode_list)) + schedule_delayed_work(&sel->work, msecs_to_jiffies(delay)); + mutex_unlock(&sel->lock); +} + +void typec_altmode_state_update(struct typec_partner *partner, const u16 s= vid, + const int error) +{ + struct mode_selection *sel =3D partner->sel; + struct mode_state *ms; + + if (sel) { + mutex_lock(&sel->lock); + ms =3D list_first_entry_or_null(&sel->mode_list, struct mode_state, list= ); + if (ms && ms->svid =3D=3D svid) { + ms->error =3D error; + cancel_delayed_work(&sel->work); + schedule_delayed_work(&sel->work, 0); + } + if (!error) + sel->active_svid =3D svid; + else + sel->active_svid =3D 0; + mutex_unlock(&sel->lock); + } +} +EXPORT_SYMBOL_GPL(typec_altmode_state_update); + +static int compare_priorities(void *priv, + const struct list_head *a, const struct list_head *b) +{ + const struct mode_state *msa =3D container_of(a, struct mode_state, list); + const struct mode_state *msb =3D container_of(b, struct mode_state, list); + + if (msa->priority < msb->priority) + return -1; + return 1; +} + +static int altmode_add_to_list(struct device *dev, void *data) +{ + if (is_typec_partner_altmode(dev)) { + struct list_head *list =3D (struct list_head *)data; + struct typec_altmode *altmode =3D to_typec_altmode(dev); + const struct typec_altmode *pdev =3D typec_altmode_get_partner(altmode); + struct mode_state *ms; + + if (pdev && altmode->ops && altmode->ops->activate) { + ms =3D kzalloc(sizeof(struct mode_state), GFP_KERNEL); + if (!ms) + return -ENOMEM; + ms->svid =3D pdev->svid; + ms->priority =3D pdev->priority; + INIT_LIST_HEAD(&ms->list); + list_add_tail(&ms->list, list); + } + } + return 0; +} + +int typec_mode_selection_start(struct typec_partner *partner, + const unsigned int delay, const unsigned int timeout) +{ + struct mode_selection *sel; + int ret; + + if (partner->usb_mode =3D=3D USB_MODE_USB4) + return -EBUSY; + + if (partner->sel) + return -EALREADY; + + sel =3D kzalloc(sizeof(struct mode_selection), GFP_KERNEL); + if (!sel) + return -ENOMEM; + + INIT_LIST_HEAD(&sel->mode_list); + + ret =3D device_for_each_child( + &partner->dev, &sel->mode_list, altmode_add_to_list); + + if (ret || list_empty(&sel->mode_list)) { + mode_list_clean(sel); + kfree(sel); + return ret; + } + + list_sort(NULL, &sel->mode_list, compare_priorities); + sel->partner =3D partner; + sel->delay =3D delay; + sel->timeout =3D timeout; + mutex_init(&sel->lock); + INIT_DELAYED_WORK(&sel->work, mode_selection_work_fn); + schedule_delayed_work(&sel->work, msecs_to_jiffies(delay)); + partner->sel =3D sel; + + return 0; +} +EXPORT_SYMBOL_GPL(typec_mode_selection_start); + +void typec_mode_selection_delete(struct typec_partner *partner) +{ + struct mode_selection *sel =3D partner->sel; + + if (sel) { + partner->sel =3D NULL; + cancel_delayed_work_sync(&sel->work); + mode_list_clean(sel); + mutex_destroy(&sel->lock); + kfree(sel); + } +} +EXPORT_SYMBOL_GPL(typec_mode_selection_delete); diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_al= tmode.h index 7e6c02d74b54f..89b285a4ee7e6 100644 --- a/include/linux/usb/typec_altmode.h +++ b/include/linux/usb/typec_altmode.h @@ -240,4 +240,44 @@ void typec_altmode_unregister_driver(struct typec_altm= ode_driver *drv); module_driver(__typec_altmode_driver, typec_altmode_register_driver, \ typec_altmode_unregister_driver) =20 +/** + * typec_mode_selection_start - Start an alternate mode selection process + * @partner: Handle to the Type-C partner device + * @delay: Delay between mode entry/exit attempts, ms + * @timeout: Timeout for a mode entry attempt, ms + * + * This function initiates the process of attempting to enter an Alternate= Mode + * supported by the connected Type-C partner. + * Returns 0 on success, or a negative error code on failure. + */ +int typec_mode_selection_start(struct typec_partner *partner, + const unsigned int delay, const unsigned int timeout); + +/** + * typec_altmode_state_update - Report the current status of an Alternate = Mode + * negotiation + * @partner: Handle to the Type-C partner device + * @svid: Standard or Vendor ID of the Alternate Mode. A value of 0 should= be + * passed if no mode is currently active + * @result: Result of the entry operation. This should be 0 on success, or= a + * negative error code if the negotiation failed + * + * This function should be called by an Alternate Mode driver to report the + * result of an asynchronous alternate mode entry request. It signals what= the + * current active SVID is (or 0 if none) and the success or failure status= of + * the last attempt. + */ +void typec_altmode_state_update(struct typec_partner *partner, const u16 s= vid, + const int result); + +/** + * typec_mode_selection_delete - Delete an alternate mode selection instan= ce + * @partner: Handle to the Type-C partner device. + * + * This function cancels a pending alternate mode selection request that w= as + * previously started with typec_mode_selection_start(). + * This is typically called when the partner disconnects. + */ +void typec_mode_selection_delete(struct typec_partner *partner); + #endif /* __USB_TYPEC_ALTMODE_H */ --=20 2.52.0.457.g6b5491de43-goog From nobody Sun Feb 8 23:37:03 2026 Received: from mail-ej1-f66.google.com (mail-ej1-f66.google.com [209.85.218.66]) (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 874813904C8 for ; Tue, 13 Jan 2026 13:05:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.66 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309561; cv=none; b=raGMzhTzoip5/PIKuXq3LzQx9xJRdpmLkTA4XUyIkTkg1gBqV9iP1Dys8cjJO/OM9Qf6TsWZ8T7R0Mjeq4wtAxpkz4N+1hvqqB0CGWmb6+9nDsspvhtOCIwEcsHn//F0MEsYmjJpjaO0SDl285fL5f6T61xntwh7tE1mxEF7V4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309561; c=relaxed/simple; bh=PBxq1XtnNJDHu6QLFTPbS6fcZBdgfVFC9T9kO3oXU8s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fmy76yqjBJkIgrY4sTkkO4Fr2eiYXU8inLE8FgCGkAfigCiWMCn3OTzQJMbvNEs8RfTER3imMewxas/1ePJhrkLxYToegwmZcbJ+pZbuleacmS7PzY5bprVYrVAd3pL9QEjjirHRw3ec51ZH+qvSbrCckeOhIacI5FEWMKFeIH4= 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=Mj5Fjztq; arc=none smtp.client-ip=209.85.218.66 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="Mj5Fjztq" Received: by mail-ej1-f66.google.com with SMTP id a640c23a62f3a-b86f3e88d4dso389306366b.0 for ; Tue, 13 Jan 2026 05:05:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1768309556; x=1768914356; 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=JexYB6ufnP2njfyWsSs8jFTtDnvJKYKAr3d1TGCGR/Q=; b=Mj5FjztqrNZA8BrHquTm+eMBlOH5i2XkFHbTVDZHWD/SNYBZ/LIieUdFS5tva1t5S+ mgrk7X+XNiVhgvi+miJOnVulbOjRYic0S2L+ZIiHsegNmJx8f/EpejtBq0qN7+aLiD1U A/R0qFaCiaY8yg1y8NQlT/9MEs8sUsXYkhPfY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768309556; x=1768914356; 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=JexYB6ufnP2njfyWsSs8jFTtDnvJKYKAr3d1TGCGR/Q=; b=d8FjoQD2U5/nMT9QNI21TLn7DviWXkFXJNABuTV63nv6WRrg/hxHVMRHi2VMtSQwjs 1EvFiikyn9oIVmgiHzFLVSf8KBMIjtUcH9zm1OnTu7l2z3M/wQig+XpdjPvio1Z8R6z6 Q2P0X6TmkAQPHRWy9hIw9L/CYVScebv2NZwTLvTWCueh9Xlf5AqU3eL9ViZJLMCezxBV X+HkKHjp4V/j9yM5zhu4e/0sPNOw/G4MWTg5xRIt7hJsmtKrXDurOZIZuXcngHlgjgfL a2oevKNPSPvVop6JDfmG7f4yUabWx1fvyx1dX9uGsiddIrgl38kr4GsoQ6f4+l4jr/Gd neZw== X-Forwarded-Encrypted: i=1; AJvYcCV22cM2EgSTnDrPrRgqZhgRp1i7MtM4okDYi87SdDkuGme3i8eI3b1Ifz8upyGZ8HYp+NTl5J8iL4LNGjE=@vger.kernel.org X-Gm-Message-State: AOJu0Yywof2nHdYix1RfF8R6miFwpIYnQIkKLjDP8gxE9RhcKhnzFpdo +qrrFRFafDUxL8rBeDIdTmGITt55NCMEUyqaJm/w/+fEf0Ex5h02KY1eLwDBgTTAoA== X-Gm-Gg: AY/fxX4sZTmZ56g5AgheDm4xxfqqb75uoeHIn203WF67qpwjz4dwzc1HQsPO2Ypz5Ok mQxV8OZI+yT+DK8NLNQD0vnTIu4Ya5deDHzCUMWJ7z6EV4wAPxF0mFwB9uyWrabLNTblHbhEoyR wMDb87c9Kn2MMsIiZjaU91W5vl5DMAS3erFs+rYHIHN1RRoG/1DtBdetBHiHUJSu49zbDpwOq8u GUWu+8wAH69qtsrGw7dSpqKjgbDJb7sTQAOJC9uIvnRb1/FiakDKAlrn+BcHZ9XmTP1HYwWUaxA TJZmfIZ1+sgC46mKF71kdG+WCucPIi2TiY3HYxvQM0V42+28k2gprb6H46VsO95WRZKOZthAhx8 s+6pm2KVWrXmwBrrZS9SfLhZl8mejU+V2Vk3JKp+8FD0UgQXXIbfZ1VsLfE6EEnUypCABexRgCe aFGFTIzH5dXIccBKQ7F5L9RQbbqMcMet9wv8MfM6w/e6YvSEdl+Yn3NA9sKDKj13/XhHXBlvHmY YapammPSfdOeF51FyM= X-Google-Smtp-Source: AGHT+IFTvE3kPXoaMFaHVoxvyk8+opt2tAgG+Q3yLoEc+MEmRNu8mDVwkVmFMuobpUoOnxGKBIsrcQ== X-Received: by 2002:a17:907:702:b0:b80:3846:d46 with SMTP id a640c23a62f3a-b8444caab67mr2155678166b.20.1768309555953; Tue, 13 Jan 2026 05:05:55 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jan 2026 05:05:55 -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 6/8] usb: typec: Introduce mode_selection bit Date: Tue, 13 Jan 2026 13:05:34 +0000 Message-ID: <20260113130536.3068311-7-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" The port driver sets this bit for an alternate mode description to indicate support for the mode selection feature. Once set, individual Alt Mode drivers will no longer attempt to activate their respective modes within their probe functions. This prevents race conditions and non-prioritized activation. The bit is not set by default. If left unset, the system retains the current behavior where Alt Mode drivers manage their own activation logic. Signed-off-by: Andrei Kuchynski --- drivers/usb/typec/altmodes/displayport.c | 6 ++++-- drivers/usb/typec/altmodes/thunderbolt.c | 2 +- drivers/usb/typec/class.c | 1 + include/linux/usb/typec.h | 1 + include/linux/usb/typec_altmode.h | 1 + 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/a= ltmodes/displayport.c index d96ab106a980b..d185688a16b13 100644 --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -804,8 +804,10 @@ int dp_altmode_probe(struct typec_altmode *alt) if (plug) typec_altmode_set_drvdata(plug, dp); =20 - dp->state =3D plug ? DP_STATE_ENTER_PRIME : DP_STATE_ENTER; - schedule_work(&dp->work); + if (!alt->mode_selection) { + dp->state =3D plug ? DP_STATE_ENTER_PRIME : DP_STATE_ENTER; + schedule_work(&dp->work); + } =20 return 0; } diff --git a/drivers/usb/typec/altmodes/thunderbolt.c b/drivers/usb/typec/a= ltmodes/thunderbolt.c index 6eadf7835f8f6..c4c5da6154da9 100644 --- a/drivers/usb/typec/altmodes/thunderbolt.c +++ b/drivers/usb/typec/altmodes/thunderbolt.c @@ -307,7 +307,7 @@ static int tbt_altmode_probe(struct typec_altmode *alt) typec_altmode_set_drvdata(alt, tbt); typec_altmode_set_ops(alt, &tbt_altmode_ops); =20 - if (tbt_ready(alt)) { + if (!alt->mode_selection && tbt_ready(alt)) { if (tbt->plug[TYPEC_PLUG_SOP_P]) tbt->state =3D TBT_STATE_SOP_P_ENTER; else if (tbt->plug[TYPEC_PLUG_SOP_PP]) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 1fb5450c0a2f2..9b9254350733d 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -655,6 +655,7 @@ typec_register_altmode(struct device *parent, alt->adev.svid =3D desc->svid; alt->adev.mode =3D desc->mode; alt->adev.vdo =3D desc->vdo; + alt->adev.mode_selection =3D desc->mode_selection; alt->roles =3D desc->roles; alt->id =3D id; =20 diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index dbb259d885266..d61ec38216fa9 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -155,6 +155,7 @@ struct typec_altmode_desc { /* Only used with ports */ enum typec_port_data roles; bool inactive; + bool mode_selection; }; =20 void typec_partner_set_pd_revision(struct typec_partner *partner, u16 pd_r= evision); diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_al= tmode.h index 89b285a4ee7e6..4bde80e4c9b0b 100644 --- a/include/linux/usb/typec_altmode.h +++ b/include/linux/usb/typec_altmode.h @@ -37,6 +37,7 @@ struct typec_altmode { u32 vdo; unsigned int active:1; u8 priority; + bool mode_selection; =20 char *desc; const struct typec_altmode_ops *ops; --=20 2.52.0.457.g6b5491de43-goog From nobody Sun Feb 8 23:37:03 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 From nobody Sun Feb 8 23:37:03 2026 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 54DB53904C2 for ; Tue, 13 Jan 2026 13:06:02 +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=1768309569; cv=none; b=WJ+BMhcbZJl6i+2AG2Y+KFDPKDJkKhxrnFTT3MamTSseARzzOTnoGR8g5EiBqLvSu6qLAWvVjCCWEqiPu0V2Hpv/Aa/d5DFSXlrQE6ta/Oq5fh8AablidSrPtXCdFZE5alBFuduWL2e4kenPsnGV83hAMcyYkZDHF+wdTcuW0G4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768309569; c=relaxed/simple; bh=xDKAaqJEsHbZnL+cmpHT9aD/t1xQZpYd2AXwHmw7ASc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eOz+MwVUhaBJXLvQzozBaobBj3kGauNZF4I1a2bt7Tm4+gJuF/DOYVm/WbgN+qqirH4ZIgVDa4XKaRyKjbKtJi2ohVL6RR+YfanO49HIkLBjPgeR8pCaivNoYwacfzdXmlaV3NJtWgZEMEC+oCf7WVDgCH9tOJk0PS9SnByAdnI= 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=DAPXqVLP; 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="DAPXqVLP" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-b86ef1e864cso367264666b.1 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=1768309560; x=1768914360; 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=ozHGUyiY6A9TybEdpmpfYkpaTQz6PtmOWnadeDhNFJQ=; b=DAPXqVLPu8jR3x+rx06HshbcAW+Ev1JU3FrRRNCMib6vvz94JCDzkFfS6MRRm3HV8I XL3m+aEybIOsi8XATyQS9BlhRuBQ2gm4nOGgdJ3z6d+koD1MPta0n136Nt9Z26TOL0+Z Zl/cRW7z7ljRcxdXV4/DY75PM7UoXaS0PwFFI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768309560; x=1768914360; 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=ozHGUyiY6A9TybEdpmpfYkpaTQz6PtmOWnadeDhNFJQ=; b=Wbuop5tiiYzFvsIUWvvJ7Hx6n160TfEWViSA1sD2aVmk9CFroTOAjJmEtD9F3Wcpyn AteGb8obG2PUogkYWf4ulXkJW7VMKHeNKlc/fJURN2iNOSlQjAuEm45PGtXbjhmNrc/W xBqZaRShj+6UWL+KOfjeVyMd5wLv10SabzKJWkZJDDStcpodBPrlr/6FFvp82nsrzWNV Vfqd5uMb/IbOmCKiHt/+2Ik5DdRISv71qXWS770PXhDyjCXeuzk+q8PF7CnQGzeak10m gq8cRnMxFhvipjYFgQLf/AwiE3mT7spYO8y/xtKaQIZgzw9EsQmiywb0k1DL/ANae8rR AG6Q== X-Forwarded-Encrypted: i=1; AJvYcCXd0EQVFd0TjLHoSmd3uC/a7lxmIQjte3j8eatuqS74OPbdiW7OjRjy28FLcfwwNYpgvQNd22IC1sV9arY=@vger.kernel.org X-Gm-Message-State: AOJu0YyC/iq+PPzB/dkfZEhowcFL/PMHndQ7qBSuqB8T97krJK1Nkj39 5QDrLsFft/ESUjhtS/uj5rCE6Z2wj0u3ROSu4EeN814stAQngi35XR/wRHKBd8Q8UA== X-Gm-Gg: AY/fxX6+mKyV8Amj3oos76EIOS+we6/gn8G2/5ZUHyj58atVoNykuM3SoP8BoS4x+SR yG13lF01PDXNY5DJj/vpY/W/v/fNuJDihrs03lOPud6ePoV5C69R0CEQIELBUq8V2qopcJuaNhH bGjO8kNsbocdFHwYUvA+qnR2LUTufYgQLqQqboxdrFoGC43OFjmf/vGz5XGHlQf6eBJ0p2Y50ol GGwhqkHnr3Vmip09gkG3U0GHL0EZ3P5QflTEiWrUgKy5KZDR/vp2D2b9ATjHPsFwYlpQfLJ3kGU AX9FKEGDH0iAbHDZMetWtdlegjos3fLz0D0Ked6vH13+LCAQr0VtpeCUCqTXS/VG18pf7a/EbND CFXAgQgEJ1y156L5hGAVV1gQDhwoHnVT1kbXTrRCk9lke06neGqRXlhY3vOVGaYGbVbvUI14n9J DqMV8liJg0Fhy3Z/hidzqEF8qwNUATLsXNkIcPcok4qeflDbD7VWB6sd7/e/IMn+YKrED+VukIb ZyCwVBY X-Google-Smtp-Source: AGHT+IERLF4PHZwh7YhwuDFtdlx0ez3BDip2EOvxGlTqLDh5wkJQ8ZMkQJAb5HRrvhsdbkq8VQofMw== X-Received: by 2002:a17:907:780b:b0:b87:1fe8:9534 with SMTP id a640c23a62f3a-b871fe8af72mr384125466b.48.1768309560490; Tue, 13 Jan 2026 05:06:00 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jan 2026 05:05:59 -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 8/8] usb: typec: ucsi: Enforce mode selection for cros_ec_ucsi Date: Tue, 13 Jan 2026 13:05:36 +0000 Message-ID: <20260113130536.3068311-9-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" The mode selection sequence is initiated by the driver after all partner alternate modes have been successfully registered. 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 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/usb/typec/ucsi/cros_ec_ucsi.c b/drivers/usb/typec/ucsi= /cros_ec_ucsi.c index eed2a7d0ebc63..437a2982a9d51 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; @@ -134,6 +140,19 @@ static int cros_ucsi_sync_control(struct ucsi *ucsi, u= 64 cmd, u32 *cci, return ret; } =20 +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); +} + static const struct ucsi_operations cros_ucsi_ops =3D { .read_version =3D cros_ucsi_read_version, .read_cci =3D cros_ucsi_read_cci, @@ -141,6 +160,8 @@ 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, + .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.457.g6b5491de43-goog