From nobody Wed Sep 10 05:43:46 2025 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 BF92036CE10 for ; Fri, 5 Sep 2025 14:22:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757082139; cv=none; b=BOJkmh8AIzIO6KhVXrUzwRKwdiJErNQeGQcYsuQmiDV7uixHZwsFxzJuXlSLNfmaVX0AWwnSag9dflfGxo4JH9Ii2pmjPjZYoMN+rdZRk0hWOoTZW13aoBG5LC8Lgl14kvt1xUg5cGemy9M+CN6UoQle3jFXGj+w0TRVNHgl9Jc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757082139; c=relaxed/simple; bh=Hc11dQRZZPHY3rRj8sQC49olD9NpE7/7qRqZ+w5XAn4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hfEWotzDgUbAGffX9cUY5DK7OqlqkUeYetsl5wYUVxVqCScKPZoEVwB0FDuC43zvHlhNqkLtn9EScxDYhlWrtu04+P8pHEb+t13A4CPyRzKWKOFfqkz8CMNqy8uhifZ1EfmAOfAvis/s10cArqKpWTGjP/jajmjrfyEWnQ7IYZ0= 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=EGi4rZ3g; arc=none smtp.client-ip=209.85.218.43 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="EGi4rZ3g" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-b046f6fb2a9so340203266b.2 for ; Fri, 05 Sep 2025 07:22:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1757082135; x=1757686935; 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=OV1LDwfiuLJ9IBiJAs7IEkPWomukwV1rFx4+Ev+/eEE=; b=EGi4rZ3gXp98MjF18cLDkcwhmcT3KAvL9cEWX0LJ4qcLVNHyJFtaNShOppa2UcyQhH CArbZZqBY6WpjM2thXJuFIe6HjYgFyUdG18KBKPWrDhuMRNbIZfWKxJ+d2zZisJguuMm QoJPx+6Y9fiPREwXKgX2FUnp4maOj08lmMFJg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757082135; x=1757686935; 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=OV1LDwfiuLJ9IBiJAs7IEkPWomukwV1rFx4+Ev+/eEE=; b=rGEt1IEXsauXYS3fDYbuYt5vCAQ5/XVH1+qEGtRIB41oykpNewJ4Oq2QWuCP5jnbBw fgBog5IhV1IL3DKh/1zia/XqL46q8w6FlmY2rXEXfZMInA62SC2plWPG3MXeXZCOxjHT fBzBPmLo5Wl+CDA2EIEdASB6rraJCg901h5d/xjqTWDryI4BuWEZ+V9fTUy3lk6vizyS 1PKxNVSQJs4Vvs7favF0f1/gO483sVwuzU/X/5YRLUG7raiaBbS2o4lw26bdjooz9UO3 AznXySh7yG0yX0IiT+MktklaIZCrX13T6d0bfXxmvn5bNcZkDeKvu0Hstq0TPeZVHfHP crwA== X-Forwarded-Encrypted: i=1; AJvYcCVXr9xiOXX239Rfq8aWpzs4BRCsYC/XQGo2vDzqfxDw3R0E9G/oxSTgbw0EEWT95KR99ZmTyxx81XhTVtc=@vger.kernel.org X-Gm-Message-State: AOJu0YzX7fcRpv3sbczEPlDAROwtBmenN4rxuKSbH7KkB59nv8eVQkKe E/ufrtnF4pntNGx3p/CpCxum9jq7mkNwvL2rR7XFsB/OPjXL7/qHKJlGt8Xt7akVoQ== X-Gm-Gg: ASbGnctEdxaaGS0ZBzV921wG8dZ/pwxzpFETD+4yj4pehUb4dgfPBocwLUO0sUwi4H+ 1mSlAb5ytJlG6Epydf452Ir4f5EP7XQfYuN1W1H2MdRd/idkdsBmd4yWPerrdoRnAwQKCOm26fI VKzoZbq4FMXtUM0RB8uIuGmucVTAeI9jBjHcnq2yMaa4CA3qoW9nYPIhyWtArYX70PtklMS47H8 y/tqMtCImpzF9r8rXTOYf+goP8ZBNWukPCn3LXaVmTT28qFQO0lv5cH1bMj2nnEH/jWa1CUNseN uyQBwdSo1btszOUZYWDe5fFitPmBWUxz/MuiDggqbPJjrkw8N21FcHQ8UmH2tAgmFVYZqKNFOti yCQJOEtoqrzXXK2LqtQc3jgywHlXIP7UaEMelphJNcTlSDqAD2C6fJ5xCMViqTZCXHqJqDF8g6Z XRG5dqAYoogfMpeRhbDBFHHJXmoA== X-Google-Smtp-Source: AGHT+IFCvd3VJRlMQTN63ZbgjjAhsrShJNCJ07Shx+1GenFVnJohKqUi4MazUtwYOIyKPWi7eRjrKA== X-Received: by 2002:a17:907:1c8c:b0:b04:8ed3:9e81 with SMTP id a640c23a62f3a-b048ed3d358mr431118866b.31.1757082134828; Fri, 05 Sep 2025 07:22:14 -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-b0476e0d61esm502141066b.53.2025.09.05.07.22.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Sep 2025 07:22:14 -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 , Dmitry Baryshkov , "Christian A. Ehrhardt" , Venkat Jayaraman , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v3 1/5] usb: typec: Add mode_control field to port property Date: Fri, 5 Sep 2025 14:22:02 +0000 Message-ID: <20250905142206.4105351-2-akuchynski@chromium.org> X-Mailer: git-send-email 2.51.0.355.g5224444f11-goog In-Reply-To: <20250905142206.4105351-1-akuchynski@chromium.org> References: <20250905142206.4105351-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 | 2 ++ include/linux/usb/typec.h | 2 ++ 3 files changed, 10 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..c53a04b9dc75 100644 --- a/drivers/usb/typec/class.h +++ b/drivers/usb/typec/class.h @@ -80,6 +80,8 @@ struct typec_port { */ struct device *usb2_dev; struct device *usb3_dev; + + bool mode_control; }; =20 #define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev) 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.355.g5224444f11-goog From nobody Wed Sep 10 05:43:46 2025 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 DCF64370585 for ; Fri, 5 Sep 2025 14:22:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757082141; cv=none; b=OksKgs6KL77d1JOF8+VodY4nwD8HmOXa9mwmmp5+nL3Drr5TJWVH2uDyvLSOTYLdoTiuGasK0q2OwuyCtgJ4tW98ZRAEj9PFLx6+7JF3MRVqe/Kl5+oaMJz76LHg1cQu++WNiSMdZbt3/fAdTmBnvkWm9v1juD7xch4NYeL0Ep8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757082141; c=relaxed/simple; bh=7dk81Au3j1iQk6yPR3k0+dfNeO3eOhLC3P47r/ZLlaA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ktaT99K6Is93M36nZrbXg8vlfs9OGiSobCmQKccZzYBI4fNoIFMZQgsUw+9kvOkMBVduT1aIVlxEoPu8oOYUwa3X2sGkw8H31Ye7uUv27ZEefmkyoQmNfFx2e5L6eKRmEsKunuIobffOMt4ktn2tSckBRUKuJ46dlWTimqs/lqk= 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=UvdsUduc; arc=none smtp.client-ip=209.85.218.45 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="UvdsUduc" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-b02c719a117so418690866b.1 for ; Fri, 05 Sep 2025 07:22:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1757082137; x=1757686937; 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=eNdygYENTLEaOX1N0zFeQLg29SgfHGJhm074WNrdLtw=; b=UvdsUduc+ZvYGFDj4pbg47208ALjcoRcHLpHCE9aKCHQ84ZDW+6CGgj0tSpuEDUGEj UZdj9Gk0l4/xt8cTX6OfkxwvcPIjiT/38W9yFAIMp58DEW2dDRAJWLAbdNndyGsLlDHi VBVSg+YXVv56qNbdqx8omDXkCRzgYRRbWWJZM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757082137; x=1757686937; 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=eNdygYENTLEaOX1N0zFeQLg29SgfHGJhm074WNrdLtw=; b=gs+dcgLiG0Z8mwiMR0A58nxZkXFyXQ/MGng1//03LKILCd6XcC5LF/nHowIbSbrckz S25/4bzPXLAGrak09SOLANU6kukOK3JP1qHEzRENGfBcuB/1kq5rC5zAotGV2s5xiPX8 Fvg4XxCe4Nh24hA7LYfpP+7VWxAfuBNtJK7XJNmEibGQhmiaANx2dCVuid232ZhlIhew wEkq9Hjc9eGdZjCCC5qboblygfKck+mc6wYVS79SE+EOf7xnHv5SrcrSOhU26dDRowCq oPKH37kx+qIQ+3WHFbh7gSx3a3/2CbFuX95caNUqVSzf7fG/xd3HPpAUO2sI0bpAdidn z0Ww== X-Forwarded-Encrypted: i=1; AJvYcCWU+EVpPXOR/7ni6/285r8kk7F4NgEUi0y9Cd2dMQMt12rnVepafLarUG1zZUNOWkoQ3KJHG3r/tJNWGYE=@vger.kernel.org X-Gm-Message-State: AOJu0YynsLCN3qLbFcpdsODM2adEKTztIgKSXbkJiCHM1SIWMmtNxatY sn2vYrHPEU0FAOfHrt/4HAgPifYf76lXnOfAn/zLNK/5gHt7gBLfU2DL5AAfPUNKUQ== X-Gm-Gg: ASbGncs6ofAXk+YGFgegIxAEs/aXckIsbgkzeC5Hc5a5bCU9r5eRDjwKZBbTUziCLE0 pgCN5C/VwDrnjEnA4g9RbwPfTYFPdnTTyTDnmY5Q5jJwO8ULkCG45MBagQ9ucJDtM3pSMEh1NWm WwdW5brQA0PN+vlWsRAbiihVcHnsd1FpL6ZI3aKctw+US5kTiM7rcSC8kELwelXB3/of3QrdEK9 FKis/TroF5kBTmmh+9JQiFjepQr7N6SFrfdePZOaGzCNq4tVP9ZobVnx3KiND/sti8jhKp9lFBb YIXE7ckJuehvKncsIk6xxuTUBj7aJH/pv5EkLlxPfpjBRuN07HdF8M6zRKlRFTWRPN65IL26+Op +G+gJhkvHpGtH5d8rEKaJtKOxxpHyfQhbL/mGxfxgCkYbfJMQLs70dWxXoHcDAUlH05UrFES200 kbjUyeiXvLq7OLdy8= X-Google-Smtp-Source: AGHT+IF1G3sXay2HMrNzwLZtA3zxVhb7Dzgn8IIvQwuekRHg2fNC6grbFYHUf3CV1eWA30lQkiz/Lw== X-Received: by 2002:a17:907:1b22:b0:aff:16eb:8b09 with SMTP id a640c23a62f3a-b01d8a2639dmr2066545166b.5.1757082136974; Fri, 05 Sep 2025 07:22:16 -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-b0476e0d61esm502141066b.53.2025.09.05.07.22.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Sep 2025 07:22:16 -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 , Dmitry Baryshkov , "Christian A. Ehrhardt" , Venkat Jayaraman , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v3 2/5] platform/chrome: cros_ec_typec: Set no_mode_control flag Date: Fri, 5 Sep 2025 14:22:03 +0000 Message-ID: <20250905142206.4105351-3-akuchynski@chromium.org> X-Mailer: git-send-email 2.51.0.355.g5224444f11-goog In-Reply-To: <20250905142206.4105351-1-akuchynski@chromium.org> References: <20250905142206.4105351-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.355.g5224444f11-goog From nobody Wed Sep 10 05:43:46 2025 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 C9BA036CE11 for ; Fri, 5 Sep 2025 14:22:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757082142; cv=none; b=hKzs0MEAZXs8eQbvkphi/oEuK/IDcJj7RAwbUemiw52BB+kSOmX+YVwch111ikKi893ob5gNMo8VlcErAXRFBA+HCpazIlOrfarv0RiUOGr4hkXCUL1uPB4kFTfQyw32XDdDIEPLSaUXsaSSpS6ZYNlEnYnSk8Me9ssdm7XZphk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757082142; c=relaxed/simple; bh=RwkDpJ4JMiS1lt6rgk/ttWd7Imn2DX4N4/is1V6nzBg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZHTddo+VST92D/w0Oef8DzdkslfgGKw7WyOOXRBwD61aCVUpr250DzqYuTx49r1gwIHxnWigOnjKpSrqzOcZK3C+4DrhcWMnlC+M23EpyFRJXApWvllfR+pC5nkn0XbCvjikvkXWev/FE2ciGe/YWDCVVZLPvpa+M6kyff7E324= 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=UC9gy2e6; arc=none smtp.client-ip=209.85.218.43 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="UC9gy2e6" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-b045d56e181so324102166b.2 for ; Fri, 05 Sep 2025 07:22:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1757082139; x=1757686939; 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=87ag1FHHaswWtSbB90U8zWSxgzWenXvtVjHwVBb5b6g=; b=UC9gy2e68kBOj8z9txY31jbyA1LYZEcwZHPYxy+uuCTVpJlLr/h/xrihaYStH+1/AY OIyzvS6xwMwEpupl583SYYyMTDS1shtXE8z+Q26ZCUQ1YM46rRIFOPEFiiEWnNqQKwnF LwPtS+fB7oxhJv8PsQfiUySTTK7NkVCO2bbyI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757082139; x=1757686939; 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=87ag1FHHaswWtSbB90U8zWSxgzWenXvtVjHwVBb5b6g=; b=nUi784Kycaw4z42Va8lLEKg89zHlozv4g9H29AmQO4M5JJGGmfuKDotIU8dmipgDZB nj/MSvok8icarcmsXph291HDAsSc7xWEq9KtuDd3JCZVtJIhl6+twz8AO59hsA84z8Ff 6GTF0xz7cHDH7Vt0VJaM3XmaqxhPSBDpedUNA3xJwZsaKinJl9Qaew9CObC13/SBqgGC AsXUF0RpyCTd0+6yGHQG5rDiytpMtIlVwc89wp6HfUehmRefB0KEfMM7ai3x2y6Raklt WF4/YDHtHQRaJ3BgukYkztgqKDkJrZB8Rp5KvU3LYjpvdEjPBe8GfPnnP4eLs9RTFDCu GZfw== X-Forwarded-Encrypted: i=1; AJvYcCVFV23dRP+8HM2KGAijKNthjat5lvIDeP2B2DUi6m4qw1EXrXJKuhlPPVz5IV46t04GdiRT3bm/WpLWnqo=@vger.kernel.org X-Gm-Message-State: AOJu0YxsUv8okqDd4dU47QbFOpdtx4+d9f1/DQxNjTcDcz7um6gZnCbm KJ3Yig4E+hQvRvoB7CfClekdGjVmct4WfEN7KIx6DtkcSgBWJsoerZhtHRx1giaxsA== X-Gm-Gg: ASbGnctzi3CJEk6OMt8AMF1MTM58sVse28nccU84nUj2YQt3+cC9cfCCrPY16/JNn6w f+N7xigmCuFTIs05wFoqvysjLIBjWXZ7P3nB9v88osuPEpDr6KfKNA9p4F6WUFSOyyU3fvs/3ay pHf93AV1CSbuHYy/nJEgxagFXK9YApUCGbe9vvXE/d5kyFMdjj8qu1hp5ZqtoMn+QFIEM6pJtmJ zND+2NyjhXwDxxEfIsgwA0ONz1yX6wMZD8LlV185JoCPA+4MP6ZgXoQHrW4WMn18NxmFwIC6bi6 ZH0ypm9m/Ggnha3GwAUGEVx2eJ0tiwzSqH1GvuAd6S7/StSVM/5lmGYRgp1IpAkmxN++BWS+z66 YTOlYw7+InyXVeavvr+/0AZYHMHziPihRjuVBquczZFeRoSXF2qo4aqQRmNSmISKOpVXumCGAL2 9FRV96u6rXZ7+Fhrg= X-Google-Smtp-Source: AGHT+IEtSMMMoUQkrS0etMzB3nxVu+EiElCLzWoEgWR+jsVPfiruWufQaw8VaX46EwAq7cMBxoT5ww== X-Received: by 2002:a17:907:3d0b:b0:adb:428f:f748 with SMTP id a640c23a62f3a-b01d8a72fddmr2287245866b.21.1757082139041; Fri, 05 Sep 2025 07:22:19 -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-b0476e0d61esm502141066b.53.2025.09.05.07.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Sep 2025 07:22:18 -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 , Dmitry Baryshkov , "Christian A. Ehrhardt" , Venkat Jayaraman , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v3 3/5] usb: typec: ucsi: Set no_mode_control flag Date: Fri, 5 Sep 2025 14:22:04 +0000 Message-ID: <20250905142206.4105351-4-akuchynski@chromium.org> X-Mailer: git-send-email 2.51.0.355.g5224444f11-goog In-Reply-To: <20250905142206.4105351-1-akuchynski@chromium.org> References: <20250905142206.4105351-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 --- 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 0d6b0cf5a7cd..9f754344a841 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -1632,6 +1632,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->ops->update_connector) ucsi->ops->update_connector(con); --=20 2.51.0.355.g5224444f11-goog From nobody Wed Sep 10 05:43:46 2025 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 C73C0370587 for ; Fri, 5 Sep 2025 14:22:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757082144; cv=none; b=trn88H55Rp7Oyu7QuX2JZXr1qC10cxCK4blLt1wsMVhf/cXv5PmiAGb/Km7Nd33STHJi7ChAWcdhhGSOAeEigBXLBJRFx2o5W3/56aPiIhRUZSZbwnxVgA650JIbjKkSs9nvjWroI+d+yHmZlFkHTBp8DsCcRjdEgyC2Nhob96E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757082144; c=relaxed/simple; bh=5N/rH2l80Ktvf6ZOLrQvgwDOrXD0nhEqJ9c02j0Lg4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gw3px25XQwZgBRP/jeQTqfwF/nd4g4mOKAkvJMMARqNpdnNIXop3y+p/TZMC/S8zREIWl6i5nVb9oGX4uFcfbBWjiKJUppyqClUj0zlE2OqBlEnHPSatZzWFPutPnkg5N36daro4kPwVmkKla2x9FzLIvfL73yF+Cl91haY8Mnk= 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=aq++zDRw; arc=none smtp.client-ip=209.85.218.41 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="aq++zDRw" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-b046fc9f359so407869466b.0 for ; Fri, 05 Sep 2025 07:22:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1757082141; x=1757686941; 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=HvUNphtUz9Y1R9ktHcB7KtYuXuG0QSWTDzZgUfzVFec=; b=aq++zDRwg1n7FS4sbh1nA226fEcGhF8WY0mJfEJz/uwH00TyqcqWWSarx8NgR/ocsG Brxq5r9Ko/QN0j5gmF3EwOsVFSpSDt6r7td/njtAZmVno/A07yoqzPi0i1dVYo6zqNOG GIL+tjM+lnGZnWtCrH35lwR7SBu6iEyNtQCZs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757082141; x=1757686941; 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=HvUNphtUz9Y1R9ktHcB7KtYuXuG0QSWTDzZgUfzVFec=; b=dF+j8snrC346SU2PamVFpXkMqoLJEAIMDK1oFaMkKS93Gsfb5es17Wdt+IJoKpinE4 S9+K8vpPxqazRUtvPDEj9+wBWrlnhgkvzOv0fHfmtZmOQzDr+HilfbGYvLy0pdXGqqRT VULHSsWoT37/Lw7VJMNm0vO6N0syUdr2Q7aXQak7hImrApkkP6KYcMidV3b5Ypm+K4is MEFWbtSJPHL7b4GIlh4DNGPGWioRLSra6Udtg/RiDAE0UoNtudegHoawFFyVvV+5rPdo QiSf6gP65uipi/30ZIgiJA18RN7ijfIjLxIWGXqXMUTJOkoVIpvuZWjEyUO02Iz9WFKu FU5w== X-Forwarded-Encrypted: i=1; AJvYcCV/zIyeE+ZZ7leRMGoPHGpbrVubcDfWiXQX9ut075v+Yr8ROFcFCoQ6tiVarCgxx+YjUinM6j/YtRIZ6hs=@vger.kernel.org X-Gm-Message-State: AOJu0Yyuv1tH21o0SVNuAKAqAUmWENbLUdJ19YJ0aiybhafQP6N6r6Q/ X+R9uuc7uQiRSn9vVBUT6dWI1ni5+qAH0wEm4V6qmVXiOR7YlINSvYGZscxIyNvVtA== X-Gm-Gg: ASbGncvEM/oVCZHuy/hB5kNd6FOcznoQa/11oBvbzr/gyej36o6JvdYVWhJQ7R41ur8 FX+/5o3cLpFmfZ4ZdEVs3yXk7bZerIMugWD/Q32ZAUwVQItQq7gaqmyHlvbsgGBVqSNmq4Vf3nr NxbV2D/PhORjbU1mYZkBuJPILKUKrkHcXGy+MdVI+0QLhhko9Kx7NS0e3jAJkyPoRnxrpH3zhrC 6lcZuDukUpqLEIkhcgl6b3JGz8okU+AhUrtXIwxLxaB+oiIcf3hA/shN2iWUXcznneWoajRWZmT To7C1T1TZ2OBzyGBFP3WpiRNXlaMyIc2NTBkO8HWi9t/So95a8chfVesbyfolsNcw0SgnM3aunN wc7AFwZ87l1mA1trIKFVYKSnyv/LdtPA41jMjf/5wgSK4QwJY4L2bXZrY0rLLmZSc6U3XXtexQ0 Pb5cRBPXK77GmTaFqJphKwJRoIuQ== X-Google-Smtp-Source: AGHT+IGfW53wYhRJFchVhlBh0z4k+oPM9nbab+nSZ8hw1YR5eT88L0CvzsuEHVeF3Ys4E5J3K9DYPg== X-Received: by 2002:a17:907:728e:b0:b04:7b7f:33be with SMTP id a640c23a62f3a-b047b7f352amr825270066b.48.1757082141093; Fri, 05 Sep 2025 07:22:21 -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-b0476e0d61esm502141066b.53.2025.09.05.07.22.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Sep 2025 07:22:20 -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 , Dmitry Baryshkov , "Christian A. Ehrhardt" , Venkat Jayaraman , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v3 4/5] usb: typec: Implement alternate mode priority handling Date: Fri, 5 Sep 2025 14:22:05 +0000 Message-ID: <20250905142206.4105351-5-akuchynski@chromium.org> X-Mailer: git-send-email 2.51.0.355.g5224444f11-goog In-Reply-To: <20250905142206.4105351-1-akuchynski@chromium.org> References: <20250905142206.4105351-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 Reviewed-by: Heikki Krogerus --- drivers/usb/typec/Makefile | 2 +- drivers/usb/typec/mode_selection.c | 38 ++++++++++++++++++++++++++++++ drivers/usb/typec/mode_selection.h | 6 +++++ include/linux/usb/typec_altmode.h | 1 + 4 files changed, 46 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..2179bf25f5d4 --- /dev/null +++ b/drivers/usb/typec/mode_selection.c @@ -0,0 +1,38 @@ +// 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) +{ + struct typec_altmode **alt_target =3D (struct typec_altmode **)data; + + if (is_typec_altmode(dev)) { + 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; +} + +void typec_mode_set_priority(struct typec_altmode *alt, + const unsigned int priority) +{ + struct typec_port *port =3D to_typec_port(alt->dev.parent); + int res =3D 1; + + alt->priority =3D priority; + + while (res) + res =3D device_for_each_child(&port->dev, &alt, + increment_duplicated_priority); +} diff --git a/drivers/usb/typec/mode_selection.h b/drivers/usb/typec/mode_se= lection.h new file mode 100644 index 000000000000..cbf5a37e6404 --- /dev/null +++ b/drivers/usb/typec/mode_selection.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include + +void typec_mode_set_priority(struct typec_altmode *alt, + const unsigned int priority); diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_al= tmode.h index b3c0866ea70f..571c6e00b54f 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; + unsigned int priority; =20 char *desc; const struct typec_altmode_ops *ops; --=20 2.51.0.355.g5224444f11-goog From nobody Wed Sep 10 05:43:46 2025 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 24A2D371EAC for ; Fri, 5 Sep 2025 14:22:25 +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=1757082147; cv=none; b=Z5MadIGOP/SsXO6ct1BeXFnvb4MKs+S8fZhBcGb70E8pLkZAHc0nT2l2/DGslYIj2yTgDihYWRgSFMF4pEMgwRrz9RE14N42vwUs86BtzM303J11q1bfGYWn113aKpRAqwdhY1fLEu/YrdJCFDvLadFUuHiKR3N4Iyv0HVKPXXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757082147; c=relaxed/simple; bh=N70arxT/iGReacj90zjbg0gjuZvRPUxNf9AQDKl2eMo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QNFMbDdAnQBx0f/KkuCxv+ykIRWtbzlg0lY2S9d+BY3BOURGplQn6rBrfsxM9TZm6p29sMHfLus7JbDybdEGX4gR64yOiu9crWjk3MATYlO3tpFSl9PTyGzQ4CZROfM6j0SzL6kQCBBbsh+n2pcQNRld6UyCcgl4n2z/aGuQTHc= 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=JR8KLbOt; 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="JR8KLbOt" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-b0454d63802so369604566b.2 for ; Fri, 05 Sep 2025 07:22:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1757082143; x=1757686943; 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=aM2EplsdBpHriECPVCPtShoqnRN3L2lkTWP4nBkA3tY=; b=JR8KLbOtEVWf0UDPiXSO50Hn2M+APsmFamSG276Yx/XvhKV4cqwDY6UbJFPJ9ejvcj yB157NpUOkmLargTviCX/y9jVjmUA2GBc7kqfI5Et9kzTrMWFg/bfmvUJOrwFtQ8P1li XrTc7CYyztG8gTnhxFf47Gq16XfVreDcJpqI4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757082143; x=1757686943; 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=aM2EplsdBpHriECPVCPtShoqnRN3L2lkTWP4nBkA3tY=; b=cyt0sM6BkndQ+06m5q/+Z/2ZT8/IwG7NoDS1Mg3wPtFr6Q1VNkVSWOucJ/Xe5jj35Y WpBfHIP2Xao7vaRKKuM8cjriwZ5y+pkeP6uyYjVCU2F66s98L8e2P3EjcI2kK6KJ/jEz SdHxTPRQTtSR8VQJVnkQlG3bBVHE+j1LW9ZAQLqB4JNAwW9m8mA9MnnFub2RRXlkIpi5 qw0Ra1fAr6YuPh6jYdEXwXDlQx0AB8HPOVZD3E56wfpAplnQbY8ilHB8KwWVJ17tQJqQ QEdsESgLiDkh76uGov7lOg4CvedvDfWtxlEO1t44ug8+ntakYSFxENZb+u5OSPaY+HRz ggOQ== X-Forwarded-Encrypted: i=1; AJvYcCWAfApJID4+Spj2oUjBKE76KrdCErkIbprOpKkaRH2x9Gk89Hg5mKZSy/XnB/7IbX5qBEGxfRYX9Fz3osg=@vger.kernel.org X-Gm-Message-State: AOJu0YwBCfMg1RJ5Vzv7LXVNEHFhW5DjFVG+QbSdiWdYFnv5HX1hTXeT 3raEeZgdrqvh6MEdOKUnhnQvdmYMQQCxTZMfLXLmU/xFBQ+kkwbXsruYLkcvOO8KQg== X-Gm-Gg: ASbGncuOgFA1MZl/9vlAZVNOK8LRzGcXDEa9cKL1+LdOH/E6tiOGRM2hDEo+rHtzb1i avkMiNiyVRFG5SFDJMojXtPQSInHSdlFRswJYqw4QfFhDs2O2K43ku+XYkXigy3rs32yiG0VblV W6S+9L5x8nHgmkluDp3jOF1ZbsiSMA5ukNW25s6zMSV+Ajw3dsD3m5V7lSH70bm2ExAS7fdCBSG sPKQTBKLPm1B2CkYQMueZ5rR3yWgr8Ag5oSfqUucrqZqNjC8OTpoDvyf0jRG/wcWQMjRZ/fY33e 8m3NOnQsdGuGyqHi7Qe8lvRUC6kkU8KTXmytfmLy20jVXu/GR4C+dgtp7CgHUunThTmrwEoGNZR FFuiemNQVlSPefrnrOsGtgr78foFYLdw/r/2zyHNcgUlZ1CWl1b/YcBpJDNUmCD4DW/afxPtgGo LGiosqzNUKIU9zACM= X-Google-Smtp-Source: AGHT+IEUW8qkOHgjidxoy4ZII7ZAuk//jICzXdqIhvcSNPCu7yDo3dIGYIsHRdwcsjy825w3RSPySA== X-Received: by 2002:a17:907:94d2:b0:af9:5ca0:e4fe with SMTP id a640c23a62f3a-b01d97bd1b7mr2225391066b.56.1757082143434; Fri, 05 Sep 2025 07:22:23 -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-b0476e0d61esm502141066b.53.2025.09.05.07.22.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Sep 2025 07:22:22 -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 , Dmitry Baryshkov , "Christian A. Ehrhardt" , Venkat Jayaraman , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v3 5/5] usb: typec: Expose alternate mode priority via sysfs Date: Fri, 5 Sep 2025 14:22:06 +0000 Message-ID: <20250905142206.4105351-6-akuchynski@chromium.org> X-Mailer: git-send-email 2.51.0.355.g5224444f11-goog In-Reply-To: <20250905142206.4105351-1-akuchynski@chromium.org> References: <20250905142206.4105351-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 Reviewed-by: Heikki Krogerus --- Documentation/ABI/testing/sysfs-class-typec | 11 +++++++ drivers/usb/typec/class.c | 32 ++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/AB= I/testing/sysfs-class-typec index 38e101c17a00..dab3e4e727b6 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 alt-mode. + When read, it shows the current integer priority value. Lower numerical + values indicate higher priority (0 is the highest priority). + 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..aaab2e1e98b4 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) +{ + unsigned int val; + int err =3D kstrtouint(buf, 10, &val); + + if (!err) { + typec_mode_set_priority(to_typec_altmode(dev), val); + return size; + } + + return err; +} + +static ssize_t priority_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(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; } @@ -2491,6 +2519,8 @@ typec_port_register_altmode(struct typec_port *port, to_altmode(adev)->retimer =3D retimer; } =20 + typec_mode_set_priority(adev, 0); + return adev; } EXPORT_SYMBOL_GPL(typec_port_register_altmode); --=20 2.51.0.355.g5224444f11-goog