From nobody Sun Nov 24 02:32:36 2024 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.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 40B37194AD6 for ; Thu, 7 Nov 2024 19:31:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007904; cv=none; b=pR8hZAR1E9s0MRPX7sowSsKQERkeBEkuQXsRaAkeSBtntMgFkqEfKbeyYeHBTRbHIBj+xqx5MWfuvgXvgp40QswcPCAMMkHwM7XsfHDoRyqIFb59DpCViLvD6YKBXwaOVQn8gGLp3YoHECLVFke4gGIW1y3giwB56Vgh3qgFo54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007904; c=relaxed/simple; bh=ND8duXxeqpOMTaKR32jDF37o2wNYr8J9a6+AaXeIoic=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g5ec5ybUdzFDCBkmMb6P7xGTf6oGNCHaUqFrpHKqoA9wb2szwdGL0Lm7KJYy01RQMpOQxBlnKrlSbJMUQ3RGQ4PSnXZgVmImgBC7xwyzJRI4jh/ihYMfRe0b1UEqP6fs6jFD/W41R4mEAxm96nq+d/MWdOqymBenJ1F+elRmqGM= 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=J9yw/BRs; arc=none smtp.client-ip=209.85.215.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="J9yw/BRs" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7ee6edc47abso1011070a12.3 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=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=Ge6TnT0PL++7IUpHJoGRRwwYMPSP58r23n3kpkNEevA=; b=J9yw/BRslc9QTQAu86qviEViBgBF8Zw1ltJwOz/ogPboDfI2/tqhNX5uJVdb74jgik 3OTwzY/1udnVZafZmFwgNQfB5UiOB+YQPvnFq8RG2bujrM0ga6EHRyVgBK/XZ0Dy9s4Q GUBtmV81emOsGrgvPUMQ7bIZ8oLNOJ5FBsvfo= 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=szfPEDaRixeUNcPwpHbUJ1XIqM4OnjJhrUz/NdWLEy90kl5lZa/81DbPPFB4lJ+9d5 EG7YsOoGlV2mQ2wikMICuHtLb/pqbuQRztTqHMq3Wy9hvaZPNKuMWHgzNoKrQyvXr++a ks0zjhu3qEbrCCxDb7IQcKbJ9RGLRzRy52S87flSUgACKe6Jb6pnUG4seaP+4qbsFV/+ 6tQMrPzGP1MW4auaeQbjXYQr7kvxGYJRG1RJR3XCQ5ttLbtIAY4GKlDkzXFFVss3Lc9w Av3JunZJFpcq66l5doL1gcPFJxRz4mbrIk3ir/pJurn3N0uLviRjKTFPgzHZzXVOTmy7 kTww== X-Forwarded-Encrypted: i=1; AJvYcCVyKB8Z2gSHXp2Hs/O9pFYnTwvIT3tn2bv53v/j0QxtwW1D8RLrfTmB+Twp+2qND2oju7yykMOBTQUzNSg=@vger.kernel.org X-Gm-Message-State: AOJu0YxiOgdAFAwgT1w2rSLFzmDTbSQMRpklU3/zSvowmbbHMfHhH+Vd xU8OhTjH0/9w1UzPLRAnCFSi4YigpZ74ue0+G4KHH/YGC0t459Wq4O/CiTJurMfspFJDWES/LpQ = 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/a= ltmodes/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); =20 static const struct typec_device_id dp_typec_id[] =3D { - { 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/altmod= es/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 *a= lt) } =20 static const struct typec_device_id nvidia_typec_id[] =3D { - { 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; =20 for (id =3D drv->id_table; id->svid; id++) - if (id->svid =3D=3D altmode->svid && - (id->mode =3D=3D TYPEC_ANY_MODE || id->mode =3D=3D altmode->mode)) + if (id->svid =3D=3D altmode->svid) return 1; return 0; } @@ -470,8 +469,7 @@ static int typec_uevent(const struct device *dev, struc= t kobj_uevent_env *env) if (add_uevent_var(env, "MODE=3D%u", altmode->mode)) return -ENOMEM; =20 - return add_uevent_var(env, "MODALIAS=3Dtypec:id%04Xm%02X", - altmode->svid, altmode->mode); + return add_uevent_var(env, "MODALIAS=3Dtypec:id%04X", altmode->svid); } =20 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 *da= ta) if (!is_typec_altmode(dev)) return 0; =20 - return ((adev->svid =3D=3D id->svid) && (adev->mode =3D=3D id->mode)); + return (adev->svid =3D=3D id->svid); } =20 static void typec_altmode_set_partner(struct altmode *altmode) { struct typec_altmode *adev =3D &altmode->adev; - struct typec_device_id id =3D { adev->svid, adev->mode, }; + struct typec_device_id id =3D { adev->svid }; struct typec_port *port =3D typec_altmode2port(adev); struct altmode *partner; struct device *dev; diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-of= fsets.c index 9c7b404defbd..d3d00e85edf7 100644 --- a/scripts/mod/devicetable-offsets.c +++ b/scripts/mod/devicetable-offsets.c @@ -237,7 +237,6 @@ int main(void) =20 DEVID(typec_device_id); DEVID_FIELD(typec_device_id, svid); - DEVID_FIELD(typec_device_id, mode); =20 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, voi= d *symval, char *alias) return 1; } =20 -/* 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); =20 sprintf(alias, "typec:id%04X", svid); - ADD(alias, "m", mode !=3D TYPEC_ANY_MODE, mode); =20 return 1; } --=20 2.47.0.277.g8800431eea-goog From nobody Sun Nov 24 02:32:36 2024 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 A5092217F39 for ; Thu, 7 Nov 2024 19:31:43 +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=1731007905; cv=none; b=aObCFAsQqxEY87J3/2orwn6unNtj4kNolGmvx41j5A9YxjnA7Ltzux8gkhrIRtVU/LPUEX06ZQrWxnERWSjE7sqjHI9VrR820NP2sWxmvoiPC5bQpgpf2xORsVPPjhrlKivEGJhFsZrt8bg8ndkZ/CrJErlM8m/Xphvf7vBHocw= 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=kQhaXhTE; 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="kQhaXhTE" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-720be27db74so1108793b3a.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=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=83Suh2wjIyKRrMNGwMzdQsYr0nqcWo4eqvxd8u8DH7w=; b=kQhaXhTEUfJBe7s3Jds9KlHa1fcBK5mBVQFGB/3DCZ6zHUt4ehSpGSAhOwAxHqPgBh fRqvE2rgnnS+TPZKJLbb7ngMHCSbqpnT0FVSCtmSrL/3KKdF5jeEbnQy3znJ6jiP3DTb A+WSooq9A+m6i7oCV8gA13ALIjODVntP4Y4f0= 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=gIFv21pwpLc9yMlHqO1VILyaKi4w4+OqDGGsv5hsO1vvzzO9XbbdiE1tvcmy1Oj11f bkTDvBit4Qtq527LeM5HqOAF6pKE4v0dvoIzhWkicWo2MJpY/ezPQidZiAobkwYXkrml MzB86Ed7ChhnkTEy9mZ3hZaDzMS+7C0MjdkHsG5xYE898pR2SRkT0N//pcYMKYebX9ob x/6VJgkQI8ISqm3GvGvbFafBqNuO8aYzEaSGzQnfTBcPK+a1IT0SNEyqgSEpiWgBYXZA cocJQxFLh2LRIwQOEiSoTgDHyWc2qrCW6cDWjqpoRFgKp+LuX0p6aHt4wSxFcItS5XCp QrWg== X-Forwarded-Encrypted: i=1; AJvYcCVvWGok32aqPCciNyqz69z0llvUxtWMCMUgo9TG9RBf5KGkOuhIxCrjmONizGaXhmVHPj24aIU5lRTkhjM=@vger.kernel.org X-Gm-Message-State: AOJu0YyrTnuSsU/hG0MljzR/Cf9gdEh8DkhUCuyOaNEEx9Fr0ubFeCLU DnTw5UYr0oLQBsdkB4+aq4CHYT/rE/6SplWBMPDb0SfGY/gHEFEJ/unDtF+iGw== 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/altmode= s/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. =20 +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/altmod= es/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) +=3D typec_displayport.o typec_displayport-y :=3D displayport.o obj-$(CONFIG_TYPEC_NVIDIA_ALTMODE) +=3D typec_nvidia.o typec_nvidia-y :=3D nvidia.o +obj-$(CONFIG_TYPEC_TBT_ALTMODE) +=3D typec_thunderbolt.o +typec_thunderbolt-y :=3D thunderbolt.o diff --git a/drivers/usb/typec/altmodes/thunderbolt.c b/drivers/usb/typec/a= ltmodes/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 =3D tbt->plug[TYPEC_PLUG_SOP_P]; + u32 vdo; + + vdo =3D tbt->alt->vdo & (TBT_VENDOR_SPECIFIC_B0 | TBT_VENDOR_SPECIFIC_B1); + vdo |=3D tbt->alt->vdo & TBT_INTEL_SPECIFIC_B0; + vdo |=3D TBT_MODE; + + if (plug) { + if (typec_cable_is_active(tbt->cable)) + vdo |=3D TBT_ENTER_MODE_ACTIVE_CABLE; + + vdo |=3D TBT_ENTER_MODE_CABLE_SPEED(TBT_CABLE_SPEED(plug->vdo)); + vdo |=3D plug->vdo & TBT_CABLE_ROUNDED; + vdo |=3D plug->vdo & TBT_CABLE_OPTICAL; + vdo |=3D plug->vdo & TBT_CABLE_RETIMER; + vdo |=3D plug->vdo & TBT_CABLE_LINK_TRAINING; + } else { + vdo |=3D TBT_ENTER_MODE_CABLE_SPEED(TBT_CABLE_USB3_PASSIVE); + } + + tbt->enter_vdo =3D vdo; + return typec_altmode_enter(tbt->alt, &vdo); +} + +static void tbt_altmode_work(struct work_struct *work) +{ + struct tbt_altmode *tbt =3D container_of(work, struct tbt_altmode, work); + int ret; + + mutex_lock(&tbt->lock); + + switch (tbt->state) { + case TBT_STATE_SOP_P_ENTER: + ret =3D 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 =3D 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 =3D 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 =3D 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 =3D typec_altmode_get_drvdata(alt); + int cmd_type =3D PD_VDO_CMDT(hdr); + int cmd =3D PD_VDO_CMD(hdr); + + mutex_lock(&tbt->lock); + + if (tbt->state !=3D 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 =3D=3D tbt->plug[TYPEC_PLUG_SOP_P]) { + if (tbt->plug[TYPEC_PLUG_SOP_PP]) + tbt->state =3D TBT_STATE_SOP_PP_ENTER; + else + tbt->state =3D TBT_STATE_ENTER; + } else if (alt =3D=3D tbt->plug[TYPEC_PLUG_SOP_PP]) { + tbt->state =3D TBT_STATE_ENTER; + } else { + struct typec_thunderbolt_data data; + + data.device_mode =3D tbt->alt->vdo; + data.cable_mode =3D + tbt->plug[TYPEC_PLUG_SOP_P] ? + tbt->plug[TYPEC_PLUG_SOP_P] + ->vdo : + 0; + data.enter_vdo =3D tbt->enter_vdo; + + typec_altmode_notify(alt, TYPEC_STATE_MODAL, &data); + } + break; + case CMD_EXIT_MODE: + if (alt =3D=3D tbt->alt) { + if (tbt->plug[TYPEC_PLUG_SOP_PP]) + tbt->state =3D TBT_STATE_SOP_PP_EXIT; + else if (tbt->plug[TYPEC_PLUG_SOP_P]) + tbt->state =3D TBT_STATE_SOP_P_EXIT; + } else if (alt =3D=3D tbt->plug[TYPEC_PLUG_SOP_PP]) { + tbt->state =3D 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 !=3D 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 =3D 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 !=3D tbt->alt) + ret =3D -EPERM; + else if (activate) + ret =3D tbt_enter_mode(tbt); + else + ret =3D typec_altmode_exit(alt); + + mutex_unlock(&tbt->lock); + + return ret; +} + +static const struct typec_altmode_ops tbt_altmode_ops =3D { + .vdm =3D tbt_altmode_vdm, + .activate =3D tbt_altmode_activate +}; + +static int tbt_altmode_probe(struct typec_altmode *alt) +{ + struct tbt_altmode *tbt; + + tbt =3D 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 =3D alt; + + alt->desc =3D "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 =3D TBT_STATE_SOP_PP_ENTER; + else if (tbt->plug[TYPEC_PLUG_SOP_P]) + tbt->state =3D TBT_STATE_SOP_P_ENTER; + else + tbt->state =3D TBT_STATE_ENTER; + schedule_work(&tbt->work); + } + + return 0; +} + +static void tbt_altmode_remove(struct typec_altmode *alt) +{ + struct tbt_altmode *tbt =3D typec_altmode_get_drvdata(alt); + + for (int i =3D 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 =3D typec_altmode_get_drvdata(alt); + struct typec_altmode *plug; + + if (tbt->cable) + return true; + + /* Thundebolt 3 requires a cable with eMarker */ + tbt->cable =3D 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 =3D 0; i < TYPEC_PLUG_SOP_PP + 1; i++) { + plug =3D typec_altmode_get_plug(tbt->alt, i); + if (IS_ERR(plug)) + continue; + + if (!plug || plug->svid !=3D USB_TYPEC_VENDOR_INTEL) + break; + + plug->desc =3D "Thunderbolt3"; + plug->ops =3D &tbt_altmode_ops; + typec_altmode_set_drvdata(plug, tbt); + + tbt->plug[i] =3D plug; + } + + return true; +} + +static const struct typec_device_id tbt_typec_id[] =3D { + { USB_TYPEC_TBT_SID }, + { } +}; +MODULE_DEVICE_TABLE(typec, tbt_typec_id); + +static struct typec_altmode_driver tbt_altmode_driver =3D { + .id_table =3D tbt_typec_id, + .probe =3D tbt_altmode_probe, + .remove =3D tbt_altmode_remove, + .driver =3D { + .name =3D "typec-thunderbolt", + .owner =3D 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 { =20 #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) --=20 2.47.0.277.g8800431eea-goog From nobody Sun Nov 24 02:32:36 2024 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (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 1845121766D for ; Thu, 7 Nov 2024 19:31:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007909; cv=none; b=QEK7Egd2U4PYkYcNF7Qwn3iSLB7vQckwDpbOoLZCkPBDpjRWVHcfQSne3SP1SBhkpf5ZyrV8p0v137+gfjUjlV7gWknkJSCyuAL3ATttNM6qFX0GIoYsjd0naXBXlole+3mek/L3kfR8ZTHEF5a3YMQmXDRARUaX2zxLfM/Vtp4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007909; c=relaxed/simple; bh=Wg/zBVFa4tGz8VOCaxh6a+i+WqdrvN3SJxMoDY3tJdA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QWjhMamzElE+TLON0EX/uydSRtDPaLYA47iz1EEMoCXyz+WEjRTaLE21RVI53WMhDrGa4uwiD7W3OvE7TUxUl5Nn+gT8WovM2Ndda9GyxoozTTyCt6DndKxpzrgQIhxr+xSry0hsmByIl5GJNvDPSsR71i8QN4l7SMmC1PpbmSY= 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=Z8jztd4I; arc=none smtp.client-ip=209.85.167.174 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="Z8jztd4I" Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-3e602994635so1038311b6e.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=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=Q0CqREGwh6IVDq65gpD5flYOXg4XbjfkPAiJB5bPZJk=; b=Z8jztd4IrTCtswb35nOJ3ftwXL90Tshcq6OXaUQUwqzkbSAdaMIunWN2P2XFr7OcaT Fs9xU7WsC6Qd7pQ667aRdDdgCNfkdgOK3AxddbP/MVFnqNA1hm7DGweYObktdi8a/IRI I3Nqmk8JKyWCxwXoclPQ7kT6AIQAEBRE3dGzY= 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=Tf4hKeLRWJrj08St1bhDBB/mMg5ESbYz9p27kjhUc4IBGiqMMV8Tc2obXJCwli0w0h THGOwCN8+7HZ9JewKZi2qImxSfZXBmYr8Sji8oLmKAakUxigRtxIV+R0Fqw+vaJL/ZHW /Xzss0yN+jaGiP4S+2WI5HsLzmIaDowdAIFstfwvWFDoht2gWmw4aTPLpSLHDZBP81oP fZ49v1OvVJgqY4MuTg7A7lI5p1aL1yBOi8TYZ1Z7HKx1hjaqLey/XwiEPARPqWuCZF1n a/G9elqUny2PEiTmW7L91yxAK+u9OarGY7USVsXe98bK40TI/gFdCRWTGVzDNbVCisjP 5c1w== X-Forwarded-Encrypted: i=1; AJvYcCURgqSVtJ5qdeMyirT1ZmDKdtDP3P7AVbQWFbOkM/ybBtxeBnFsSylyuhDgUQ1oaN850cWrdo75aJaYv+Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1MkuiK/WhjVwsVDGaG5RKDmC1ymLC4qflNlVNu6/ZsUcE+ocG Wpgt+PDFEUstVRwPcey5ZTaSIE6CVb+xxcjEQgqwSw41OrjIiexudycXMsedMQ== 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/a= ltmodes/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); =20 - dp->state =3D 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 =3D plug ? DP_STATE_ENTER_PRIME : DP_STATE_ENTER; + schedule_work(&dp->work); + } =20 return 0; } diff --git a/drivers/usb/typec/altmodes/thunderbolt.c b/drivers/usb/typec/a= ltmodes/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 = =3D { =20 static int tbt_altmode_probe(struct typec_altmode *alt) { + const struct typec_altmode *port =3D typec_altmode_get_partner(alt); struct tbt_altmode *tbt; =20 tbt =3D 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); =20 - 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 =3D 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 kob= ject *kobj, struct typec_altmode *adev =3D to_typec_altmode(kobj_to_dev(kobj)); =20 if (attr =3D=3D &dev_attr_active.attr) - if (!adev->ops || !adev->ops->activate) + if (!is_typec_port(adev->dev.parent) && + (!adev->ops || !adev->ops->activate)) return 0444; =20 return attr->mode; @@ -563,7 +564,7 @@ typec_register_altmode(struct device *parent, =20 if (is_port) { alt->attrs[3] =3D &dev_attr_supported_roles.attr; - alt->adev.active =3D true; /* Enabled by default */ + alt->adev.active =3D !desc->inactive; /* Enabled by default */ } =20 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 partn= er * supports. @@ -150,6 +151,7 @@ struct typec_altmode_desc { u32 vdo; /* Only used with ports */ enum typec_port_data roles; + bool inactive : 1; }; =20 void typec_partner_set_pd_revision(struct typec_partner *partner, u16 pd_r= evision); --=20 2.47.0.277.g8800431eea-goog From nobody Sun Nov 24 02:32:36 2024 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 74E4D218302 for ; Thu, 7 Nov 2024 19:31:47 +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=1731007908; cv=none; b=Bq8za4jWtrdeF3V/sGP67MMVdjSxXnW/wlaogxSxLfUkSHPUc5lB07mVDTAuQ7ZZ2ouCfMCgLIZ6YX6/IWssUQeyzMYY5gwlIGLgpuPPy7xoiGhv3tWiwK0nyVltiY8i+/7TiXJcUuEtSdx+iCWjeZs/SIZRAgBECsM3R+FDRcI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007908; c=relaxed/simple; bh=F1pTFIC/STStCNqTkG+Kgg/bMEZb3NhFwcrsacG2V4E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jx8c5vAyoP/23SsVeU+5gLFDGBHtJ/+WGSFL6ZR8mwDHzyFv1lht18qEkMwUMUthJYg6ZdB8o2U2cFvDUcRgP4E6n1psT4S4NW50Qytt5FsXv7OMH8AbFKb8b3xec8jsU4zpWXITPk5gKILJhD19zeF61iWHGCjm/NjWaJevx6w= 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=B7qvQ3Pt; 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="B7qvQ3Pt" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-71e4e481692so1237626b3a.1 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=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=MHcj0dVpOorLNzt+K3XMiAGRMpCigjM3RXLcIpCRHg4=; b=B7qvQ3PtvX9X6yi8e3YvRXZb0AXPDwf3xDOamCQetG0+gOfljQdDbVV+WDzWW1LqtT aRAqi95v1LYRbEdM5M1uLw+CKH6pGiO14Pwa3tdar8Dp30Wp1q4DryGCMIgO8eRV2hmp vZISuXaUNC+q+oNeziXp8EBdEoQX47Fy2ET9Q= 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=VMsgBY62t+1QWvIWEZQZye248kaSegPqdBdHfyRVU36dtIvnJvQwOLRxLt7xLiqTW5 BZqpSjA3syFgwuFrY85DQYs/3adANfV/8RIBgAzV0ccQJcGbnWbunplU2JYdhYYDADFk 8TXmr0M0ov8L6aJM07lRAzYUATDTfPBCVZ4AthZ8GbPV2YYht5zrzlgDALT7RQGAe1DY ay6bqbn2wG8n2CKCSH1WkuQdo4OBWM8cVUuRr09E+V/jHmZCrMKZi1vPtJ8tkMYR42Mp btEuyyNojJ6xRArmPQvGcej5v1fKFBhH79j64kEMk9AaCa3x7gV58u+Z/fcH8+acM2bF r9bQ== X-Forwarded-Encrypted: i=1; AJvYcCXF+73sEbra0ZKBbzpeFzSexkb+pDNAW2X9rFJsit3lVMy5A++9RFiQRbyAur5dKlUaGBy0qncOZXZ2Z2o=@vger.kernel.org X-Gm-Message-State: AOJu0YyHtgLH+uQ016hJ+bxdG5KhpVa4Q7F3rt0eNPs0lEamToPI/5Aw uVkDsRH7axXsVv3HMtcilz+4IEwsXFrO0yrtTkV8lLg0r3YEKC3z+qzmAM2CKg== 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/chr= ome/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_d= ata *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; =20 ret =3D 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); } =20 + /* 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 !=3D NULL && + node->amode->svid =3D=3D 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; --=20 2.47.0.277.g8800431eea-goog From nobody Sun Nov 24 02:32:36 2024 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.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 5F76D218339 for ; Thu, 7 Nov 2024 19:31:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007911; cv=none; b=Y5FjX+yS98pmKN7Pb9JWMpreBhZs3jTj6zoLEpuAqbzxg5/EpMqVFhMZ+czK512xeG0u+c2EWsuIBG+OF2ill4z++aayEoP+zkApAlq6KkGWzemWqnoJupmW7NfthwaTTIM4tCAbzlRrU/1nY0RkCGcyEky+SrDCUtRX0LQ4tKQ= 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=fTvkNs8B; arc=none smtp.client-ip=209.85.210.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="fTvkNs8B" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-720e94d36c8so2250760b3a.1 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=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=NXLwVpSoeftRoET3ccC5saeWASd5OdykBU3Zi9Wk7FE=; b=fTvkNs8BX9pKsOmaeWqfgxYzFZnfGsz7ELdOuRIdS5noby3JSRoiVTXdPYunfK2pSH z/3RpUePEKSmJtiNUlfMhbKLHg2pfyUXMTsJBm+36D9YKOfNiVzglkh1JKIhRHZbW3wa N2n7Xc7GhzixintdVdGe00PZxsuwoHITENiTg= 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=fpwuK3H4oGnIEDT8ZDJyxaC7cM8tjuK6/kq8nYwhCrtMNvazEp0PViYx2s2kbeukS8 J84eM6fvVUkF+2TK4V8UO2svmtL/yLLko1HGWT1fnA4uTXhIzY4JW1IwfGrE2tQ3X7yu bjSPG9R6fFK2dHX0xLFT85OlapJXf1dW+VaWSFmQwHrnT6kryAw1VIPQohP/QT4DhaWb 9euO9sYky2DlgGipNhf944Z8WLI1NCU9cqfUt0DMT+wpARscvQ72rz8ie/DApop6872Y ScdAeR5ckdc7hnqHrp69JEVQy/QT2e7HFUQgJAogXuzppr30yHBJCeLq7kk/4dwatAd5 2UFA== X-Forwarded-Encrypted: i=1; AJvYcCU6w0z/sfHo7UjXMrizx5z8tHUyOWUD10ECpHRjFfmumuOSutxqz5wjkN2K+q0muwPgV47KSFajCHEHHxw=@vger.kernel.org X-Gm-Message-State: AOJu0YxLoPdRcdEGMIZKsvF4VHeP/Lr9zkFHb1qAZdMkkQcvBKsomeMB 9GakShyR8mZX5Z25yVsfz7C3xOh5/qxGPxSsM+dXrr19PXmLjWVs4CuWuE5EqA== 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =20 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.* =20 diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Mak= efile index 2dcc6ccc2302..2f90d4db8099 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -18,7 +18,11 @@ obj-$(CONFIG_CROS_EC_SPI) +=3D cros_ec_spi.o obj-$(CONFIG_CROS_EC_UART) +=3D cros_ec_uart.o cros_ec_lpcs-objs :=3D cros_ec_lpc.o cros_ec_lpc_mec.o cros-ec-typec-objs :=3D cros_ec_typec.o cros_typec_vdm.o +ifneq ($(CONFIG_TYPEC_DP_ALTMODE),) + cros-ec-typec-objs +=3D cros_typec_altmode.o +endif obj-$(CONFIG_CROS_EC_TYPEC) +=3D cros-ec-typec.o + obj-$(CONFIG_CROS_EC_LPC) +=3D cros_ec_lpcs.o obj-$(CONFIG_CROS_EC_PROTO) +=3D cros_ec_proto.o cros_ec_trace.o obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) +=3D cros_kbd_led_backlight.o diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chr= ome/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 @@ =20 #include "cros_ec_typec.h" #include "cros_typec_vdm.h" +#include "cros_typec_altmode.h" =20 #define DRV_NAME "cros-ec-typec" =20 @@ -293,12 +294,11 @@ static int cros_typec_register_port_altmodes(struct c= ros_typec_data *typec, desc.svid =3D USB_TYPEC_DP_SID; desc.mode =3D USB_TYPEC_DP_MODE; desc.vdo =3D DP_PORT_VDO; - amode =3D typec_port_register_altmode(port->port, &desc); + amode =3D 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] =3D amode; - typec_altmode_set_drvdata(amode, port); - amode->ops =3D &port_amode_ops; =20 /* * 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 =3D typec_mux_set(port->mux, &port->state); =20 + if (!ret) + cros_typec_displayport_status_update(port->state.alt, + port->state.data); + return ret; } =20 @@ -1254,6 +1258,8 @@ static int cros_typec_probe(struct platform_device *p= dev) =20 typec->typec_cmd_supported =3D cros_ec_check_features(ec_dev, EC_FEATURE_= TYPEC_CMD); typec->needs_mux_ack =3D cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_= MUX_REQUIRE_AP_ACK); + typec->ap_driven_altmode =3D cros_ec_check_features( + ec_dev, EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY); =20 ret =3D 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/chr= ome/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; }; =20 /* Per port data. */ diff --git a/drivers/platform/chrome/cros_typec_altmode.c b/drivers/platfor= m/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 =3D + 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 =3D 0; + data->vdo_data =3D NULL; + data->vdo_size =3D 0; +} + +static int cros_typec_altmode_enter(struct typec_altmode *alt, u32 *vdo) +{ + struct cros_typec_altmode_data *data =3D typec_altmode_get_drvdata(alt); + struct ec_params_typec_control req =3D { + .port =3D data->port->port_num, + .command =3D TYPEC_CONTROL_COMMAND_ENTER_MODE, + }; + int svdm_version; + int ret; + + if (!data->ap_mode_entry) { + const struct typec_altmode *partner =3D + typec_altmode_get_partner(alt); + dev_warn(&partner->dev, + "EC does not support ap driven mode entry\n"); + return -EOPNOTSUPP; + } + + if (data->sid =3D=3D USB_TYPEC_DP_SID) + req.mode_to_enter =3D CROS_EC_ALTMODE_DP; + else + return -EOPNOTSUPP; + + ret =3D 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 =3D typec_altmode_get_svdm_version(alt); + if (svdm_version < 0) + return svdm_version; + + data->header =3D VDO(data->sid, 1, svdm_version, CMD_ENTER_MODE); + data->header |=3D VDO_OPOS(data->mode); + data->header |=3D VDO_CMDT(CMDT_RSP_ACK); + + data->vdo_data =3D NULL; + data->vdo_size =3D 1; + + schedule_work(&data->work); + + return ret; +} + +static int cros_typec_altmode_exit(struct typec_altmode *alt) +{ + struct cros_typec_altmode_data *data =3D typec_altmode_get_drvdata(alt); + struct ec_params_typec_control req =3D { + .port =3D data->port->port_num, + .command =3D TYPEC_CONTROL_COMMAND_EXIT_MODES, + }; + int svdm_version; + int ret; + + if (!data->ap_mode_entry) { + const struct typec_altmode *partner =3D + typec_altmode_get_partner(alt); + dev_warn(&partner->dev, + "EC does not support ap driven mode entry\n"); + return -EOPNOTSUPP; + } + + ret =3D 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 =3D typec_altmode_get_svdm_version(alt); + if (svdm_version < 0) + return svdm_version; + + data->header =3D VDO(data->sid, 1, svdm_version, CMD_EXIT_MODE); + data->header |=3D VDO_OPOS(data->mode); + data->header |=3D VDO_CMDT(CMDT_RSP_ACK); + + data->vdo_data =3D NULL; + data->vdo_size =3D 1; + + schedule_work(&data->work); + + return ret; +} + +static int cros_typec_displayport_vdm(struct typec_altmode *alt, u32 heade= r, + const u32 *data, int count) +{ + struct cros_typec_dp_data *dp_data =3D typec_altmode_get_drvdata(alt); + struct cros_typec_altmode_data *adata =3D &dp_data->adata; + + + int cmd_type =3D PD_VDO_CMDT(header); + int cmd =3D PD_VDO_CMD(header); + int svdm_version; + + if (!adata->ap_mode_entry) { + const struct typec_altmode *partner =3D + typec_altmode_get_partner(alt); + dev_warn(&partner->dev, + "EC does not support ap driven mode entry\n"); + return -EOPNOTSUPP; + } + + svdm_version =3D 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 =3D PD_VDO_SVDM_VER(header); + } + + adata->header =3D VDO(adata->sid, 1, svdm_version, cmd); + adata->header |=3D 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 =3D *data; + adata->header |=3D VDO_CMDT(CMDT_RSP_ACK); + dp_data->configured =3D true; + schedule_work(&adata->work); + break; + case DP_CMD_STATUS_UPDATE: + dp_data->pending_status_update =3D true; + break; + default: + adata->header |=3D 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 =3D typec_altmode_get_drvdata(alt); + + if (adata->sid =3D=3D 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 =3D { + .enter =3D cros_typec_altmode_enter, + .exit =3D cros_typec_altmode_exit, + .vdm =3D 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 =3D + typec_altmode_get_drvdata(altmode); + struct cros_typec_altmode_data *adata =3D &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 !=3D 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 =3D *data; + dp_data->pending_status_update =3D false; + adata->header |=3D VDO_CMDT(CMDT_RSP_ACK); + adata->vdo_data =3D &dp_data->data.status; + adata->vdo_size =3D 2; + + 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 =3D typec_port_register_altmode(port->port, desc); + if (IS_ERR(alt)) + return alt; + + data =3D 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 =3D alt; + data->port =3D port; + data->ap_mode_entry =3D ap_mode_entry; + data->sid =3D desc->svid; + data->mode =3D 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/platfor= m/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_altmod= e *altmode, + struct typec_displayport_data *data) +{ + return 0; +} +#endif +#endif /* __CROS_TYPEC_ALTMODE_H__ */ --=20 2.47.0.277.g8800431eea-goog From nobody Sun Nov 24 02:32:36 2024 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 E4C262185AA 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=1731007913; cv=none; b=fn89Jz9cfcDELEFbMDnRc53aPH1AS3hhznJ0OdDgKVDl6aFNxVwQ7VTlzhtGKN+1LI0rIO6PJr0CHqvd3vA9hnGu0L57amFJNrmDBF1NdDijpgjQ4RaUfF19cDEvVykK092bb70zRlaSvwHwvxmWdLkx6Cm9znAzBPMrAKVAjU0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007913; c=relaxed/simple; bh=E2+M2MN8fFlYlxb6VQg1nVCnYvwszeZCoKtjpG3T7lM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VASR0IcKTEi+XhU/edltR5I6BJY3aPegMjse7LXxe88qkQBLluP/YsX82GBpX20IT97W0BXcFu7yh65N4V7HGjPxY+V3xE/QFRF0ZeVYJPn2rq0ZPzANUgHnQYRaqfeDGREFobj7NHRzsQOHRwWWZ+uMAIFbx57uE4CNjG0d6Kc= 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=E+pK1ly0; 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="E+pK1ly0" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-20ce65c8e13so15193265ad.1 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=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=qahFf7OaEhB1/uoMJ7ZhjCogHtklDwuIFxHOF/W2wEw=; b=E+pK1ly0o649jvKF5Xyu1meg7xGtiWHfp0+AXj7SgD363y/WdgeNuONeLhkeV6FGCp 99RHm34zl1zBZPa2g4dj2+4th4sMhdfMNFKNz60xWic/XEtYWeOXAwHL+EYj38SmSfFl VQncJdQZiTsI3XNS8ikO3W3oetiXEjy0G9fT4= 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=VoENS2Kp2f6v+9W7DNub2tl3B/jdyDw3k3ojeHHUlmSgXTtr5Qq6JahD7pSk3I5n74 FQghVSmIF9mYU5Pels4zoK+HOLTO2d1yh3dGgGvTLMHcWyJguBECcQ7LaypTmJ6ndMj1 WQtDbtXNGANGEwxc79HWU1UqJhm/Y2YwPD03oHKIS8nr2rM0zbDo34UzPhZW4C9f/7PG +2INwfuwSN+zpUpRBYjeJnHfIBtBnNc6L60SNMMUMm4LnMC0lR/QXbdB+1EiZmcowFNZ rK3RzfZq/0oAGKHXO/Ja8Fui++dSgopOXKdOCSy3XOE549+RxHKaA06utSSAfbSopQwE qN0g== X-Forwarded-Encrypted: i=1; AJvYcCXCMEHmU8eD1bQfzMOp3e/xn4QiUjJzBVOpE/FLErkV4H6lXqYzGCpr9gTSErE4nS1y2wW0UWn0uZuPSFo=@vger.kernel.org X-Gm-Message-State: AOJu0YymudPU0XvVQ2YKq/+MenCNVYguFO9hLPK0Is6ki0TyOW8CFxe4 yvDC0ow4lXtd/lW+RCN2QJt7DqmxWIWNBKuwxqZ2fsD/ZQMslB8etxWhxMovzg== 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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/Mak= efile index 2f90d4db8099..b9b1281de063 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -21,6 +21,9 @@ cros-ec-typec-objs :=3D cros_ec_typec.o cros_typec_vdm.o ifneq ($(CONFIG_TYPEC_DP_ALTMODE),) cros-ec-typec-objs +=3D cros_typec_altmode.o endif +ifneq ($(CONFIG_TYPEC_TBT_ALTMODE),) + cros-ec-typec-objs +=3D cros_typec_altmode.o +endif obj-$(CONFIG_CROS_EC_TYPEC) +=3D cros-ec-typec.o =20 obj-$(CONFIG_CROS_EC_LPC) +=3D cros_ec_lpcs.o diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chr= ome/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 c= ros_typec_data *typec, =20 /* * 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 =3D USB_TYPEC_TBT_SID; - desc.mode =3D TYPEC_ANY_MODE; - amode =3D typec_port_register_altmode(port->port, &desc); - if (IS_ERR(amode)) - return PTR_ERR(amode); - port->port_altmode[CROS_EC_ALTMODE_TBT] =3D amode; - typec_altmode_set_drvdata(amode, port); - amode->ops =3D &port_amode_ops; + if (typec->ap_driven_altmode) { + memset(&desc, 0, sizeof(desc)); + desc.svid =3D USB_TYPEC_TBT_SID; + desc.mode =3D TBT_MODE; + amode =3D cros_typec_register_thunderbolt(port, &desc); + if (IS_ERR(amode)) + return PTR_ERR(amode); + port->port_altmode[CROS_EC_ALTMODE_TBT] =3D amode; + } =20 port->state.alt =3D NULL; port->state.mode =3D TYPEC_STATE_USB; diff --git a/drivers/platform/chrome/cros_typec_altmode.c b/drivers/platfor= m/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" =20 #include +#include #include =20 #include "cros_typec_altmode.h" @@ -67,6 +68,8 @@ static int cros_typec_altmode_enter(struct typec_altmode = *alt, u32 *vdo) =20 if (data->sid =3D=3D USB_TYPEC_DP_SID) req.mode_to_enter =3D CROS_EC_ALTMODE_DP; + else if (data->sid =3D=3D USB_TYPEC_TBT_SID) + req.mode_to_enter =3D CROS_EC_ALTMODE_TBT; else return -EOPNOTSUPP; =20 @@ -196,6 +199,53 @@ static int cros_typec_displayport_vdm(struct typec_alt= mode *alt, u32 header, return 0; } =20 +static int cros_typec_thunderbolt_vdm(struct typec_altmode *alt, u32 heade= r, + const u32 *data, int count) +{ + struct cros_typec_altmode_data *adata =3D typec_altmode_get_drvdata(alt); + + int cmd_type =3D PD_VDO_CMDT(header); + int cmd =3D PD_VDO_CMD(header); + int svdm_version; + + svdm_version =3D 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 =3D PD_VDO_SVDM_VER(header); + } + + adata->header =3D VDO(adata->sid, 1, svdm_version, cmd); + adata->header |=3D 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 |=3D 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 =3D=3D USB_TYPEC_DP_SID) return cros_typec_displayport_vdm(alt, header, data, count); =20 + if (adata->sid =3D=3D USB_TYPEC_TBT_SID) + return cros_typec_thunderbolt_vdm(alt, header, data, count); + return -EINVAL; } =20 @@ -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 =3D typec_port_register_altmode(port->port, desc); + if (IS_ERR(alt)) + return alt; + + data =3D 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 =3D alt; + data->port =3D port; + data->ap_mode_entry =3D true; + data->sid =3D desc->svid; + data->mode =3D 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/platfor= m/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(s= truct 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__ */ --=20 2.47.0.277.g8800431eea-goog From nobody Sun Nov 24 02:32:36 2024 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 9D0CD21892B for ; Thu, 7 Nov 2024 19:31:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731007914; cv=none; b=T5FYvtT8M5b0ZhJR4MtBcQa7zxY2W9vJF5hJ/SYPzPiT6LnheiLMO5VkurUbyocJjhxihbtuHPCYE5KzIurcrwpPv4hP/DYZKNq0TSUECZfmaOLPmR4zBCKZvEbLmjN7hIX8WTNJhv1tQmsq/b7BdAvq4nBhHgzgm3EzHmeAkig= 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=f+zXuhzK; arc=none smtp.client-ip=209.85.210.171 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="f+zXuhzK" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-71e8235f0b6so1109468b3a.3 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=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=qB0OiXmaVUdpADLZ0hMEUy5iSBeICNTxG7bvkK2xwhA=; b=f+zXuhzKP8g16hRxhl9WCu4+Vfv0LBuMfeDtEtdo/QIdo1ObbdDJ1Z91djDSE8viYO aJgeyoginenTqwlKgVGrSdAKH0CxkGo+icUjPiy4YjxliIe2BSYwi+TAIFFITP9ueudf fwrKVZKlsjtLOibJ46scMHJA8uLFI1gWJPHZU= 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=O68rWBe9E2/C8jlU5ilFU4DK2Zb4IvbKOoC47pwRPRWPBDeoabgm+L1S7Z8xBQ33vJ MR93kYd3PpTMkOFzT/aQU+iy5bt1vmN+RhPSN8RRY/q8s7vIiHV7phMEJ88B4e2+k6OR LWd1Tu9xWENKR1a0kwkncA9zDPmx+9ooCxNKZnHePcZBwyOslb3nGtiiEO+61yRxdGkL 8J8NgjTRTfIajmKz7VrviYUGiENU6XneIe2uqoyTg8C7P7FLt7aaRueSOHdl9hJxZeEA Gna1qM+oztGWznowQNVi7DFJMZvv399HABOnfrVgDRLehWsZl0BFDE0D8AqOh0OTbeRn W34g== X-Forwarded-Encrypted: i=1; AJvYcCXVs+x4qfmyM8GjBfcjw3OFaPLtQU8LsHrH5iym6hnTWVEPu7X5GPwDXqKfeF3NVFXBsBoat2OnKVmGZyw=@vger.kernel.org X-Gm-Message-State: AOJu0Yypqiy/SB8FXb75OSMiIqhXumDmYrlLlD53eAh68YRuSmA/B2Ym e8mcQ98BJ6OtlHWPKKf9DuqqxbhXiMRhCS/rHRrxb5PvQ2NnNca9gEv/NPoiJg== 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D 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/chr= ome/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 cro= s_typec_data *typec, memset(&desc, 0, sizeof(desc)); desc.svid =3D USB_TYPEC_TBT_SID; desc.mode =3D TBT_MODE; + desc.inactive =3D true; amode =3D cros_typec_register_thunderbolt(port, &desc); if (IS_ERR(amode)) return PTR_ERR(amode); --=20 2.47.0.277.g8800431eea-goog