From nobody Thu Oct 2 19:27:59 2025 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 E201C298CA3 for ; Fri, 12 Sep 2025 06:48:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757659682; cv=none; b=DvTZkxsle+yLymcDRXTf9xw8Jv/Be6aT8m/tEN8EwUmzz2encQF8GTnV3P8g0Ta1DWMDsJCDqs1s85QlohsfiTw93BaGenxc/d4RXhrQ+NsSvUuGJSx10kiNeQDWtasFFjaZBoRWPvogDlHrTRsv0Wr7Maf6xl5NeHrETUTAmhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757659682; c=relaxed/simple; bh=9TpjhbJBttEeS1KmCJosi4Hh395qIeJ+0k53azp1Q0Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IgIBPOMtNX4oCjIpWHjrhclx/AKcxEQhuiAdGfPLNTLlamkxP8TjxE/PGvWtcpGhLpUgXcIi+yENItkMgx7oOe7aFc9PrrLTKec09n55/iNwohTLt6qtXzkQLKCjDbhnYM15vs9i94juEZUEDeUhXQMTwjvfLg859QrA4SJTwh0= 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=Ori/PK32; arc=none smtp.client-ip=209.85.218.50 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="Ori/PK32" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-b0787fdb137so225792566b.0 for ; Thu, 11 Sep 2025 23:48:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1757659679; x=1758264479; 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=faD29vPc8TtJSIlMGbZZx8zq4usFD6uCUoteS6fd/xA=; b=Ori/PK32m0qecDiURF5UbohhVhLpLD7bJ5olQjAd28TQOk8JN5wH+NvtWXpKPs08Xb X/GYUk3CFtrX0H8WR//izJcZVc/Yt7ZYoiDNzVt+1QJoaOyePgjkLWYSp6HqDBkgQ9k+ DJLr3JZTdqFTL/YIx3HjkQzNC4uzTl9nFuTwY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757659679; x=1758264479; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=faD29vPc8TtJSIlMGbZZx8zq4usFD6uCUoteS6fd/xA=; b=FQOKrNX8cyaqdfhBLi/0DgeJK+Pi2yjFa0IqAxqt02/H+FqKBpBLgfmNq90XFA7JcD 4LrQJQ9X2GznwYtV4ZdYkozvYn7TDnqbHWLr1rGVYsvVGxOHb4L2QNaPTNypbwX8gS/d FceGnkHfsksO5IZCz2v/6iyMGoZ8xLoSxsx8XRVRLXBPPJephEyZmXmakyEME9CgRq8J /6WYSadgOjNHjyUlm2oQMfu2MIyQYPeB3TVx3mMJvS5U7L2e0U1fwIuK9yICP1jEd8Wa PgiDBy3Bfw8MU85HC8hXucjetjnTxOFd+y7ZDYRVGusUjNuFkXVbbTQI68D84BqFJPjA EwLQ== X-Forwarded-Encrypted: i=1; AJvYcCXDHnqb6qdBTKfU0X9j1mxV1dKOk9cmw4SBtAfR7ZGrFZdRS2hAzeom0CLV167DTTfHMNWbO22wwR5qGh4=@vger.kernel.org X-Gm-Message-State: AOJu0YxYpJmmytoWUkSIsSqVnUTQGrfVqHDioLvKwV5iXP6nTK8l2ajD rhSty4zbjqi6p+tBA5Z0P82A9wAUG7hSdlU5Oa9FFd4IcN9Val7pd27xOlvthIE4Ew== X-Gm-Gg: ASbGnct1EBzbStoY/uECYXUflKMw1K1f9onoW1XuDk8n3k6Z3v6j/QoER4s/lccNyeA CWZGwErpX/+coXrPOYL4VumxP+x8/uO6HtfnAPZ4+lAru6SOzCL2jBOgOluWbIFqSmJ5WM4C3Px juFVVE8HiQPJBX9fc1chQpOlX06J2ybqz7/hyeDF2UD9EySCWW7jEYY4sG+XqotpQ8vdsdJ5MkK W+QYzBDqOI9bMxEApKXZHXruJA63N1UUHzaRV0LImfbcpKWKVBF0iz6ZBmaVY9XtTGkjuvLWf+7 oh8NUTgLKaWiSYInyKbR/W8NRgCtOnXTPfyRfzblaOio86mbPAZ+Dhu4DJD1ejq88uU5/QD/RVZ IRlnVlhv/XdxKWOACrjHM+8Sb/z9X48JrSVX0kzwFsn7+/+0BjQv2oyLescQT9WU65FcuckRSJW awv1yJHQSgvcfLbhqFBtgHglxMkA== X-Google-Smtp-Source: AGHT+IFx9ydYE5CesosJBDmvUWYyToOaRt9RCUyztzIS5eLFbP6lDhD0TsJXKbVlqYDJqGhNfxzUgg== X-Received: by 2002:a17:907:6d21:b0:b04:bfda:e457 with SMTP id a640c23a62f3a-b07c3a7b8d8mr152607566b.63.1757659679234; Thu, 11 Sep 2025 23:47:59 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (240.225.32.34.bc.googleusercontent.com. [34.32.225.240]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b07b3128a1esm295465366b.29.2025.09.11.23.47.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Sep 2025 23:47:58 -0700 (PDT) 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 , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v4 1/4] usb: typec: Add mode_control field to port property Date: Fri, 12 Sep 2025 06:47:48 +0000 Message-ID: <20250912064751.1987850-2-akuchynski@chromium.org> X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog In-Reply-To: <20250912064751.1987850-1-akuchynski@chromium.org> References: <20250912064751.1987850-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 --- 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 67a533e35150..9f86605ce125 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; } @@ -2681,6 +2683,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 db2fe96c48ff..2e89a83c2eb7 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 252af3f77039..8f51665d44ec 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -287,6 +287,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 @@ -304,6 +305,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.51.0.384.g4c02a37b29-goog From nobody Thu Oct 2 19:27:59 2025 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 4FEFC287510 for ; Fri, 12 Sep 2025 06:48:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757659685; cv=none; b=IU0rJwgy00ppHYUwopQSAIMohhShLfPA3t2VksVr47PAcDEiHrESHNrRLYeLvTZJkUgw8nsxPFcO+rlxXaIfBgo2paXBQPnJTQTb5XGPpYydCn/5IQLNiuvld1fjFQkgV3ia8I0a31xuomclyEpI2yVbxFfqQ1X5DGOC4UXEpwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757659685; c=relaxed/simple; bh=6KQEugjnx2rJCM48+qtPictQnwqObzm5rcbLajzHMU4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HGk1KeNN+Fe51X0g/PnkBqFZJ0T+AWiNO0x7miBF4zchhPnsUQUMifNqKgjCpTv7EXpIr8sW6t4ydhlRv76I0CMCV51xloC6Mx+RuH8Z0LmfEzOLppcqV3owlqzdVpk8h/mzlHtB/iZcF/ujycdWEQKkFkpJvaNctWwwAD0oRvw= 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=Kh9zipaZ; arc=none smtp.client-ip=209.85.218.51 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="Kh9zipaZ" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-b046fc9f359so236538166b.0 for ; Thu, 11 Sep 2025 23:48:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1757659682; x=1758264482; 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=/NeNrKd6NoBbgDfjKGLBumkxmas+f61lF0BwvgkVNtg=; b=Kh9zipaZxajVGH4xeN3ClG+zRHVb3Y+jlk/+SdO/tjmygNYJQa29LOkZsepxHUwuTv l6x24eCmWHrmh9AVWcpoE/GK1ETizP5gbC10GREXP+iBEQAU5VJ90LFXRonc5K1Z/umk DtrWByY9SyhMon+UTMCxRIr/ChaoRai0H69lY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757659682; x=1758264482; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/NeNrKd6NoBbgDfjKGLBumkxmas+f61lF0BwvgkVNtg=; b=M6MfkFIZ6D2EvXLe7Vqxu0SktxrgJsya7j1bZj0s7njaglcamLbTYFdtLzhCfoxARX KjanQgg7HN8BrswEeEASDpzFbEmpxQfW9vMVSwx/xeuXcF0mxVlxAcMcdXnUbqvh9uLg 1x7o5eIUfBocASiTmofbQMR3z0hBHVugwipzpDPOrQUpOTtyUh012MWPV3sfINIYeCTw +Fo3GthjeP+Hc9tjNPqz8lCApC25issrL97toDvSRnnOt2QpSl4eVgS+QbIJokVo7cL8 0xkW/O2aqINqdUj06yoo/zcyG1MsrbA3Y0hkcRDTLzXhjAeu0Ipk7pcZ7texYO6be98T L2xA== X-Forwarded-Encrypted: i=1; AJvYcCXO+4OYo9HgOR5xdCvgx2Aw7/waKXsCinfoc9iQ1lswGErmx5GAPX6etkRALwYn799k7u5KzaMrow+/HtY=@vger.kernel.org X-Gm-Message-State: AOJu0YxT8ETt3f9Fqx6E3VcGitGmgNI8E1NrvwoxG6kgDm9EOJOtlIzA jUhMmQVpdi33ls30afCz+MVT6AV4CZdNkS3biFU6FmwYtljMp/IhAwx+0nsUzOpezw== X-Gm-Gg: ASbGnctY7D1E9mCoDWBgxr0ei00q2tVzoOSkDGzkwZ6sbtAyxZ423K/kjERO4+UjuZO LIt8hNS/7AOyEPIesbpvXRaQ9TA7aLKZ6kEt/kd9wfsHDK8MiNVYr9I5biCER1V+cYoGsYoFRxJ cSCVp8yq7W4J8Gq2k4qjGM5ghq3cJlxMP8MY9QHd/eajLdtpzNgeHMQlo8b9eBB+BSZT8FCkorn vUls/ujDQX/R5kG07BYndtQgFwNOZ48OVvPbvVEi2aK5Hr5wSA7Iz+GveJkwBdgj7iUsSF8B2Cg SxCHfrGmENjUwQc0aW/mHZ/SoIaw06Ie7WLMWSp4KSP7LaTv64jU4X6jBVy5toKQzuP/OIzTkMW W5puxOFwZp2dhEY83tm0UdZhoJ4S7KQhZmq3+Wn9c9/OoFWOW9gYmcy0Y7SzWVfR0oIW9uVXwKk a+M/aGjGgdiEoORUE= X-Google-Smtp-Source: AGHT+IG1I03T5HSq2OfkiQuee3J0Y3gSkDAX+xUtryPFhxhfXEKh52whMlG6mWqFElm4wgmiKoe2Pw== X-Received: by 2002:a17:906:794d:b0:b04:8701:7304 with SMTP id a640c23a62f3a-b07c3546e64mr171386666b.10.1757659681595; Thu, 11 Sep 2025 23:48:01 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (240.225.32.34.bc.googleusercontent.com. [34.32.225.240]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b07b3128a1esm295465366b.29.2025.09.11.23.48.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Sep 2025 23:48:01 -0700 (PDT) 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 , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v4 2/4] platform/chrome: cros_ec_typec: Set no_mode_control flag Date: Fri, 12 Sep 2025 06:47:49 +0000 Message-ID: <20250912064751.1987850-3-akuchynski@chromium.org> X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog In-Reply-To: <20250912064751.1987850-1-akuchynski@chromium.org> References: <20250912064751.1987850-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 --- 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 b712bcff6fb2..c0806c562bb9 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.51.0.384.g4c02a37b29-goog From nobody Thu Oct 2 19:27:59 2025 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 AAB452BE64A for ; Fri, 12 Sep 2025 06:48:05 +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=1757659687; cv=none; b=JYpPb791GJ6QK7eayA7qAfdSNlPAjuZyFqL5M51tuAfHmzBNBxbFxerXv6+C9BFbecRnoZl45Fxu4OusujB7ZdYJubp/DmNla4WzWpVoHJ0EV8nlIH9kq9+xG+IXp5hZLK7asIM+SxqYIo0vzqDLXv4gTc2UFvymFUPdryxQo8s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757659687; c=relaxed/simple; bh=DUPoh4Zyec6Zt7EqJ5e3ik3Z5aBUkLkTB6W4xkQH9DM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jHmZtxXS24UPtsKX3G/W7hX6BZ/oTf5Rs5jLXWz3MYczYHmgX1SQNe6vtuzHH+VNe2faQODrwE3rh1NTLsd1EznyY4ydSZS/LRh7cpK62QAi+Fn5xW20aZ8GdTEgQqDP/iZvNpn5bySMmsNN3Gdc6U+joj24BpcSCoUfMDnx48k= 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=ca8uOeGn; 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="ca8uOeGn" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-b079c13240eso250849266b.1 for ; Thu, 11 Sep 2025 23:48:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1757659684; x=1758264484; 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=9NvADMrt6HurTsoe+Lfqu7ifPRq1qi6pH7Zq/9XUUt8=; b=ca8uOeGnXXxsicS323wJ9Wgub4BL+OtascBdAq8pCWyy4BuuyHIzNTEVPFKAFDUNlG HwbujBgxaioMKvnLwFoLZIqgm3rFFxv8//0P3N2qAPXixpWW+QB4DEh2d79F2/RPIUvB pKVJzrWUUL7qN5SSh6ABRq/kFvWuJ7kVpwsBo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757659684; x=1758264484; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9NvADMrt6HurTsoe+Lfqu7ifPRq1qi6pH7Zq/9XUUt8=; b=J1iqT4HsiWBMDNIMfz+eZqrs0ib0Lhi5shTXacU7ikZTnXz8y45PSS1f1li6oJPjMA fHLxft9omw41rEePqcgtlBIHELlnLBpWbUvWjVGLJogjLfa+C9waqCBp1oDvHGCXNCSZ GSFlOe3xyFh6r8rVv/99zzwJePdEbqweB6I1s/Rl69MFyQKZ9f1wI1AfZlWicbGyOxjA TO80KhexXc5g2BUadwXBnbE0/VcamuRnGETynwp8rw/15ztw6SzOiv9XD6N6cB670Mrg oclelBapZ12sQHHxonWktkVXcYPX9oEPttpEeKbfYsIEMj4xyDOHoZHy9Odh2pm8z9mH E9Pw== X-Forwarded-Encrypted: i=1; AJvYcCW3IA6Ho4+Gd84CR/cxoXlPiPagNGFytF0AXjL5o02C6FuH7aFcIJKSoxbO53527795aOxcvRYtIuzzy1U=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2OwVJpdKRxEDH1bXi9GCYrTzS/OgWE5w6g0NmwVP5gVrjNIsu NE4TgONKBTDD9XCMZYF3Kz7RWlPcfZLbSV44l7+ARjjG3xH6cwz7mmAK9aTiaQ0wFw== X-Gm-Gg: ASbGncsDFwo190WX+ulTiEuRLXwXfUglfL8MBiGiKbxrg30C0Sad8zvaHInK7Tx5CB8 IZt7Kw/AjikHNcJ974EqTCVNmw5WOrto11Gau0LF2JXmMgqtGUkGEH04lf13N5Knj2adG2/vBRA KXDuSAwai+hJ62smet/JnfxIs5t+P8zDc0R0UvrrS7i8tOHhdQzkiZi/2zqz0o7dRR+LW9Bkh0s VYfYuvmx9tpKEFZw5MJ01YT7IlkOhxLjltd+dvngCB7lDpfGvUZl2DhkLfpma3H8yrPlQclZdBP roeWsnsEnX1meknmQJXhecdMrfBTzK5cYRs+ucMFoVfVwVuFnYtDz9LcuUvXk4V+LC6uytck/Wn JwiZiQ1WvM4N5gespj6O6Zce3Zmm5uXFLu6oJULECCcZnZArOHrtsEMm+qZaGqKYPDO1lKb6UOQ jQR2t4oVVEtj+8LLlLSkrUEU+Bhb/GlI4r5O07 X-Google-Smtp-Source: AGHT+IHO5xX13tdxcN9DsT2lG0RauabvfBllR6+E3bjJfEFfjTIbdd3fJBDvYLD+ZC7qjjUCzN9HRQ== X-Received: by 2002:a17:907:7e9a:b0:afe:ea93:ddbb with SMTP id a640c23a62f3a-b07c38673ccmr167104066b.45.1757659684076; Thu, 11 Sep 2025 23:48:04 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (240.225.32.34.bc.googleusercontent.com. [34.32.225.240]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b07b3128a1esm295465366b.29.2025.09.11.23.48.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Sep 2025 23:48:03 -0700 (PDT) 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 , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v4 3/4] usb: typec: Implement alternate mode priority handling Date: Fri, 12 Sep 2025 06:47:50 +0000 Message-ID: <20250912064751.1987850-4-akuchynski@chromium.org> X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog In-Reply-To: <20250912064751.1987850-1-akuchynski@chromium.org> References: <20250912064751.1987850-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 APIs to manage the priority of USB Type-C alternate modes. These APIs allow for setting and retrieving a priority number for each mode. 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 --- drivers/usb/typec/Makefile | 2 +- drivers/usb/typec/mode_selection.c | 62 ++++++++++++++++++++++++++++++ drivers/usb/typec/mode_selection.h | 5 +++ include/linux/usb/typec_altmode.h | 1 + 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 drivers/usb/typec/mode_selection.c create mode 100644 drivers/usb/typec/mode_selection.h diff --git a/drivers/usb/typec/Makefile b/drivers/usb/typec/Makefile index 7a368fea61bc..8a6a1c663eb6 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/mode_selection.c b/drivers/usb/typec/mode_se= lection.c new file mode 100644 index 000000000000..048e3f75efa5 --- /dev/null +++ b/drivers/usb/typec/mode_selection.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2025 Google LLC. + */ + +#include "mode_selection.h" +#include "class.h" +#include "bus.h" + +static int increment_duplicated_priority(struct device *dev, void *data) +{ + if (is_typec_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_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; +} + +int typec_mode_set_priority(struct typec_altmode *alt, const u8 priority) +{ + 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; +} diff --git a/drivers/usb/typec/mode_selection.h b/drivers/usb/typec/mode_se= lection.h new file mode 100644 index 000000000000..7f027d591cdc --- /dev/null +++ b/drivers/usb/typec/mode_selection.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include + +int typec_mode_set_priority(struct typec_altmode *alt, const u8 priority); diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_al= tmode.h index b3c0866ea70f..fdac5e227df5 100644 --- a/include/linux/usb/typec_altmode.h +++ b/include/linux/usb/typec_altmode.h @@ -28,6 +28,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.51.0.384.g4c02a37b29-goog From nobody Thu Oct 2 19:27:59 2025 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 3273A2BF3E2 for ; Fri, 12 Sep 2025 06:48:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757659689; cv=none; b=kE6k38rwGf6S1dGdMw3y+cXrA2ms2nb1eRbmkTunFzkpDwh4c2tJlkoLogOfms6gTz2uOucMzfS0aehnPd6/UhzXHF9c1zlWJoeAj7L5RyNkLlwlOppdeuBubIbthEdk6QD70oIURLm1pHREhd51svOmVYw8lV2AwL9YZlFfSo0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757659689; c=relaxed/simple; bh=UT/bION2zNpmXwBRk6uc/9Eat1ApMNYCZlITkT1NplQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=evp9k8migXObK2Qp1en8KgRg1goUHm4iJDrxdv80VU5o4M6s5fyxNCJ+gLte10GVtRkxaLR1skDUSay71pM/a+SbgtiSJJsWNPaQwqzk3CwN83zR52KGeXBgDLBKas1ecPW/EH/w5wHiraOWH8Mgo8LgbpgXYvUtlc6SFCqdEuk= 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=HJclE4RQ; arc=none smtp.client-ip=209.85.218.51 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="HJclE4RQ" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-b0787fdb137so225806366b.0 for ; Thu, 11 Sep 2025 23:48:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1757659687; x=1758264487; 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=a0Xtud0TdVZ+DWagzGFvFsKpmqRiYDQ9VDWpfm1enwI=; b=HJclE4RQxmxaCLVM93/M+u9jaZapowUif+CwHjITSKUfHZux+HseO5umqbQKPEuZTI vxepY5pl31etZNwc+jzTLepMZGT3wn1IpRfgwluWLWqvnOKEwEAq7o/WY9jLRF5d2vyC UtyhuEvpuKz1iVBlDc7URgNWq8MO1JNU+DFoc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757659687; x=1758264487; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a0Xtud0TdVZ+DWagzGFvFsKpmqRiYDQ9VDWpfm1enwI=; b=O25Umzvmr07X/D4lX6viSScbhMIFXIZvuzsmoEfMfEPADpojZDllV9Em7RH8mFzXkF ZUQuyQXmJs5Q5m6Ki6OwyqnTK2id+nN860R5/ouWoeplKb3rGF8A1YTZWZkJWzX3VQI0 BSlWn266oqpbqcrgdecCZN+qu6Yj83FFa6lMGuH0rV1fLUz1UaaK3JmbJDI4eiQFhISH 3QFv4v2BbBHn9Y4AKdD/hUJtr6yjaRPx2GwNqfumlbPWshhPzZqCq6mggqq8pFS47weD pubE+02I5WeBzIZaBOeYJvAdbJlPRCHYP5OPzLdaJ/hLIieJqR/Jud89/dxSCL6gOYqc HPFw== X-Forwarded-Encrypted: i=1; AJvYcCVoHPRczd7Z2Ul+CG9VUMwMRy+oJItXNoHV9zcdL22B9w6OSmirUjO2tQ8/oUxeCEFh7QteC3xLYQsS2T0=@vger.kernel.org X-Gm-Message-State: AOJu0YypAopISJuHbjCi6KfxzuGGmX4k892dJJj6Dlym0bLgVvUvw7/o 1cekf+BS9enxdQr//0u5uIAwe9fWaUYZU1CrDcHvVTBpV17X3aEQU/jY3J3Dl6NyHA== X-Gm-Gg: ASbGncvnVhA+iWBv6aLjdn99BThL0fYU1NKpvuBQRLPbE3iuOp9Pk3sQTXPWJ3etYc5 PKmkzo8QygEn0ICNv0/oPdw4VQXZ5c9X6nDHpnCmqlwHFQ2neJq53lAVsLzSWsibDx6RLkDY/2j BYcSwiKlFrXWkAeQLoWUt4VJGShIAW1SdEaO6Arq2Ub9up3gp8s65xSshYBJOwfd/doca5/EEY/ y6KtwN8zzN0vSTdmWsIW6zAzma9dho+TaGwxhlf/2+11K9hGaGDVA9NoK67W1rzGBNAXs5qI1Q4 I8t2ExrJi7kLSEl/ypcCdP79PLfz+cyUa4LAm+pW63ylsmJssy6igABgvT5aQp+9htr/iaUr9AL OIHLwr4+nTOgCqOpvqZIo3qhSAlojPH0bJUdcgRPJ/oG+RGzHwjzBkTSBDWkzZ+51IE95MJO4HR fmYjLpocmXVrWifIL5G7uCdr8OW8ky9nfYrPgP X-Google-Smtp-Source: AGHT+IFJXwxQzhGtmgTg6Wyltw4l/rkxAEpJ7pN6ZY/j+zLPCSWzQ8LLU+wbeQfpDvkIAniXPe0jLQ== X-Received: by 2002:a17:907:9623:b0:b04:708e:7348 with SMTP id a640c23a62f3a-b07c37e0e05mr181292666b.30.1757659686414; Thu, 11 Sep 2025 23:48:06 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (240.225.32.34.bc.googleusercontent.com. [34.32.225.240]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b07b3128a1esm295465366b.29.2025.09.11.23.48.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Sep 2025 23:48:06 -0700 (PDT) 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 , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v4 4/4] usb: typec: Expose alternate mode priority via sysfs Date: Fri, 12 Sep 2025 06:47:51 +0000 Message-ID: <20250912064751.1987850-5-akuchynski@chromium.org> X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog In-Reply-To: <20250912064751.1987850-1-akuchynski@chromium.org> References: <20250912064751.1987850-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. Signed-off-by: Andrei Kuchynski --- Documentation/ABI/testing/sysfs-class-typec | 11 ++++++ drivers/usb/typec/class.c | 37 ++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/AB= I/testing/sysfs-class-typec index 38e101c17a00..0f6e6adb71c4 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 9f86605ce125..6191f7def91c 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -19,6 +19,7 @@ #include "bus.h" #include "class.h" #include "pd.h" +#include "mode_selection.h" =20 static DEFINE_IDA(typec_index_ida); =20 @@ -445,11 +446,34 @@ svid_show(struct device *dev, struct device_attribute= *attr, char *buf) } static DEVICE_ATTR_RO(svid); =20 +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 +483,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; } @@ -2471,6 +2499,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)) @@ -2489,6 +2518,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; --=20 2.51.0.384.g4c02a37b29-goog