From patchwork Wed Oct 30 21:28:32 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: 13857200 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 464D6215C72 for ; Wed, 30 Oct 2024 21:29:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730323749; cv=none; b=OjdMOLjYvl8mITWT6Y0ze62kxigD1iV6LSGhmN/XGgdHthrN1zEsTs+p+TvLzoYKcI/RB5W/UuWxl0ty39ELwhscNx9eoc6GX3WzTH034PmIs6RgJ7OCuE0zS+tLSmxgs3xg80xUIQfefix+IEfBKOKdW5JoS4HtRMXnfJs+GCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730323749; c=relaxed/simple; bh=Gp9ZzmkgCLODIrJpltJ+wNHoXsorOGS3Dj3QSbhDYD4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qLr8xD2qcF6Xn8suYyKRXDDQZeE6cMvbHM68MQHmki3fa40OSVTW089J6Cmh0k6ogh1nTyiJSBZbKJ+6+GhPux1AZzvIqTFCcRBFKYOXz+SjNplCgUyWLz2b2VimfNZ8udTfJYZ/MgCXn912FBzAcz0lyYkihMzwoxmXMI6zt8w= 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=BQvvYXLh; arc=none smtp.client-ip=209.85.215.180 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="BQvvYXLh" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-7eae96e6624so278958a12.2 for ; Wed, 30 Oct 2024 14:29:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730323745; x=1730928545; 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=/PnhQeGNYnnhwKBdddOGJEQQVFTvtee1pyk4eZRIhl4=; b=BQvvYXLhJygYJWxjruZUpLq2/N8ctxIx63XR5bDMdV7LUd9rY9BYbfSwGuiHWKpPii tdU+PeT9Umi9EVcv7AojjkBxMiKR6y+vQeuLUMWNl5eMjRE7kawwMg8U7Dpu39zjw0ZT zF7FFUP8sp0bIY8kL4z2JZAENGzU7mOyB+E2s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730323745; x=1730928545; 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=/PnhQeGNYnnhwKBdddOGJEQQVFTvtee1pyk4eZRIhl4=; b=vY4kf2dXsKo1tARe/y7O1lykcsJtgrC1NkrXFsPB+KDHwZDTdKe/+AUgvZeGDDT+My 70fciKtwI37UNSBdE725yVjsB0kS226vqoaBo0O6Li/iyj7aR6JPTC3j0NOdzxYCFStD y9I1oDm8DTTRvTU4CKsQ/VIdgzL62VXJtRoz6qcnrk5u15UFaWHtSyCCUF5+tPMasdLH /HHFmCVMjWRk7fyg/vvJ73/gnnXN30o2KFMGoEuTw0z4iFxn+MoLOjwk+k7RbYChR36T IIOtPSr9lt2gvOlLznn3REcdQiP8Ip4/9ilAMTzyREAyatxMysMYesZ7KWqYr7n0LYpG LCCg== X-Forwarded-Encrypted: i=1; AJvYcCVzEMOXJsfk8IVEO+2viUiLKtDZRzdnMAziSaY0oemuGQUnSvQaDbOJ5w7m0FMCkBgiCZUmPPgZjDE=@vger.kernel.org X-Gm-Message-State: AOJu0Yyj17kQGTNyVdryDqi9/UWL0yzXvkJnDG7i+rwvK1n6Xfe/7uPA 1s3puFtZ0um3Hu9WudGNMOX5Sk1KYiOksvElvbgdE4zEbEopX2ZJFBUHEqPvYDSR53CJ5Nr9k64 = X-Google-Smtp-Source: AGHT+IFAEOrWR6hf5Xa/skswhh8HvyXXxaQsT/aXROLLL9EWagkwq2Yp2/4ahEp1oeI18PyRetfS9A== X-Received: by 2002:a05:6a20:9f43:b0:1d8:aadd:64f2 with SMTP id adf61e73a8af0-1d9a840a2abmr22924760637.22.1730323745542; Wed, 30 Oct 2024 14:29:05 -0700 (PDT) Received: from localhost (198.103.247.35.bc.googleusercontent.com. [35.247.103.198]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7ee45a0dfe2sm29950a12.83.2024.10.30.14.29.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Oct 2024 14:29:05 -0700 (PDT) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: dmitry.baryshkov@linaro.org, jthies@google.com, akuchynski@google.com, pmalani@chromium.org, Abhishek Pandit-Subedi , Benson Leung , Greg Kroah-Hartman , Guenter Roeck , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/7] usb: typec: Add driver for Thunderbolt 3 Alternate Mode Date: Wed, 30 Oct 2024 14:28:32 -0700 Message-ID: <20241030142833.v2.1.I3080b036e8de0b9957c57c1c3059db7149c5e549@changeid> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241030212854.998318-1-abhishekpandit@chromium.org> References: <20241030212854.998318-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org 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 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/platform/chrome/cros_ec_typec.c | 2 +- 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 | 3 +- 5 files changed, 322 insertions(+), 2 deletions(-) create mode 100644 drivers/usb/typec/altmodes/thunderbolt.c diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index c7781aea0b88..53d93baa36a8 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -499,7 +499,7 @@ static int cros_typec_enable_tbt(struct cros_typec_data *typec, } port->state.data = &data; - port->state.mode = TYPEC_TBT_MODE; + port->state.mode = USB_TYPEC_TBT_MODE; return typec_mux_set(port->mux, &port->state); } 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..8380b22d26a7 --- /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, USB_TYPEC_TBT_MODE }, + { } +}; +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..3ff82641f6a0 100644 --- a/include/linux/usb/typec_tbt.h +++ b/include/linux/usb/typec_tbt.h @@ -10,7 +10,7 @@ #define USB_TYPEC_TBT_SID USB_TYPEC_VENDOR_INTEL /* Connector state for Thunderbolt3 */ -#define TYPEC_TBT_MODE TYPEC_STATE_MODAL +#define USB_TYPEC_TBT_MODE TYPEC_STATE_MODAL /** * struct typec_thunderbolt_data - Thundebolt3 Alt Mode specific data @@ -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 Wed Oct 30 21:28:33 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: 13857201 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 290FF1E1A23 for ; Wed, 30 Oct 2024 21:29:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730323751; cv=none; b=FR6lg8iucigrV/8lA4ksm+yMJfXN4VJO66bHwShfF/2UdDwkRnECGS/qhRPFYi1T6n4AlUQNwpE2ySfRhwL5ksuVQoUv1jrdV51v3iC27ijRZnPFUbCDKCFgHLs1fDi/PmDMikL7bqG79AFAFB6clV0j3pvwTqZJ/Ssh0W5759U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730323751; c=relaxed/simple; bh=pmjvhjw4ANaGJaaJIPAfAMKeQBbfRAJ7IKjlQWEKmyQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RyPJ2BZ8bzRwSGWzEf4zc14WlqMZPRCUAUQa7ztJfM3cB/ulASW9LA5V2P/ytqeJURsnkXZDPK0YXhCk/lqhnIPbWXkFfOOaVjHHheYUA2zDpPlyM/rkIsp9yHoIHOq4nqkE02nlzAwlG1iruAvN7zA22fAFIBrH+qiaWv/TjFQ= 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=n+5wlwnL; arc=none smtp.client-ip=209.85.210.170 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="n+5wlwnL" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-71e4c2e36daso1019906b3a.0 for ; Wed, 30 Oct 2024 14:29:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730323748; x=1730928548; 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=MKi+NPRYmwJ2A38UY9R/topls2qQmTfhUwGCoXEdFfM=; b=n+5wlwnL51JeGpdUzmEOdLsoUSmXp/u1l7KD5Ei2qVQkSMpMIJ1G6rbtoMYYbChAGl 8BKffZXmXroVpd0OmyDuMhfoJCtNZaSsFT1N5QPZL1KB4btElOwpUBOkK16QhcOu3y1e vkPeyjAzfmFm04Z0NqB38BVkFQcWc08BnC06o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730323748; x=1730928548; 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=MKi+NPRYmwJ2A38UY9R/topls2qQmTfhUwGCoXEdFfM=; b=CGXjIMADG/9aZuOz1kNLvo1S+Zp+91TVCBQrdoHOSXCJB5JSziERwifGwsJrOhEoWf J9hnmjenMUfYUMLwE8hCDMN1C1oQ6PE61CxUkkt6N6dGaa6oesLlQBi6txFh0/56CYv8 tm+07CyGpi3U3AfBIg888yRyHlRNjXyos8KLGLJdeLoCBaqp+/V0Ol4eMFZ9QNDjdEug XoVCsRGuG7aHqh9zRwrVutqmO6V0nsJfScq4A77BZrkM1rDs3Q4Jq11BUdclVa6tBrY3 wCBGlz5fLksithRodxxu8dGvd7loclxgmcpcBW0yVpn9FquGxXr4ZYOprnxp82SDim3j 1GtQ== X-Forwarded-Encrypted: i=1; AJvYcCVwHwfOJ8Na5pI20G2pAbPk57M00hikzq7vO8rZPpy0h8mAu5ZDHzdIUrjdfRV4nQ9eJ36hHQArO/4=@vger.kernel.org X-Gm-Message-State: AOJu0YzpxxLZtLiL69Q5PPx260xEHMed7Wz+fybxjU3vqP7ccVAOfjpd 3VkJ1wOdNJrzTQDeEz3L3CjiswelpJkmNqCnonFBac5V+bLFW0BQxJdyKKVJVA== X-Google-Smtp-Source: AGHT+IFzsx/2nziVzAA3aVi8a7q+nlWhb2DtVPBhQAAbTqwOb89dC8jOYaMI05+lY1hky0mFR4od6w== X-Received: by 2002:a05:6a00:2383:b0:71e:735f:692a with SMTP id d2e1a72fcca58-720bd1a046amr139794b3a.14.1730323748323; Wed, 30 Oct 2024 14:29:08 -0700 (PDT) Received: from localhost (198.103.247.35.bc.googleusercontent.com. [35.247.103.198]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7ee452979e4sm36885a12.9.2024.10.30.14.29.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Oct 2024 14:29:08 -0700 (PDT) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: dmitry.baryshkov@linaro.org, jthies@google.com, akuchynski@google.com, pmalani@chromium.org, Abhishek Pandit-Subedi , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/7] usb: typec: Only use SVID for matching altmodes Date: Wed, 30 Oct 2024 14:28:33 -0700 Message-ID: <20241030142833.v2.2.Ie0d37646f18461234777d88b4c3e21faed92ed4f@changeid> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241030212854.998318-1-abhishekpandit@chromium.org> References: <20241030212854.998318-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org 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. When searching for altmodes, it doesn't make sense to use the mode as a criteria since it could be any value depending on the enumeration order of the driver. Signed-off-by: Abhishek Pandit-Subedi Reviewed-by: Heikki Krogerus --- Changes in v2: - Update altmode_match to ignore mode entirely - Also apply the same behavior to typec_match drivers/usb/typec/bus.c | 3 +-- drivers/usb/typec/class.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/usb/typec/bus.c b/drivers/usb/typec/bus.c index aa879253d3b8..a5cb4bbb877d 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; } diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index bd41abceb050..85494b9f7502 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -237,7 +237,7 @@ 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) From patchwork Wed Oct 30 21:28:34 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: 13857202 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.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 BF75921765A for ; Wed, 30 Oct 2024 21:29:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730323753; cv=none; b=Q2fcmzj5fyeUxFZmIjhlaOepuQqjYM3y0dnGoeB4Q5W+zHJjguM5Ze3EgI2el/v9Kx4cXQ8b7cVpcZRh294Al5hEDwL3V4hJlglAth2XOOoqAR8ekBVDiY42gRw6h/vbk0b4qZ+qbTnt6JgC11B6CENDSWfw34j6LL/nn7MT2FU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730323753; c=relaxed/simple; bh=wmoTH6RDMvSrIitc+RyQ8z5eGj/rSYnzG0QzoUpsshA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GrpJWtiT0S+WfboorblLXqG4AOED7GgkCxQfgcyg9o/dvysudub30JNl1LH+ONawH/CUYGXEIaGrfl6uBdaGq6bAbtdJfvDVZXAXkrumapFvLY3qDpMteFkAGfXzuGVlRi1wbS5+INhuryC7deBU7de+Qvx+B3DKHxlEqtxC9O0= 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=ctwky1Bl; arc=none smtp.client-ip=209.85.215.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="ctwky1Bl" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-7ee11ff7210so270348a12.1 for ; Wed, 30 Oct 2024 14:29:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730323750; x=1730928550; 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=XcJ6rYdsw1OyRONz4zGVh02ld/8YsK6wUyzfWA/Y9e4=; b=ctwky1BlJ4LdpQj2KLWdI0KGmNxRPbAHE8a/a3hWCYzBGrdwimrLRrXaCdX5F6ikBz udRoPKJdO5MvENQcqF4UfT7GFuzLIDvWFCElxzrc5ZJ/o7rSkKcPBIRTbjYpH9z9HDyp A6TVM2uCy3+yg7GlLmwLvqOKvrVlAkPZ28MZI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730323750; x=1730928550; 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=XcJ6rYdsw1OyRONz4zGVh02ld/8YsK6wUyzfWA/Y9e4=; b=NBgKcfTPEcqM7SDbc19SXA534Kxk7uEqjbpl2zw3LZYiPUCWgtNPxUbafN2zMzuC4W Bo6LXhJxhVDbIpf3p6R1pamSQPdHQ54tUCIm0XmCDDy7PJCni3wqqKTvC6SKofDmOoFU LG+OmqqbWEnA7yQmvAYd9V3Vpqum6kEHIrx24oFyy5uSV8nagpb7XPGPgBxFk3e24ZFz qHelILni7g0eYQA+go2EEGiL/UBYKQvrx8mdIsKnZ9iI2RPWFYIAl/n7jsBA0lT58ORK SgJVcaGZExY/BEtayxxLUlgz1vPiKb7obK/DiCaINbx4Q2NrxtwXMC+uc7RVxz9wAagJ FgZA== X-Forwarded-Encrypted: i=1; AJvYcCUqxvvpflv5WQ5FbYOhyTGmlRGmXlaD143adNUPTY4uXDkZYdhTzPanqLhjHBmQ2jKtd9mb80BxzJQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzsQiZcwiSDPxXr1AhuVe9WS9liTdylX+c5zm1todLEMl5goKwf 5r49G5lwArmsvXJt6CkOBA2KarrsaFFfsZUFwC4NNhjbgPzjt6FRbEuFwkmrYQ== X-Google-Smtp-Source: AGHT+IHxkwiPUzOjIQu7smhe9Fr6RzmKM9yzxhOhZb+U58++hpr/bZMA54sfwCVhxTtriq/TmBMRSA== X-Received: by 2002:a05:6a21:3984:b0:1d8:a759:524d with SMTP id adf61e73a8af0-1d9a83d60cfmr20785025637.18.1730323750045; Wed, 30 Oct 2024 14:29:10 -0700 (PDT) Received: from localhost (198.103.247.35.bc.googleusercontent.com. [35.247.103.198]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-720bc2eb76esm76989b3a.154.2024.10.30.14.29.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Oct 2024 14:29:09 -0700 (PDT) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: dmitry.baryshkov@linaro.org, jthies@google.com, akuchynski@google.com, pmalani@chromium.org, Abhishek Pandit-Subedi , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [PATCH v2 3/7] usb: typec: Auto enter control for alternate modes Date: Wed, 30 Oct 2024 14:28:34 -0700 Message-ID: <20241030142833.v2.3.I439cffc7bf76d94f5850eb85980f1197c4f9154c@changeid> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241030212854.998318-1-abhishekpandit@chromium.org> References: <20241030212854.998318-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add controls for whether an alternate mode is automatically entered when a partner connects. The auto_enter control is only available on ports and applies immediately after a partner connects. The default behavior is to enable auto enter and drivers must explicitly disable it. Signed-off-by: Abhishek Pandit-Subedi --- (no changes since v1) Documentation/ABI/testing/sysfs-bus-typec | 9 +++++++ drivers/usb/typec/altmodes/displayport.c | 6 +++-- drivers/usb/typec/altmodes/thunderbolt.c | 3 ++- drivers/usb/typec/class.c | 31 +++++++++++++++++++++++ include/linux/usb/typec.h | 2 ++ include/linux/usb/typec_altmode.h | 2 ++ 6 files changed, 50 insertions(+), 3 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-bus-typec b/Documentation/ABI/testing/sysfs-bus-typec index 205d9c91e2e1..f09d05727b82 100644 --- a/Documentation/ABI/testing/sysfs-bus-typec +++ b/Documentation/ABI/testing/sysfs-bus-typec @@ -12,6 +12,15 @@ Description: Valid values are boolean. +What: /sys/bus/typec/devices/.../auto_enter +Date: September 2024 +Contact: Heikki Krogerus +Description: + Controls whether a mode will be automatically entered when a partner is + connected. + + This field is only valid and displayed on a port. Valid values are boolean. + What: /sys/bus/typec/devices/.../description Date: July 2018 Contact: Heikki Krogerus diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c index 2f03190a9873..62263f1d3a72 100644 --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -767,8 +767,10 @@ 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); + if (port->auto_enter) { + 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 8380b22d26a7..181892bf1225 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,7 @@ 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)) { + if (port->auto_enter && 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 85494b9f7502..e74f835c6859 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -403,6 +403,31 @@ static ssize_t active_store(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RW(active); +static ssize_t +auto_enter_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct typec_altmode *alt = to_typec_altmode(dev); + + return sprintf(buf, "%s\n", alt->auto_enter ? "yes" : "no"); +} + +static ssize_t auto_enter_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t size) +{ + struct typec_altmode *adev = to_typec_altmode(dev); + bool auto_enter; + int ret; + + ret = kstrtobool(buf, &auto_enter); + if (ret) + return ret; + + adev->auto_enter = auto_enter; + + return size; +} +static DEVICE_ATTR_RW(auto_enter); + static ssize_t supported_roles_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -446,6 +471,7 @@ static DEVICE_ATTR_RO(svid); static struct attribute *typec_altmode_attrs[] = { &dev_attr_active.attr, + &dev_attr_auto_enter.attr, &dev_attr_mode.attr, &dev_attr_svid.attr, &dev_attr_vdo.attr, @@ -461,6 +487,10 @@ static umode_t typec_altmode_attr_is_visible(struct kobject *kobj, if (!adev->ops || !adev->ops->activate) return 0444; + if (attr == &dev_attr_auto_enter.attr) + if (!is_typec_port(adev->dev.parent)) + return 0; + return attr->mode; } @@ -564,6 +594,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.auto_enter = !desc->no_auto_enter; } sprintf(alt->group_name, "mode%d", desc->mode); diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index d616b8807000..5336b7c92ca4 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -139,6 +139,7 @@ int typec_cable_set_identity(struct typec_cable *cable); * @svid: Standard or Vendor ID * @mode: Index of the Mode * @vdo: VDO returned by Discover Modes USB PD command + * @no_auto_enter: Only for ports. Disables auto enter which is default behavior. * @roles: Only for ports. DRP if the mode is available in both roles * * Description of an Alternate Mode which a connector, cable plug or partner @@ -148,6 +149,7 @@ struct typec_altmode_desc { u16 svid; u8 mode; u32 vdo; + bool no_auto_enter; /* Only used with ports */ enum typec_port_data roles; }; diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_altmode.h index b3c0866ea70f..ab7c3ebe4926 100644 --- a/include/linux/usb/typec_altmode.h +++ b/include/linux/usb/typec_altmode.h @@ -18,6 +18,7 @@ struct typec_altmode_ops; * @mode: Index of the Mode * @vdo: VDO returned by Discover Modes USB PD command * @active: Tells has the mode been entered or not + * @auto_enter: Tells whether to auto-enter mode (only valid for port mode). * @desc: Optional human readable description of the mode * @ops: Operations vector from the driver * @cable_ops: Cable operations vector from the driver. @@ -28,6 +29,7 @@ struct typec_altmode { int mode; u32 vdo; unsigned int active:1; + unsigned int auto_enter:1; char *desc; const struct typec_altmode_ops *ops; From patchwork Wed Oct 30 21:28:35 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: 13857203 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.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 443C9217902 for ; Wed, 30 Oct 2024 21:29:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730323754; cv=none; b=VOxqRCWlljC0pX6YG3UaT+6vBxieh3/jZe8mCb5ZiRMaytmKeQTypvmRzJFiaS7ojG9eg5PPWkne3IA/kwtVtuwv0kiX1v6mtw+X9/5AwAVTCmEeMt1T3Wkk6z/u932a0TkCFo+Xr7g2q9odXDIjpwJ10/CJZEgDWM7B1UVGoxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730323754; c=relaxed/simple; bh=0F0599rOKHxfQvf7XtskB5Mt/xYLB1cPEJKxRmRO258=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TB/mzZkiAvPuKPMXBJ8cUPC9xRAeJKqLSjKjWDyJ5nMUrPzDPvjG558YKqPYhlXykrDKUaw7w8wRTyc7UcjprKlRu7ppHG6DbVNEhCg5huN4QkansIGTmwLhwJjY0WMNVAkx7sTwlBzkspEl0IretKkFtJIFPZCTqMzU+KuCtng= 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=XAlGnXJa; arc=none smtp.client-ip=209.85.216.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="XAlGnXJa" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2e2e050b1c3so1108835a91.0 for ; Wed, 30 Oct 2024 14:29:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730323751; x=1730928551; 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=dCXmBmJO0w4Chs93Xm3BeF6wgI3Tb8Gd24Xh4PooSyo=; b=XAlGnXJaz2B2u2uBBL2Q66lBVA+GuGGlDQ/1nTaCdzAlGXPjluXtYbWs542W2smDXq MjxyKgWrCxihXAwRi3bExtyknkClOcfEJwrukXnBh/nuKjIc5jV+LJFRtmtnIhvHJS0O TmQrKbjTXFyom9abMo1zoPiBHn4+FQT95yCeM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730323751; x=1730928551; 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=dCXmBmJO0w4Chs93Xm3BeF6wgI3Tb8Gd24Xh4PooSyo=; b=K6iTELel7bErDdb2FoX0denAt+jTMcfOnvq31pqjKTGJuW3Pr2ESJl4ude5+GfTAeS MkVyN8IdzjyqvTaYdkTiF8bU+dpdrjN3ptZve1ybknGXwEkZaBuYtPh5RTqHDihRsx1p cuyPQgWByczeqDAGG+UG5e6QUR0+B7lWG7iGdkRQVce8qj6flfUG7hJpYYUKlf5qVJaq vJiRwW9bKW2rCz1HKcp9ojIPc5zAlOTMdTnunGxrnBDy1XwPKaJhp9dcuRgmrVx9yikQ AtD+FF0uiy+cgRkd6pikeYkGtoQbX3Aviy3+c7hQhgJ/mz8pGxgZQ7+V7VgfvRxnkypH hyvw== X-Forwarded-Encrypted: i=1; AJvYcCWJ5cCtX0VEHNdRz8L4NpSBjW907A0i2xPul207CdnyoR5891EoopXF15Lw8BJ14/ER5zRC3qsExXE=@vger.kernel.org X-Gm-Message-State: AOJu0YwGP2LaDaaNZUL1jwnkb8mlknSF4pyVQpK/Z4UCfT93CzNOD6eV suDhaGxNrp8ryWdRjNF51iep878TcwHLikVt7DFvShjDxHg32Zg/9otmr5h57A== X-Google-Smtp-Source: AGHT+IHBRIrLXFaaBv6UUOjhdIM7tK6tsQj3oOcxvxYkMmGaYVMHAjdBu/AmhHynbAxlaCZw2kdHoQ== X-Received: by 2002:a17:90b:1b4a:b0:2e9:20d8:414c with SMTP id 98e67ed59e1d1-2e93e0139a2mr257317a91.5.1730323751676; Wed, 30 Oct 2024 14:29:11 -0700 (PDT) Received: from localhost (198.103.247.35.bc.googleusercontent.com. [35.247.103.198]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2e93daac455sm141073a91.19.2024.10.30.14.29.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Oct 2024 14:29:11 -0700 (PDT) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: dmitry.baryshkov@linaro.org, jthies@google.com, akuchynski@google.com, pmalani@chromium.org, Abhishek Pandit-Subedi , Benson Leung , Guenter Roeck , linux-kernel@vger.kernel.org Subject: [PATCH v2 4/7] platform/chrome: cros_ec_typec: Update partner altmode active Date: Wed, 30 Oct 2024 14:28:35 -0700 Message-ID: <20241030142833.v2.4.I083bf9188947be8cb7460211cfdf3233370a28f6@changeid> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241030212854.998318-1-abhishekpandit@chromium.org> References: <20241030212854.998318-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org 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 53d93baa36a8..0c8db11bd8a4 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 Wed Oct 30 21:28:36 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: 13857205 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 2FFF5218933 for ; Wed, 30 Oct 2024 21:29:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730323757; cv=none; b=uKerYeF8bmXAfODq/u96PIcXx1wNlAduux1TDm2xLabcqPQa4GBJ1YXYkrS/JZ519aXrIwq6oVc4bV+UquR1CQwXREeR+wvrKY53+c7kl90NYwOTyQkrQPZGnk+GN7Ay5g4f3iXr25DOTF2SRckNo0PKTbxKR3aS3fRyT/55YBs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730323757; c=relaxed/simple; bh=uMeysR189IthOyETjVc8vjImbzvEmWjmALZpdXtfhNg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ties12qd8e9c+f+CxbfzmGo7Dz5CfHirs00Zk/8SscQ7vFQ+S9jEX/HwCj8njRCSEOE5nP5l7JzBf/3vyq0LWn939DlzrMbAyQuL/ubPL5cpZiGFxneKQ6qAueA/JZRDHDXw98pbx/YddEkcNHf4yrn68H/qeSmOuMUIyD+EG/A= 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=oHK1j9A4; arc=none smtp.client-ip=209.85.210.180 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="oHK1j9A4" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-71e7086c231so221116b3a.0 for ; Wed, 30 Oct 2024 14:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730323753; x=1730928553; 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=G5F33qV6ofAibcr8moJJ8wWx5Tp3luAqpEsJU6dkvkI=; b=oHK1j9A4dF0/7/GdsnB9Oxk2PLibwVtBJRlD46y/jLsSW2h/6vyQpt8GCQP5yFdrJY IJQfeYgB94cLCtVA60nwpJtphM3P3Oim+P6Pzgy8zaF/5FdQ9FWSDc1908YmJG+ZHoof OQLi2c39iBI7aMM4AwV1RePsi4Qu4H/qvzMtU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730323753; x=1730928553; 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=G5F33qV6ofAibcr8moJJ8wWx5Tp3luAqpEsJU6dkvkI=; b=E8XYIP+6deT0mIoAAk8mplQz12mYD3Egt/y0dUYp6o8RPmS7B2P8gglwj6TurjhP3K DelYHRroMM0VAuVX1QLEjse/huh1BD5ARTqCBCvcoHHHFkGFcrbAqg0UYroYVcTdOxcU z9meBc5a22j8kVOU+eQBPJOB9ovzJTVVl5CmCXGMhCMpoWQtdJGyI0ljuQwlcwv9/5uu u+vErk1pLZcmSlqEXAMgROfTclus6btxTZz5sqCyqX2yHZHgtkCPnuA2xFJ7oUgq7Od6 UnTHLc8W0UgzNrtH1f7Auj1VmIi67+pr1uMPxW89A2u/b7DivViq++jo5AADv3IPFNdo wiNw== X-Forwarded-Encrypted: i=1; AJvYcCV/8kZcTvr9wReXGbftyeshVk9oY+uVzsl6jAxrfSXL/Zlq5H3myz336ztfzZje1qz0zw9PcHGpHic=@vger.kernel.org X-Gm-Message-State: AOJu0YwgxpRQUwk5afu/J6U6q4BvUCDzptvHKZQjJDVKxr4hgRaE4Hwk DIFoiTwr0otYB6S9uUYupWszvSHBh7amjsvnKKvEu6WPepsV+lZnGZSHlX3tQQ== X-Google-Smtp-Source: AGHT+IG3h/s8BEHneIECR74Vhcotk/tJPVp1H5/oohF4H43/iSeH9VOVd5Em8mOeT0ufiALdl9qWUQ== X-Received: by 2002:a05:6a00:80c:b0:71e:5d1d:1aa0 with SMTP id d2e1a72fcca58-72062f4e529mr24388059b3a.6.1730323753267; Wed, 30 Oct 2024 14:29:13 -0700 (PDT) Received: from localhost (198.103.247.35.bc.googleusercontent.com. [35.247.103.198]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-720bc31b40csm74200b3a.209.2024.10.30.14.29.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Oct 2024 14:29:12 -0700 (PDT) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: dmitry.baryshkov@linaro.org, jthies@google.com, akuchynski@google.com, pmalani@chromium.org, Abhishek Pandit-Subedi , Benson Leung , Guenter Roeck , linux-kernel@vger.kernel.org Subject: [PATCH v2 5/7] platform/chrome: cros_ec_typec: Displayport support Date: Wed, 30 Oct 2024 14:28:36 -0700 Message-ID: <20241030142833.v2.5.I142fc0c09df58689b98f0cebf1c5e48b9d4fa800@changeid> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241030212854.998318-1-abhishekpandit@chromium.org> References: <20241030212854.998318-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org 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 v2: - Refactored displayport into cros_typec_altmode.c to extract common implementation between altmodes MAINTAINERS | 3 + drivers/platform/chrome/Makefile | 3 +- drivers/platform/chrome/cros_ec_typec.c | 13 +- drivers/platform/chrome/cros_ec_typec.h | 1 + drivers/platform/chrome/cros_typec_altmode.c | 277 +++++++++++++++++++ drivers/platform/chrome/cros_typec_altmode.h | 34 +++ 6 files changed, 329 insertions(+), 2 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 e9659a5a7fb3..de99bcbda7d4 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..8b007404c024 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -17,8 +17,9 @@ obj-$(CONFIG_CROS_EC_RPMSG) += cros_ec_rpmsg.o 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 +cros-ec-typec-objs := cros_ec_typec.o cros_typec_vdm.o cros_typec_altmode.o 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 0c8db11bd8a4..7997e7136c4c 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,16 @@ 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; + +#if !IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE) typec_altmode_set_drvdata(amode, port); amode->ops = &port_amode_ops; +#endif /* * Register TBT compatibility alt mode. The EC will not enter the mode @@ -575,6 +580,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 +1263,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..af2f077674f1 --- /dev/null +++ b/drivers/platform/chrome/cros_typec_altmode.c @@ -0,0 +1,277 @@ +// 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_dp_data { + struct typec_displayport_data data; + + bool configured; + bool pending_status_update; +}; + +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; + + union am_specific { + struct cros_typec_dp_data dp; + } am_data; +}; + +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_altmode_data *adata = typec_altmode_get_drvdata(alt); + + 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: + adata->am_data.dp.data.conf = *data; + adata->header |= VDO_CMDT(CMDT_RSP_ACK); + adata->am_data.dp.configured = true; + schedule_work(&adata->work); + break; + case DP_CMD_STATUS_UPDATE: + adata->am_data.dp.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_altmode_data *adata = + typec_altmode_get_drvdata(altmode); + + if (!adata->am_data.dp.pending_status_update) { + dev_dbg(&altmode->dev, + "Got DPStatus without a pending request"); + return 0; + } + + if (adata->am_data.dp.configured && adata->am_data.dp.data.conf != data->conf) + dev_dbg(&altmode->dev, + "DP Conf doesn't match. Requested 0x%04x, Actual 0x%04x", + adata->am_data.dp.data.conf, data->conf); + + adata->am_data.dp.data = *data; + adata->am_data.dp.pending_status_update = false; + adata->header |= VDO_CMDT(CMDT_RSP_ACK); + adata->vdo_data = &adata->am_data.dp.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 = USB_TYPEC_DP_SID; + data->mode = USB_TYPEC_DP_MODE; + + data->am_data.dp.configured = false; + 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 Wed Oct 30 21:28:37 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: 13857204 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.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 64579217902 for ; Wed, 30 Oct 2024 21:29:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730323757; cv=none; b=SH0VsL2JqHGKsIh5lQL2BxX8aX6LlbxKgQlBlTKSw7ArlZhOHVE2A1wtMpL+uz0veXHvrsv7Ed+R0Ifl/HSzMY5fVIFcu8rdJUjbpWW+/jskwWTXaHpLAjHHXBac+zcTHzCgM4eyjZLRJNChpAtGV5CIp8slBP2vGpY6O2NAh/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730323757; c=relaxed/simple; bh=omExQ4fXBrGKFkhUOcF2QtIVYwoNMUYC+ZmXtt0yiTQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GBY0epEsINKODpFOs88XWV5EzZ7ilRTmBGiUm/EHbHrMEIaRoo9kWenYuNnEs7Hul8OCIdpk6BGpbfZNueMMl8JDXoiz1z4+LGVOip1GoT6BaWSLXdH+LncQcNHWK3IGiAzI1TYgAN7ryKuiRcV0Py3uXL8Y7bSgpa4ui6zCXAM= 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=esPjuJPf; arc=none smtp.client-ip=209.85.216.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="esPjuJPf" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2e2e23f2931so211847a91.0 for ; Wed, 30 Oct 2024 14:29:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730323755; x=1730928555; 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=RPKYpsefWRFNcyZV29jn0Qpqfxxh2cQB2XHzcOA2LTA=; b=esPjuJPfrX1guNAB7S9K09gT+9+K9OJlBWiboTexq4kTU6SRitLXKyfiPoGNml3cHy vqE5Lqvrzi9nku2Pn0ib5VJOAEzI7H7FQmYAo2OSYMR2zUP2DMpbOw/arDUE7hMU32Qk V7uSNWpzAlHc2M+TF9xZQ5CLdMn10AQNMsinY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730323755; x=1730928555; 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=RPKYpsefWRFNcyZV29jn0Qpqfxxh2cQB2XHzcOA2LTA=; b=nKCTjwrEDKpTOS89lnCW73LVaKVTfsLYJTLn0tYipd3v/qSwZSinvvKGTfEA6hln9V G6Rmpa3uZn7nl27oBKet5IdWae0+2cJmHuhxIeuXMDE/C/zqz8V+s602sGKNtEol8y/b vhlbj8WRh0Im+dctrXy9YkavjHrADrnqWH9ZTtTR84sd0rNAb+3FXF4m0x6NeUXopV8a ZDKUUp7g+aMR8MErxfhWa5kXVvMIcRM7q7HEUFevkGoqUmab+1LOrqTD5E7xAUW1qKSQ 9O34mtRVmALC2Kgq9Hbwk5Kze+c99V0Ipu8ORMBGolYrV/AvT5FGkhxfpb1VquX88L77 93jA== X-Forwarded-Encrypted: i=1; AJvYcCWCjqEpmV48J4V9qYs4ivEIbaAGmKo9F3f88qS5t+k7yziYoi1oz1Vw+j1wF7J1TnqX4IwQ8jwfy8k=@vger.kernel.org X-Gm-Message-State: AOJu0YyEocIflNvW+bfkcmvkLbqcLOZuBRsrb9AQzHo2ShxDfVQhrBxv cU1ZMYsVrOfbebC/ZGM6Hm1u7q6Gq8xuO2iJIdG2NLqeHAYoO890GBf0xWgocA== X-Google-Smtp-Source: AGHT+IFlY/igGtC8ACf1t1ncIipTUUeVB1dKonJWB7PHygnEcbPHAco/gt4xLpUFAPp3zDZE2VDH2g== X-Received: by 2002:a17:90a:e295:b0:2e2:e2f1:aee with SMTP id 98e67ed59e1d1-2e8f1077416mr18096749a91.22.1730323754798; Wed, 30 Oct 2024 14:29:14 -0700 (PDT) Received: from localhost (198.103.247.35.bc.googleusercontent.com. [35.247.103.198]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2e92fbfa8a4sm2365726a91.53.2024.10.30.14.29.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Oct 2024 14:29:14 -0700 (PDT) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: dmitry.baryshkov@linaro.org, jthies@google.com, akuchynski@google.com, pmalani@chromium.org, Abhishek Pandit-Subedi , Benson Leung , Guenter Roeck , linux-kernel@vger.kernel.org Subject: [PATCH v2 6/7] platform/chrome: cros_ec_typec: Thunderbolt support Date: Wed, 30 Oct 2024 14:28:37 -0700 Message-ID: <20241030142833.v2.6.Ic61ced3cdfb5d6776435356061f12307da719829@changeid> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241030212854.998318-1-abhishekpandit@chromium.org> References: <20241030212854.998318-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org 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 v2: - Refactored thunderbolt support into cros_typec_altmode.c drivers/platform/chrome/cros_ec_typec.c | 29 ++++--- drivers/platform/chrome/cros_typec_altmode.c | 85 ++++++++++++++++++++ drivers/platform/chrome/cros_typec_altmode.h | 14 ++++ 3 files changed, 116 insertions(+), 12 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index 7997e7136c4c..3e043b1c1cc8 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -304,21 +304,26 @@ static int cros_typec_register_port_altmodes(struct cros_typec_data *typec, typec_altmode_set_drvdata(amode, port); amode->ops = &port_amode_ops; #endif - /* * 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 = TYPEC_ANY_MODE; + amode = cros_typec_register_thunderbolt(port, &desc); + if (IS_ERR(amode)) + return PTR_ERR(amode); + port->port_altmode[CROS_EC_ALTMODE_TBT] = amode; + +#if !IS_ENABLED(CONFIG_TYPEC_TBT_ALTMODE) + typec_altmode_set_drvdata(amode, port); + amode->ops = &port_amode_ops; +#endif + } 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 af2f077674f1..6cb1e1320d6c 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" @@ -71,6 +72,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; @@ -198,6 +201,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(USB_TYPEC_TBT_SID, 1, svdm_version, cmd); + adata->header |= VDO_OPOS(USB_TYPEC_TBT_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) { @@ -206,6 +256,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; } @@ -275,3 +328,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 = USB_TYPEC_TBT_SID; + data->mode = USB_TYPEC_TBT_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..c71568314e3f 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 +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 Wed Oct 30 21:28:38 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: 13857206 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 DF803218958 for ; Wed, 30 Oct 2024 21:29:16 +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=1730323759; cv=none; b=gi9Kqj4g/3PYWDJH0keFP7LO/eOcvZgN2Nntl/e+X0R8rYKtI0K9xud4rIh4OBkW0JZ+ox18uYoRWrP0PD7sLnaT1hBu0Mb+gOX4r9yRGFxkqWNIoBYzFRMLv9AnJgzHV8/hZocsr3YkVi1DnANRuNWsCwiRg0szyPyF8rk/sts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730323759; c=relaxed/simple; bh=hAp/Wgn9qETJ9JtmrJOl57caWyJEtC39CrlS/6VnGMs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cxwUBQ5ST4fGqmI1cVGnCdEh4DyMrVERrQG0C+dtctfM2APYV1y4x/2L7VoYdNMIYwUXSZVpH9HtAy8zVGfsJYGxAco9e7sit0NvraMf2vPNIjH2MO5M7KNMIkwEL2tFemeVZ7MVLrE6V/8Jefn7ZYK/iWza3xdOekB4hwNfTI4= 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=fJKXZMMo; 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="fJKXZMMo" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-20cb89a4e4cso2486915ad.3 for ; Wed, 30 Oct 2024 14:29:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730323756; x=1730928556; 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=p1LFW748m48R3d4nGBRyW7y9JsiXUpIXaqKR2jh3vhg=; b=fJKXZMMoHhvpokEchR1lVDqSuAxz4eWJGDhOaTZGy006iHjzUHfISO0faYL1jRof1Z HON2I0G0i8OpZf9P688gDiL4P4s5xnu1/YEapLu3NEL9sY0jK5bxhr3sMHNqF1j1YZbG V3Ga4uL76reu89/D9+w5SFlETWmpCeWH8PJA4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730323756; x=1730928556; 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=p1LFW748m48R3d4nGBRyW7y9JsiXUpIXaqKR2jh3vhg=; b=Lr2l4X33178LI1Uj0k61nJzbPEQ8a7/9Y8i+N8ZzvY0w4ke4/IPQ6syUd8giiSzheB rNVGNQdok6YdeD/1TSS22j8osuNuqrZ4Uaq7QZEv5+GxLbpf7XpcRllJhM5pxcnoZbpF N/va7hwrpbW8Wrmc/2qbDx9HrZwO0g49TV8w8WR2qIxY7sTan+JrW0cFYPfoRWzu4u0s 4EPHNdvEBA+BYp+79cuhuqcgR12G1admMbYSPLUM94gb2EciLxPA8J8xvmvS+xz/UIPz RfswMrVmLRWDjz+58PS2JvFtD9QfVsnpABOEmhHmfnoWqeGbugYHraKW6xGbbC6evlgj a2AA== X-Forwarded-Encrypted: i=1; AJvYcCVzbzK3Tdx7dqRbG59HPwFRlpyZRAJWsPf1fbs/zkrRFXg7snO+3sw+QGosiJBvM94EzNgYNiqwiYk=@vger.kernel.org X-Gm-Message-State: AOJu0Yy77wzULfM/4/jCl9bfgN45hWyYtUo0uUhBXC0pAO34XMDS4g6/ l6Gl7nt21PZKXFlDTPxL87Xdh4NA8qDXVqBQ+Heo5YMjdYcqVW0uw9aRoWtm2w== X-Google-Smtp-Source: AGHT+IH/KrpwE9PQHVPUqWJzTKYOAjHoclvbrW0UAtqgCiIc5SyQ/Ee9JadYFBZqNKDKLFyOZzsbDA== X-Received: by 2002:a17:902:d544:b0:20c:7181:51c7 with SMTP id d9443c01a7336-210c6c8ff93mr235487335ad.52.1730323756367; Wed, 30 Oct 2024 14:29:16 -0700 (PDT) Received: from localhost (198.103.247.35.bc.googleusercontent.com. [35.247.103.198]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-211057d833fsm335115ad.261.2024.10.30.14.29.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Oct 2024 14:29:16 -0700 (PDT) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: dmitry.baryshkov@linaro.org, jthies@google.com, akuchynski@google.com, pmalani@chromium.org, Abhishek Pandit-Subedi , Benson Leung , Guenter Roeck , linux-kernel@vger.kernel.org Subject: [PATCH v2 7/7] platform/chrome: cros_ec_typec: Disable tbt auto_enter Date: Wed, 30 Oct 2024 14:28:38 -0700 Message-ID: <20241030142833.v2.7.Ic14738918e3d026fa2d85e95fb68f8e07a0828d0@changeid> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241030212854.998318-1-abhishekpandit@chromium.org> References: <20241030212854.998318-1-abhishekpandit@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org 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 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 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index 3e043b1c1cc8..aadd2704e445 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -313,7 +313,8 @@ static int cros_typec_register_port_altmodes(struct cros_typec_data *typec, if (typec->ap_driven_altmode) { memset(&desc, 0, sizeof(desc)); desc.svid = USB_TYPEC_TBT_SID; - desc.mode = TYPEC_ANY_MODE; + desc.mode = USB_TYPEC_TBT_MODE; + desc.no_auto_enter = true; amode = cros_typec_register_thunderbolt(port, &desc); if (IS_ERR(amode)) return PTR_ERR(amode);