From patchwork Thu Nov 7 19:29:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 13866990 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 6FD8621733F for ; Thu, 7 Nov 2024 19:31:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007902; cv=none; b=TmAhm8rASeRkQ3VSGTVIJETD44TqtEykE+nMbfdpjfmTOcXll1uxKi+ogR/NpOaBakuUi2Qhb50qtIanJiLB4vcOyyqndaHuQ0biswyJbIO1slgXk4WHwDxUGQVhDen4H1yYiBX7jrG5MAKLivHPk1stNFyDKHwFCepH8oUTQsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007902; c=relaxed/simple; bh=ND8duXxeqpOMTaKR32jDF37o2wNYr8J9a6+AaXeIoic=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WFbiP2dZWdY9yxO0kVwXLGNItMXlxZXNLB3FludqDM/GRuoF7FIBBQU6xYyVXMPCUcX5Yo3eJDqaUrKVf89dz+VAmqXQXG5OCVTe7Bsl24EPabnciUZ+qiLaxRFteaViQpP0iZQif6Bnif/TdD5Sbq3c/dvk+XVh5xI3kf8ttro= 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=c5nS5COz; arc=none smtp.client-ip=209.85.210.182 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="c5nS5COz" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-71e52582cf8so1079156b3a.2 for ; Thu, 07 Nov 2024 11:31:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731007901; x=1731612701; darn=lists.linux.dev; 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=Ge6TnT0PL++7IUpHJoGRRwwYMPSP58r23n3kpkNEevA=; b=c5nS5COzuSmMGNuovVz3BtOjWUQWr1Thqyp10Bgqd33/pBI5IgFumqAAKXZfEkEulE Wf1Lo8LCS7mS7GgEvIwwC4Q4bQgjJ+++wJaMK0FeSmxIrgXinyZTaktduiJZ0RLTYOtk HilVruEheZh8lWHnLCZWKcXkjrwBf+iBgS/mI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731007901; x=1731612701; 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=Ge6TnT0PL++7IUpHJoGRRwwYMPSP58r23n3kpkNEevA=; b=A9fP6pJJKwPGb4zUrxrxB9pFoLZAc4sSmZtvk2sKMh7RehE2xYuccp/p2bMXeTYPJK cubXBb2YW/T5VFldjpD8kvllo9iSsravIi0mWZ4sg3ZXPC1VTMxG9gzJfiV6Kcgezdpq 8TmC8dC0/11xsUL1UhXXB3EEZdNzB8kbXRLo0NIxOFn5oobGDRAjggcCSS6gntExMPSr dEpbneiSenrmxvFPou+8twqIK6Fbbq7D7XUnN7Kp2rRytiIu4eR1P2eBroiaIMh7XUsY DcHfbtb5E7MGBuhpK6mcRnU2b/gbkEt5fwjS0FZHEfmEYMZJlsCYB6QqFxWC7H1hjwLl fgeA== X-Forwarded-Encrypted: i=1; AJvYcCUk25u/4lnILkJJUdRG/QukrsuEVczkZgKjaiu8cpFLAJyEFxBWdjS2I8ZxhkyD56GPY1aekduHlHV81+WtBj4=@lists.linux.dev X-Gm-Message-State: AOJu0YwOLHrKEu1VBU1PlVLlTUwPQi9YJrz0bIBjOf5scyzPxkSbOsXt rgLCDPxwEMo6NgZwwlRWQPqegNz1zJa7I9Sk/WM0ER8P2kopPkR774qMzbKZ5w== X-Google-Smtp-Source: AGHT+IE7o1xJwA2XjuGz9LhbPKe/6CQOLFgBLUy5xzkzep2TbqXM20/rFdDiwN3eRoefW7Th2I/1zg== X-Received: by 2002:a17:90b:3847:b0:2e2:e136:a931 with SMTP id 98e67ed59e1d1-2e9b16ea3e7mr488934a91.6.1731007900637; Thu, 07 Nov 2024 11:31:40 -0800 (PST) Received: from localhost (198.103.247.35.bc.googleusercontent.com. [35.247.103.198]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2e9a5fd180fsm1869330a91.33.2024.11.07.11.31.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Nov 2024 11:31:40 -0800 (PST) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: jthies@google.com, akuchynski@google.com, pmalani@chromium.org, dmitry.baryshkov@linaro.org, Abhishek Pandit-Subedi , Greg Kroah-Hartman , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/7] usb: typec: Only use SVID for matching altmodes Date: Thu, 7 Nov 2024 11:29:54 -0800 Message-ID: <20241107112955.v3.1.Ie0d37646f18461234777d88b4c3e21faed92ed4f@changeid> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <20241107193021.2690050-1-abhishekpandit@chromium.org> References: <20241107193021.2690050-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Mode in struct typec_altmode is used to indicate the index of the altmode on a port, partner or plug. It is used in enter mode VDMs but doesn't make much sense for matching against altmode drivers or for matching partner to port altmodes. Signed-off-by: Abhishek Pandit-Subedi Reviewed-by: Heikki Krogerus --- Changes in v3: - Removed mode from altmode device ids - Updated modalias for typecd bus to remove mode - Re-ordered to start of series Changes in v2: - Update altmode_match to ignore mode entirely - Also apply the same behavior to typec_match drivers/usb/typec/altmodes/displayport.c | 2 +- drivers/usb/typec/altmodes/nvidia.c | 2 +- drivers/usb/typec/bus.c | 6 ++---- drivers/usb/typec/class.c | 4 ++-- scripts/mod/devicetable-offsets.c | 1 - scripts/mod/file2alias.c | 4 +--- 6 files changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c index 2f03190a9873..3245e03d59e6 100644 --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -791,7 +791,7 @@ void dp_altmode_remove(struct typec_altmode *alt) EXPORT_SYMBOL_GPL(dp_altmode_remove); static const struct typec_device_id dp_typec_id[] = { - { USB_TYPEC_DP_SID, USB_TYPEC_DP_MODE }, + { USB_TYPEC_DP_SID }, { }, }; MODULE_DEVICE_TABLE(typec, dp_typec_id); diff --git a/drivers/usb/typec/altmodes/nvidia.c b/drivers/usb/typec/altmodes/nvidia.c index fe70b36f078f..2b77d931e494 100644 --- a/drivers/usb/typec/altmodes/nvidia.c +++ b/drivers/usb/typec/altmodes/nvidia.c @@ -24,7 +24,7 @@ static void nvidia_altmode_remove(struct typec_altmode *alt) } static const struct typec_device_id nvidia_typec_id[] = { - { USB_TYPEC_NVIDIA_VLINK_SID, TYPEC_ANY_MODE }, + { USB_TYPEC_NVIDIA_VLINK_SID }, { }, }; MODULE_DEVICE_TABLE(typec, nvidia_typec_id); diff --git a/drivers/usb/typec/bus.c b/drivers/usb/typec/bus.c index aa879253d3b8..ae90688d23e4 100644 --- a/drivers/usb/typec/bus.c +++ b/drivers/usb/typec/bus.c @@ -454,8 +454,7 @@ static int typec_match(struct device *dev, const struct device_driver *driver) const struct typec_device_id *id; for (id = drv->id_table; id->svid; id++) - if (id->svid == altmode->svid && - (id->mode == TYPEC_ANY_MODE || id->mode == altmode->mode)) + if (id->svid == altmode->svid) return 1; return 0; } @@ -470,8 +469,7 @@ static int typec_uevent(const struct device *dev, struct kobj_uevent_env *env) if (add_uevent_var(env, "MODE=%u", altmode->mode)) return -ENOMEM; - return add_uevent_var(env, "MODALIAS=typec:id%04Xm%02X", - altmode->svid, altmode->mode); + return add_uevent_var(env, "MODALIAS=typec:id%04X", altmode->svid); } static int typec_altmode_create_links(struct altmode *alt) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 4b3047e055a3..febe453b96be 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -237,13 +237,13 @@ static int altmode_match(struct device *dev, void *data) if (!is_typec_altmode(dev)) return 0; - return ((adev->svid == id->svid) && (adev->mode == id->mode)); + return (adev->svid == id->svid); } static void typec_altmode_set_partner(struct altmode *altmode) { struct typec_altmode *adev = &altmode->adev; - struct typec_device_id id = { adev->svid, adev->mode, }; + struct typec_device_id id = { adev->svid }; struct typec_port *port = typec_altmode2port(adev); struct altmode *partner; struct device *dev; diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c index 9c7b404defbd..d3d00e85edf7 100644 --- a/scripts/mod/devicetable-offsets.c +++ b/scripts/mod/devicetable-offsets.c @@ -237,7 +237,6 @@ int main(void) DEVID(typec_device_id); DEVID_FIELD(typec_device_id, svid); - DEVID_FIELD(typec_device_id, mode); DEVID(tee_client_device_id); DEVID_FIELD(tee_client_device_id, uuid); diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index c4cc11aa558f..218ccb7150bf 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -1343,14 +1343,12 @@ static int do_tbsvc_entry(const char *filename, void *symval, char *alias) return 1; } -/* Looks like: typec:idNmN */ +/* Looks like: typec:idN */ static int do_typec_entry(const char *filename, void *symval, char *alias) { DEF_FIELD(symval, typec_device_id, svid); - DEF_FIELD(symval, typec_device_id, mode); sprintf(alias, "typec:id%04X", svid); - ADD(alias, "m", mode != TYPEC_ANY_MODE, mode); return 1; } From patchwork Thu Nov 7 19:29:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 13866991 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 7B461217F36 for ; Thu, 7 Nov 2024 19:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007905; cv=none; b=JCmXZ6L3mqAegR+QcNcUtrBNi8vwEuAyHqMpIvDWaSnyVzF3XXVJiQWguZB/jHj1L8UnJP+vLs4lT9VipJDbAV3r4WjpyTf9QPqnfsOqge4uJP3RKyeWq7XutLAY2bO3kpPzf3JIukMJEj8TaD53QVaraMGhRv0utKHMOyixQWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007905; c=relaxed/simple; bh=xKZEM3BEB1RuTSN4Uueuml1p0DgkTsbm8rJMvKSFMCk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AjBDp7vNNOvq7jR/N2iG0/sAmCOnQGjdLhMy0QpAaPuZi8/etj2LOCW6/DZQ7mdDratwgRMeYoRV3QZWIyqJfG0w1OLnlzo/CY3ASdgLCXvhAk6L4xK61pX5+1ZUBmUBQb9DJl7qU0unltqDTSm2s9h8gIPJoInOxce2I3thoEg= 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=B2VFUC32; arc=none smtp.client-ip=209.85.210.177 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="B2VFUC32" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-720be27db74so1108794b3a.1 for ; Thu, 07 Nov 2024 11:31:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731007903; x=1731612703; darn=lists.linux.dev; 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=83Suh2wjIyKRrMNGwMzdQsYr0nqcWo4eqvxd8u8DH7w=; b=B2VFUC325izet/DUZSw5jnrUuWTjHzsHjieedlCuNlTSMCZY4tT1PMHfSXXtnPAEfA I0h9UnzTqkcY6povjCdTpv765UrBlt87szzUs6poqeckO5RJYc51OOXk2CN3iJ15K3TN tGfDP4UEfyMFnqj02WEXFZ5WyZtM8wcmTmCaA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731007903; x=1731612703; 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=83Suh2wjIyKRrMNGwMzdQsYr0nqcWo4eqvxd8u8DH7w=; b=R1qnJI/C27T5/BqPtjFlcMMedkCXF/dnkJji/1oz/gyH5tVCNZ9RewznHJusgAYptj Zvty3krrHPKV9JQaGjteZRxTQ0Bl8S+zlJI3a+R8w2FSDpBwHFeZZPatSJ/Koz0IDa8a FSxb7u/DupcYBVinTTyFfUwWwAN4RSOYAtDGBd2WzWDJcvZ4r+Hv5758MyivdqlBNImL gRdl1onbcU2IpncC6KSGI19q/MHhxu2c/hwibk0kPdTX1Sm9XRu2ntnW2ju74dKozgZV N3VMOsFI5AqNc44HYTfmA6Xk6c690Hb4a9+ax8m9SCD/FydQIHl0YHvbzBeCeC7Ej9yA wRgw== X-Forwarded-Encrypted: i=1; AJvYcCXJ5O1XqfxhwfgmlInOXC9ApsxgBfoEcucjWQJ27rLTZ3haE1VMhL5oMzE4Ob7Xaa0qX3uitqVv8ZAHG2EZgw4=@lists.linux.dev X-Gm-Message-State: AOJu0YxhExBh44lihpM/MOR5wnbZhD7P0k3u+Tc5rQHeLDX+jAx5+Da9 bfE6zgoQVm6hmkdJkQki7m6EsKnHfjWPOrN2Ac1KV6jE7MmePVffVXqFqysrdg== X-Google-Smtp-Source: AGHT+IHowZtPGb5/tcFnUmur6kDpXYtUcCT3psAEQ+OeTjw995kJie6fup9tOg4xNTXfF4EEHk+p9Q== X-Received: by 2002:a05:6a00:21c4:b0:71e:7f08:492c with SMTP id d2e1a72fcca58-72413f4c526mr51975b3a.1.1731007902821; Thu, 07 Nov 2024 11:31:42 -0800 (PST) Received: from localhost (198.103.247.35.bc.googleusercontent.com. [35.247.103.198]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-724078cd28asm2002020b3a.85.2024.11.07.11.31.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Nov 2024 11:31:42 -0800 (PST) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: jthies@google.com, akuchynski@google.com, pmalani@chromium.org, dmitry.baryshkov@linaro.org, Abhishek Pandit-Subedi , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [PATCH v3 2/7] usb: typec: Add driver for Thunderbolt 3 Alternate Mode Date: Thu, 7 Nov 2024 11:29:55 -0800 Message-ID: <20241107112955.v3.2.I3080b036e8de0b9957c57c1c3059db7149c5e549@changeid> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <20241107193021.2690050-1-abhishekpandit@chromium.org> References: <20241107193021.2690050-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Heikki Krogerus Thunderbolt 3 Alternate Mode entry flow is described in USB Type-C Specification Release 2.0. Signed-off-by: Heikki Krogerus Co-developed-by: Abhishek Pandit-Subedi Signed-off-by: Abhishek Pandit-Subedi --- Changes: * Delay cable + plug checks so that the module doesn't fail to probe if cable + plug information isn't available by the time the partner altmode is registered. * Remove unncessary brace after if (IS_ERR(plug)) The rest of this patch should be the same as Heikki's original RFC. Changes in v3: - Revert rename of TYPEC_TBT_MODE - Remove mode from typec_device_id Changes in v2: - Use and add missing TBT_CABLE_ROUNDED - Pass struct typec_thunderbolt_data to typec_altmode_notify - Rename TYPEC_TBT_MODE to USB_TYPEC_TBT_MODE - Use USB_TYPEC_TBT_SID and USB_TYPEC_TBT_MODE for device id - Change module license to GPL due to checkpatch warning drivers/usb/typec/altmodes/Kconfig | 9 + drivers/usb/typec/altmodes/Makefile | 2 + drivers/usb/typec/altmodes/thunderbolt.c | 308 +++++++++++++++++++++++ include/linux/usb/typec_tbt.h | 1 + 4 files changed, 320 insertions(+) create mode 100644 drivers/usb/typec/altmodes/thunderbolt.c diff --git a/drivers/usb/typec/altmodes/Kconfig b/drivers/usb/typec/altmodes/Kconfig index 1a6b5e872b0d..7867fa7c405d 100644 --- a/drivers/usb/typec/altmodes/Kconfig +++ b/drivers/usb/typec/altmodes/Kconfig @@ -23,4 +23,13 @@ config TYPEC_NVIDIA_ALTMODE To compile this driver as a module, choose M here: the module will be called typec_nvidia. +config TYPEC_TBT_ALTMODE + tristate "Thunderbolt3 Alternate Mode driver" + help + Select this option if you have Thunderbolt3 hardware on your + system. + + To compile this driver as a module, choose M here: the + module will be called typec_thunderbolt. + endmenu diff --git a/drivers/usb/typec/altmodes/Makefile b/drivers/usb/typec/altmodes/Makefile index 45717548b396..508a68351bd2 100644 --- a/drivers/usb/typec/altmodes/Makefile +++ b/drivers/usb/typec/altmodes/Makefile @@ -4,3 +4,5 @@ obj-$(CONFIG_TYPEC_DP_ALTMODE) += typec_displayport.o typec_displayport-y := displayport.o obj-$(CONFIG_TYPEC_NVIDIA_ALTMODE) += typec_nvidia.o typec_nvidia-y := nvidia.o +obj-$(CONFIG_TYPEC_TBT_ALTMODE) += typec_thunderbolt.o +typec_thunderbolt-y := thunderbolt.o diff --git a/drivers/usb/typec/altmodes/thunderbolt.c b/drivers/usb/typec/altmodes/thunderbolt.c new file mode 100644 index 000000000000..a945b9d35a1d --- /dev/null +++ b/drivers/usb/typec/altmodes/thunderbolt.c @@ -0,0 +1,308 @@ +// SPDX-License-Identifier: GPL-2.0 +/** + * USB Typec-C Thuderbolt3 Alternate Mode driver + * + * Copyright (C) 2019 Intel Corporation + * Author: Heikki Krogerus + */ + +#include +#include +#include +#include +#include +#include + +enum tbt_state { + TBT_STATE_IDLE, + TBT_STATE_SOP_P_ENTER, + TBT_STATE_SOP_PP_ENTER, + TBT_STATE_ENTER, + TBT_STATE_EXIT, + TBT_STATE_SOP_PP_EXIT, + TBT_STATE_SOP_P_EXIT +}; + +struct tbt_altmode { + enum tbt_state state; + struct typec_cable *cable; + struct typec_altmode *alt; + struct typec_altmode *plug[2]; + u32 enter_vdo; + + struct work_struct work; + struct mutex lock; /* device lock */ +}; + +static bool tbt_ready(struct typec_altmode *alt); + +static int tbt_enter_mode(struct tbt_altmode *tbt) +{ + struct typec_altmode *plug = tbt->plug[TYPEC_PLUG_SOP_P]; + u32 vdo; + + vdo = tbt->alt->vdo & (TBT_VENDOR_SPECIFIC_B0 | TBT_VENDOR_SPECIFIC_B1); + vdo |= tbt->alt->vdo & TBT_INTEL_SPECIFIC_B0; + vdo |= TBT_MODE; + + if (plug) { + if (typec_cable_is_active(tbt->cable)) + vdo |= TBT_ENTER_MODE_ACTIVE_CABLE; + + vdo |= TBT_ENTER_MODE_CABLE_SPEED(TBT_CABLE_SPEED(plug->vdo)); + vdo |= plug->vdo & TBT_CABLE_ROUNDED; + vdo |= plug->vdo & TBT_CABLE_OPTICAL; + vdo |= plug->vdo & TBT_CABLE_RETIMER; + vdo |= plug->vdo & TBT_CABLE_LINK_TRAINING; + } else { + vdo |= TBT_ENTER_MODE_CABLE_SPEED(TBT_CABLE_USB3_PASSIVE); + } + + tbt->enter_vdo = vdo; + return typec_altmode_enter(tbt->alt, &vdo); +} + +static void tbt_altmode_work(struct work_struct *work) +{ + struct tbt_altmode *tbt = container_of(work, struct tbt_altmode, work); + int ret; + + mutex_lock(&tbt->lock); + + switch (tbt->state) { + case TBT_STATE_SOP_P_ENTER: + ret = typec_altmode_enter(tbt->plug[TYPEC_PLUG_SOP_P], NULL); + if (ret) + dev_dbg(&tbt->plug[TYPEC_PLUG_SOP_P]->dev, + "failed to enter mode (%d)\n", ret); + break; + case TBT_STATE_SOP_PP_ENTER: + ret = typec_altmode_enter(tbt->plug[TYPEC_PLUG_SOP_PP], NULL); + if (ret) + dev_dbg(&tbt->plug[TYPEC_PLUG_SOP_PP]->dev, + "failed to enter mode (%d)\n", ret); + break; + case TBT_STATE_ENTER: + ret = tbt_enter_mode(tbt); + if (ret) + dev_dbg(&tbt->alt->dev, "failed to enter mode (%d)\n", + ret); + break; + case TBT_STATE_EXIT: + typec_altmode_exit(tbt->alt); + break; + case TBT_STATE_SOP_PP_EXIT: + typec_altmode_exit(tbt->plug[TYPEC_PLUG_SOP_PP]); + break; + case TBT_STATE_SOP_P_EXIT: + typec_altmode_exit(tbt->plug[TYPEC_PLUG_SOP_P]); + break; + default: + break; + } + + tbt->state = TBT_STATE_IDLE; + + mutex_unlock(&tbt->lock); +} + +static int tbt_altmode_vdm(struct typec_altmode *alt, + const u32 hdr, const u32 *vdo, int count) +{ + struct tbt_altmode *tbt = typec_altmode_get_drvdata(alt); + int cmd_type = PD_VDO_CMDT(hdr); + int cmd = PD_VDO_CMD(hdr); + + mutex_lock(&tbt->lock); + + if (tbt->state != TBT_STATE_IDLE) { + mutex_unlock(&tbt->lock); + return -EBUSY; + } + + switch (cmd_type) { + case CMDT_RSP_ACK: + switch (cmd) { + case CMD_ENTER_MODE: + /* + * Following the order describeded in USB Type-C Spec + * R2.0 Section 6.7.3. + */ + if (alt == tbt->plug[TYPEC_PLUG_SOP_P]) { + if (tbt->plug[TYPEC_PLUG_SOP_PP]) + tbt->state = TBT_STATE_SOP_PP_ENTER; + else + tbt->state = TBT_STATE_ENTER; + } else if (alt == tbt->plug[TYPEC_PLUG_SOP_PP]) { + tbt->state = TBT_STATE_ENTER; + } else { + struct typec_thunderbolt_data data; + + data.device_mode = tbt->alt->vdo; + data.cable_mode = + tbt->plug[TYPEC_PLUG_SOP_P] ? + tbt->plug[TYPEC_PLUG_SOP_P] + ->vdo : + 0; + data.enter_vdo = tbt->enter_vdo; + + typec_altmode_notify(alt, TYPEC_STATE_MODAL, &data); + } + break; + case CMD_EXIT_MODE: + if (alt == tbt->alt) { + if (tbt->plug[TYPEC_PLUG_SOP_PP]) + tbt->state = TBT_STATE_SOP_PP_EXIT; + else if (tbt->plug[TYPEC_PLUG_SOP_P]) + tbt->state = TBT_STATE_SOP_P_EXIT; + } else if (alt == tbt->plug[TYPEC_PLUG_SOP_PP]) { + tbt->state = TBT_STATE_SOP_P_EXIT; + } + break; + } + break; + case CMDT_RSP_NAK: + switch (cmd) { + case CMD_ENTER_MODE: + dev_warn(&alt->dev, "Enter Mode refused\n"); + break; + default: + break; + } + break; + default: + break; + } + + if (tbt->state != TBT_STATE_IDLE) + schedule_work(&tbt->work); + + mutex_unlock(&tbt->lock); + + return 0; +} + +static int tbt_altmode_activate(struct typec_altmode *alt, int activate) +{ + struct tbt_altmode *tbt = typec_altmode_get_drvdata(alt); + int ret; + + mutex_lock(&tbt->lock); + + if (!tbt_ready(alt)) + return -ENODEV; + + /* Preventing the user space from entering/exiting the cable alt mode */ + if (alt != tbt->alt) + ret = -EPERM; + else if (activate) + ret = tbt_enter_mode(tbt); + else + ret = typec_altmode_exit(alt); + + mutex_unlock(&tbt->lock); + + return ret; +} + +static const struct typec_altmode_ops tbt_altmode_ops = { + .vdm = tbt_altmode_vdm, + .activate = tbt_altmode_activate +}; + +static int tbt_altmode_probe(struct typec_altmode *alt) +{ + struct tbt_altmode *tbt; + + tbt = devm_kzalloc(&alt->dev, sizeof(*tbt), GFP_KERNEL); + if (!tbt) + return -ENOMEM; + + INIT_WORK(&tbt->work, tbt_altmode_work); + mutex_init(&tbt->lock); + tbt->alt = alt; + + alt->desc = "Thunderbolt3"; + typec_altmode_set_drvdata(alt, tbt); + typec_altmode_set_ops(alt, &tbt_altmode_ops); + + if (tbt_ready(alt)) { + if (tbt->plug[TYPEC_PLUG_SOP_PP]) + tbt->state = TBT_STATE_SOP_PP_ENTER; + else if (tbt->plug[TYPEC_PLUG_SOP_P]) + tbt->state = TBT_STATE_SOP_P_ENTER; + else + tbt->state = TBT_STATE_ENTER; + schedule_work(&tbt->work); + } + + return 0; +} + +static void tbt_altmode_remove(struct typec_altmode *alt) +{ + struct tbt_altmode *tbt = typec_altmode_get_drvdata(alt); + + for (int i = TYPEC_PLUG_SOP_PP; i > 0; --i) { + if (tbt->plug[i]) + typec_altmode_put_plug(tbt->plug[i]); + } + + if (tbt->cable) + typec_cable_put(tbt->cable); +} + +static bool tbt_ready(struct typec_altmode *alt) +{ + struct tbt_altmode *tbt = typec_altmode_get_drvdata(alt); + struct typec_altmode *plug; + + if (tbt->cable) + return true; + + /* Thundebolt 3 requires a cable with eMarker */ + tbt->cable = typec_cable_get(typec_altmode2port(tbt->alt)); + if (!tbt->cable) + return false; + + /* We accept systems without SOP' or SOP''. This means the port altmode + * driver will be responsible for properly ordering entry/exit. + */ + for (int i = 0; i < TYPEC_PLUG_SOP_PP + 1; i++) { + plug = typec_altmode_get_plug(tbt->alt, i); + if (IS_ERR(plug)) + continue; + + if (!plug || plug->svid != USB_TYPEC_VENDOR_INTEL) + break; + + plug->desc = "Thunderbolt3"; + plug->ops = &tbt_altmode_ops; + typec_altmode_set_drvdata(plug, tbt); + + tbt->plug[i] = plug; + } + + return true; +} + +static const struct typec_device_id tbt_typec_id[] = { + { USB_TYPEC_TBT_SID }, + { } +}; +MODULE_DEVICE_TABLE(typec, tbt_typec_id); + +static struct typec_altmode_driver tbt_altmode_driver = { + .id_table = tbt_typec_id, + .probe = tbt_altmode_probe, + .remove = tbt_altmode_remove, + .driver = { + .name = "typec-thunderbolt", + .owner = THIS_MODULE, + } +}; +module_typec_altmode_driver(tbt_altmode_driver); + +MODULE_AUTHOR("Heikki Krogerus "); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Thunderbolt3 USB Type-C Alternate Mode"); diff --git a/include/linux/usb/typec_tbt.h b/include/linux/usb/typec_tbt.h index fa97d7e00f5c..55dcea12082c 100644 --- a/include/linux/usb/typec_tbt.h +++ b/include/linux/usb/typec_tbt.h @@ -44,6 +44,7 @@ struct typec_thunderbolt_data { #define TBT_GEN3_NON_ROUNDED 0 #define TBT_GEN3_GEN4_ROUNDED_NON_ROUNDED 1 +#define TBT_CABLE_ROUNDED BIT(19) #define TBT_CABLE_OPTICAL BIT(21) #define TBT_CABLE_RETIMER BIT(22) #define TBT_CABLE_LINK_TRAINING BIT(23) From patchwork Thu Nov 7 19:29:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 13866992 Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) (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 1B5DB217F49 for ; Thu, 7 Nov 2024 19:31:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007907; cv=none; b=r/+MGuoSuZdTp3GuDKQtPelEhRtORq/Kgxhd/scVTSc+RJPWRSf4gKIzSNE7C2VT0AK911jpL0NCtiW1Q2csHtsYLhtOKGReq0OcCd/gd52pzXMV55UWn5CS1nQcG4c0gLXi5Bz/PTZAoyblNBeDfcNWiKiYQbJ5z1sMM7w531k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007907; c=relaxed/simple; bh=Wg/zBVFa4tGz8VOCaxh6a+i+WqdrvN3SJxMoDY3tJdA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DzSDGVNo8EsMkGbIwVxYborc3D//TCSIPuk7Dvoe/t38SA2G8IBN2IF+PGl4ON2xIoFxzZZxhGbQ3DhcswWt5hoAXhOCnYZ66LqMQjx/oo2E94J9O0u/7Y+lRt9v0Daly1zKQdP/W3CtY8212ODWrW4cdl3vEau/TYlBZqItmMQ= 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=Kgv7x5kb; arc=none smtp.client-ip=209.85.167.173 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="Kgv7x5kb" Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3e602994635so1038310b6e.0 for ; Thu, 07 Nov 2024 11:31:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731007905; x=1731612705; darn=lists.linux.dev; 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=Q0CqREGwh6IVDq65gpD5flYOXg4XbjfkPAiJB5bPZJk=; b=Kgv7x5kbg1Dx5QSEv1A/TY1VDeMkNFXwqhrReovt8DP+C0pTlFpmIMZU6TSL0aS6s1 w4ZoftIa0pAq1qFKb+y9KbCnfSrZQw7cqQyOqkEyCV0ImB3I0CgnOKTYrAWSQ9t1BSrc Uy/OEQnc6hmYJ9IwodFqqQTTrrBOff9XOt8Hg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731007905; x=1731612705; 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=Q0CqREGwh6IVDq65gpD5flYOXg4XbjfkPAiJB5bPZJk=; b=BPKmi1fu7dPmOcREEygcGWae2MwiPAnYsQZd65uf8vpIUMxJLEebPXbkagmBkRNvIV 8FecC+y8FHsw8gJZYzekjI5b7G4M1OPVDF8ujMwLK3XcvqeeIFFZaSsQbGuvQaUNfCfq t4FqjdbC46JCrcy5yECP6cOY5YIiPM0Q5tGFdtJCrDrskm55zykGvB8asw+XSqgapoZU 2ElEEvJRRwYWTGe8koUV9fRwp9mHkP7BBYY7btCp+pGRU2eBOzLxzX9ryyoCuY2dinb6 3T3RIqw+y8EZ3foZ2SNBtGPSdKJifPogmGq6zErQJAq4TCwEjQmCknU+eFt2N/5toSdx 6E7Q== X-Forwarded-Encrypted: i=1; AJvYcCULbjXgwpNagz+4KbWSWkb1xk70Xf7BdvbYZhDucqfJz3+dlgGdhRw0XLRIYomeGMwMYNrhqPCNKs4RVeMCgO4=@lists.linux.dev X-Gm-Message-State: AOJu0YysYyzdNUOBHJDgBGJ+UVzvUGADJbqJU8CV8T1YbEEaGyhvUY88 MwJcZmhqUMmNZCLiYWbrmJYvD7+UjV8rxK3qYq2q/EKN8CTpIYTbNzGnv+C6dg== X-Google-Smtp-Source: AGHT+IFgcTmVRvr38xnLKX/v1C7i4XoxmAx6AzKMJtRI0ZbWE+Lp0wJnd9PeKHKFSh9kgaJYd9NuNA== X-Received: by 2002:a05:6808:1791:b0:3e6:2471:4d10 with SMTP id 5614622812f47-3e794675446mr451938b6e.11.1731007904802; Thu, 07 Nov 2024 11:31:44 -0800 (PST) Received: from localhost (198.103.247.35.bc.googleusercontent.com. [35.247.103.198]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7f41f65bf87sm1827097a12.70.2024.11.07.11.31.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Nov 2024 11:31:44 -0800 (PST) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: jthies@google.com, akuchynski@google.com, pmalani@chromium.org, dmitry.baryshkov@linaro.org, Abhishek Pandit-Subedi , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [PATCH v3 3/7] usb: typec: Check port is active before enter mode on probe Date: Thu, 7 Nov 2024 11:29:56 -0800 Message-ID: <20241107112955.v3.3.I439cffc7bf76d94f5850eb85980f1197c4f9154c@changeid> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <20241107193021.2690050-1-abhishekpandit@chromium.org> References: <20241107193021.2690050-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Enforce the same requirement as when we attempt to activate altmode via sysfs (do not enter partner mode if port mode is not active). In order to set a default value for this field, also introduce the inactive field in struct typec_altmode_desc. Signed-off-by: Abhishek Pandit-Subedi Reviewed-by: Heikki Krogerus --- Changes in v3: - Use port.active instead of introducing auto-enter field - Introduce inactive field to typec_altmode_desc to set default value for active. - Always make port 'active' field writable drivers/usb/typec/altmodes/displayport.c | 7 +++++-- drivers/usb/typec/altmodes/thunderbolt.c | 6 +++++- drivers/usb/typec/class.c | 5 +++-- include/linux/usb/typec.h | 2 ++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c index 3245e03d59e6..f4116e96f6a1 100644 --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -767,8 +767,11 @@ int dp_altmode_probe(struct typec_altmode *alt) if (plug) typec_altmode_set_drvdata(plug, dp); - dp->state = plug ? DP_STATE_ENTER_PRIME : DP_STATE_ENTER; - schedule_work(&dp->work); + /* Only attempt to enter altmode if port is active. */ + if (port->active) { + dp->state = plug ? DP_STATE_ENTER_PRIME : DP_STATE_ENTER; + schedule_work(&dp->work); + } return 0; } diff --git a/drivers/usb/typec/altmodes/thunderbolt.c b/drivers/usb/typec/altmodes/thunderbolt.c index a945b9d35a1d..45567abc3bb8 100644 --- a/drivers/usb/typec/altmodes/thunderbolt.c +++ b/drivers/usb/typec/altmodes/thunderbolt.c @@ -212,6 +212,7 @@ static const struct typec_altmode_ops tbt_altmode_ops = { static int tbt_altmode_probe(struct typec_altmode *alt) { + const struct typec_altmode *port = typec_altmode_get_partner(alt); struct tbt_altmode *tbt; tbt = devm_kzalloc(&alt->dev, sizeof(*tbt), GFP_KERNEL); @@ -226,7 +227,10 @@ static int tbt_altmode_probe(struct typec_altmode *alt) typec_altmode_set_drvdata(alt, tbt); typec_altmode_set_ops(alt, &tbt_altmode_ops); - if (tbt_ready(alt)) { + /* Only attempt to enter altmode if port is active and cable/plug + * information is ready. + */ + if (port->active && tbt_ready(alt)) { if (tbt->plug[TYPEC_PLUG_SOP_PP]) tbt->state = TBT_STATE_SOP_PP_ENTER; else if (tbt->plug[TYPEC_PLUG_SOP_P]) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index febe453b96be..b5e67a57762c 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -458,7 +458,8 @@ static umode_t typec_altmode_attr_is_visible(struct kobject *kobj, struct typec_altmode *adev = to_typec_altmode(kobj_to_dev(kobj)); if (attr == &dev_attr_active.attr) - if (!adev->ops || !adev->ops->activate) + if (!is_typec_port(adev->dev.parent) && + (!adev->ops || !adev->ops->activate)) return 0444; return attr->mode; @@ -563,7 +564,7 @@ typec_register_altmode(struct device *parent, if (is_port) { alt->attrs[3] = &dev_attr_supported_roles.attr; - alt->adev.active = true; /* Enabled by default */ + alt->adev.active = !desc->inactive; /* Enabled by default */ } sprintf(alt->group_name, "mode%d", desc->mode); diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index d616b8807000..56c01771c190 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -140,6 +140,7 @@ int typec_cable_set_identity(struct typec_cable *cable); * @mode: Index of the Mode * @vdo: VDO returned by Discover Modes USB PD command * @roles: Only for ports. DRP if the mode is available in both roles + * @inactive: Only for ports. Make this port inactive (default is active). * * Description of an Alternate Mode which a connector, cable plug or partner * supports. @@ -150,6 +151,7 @@ struct typec_altmode_desc { u32 vdo; /* Only used with ports */ enum typec_port_data roles; + bool inactive : 1; }; void typec_partner_set_pd_revision(struct typec_partner *partner, u16 pd_revision); From patchwork Thu Nov 7 19:29:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 13866993 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 89F5F218304 for ; Thu, 7 Nov 2024 19:31:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007909; cv=none; b=b5DGW4GyzmMP46Bgp2+vynf6Dtn1XZfD5i2/a72eASGqEh3z+gQNG5Tyaz5HAL7xragtJ+zJxc1v0AJm9pp1iAeb88EXx0scF6js4HZpQXO1ARLTYkFNm5Ljz5C7sSwN5WTuVrQ4vuUgMWCo5WVf5l4SovcgDY4JYPpoAZWMobE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007909; c=relaxed/simple; bh=F1pTFIC/STStCNqTkG+Kgg/bMEZb3NhFwcrsacG2V4E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ew5E6IKKt4rZAdmPKZp2/bkOl0YS/54ebtywI8DuUzxMQaR+HEoF/jFodXUHtX0sGsggXg/Bns3P3KyOZsiFooUCdWK+HkSdsD3p62h5qeMWeHt+jEEwGq2qy9GZWWHqvyrH71BSLFIxS+LIJCgIhU9LIN8cESHSx46virpfjjU= 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=Ymz+yPpV; arc=none smtp.client-ip=209.85.210.181 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="Ymz+yPpV" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-7206304f93aso1209359b3a.0 for ; Thu, 07 Nov 2024 11:31:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731007907; x=1731612707; darn=lists.linux.dev; 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=MHcj0dVpOorLNzt+K3XMiAGRMpCigjM3RXLcIpCRHg4=; b=Ymz+yPpVrq5GAgkxklccyD51bw44ApAc2drXDCd6rQI3dvLe5ctQig7cSbwqPkZwR1 sncgnzcyuQPixzzg7Lm9jcx1woQr9ChksshPl7O2bMH5kN4If/GwoYcohqU3K1zxwFeP qMgpGatOot1POfhPaH8o9VvW9IYyw2tfmliE0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731007907; x=1731612707; 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=MHcj0dVpOorLNzt+K3XMiAGRMpCigjM3RXLcIpCRHg4=; b=gB8QxF4oMAxyBlIFkpDvgb3s/2HfkluKxNjVrtyWfd5GZiLAWu/SQRXy/RAqMz21ni ibkVjdEN2hzL9gpv5Hb3cO/AdTiMZYP4fxGplYhH8myNTqJtngGpHq6bfepMNEk2qCaf TpjOej88mGTPzZzbDiRvDx9yqnYPbFCLr8or8PjX2KKs349UPQPbkEHagKikBLb6d9ff vZIQ9iJyfIsfopCP9GlFugez9ARSsVYm6MBZ0Iv5XKvAdnvsPnNtkouufRu+kL96lpAM dsn+lO7KWtZEz9yvnU3s6FV+taBZQVXtcur+sGyoEkeeb4FEXzK9Krs53m/QG4yfN0r8 1SYw== X-Forwarded-Encrypted: i=1; AJvYcCU+apJjobe3lXAN8VJON9MIIm5wC9ZnXEz2VJnJhyqNhvqeTRoF0Ekhs2UGXNb3C28sykC28THYmnfPx2mMctw=@lists.linux.dev X-Gm-Message-State: AOJu0YyCDivoh5rvoMi+KZHpQUugigxJKJCwDBXb+Pyk0KByXSWDLvq9 ApB3hRXbSC9MRt5Rw8YFYLnjeu0bqAtT+BTLkOOR4JLGO9n/KNS7ASvdtVAkCdt+ju166ulmTg0 = X-Google-Smtp-Source: AGHT+IHDevD6Gmfrr4MwmAepRm3599OBUDO0F/CJ4qgD4bU7JNZCnBYFjzrvU6Mh5L/usSA2LFDrWA== X-Received: by 2002:a05:6a00:1252:b0:71e:c0c:5996 with SMTP id d2e1a72fcca58-724132a3730mr313854b3a.7.1731007906775; Thu, 07 Nov 2024 11:31:46 -0800 (PST) Received: from localhost (198.103.247.35.bc.googleusercontent.com. [35.247.103.198]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-72407a18e2csm2009358b3a.156.2024.11.07.11.31.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Nov 2024 11:31:46 -0800 (PST) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: jthies@google.com, akuchynski@google.com, pmalani@chromium.org, dmitry.baryshkov@linaro.org, Abhishek Pandit-Subedi , Benson Leung , Guenter Roeck , linux-kernel@vger.kernel.org Subject: [PATCH v3 4/7] platform/chrome: cros_ec_typec: Update partner altmode active Date: Thu, 7 Nov 2024 11:29:57 -0800 Message-ID: <20241107112955.v3.4.I083bf9188947be8cb7460211cfdf3233370a28f6@changeid> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <20241107193021.2690050-1-abhishekpandit@chromium.org> References: <20241107193021.2690050-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Mux configuration is often the final piece of mode entry and can be used to determine whether a partner altmode is active. When mux configuration is done, use the active port altmode's SVID to set the partner active field for all partner alt modes. Signed-off-by: Abhishek Pandit-Subedi --- (no changes since v1) drivers/platform/chrome/cros_ec_typec.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index c7781aea0b88..e3eabe5e42ac 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -618,6 +618,7 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num, }; struct ec_params_usb_pd_mux_ack mux_ack; enum typec_orientation orientation; + struct cros_typec_altmode_node *node, *n; int ret; ret = cros_ec_cmd(typec->ec, 0, EC_CMD_USB_PD_MUX_INFO, @@ -676,6 +677,16 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num, port->mux_flags); } + /* Iterate all partner alt-modes and set the active alternate mode. */ + list_for_each_entry_safe(node, n, &port->partner_mode_list, list) { + if (port->state.alt != NULL && + node->amode->svid == port->state.alt->svid) { + typec_altmode_update_active(node->amode, true); + } else { + typec_altmode_update_active(node->amode, false); + } + } + mux_ack: if (!typec->needs_mux_ack) return ret; From patchwork Thu Nov 7 19:29:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 13866994 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 5A22F218336 for ; Thu, 7 Nov 2024 19:31:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007911; cv=none; b=H+GmjQIcpxRmP22CYDTEnmXI0lYMKHJFVz/Nc6mPGo0TTf4DfHl/ndZADE5OB4vY35k+uqFY1a8kaCwrDKisx/0wY3EOjXUekaCjt7kVsO4UXYaLF00ZN27J2tvavtjhsud/auiSc7quRxwFhsP4ocsJ7qsUKEbSn/714K6VWOo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007911; c=relaxed/simple; bh=n8KJY3J9iv2lpBcZuKW5kNPAa04zqHHybIY+sJNd8J0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U2r1aMYjKa/sDuGdK5HyQn2MfrSw0lsyRAFpeamkhhdQA1DcR52aAz5DPYZWjUzoyWt/DbnjhyDDC9UtYYQH3eUAhzSSGYrlXCfr4ANPe+lvoPpKszaMPmXPFIoN4WdVN2usk314uw/zfAx/kjcYaLUDNa2+4RzkzvoaIAa9R6Y= 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=Qt0n70oU; arc=none smtp.client-ip=209.85.210.181 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="Qt0n70oU" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-71e681bc315so1044097b3a.0 for ; Thu, 07 Nov 2024 11:31:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731007909; x=1731612709; darn=lists.linux.dev; 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=NXLwVpSoeftRoET3ccC5saeWASd5OdykBU3Zi9Wk7FE=; b=Qt0n70oUz1qLc1p3/C5Y9Zk5pmZzcY8JbU30z99JqjW+rzzKEvWGMOjXzHQuYtjpI/ +Dt0iZDU+T3X/PaePunQ+ibArC9A2KAFS/t0sMAwUc3x9aZUEen5eZ8eXoqMXKnltwJN dYTapSVdjpHqCS3ZHDJuOaf9SqsuWa16GWaqM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731007909; x=1731612709; 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=NXLwVpSoeftRoET3ccC5saeWASd5OdykBU3Zi9Wk7FE=; b=iC79om3SCkPHVcp20aqXFj4tNa4kWhnURuHbVHpgF5wGvCNHQvUEV0VFgVPuGWqzqE cRqTrXeZQ/5vy8dabokThqWD39+2m60hf5qcsVdmXqU9rqGPQKVEN+ScRHjPLw1Nw8WC +hQFZu0a3d6/rE1ldCMv38vll2T+UC3vDnmTnRKy51QUNCNB3RtFkqkhbyjf06NbLr2H xuoCNuDrAdyRsjpMTEWpwrvkY0+WC/nhsVHryADqVxvTPpakX0OqXFZEWiqfkE9l7kRt HjhX/2ZNqqeiSXHNdNy07fbGZr/QmjMSgujfVjw+UicMkSMc6vTpkcroDHjAw3E8I3p3 qHqg== X-Forwarded-Encrypted: i=1; AJvYcCU/oUnrauC+gJvvU/8Y2b6XsfQsJhRh6lktFRbLfkHtq5HnympK0wFL+OJj3nZHsdnCG5pLq1ufe7f8jVIerS0=@lists.linux.dev X-Gm-Message-State: AOJu0YzkM9A5Hx6MUZPR9jtgE+s65v8FVfl2dwA+DYmAvbSc8DY/HG5Z 4vzUlJY2eT3hFBxdYv9k54T5FrlC2EABKyjSGAj8HIBFlPwWkvnclW5Qm+YANA== X-Google-Smtp-Source: AGHT+IEzLgAEfMGzFznaFn3bTLRyae18n1VFGCeP42BEZFpREYg7bSCd8zK2x0KaKUJw6VFBifesYA== X-Received: by 2002:a05:6a20:7f97:b0:1d9:a94:feec with SMTP id adf61e73a8af0-1dc232d81afmr22786637.2.1731007908603; Thu, 07 Nov 2024 11:31:48 -0800 (PST) Received: from localhost (198.103.247.35.bc.googleusercontent.com. [35.247.103.198]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7f41f5e7350sm1844353a12.44.2024.11.07.11.31.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Nov 2024 11:31:48 -0800 (PST) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: jthies@google.com, akuchynski@google.com, pmalani@chromium.org, dmitry.baryshkov@linaro.org, Abhishek Pandit-Subedi , Benson Leung , Guenter Roeck , linux-kernel@vger.kernel.org Subject: [PATCH v3 5/7] platform/chrome: cros_ec_typec: Displayport support Date: Thu, 7 Nov 2024 11:29:58 -0800 Message-ID: <20241107112955.v3.5.I142fc0c09df58689b98f0cebf1c5e48b9d4fa800@changeid> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <20241107193021.2690050-1-abhishekpandit@chromium.org> References: <20241107193021.2690050-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add support for entering and exiting displayport alt-mode on systems using AP driven alt-mode. Signed-off-by: Abhishek Pandit-Subedi --- Changes in v3: - Refactored typec_altmode_dp_data per review request - Removed unused vdm operations during altmode registration Changes in v2: - Refactored displayport into cros_typec_altmode.c to extract common implementation between altmodes MAINTAINERS | 3 + drivers/platform/chrome/Makefile | 4 + drivers/platform/chrome/cros_ec_typec.c | 12 +- drivers/platform/chrome/cros_ec_typec.h | 1 + drivers/platform/chrome/cros_typec_altmode.c | 275 +++++++++++++++++++ drivers/platform/chrome/cros_typec_altmode.h | 34 +++ 6 files changed, 326 insertions(+), 3 deletions(-) create mode 100644 drivers/platform/chrome/cros_typec_altmode.c create mode 100644 drivers/platform/chrome/cros_typec_altmode.h diff --git a/MAINTAINERS b/MAINTAINERS index cd6aa609deba..5f9d8b8f1cb3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5369,9 +5369,12 @@ F: include/linux/platform_data/cros_usbpd_notify.h CHROMEOS EC USB TYPE-C DRIVER M: Prashant Malani +M: Benson Leung +M: Abhishek Pandit-Subedi L: chrome-platform@lists.linux.dev S: Maintained F: drivers/platform/chrome/cros_ec_typec.* +F: drivers/platform/chrome/cros_typec_altmode.* F: drivers/platform/chrome/cros_typec_switch.c F: drivers/platform/chrome/cros_typec_vdm.* diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile index 2dcc6ccc2302..2f90d4db8099 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -18,7 +18,11 @@ obj-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o obj-$(CONFIG_CROS_EC_UART) += cros_ec_uart.o cros_ec_lpcs-objs := cros_ec_lpc.o cros_ec_lpc_mec.o cros-ec-typec-objs := cros_ec_typec.o cros_typec_vdm.o +ifneq ($(CONFIG_TYPEC_DP_ALTMODE),) + cros-ec-typec-objs += cros_typec_altmode.o +endif obj-$(CONFIG_CROS_EC_TYPEC) += cros-ec-typec.o + obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o cros_ec_trace.o obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index e3eabe5e42ac..3a6f5f2717b9 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -18,6 +18,7 @@ #include "cros_ec_typec.h" #include "cros_typec_vdm.h" +#include "cros_typec_altmode.h" #define DRV_NAME "cros-ec-typec" @@ -293,12 +294,11 @@ static int cros_typec_register_port_altmodes(struct cros_typec_data *typec, desc.svid = USB_TYPEC_DP_SID; desc.mode = USB_TYPEC_DP_MODE; desc.vdo = DP_PORT_VDO; - amode = typec_port_register_altmode(port->port, &desc); + amode = cros_typec_register_displayport(port, &desc, + typec->ap_driven_altmode); if (IS_ERR(amode)) return PTR_ERR(amode); port->port_altmode[CROS_EC_ALTMODE_DP] = amode; - typec_altmode_set_drvdata(amode, port); - amode->ops = &port_amode_ops; /* * Register TBT compatibility alt mode. The EC will not enter the mode @@ -575,6 +575,10 @@ static int cros_typec_enable_dp(struct cros_typec_data *typec, if (!ret) ret = typec_mux_set(port->mux, &port->state); + if (!ret) + cros_typec_displayport_status_update(port->state.alt, + port->state.data); + return ret; } @@ -1254,6 +1258,8 @@ static int cros_typec_probe(struct platform_device *pdev) typec->typec_cmd_supported = cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_CMD); typec->needs_mux_ack = cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK); + typec->ap_driven_altmode = cros_ec_check_features( + ec_dev, EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY); ret = cros_ec_cmd(typec->ec, 0, EC_CMD_USB_PD_PORTS, NULL, 0, &resp, sizeof(resp)); diff --git a/drivers/platform/chrome/cros_ec_typec.h b/drivers/platform/chrome/cros_ec_typec.h index deda180a646f..9fd5342bb0ad 100644 --- a/drivers/platform/chrome/cros_ec_typec.h +++ b/drivers/platform/chrome/cros_ec_typec.h @@ -39,6 +39,7 @@ struct cros_typec_data { struct work_struct port_work; bool typec_cmd_supported; bool needs_mux_ack; + bool ap_driven_altmode; }; /* Per port data. */ diff --git a/drivers/platform/chrome/cros_typec_altmode.c b/drivers/platform/chrome/cros_typec_altmode.c new file mode 100644 index 000000000000..3598b8a6ceee --- /dev/null +++ b/drivers/platform/chrome/cros_typec_altmode.c @@ -0,0 +1,275 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Alt-mode implementation on ChromeOS EC. + * + * Copyright 2024 Google LLC + * Author: Abhishek Pandit-Subedi + */ +#include "cros_ec_typec.h" + +#include +#include + +#include "cros_typec_altmode.h" + +struct cros_typec_altmode_data { + struct work_struct work; + struct cros_typec_port *port; + struct typec_altmode *alt; + bool ap_mode_entry; + + u32 header; + u32 *vdo_data; + u8 vdo_size; + + u16 sid; + u8 mode; +}; + +struct cros_typec_dp_data { + struct cros_typec_altmode_data adata; + struct typec_displayport_data data; + bool configured; + bool pending_status_update; +}; + +static void cros_typec_altmode_work(struct work_struct *work) +{ + struct cros_typec_altmode_data *data = + container_of(work, struct cros_typec_altmode_data, work); + + if (typec_altmode_vdm(data->alt, data->header, data->vdo_data, + data->vdo_size)) + dev_err(&data->alt->dev, "VDM 0x%x failed", data->header); + + data->header = 0; + data->vdo_data = NULL; + data->vdo_size = 0; +} + +static int cros_typec_altmode_enter(struct typec_altmode *alt, u32 *vdo) +{ + struct cros_typec_altmode_data *data = typec_altmode_get_drvdata(alt); + struct ec_params_typec_control req = { + .port = data->port->port_num, + .command = TYPEC_CONTROL_COMMAND_ENTER_MODE, + }; + int svdm_version; + int ret; + + if (!data->ap_mode_entry) { + const struct typec_altmode *partner = + typec_altmode_get_partner(alt); + dev_warn(&partner->dev, + "EC does not support ap driven mode entry\n"); + return -EOPNOTSUPP; + } + + if (data->sid == USB_TYPEC_DP_SID) + req.mode_to_enter = CROS_EC_ALTMODE_DP; + else + return -EOPNOTSUPP; + + ret = cros_ec_cmd(data->port->typec_data->ec, 0, EC_CMD_TYPEC_CONTROL, + &req, sizeof(req), NULL, 0); + if (ret < 0) + return ret; + + svdm_version = typec_altmode_get_svdm_version(alt); + if (svdm_version < 0) + return svdm_version; + + data->header = VDO(data->sid, 1, svdm_version, CMD_ENTER_MODE); + data->header |= VDO_OPOS(data->mode); + data->header |= VDO_CMDT(CMDT_RSP_ACK); + + data->vdo_data = NULL; + data->vdo_size = 1; + + schedule_work(&data->work); + + return ret; +} + +static int cros_typec_altmode_exit(struct typec_altmode *alt) +{ + struct cros_typec_altmode_data *data = typec_altmode_get_drvdata(alt); + struct ec_params_typec_control req = { + .port = data->port->port_num, + .command = TYPEC_CONTROL_COMMAND_EXIT_MODES, + }; + int svdm_version; + int ret; + + if (!data->ap_mode_entry) { + const struct typec_altmode *partner = + typec_altmode_get_partner(alt); + dev_warn(&partner->dev, + "EC does not support ap driven mode entry\n"); + return -EOPNOTSUPP; + } + + ret = cros_ec_cmd(data->port->typec_data->ec, 0, EC_CMD_TYPEC_CONTROL, + &req, sizeof(req), NULL, 0); + + if (ret < 0) + return ret; + + svdm_version = typec_altmode_get_svdm_version(alt); + if (svdm_version < 0) + return svdm_version; + + data->header = VDO(data->sid, 1, svdm_version, CMD_EXIT_MODE); + data->header |= VDO_OPOS(data->mode); + data->header |= VDO_CMDT(CMDT_RSP_ACK); + + data->vdo_data = NULL; + data->vdo_size = 1; + + schedule_work(&data->work); + + return ret; +} + +static int cros_typec_displayport_vdm(struct typec_altmode *alt, u32 header, + const u32 *data, int count) +{ + struct cros_typec_dp_data *dp_data = typec_altmode_get_drvdata(alt); + struct cros_typec_altmode_data *adata = &dp_data->adata; + + + int cmd_type = PD_VDO_CMDT(header); + int cmd = PD_VDO_CMD(header); + int svdm_version; + + if (!adata->ap_mode_entry) { + const struct typec_altmode *partner = + typec_altmode_get_partner(alt); + dev_warn(&partner->dev, + "EC does not support ap driven mode entry\n"); + return -EOPNOTSUPP; + } + + svdm_version = typec_altmode_get_svdm_version(alt); + if (svdm_version < 0) + return svdm_version; + + switch (cmd_type) { + case CMDT_INIT: + if (PD_VDO_SVDM_VER(header) < svdm_version) { + typec_partner_set_svdm_version(adata->port->partner, + PD_VDO_SVDM_VER(header)); + svdm_version = PD_VDO_SVDM_VER(header); + } + + adata->header = VDO(adata->sid, 1, svdm_version, cmd); + adata->header |= VDO_OPOS(adata->mode); + + /* + * DP_CMD_CONFIGURE: We can't actually do anything with the + * provided VDO yet so just send back an ACK. + * + * DP_CMD_STATUS_UPDATE: We wait for Mux changes to send + * DPStatus Acks. + */ + switch (cmd) { + case DP_CMD_CONFIGURE: + dp_data->data.conf = *data; + adata->header |= VDO_CMDT(CMDT_RSP_ACK); + dp_data->configured = true; + schedule_work(&adata->work); + break; + case DP_CMD_STATUS_UPDATE: + dp_data->pending_status_update = true; + break; + default: + adata->header |= VDO_CMDT(CMDT_RSP_ACK); + schedule_work(&adata->work); + break; + } + + break; + default: + break; + } + + return 0; +} + +static int cros_typec_altmode_vdm(struct typec_altmode *alt, u32 header, + const u32 *data, int count) +{ + struct cros_typec_altmode_data *adata = typec_altmode_get_drvdata(alt); + + if (adata->sid == USB_TYPEC_DP_SID) + return cros_typec_displayport_vdm(alt, header, data, count); + + return -EINVAL; +} + +static const struct typec_altmode_ops cros_typec_altmode_ops = { + .enter = cros_typec_altmode_enter, + .exit = cros_typec_altmode_exit, + .vdm = cros_typec_altmode_vdm, +}; + +#if IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE) +int cros_typec_displayport_status_update(struct typec_altmode *altmode, + struct typec_displayport_data *data) +{ + struct cros_typec_dp_data *dp_data = + typec_altmode_get_drvdata(altmode); + struct cros_typec_altmode_data *adata = &dp_data->adata; + + if (!dp_data->pending_status_update) { + dev_dbg(&altmode->dev, + "Got DPStatus without a pending request"); + return 0; + } + + if (dp_data->configured && dp_data->data.conf != data->conf) + dev_dbg(&altmode->dev, + "DP Conf doesn't match. Requested 0x%04x, Actual 0x%04x", + dp_data->data.conf, data->conf); + + dp_data->data = *data; + dp_data->pending_status_update = false; + adata->header |= VDO_CMDT(CMDT_RSP_ACK); + adata->vdo_data = &dp_data->data.status; + adata->vdo_size = 2; + + schedule_work(&adata->work); + return 0; +} + +struct typec_altmode * +cros_typec_register_displayport(struct cros_typec_port *port, + struct typec_altmode_desc *desc, + bool ap_mode_entry) +{ + struct typec_altmode *alt; + struct cros_typec_altmode_data *data; + + alt = typec_port_register_altmode(port->port, desc); + if (IS_ERR(alt)) + return alt; + + data = devm_kzalloc(&alt->dev, sizeof(*data), GFP_KERNEL); + if (!data) { + typec_unregister_altmode(alt); + return ERR_PTR(-ENOMEM); + } + + INIT_WORK(&data->work, cros_typec_altmode_work); + data->alt = alt; + data->port = port; + data->ap_mode_entry = ap_mode_entry; + data->sid = desc->svid; + data->mode = desc->mode; + + typec_altmode_set_ops(alt, &cros_typec_altmode_ops); + typec_altmode_set_drvdata(alt, data); + + return alt; +} +#endif diff --git a/drivers/platform/chrome/cros_typec_altmode.h b/drivers/platform/chrome/cros_typec_altmode.h new file mode 100644 index 000000000000..c6f8fb02c99c --- /dev/null +++ b/drivers/platform/chrome/cros_typec_altmode.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __CROS_TYPEC_ALTMODE_H__ +#define __CROS_TYPEC_ALTMODE_H__ + +struct cros_typec_port; +struct typec_altmode; +struct typec_altmode_desc; +struct typec_displayport_data; + +#if IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE) +struct typec_altmode * +cros_typec_register_displayport(struct cros_typec_port *port, + struct typec_altmode_desc *desc, + bool ap_mode_entry); + +int cros_typec_displayport_status_update(struct typec_altmode *altmode, + struct typec_displayport_data *data); +#else +static inline struct typec_altmode * +cros_typec_register_displayport(struct cros_typec_port *port, + struct typec_altmode_desc *desc, + bool ap_mode_entry) +{ + return typec_port_register_altmode(port->port, desc); +} + +static inline int cros_typec_displayport_status_update(struct typec_altmode *altmode, + struct typec_displayport_data *data) +{ + return 0; +} +#endif +#endif /* __CROS_TYPEC_ALTMODE_H__ */ From patchwork Thu Nov 7 19:29:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 13866995 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 E4BC1198840 for ; Thu, 7 Nov 2024 19:31:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007912; cv=none; b=H+i2vjqJUvIK84ArWk3na16Egl0MkouyVG1zHb2bRDeL6Yro69ydZNNboSphiCTN6lpUqmiJ/wRtRyPF8rVHPnBSAFVOStzNyH7orUxmoSMx3SBwoImiK6uDAqf6PcaYiH8ZtvEafsKcn8Bglc21XSIyERATzKozK8Zp4607jr0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007912; c=relaxed/simple; bh=E2+M2MN8fFlYlxb6VQg1nVCnYvwszeZCoKtjpG3T7lM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c54c6/au+xFslfI3AiUG+PKicg7tStXUjkBQVSlvZJ8GhF3WSJ6OCN9/LmcXtn7VdZEBoIDkERa7sazvMYppfyXbSLYSXWtx1nu6O4DRmfAluXvdq8PLFysMDSbu81/pmHXBcrA85bRN6Dkr1wT9slCh+VVl/ucggykD//ZRFdI= 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=TZmpqaWD; arc=none smtp.client-ip=209.85.214.172 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="TZmpqaWD" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-20e576dbc42so15529365ad.0 for ; Thu, 07 Nov 2024 11:31:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731007910; x=1731612710; darn=lists.linux.dev; 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=qahFf7OaEhB1/uoMJ7ZhjCogHtklDwuIFxHOF/W2wEw=; b=TZmpqaWD34WYeeprwAxerWtNA6nWE+G+LAdtYpwWsKL8JURgkygszSqjIYinWFfbyX 59SSMB7QOxZYG/cCQJ4kXCvwa7oIZffNUsbQr3zE3ZfMMU94QNTtpJ3k9gaV8VqfDM1M wktSMHZWu6l2mAUAfavEzvkeZNT9aZNy8aJ2Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731007910; x=1731612710; 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=qahFf7OaEhB1/uoMJ7ZhjCogHtklDwuIFxHOF/W2wEw=; b=VrfS3K7ekfg7OXCXnImK+cRWkJ2q/s8lEVyFN+aWLa3Af8H0tPiLueSHUmCletwhAc OIUNDIc9wdFUeiF+vlEaL6yaBIUdakDMV8Nrd8XrzXuPOJz1OJNNYufkUfv4MY6wnjx2 X13TG5BrZw4cFnFaMFkwjx1RaxiTyDzrVGGWklXQ6b4oekx6iw3TQAZ8TiMHpQezd7lM D/dYp3i6X+uT6KWDfTDKPTBDScceVVhGLTw9IVKrycXRj2fDxNV/dpSxkPUch/56gpVo D4agHgJzZObqVZL2zA3+jroGDEf023dBu06sNH8QqlfxkJoDUjvTEbCmihWhZVi1dhCo zSWg== X-Forwarded-Encrypted: i=1; AJvYcCVptF/pjQt8+Xu8f8zS3FQyGEwqLFV4qmTJAoVykJ4sLeNn8zTBdHBgQBXjB7WukKqEkVK7/kE9L186TGMypR8=@lists.linux.dev X-Gm-Message-State: AOJu0YxItEoGyopS8z6ctT2MRN9BdoMUoLEFx89sprZJBE/Krt6gt0VE GkrqnFZeFQiAhLFm5xATvKtUQlyefYolruQ2PvGHVYH8YTWdt3fStqPetMPa6Q== X-Google-Smtp-Source: AGHT+IGWkbnkCjIV3dJz/iBdmtY7Ly9vf/uAdEsL99zEhI6TLxL9l3vnmT+LElfo1eNNfah7sutZAg== X-Received: by 2002:a17:902:e550:b0:20b:c17f:9dad with SMTP id d9443c01a7336-211835cce81mr452975ad.53.1731007910361; Thu, 07 Nov 2024 11:31:50 -0800 (PST) Received: from localhost (198.103.247.35.bc.googleusercontent.com. [35.247.103.198]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-21177e6b9besm16137755ad.248.2024.11.07.11.31.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Nov 2024 11:31:50 -0800 (PST) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: jthies@google.com, akuchynski@google.com, pmalani@chromium.org, dmitry.baryshkov@linaro.org, Abhishek Pandit-Subedi , Benson Leung , Guenter Roeck , linux-kernel@vger.kernel.org Subject: [PATCH v3 6/7] platform/chrome: cros_ec_typec: Thunderbolt support Date: Thu, 7 Nov 2024 11:29:59 -0800 Message-ID: <20241107112955.v3.6.Ic61ced3cdfb5d6776435356061f12307da719829@changeid> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <20241107193021.2690050-1-abhishekpandit@chromium.org> References: <20241107193021.2690050-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add support for entering and exiting Thunderbolt alt-mode using AP driven alt-mode. Signed-off-by: Abhishek Pandit-Subedi --- Changes in v3: - Fix usage of TBT sid and mode. - Removed unused vdm operations during altmode registration Changes in v2: - Refactored thunderbolt support into cros_typec_altmode.c drivers/platform/chrome/Makefile | 3 + drivers/platform/chrome/cros_ec_typec.c | 23 +++--- drivers/platform/chrome/cros_typec_altmode.c | 85 ++++++++++++++++++++ drivers/platform/chrome/cros_typec_altmode.h | 14 ++++ 4 files changed, 114 insertions(+), 11 deletions(-) diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile index 2f90d4db8099..b9b1281de063 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -21,6 +21,9 @@ cros-ec-typec-objs := cros_ec_typec.o cros_typec_vdm.o ifneq ($(CONFIG_TYPEC_DP_ALTMODE),) cros-ec-typec-objs += cros_typec_altmode.o endif +ifneq ($(CONFIG_TYPEC_TBT_ALTMODE),) + cros-ec-typec-objs += cros_typec_altmode.o +endif obj-$(CONFIG_CROS_EC_TYPEC) += cros-ec-typec.o obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index 3a6f5f2717b9..558b618df63c 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -302,18 +302,19 @@ static int cros_typec_register_port_altmodes(struct cros_typec_data *typec, /* * Register TBT compatibility alt mode. The EC will not enter the mode - * if it doesn't support it, so it's safe to register it unconditionally - * here for now. + * if it doesn't support it and it will not enter automatically by + * design so we can use the |ap_driven_altmode| feature to check if we + * should register it. */ - memset(&desc, 0, sizeof(desc)); - desc.svid = USB_TYPEC_TBT_SID; - desc.mode = TYPEC_ANY_MODE; - amode = typec_port_register_altmode(port->port, &desc); - if (IS_ERR(amode)) - return PTR_ERR(amode); - port->port_altmode[CROS_EC_ALTMODE_TBT] = amode; - typec_altmode_set_drvdata(amode, port); - amode->ops = &port_amode_ops; + if (typec->ap_driven_altmode) { + memset(&desc, 0, sizeof(desc)); + desc.svid = USB_TYPEC_TBT_SID; + desc.mode = TBT_MODE; + amode = cros_typec_register_thunderbolt(port, &desc); + if (IS_ERR(amode)) + return PTR_ERR(amode); + port->port_altmode[CROS_EC_ALTMODE_TBT] = amode; + } port->state.alt = NULL; port->state.mode = TYPEC_STATE_USB; diff --git a/drivers/platform/chrome/cros_typec_altmode.c b/drivers/platform/chrome/cros_typec_altmode.c index 3598b8a6ceee..9cf2cef6c277 100644 --- a/drivers/platform/chrome/cros_typec_altmode.c +++ b/drivers/platform/chrome/cros_typec_altmode.c @@ -8,6 +8,7 @@ #include "cros_ec_typec.h" #include +#include #include #include "cros_typec_altmode.h" @@ -67,6 +68,8 @@ static int cros_typec_altmode_enter(struct typec_altmode *alt, u32 *vdo) if (data->sid == USB_TYPEC_DP_SID) req.mode_to_enter = CROS_EC_ALTMODE_DP; + else if (data->sid == USB_TYPEC_TBT_SID) + req.mode_to_enter = CROS_EC_ALTMODE_TBT; else return -EOPNOTSUPP; @@ -196,6 +199,53 @@ static int cros_typec_displayport_vdm(struct typec_altmode *alt, u32 header, return 0; } +static int cros_typec_thunderbolt_vdm(struct typec_altmode *alt, u32 header, + const u32 *data, int count) +{ + struct cros_typec_altmode_data *adata = typec_altmode_get_drvdata(alt); + + int cmd_type = PD_VDO_CMDT(header); + int cmd = PD_VDO_CMD(header); + int svdm_version; + + svdm_version = typec_altmode_get_svdm_version(alt); + if (svdm_version < 0) + return svdm_version; + + switch (cmd_type) { + case CMDT_INIT: + if (PD_VDO_SVDM_VER(header) < svdm_version) { + typec_partner_set_svdm_version(adata->port->partner, + PD_VDO_SVDM_VER(header)); + svdm_version = PD_VDO_SVDM_VER(header); + } + + adata->header = VDO(adata->sid, 1, svdm_version, cmd); + adata->header |= VDO_OPOS(adata->mode); + + switch (cmd) { + case CMD_ENTER_MODE: + /* Don't respond to the enter mode vdm because it + * triggers mux configuration. This is handled directly + * by the cros_ec_typec driver so the Thunderbolt driver + * doesn't need to be involved. + */ + break; + default: + adata->header |= VDO_CMDT(CMDT_RSP_ACK); + schedule_work(&adata->work); + break; + } + + break; + default: + break; + } + + return 0; +} + + static int cros_typec_altmode_vdm(struct typec_altmode *alt, u32 header, const u32 *data, int count) { @@ -204,6 +254,9 @@ static int cros_typec_altmode_vdm(struct typec_altmode *alt, u32 header, if (adata->sid == USB_TYPEC_DP_SID) return cros_typec_displayport_vdm(alt, header, data, count); + if (adata->sid == USB_TYPEC_TBT_SID) + return cros_typec_thunderbolt_vdm(alt, header, data, count); + return -EINVAL; } @@ -273,3 +326,35 @@ cros_typec_register_displayport(struct cros_typec_port *port, return alt; } #endif + +#if IS_ENABLED(CONFIG_TYPEC_TBT_ALTMODE) +struct typec_altmode * +cros_typec_register_thunderbolt(struct cros_typec_port *port, + struct typec_altmode_desc *desc) +{ + struct typec_altmode *alt; + struct cros_typec_altmode_data *data; + + alt = typec_port_register_altmode(port->port, desc); + if (IS_ERR(alt)) + return alt; + + data = devm_kzalloc(&alt->dev, sizeof(*data), GFP_KERNEL); + if (!data) { + typec_unregister_altmode(alt); + return ERR_PTR(-ENOMEM); + } + + INIT_WORK(&data->work, cros_typec_altmode_work); + data->alt = alt; + data->port = port; + data->ap_mode_entry = true; + data->sid = desc->svid; + data->mode = desc->mode; + + typec_altmode_set_ops(alt, &cros_typec_altmode_ops); + typec_altmode_set_drvdata(alt, data); + + return alt; +} +#endif diff --git a/drivers/platform/chrome/cros_typec_altmode.h b/drivers/platform/chrome/cros_typec_altmode.h index c6f8fb02c99c..810b553ddcd8 100644 --- a/drivers/platform/chrome/cros_typec_altmode.h +++ b/drivers/platform/chrome/cros_typec_altmode.h @@ -31,4 +31,18 @@ static inline int cros_typec_displayport_status_update(struct typec_altmode *alt return 0; } #endif + +#if IS_ENABLED(CONFIG_TYPEC_TBT_ALTMODE) +struct typec_altmode * +cros_typec_register_thunderbolt(struct cros_typec_port *port, + struct typec_altmode_desc *desc); +#else +static inline struct typec_altmode * +cros_typec_register_thunderbolt(struct cros_typec_port *port, + struct typec_altmode_desc *desc) +{ + return typec_port_register_altmode(port->port, desc); +} +#endif + #endif /* __CROS_TYPEC_ALTMODE_H__ */ From patchwork Thu Nov 7 19:30:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 13866996 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 80323218302 for ; Thu, 7 Nov 2024 19:31:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007914; cv=none; b=maq4sGzKvCdXIpbJ2of+CskrBy7oM9sxwzCn7/rbc5g/sKNiUAqjZ+JltKhUnIcBVL8Gj6QUlJxN5TlDvgdWR8ak8HA+0e1/uo2SXMPiWjOJfqwbM4+w6EyWEkyOIwrm6aofhVzD3R0xCQsUfdohmXtkxkJusHUnCYix6WsDbUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007914; c=relaxed/simple; bh=WCQG+4mTAioC2RRhlKrzuWizF30INk2UWBFKj8OUk3c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n2dcWaHWRJQRCo7RjHdzFjLfcp5P0iRoHOKEz6/1vcSn6cIm6ydGOQnaMovXqUCkj7R8D3Iy/lEqDiGgIj4WRXSWp8if2T5qO36J4taq3FmJPqypP9wYH20Zn1cVDp+uHx7/qyqEt36XRgRVHTHA+oQBDT2/mzkjDpoxcwEJ3PY= 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=ScNUYfd+; arc=none smtp.client-ip=209.85.210.176 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="ScNUYfd+" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-723f37dd76cso1342046b3a.0 for ; Thu, 07 Nov 2024 11:31:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1731007912; x=1731612712; darn=lists.linux.dev; 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=qB0OiXmaVUdpADLZ0hMEUy5iSBeICNTxG7bvkK2xwhA=; b=ScNUYfd+gpV6vywmc0QCuTV2l18jiFMQX12bCXjLHf3XHGvni/ysosHgbgHy07TtGY dd2wrIcc7QfEBLVLrIAkBLBB9DaKNHt21rWlHCENoAwZrtAFxowpldJ4Np9xdEtsnR8p Si6W5898HlVwwDfUNk0TO/2tSrTcv1Ihm//D4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731007912; x=1731612712; 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=qB0OiXmaVUdpADLZ0hMEUy5iSBeICNTxG7bvkK2xwhA=; b=ss+3iPXmc3dEDssmSMwI7KiKiy+GeiGkYhgrjdpgNexkLl5UL3HD/3JEQ+VyjrdxfJ mVLIRoL/lwL24FNipsBy5oSSEkFi5io8Itup5BCNlTt6v+sLIiCjj19R20mh5rP0JUKU EkueWcqXQIlOgvtMVCLTlLdyen90yG1wBuYbZ4adNILJgBUyrqQjCpvIK6ZJGjbAHFTD r7JcOylNoEkmCtwczxrqQVFV/TZVLaiRUTkYEjKvelzpp4mgjcJTDgJ+05GNCr14TRlg XntfocCJL4yDPl54AczLeQ7P0x1CIJup3OvpSv4A+hHX+dnSjq/QEJQW1+LJ07yDck82 PGXA== X-Forwarded-Encrypted: i=1; AJvYcCXmAA8nIagW7+X8wxTCrZ/Slnb23VSpn2orZkAv5kNHBIpnWl2uGMHTtqcE6MaeVLj/XIPH0xAih8tCgflPhF8=@lists.linux.dev X-Gm-Message-State: AOJu0YyCIl+srh6hhQCmMNRQknxmzF0STjX05g4sEDcMsYT3UX1CoiiC fRUhcUVa5iUfYPz7Chm3mjII0J2LmLQ7G6SQm3HHMpW2zo7ht1bAVKb+tqfC9w== X-Google-Smtp-Source: AGHT+IF2ok0t254IPtGqAU7UW2SbCfuqikNyMbjEWny3NohvrWFkb+GFcVlJONRZBGlNxqHJEomkEQ== X-Received: by 2002:a05:6a00:a1d:b0:71e:693c:107c with SMTP id d2e1a72fcca58-724132c15a3mr347895b3a.11.1731007911958; Thu, 07 Nov 2024 11:31:51 -0800 (PST) Received: from localhost (198.103.247.35.bc.googleusercontent.com. [35.247.103.198]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-72407a1fd2bsm1984909b3a.167.2024.11.07.11.31.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Nov 2024 11:31:51 -0800 (PST) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: jthies@google.com, akuchynski@google.com, pmalani@chromium.org, dmitry.baryshkov@linaro.org, Abhishek Pandit-Subedi , Benson Leung , Guenter Roeck , linux-kernel@vger.kernel.org Subject: [PATCH v3 7/7] platform/chrome: cros_ec_typec: Disable tbt on port Date: Thu, 7 Nov 2024 11:30:00 -0800 Message-ID: <20241107112955.v3.7.Ic14738918e3d026fa2d85e95fb68f8e07a0828d0@changeid> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <20241107193021.2690050-1-abhishekpandit@chromium.org> References: <20241107193021.2690050-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Altmodes with cros_ec are either automatically entered by the EC or entered by the AP if TBT or USB4 are supported on the system. Due to the security risk of PCIe tunneling, TBT modes should not be auto entered by the kernel at this time and will require user intervention. With this change, a userspace program will need to explicitly activate the thunderbolt mode on the port and partner in order to enter the mode and the thunderbolt driver will not automatically enter when a partner is connected. Signed-off-by: Abhishek Pandit-Subedi --- Changes in v3: - Set port.inactive = true instead of auto-enter. Changes in v2: - Only disable auto-enter for Thunderbolt - Update commit message to clearly indicate the need for userspace intervention to enter TBT mode 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/chrome/cros_ec_typec.c index 558b618df63c..b01efe82fb1e 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -310,6 +310,7 @@ static int cros_typec_register_port_altmodes(struct cros_typec_data *typec, memset(&desc, 0, sizeof(desc)); desc.svid = USB_TYPEC_TBT_SID; desc.mode = TBT_MODE; + desc.inactive = true; amode = cros_typec_register_thunderbolt(port, &desc); if (IS_ERR(amode)) return PTR_ERR(amode);