From nobody Wed Oct 8 09:22:11 2025 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 1387A28C02A for ; Mon, 30 Jun 2025 14:12:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751292773; cv=none; b=F32GiU/22vy7WQVvWP4Bzf2/+p3LdJg4XoebuyWCmz3c8ueCGbujSPAsGrL1iwjMzLvI8SAEw23R5aNOq5MBuTMRLLChXvcnoYzY1h/Lj2hB4qAFmchV7WIawz/TBQoZX0nMIe+3TXJ4djllHo43x0b+OqQYFYhaND98o16sxDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751292773; c=relaxed/simple; bh=UbU7avGhiW9Nh0EyyPRGSkHu5w0s9/pYfAxGAYTBVT4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WwZP8xlydtUiWsX/ltH1B0lK0tDYBPHqsCf8UlEKLm1EYbRu4tKVTNTyHXcwrM1KS265B2cP6LfHvYoIZlCvXLvLls1qZg0BPsEGzmzP+6QpX35RCHtkuFv9eQVTMLE/SwySBVW4MSMn0AdhLb25sdeRS20koZA+mPFZ8arjNds= 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=iRJQqOJx; arc=none smtp.client-ip=209.85.208.42 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="iRJQqOJx" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-60c4521ae2cso8206318a12.0 for ; Mon, 30 Jun 2025 07:12:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751292770; x=1751897570; 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=3faCGZIUGXYM8A0hkVX0sik8je51spanXR3H0h+FTl8=; b=iRJQqOJxfnPkd6Wl2DfM1kvlsltOm2MQaJWvBQyB7ZWmh2Q8DIvyXNMhKhEz02EyKE bMvJFfSEzi3ODwCsJ/BIK9iLR4c3o/lliXD+IHH7Dlp8jgYt3pBIovPZ1efczWS4iw5E +eibB8U9w1RRwOXfttFjbgHUAHQR+WTeQHNyI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751292770; x=1751897570; 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=3faCGZIUGXYM8A0hkVX0sik8je51spanXR3H0h+FTl8=; b=Sj6soQwiZNZfixty1svkntFpVy/y4/IVInxl7JSBvC0uVUQoXtOOXivy6vvAjQsipe dAZRkdsYQFe4Uv2bk0zOFvaMQk6csSCeou67/6PPJXcnMWWjnboJ9iDoQVENM9u4i0kF C+FCG6rAMADa7uvcrmgHxNE5hbbJ68bTB5/PnRdJQon5yiPa9jSRcJIZjRN8yWvu33pK nOnF1lUAlovhtD5qwbzanfo9pITsb9tcp0r4Qy4KNQxfpclLGJcGuOPWbsBBpiUsyMPP exNBwCILoqSxnloyhpABxpnkMgXPMF7s1d5mG71UAURIpj92CLQzk0QKsIgDhsz5kBZt PO6g== X-Forwarded-Encrypted: i=1; AJvYcCV+7ivSe2CTT74QubwZM7BRtHSmslLXc+SyoVy7eu9jLWBEoc1KcuPC5QzEDOjWXgncZsHn/+70B/hiymo=@vger.kernel.org X-Gm-Message-State: AOJu0YwGX/ixfH0bOsFpfjpbMcrvYycssE5ks2lFN/88dlLfN0i4acrZ oLkDfQyys7kW5Vsuqc9/WRU7YLEw+TaYzw/i/18QAnUzqr2DnwvV88hhU5Sj4RrZ5A== X-Gm-Gg: ASbGncvH5QytayXBuBoVuLuWDcbkrZ6+wEfawZ/s0XqZzr3/BnzlWnjfMvibxm/zdTH g/Ycay2XE2LTfl+UL/5lQZCgJZrbbjsdYH8MDMUSvpnr1tQAJTVzhYR5gzzm0VdUBUqRGw3L2i4 UnzsIQIfkJXAF3MbMpoSXzcQoMcfmODWkXl1WV+CJGnEWj6GfAngQCB8ysXpJhKzr4kLdY8rSSP DeGCNJj+pKkSPbE6lT17PZFv4YOw0RdDmpVgLK33UDNPEfG/kGoTqT1H5KoHITJ8DON6DWrUcVj AGdvpSCgri92Tc3k/bmpVAN0CCEOxeVeBIUEMR/wQ7tt8mFv7zhF36Mn1lYYrocZ0QttcMqHWh3 dQcyscmlHHWKzTZEybYiBQ2endsRKDkjWOGWm4hRgVz8SPuWxNwlb X-Google-Smtp-Source: AGHT+IGivi6cPTyaSHpxq+HEAQH9kp3ktVpVCImG4H7wtjZGGZZw4e2kZfR98cB5DDtCwjdDtwQmUw== X-Received: by 2002:a17:907:3f1f:b0:ae3:6a82:e6a2 with SMTP id a640c23a62f3a-ae36a82f7b0mr1096335266b.29.1751292770281; Mon, 30 Jun 2025 07:12:50 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (72.144.91.34.bc.googleusercontent.com. [34.91.144.72]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae35363b416sm670643866b.28.2025.06.30.07.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 07:12:48 -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" , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v2 01/10] usb: typec: Add alt_mode_override field to port property Date: Mon, 30 Jun 2025 14:12:30 +0000 Message-ID: <20250630141239.3174390-2-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250630141239.3174390-1-akuchynski@chromium.org> References: <20250630141239.3174390-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 --- drivers/usb/typec/class.c | 14 +++++++++++--- drivers/usb/typec/class.h | 2 ++ include/linux/usb/typec.h | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 67a533e35150..a72325ff099a 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -459,9 +459,16 @@ static umode_t typec_altmode_attr_is_visible(struct ko= bject *kobj, struct typec_altmode *adev =3D to_typec_altmode(kobj_to_dev(kobj)); =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)) { + struct typec_partner *partner =3D + to_typec_partner(adev->dev.parent); + struct typec_port *port =3D + to_typec_port(partner->dev.parent); + + if (!port->alt_mode_override || !adev->ops || + !adev->ops->activate) + return 0444; + } =20 return attr->mode; } @@ -2681,6 +2688,7 @@ struct typec_port *typec_register_port(struct device = *parent, } =20 port->pd =3D cap->pd; + port->alt_mode_override =3D cap->alt_mode_override; =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..f05d9201c233 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 alt_mode_override; }; =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..6e09e68788dd 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -304,6 +304,7 @@ struct typec_capability { enum typec_accessory accessory[TYPEC_MAX_ACCESSORY]; unsigned int orientation_aware:1; u8 usb_capability; + bool alt_mode_override; =20 struct fwnode_handle *fwnode; void *driver_data; --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 09:22:11 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 830C928C2BC for ; Mon, 30 Jun 2025 14:12:54 +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=1751292776; cv=none; b=fo+N1AcKNrnWiYXwDTftckMHxQznFyOI2TT41JcB3B9b2m3nKr/JI4+1l4snq1bPv2LmLGbr549j1dyHSdoBfByVSmjExxP/F+r0WzbxcpTt3Lv48urOekI9XwQAvXL4pePz+b/hgZgo3ofBqF5Pmf9UFK/eQ+G1vHRM7nkwqB0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751292776; c=relaxed/simple; bh=LNKB7M4XGZD1wvMm18MmkB/SXjyMDrkXYtnipJUgGD4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uzn10QiTy1bHbC4cheepXeA2HZYpJDTaFpnD/DgvzlFZD1YEZj6nvKnQy38SW5n9ev2Sovctc7YbAYLwZ2TLSeVLk4xK54LfMvz0unagT5P3UnkhexzeKTaLU8k09bpK4YN514pz8yWIXZaSzsQhxPGKB7yvVOGKJWhZhD/GiVQ= 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=Y8n+/Cud; 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="Y8n+/Cud" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-ae0bc7aa21bso476276066b.2 for ; Mon, 30 Jun 2025 07:12:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751292773; x=1751897573; 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=7KBYhaaZ6zyK1v99fMMJLyWKmWrudMkEEsbHwWdxmU4=; b=Y8n+/CudVs1P+ZoiEKWB4SLwaZ/FJAQ9fMnvz9GF1Wncl/nBfn7WvX+p4umrPfrTQR oCeUW1gVzarvUfyWje43hFPhjtmxw1a1ywX8yUHbiDYJZVVVcgnGD/PtYBDY5rwxugcz 2cQcB4UFEbefwiqXCWcCPBMrkOPdQS9I+Uu2s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751292773; x=1751897573; 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=7KBYhaaZ6zyK1v99fMMJLyWKmWrudMkEEsbHwWdxmU4=; b=fZBZ3dBGba5k/ePORfozLXwL/oB4r6kRlxoEucblurGzWDXSvC1fL+WYZof+fHADSv 6zBnwDp8ngmQC7lkzph9gLhLPm5csbdWqwCZStGdd7U02bcAJABbOO0FvN5wjcRuKhYH tY0pXD24wg/3TUy3ED3qx5xQP8ckR8B+0kYGEEdszVz6MpjZpRZHrqeLQdGPIlZ2wZYY hNGJVO+/IAVpKGOTJ5WfXoONfdxjfGBb4rUMFgaZjahLbMf3zn4p2wwuRnBAEGCvPU32 MS7ibaG1Oxts2EdEVgqC43xh635bV148b59RGpe1kw+/IWBwRBS1CnwTd8JhFQC/mrWG Wv6Q== X-Forwarded-Encrypted: i=1; AJvYcCXG+rN3mBBzFxOLKShao1cUdspxRMYZLYsYVqzc0jFxxvBPs6lbfWa+NYtEzuqiEnumEjM1XEl6zPq3rZM=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/py0Ucsz4GTns2LtMe9JUUndEtkuesqVSdatyqas2KX+279Es qQODRitmG/YRSV9AET1e+tPE/ge5aiwTEzBr9HQwnDC5u/zqeVJC2Qh/x5ZQYYcz7Q== X-Gm-Gg: ASbGnctayWabVjVXkAA9NB++QxhlNP+yJFS8bcjwFAVLrX8J5+GOHdhJzXKwQ6urN2Y VedZZDXQ2ZiNwc5f8dSZeu4AalIbwfPSWH2eRmZXSU1n7TfUeOd6DHVN/XTUAS1c7O1b9vdeYL+ pUq9Lf+uD8muq6IEFwPPA1vNOq3aYafEC//jboiV++x0xQ5xAE5LNVNyBhlFo6o+NrV8m4g0bUa 4ulk3Bo+PWUww8M0Eo3UmrER9PTtKxeuK9EnYE8HtNpj+70KteFi3uLa3re+WCxlpWaVHg4AQUo S0J+3olyLO9UreTjCAlDxjG/oH7HGFNZtwMDIWhTv6fv0avzoQ0vObyye29lYOYTv4F9VuRgHcv 41f1/ir+ww7P4DrVqEvomSxeqKYaoMkkcKn08cmFflt/l+t4/SYGP X-Google-Smtp-Source: AGHT+IHGJggqCDNtOOZaIaGa+EEv/ilhZRgs8ngdME1C5KWNG1YEyP/nwbdR5Tfg1rSmkUT0/Gm90g== X-Received: by 2002:a17:907:2954:b0:ae0:ded9:7f31 with SMTP id a640c23a62f3a-ae34fd88f19mr862849766b.20.1751292772639; Mon, 30 Jun 2025 07:12:52 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (72.144.91.34.bc.googleusercontent.com. [34.91.144.72]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae35363b416sm670643866b.28.2025.06.30.07.12.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 07:12:51 -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" , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v2 02/10] platform/chrome: cros_ec_typec: Set alt_mode_override flag Date: Mon, 30 Jun 2025 14:12:31 +0000 Message-ID: <20250630141239.3174390-3-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250630141239.3174390-1-akuchynski@chromium.org> References: <20250630141239.3174390-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 --- 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 7678e3d05fd3..3aed429fde03 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -408,6 +408,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->alt_mode_override =3D typec->ap_driven_altmode; =20 cros_port->port =3D typec_register_port(dev, cap); if (IS_ERR(cros_port->port)) { --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 09:22:11 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 CC1DC28C5C7 for ; Mon, 30 Jun 2025 14:12:56 +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=1751292778; cv=none; b=u8REGNcXCDcQL2glGivEmcsMZoaayX3N80S/WSWwit10e8Egrr+fw5IMdY6wSaKIYtsjZKbfaZKZY0bgpubGF0cwpkEzp+NGC6GyZl/lP1mNiI9E6tXGZdFecM4ynneEDij4suvcIz5i3nkk2P3k7TdTVQ24GQ3DlkyOj5hez9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751292778; c=relaxed/simple; bh=ytxK9BrkKoT/N8cg9coC0zFOaRK3Cp6/HIU92e99cEw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H1vKgEIWPe37bl5WRtQmoKR48/9x+SkBPe8qgMBFuaopDLppGcC9HXrZM4VX0m6ahVcXodj6p2uT3wIY7Nbxl4lgDMmBrGj0fiC8yQ6LqrHKOKa/oaMbtPmybn9YGA5LVpSpDFjD8URXlE8/xI844Xdf9fmnjXbpt60hxS4uQ7M= 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=IBpaNIIS; 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="IBpaNIIS" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-ae0de1c378fso314367966b.3 for ; Mon, 30 Jun 2025 07:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751292775; x=1751897575; 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=BlOV7R9ML+sYKy5LsxmrHuBwhtr5k9iFt4a13bQXPG8=; b=IBpaNIISfOJcdeNC2qnfuKcaMrkxbVQfyv2YAFC0Q35DurCqYFv3gw6i9QmRT/5ohX QFLiR9UDlimkYGTF9u1vol5LOgkgclyxMiqfDDzppyvcNPEP0FEgi2w8HPSNPRLpLiKq uaFBFu39aUc4IroUg+dV06G1j4gDSr6+6dmAE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751292775; x=1751897575; 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=BlOV7R9ML+sYKy5LsxmrHuBwhtr5k9iFt4a13bQXPG8=; b=azi6MUfadAbsJFKIMvubfyXzlln0Xq490F508mCiYbWykOZ27eLveHiYW7rL8ChHUa BqiutIiy82VMhWmrFPBvjNVvQw7YiSbqWGoqDBBojBpM0HDnFOWc1Ryhu2ZJn7VxTg5d Q7MDAa/gpRqPJzVfVZh2F1sy/ZooYjpjztpliDf73bZPzKzeVr+tXIXpyWEW2c7FkSOR bHCbM9hz5AzIecKTxlV/PInLRMTqDe6IrDm0CrOpjEp2geQ02XsLg3bGonLwHaIv3QBR 5EJ47Jl3J3Kn/YJMSaDUEmLtCxiAroTd8j+S9K2g9WCoq3XvpM6yXm1qORRAjqFMuhzL H5fQ== X-Forwarded-Encrypted: i=1; AJvYcCUV4/SR83BGE/OCvGNdAjU2JDo2xuDfrQJ0xAglYKxrDzhSvwYtScg4YXqy+ZjXElprgo1IZzI4pBU6fqw=@vger.kernel.org X-Gm-Message-State: AOJu0YwMZGXvCC47ZLW2iPo1M3H0v1CpxVKvA1/PAWShtRcjFZz/V5yN SfR1O0NijabpmlJL9lEUwSQj446OEYlC2u1iFN6mdjherFmWIZQ+oADTzDW6xbKy9A== X-Gm-Gg: ASbGncuw3Sn1drmHCykqUWLGsK096WL7axx/cGJ6roFLJJQCloML4i4ZMm+PpN8r5mj J0/893yYq2s3VRTAZbhuHxoeIHBYAbr5IcU2R/qnaa+kIRA4omIhdRhrR+0UWt/+27z0bsDMBOB vjdX5n/ZScUNN6UN4F/7ZNpPBi7zfrK2Y2M6v0xgOFVKyC/XC/cpRlwwMEn0fyaMpcxDSW4CFxN gRbzKJtqUAGZodRRkQcaPTKXXX4N43cWsUh1SZSC4A6hFHdstnu1WWdcq+POlcouNqLkkGcLAAh nFlH9MoyvdRZmcuQ24kXtNWmHRhD0tlqlZgkYfSv2nAuoeYEV+zGZJKAMSzcNbxvc17fQgFk0JB Ix+2+5AkPXuzHV40Gqnz4fgCsiiWkmlUUGwMVOnLN+hf+Nnoi+x86 X-Google-Smtp-Source: AGHT+IH7cGazfkX+Q/r6UXJxDNNrYEeVRMUy3tM0qgcbXb/BVt0v1LwGWdxtyfIaNhvclHwiul1KLA== X-Received: by 2002:a17:907:e2cd:b0:ae0:7db8:4189 with SMTP id a640c23a62f3a-ae34fd38c3fmr1311198066b.18.1751292775141; Mon, 30 Jun 2025 07:12:55 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (72.144.91.34.bc.googleusercontent.com. [34.91.144.72]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae35363b416sm670643866b.28.2025.06.30.07.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 07:12:53 -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" , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v2 03/10] usb: typec: ucsi: Set alt_mode_override flag Date: Mon, 30 Jun 2025 14:12:32 +0000 Message-ID: <20250630141239.3174390-4-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250630141239.3174390-1-akuchynski@chromium.org> References: <20250630141239.3174390-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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 01ce858a1a2b..1372becaec82 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -1616,6 +1616,8 @@ 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->alt_mode_override =3D + !!(con->ucsi->cap.features & UCSI_CAP_ALT_MODE_OVERRIDE); =20 if (ucsi->ops->update_connector) ucsi->ops->update_connector(con); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 09:22:11 2025 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.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 824C528C5CC for ; Mon, 30 Jun 2025 14:12:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751292781; cv=none; b=cbJvUsDh42JW/p4As3V0EHFXXKlDh4Ew07jgmKt8mb4hRQvPNxfyQ6tUeoJxGVpgGBLhGApENlWY2hle4uRdQBv4MY796NXTgGEmTuaKJIKh3Mdqxxhdd2WEcx2VNGRLUwrfgJ78xk+/RXy4mfD4/7DWolACJrRWvbuUdiQd6GQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751292781; c=relaxed/simple; bh=fbFWhcTlNTRdWyl21dI+mXVR7oyksRyANGkxIYDmUH4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PjWsP1uox2Uu6JulIpRLeDswJz5kVsw7YAG9br0BmHucNbfk80XRQjYZdtdI572HdWYFmKsa9MH5lG+82jiUFBVJ29GKdkCFnx2X+ha6XPv2l3613d/bfT3fa3ZjhTnlaE4TfFPJ7asPhWX1NQ6+UhzJR3PPQHYM/AZLwJmqSec= 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=Nw6qpG6H; arc=none smtp.client-ip=209.85.208.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="Nw6qpG6H" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-607cf70b00aso9145229a12.2 for ; Mon, 30 Jun 2025 07:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751292778; x=1751897578; 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=zsuVofM4iWQWBL1t5ktFAF3YZKmCFx1yd4aN3Oe9hqM=; b=Nw6qpG6H0m0w36R2VyUFp1rMCvoZbXPQpzoXfb0hP2DOLOmRTAi5JQEdefIJZ2cKGK 76rqvPd9068PomcY4r8yvNhMXGqL12Wa+U9dk7tI5f/WdK1EsQzrLHaRs9BFL2D/I0k5 P5aa0F7M3dzZ2OENhfDwQiiOWV8SkV4BDi4j0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751292778; x=1751897578; 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=zsuVofM4iWQWBL1t5ktFAF3YZKmCFx1yd4aN3Oe9hqM=; b=oD6B7V7ubuya6hORDseAeIFT3BAd6wmaT/pnWFts2gFwlARETIHCZnVSZhieFeV51d RSmEEqsO8eC1Rxut3YvyHthtgPhzcsSDw2NLMSpxgQL53L2PerTNZJklax1EZHPVcdZ2 F3jRj0AKrTlXMhSqeQc6dEfyMSOtUjMf+/41zMmM4Mua7d8wRrf9Mhbr+vyuY03HmDn7 UGikMwZm7kvnokM39xaDBMUPjt8ZcWW6h7UmLcm5Wfzag5EM26HnQGUdynqOy1I/VzKV wZQT21HQgK7Gqnria1bkVJ0IqGjaWbRYzwK+G4bfhRM8U7FIAmtZNod2jTOCbNqFuZLg 7KhQ== X-Forwarded-Encrypted: i=1; AJvYcCUw8nWHMMIR5YhN2FRLEUVU6VsSgVGNshdAJDfokAWqHZVoBW3nM7ai23TCRi/3zFEHM4KaH+amNKK3ANo=@vger.kernel.org X-Gm-Message-State: AOJu0YzX1nOnjtk0Da7O7l8+szAfclMyY4vcd/vC+CRPd2Qt19LC2wsR 9boxiQC3OE5jv5HiI0IgGPPrkObTeClSgXjRK8sKx7OabT5+egxdce7IudBKOmUhzA== X-Gm-Gg: ASbGncsfORpxZRFeArp6eaZJ/RbNiUWGTudgWmWX1mNcqO5pfpXnODTX6pwdEvx/7Xx wzRCmxt1Pb11ZnQygtd5wCTrGzKmUHD83Nu09YP8JdC9Sxv3XzMLNu8wDJQvfu2CkbpCZZYrtOm M+dXMKcTJioAYMxS5eje8UT1Im3eagAkyawQAP7t1ViBlQPANH6WIH/nLPr5veLusfsVO6gDXvP rSc2t4vHGoe6omVgrLD8v/9Sa+BoS0hDN7Mr6V7usaUneHkuiCc3CpF1ruyR1m3i8ZgXRvpZCGA fsaUG6zl4/mbXcuHahbT65dlEnPdVCrt6HjEWoI0DjzIRWUH3oS3pey+YO/e0vvNVkDz405sqXE 66xDI4ZzzIlQ1scqCVB9Bm8Wu1JMlTDPANv+04a6pZ9lx6aUT/YX6 X-Google-Smtp-Source: AGHT+IFng48vS8GwHtMSOPA8+nACXUmszhIUqjqoOz2PD+r5leUDPaXGLvaPuVpVb/IEbJD9uKO2Ow== X-Received: by 2002:a17:907:e885:b0:ade:4121:8d52 with SMTP id a640c23a62f3a-ae34fd6c415mr1272248866b.16.1751292777693; Mon, 30 Jun 2025 07:12:57 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (72.144.91.34.bc.googleusercontent.com. [34.91.144.72]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae35363b416sm670643866b.28.2025.06.30.07.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 07:12:56 -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" , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v2 04/10] usb: typec: Expose mode priorities via sysfs Date: Mon, 30 Jun 2025 14:12:33 +0000 Message-ID: <20250630141239.3174390-5-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250630141239.3174390-1-akuchynski@chromium.org> References: <20250630141239.3174390-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 sysfs attribute specifies the preferred order for enabling DisplayPort, Thunderbolt alternate modes, and USB4 mode. Signed-off-by: Andrei Kuchynski --- Documentation/ABI/testing/sysfs-class-typec | 16 +++ drivers/usb/typec/Makefile | 2 +- drivers/usb/typec/class.c | 28 ++++- drivers/usb/typec/class.h | 4 + drivers/usb/typec/mode_selection.c | 116 ++++++++++++++++++++ drivers/usb/typec/mode_selection.h | 19 ++++ include/linux/usb/typec_altmode.h | 7 ++ 7 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 drivers/usb/typec/mode_selection.c create mode 100644 drivers/usb/typec/mode_selection.h diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/AB= I/testing/sysfs-class-typec index 38e101c17a00..ff3296ee8e1c 100644 --- a/Documentation/ABI/testing/sysfs-class-typec +++ b/Documentation/ABI/testing/sysfs-class-typec @@ -162,6 +162,22 @@ 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//mode_priorities +Date: June 2025 +Contact: Andrei Kuchynski +Description: Lists the modes supported by the port, ordered by their + activation priority. It defines the preferred sequence for activating + modes such as Displayport alt-mode, Thunderbolt alt-mode and USB4 mode. + The default order can be modified by writing a new sequence to this + attribute. Any modes omitted from a user-provided list will be + automatically placed at the end of the list. + + Example values: + - "USB4 TBT DP": default priority order + - "USB4 DP TBT": modified priority order after writing "USB4 DP TBT" or + "USB4 DP" + - "DP": the port only supports Displayport alt-mode + 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/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/class.c b/drivers/usb/typec/class.c index a72325ff099a..93eadbcdd4c0 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 @@ -540,7 +541,7 @@ static void typec_altmode_release(struct device *dev) } =20 const struct device_type typec_altmode_dev_type =3D { - .name =3D "typec_alternate_mode", + .name =3D ALTERNATE_MODE_DEVICE_TYPE_NAME, .groups =3D typec_altmode_groups, .release =3D typec_altmode_release, }; @@ -1942,6 +1943,25 @@ static ssize_t orientation_show(struct device *dev, } static DEVICE_ATTR_RO(orientation); =20 +static ssize_t mode_priorities_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + struct typec_port *port =3D to_typec_port(dev); + int ret =3D typec_mode_priorities_set(port, buf); + + return ret ? : size; +} + +static ssize_t mode_priorities_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct typec_port *port =3D to_typec_port(dev); + + return typec_mode_priorities_get(port, buf); +} +static DEVICE_ATTR_RW(mode_priorities); + static struct attribute *typec_attrs[] =3D { &dev_attr_data_role.attr, &dev_attr_power_operation_mode.attr, @@ -1954,6 +1974,7 @@ static struct attribute *typec_attrs[] =3D { &dev_attr_port_type.attr, &dev_attr_orientation.attr, &dev_attr_usb_capability.attr, + &dev_attr_mode_priorities.attr, NULL, }; =20 @@ -1992,6 +2013,9 @@ static umode_t typec_attr_is_visible(struct kobject *= kobj, return 0; if (!port->ops || !port->ops->default_usb_mode_set) return 0444; + } else if (attr =3D=3D &dev_attr_mode_priorities.attr) { + if (!port->alt_mode_override) + return 0; } =20 return attr->mode; @@ -2652,6 +2676,8 @@ struct typec_port *typec_register_port(struct device = *parent, else if (cap->usb_capability & USB_CAPABILITY_USB2) port->usb_mode =3D USB_MODE_USB2; =20 + typec_mode_priorities_set(port, ""); + device_initialize(&port->dev); port->dev.class =3D &typec_class; port->dev.parent =3D parent; diff --git a/drivers/usb/typec/class.h b/drivers/usb/typec/class.h index f05d9201c233..28b3c19a0632 100644 --- a/drivers/usb/typec/class.h +++ b/drivers/usb/typec/class.h @@ -5,6 +5,7 @@ =20 #include #include +#include =20 struct typec_mux; struct typec_switch; @@ -82,6 +83,7 @@ struct typec_port { struct device *usb3_dev; =20 bool alt_mode_override; + int mode_priority_list[TYPEC_MODE_MAX]; }; =20 #define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev) @@ -111,4 +113,6 @@ static inline int typec_link_ports(struct typec_port *c= onnector) { return 0; } static inline void typec_unlink_ports(struct typec_port *connector) { } #endif =20 +#define ALTERNATE_MODE_DEVICE_TYPE_NAME "typec_alternate_mode" + #endif /* __USB_TYPEC_CLASS__ */ diff --git a/drivers/usb/typec/mode_selection.c b/drivers/usb/typec/mode_se= lection.c new file mode 100644 index 000000000000..cb7ddf679037 --- /dev/null +++ b/drivers/usb/typec/mode_selection.c @@ -0,0 +1,116 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2025 Google LLC. + */ + +#include +#include +#include "mode_selection.h" +#include "class.h" + +static const char * const mode_names[] =3D { + [TYPEC_DP_ALTMODE] =3D "DP", + [TYPEC_TBT_ALTMODE] =3D "TBT", + [TYPEC_USB4_MODE] =3D "USB4", +}; +static const char * const default_priorities =3D "USB4 TBT DP"; + +/* -----------------------------------------------------------------------= --- */ +/* port 'mode_priorities' attribute */ +static int typec_mode_parse_priority_string(const char *str, int *list) +{ + const bool user_settings =3D list[0] =3D=3D TYPEC_MODE_MAX; + char *buf, *ptr; + char *token; + int ret =3D 0; + + buf =3D vmalloc(strlen(str) + 1); + if (!buf) + return -ENOMEM; + for (int i =3D 0; i <=3D strlen(str); i++) + buf[i] =3D (str[i] =3D=3D '\n') ? '\0' : str[i]; + ptr =3D buf; + + while ((token =3D strsep(&ptr, " ")) && !ret) { + if (strlen(token)) { + int mode =3D 0; + + while ((mode < TYPEC_MODE_MAX) && + strcmp(token, mode_names[mode])) + mode++; + if (mode =3D=3D TYPEC_MODE_MAX) { + ret =3D -EINVAL; + continue; + } + + for (int i =3D 0; i < TYPEC_MODE_MAX; i++) { + if (list[i] =3D=3D TYPEC_MODE_MAX) { + list[i] =3D mode; + break; + } + if (list[i] =3D=3D mode) { + if (user_settings) + ret =3D -EINVAL; + break; + } + } + } + } + vfree(buf); + + return ret; +} + +int typec_mode_priorities_set(struct typec_port *port, + const char *user_priorities) +{ + int list[TYPEC_MODE_MAX]; + int ret; + + for (int i =3D 0; i < TYPEC_MODE_MAX; i++) + list[i] =3D TYPEC_MODE_MAX; + + ret =3D typec_mode_parse_priority_string(user_priorities, list); + if (!ret) + ret =3D typec_mode_parse_priority_string(default_priorities, list); + + if (!ret) + for (int i =3D 0; i < TYPEC_MODE_MAX; i++) + port->mode_priority_list[i] =3D list[i]; + + return ret; +} + +static int port_altmode_supported(struct device *dev, void *data) +{ + if (!strcmp(dev->type->name, ALTERNATE_MODE_DEVICE_TYPE_NAME)) { + struct typec_altmode *alt =3D to_typec_altmode(dev); + + if (*(int *)data =3D=3D typec_svid_to_altmode(alt->svid)) + return 1; + } + return 0; +} + +static bool port_mode_supported(struct typec_port *port, int mode) +{ + if (mode >=3D TYPEC_MODE_MAX) + return false; + if (mode =3D=3D TYPEC_USB4_MODE) + return !!(port->cap->usb_capability & USB_CAPABILITY_USB4); + return device_for_each_child(&port->dev, &mode, port_altmode_supported); +} + +int typec_mode_priorities_get(struct typec_port *port, char *buf) +{ + ssize_t count =3D 0; + + for (int i =3D 0; i < TYPEC_MODE_MAX; i++) { + int mode =3D port->mode_priority_list[i]; + + if (port_mode_supported(port, mode)) + count +=3D sysfs_emit_at(buf, count, "%s ", mode_names[mode]); + } + + return count + sysfs_emit_at(buf, count, "\n"); +} diff --git a/drivers/usb/typec/mode_selection.h b/drivers/usb/typec/mode_se= lection.h new file mode 100644 index 000000000000..c595c84e26a4 --- /dev/null +++ b/drivers/usb/typec/mode_selection.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include +#include + +static inline int typec_svid_to_altmode(const u16 svid) +{ + switch (svid) { + case USB_TYPEC_DP_SID: + return TYPEC_DP_ALTMODE; + case USB_TYPEC_TBT_SID: + return TYPEC_TBT_ALTMODE; + } + return TYPEC_MODE_MAX; +} + +int typec_mode_priorities_set(struct typec_port *port, + const char *user_priorities); +int typec_mode_priorities_get(struct typec_port *port, char *buf); diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_al= tmode.h index b3c0866ea70f..4f05c5f5c91d 100644 --- a/include/linux/usb/typec_altmode.h +++ b/include/linux/usb/typec_altmode.h @@ -145,6 +145,13 @@ enum { =20 #define TYPEC_MODAL_STATE(_state_) ((_state_) + TYPEC_STATE_MODAL) =20 +enum { + TYPEC_DP_ALTMODE =3D 0, + TYPEC_TBT_ALTMODE, + TYPEC_USB4_MODE, + TYPEC_MODE_MAX, +}; + struct typec_altmode *typec_altmode_get_plug(struct typec_altmode *altmode, enum typec_plug_index index); void typec_altmode_put_plug(struct typec_altmode *plug); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 09:22:11 2025 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 7F32D28BAA1 for ; Mon, 30 Jun 2025 14:13:02 +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=1751292785; cv=none; b=VZl8p29dahp+++h+JXfURVYTL5MlnGOQ4c6RJUrtZFzotJ3V9nIIlw/vnxyU8LKJt9l1pk0s2X50uDVyTanC6NRMuNtAp+oG3nEQ6Ipz+JKMkvmTq4SxavCAq0jHdPuDepuFc36Cs25UUZfeC28qL44AtoA/tDK5X3bOTqNUql4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751292785; c=relaxed/simple; bh=s/k5WYOwT5p+nmwNFgcSXpx6SWgklWpQaiFbLfMDTDE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p2/5NWsFy/86ISPjjnZO51CrXBkxjRPkH3bbcqFjB7HxmnzpPpYyZmtm1w7fWh82MXf6Jzx6aEvtqa1Bb8KXzrU2ABBVCzZrKtJidHedSRBw2BrkCTMDkM4pQ6vEtgHqFMKoVU+vOGLbny5ve8f/hUV1vI3EU6JrcM8EMC84Pk0= 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=WwzuidTP; 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="WwzuidTP" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-60c3aafae23so12051979a12.1 for ; Mon, 30 Jun 2025 07:13:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751292781; x=1751897581; 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=EjogWbmRChrVg/U9/QBtp789lljuLZEtjuIUOjGjLMA=; b=WwzuidTPT+epE7U00DUeRbDMCvcquOqAx3RxamW0Gi8f8qRZ8atjO9YtP/ox9a9vS3 4J5VC5lcHz9cTRShDXUhp7b+352YUvs+3jaMjXZFKAU9knRSdC2kcAAJl7ZLpkH9zJ/E +fZ79VV8gDmEsuP1LlOq2t5rb/uBx7cAJwL0o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751292781; x=1751897581; 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=EjogWbmRChrVg/U9/QBtp789lljuLZEtjuIUOjGjLMA=; b=sNzxDHVmMJKiRWzpXyjDK6EKAtMxeUAM/b6eIa10Hjnb+gFMkM4cRsKd9YhWdwcs8z LUVAyf6s2osPVZT00hxs9vUGyJ3r7hSjypBQPRgrIy5uIBUuRAkxIISVLkziNGrpxlok K1Ho+Nx5V0MEyDr4qwYuGW/zCByX2z0ewVoklyF94nyAZ/YQLozqiCCo87XBr9aj70Dq uCzjo/C4nKEpEd7MVZ2gxghon8XJIMzO48ohkzoQ4AxgLTKCzJrbJmgcbRCLGtiJe3Cr DV0nrTRoBnADlYExUQH4nAD1XO30Hc9TG4SWtAO/LRKClfKQgpF//g2RcZuIczo19bQ9 Mj6g== X-Forwarded-Encrypted: i=1; AJvYcCUTRflX9pNmRH5oJfjDChqxnQDmxvS/K7Z/rBTqZjNrECPXkS63Uc7qz9+I+Z+HvkxM7RN4s37MKS7eWBU=@vger.kernel.org X-Gm-Message-State: AOJu0YwbaCrlnMwBPgEeYCe5AL24XCQgBuy9nx0mTK6Y3s9mskTVxHMP A8UaUBh8S2/B5v8d4nZO46LwDKuuDxD3TEyL5yxfsiIKFEKHqDC5QPRcKj7kINgLGA== X-Gm-Gg: ASbGncugmJ5qCl0A1tbWKS8mnmOTMhvkN5b2Pk9uiABY7/DGSyRWLjlGzfnP6S+km0M zSZwxqR+mIJSGzqN6vcsis9Lia8cNIxbBJmqpDlu3gOZrAfzjrdZEGhL6URT7MEZeG94ynrJEMW H+anTRPg0B135ua+9V7NVGtS3MemBtXayRYXQu1eMK4PG8CiNS3Y9PVnehMPvMwwgNsnNQDadT3 ND6CrO9eVLkw1iuW87dOh6/wKDW0nmlPLMeEcOigwF9Q+/Yye0UGXeADUEFxlrF/rehQ16CICYK l6e6DjaT/7ppm+hW9dS8u/xhRkvub8JaOR1OyXvohfiNPE/OD9aWRR3be1wXbq78Ydk1MrBA5IM AojpUNPrvNoWShV8q0XgWZugoybBDEr2ch5I3mYPSWDtTCS5pAKZ3HBEodm6/uYY= X-Google-Smtp-Source: AGHT+IHcLuKRmuowR4Ws5a+TXpVMjv8QGOB507cIESGE9ZRi1wNw2bdiobBj9vYSo52E+U4pHwEnMg== X-Received: by 2002:a17:907:d25:b0:ae3:5be2:d9c8 with SMTP id a640c23a62f3a-ae35be2df63mr1229074666b.3.1751292780471; Mon, 30 Jun 2025 07:13:00 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (72.144.91.34.bc.googleusercontent.com. [34.91.144.72]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae35363b416sm670643866b.28.2025.06.30.07.12.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 07:12: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 , Dmitry Baryshkov , "Christian A. Ehrhardt" , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v2 05/10] usb: typec: Implement automated mode selection Date: Mon, 30 Jun 2025 14:12:34 +0000 Message-ID: <20250630141239.3174390-6-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250630141239.3174390-1-akuchynski@chromium.org> References: <20250630141239.3174390-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 commit introduces mode_selection sysfs attribute to control automated mode negotiation. Writing "yes" to this file activates the automated selection process for DisplayPort, Thunderbolt alternate modes, and USB4 mode. Conversely, writing "no" will cancel any ongoing selection process and exit the currently active mode. Signed-off-by: Andrei Kuchynski --- Documentation/ABI/testing/sysfs-class-typec | 17 + drivers/usb/typec/class.c | 52 ++- drivers/usb/typec/class.h | 10 + drivers/usb/typec/mode_selection.c | 413 ++++++++++++++++++++ drivers/usb/typec/mode_selection.h | 30 ++ include/linux/usb/pd_vdo.h | 2 + include/linux/usb/typec_altmode.h | 5 + 7 files changed, 527 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/AB= I/testing/sysfs-class-typec index ff3296ee8e1c..0ffc71a7c374 100644 --- a/Documentation/ABI/testing/sysfs-class-typec +++ b/Documentation/ABI/testing/sysfs-class-typec @@ -263,6 +263,23 @@ Description: The USB Modes that the partner device sup= ports. The active mode - usb3 (USB 3.2) - usb4 (USB4) =20 +What: /sys/class/typec/-partner/mode_selection +Date: June 2025 +Contact: Andrei Kuchynski +Description: Lists the partner-supported alternate modes and mode entry + results with the currently entered mode bracketed. If a cable doesn't + support a mode, it's marked as 'nc'. An ellipsis indicates a mode + currently in progress. Automated mode selection is activated by writing + "yes" to the file. Conversely, writing "no" will cancel any ongoing + selection process and exit the currently active mode, if any. + + Example values: + - "DP TBT=3D... USB4=3Dnc": The cable does not support USB4 mode, + The driver is currently attempting to enter Thunderbolt alt-mode. + - "[DP] TBT=3D-EOPNOTSUPP USB4=3D-ETIME": USB4 mode entry failed due to + a timeout, Thunderbolt failed with the result -EOPNOTSUPP, + and DisplayPort is the active alt-mode. + USB Type-C cable devices (eg. /sys/class/typec/port0-cable/) =20 Note: Electronically Marked Cables will have a device also for one cable p= lug diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 93eadbcdd4c0..8455e07a9934 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -741,6 +741,33 @@ static ssize_t number_of_alternate_modes_show(struct d= evice *dev, struct device_ } static DEVICE_ATTR_RO(number_of_alternate_modes); =20 +static ssize_t mode_selection_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct typec_partner *partner =3D to_typec_partner(dev); + + return typec_mode_selection_get(partner, buf); +} + +static ssize_t mode_selection_store(struct device *dev, struct device_attr= ibute *attr, + const char *buf, size_t size) +{ + struct typec_partner *partner =3D to_typec_partner(dev); + bool start; + int ret =3D kstrtobool(buf, &start); + + if (!ret) { + if (start) + ret =3D typec_mode_selection_start(partner); + else + ret =3D typec_mode_selection_reset(partner); + } + + return ret ? : size; +} +static DEVICE_ATTR_RW(mode_selection); + static struct attribute *typec_partner_attrs[] =3D { &dev_attr_accessory_mode.attr, &dev_attr_supports_usb_power_delivery.attr, @@ -748,6 +775,7 @@ static struct attribute *typec_partner_attrs[] =3D { &dev_attr_type.attr, &dev_attr_usb_mode.attr, &dev_attr_usb_power_delivery_revision.attr, + &dev_attr_mode_selection.attr, NULL }; =20 @@ -772,6 +800,10 @@ static umode_t typec_partner_attr_is_visible(struct ko= bject *kobj, struct attrib if (!get_pd_product_type(kobj_to_dev(kobj))) return 0; =20 + if (attr =3D=3D &dev_attr_mode_selection.attr) + if (!port->alt_mode_override) + return 0; + return attr->mode; } =20 @@ -850,8 +882,10 @@ int typec_partner_set_identity(struct typec_partner *p= artner) usb_capability |=3D USB_CAPABILITY_USB2; if (devcap & DEV_USB3_CAPABLE) usb_capability |=3D USB_CAPABILITY_USB3; - if (devcap & DEV_USB4_CAPABLE) + if (devcap & DEV_USB4_CAPABLE) { usb_capability |=3D USB_CAPABILITY_USB4; + typec_mode_selection_add_mode(partner, TYPEC_USB4_MODE); + } } else { usb_capability =3D PD_VDO_DFP_HOSTCAP(id->vdo[0]); } @@ -971,7 +1005,12 @@ struct typec_altmode * typec_partner_register_altmode(struct typec_partner *partner, const struct typec_altmode_desc *desc) { - return typec_register_altmode(&partner->dev, desc); + struct typec_altmode *alt =3D typec_register_altmode(&partner->dev, desc); + + if (alt) + typec_mode_selection_add_mode(partner, typec_svid_to_altmode(alt->svid)); + + return alt; } EXPORT_SYMBOL_GPL(typec_partner_register_altmode); =20 @@ -1075,6 +1114,8 @@ struct typec_partner *typec_register_partner(struct t= ypec_port *port, typec_partner_link_device(partner, port->usb3_dev); mutex_unlock(&port->partner_link_lock); =20 + typec_mode_selection_create(partner); + return partner; } EXPORT_SYMBOL_GPL(typec_register_partner); @@ -1092,6 +1133,7 @@ void typec_unregister_partner(struct typec_partner *p= artner) if (IS_ERR_OR_NULL(partner)) return; =20 + typec_mode_selection_destroy(partner); port =3D to_typec_port(partner->dev.parent); =20 mutex_lock(&port->partner_link_lock); @@ -1360,6 +1402,7 @@ int typec_cable_set_identity(struct typec_cable *cabl= e) } EXPORT_SYMBOL_GPL(typec_cable_set_identity); =20 +static struct typec_partner *typec_get_partner(struct typec_port *port); /** * typec_register_cable - Register a USB Type-C Cable * @port: The USB Type-C Port the cable is connected to @@ -1374,6 +1417,7 @@ struct typec_cable *typec_register_cable(struct typec= _port *port, struct typec_cable_desc *desc) { struct typec_cable *cable; + struct typec_partner *partner; int ret; =20 cable =3D kzalloc(sizeof(*cable), GFP_KERNEL); @@ -1405,6 +1449,10 @@ struct typec_cable *typec_register_cable(struct type= c_port *port, return ERR_PTR(ret); } =20 + partner =3D typec_get_partner(port); + typec_mode_selection_add_cable(partner, cable); + put_device(&partner->dev); + return cable; } EXPORT_SYMBOL_GPL(typec_register_cable); diff --git a/drivers/usb/typec/class.h b/drivers/usb/typec/class.h index 28b3c19a0632..17efaacc2b8f 100644 --- a/drivers/usb/typec/class.h +++ b/drivers/usb/typec/class.h @@ -6,6 +6,7 @@ #include #include #include +#include =20 struct typec_mux; struct typec_switch; @@ -27,6 +28,8 @@ struct typec_cable { enum usb_pd_svdm_ver svdm_version; }; =20 +struct mode_selection_state; + struct typec_partner { struct device dev; unsigned int usb_pd:1; @@ -41,6 +44,13 @@ struct typec_partner { =20 struct usb_power_delivery *pd; =20 + struct delayed_work mode_selection_work; + DECLARE_KFIFO(mode_sequence, struct mode_selection_state *, + roundup_pow_of_two(TYPEC_MODE_MAX)); + struct mutex mode_sequence_lock; + struct mode_selection_state *mode_states; + struct mode_selection_state *active_mode; + 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 index cb7ddf679037..5b29ca0201ca 100644 --- a/drivers/usb/typec/mode_selection.c +++ b/drivers/usb/typec/mode_selection.c @@ -5,9 +5,25 @@ =20 #include #include +#include +#include #include "mode_selection.h" #include "class.h" =20 +static unsigned int mode_selection_timeout =3D 4000; +module_param(mode_selection_timeout, uint, 0644); +MODULE_PARM_DESC(mode_selection_timeout, "The timeout mode entry, ms"); + +static unsigned int mode_selection_delay =3D 1000; +module_param(mode_selection_delay, uint, 0644); +MODULE_PARM_DESC(mode_selection_delay, + "The delay between attempts to enter or exit a mode, ms"); + +static unsigned int mode_selection_entry_attempts =3D 4; +module_param(mode_selection_entry_attempts, uint, 0644); +MODULE_PARM_DESC(mode_selection_entry_attempts, + "Max attempts to enter mode on BUSY result"); + static const char * const mode_names[] =3D { [TYPEC_DP_ALTMODE] =3D "DP", [TYPEC_TBT_ALTMODE] =3D "TBT", @@ -15,6 +31,15 @@ static const char * const mode_names[] =3D { }; static const char * const default_priorities =3D "USB4 TBT DP"; =20 +struct mode_selection_state { + int mode; + bool enable; + bool cable_capability; + bool enter; + int attempt_count; + int result; +}; + /* -----------------------------------------------------------------------= --- */ /* port 'mode_priorities' attribute */ static int typec_mode_parse_priority_string(const char *str, int *list) @@ -114,3 +139,391 @@ int typec_mode_priorities_get(struct typec_port *port= , char *buf) =20 return count + sysfs_emit_at(buf, count, "\n"); } + +/* -----------------------------------------------------------------------= --- */ +/* partner 'mod_selection' attribute */ + +/** + * mode_selection_next() - Process mode selection results and schedule next + * action + * + * This function evaluates the outcome of the previous mode entry or exit + * attempt. Based on this result, it determines the next mode to process a= nd + * schedules `mode_selection_work()` if further actions are required. + * + * If the previous mode entry was successful, the mode selection sequence = is + * considered complete for the current cycle. + * + * If the previous mode entry failed, this function schedules + * `mode_selection_work()` to attempt exiting the mode that was partially + * activated but not fully entered. + * + * If the previous operation was an exit (after a failed entry attempt), + * `mode_selection_next()` then advances the internal list of candidate + * modes to determine the next mode to enter. + */ +static void mode_selection_next( + struct typec_partner *partner, struct mode_selection_state *ms) +{ + if (!ms->enter) { + kfifo_skip(&partner->mode_sequence); + } else if (!ms->result) { + dev_info(&partner->dev, "%s mode entered\n", mode_names[ms->mode]); + + partner->active_mode =3D ms; + kfifo_reset(&partner->mode_sequence); + } else { + dev_err(&partner->dev, "%s mode entry failed: %pe\n", + mode_names[ms->mode], ERR_PTR(ms->result)); + + if (ms->result !=3D -EBUSY || + ms->attempt_count >=3D mode_selection_entry_attempts) + ms->enter =3D false; + } + + if (!kfifo_is_empty(&partner->mode_sequence)) + schedule_delayed_work(&partner->mode_selection_work, + msecs_to_jiffies(mode_selection_delay)); +} + +static void mode_selection_complete(struct typec_partner *partner, + const int mode, const int result) +{ + struct mode_selection_state *ms; + + mutex_lock(&partner->mode_sequence_lock); + if (kfifo_peek(&partner->mode_sequence, &ms)) { + if (ms->mode =3D=3D mode) { + ms->result =3D result; + cancel_delayed_work(&partner->mode_selection_work); + mode_selection_next(partner, ms); + } + } + mutex_unlock(&partner->mode_sequence_lock); +} + +void typec_mode_selection_altmode_complete(struct typec_altmode *alt, + const int result) +{ + mode_selection_complete(to_typec_partner(alt->dev.parent), + typec_svid_to_altmode(alt->svid), result); +} +EXPORT_SYMBOL_GPL(typec_mode_selection_altmode_complete); + +void typec_mode_selection_usb4_complete(struct typec_partner *partner, + const int result) +{ + mode_selection_complete(partner, TYPEC_USB4_MODE, result); +} +EXPORT_SYMBOL_GPL(typec_mode_selection_usb4_complete); + +static void mode_selection_activate_usb4_mode(struct typec_partner *partne= r, + struct mode_selection_state *ms) +{ + struct typec_port *port =3D to_typec_port(partner->dev.parent); + int result =3D -EOPNOTSUPP; + + if (port->ops && port->ops->enter_usb_mode) { + if (ms->enter && port->usb_mode !=3D USB_MODE_USB4) + result =3D -EPERM; + else + result =3D port->ops->enter_usb_mode(port, + ms->enter ? USB_MODE_USB4 : USB_MODE_USB3); + } + + if (ms->enter) + ms->result =3D result; +} + +static int mode_selection_activate_altmode(struct device *dev, void *data) +{ + struct typec_altmode *alt =3D to_typec_altmode(dev); + struct mode_selection_state *ms =3D (struct mode_selection_state *)data; + int result =3D -ENODEV; + + if (!strcmp(dev->type->name, ALTERNATE_MODE_DEVICE_TYPE_NAME)) { + if (ms->mode =3D=3D typec_svid_to_altmode(alt->svid)) { + if (alt->ops && alt->ops->activate) + result =3D alt->ops->activate(alt, ms->enter ? 1 : 0); + else + result =3D -EOPNOTSUPP; + } + } + + if (ms->enter) + ms->result =3D result; + + return result =3D=3D -ENODEV ? 0 : 1; +} + +static void mode_selection_activate_mode(struct typec_partner *partner, + struct mode_selection_state *ms) +{ + dev_info(&partner->dev, "%s %s mode\n", + ms->enter ? "Enter" : "Exit", mode_names[ms->mode]); + + if (ms->enter) + ms->attempt_count++; + + if (ms->mode =3D=3D TYPEC_USB4_MODE) + mode_selection_activate_usb4_mode(partner, ms); + else + device_for_each_child(&partner->dev, ms, + mode_selection_activate_altmode); + + if (ms->enter && ms->result) + dev_err(&partner->dev, "%s mode activation failed: %pe\n", + mode_names[ms->mode], ERR_PTR(ms->result)); +} + +/** + * mode_selection_work() - Activate entry into the upcoming mode + * + * This function works in conjunction with `mode_selection_next()`. + * It attempts to activate the next mode in the selection sequence. + * + * If the mode activation (`mode_selection_activate_mode()`) fails, + * `mode_selection_next()` will be called to initiate a new selection cycl= e. + * + * Otherwise, the result is temporarily set to -ETIME, and + * `mode_selection_activate_mode()` is scheduled for a subsequent entry af= ter a + * timeout period. The alternate mode driver is expected to call back with= the + * actual mode entry result. Upon this callback, `mode_selection_next()` w= ill + * determine the subsequent mode and re-schedule mode_selection_work(). + */ +static void mode_selection_work(struct work_struct *work) +{ + struct typec_partner *partner =3D container_of(work, struct typec_partner, + mode_selection_work.work); + struct mode_selection_state *ms; + + mutex_lock(&partner->mode_sequence_lock); + if (kfifo_peek(&partner->mode_sequence, &ms)) { + if (ms->enter && ms->result =3D=3D -ETIME) { + mode_selection_next(partner, ms); + } else { + mode_selection_activate_mode(partner, ms); + + if (ms->enter) { + if (!ms->result) { + ms->result =3D -ETIME; + schedule_delayed_work(&partner->mode_selection_work, + msecs_to_jiffies(mode_selection_timeout)); + } else { + ms->enter =3D ms->result =3D=3D -EBUSY; + mode_selection_next(partner, ms); + } + } else + mode_selection_next(partner, ms); + } + } + mutex_unlock(&partner->mode_sequence_lock); +} + +static void mode_selection_init(struct typec_partner *partner) +{ + for (int i =3D 0; i < TYPEC_MODE_MAX; i++) { + partner->mode_states[i].mode =3D i; + partner->mode_states[i].enter =3D true; + partner->mode_states[i].result =3D 0; + partner->mode_states[i].attempt_count =3D 0; + } + + kfifo_reset(&partner->mode_sequence); + partner->active_mode =3D NULL; +} + +int typec_mode_selection_create(struct typec_partner *partner) +{ + partner->mode_states =3D vmalloc( + sizeof(struct mode_selection_state) * TYPEC_MODE_MAX); + if (!partner->mode_states) + return -ENOMEM; + + INIT_KFIFO(partner->mode_sequence); + mutex_init(&partner->mode_sequence_lock); + mode_selection_init(partner); + INIT_DELAYED_WORK(&partner->mode_selection_work, mode_selection_work); + + return 0; +} + +void typec_mode_selection_add_mode(struct typec_partner *partner, + const int mode) +{ + if (partner->mode_states) + partner->mode_states[mode].enable =3D + port_mode_supported(to_typec_port(partner->dev.parent), mode); +} + +void typec_mode_selection_add_cable(struct typec_partner *partner, + struct typec_cable *cable) +{ + const u32 id_header =3D cable->identity->id_header; + const u32 vdo1 =3D cable->identity->vdo[0]; + const u32 type =3D PD_IDH_PTYPE(id_header); + const u32 speed =3D VDO_TYPEC_CABLE_SPEED(vdo1); + bool capability[] =3D { + [TYPEC_DP_ALTMODE] =3D true, + [TYPEC_TBT_ALTMODE] =3D false, + [TYPEC_USB4_MODE] =3D false, + }; + + if (!partner->mode_states) + return; + + if (type =3D=3D IDH_PTYPE_PCABLE) { + capability[TYPEC_DP_ALTMODE] =3D (speed > CABLE_USB2_ONLY); + capability[TYPEC_TBT_ALTMODE] =3D (speed > CABLE_USB2_ONLY); + capability[TYPEC_USB4_MODE] =3D (speed > CABLE_USB2_ONLY); + } else if (type =3D=3D IDH_PTYPE_ACABLE) { + const u32 vdo2 =3D cable->identity->vdo[1]; + const u32 version =3D VDO_TYPEC_CABLE_VERSION(vdo1); + const bool usb4_support =3D VDO_TYPEC_CABLE_USB4_SUPP(vdo2); + const bool modal_support =3D PD_IDH_MODAL_SUPP(id_header); + + capability[TYPEC_DP_ALTMODE] =3D modal_support; + capability[TYPEC_TBT_ALTMODE] =3D true; + if (version =3D=3D CABLE_VDO_VER1_3) + capability[TYPEC_USB4_MODE] =3D usb4_support; + else + capability[TYPEC_USB4_MODE] =3D modal_support; + } + + for (int i =3D 0; i < TYPEC_MODE_MAX; i++) + partner->mode_states[i].cable_capability =3D capability[i]; +} + +void typec_mode_selection_destroy(struct typec_partner *partner) +{ + if (!partner->mode_states) + return; + + mutex_lock(&partner->mode_sequence_lock); + kfifo_reset(&partner->mode_sequence); + mutex_unlock(&partner->mode_sequence_lock); + + cancel_delayed_work_sync(&partner->mode_selection_work); + mutex_destroy(&partner->mode_sequence_lock); + vfree(partner->mode_states); + partner->mode_states =3D NULL; +} + +/** + * typec_mode_selection_start() - Starts the mode selection process. + * + * This function populates a 'mode_sequence' FIFO with pointers to + * `struct mode_selection_state` instances. The sequence is generated base= d on + * partner/cable capabilities and prioritized according to the port's sett= ings. + */ +int typec_mode_selection_start(struct typec_partner *partner) +{ + struct typec_port *port =3D to_typec_port(partner->dev.parent); + int ret =3D 0; + + if (!partner->mode_states) + return -ENOMEM; + + mutex_lock(&partner->mode_sequence_lock); + + if (!kfifo_is_empty(&partner->mode_sequence)) + ret =3D -EINPROGRESS; + else if (partner->active_mode) + ret =3D -EALREADY; + else { + mode_selection_init(partner); + + for (int i =3D 0; i < TYPEC_MODE_MAX; i++) { + const int mode =3D port->mode_priority_list[i]; + struct mode_selection_state *ms; + + if (mode < TYPEC_MODE_MAX) { + ms =3D &partner->mode_states[mode]; + if (ms->enable && ms->cable_capability) + kfifo_put(&partner->mode_sequence, ms); + } + } + + if (!kfifo_is_empty(&partner->mode_sequence)) + schedule_delayed_work(&partner->mode_selection_work, 0); + } + + mutex_unlock(&partner->mode_sequence_lock); + + return ret; +} + +/** + * typec_mode_selection_reset() - Reset the mode selection process. + * + * This function cancels ongoing mode selection and exits the currently ac= tive + * mode, if present. + * It returns -EINPROGRESS when a mode exit is already scheduled, or a mode + * entry is ongoing, indicating that the reset cannot immediately complete. + */ +int typec_mode_selection_reset(struct typec_partner *partner) +{ + struct mode_selection_state *ms; + + if (!partner->mode_states) + return -ENOMEM; + + mutex_lock(&partner->mode_sequence_lock); + if (kfifo_peek(&partner->mode_sequence, &ms)) { + kfifo_reset(&partner->mode_sequence); + + if (!ms->enter || ms->result) { + ms->attempt_count =3D mode_selection_entry_attempts; + kfifo_put(&partner->mode_sequence, ms); + mutex_unlock(&partner->mode_sequence_lock); + + return -EINPROGRESS; + } + } + + if (partner->active_mode) { + partner->active_mode->enter =3D false; + mode_selection_activate_mode(partner, partner->active_mode); + } + mode_selection_init(partner); + mutex_unlock(&partner->mode_sequence_lock); + + return 0; +} + +int typec_mode_selection_get(struct typec_partner *partner, char *buf) +{ + ssize_t count =3D 0; + struct mode_selection_state *running_ms; + + if (!partner->mode_states) + return -ENOMEM; + + mutex_lock(&partner->mode_sequence_lock); + if (!kfifo_peek(&partner->mode_sequence, &running_ms)) + running_ms =3D NULL; + + for (int i =3D 0; i < TYPEC_MODE_MAX; i++) { + struct mode_selection_state *ms =3D &partner->mode_states[i]; + + if (ms->enable) { + if (!ms->cable_capability) + count +=3D sysfs_emit_at(buf, count, "%s=3Dnc ", mode_names[i]); + else if (ms =3D=3D running_ms) + count +=3D sysfs_emit_at(buf, count, "%s=3D... ", mode_names[i]); + else if (ms->attempt_count =3D=3D 0) + count +=3D sysfs_emit_at(buf, count, "%s ", mode_names[i]); + else if (ms->result =3D=3D 0) + count +=3D sysfs_emit_at(buf, count, "[%s] ", mode_names[i]); + else + count +=3D sysfs_emit_at(buf, count, "%s=3D%pe ", mode_names[i], + ERR_PTR(ms->result)); + } + } + mutex_unlock(&partner->mode_sequence_lock); + + if (count) + count +=3D sysfs_emit_at(buf, count, "\n"); + + return count; +} diff --git a/drivers/usb/typec/mode_selection.h b/drivers/usb/typec/mode_se= lection.h index c595c84e26a4..6a54792a20db 100644 --- a/drivers/usb/typec/mode_selection.h +++ b/drivers/usb/typec/mode_selection.h @@ -17,3 +17,33 @@ static inline int typec_svid_to_altmode(const u16 svid) int typec_mode_priorities_set(struct typec_port *port, const char *user_priorities); int typec_mode_priorities_get(struct typec_port *port, char *buf); + +/** + * The mode selection process follows a lifecycle tied to the USB-C partner + * device. The API is designed to first build a set of desired modes and t= hen + * trigger the selection process. The expected sequence of calls is as fol= lows: + * + * Creation and Configuration: + * call typec_mode_selection_create() when the partner device is being set + * up. This allocates resources for the mode selection. + * After creation, call typec_mode_selection_add_mode() and + * typec_mode_selection_add_cable() to define the parameters for the + * selection process. + * + * Execution: + * Call typec_mode_selection_start() to trigger the mode selection. + * Call typec_mode_selection_reset() to prematurely stop the selection + * process and clear any stored results. + * + * Destruction: + * Before destroying a partner, call typec_mode_selection_destroy() + */ +int typec_mode_selection_create(struct typec_partner *partner); +void typec_mode_selection_destroy(struct typec_partner *partner); +int typec_mode_selection_start(struct typec_partner *partner); +int typec_mode_selection_reset(struct typec_partner *partner); +void typec_mode_selection_add_mode(struct typec_partner *partner, + const int mode); +void typec_mode_selection_add_cable(struct typec_partner *partner, + struct typec_cable *cable); +int typec_mode_selection_get(struct typec_partner *partner, char *buf); diff --git a/include/linux/usb/pd_vdo.h b/include/linux/usb/pd_vdo.h index 5c48e8a81403..20bcf37ad634 100644 --- a/include/linux/usb/pd_vdo.h +++ b/include/linux/usb/pd_vdo.h @@ -439,6 +439,8 @@ | (trans) << 11 | (phy) << 10 | (ele) << 9 | (u4) << 8 \ | ((hops) & 0x3) << 6 | (u2) << 5 | (u32) << 4 | (lane) << 3 \ | (iso) << 2 | (gen)) +#define VDO_TYPEC_CABLE_VERSION(vdo) (((vdo) >> 21) & 0x7) +#define VDO_TYPEC_CABLE_USB4_SUPP(vdo) (((vdo) & BIT(8)) =3D=3D ACAB2_USB4= _SUPP) =20 /* * AMA VDO (PD Rev2.0) diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_al= tmode.h index 4f05c5f5c91d..49213cf27565 100644 --- a/include/linux/usb/typec_altmode.h +++ b/include/linux/usb/typec_altmode.h @@ -225,4 +225,9 @@ void typec_altmode_unregister_driver(struct typec_altmo= de_driver *drv); module_driver(__typec_altmode_driver, typec_altmode_register_driver, \ typec_altmode_unregister_driver) =20 +void typec_mode_selection_altmode_complete(struct typec_altmode *alt, + const int result); +void typec_mode_selection_usb4_complete(struct typec_partner *partner, + const int result); + #endif /* __USB_TYPEC_ALTMODE_H */ --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 09:22:11 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 73C3028D844 for ; Mon, 30 Jun 2025 14:13:05 +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=1751292787; cv=none; b=tkiRBaA7Mt9JiUMjcbDOYcqwc6jIHMVZ0FGZSCayw3qTPmSwBIncHOwyCCLBXihSJ17siSq2vYo3jXP8zb87KGgLBgZA6oYOogqZMOXY2bQnLnOe+KId7Ws5ZOOazW7N8K/f1S8Z2ndEZLw3qi21sBEiqFjcew8jhFh80Gz8/vc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751292787; c=relaxed/simple; bh=JA24plc6JdjA4fikFG6BIX4URnAqtE4V6iIC4bwufO8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LtSEpuu3+m/XGGgkbW23rHnIF/vrMXNFyjb9/S2FJ66pIIqQT6NWQL4qXr9cCP0s2hJtz0VU4g2EAHb9jgsigClAYcJ3RsVyCVePja/yVMIIvFh3gAXFq9Qpmt94QCBXOcgbFsnpe2ChucyY0nyWcCILLaktbmokrPzusaYGyos= 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=FSogK4VZ; 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="FSogK4VZ" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-ae3a604b43bso39537866b.0 for ; Mon, 30 Jun 2025 07:13:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751292784; x=1751897584; 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=KnfzEhcMGH710pP5n1hL+xNgQ88oIo7YgySroYK1fww=; b=FSogK4VZG+7yf3CRktFJwtPI8J53l0Hs94SdQ0zGK9X9K9AURNdw23ydsVJgWX77Dv qx0b8EAVDIe/NNxmIf73lyq9ApjQfoY81FF6wwYOewVRkjQA0cL7bmVlYMJrLSRBI8RM 8zeFQ7Mx2Q9Y1d1gaNWYrWiZUFeFN1k8D0nfQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751292784; x=1751897584; 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=KnfzEhcMGH710pP5n1hL+xNgQ88oIo7YgySroYK1fww=; b=vqPqfmPlm9stlfbLEir3vomJIMiz0cAMlhx8M9o5Va7eks0Vok0bFVJ1d9nYEc/6QO EUIXDudjmZ1znnmmfSCugQWydrMU7uAhPgtjyD+1uvmBzVqWU/PsD9DXYlvPegoPL3CE 3mf6XYpjDq25a2wV1jc8x4lL3erGN5CyEoMwB13tfE25/iJFWN0kl2OCr+kaNa9fNuPk HePnc3SbL3tILwTMa7ZYOPCQYT3SYT+QQXPIGVKM6DR9BWslZaGM/dMae82v/c6+xXuF aYRqHlvULt2IEiASN0i7+GABMQ7ssqUtEjAB0Of56XyP14CWt4s+e080UoboqK0DBO4I cDVQ== X-Forwarded-Encrypted: i=1; AJvYcCW8JBDkulgf1evKJj7/uH4Bz7jHLOEKXKSXujd3ky/x1J+3IfflaphpNhkm6iR49dQY7KdzCoYAhAR/6sk=@vger.kernel.org X-Gm-Message-State: AOJu0YyXDaY8Q4RBwcoo4HsSocFWaq57PZi/cCgM658JpWPQ7Nwxm55E MvQGubyAN0nwnG5BfumLNVotKGHRyklF3Sgsn+cbeyIz0vXyz7eul4nHgajwfDeAJA== X-Gm-Gg: ASbGncshni2rvqjP89ngKGf28hT5AH1jpG4+HpFusEVcfNBYfnmZDPXe7fwk7cuJS3P PE1N2hguD3wdmBSDJeSd7Vvk4wQ8LuxQP6RveuhGJFbdJYIAqKMCD7ucyhIgWgUBxK4CcfzioVQ SlTbfGi0egvOp5ScV1mVXGurNxf1Hse5aV6jBii3XJTGSAqEaaC80LbxPztUwqDyuk7ximZl7iK 90iJ4LElY7fslyWcH9FzboYGKYcsS7BTSLlF21VsqLtl1r++admxYKWZhzcJ9vo+MFyYEIvhcCr BHicv/nHqhxld2VLipFezfyowYT+XYR9pTkzFhFHDv24CBcw7INi7QRekxiGeeFFj6ikGLf1Qef bG/WKTSOWvjbzqDl8OoJkk3/ymO0JY2SkhWUvY5OICItmdPd/YVpI X-Google-Smtp-Source: AGHT+IFRl69xcS5vTWBsPpI7KkA2Isw3/oNvqKOqHzWPALspUIXL6/n50O56D58RXbIYSpJYvzr3+w== X-Received: by 2002:a17:907:8691:b0:ae0:180b:bb54 with SMTP id a640c23a62f3a-ae34fd8981fmr1240152466b.26.1751292782963; Mon, 30 Jun 2025 07:13:02 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (72.144.91.34.bc.googleusercontent.com. [34.91.144.72]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae35363b416sm670643866b.28.2025.06.30.07.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 07:13:02 -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" , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v2 06/10] usb: typec: Report altmode entry status via callback Date: Mon, 30 Jun 2025 14:12:35 +0000 Message-ID: <20250630141239.3174390-7-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250630141239.3174390-1-akuchynski@chromium.org> References: <20250630141239.3174390-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 Type-C mode selection logic requires feedback on the result of an alternate mode entry attempt. Call the `typec_mode_selection_altmode_complete()` callback to provide this final success or failure status. Signed-off-by: Andrei Kuchynski --- drivers/usb/typec/altmodes/displayport.c | 17 +++++++++++++++-- drivers/usb/typec/altmodes/thunderbolt.c | 8 ++++++++ include/linux/usb/typec_tbt.h | 3 +++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/a= ltmodes/displayport.c index d8b906ec4d1c..f0c8395a6652 100644 --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -274,16 +274,20 @@ static void dp_altmode_work(struct work_struct *work) header =3D DP_HEADER(dp, svdm_version, DP_CMD_STATUS_UPDATE); vdo =3D 1; ret =3D typec_altmode_vdm(dp->alt, header, &vdo, 2); - if (ret) + if (ret) { dev_err(&dp->alt->dev, "unable to send Status Update command (%d)\n", ret); + typec_mode_selection_altmode_complete(dp->alt, ret); + } break; case DP_STATE_CONFIGURE: ret =3D dp_altmode_configure_vdm(dp, dp->data.conf); - if (ret) + if (ret) { dev_err(&dp->alt->dev, "unable to send Configure command (%d)\n", ret); + typec_mode_selection_altmode_complete(dp->alt, ret); + } break; case DP_STATE_CONFIGURE_PRIME: ret =3D dp_altmode_configure_vdm_cable(dp, dp->data_prime.conf); @@ -352,6 +356,7 @@ static int dp_altmode_vdm(struct typec_altmode *alt, int cmd_type =3D PD_VDO_CMDT(hdr); int cmd =3D PD_VDO_CMD(hdr); int ret =3D 0; + int entry_result =3D 0; =20 mutex_lock(&dp->lock); =20 @@ -395,10 +400,12 @@ static int dp_altmode_vdm(struct typec_altmode *alt, switch (cmd) { case DP_CMD_STATUS_UPDATE: dp->state =3D DP_STATE_EXIT; + entry_result =3D *(int *)vdo; break; case DP_CMD_CONFIGURE: dp->data.conf =3D 0; ret =3D dp_altmode_configured(dp); + entry_result =3D *(int *)vdo; break; default: break; @@ -413,6 +420,12 @@ static int dp_altmode_vdm(struct typec_altmode *alt, =20 err_unlock: mutex_unlock(&dp->lock); + + if (!entry_result) + entry_result =3D ret; + if (entry_result || cmd =3D=3D DP_CMD_CONFIGURE) + typec_mode_selection_altmode_complete(dp->alt, entry_result); + return ret; } =20 diff --git a/drivers/usb/typec/altmodes/thunderbolt.c b/drivers/usb/typec/a= ltmodes/thunderbolt.c index 6eadf7835f8f..bbba3c6bc8b8 100644 --- a/drivers/usb/typec/altmodes/thunderbolt.c +++ b/drivers/usb/typec/altmodes/thunderbolt.c @@ -214,6 +214,7 @@ static int tbt_altmode_vdm(struct typec_altmode *alt, struct typec_thunderbolt_data data; int cmd_type =3D PD_VDO_CMDT(hdr); int cmd =3D PD_VDO_CMD(hdr); + int entry_result =3D 0; =20 mutex_lock(&tbt->lock); =20 @@ -248,6 +249,10 @@ static int tbt_altmode_vdm(struct typec_altmode *alt, switch (cmd) { case CMD_ENTER_MODE: dev_warn(&alt->dev, "Enter Mode refused\n"); + entry_result =3D *(int *)vdo; + break; + case TBT_CMD_STATUS_UPDATE: + entry_result =3D *(int *)vdo; break; default: break; @@ -262,6 +267,9 @@ static int tbt_altmode_vdm(struct typec_altmode *alt, =20 mutex_unlock(&tbt->lock); =20 + if (entry_result || cmd =3D=3D TBT_CMD_STATUS_UPDATE) + typec_mode_selection_altmode_complete(alt, entry_result); + return 0; } =20 diff --git a/include/linux/usb/typec_tbt.h b/include/linux/usb/typec_tbt.h index 55dcea12082c..57cbda5292bb 100644 --- a/include/linux/usb/typec_tbt.h +++ b/include/linux/usb/typec_tbt.h @@ -24,6 +24,9 @@ struct typec_thunderbolt_data { u32 enter_vdo; }; =20 +/* TBT3 alt mode specific commands */ +#define TBT_CMD_STATUS_UPDATE VDO_CMD_VENDOR(0) + /* TBT3 Device Discover Mode VDO bits */ #define TBT_MODE BIT(0) #define TBT_ADAPTER(_vdo_) FIELD_GET(BIT(16), _vdo_) --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 09:22:11 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 00C0228D8D6 for ; Mon, 30 Jun 2025 14:13:06 +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=1751292788; cv=none; b=ACSp4Kokp7C07eCam1b/765CFssmlZ4YlMlecpK6mvzonz1OBUfz1t5RfWFeCoRUBm1F7cwWgYZgSIJNwIMEBSUuaFvwUpyl4VpLDS0VEZeL5Y2tA7Zt4QDX4/wpbW8s960GTBbYgQuXDMgAFIWYQJwmSZeJyxrNW2kFzyKo9ng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751292788; c=relaxed/simple; bh=qWGW8YbtsDuKpbmI6ubepotX+ijoTJp4dAQsUcMuZjU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ugE1U0QS+PjmvB6eZcAgzsJNE45LqbBM6I1VV81nXzyCR7mPWSwlxjYGhrGy1hoDlM+az72YE8dNjq9+OJvf/LqDf/cUCX/1in66Srv3clWdlzyynUEEh+BGo2bV+S0W6tnt78W8FcYBFMIStctawLqOO2HMLm7DA36OPCbHw3g= 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=PkYuq1cn; 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="PkYuq1cn" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-ae35f36da9dso453532566b.0 for ; Mon, 30 Jun 2025 07:13:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751292785; x=1751897585; 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=N1Xh0BjAurZ8GfKMX5dM5eIqjsMx/yoO6fgXGDkZDUE=; b=PkYuq1cn2UtiD87OCXUnyJQnJDVZtFkTp0kAayK3suKPJmy6f1DWPNsNkgzwSO0Apt Vkc7MRB5mAmGEaWt+P03dXIh8dTqTVAjRq3GTZkpDZN0+UkjY318cQyRPrnrITNwqSNr aspimak4joIRLHUMkUzPKnKmqp651WWDLEksI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751292785; x=1751897585; 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=N1Xh0BjAurZ8GfKMX5dM5eIqjsMx/yoO6fgXGDkZDUE=; b=bpg3wV5sMM4Bk8bXSr3FiwH7Ivc0KSDoxnhmPxs/bKyFrmk2Ky81G8l1BDx8wLsqEs vkx2ZAIoU9sY85uYLpdznvii8w4kFiZ+qI/JddreGs98I3S9Ny1oAl6SUtv4fG30YGvh b3AdihbrQuOEgnws6IsiV5M4+Rx0pNcE3FTPZA9ccbltxNp8jqiVNfG6bg1K9XR/eoeq 0dtUSRPH11rrtCr2JFMDEHKXSGBuScFXWU+rG8EuR/PtDaYAXtZOjb7RWHPFdzkw3Wan /noPQIufoqD/3+SSMb5p7ezQGRhof/w/KgwzGMLdPYs3on/sgnqdHHNP/11SPMnLCcaa Pt0w== X-Forwarded-Encrypted: i=1; AJvYcCVWboxmbWTCSGSDu+YYZGZHYopJtRynaD401U2h+u/ZKzavTyBOo3bqDqEGGCs0X8cT6r/gBjxmLjJMuoU=@vger.kernel.org X-Gm-Message-State: AOJu0YzHbzkKMvTEHshD+9QdynNAGuecg1Mm+c0e8UNPTt1pVxhmyIo0 QGVAziSabx0tx07i6S+EWno9lTEh4E9HqLppUoA2PiCL+NHUYCZ66u8IddzucJwQUw== X-Gm-Gg: ASbGncvEGH2D6MXm62hHYIloZo/u2cvyllx0j/36Ifnn9PUHDWMBIUHqZmYcCHzAmQq hoJryVn4t1w8AjCK0EXt8/v3Ex6RlUolD05l/4FGchVCMt3iD8uPvrLLQLCpH2K7YqGH1EJEiEr B9nkqcsBMRJlLwBrDHZTRY/srUVLGHWpAky1lYd7KtwVAvNYBtwDD9nPZGVxPmTQLndvtJiEfKA hUoF7PsULF1Q5BeprjBU8s9OtwqX8akWl1GyxFmKixFnSHQN7s3Y65jMociFvqf9ufj2+wcOO9i Xq1Uo69oivjp6rS2vH3kpINAKtnBqeIL1L+63XvvZGl8gKtQwW20qdpG5TZjp3smdM9tZoPX6I1 KEOAH4Ke37TDiWkHK7iy9tutE3gOFkSZm7Q/xljXzSf8X3lM/KzsZ X-Google-Smtp-Source: AGHT+IGiJo2J+7ysvkMPbSppys/RSb0riJCR/djRR3Vxz/X1CdlBlaaZmnA7ExkeEfvj0vTjvfESJg== X-Received: by 2002:a17:907:d78b:b0:ae0:af6c:680 with SMTP id a640c23a62f3a-ae34fd3311fmr1153897566b.2.1751292785232; Mon, 30 Jun 2025 07:13:05 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (72.144.91.34.bc.googleusercontent.com. [34.91.144.72]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae35363b416sm670643866b.28.2025.06.30.07.13.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 07:13:04 -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" , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v2 07/10] usb: typec: ucsi: displayport: Propagate DP altmode entry result Date: Mon, 30 Jun 2025 14:12:36 +0000 Message-ID: <20250630141239.3174390-8-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250630141239.3174390-1-akuchynski@chromium.org> References: <20250630141239.3174390-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" Reporting the error code via VDM back to the Type-C mode selection logic allows the detailed result to be propagated to user space. Signed-off-by: Andrei Kuchynski --- drivers/usb/typec/ucsi/displayport.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/ucsi/displayport.c b/drivers/usb/typec/ucsi/= displayport.c index 8aae80b457d7..47c28646cfa9 100644 --- a/drivers/usb/typec/ucsi/displayport.c +++ b/drivers/usb/typec/ucsi/displayport.c @@ -234,14 +234,18 @@ static int ucsi_displayport_vdm(struct typec_altmode = *alt, =20 switch (cmd) { case DP_CMD_STATUS_UPDATE: - if (ucsi_displayport_status_update(dp)) + dp->data.error =3D ucsi_displayport_status_update(dp); + if (dp->data.error) { + dp->vdo_data =3D &dp->data.error; dp->header |=3D VDO_CMDT(CMDT_RSP_NAK); - else + } else dp->header |=3D VDO_CMDT(CMDT_RSP_ACK); break; case DP_CMD_CONFIGURE: dp->data.conf =3D *data; - if (ucsi_displayport_configure(dp)) { + dp->data.error =3D ucsi_displayport_configure(dp); + if (dp->data.error) { + dp->vdo_data =3D &dp->data.error; dp->header |=3D VDO_CMDT(CMDT_RSP_NAK); } else { dp->header |=3D VDO_CMDT(CMDT_RSP_ACK); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 09:22:11 2025 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.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 2CB8328DB57 for ; Mon, 30 Jun 2025 14:13:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751292791; cv=none; b=M059pfnZ2lfK6G5HAltv/1KlUXdqsJTqzQsSMfxsjzHpApMcwc9wkRWyrl0RkOGtdprmoQMG7VUqrfN3ocC9ovDDYY1Cc990NQWDb65ClGTEedIPy+JcQceepresFHzeP5GD7EzfzL4IVpJEMZ9BKwDFlOFJg8d3LVM0mZupSpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751292791; c=relaxed/simple; bh=jY2kl9ZPMO1inB5dCrD4v6khuWhLHIwJ9BEpVcZ+hmI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bluLtJg5kI1YwrRh7KGjNMGTma5pVMx9gzNL9pyRVRvFh/BQVjt5KmfYq/DnqFlBqYOVKderhqqQPzOsYXC5v1cDGXwo33Mw2XHnAQh6Mp2NuLfn9jRBY2h8Bf2gO5j0jsdZ50oprz54gh90T2TYLksG3D87N1LaWUEfGUdAkD0= 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=k1ifZ+oB; arc=none smtp.client-ip=209.85.218.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="k1ifZ+oB" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-ad572ba1347so325722066b.1 for ; Mon, 30 Jun 2025 07:13:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751292787; x=1751897587; 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=LKcKyNroNdhYDyM3neEw35xcf3wigABtK62twr/XvoA=; b=k1ifZ+oB5UHzBpwVegb0xh2+imVRzxFVT54UumLchZ/UiU/9CulZrGiHu0XoeuVxmN ensZ2c1uRvbi+/MROcyJ4EqF6QzN0UqWnlLvx6Q5+biN6w0LbkubuAy91AZmWN8+ITZ/ qs2+2P+tKSChv9SSA1F/yCV1DI5TXrOgJGzkI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751292787; x=1751897587; 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=LKcKyNroNdhYDyM3neEw35xcf3wigABtK62twr/XvoA=; b=WINfVROsQya39noa0vS8vtqbKRJgqZwcL2XtPuarGlFuIHNzJkQae+hh+2+etemtYy EAjp3cnvqNTTV3sg2lWyCn3pkJ9xnnl9iEiY+SU5m3jue71Hx0MAvpL1DgceNlnjJEww NqzUfpFQ91VJVK/0/EwjILGtmSUsZJjsFugNcbq7Tb2RZkkegvu/R61CRb5Rx7JuCcfs V6SYXmfsbHwp/KYyv7b4chFZtilqR4b+PixhzmaEAm0jJ5svldDh88ZJZRa++vEKzwnM 79S6ig9Wibjf6D0c2efPBK5ybEd104+4Uy/x72b9dpBgyBQJ5p4STbdlmZszGYeVsQ/l 74Tg== X-Forwarded-Encrypted: i=1; AJvYcCWIlZ08sz4uzl+p6oIPF1LmMeS04+WRlbOHTXZSF8BQpbDvP2MToSn2Y2+QLg15fTcJ3QDG4pFKMfj13xU=@vger.kernel.org X-Gm-Message-State: AOJu0YwjDSmJpue4zEa2lsS1WNAV6zT58Ug3qCRix2IjxPrU+w7/edLo VBIxgT4/F8z96cbYKnHnfB5XUVn9wkoDashFojfsciYZxgwJd1Rl8D8BfVhqZFCaVQ== X-Gm-Gg: ASbGncvwYDNj4gOe6BwnStnxaK8cDA/wDxyAGOsYR3RiBZdefcqbetMAkD2tR6vmTiy YlFwmCm6CwY92RIbq2C2a+VcPSq6QfQcpBUzQ+Gw3ABxZft0rgtCCSHsNhT5ti4j8e+qPLPUvDe 62MrjVftWAj9kgBKMOC0GXiPBap2d8r8ClZJh34ZSU2VpHdmlxmUjDAusQweCbOF2qU+bBkoETr 1zBLpVN1XRRa1LgIcccz8kN4L9TCPgn6x5xd1way1DE2ufPjJ22FdrABVEvOt1nG8pmQ6xSXc53 KR3zHycgDGX61U/xt5KWD1rzJ/9VT06zQQTDr5oPkd4XCCMq71BYtyyp2sdjjgPjhsTxPkm+KWG j1Om2JHpHYxMtEeaHWgLsOiBOxEf5apK2pssjonXoTp8GBMGlk1OU5sgHZHuEKVI= X-Google-Smtp-Source: AGHT+IEtMD4sbN5MFgRBUz6sC266Jsy/uQbBZWwtTQF8DL1F5ZClStA2819UuHd7XVsuqRIuVz6m4g== X-Received: by 2002:a17:907:728e:b0:ae3:4f99:a5aa with SMTP id a640c23a62f3a-ae34fcf30e3mr1386108366b.4.1751292787420; Mon, 30 Jun 2025 07:13:07 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (72.144.91.34.bc.googleusercontent.com. [34.91.144.72]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae35363b416sm670643866b.28.2025.06.30.07.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 07:13: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 , Dmitry Baryshkov , "Christian A. Ehrhardt" , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v2 08/10] platform/chrome: cros_ec_typec: Propagate altmode entry result Date: Mon, 30 Jun 2025 14:12:37 +0000 Message-ID: <20250630141239.3174390-9-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250630141239.3174390-1-akuchynski@chromium.org> References: <20250630141239.3174390-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" In the `cros_typec_configure_mux` function, which concludes the DP/TBT alternate mode entry, the error code should be reported back to the Type-C mode selection logic. This ensures a detailed result is conveyed to user space. To inform partner drivers about the result, the VDM mechanism is used: DP_CMD_STATUS_UPDATE for DP altmode and TBT_CMD_STATUS_UPDATE for TBT altmode. Signed-off-by: Andrei Kuchynski --- drivers/platform/chrome/cros_ec_typec.c | 9 ++++++ drivers/platform/chrome/cros_typec_altmode.c | 32 ++++++++++++++++++-- drivers/platform/chrome/cros_typec_altmode.h | 6 ++++ include/linux/usb/typec_dp.h | 2 ++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chr= ome/cros_ec_typec.c index 3aed429fde03..a4f338771094 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -610,6 +610,7 @@ static int cros_typec_enable_dp(struct cros_typec_data = *typec, if (!ret) ret =3D typec_mux_set(port->mux, &port->state); =20 + dp_data.error =3D 0; if (!ret) ret =3D cros_typec_displayport_status_update(port->state.alt, port->state.data); @@ -699,8 +700,16 @@ static int cros_typec_configure_mux(struct cros_typec_= data *typec, int port_num, ret =3D cros_typec_enable_usb4(typec, port_num, pd_ctrl); } else if (port->mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) { ret =3D cros_typec_enable_tbt(typec, port_num, pd_ctrl); + cros_typec_tbt_status_update( + port->port_altmode[CROS_EC_ALTMODE_TBT], ret); } else if (port->mux_flags & USB_PD_MUX_DP_ENABLED) { ret =3D cros_typec_enable_dp(typec, port_num, pd_ctrl); + if (ret) { + struct typec_displayport_data dp_data =3D {.error =3D ret}; + + cros_typec_displayport_status_update( + port->port_altmode[CROS_EC_ALTMODE_DP], &dp_data); + } } else if (port->mux_flags & USB_PD_MUX_SAFE_MODE) { ret =3D cros_typec_usb_safe_state(port); } else if (port->mux_flags & USB_PD_MUX_USB_ENABLED) { diff --git a/drivers/platform/chrome/cros_typec_altmode.c b/drivers/platfor= m/chrome/cros_typec_altmode.c index 557340b53af0..7ee295cf0c02 100644 --- a/drivers/platform/chrome/cros_typec_altmode.c +++ b/drivers/platform/chrome/cros_typec_altmode.c @@ -28,6 +28,7 @@ struct cros_typec_altmode_data { =20 u16 sid; u8 mode; + int error; }; =20 struct cros_typec_dp_data { @@ -295,9 +296,16 @@ int cros_typec_displayport_status_update(struct typec_= altmode *altmode, =20 dp_data->data =3D *data; dp_data->pending_status_update =3D false; - adata->header |=3D VDO_CMDT(CMDT_RSP_ACK); - adata->vdo_data =3D &dp_data->data.status; - adata->vdo_size =3D 2; + if (data->error) { + adata->header |=3D VDO_CMDT(CMDT_RSP_NAK); + adata->error =3D dp_data->data.error; + adata->vdo_data =3D &adata->error; + adata->vdo_size =3D 1; + } else { + adata->header |=3D VDO_CMDT(CMDT_RSP_ACK); + adata->vdo_data =3D &dp_data->data.status; + adata->vdo_size =3D 2; + } schedule_work(&adata->work); =20 mutex_unlock(&adata->lock); @@ -370,4 +378,22 @@ cros_typec_register_thunderbolt(struct cros_typec_port= *port, =20 return alt; } + +int cros_typec_tbt_status_update(struct typec_altmode *alt, int error) +{ + struct cros_typec_altmode_data *adata =3D typec_altmode_get_drvdata(alt); + + mutex_lock(&adata->lock); + + adata->header =3D VDO(adata->sid, 1, SVDM_VER_2_0, TBT_CMD_STATUS_UPDATE); + adata->header |=3D VDO_CMDT(error ? CMDT_RSP_NAK : CMDT_RSP_ACK); + adata->error =3D error; + adata->vdo_data =3D &adata->error; + adata->vdo_size =3D 1; + schedule_work(&adata->work); + + mutex_unlock(&adata->lock); + + return 0; +} #endif diff --git a/drivers/platform/chrome/cros_typec_altmode.h b/drivers/platfor= m/chrome/cros_typec_altmode.h index 3f2aa95d065a..848a2b194b34 100644 --- a/drivers/platform/chrome/cros_typec_altmode.h +++ b/drivers/platform/chrome/cros_typec_altmode.h @@ -39,6 +39,7 @@ static inline int cros_typec_displayport_status_update(st= ruct typec_altmode *alt struct typec_altmode * cros_typec_register_thunderbolt(struct cros_typec_port *port, struct typec_altmode_desc *desc); +int cros_typec_tbt_status_update(struct typec_altmode *alt, int error); #else static inline struct typec_altmode * cros_typec_register_thunderbolt(struct cros_typec_port *port, @@ -46,6 +47,11 @@ cros_typec_register_thunderbolt(struct cros_typec_port *= port, { return typec_port_register_altmode(port->port, desc); } +static inline int cros_typec_tbt_status_update(struct typec_altmode *alt, + int error) +{ + return 0; +} #endif =20 #endif /* __CROS_TYPEC_ALTMODE_H__ */ diff --git a/include/linux/usb/typec_dp.h b/include/linux/usb/typec_dp.h index acb0ad03bdac..c9fa68cd1265 100644 --- a/include/linux/usb/typec_dp.h +++ b/include/linux/usb/typec_dp.h @@ -44,10 +44,12 @@ enum { * commands: Status Update and Configure. * * @status will show for example the status of the HPD signal. + * @error will contain the error code, if applicable. */ struct typec_displayport_data { u32 status; u32 conf; + int error; }; =20 enum { --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 09:22:11 2025 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.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 32FF328C2CB for ; Mon, 30 Jun 2025 14:13:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751292792; cv=none; b=Ewm8/c6LKAzCph4Sr6hPdy6ssfqfDRR1l9l6bjkT9+ELZqx9Hj9RcIyqVCzIXKa/K7LlCQiASap06Irb4hY9UqflNZ+3lkMQ7APeGCmbHw2PWOHLa4M3VaTJk8qpegA3STeAh6ISP69zE79Ujt2drcoKiZv3gaRczp/i93+xqWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751292792; c=relaxed/simple; bh=9YO6vTmmSzYJ6+ilrVSIaHhLFOqDRbwDZf1V4ontcm8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PIPG/80bBBvYVG05hN1u3OceogWNw/fkidjbndAzhvrv7U1LZfcrXgpdMctrhqJF0x+WzrFN15iEdO5utGOEr/YyGo0tbcRikwA0IFyJpI/SxBv0MQrlAVlFJ3NekGbYA7rli5F0WDQcJ+asjttCB9T95u+OzV3uCmovpInPd1Q= 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=SlsrfnWv; arc=none smtp.client-ip=209.85.218.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="SlsrfnWv" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-ad574992fcaso365800766b.1 for ; Mon, 30 Jun 2025 07:13:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751292789; x=1751897589; 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=CC8cr4prgnEYpYc0c9MsVzaUXE6Rfq2YIvUMxEgcago=; b=SlsrfnWv/n71EU/XLE++kgqad00Hw2+F5RQzdHjwKXwrSMzWMPW6zE5g6e5ndhOCta yD8dP7bpdpc8ZheLy2K2fK2KiFlxSUT8dc2GjiHNfGx/saMcKTlnjmOAyfnW4tJYCF6X c/tSkADwE5EK2ed5vfwnAkAhCAj0cEBK3E0nk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751292789; x=1751897589; 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=CC8cr4prgnEYpYc0c9MsVzaUXE6Rfq2YIvUMxEgcago=; b=ApdaANbMEgGcEjHM4C3BEp4NPO5MSEdd4VoU8zex1441BzSejb83mVJsv1Ao9tbFUF nYKsFRi1HhZLO2fv5sTIgQLSELtjgzGYfVUCa7VqNHRhNzXJoV4W35dHIiE1ym1V2N3d EBANxN6s4XDfCgoQBgPSDjQkXHeskfWU2BSZM7KTLL1WNiu0tYbCWt2siPC3XLDwgqRN O4dWzpq0zLNwWdKtCZhZwrCrghisNRMOE834+olSPUNsoejmt4Zaycqy9wZsYB+QjLQ/ hjiNIWVLuXK1YSK7WHyQmvtoxX/VwuN3KfHE7ZjiONdRewX8FMGRBtspd/zvgLJgee/V IjbA== X-Forwarded-Encrypted: i=1; AJvYcCXORl63GzDJ3FNoGzf+Dctq7r15HhZij3UaHJrm+u22WZhZlKabl4B02n/2eNXVyoZkfkd7DD1DNjMTKxo=@vger.kernel.org X-Gm-Message-State: AOJu0YzU8LELroVvxvsNPeNP5pyZOCgNbC5XAM2ODtih3SmHtLvycgwl QIrg5kzQiAf9Tfkm8cULlTH3GebvHZKaaC//OkHWYlnoncqo2RQXeW16Ady4teufRA== X-Gm-Gg: ASbGnct/eytmU39DRSZZmukkzDMQhinQ9EVlRfWdFdOUtd5yr5BHYpiVebyWdmH+UMB rlRiKGSQCCYtcq/ijXnLSx90lVNdlkb1n/jdtd6JFHVpz+nefnLjA4iWwpaB+RJHi58dMRp7yj/ ASiXtwoloN5hFuHrveMrLluRcR5dsJo3ubWK9ucFATTjZd2L+R6NSM/bW9GSS5a3cK9ERnTSd0r fuyrBmgn+bYGwVJurOcsrBZ2xg64mrTXKsY1UPgHO/FP2Lpv1mys4JMICE6Fwcw1kpFpF0PnPbd GNGUokiKm/zpNZsYp8GsnESaWy4z9v/pV+tvTUHWw3Drh17NiAAd4FoWCl9cJfcJqMKlnLavPfB EGqb+ZeGeRgBd1sdCSuO57ePt/RVZtdenXoldayy5WhEznfOZtCmn X-Google-Smtp-Source: AGHT+IGAPr4AL+m9Q53Is3hbLm4DqSgPBqlFVyHvgBt7nn+yWfXW/dahX7CBUSLpmXWeZqCzkyRaOw== X-Received: by 2002:a17:907:1c1d:b0:ae0:c803:c96 with SMTP id a640c23a62f3a-ae34fddefb3mr1305940266b.24.1751292789206; Mon, 30 Jun 2025 07:13:09 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (72.144.91.34.bc.googleusercontent.com. [34.91.144.72]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae35363b416sm670643866b.28.2025.06.30.07.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 07:13:08 -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" , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v2 09/10] platform/chrome: cros_ec_typec: Report USB4 entry status via callback Date: Mon, 30 Jun 2025 14:12:38 +0000 Message-ID: <20250630141239.3174390-10-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250630141239.3174390-1-akuchynski@chromium.org> References: <20250630141239.3174390-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 Type-C mode selection logic requires feedback on the result of USB4 mode entry attempt. Call the `typec_mode_selection_usb4_complete()` callback to provide this final success or failure status. Signed-off-by: Andrei Kuchynski --- 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 a4f338771094..c5a7f42ffb5a 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -698,6 +698,7 @@ static int cros_typec_configure_mux(struct cros_typec_d= ata *typec, int port_num, =20 if (port->mux_flags & USB_PD_MUX_USB4_ENABLED) { ret =3D cros_typec_enable_usb4(typec, port_num, pd_ctrl); + typec_mode_selection_usb4_complete(port->partner, ret); } else if (port->mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) { ret =3D cros_typec_enable_tbt(typec, port_num, pd_ctrl); cros_typec_tbt_status_update( --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 09:22:11 2025 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B1AB28C2BE for ; Mon, 30 Jun 2025 14:13:12 +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=1751292794; cv=none; b=VRg74EiJzU7O7LrQimbU7/i4JFAqWAOKkCRL2LvF76A0uT1vzyjaxLmKvZ+8eSgu2mpOqxvZqMwV/z/8NHaNmNEbrFHH8nK1SVlEq1Lqx6eXJdJVhv0qRyBQe9ifE2WCF8uG2VodOGLTbCVaofI1+p/qvxAQVH/N82lWE+AtRTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751292794; c=relaxed/simple; bh=Vml+Vlmh/yNyrlNV0OMkYSZVPlVmBlgOUuBzWRBqzfg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZQ6dbNBlikwI8y8LxEln90ObuyAmx94laBBCH7tvbPRznB8e3S3SXJQ/hJ5A3xCSfOcWO5t0dXIvCQCgPzfJlo++fs2wMLbEV6C+ZIa20ByHiX4lplYCBWJosnNh2vWQ0aLEXOfEWyN4A1fvpuJSXm0x0y7Nz40JIjXluNTk5D8= 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=nQbDSTCC; 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="nQbDSTCC" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-ae0dd62f2adso799370866b.2 for ; Mon, 30 Jun 2025 07:13:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751292791; x=1751897591; 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=/8NRsPP90vS0j3nzCWJKBndtcs4Ube9as2Ue2hWIhFU=; b=nQbDSTCC3FxgKwEiRz1PSeZOVISZ5LatLPX66rfD6etRhMS3QASWeUW7zKGxbLinig vdA76B/6nbXoj3bCxCUCGLjzOl88bDgERTbkpF2cp3F0jh/d60OUj3p1t7XD/oGyV2Il YvCCVfLRppreCCw7f0d0AbR9a/FNp0Hy2IDo8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751292791; x=1751897591; 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=/8NRsPP90vS0j3nzCWJKBndtcs4Ube9as2Ue2hWIhFU=; b=vUJFE/wmFCDK0fvTVCZK+RsN8CGCMbwEulkk3Y6l9ZOb0C2RswkR0qN+GA4exxVCby mugDWBvGyDR9ZizSK+cH3V9v4P2wthlmYer+hQ5FXfV8gLDEcTHlcBtckiJ9euTextvH /Lq3i+5hfzlCQNCksU6Dalj0yTfreldqkucTTDAgXzGTB0Dk4LjIL0fv4pocNND49fwE 7zz5bFH1pgohC7oaB9UxLZv6cAgIPnPy1r5ztMnJ2DYEqQ/duIIuvujlAc2RwxixQr5p 2aCm44AgZjrUD5a6e9Zr3ShC6yDi65MTiw8uBTTNHWH3U0KTvhjVNkU6jQITa6gt9iru mkkA== X-Forwarded-Encrypted: i=1; AJvYcCVaoyrUmPYU3lp73dhraDoOeF27v2nOq6/dEk+z/9Y0w8tATCMiFp0Nd8XvzXVtzO6gcTGs7EoxhHiYfZI=@vger.kernel.org X-Gm-Message-State: AOJu0YylUYliOz5HwzFyrO5ic9/uKffSPxs6ueYIR57fuVTXEZz66Lga XLmXzgKqdjyzDEmXMA+tGRhDS9j2YtV0/RmVvWABDS437wqZXmBZ4YZp1ikLI5uFCg== X-Gm-Gg: ASbGncuTYuqNZeN6wSm71dL0H+H1HsQcx95DOa3BXhf3r/anjI5Vkd0hnQi8cB1r8t6 zMxKXk7jHoqwR6Y9sJDYVhHhqfZQAW/shLIN8nkUyCj0n01lDuoW1sEuuntMKP4fpQQ+X4vRQhe bWCWQlFPj6fKDwuNfYRmSFIJGDVXwASUf/7Vl7/X/cPk54eU1ONIpz5m9Nd3KqTxJ9L62/JXFYg N9loapFWEEPZSgeE75ZWKBoWeyuYkmzqmAdzZELzSjZqT86bQDA4MjWo4/c8Sg7parn3bfzOp9r o3OK2O0xfK+QBKZ7IssSM9OkDaiu27hl8hSQhj/B9njhrd01gJaUeSkofhaEJcIx3SDM/UlWR0/ C++vnDGpxNBAco3wArgNmpWNLWypaHMjmrFtOCTxstOmDdI6Ebl64 X-Google-Smtp-Source: AGHT+IE29gt8xWBI8pZXeQthKWA11FWxnfDchrHgHB2UzYqRmz/TTQgJ95KCGJWKBD6ofw4Dv8EGrQ== X-Received: by 2002:a17:907:720f:b0:ae0:c6fa:ef45 with SMTP id a640c23a62f3a-ae35011ed14mr1314176166b.41.1751292791326; Mon, 30 Jun 2025 07:13:11 -0700 (PDT) Received: from akuchynski.c.googlers.com.com (72.144.91.34.bc.googleusercontent.com. [34.91.144.72]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae35363b416sm670643866b.28.2025.06.30.07.13.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 07:13:10 -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" , linux-kernel@vger.kernel.org, Andrei Kuchynski Subject: [PATCH v2 10/10] platform/chrome: cros_ec_typec: Add default_usb_mode_set support Date: Mon, 30 Jun 2025 14:12:39 +0000 Message-ID: <20250630141239.3174390-11-akuchynski@chromium.org> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250630141239.3174390-1-akuchynski@chromium.org> References: <20250630141239.3174390-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 `cros_ec_typec` driver currently doesn't directly consume a default USB mode value. This commit adds the `default_usb_mode_set` function, enabling the `usb_capability` sysfs attribute to be writable. This functionality allows users to dynamically activate or deactivate USB4 mode on a given port. Signed-off-by: Andrei Kuchynski --- drivers/platform/chrome/cros_ec_typec.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chr= ome/cros_ec_typec.c index c5a7f42ffb5a..3de6b819906e 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -44,6 +44,11 @@ static void cros_typec_role_switch_quirk(struct fwnode_h= andle *fwnode) #endif } =20 +static int cros_typec_default_usb_mode_set(struct typec_port *port, enum u= sb_mode mode) +{ + return 0; +} + static int cros_typec_enter_usb_mode(struct typec_port *tc_port, enum usb_= mode mode) { struct cros_typec_port *port =3D typec_get_drvdata(tc_port); @@ -59,6 +64,7 @@ static int cros_typec_enter_usb_mode(struct typec_port *t= c_port, enum usb_mode m } =20 static const struct typec_operations cros_typec_usb_mode_ops =3D { + .default_usb_mode_set =3D cros_typec_default_usb_mode_set, .enter_usb_mode =3D cros_typec_enter_usb_mode }; =20 --=20 2.50.0.727.gbf7dc18ff4-goog