From nobody Wed Dec 17 19:37:26 2025 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.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 17160212FB3 for ; Fri, 6 Dec 2024 23:38:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733528325; cv=none; b=JZL6hM9d7WSGJN0G+YoywTNo3YWjaJh+GNj3l040jtfUwDjQy8xfOYFr+okK58/EXeEi6EqvT2Wd5WGmAftY5WuJJvHktpxzxYTHkHctgRDtk8yZtHd/SDjChhOEfq0BMSotpoe7jEzCH1dsbfmlmmrLrowdHqQT5+wYMXFiJWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733528325; c=relaxed/simple; bh=Wa7Kv7PricBjMroxEO0Q9NJCwPJQ0U69/lCUJwLLOoA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NyVmg48opOkFaoOCpb9UxxNl6UHGBlm6vMAuzSZR+tpvxkpMMvm4K1F5f7D3dE88O25aTL9BgCpnrJ8DczSqmBpVJMqdTlfDofMzxxQazSzIggqixTWMSUGJA9BOxmJs+TAwdwDRc7ZT9CDZMOiuNwE5wm9wVIP06esPB8qDsRg= 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=Rvp+WWeL; arc=none smtp.client-ip=209.85.214.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="Rvp+WWeL" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-215b0582aaeso20645025ad.3 for ; Fri, 06 Dec 2024 15:38:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733528323; x=1734133123; 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=npc5/EXwRgV9fZkcYMR5vMPbJLkeKsCQO+ev3yk2o1U=; b=Rvp+WWeLyvJtHNcbfMwhxHPFbpZPCajJ49QfKh36ep8dKX7cg+l23U8M/rTEF+0BHX Yz5XM7uAoW+Cf1i0UDcdhmBD4X5mbEg3WDMmp4ncAlG7DGgfqodt29ROHI/jV9LqY4Ee gapUR74zeKWz97xQDcazDhLOatXydswt/TNGA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733528323; x=1734133123; 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=npc5/EXwRgV9fZkcYMR5vMPbJLkeKsCQO+ev3yk2o1U=; b=ZvBdh7xTNyeqeMWgGu/sPvyJ4/Pu0oEkl26F6v7XYrp7cl5PiNRYP0bJN80a6Uw0hM TjsBgq8Dx5GV5yHEpnBPo6aIs9udSTVKZ3yBF0zcukc9eTGBkMTDxwczPdnvr2WGqxcC Y5ec5zkr1VWB3ZQI6hsnRprUGDJPzwxuCvOWesQPceu9lmXF7RVDWgesUyGIUk9hS9pc YC8k6ntmBCiFzPrJC62To3xpNHwFDopZccyB/bxIzPGxa7yGF6qsqMMDFXqZT19zcjGp h2RYKYw42KPhr5BVpBh0HwsO8Pw+Iz64w6XVyde++r/FKq/aIpKQDSsYSLwptC0iVQf8 YVZQ== X-Forwarded-Encrypted: i=1; AJvYcCVS1RQ3V4hefPs77UzGGSAqH7ggY1bXSj7vd+R1H8kAUs/I7zTT6Tbd+/0LCgPHtm322E7VJLohK48CtsY=@vger.kernel.org X-Gm-Message-State: AOJu0YwvxUjUn9AUIePT913ln1Sj+XEtXLqalZLS+d9cuh+Vrjbf+v62 sCC+eKqCrlbh/DJWrrEoX4u0CtipEl1VHl6Qwn34QNMqikHudMOTfIHM7Lsohg== X-Gm-Gg: ASbGnctr5mI8RPWsxorT1NPSvwGQFTgfJUULgESH13nnOeNBwntJP7kdVsMlmTqKeJp 9sA3K56K/bvGSzRYfAWmN3L4+VVGmKCSMIMqpCxJAD8AzSUsDwRxJz6wJmC2yVFAnjsyoNLfq+N oQFsEDyoKFiYHYT0LjaNoS+7FXWM58TrWeWZl5kXp7q7DtHBEP6Ahi3Ff9jI5F6T+e/QG0uzwCw pkqmN1tnEecSi1Lv3WqsoSSS36h3i4wG6y932RuLEEppcJw4vXpD2Jhm/x3KWpDYF31dEGVJ1vN xoZA3/7lZZidpM0fRwqCxNDc X-Google-Smtp-Source: AGHT+IEwnZn4JmHjf3RRZuf4aJQ3xLLJws8lCWbViXA/5lZ1RWNF9JnUYcLQmuMX0s00k7x5Jh8dAg== X-Received: by 2002:a17:903:110f:b0:215:44fe:1640 with SMTP id d9443c01a7336-21614d1f22amr59537635ad.3.1733528323337; Fri, 06 Dec 2024 15:38:43 -0800 (PST) Received: from localhost (227.180.227.35.bc.googleusercontent.com. [35.227.180.227]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-215f8e5f2d6sm33999035ad.71.2024.12.06.15.38.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Dec 2024 15:38: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: akuchynski@google.com, pmalani@chromium.org, jthies@google.com, dmitry.baryshkov@linaro.org, badhri@google.com, rdbabiera@google.com, Abhishek Pandit-Subedi , Greg Kroah-Hartman , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/7] usb: typec: Only use SVID for matching altmodes Date: Fri, 6 Dec 2024 15:38:12 -0800 Message-ID: <20241206153813.v4.1.Ie0d37646f18461234777d88b4c3e21faed92ed4f@changeid> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog In-Reply-To: <20241206233830.2401638-1-abhishekpandit@chromium.org> References: <20241206233830.2401638-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 --- (no changes since v3) 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.338.g60cca15819-goog From nobody Wed Dec 17 19:37:26 2025 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 E6063213E89 for ; Fri, 6 Dec 2024 23:38:45 +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=1733528327; cv=none; b=X/hof1cqdFaM6OFrraVvCYx0NPQxSbzZqfC+/Z6Vs6Na5pWDmt+7m6EARX7zypsOL0WDF1wUKbyAetCSzPIf7wfVwqrVzsCa1l6I6d+3+pfI+itLW4ssJ6EojwhJfaQKPr7oVzAS68UjhY/cqP/qtSZBMJxBG4IVFp0HCO+w020= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733528327; c=relaxed/simple; bh=smB67MxYTGXL0wT1q7L5mLkbgh4UMdxC1IAgHVVgeBk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=thdkAMRLWUhbr7JZ+NyLUQqqwwN5BZ21/isjh1v+qXWlXcDRFoboNa0hI+yFfcaQKglIJRyb00LdRqrr9dPSTs5IvX6/hB5I9xnSHcM14+yeOVong1a7AC7YWf/oK7znVupxckonI18eyM6JJ3pZoEOp3RL/ljYKM3ErcWS5B2k= 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=KAm6cm7L; 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="KAm6cm7L" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-724e1742d0dso2429389b3a.0 for ; Fri, 06 Dec 2024 15:38:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733528325; x=1734133125; 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=2rMEcgn2kv9SSKmI6LxVsXgCiZxQojUUrd3cm2OFs5Y=; b=KAm6cm7Ll097qlmFWfE/CNS2X8E9rGyODJDlbxPicFckp+50Y94ZllS05EeemUjsLv Ew1tobuULDvokUSOnLx+5l8AXVYzKTURXkSQ/poeGqw2RYxdbALEjBygmcZSfLQnYH9z 0Mjq8zOqc12FdtYD/nHV7UA1CgEd8DSiDgYKs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733528325; x=1734133125; 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=2rMEcgn2kv9SSKmI6LxVsXgCiZxQojUUrd3cm2OFs5Y=; b=lLFXOJ3XBlkABZOafAR9TAQSacUpTGGW667XMCWrga/Up/Y7HSKbX5IGwptPmF40vi oQKwH7GHemk+8F5qPM8JjuFA3mwultBonHP35kKPEUMcsfzT7AfSJQQHH/4p0e7gBE71 XVD4Sa3E6H9L10HJJjmQDsDNupgr8vagcirfhLXgBzazQon4JSqxIVOrcK6M4MBm2awe dwZ9BNkTXhfDIGQ8BsCFKNnNKsSOa8KYvYCbze05jHE07nJK0/axET7lFhu4zN6yraXp ZovJEoV3IWBpPy1WmHixc6KbulLA/pEDgdrEUcb0fzvqzT+J/OVDzr2zemSnm+pIrY4+ QyRA== X-Forwarded-Encrypted: i=1; AJvYcCXmHB/t72fRLy9QkNqm8BnQmZAvdTakP6UBMeJzZi3y3eBg1FVOMr+IYepnjVuD6aQFJX02vYQ+D6+bMWw=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0B4sQZ3FEb72Mhs6yQhJTyey4BQzAsZ2vKWccC5ik4dk2L/Pn JSXG/3lbJ3Xt4vc9R9HQ9j4l2YfrhXnl7I7C8uBD2lTDd1IPCNsNjOGiQvdLaQ== X-Gm-Gg: ASbGncsUE/UYolfBf6qoZae6gJaTlUu6q56KP2bkM3ET0lpR3RS7r9Dopj/BeU/aG2R ILtRyyMbMUB1g3Cjo1NBIfdk8RRGIH9+CwC/cNloOcHzH40VTN36wUH5RDVH7QV3cnDXmaFhCur FkvT6yIdol+H0++GbaDBuuZAySjN8QV8QHlqOg8Cvh8+f6fBLcNAbAWm0by7X7q06aLv5y5Dnso JbsdCMQmOgXdj2Px4ULCO7ZjNRU0re6FOj6AlC1XnTwbzz1d4Z1l1LyovBfvRRk4hPrep1tdm1K 49Mz97IfC31ZCjZ1/sdesAfF X-Google-Smtp-Source: AGHT+IGMkAHbAyLL/Sws52EMD14nSuU+heoWGjssi5zVIb7cyOVFaZvfBHEZ5Z3gJblyJe0Ihk0i/A== X-Received: by 2002:a17:903:2290:b0:216:2426:767f with SMTP id d9443c01a7336-216242677d2mr34935115ad.49.1733528325212; Fri, 06 Dec 2024 15:38:45 -0800 (PST) Received: from localhost (227.180.227.35.bc.googleusercontent.com. [35.227.180.227]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-215f8f09146sm33847435ad.199.2024.12.06.15.38.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Dec 2024 15:38: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: akuchynski@google.com, pmalani@chromium.org, jthies@google.com, dmitry.baryshkov@linaro.org, badhri@google.com, rdbabiera@google.com, Abhishek Pandit-Subedi , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [PATCH v4 2/7] usb: typec: Add driver for Thunderbolt 3 Alternate Mode Date: Fri, 6 Dec 2024 15:38:13 -0800 Message-ID: <20241206153813.v4.2.I3080b036e8de0b9957c57c1c3059db7149c5e549@changeid> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog In-Reply-To: <20241206233830.2401638-1-abhishekpandit@chromium.org> References: <20241206233830.2401638-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 in v4: - Large refactor to use cable_altmodes - Fixed ordering of cable mode enter/exit (SOP', SOP", then port for enter; reverse order for exit) - Other small fixes from v3 feedback 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 Changes in v1: - 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)) drivers/usb/typec/altmodes/Kconfig | 9 + drivers/usb/typec/altmodes/Makefile | 2 + drivers/usb/typec/altmodes/thunderbolt.c | 387 +++++++++++++++++++++++ drivers/usb/typec/class.c | 5 +- include/linux/usb/typec.h | 2 + include/linux/usb/typec_tbt.h | 1 + 6 files changed, 404 insertions(+), 2 deletions(-) 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..14e89e9a7691 --- /dev/null +++ b/drivers/usb/typec/altmodes/thunderbolt.c @@ -0,0 +1,387 @@ +// 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_cable_altmode_enter(tbt->alt, TYPEC_PLUG_SOP_P, NULL); + if (ret) { + dev_dbg(&tbt->plug[TYPEC_PLUG_SOP_P]->dev, + "failed to enter mode (%d)\n", ret); + goto disable_plugs; + } + break; + case TBT_STATE_SOP_PP_ENTER: + ret =3D typec_cable_altmode_enter(tbt->alt, TYPEC_PLUG_SOP_PP, NULL); + if (ret) { + dev_dbg(&tbt->plug[TYPEC_PLUG_SOP_PP]->dev, + "failed to enter mode (%d)\n", ret); + goto disable_plugs; + } + 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_cable_altmode_exit(tbt->alt, TYPEC_PLUG_SOP_PP); + break; + case TBT_STATE_SOP_P_EXIT: + typec_cable_altmode_exit(tbt->alt, TYPEC_PLUG_SOP_P); + break; + default: + break; + } + + tbt->state =3D TBT_STATE_IDLE; + + mutex_unlock(&tbt->lock); + return; + +disable_plugs: + for (int i =3D TYPEC_PLUG_SOP_PP; i > 0; --i) { + if (tbt->plug[i]) + typec_altmode_put_plug(tbt->plug[i]); + + tbt->plug[i] =3D NULL; + } + + tbt->state =3D TBT_STATE_ENTER; + schedule_work(&tbt->work); + mutex_unlock(&tbt->lock); +} + +/* MUST HOLD tbt->lock. + * + * If SOP' is available, enter that first (which will trigger a VDM respon= se + * that will enter SOP" if available and then the port). If entering SOP' = fails, + * stop attempting to enter either cable altmode (probably not supported) = and + * directly enter the port altmode. + */ +static int tbt_enter_modes_ordered(struct typec_altmode *alt) +{ + struct tbt_altmode *tbt =3D typec_altmode_get_drvdata(alt); + int ret =3D 0; + + if (!tbt_ready(tbt->alt)) + return -ENODEV; + + if (tbt->plug[TYPEC_PLUG_SOP_P]) { + ret =3D typec_cable_altmode_enter(alt, TYPEC_PLUG_SOP_P, NULL); + if (ret < 0) { + for (int i =3D TYPEC_PLUG_SOP_PP; i > 0; --i) { + if (tbt->plug[i]) + typec_altmode_put_plug(tbt->plug[i]); + + tbt->plug[i] =3D NULL; + } + } else { + return ret; + } + } + + return tbt_enter_mode(tbt); +} + +static int tbt_cable_altmode_vdm(struct typec_altmode *alt, + enum typec_plug_index sop, 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 described in USB Type-C Spec + * R2.0 Section 6.7.3: SOP', SOP", then port. + */ + if (sop =3D=3D 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 (sop =3D=3D TYPEC_PLUG_SOP_PP) + tbt->state =3D TBT_STATE_ENTER; + + break; + case CMD_EXIT_MODE: + /* Exit in opposite order: Port, SOP", then SOP'. */ + if (sop =3D=3D TYPEC_PLUG_SOP_PP) + tbt->state =3D TBT_STATE_SOP_P_EXIT; + 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_vdm(struct typec_altmode *alt, + const u32 hdr, const u32 *vdo, int count) +{ + struct tbt_altmode *tbt =3D typec_altmode_get_drvdata(alt); + struct typec_thunderbolt_data data; + 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: + /* Port altmode is last to enter and first to exit. */ + switch (cmd) { + case CMD_ENTER_MODE: + memset(&data, 0, sizeof(data)); + + data.device_mode =3D tbt->alt->vdo; + data.enter_vdo =3D tbt->enter_vdo; + if (tbt->plug[TYPEC_PLUG_SOP_P]) + data.cable_mode =3D tbt->plug[TYPEC_PLUG_SOP_P]->vdo; + + typec_altmode_notify(alt, TYPEC_STATE_MODAL, &data); + break; + case CMD_EXIT_MODE: + 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; + 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 (activate) + ret =3D tbt_enter_modes_ordered(alt); + 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 const struct typec_cable_ops tbt_cable_ops =3D { + .vdm =3D tbt_cable_altmode_vdm, +}; + +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_P]) + tbt->state =3D TBT_STATE_SOP_P_ENTER; + else if (tbt->plug[TYPEC_PLUG_SOP_PP]) + tbt->state =3D TBT_STATE_SOP_PP_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; + + /* Thunderbolt 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_TBT_SID) + break; + + plug->desc =3D "Thunderbolt3"; + plug->cable_ops =3D &tbt_cable_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", + } +}; +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/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..252af3f77039 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; }; =20 void typec_partner_set_pd_revision(struct typec_partner *partner, u16 pd_r= evision); 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.338.g60cca15819-goog From nobody Wed Dec 17 19:37:26 2025 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.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 E55C221480E for ; Fri, 6 Dec 2024 23:38:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733528330; cv=none; b=jZYGodVxkZsN4NctkHtaZdLgkXhhgKXEdAqtZYxAuBR7sUjypmDAVpxsDm5gg4TYU2WYYKhvj3SG6Nvpxps3tQggFvzeoV3kzDnzKLvQkHgd2B8T9AbjVzchZxnn3u0lUyNZJ0q2wtpuVdRchvn8PTu5Z5Qzjva8h0vQv/EsRR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733528330; c=relaxed/simple; bh=Jlz35Axmxas20UXZdMUAEnU/Zcdy+VnrtwvvujZhzjM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dnxtx8bnxKD92V/aSyg88klRilv4zQlP0so9N4sYn0UDzFcO6wKavOy6KuH1FFdffvcGFy+HLzEBjV+SyoPX15lT0o+ujIEA5TsidadkyMkg7VuqH4PXsyipB/pKAwoSgI975w/IEo+sdnQcM1ygT4n3xPPiiw7VVvC5vw0AGsk= 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=k5onkOd+; arc=none smtp.client-ip=209.85.214.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="k5onkOd+" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-215b13e9ccbso25371045ad.0 for ; Fri, 06 Dec 2024 15:38:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733528328; x=1734133128; 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=qEsFgZZBOjZItw/w6Re8IWK1gazviV9TFZpIsGLgdzk=; b=k5onkOd+HLH6NzluXQuidMKvZdOf6eBpLocBkdHjOKw2qGL2wsmupbrSb7oCPSnEE2 yFFXcY72Me+Cwni12FjPmEQ6rHApRC6UefZJKhgiQZzBBhgxVLvden6s+Lx2Wkd7yT/o V6t48z2hXSi53XkWWj4xPBqtljEPekTnv2SAQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733528328; x=1734133128; 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=qEsFgZZBOjZItw/w6Re8IWK1gazviV9TFZpIsGLgdzk=; b=EpZYGR8KW0BOXIAfKho4S5cK0Zz5AQPMJ35EtavU+/CuEf6vxt8ms/HqzjF1Sxoyxx mnRjZJ+6LTSGyjHjbREdLsagiKMBlfKQldI95LQM3dXuk6kTS3uPf8KrhJ+jbnB1oDiV i8LjCwyfcTG2/XThtjUVAa2aveWqPpHeAnbwZJ0XMfl0clnLXM0rqFv1Cwy3v1fOlRWb RS93vX38ATl4NA4b54c+bCcxtcytr+aPDCYU9RBVPqCePK6Pd4D14E14LeD1xjP+9YPF u7EQJGwEFdXHZ3RJuFef6iJyx2SdJFGqW3iNXa4BwV+WpWphqMMgNUN+sVkO3L9tsXaE 2dpA== X-Forwarded-Encrypted: i=1; AJvYcCUKn3ivJ5OpebuoGGaO5NKDxx3wc1tz4qRLhv8F/VQfKnkg8zRncK4IA8BHKh4MeGjURps5OlYzA1qXoDc=@vger.kernel.org X-Gm-Message-State: AOJu0YzRgA8RlHX+Y0582OFE1CWoCuZxC3NVdxSsjsbQDgpQtCwCrHjC X7DfcofCeFwOT/+kmggnX/PsUj6ty8yDxJB+ElIMEXhS862seS3CUo7f78uLeQ== X-Gm-Gg: ASbGnctPTO0UvDbAgJPbRAkfyaWEvUNsbuzcZcNuvAtm9qWrngOybc+N2cAm/xK+99e 6Y19uzsfoIS6y8t9IAJdWR42U2axvlCaW+TXaHerE2ZoSO0n0jX6MQVtQ+Le55Xb4nnDnwkqwaW e2qSKbPmxdFqO4y5SU0cLvYINVZGly/s3D8vIqr3LVUyd3dgBz3EPW3wJ91Sx/zgnpP8y3Z5HqG /YdsewN3HWXHY74czDWH0V+agiC0LVHKleoejO2fEoNHE9TSvfVC5VZLqBBSKT6EqREuZDcTpEf jARFV+PXGOKLxODkK7QnOsxL X-Google-Smtp-Source: AGHT+IE2s40s6YYwYc1sTeIXRAHidUXahuDrUL8yJczv/cBkFhoKl7A5wKj7RNqs4UHrL++1LK1l/Q== X-Received: by 2002:a17:902:e5cd:b0:215:9642:4d6d with SMTP id d9443c01a7336-21614d3ac8amr54953465ad.17.1733528328424; Fri, 06 Dec 2024 15:38:48 -0800 (PST) Received: from localhost (227.180.227.35.bc.googleusercontent.com. [35.227.180.227]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-215f8efcc70sm33915095ad.167.2024.12.06.15.38.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Dec 2024 15:38:47 -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: akuchynski@google.com, pmalani@chromium.org, jthies@google.com, dmitry.baryshkov@linaro.org, badhri@google.com, rdbabiera@google.com, Abhishek Pandit-Subedi , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [PATCH v4 3/7] usb: typec: Print err when displayport fails to enter Date: Fri, 6 Dec 2024 15:38:14 -0800 Message-ID: <20241206153813.v4.3.I6cff9d767b0f8ab6458d8940941e42c920902d49@changeid> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog In-Reply-To: <20241206233830.2401638-1-abhishekpandit@chromium.org> References: <20241206233830.2401638-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" Print the error reason for typec_altmode_enter so users can understand why displayport failed to enter. Signed-off-by: Abhishek Pandit-Subedi --- (no changes since v1) drivers/usb/typec/altmodes/displayport.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/a= ltmodes/displayport.c index 3245e03d59e6..e292780ec309 100644 --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -252,7 +252,8 @@ static void dp_altmode_work(struct work_struct *work) case DP_STATE_ENTER: ret =3D typec_altmode_enter(dp->alt, NULL); if (ret && ret !=3D -EBUSY) - dev_err(&dp->alt->dev, "failed to enter mode\n"); + dev_err(&dp->alt->dev, "failed to enter mode: %d\n", + ret); break; case DP_STATE_ENTER_PRIME: ret =3D typec_cable_altmode_enter(dp->alt, TYPEC_PLUG_SOP_P, NULL); --=20 2.47.0.338.g60cca15819-goog From nobody Wed Dec 17 19:37:26 2025 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.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 86BB3214818 for ; Fri, 6 Dec 2024 23:38:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733528332; cv=none; b=ZEKNUfO7gwJbFk63OTp6gAhKetfM90YM/KSuXNMi/U5CWB7UMINRQj0mDTFUV5PInCMGHVJsn41FhibscJdIfVrlx97AzzAVVVsziuMPYda5jFXXr8/8DlNb42kMxrQtOmqNvxJ3z43TUuSVrEelzRyk37MAuZ4VtSxhr2Ah06Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733528332; c=relaxed/simple; bh=mSbImJ4dzWme04JaRICj6xcOiMD+Em1Pq6oCKRsC+SU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bkod9wOzBm/mRKVU+DK9msRJ9msMcbyX3bPmQT645tb04vLnQ7Rk15/rpzDwhCrR66ys3YLpTLlj7NGWNtHYSYmqrPR1BQGnsk++58IMuWanzdmyIB0moJTJ/JhX7jP/Wph31gZcm7hT8foGb9n8Fq9hmQC6jcs9h3SBo89MKtI= 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=QBfg9eJs; arc=none smtp.client-ip=209.85.214.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="QBfg9eJs" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-215b45a40d8so22734665ad.1 for ; Fri, 06 Dec 2024 15:38:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733528330; x=1734133130; 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=GcArLAGlc9DQDoWi6KCdvmZsVO2iZiC3gTAsa+lsHVQ=; b=QBfg9eJsFfMm2MCqnNjPWey35dGy4Q4Gn10RNRp5un54nhonw2bgAlC/r/i8Mr8FtL hS4dmV+5RQ+z8Znt+jxKnh5IPbHeZUoRIEhHYM4RnZYsWPtq769WlUWaEgTA+n6T/Vm/ C74em7f1Ec7GxhNz0AjLDLurIJ5ZuM5jxOt5k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733528330; x=1734133130; 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=GcArLAGlc9DQDoWi6KCdvmZsVO2iZiC3gTAsa+lsHVQ=; b=JEdn4PPJ9UeK0CrlE64xDnRJo68WE03gY9RJsBRP0fVi67quk8EBTcemoTzz5D5vtY Ol9bE/GC91NW2wWRNV50OkmCi63XU+rUVJWQS6c745KmyN718aTNkr1YwsDs75BfQR+9 Batcod7Tq48bhKdexxHZc7Lqpq4YdQxzz7U+WPqKVtQkqyy+/jrOsUFB+rspk2PinaUM XAt/oLYpFr9loaewSxfNhnou0MuMxkOGEgAo7zz2e6vDgw4Ea3uOVmAD7pLdp1KHONuP 12bIXALo0/d7WN0kqD9/ntizvLgaoKjvcVCEAR4Yj8QieX/vVulZ4zCg8UeRbQSOIITM jzBg== X-Forwarded-Encrypted: i=1; AJvYcCX+Bg998fEfySykKAQWQ+A0gKfv3qfuxyGCh0vodsYLPdtQ9uwTseTn97Lt2RbMSBukm5xt1C/HioUOfGw=@vger.kernel.org X-Gm-Message-State: AOJu0YywLq0nu0TpLYB3rJx6e27iU8m3XoFNmQWjrvTuycMJFTUu+iKB V+r6yxATN6uomrZddqBdDTO44qLtuLV+9rmvvQJt0jUeFNG833PEGIvUsFAfXw== X-Gm-Gg: ASbGncsKc4aRWiKpAyeapjZ4zZxPjyfMlpfgBhvr65hYtab2a0zQwhuEcn2/7cWvq7B 47+osQwDOt+OeB/QJYdBYOiIkT3jZjXFpWaLml+3ekRy2MPSQyYHhh9nt1pYSDoUS07mGECZbrU bdyZTlBsxGjIoNeqlQsg71VZzrtW6arDZQxK2ijJuzTYNXMXrid0+Uo2LvJAPnjarK037bx6Qey rGR6RwLTVKyeytPrYzU07082wHqldUNDwFgbuN3TH7q47LpwhLTt+IWovEV/0EGvIwzyjhYeGKa 1x5b4Xgz8KbmJUkGzxJn2/zq X-Google-Smtp-Source: AGHT+IFfLFsxeaCP6JpA4wv/h1BK8Dgjnc9khGWbX2GJzIK3a3OtB6TO5+qcZX4naTvJeWS7CY8AWQ== X-Received: by 2002:a17:902:d2cc:b0:215:94c0:f6ea with SMTP id d9443c01a7336-21614ddb7b8mr57867325ad.56.1733528330015; Fri, 06 Dec 2024 15:38:50 -0800 (PST) Received: from localhost (227.180.227.35.bc.googleusercontent.com. [35.227.180.227]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-215f8e3e452sm33980235ad.43.2024.12.06.15.38.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Dec 2024 15:38:49 -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: akuchynski@google.com, pmalani@chromium.org, jthies@google.com, dmitry.baryshkov@linaro.org, badhri@google.com, rdbabiera@google.com, Abhishek Pandit-Subedi , Benson Leung , Guenter Roeck , linux-kernel@vger.kernel.org Subject: [PATCH v4 4/7] platform/chrome: cros_ec_typec: Update partner altmode active Date: Fri, 6 Dec 2024 15:38:15 -0800 Message-ID: <20241206153813.v4.4.I083bf9188947be8cb7460211cfdf3233370a28f6@changeid> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog In-Reply-To: <20241206233830.2401638-1-abhishekpandit@chromium.org> References: <20241206233830.2401638-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.338.g60cca15819-goog From nobody Wed Dec 17 19:37:26 2025 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.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 B1466212F9E for ; Fri, 6 Dec 2024 23:38:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733528333; cv=none; b=KRGVzESpNN/0rEQXdoQ3vkbvNG1e5BAvSr1pUlWYkSfF7hoblNevE8E5n8EmXrn/wPtcrFQxFMLslr1B1c3x6PMRFgAbhJ2P5LgCDHAm96CEFyGZDE7YYeg1763ZPvk4ZAkXlUskHiKWSKEnnttRjTNjzg5caAh0r9TUWNSKxIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733528333; c=relaxed/simple; bh=2+wBq8u+eD2ermclDg0jFeGME49qev4T7mEgijTUuQ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QOC8WajLuSbh1oLO/6M7HFUzog/e/A+OguLyuCC3jMr2GQst3sJ1myAntQ2owB0bzsRNoDZGmBD34ylGpL2gSERUNTkIzAgJzwD8f2B9fn2gcbv4hQ7e03YJtYaITx9MiPjdyoZB8DvBvVHtsuwA4/uSdm1lbjSsc19xEFF8ZVw= 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=TgfYLpDF; arc=none smtp.client-ip=209.85.210.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="TgfYLpDF" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-725b3b9fa6cso1631506b3a.3 for ; Fri, 06 Dec 2024 15:38:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733528331; x=1734133131; 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=FdVPVTBpSHJ+79KT4El6LsZDWrZDHedECOLs0CT3WJ4=; b=TgfYLpDFsMpnsXHX0lxz+SIngq+phE14ovn6l+A6ci5Say5pusPxUh17enUsD47W+s Adw40b4oBuC7qSIy9KOw2zgShdzw7UoZUC2iN9Vyo7FKBoKLftTodxwOfw3ekaHqbzVy l34rruPgodfO4+g7mGq3xOiuvcVwHGepCEySM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733528331; x=1734133131; 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=FdVPVTBpSHJ+79KT4El6LsZDWrZDHedECOLs0CT3WJ4=; b=xTv0iQVguzJZhz1iqrX+aaEMADsi1b0SO77bl8/qSlREDnLtkV/cFImCvi0KUVHwkI eBZaN5sT/BriZckCteQj0JP9aS9cAqexQDLALkY6Ouq1L8w2+12M0lvzW3BOPxKftXMj XbCQFwdH01qzYPCMVvtAaBpDP2bZJb89vX3fxZWsNxJ6fLxP7lxXaezDw67MXmXGpLyU 7LIqvo6H9abSq7P3TChLOkaMe006qXnBSfJEwQGFB/qzABnSqsSj8a0SpPTchnM9gRPn 12oscv3lVhpHr+EJFzrUJ1gikiZUvDM+O8Xp8Ld2NaEjRxjzYjvTs+sxxE0wexGW3O+7 7TxA== X-Forwarded-Encrypted: i=1; AJvYcCVOiIW4dbW6N8Y9vTC34FQtwIyYyejnU6S+qV9thWnvtfVRJJvDIIQDH8n8ewlOB4EW2ftUxkaoEntxEyg=@vger.kernel.org X-Gm-Message-State: AOJu0YwPRUsebHK6M43CPj2K4QUW4sny5r6/Kso/LhCNc5iknMocGVx1 N+RNdE5D+WNQO/M824xPQopSI9cfhB6ANfQYlm3T12NFkTHhzq6aGwSiSNQT0Q== X-Gm-Gg: ASbGncvL/ZGL9zMvWmoGQcCFQxyZBfrLrYvImh1pEJbwb0CLqAbFK6mQXZHpXtrYfc5 ka7En3OBpwX5NtjE1pIXin4nOruQYeqm004Hd7Z9FIcIE37xHfIBNIyr9iM+cmnPNj2/gc4RMpQ m/tu2evBlR9W/IO8wYfl+hWcBBWKVfNKWKDvv8d9km+k3Is+0cge/InnfsnyoN3o6Mfm2VpGnKO bZdH2DYZr4nZtDFdZMg2WHiG0oDs+80ykZ95TdYCcOSdfv/SFa+GGHJr4Q01SiZ+zVzX0X/T2RA MhpaVWE8sdZ69vdKyHOL6y4F X-Google-Smtp-Source: AGHT+IH1WcTWH/AnvqB14ooojDiG20Od9CpEHQt6ICLFCNdse1mkRXoI9sx7hDec7O26SURGe5T/6Q== X-Received: by 2002:a05:6a00:92a6:b0:724:5815:62c1 with SMTP id d2e1a72fcca58-725b81a3f83mr7284055b3a.19.1733528331002; Fri, 06 Dec 2024 15:38:51 -0800 (PST) Received: from localhost (227.180.227.35.bc.googleusercontent.com. [35.227.180.227]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-725bcee5f2esm1728558b3a.54.2024.12.06.15.38.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Dec 2024 15:38: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: akuchynski@google.com, pmalani@chromium.org, jthies@google.com, dmitry.baryshkov@linaro.org, badhri@google.com, rdbabiera@google.com, Abhishek Pandit-Subedi , Benson Leung , Guenter Roeck , linux-kernel@vger.kernel.org Subject: [PATCH v4 5/7] platform/chrome: cros_ec_typec: Displayport support Date: Fri, 6 Dec 2024 15:38:16 -0800 Message-ID: <20241206153813.v4.5.I142fc0c09df58689b98f0cebf1c5e48b9d4fa800@changeid> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog In-Reply-To: <20241206233830.2401638-1-abhishekpandit@chromium.org> References: <20241206233830.2401638-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 v4: - memset struct typec_altmode_desc - Add CONFIG_CROS_EC_TYPEC_ALTMODES for Makefile use - Move ap_driven_altmode check to common vdm function - Add locking to protect shared data - Update enter/exit error messages 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/Kconfig | 6 + drivers/platform/chrome/Makefile | 4 + drivers/platform/chrome/cros_ec_typec.c | 13 +- drivers/platform/chrome/cros_ec_typec.h | 1 + drivers/platform/chrome/cros_typec_altmode.c | 281 +++++++++++++++++++ drivers/platform/chrome/cros_typec_altmode.h | 34 +++ 7 files changed, 339 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/Kconfig b/drivers/platform/chrome/Kcon= fig index 7dbeb786352a..984f843ea7a2 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -226,12 +226,18 @@ config CROS_EC_SYSFS To compile this driver as a module, choose M here: the module will be called cros_ec_sysfs. =20 +config CROS_EC_TYPEC_ALTMODES + bool + help + Selectable symbol to enable altmodes. + config CROS_EC_TYPEC tristate "ChromeOS EC Type-C Connector Control" depends on MFD_CROS_EC_DEV && TYPEC depends on CROS_USBPD_NOTIFY depends on USB_ROLE_SWITCH default MFD_CROS_EC_DEV + select CROS_EC_TYPEC_ALTMODES if TYPEC_DP_ALTMODE help If you say Y here, you get support for accessing Type C connector information from the Chrome OS EC. diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Mak= efile index 2dcc6ccc2302..aec2d043a0fe 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_CROS_EC_TYPEC_ALTMODES),) + 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..0f3bc335f583 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 @@ -290,15 +291,15 @@ static int cros_typec_register_port_altmodes(struct c= ros_typec_data *typec, struct typec_altmode *amode; =20 /* All PD capable CrOS devices are assumed to support DP altmode. */ + memset(&desc, 0, sizeof(desc)); 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 +576,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 +1259,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..bb7c7ad2ff6e --- /dev/null +++ b/drivers/platform/chrome/cros_typec_altmode.c @@ -0,0 +1,281 @@ +// 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; + + struct mutex lock; + 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); + + mutex_lock(&data->lock); + + 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; + + mutex_unlock(&data->lock); +} + +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) { + dev_warn(&alt->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; + + mutex_lock(&data->lock); + + 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); + + mutex_unlock(&data->lock); + 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) { + dev_warn(&alt->dev, + "EC does not support AP driven mode exit\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; + + mutex_lock(&data->lock); + + 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); + + mutex_unlock(&data->lock); + 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; + + svdm_version =3D typec_altmode_get_svdm_version(alt); + if (svdm_version < 0) + return svdm_version; + + mutex_lock(&adata->lock); + + 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; + } + + mutex_unlock(&adata->lock); + 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->ap_mode_entry) + return -EOPNOTSUPP; + + 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); + + mutex_lock(&adata->lock); + + 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); + + mutex_unlock(&adata->lock); + + 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); + mutex_init(&data->lock); + 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.338.g60cca15819-goog From nobody Wed Dec 17 19:37:26 2025 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 C3BD3213E74 for ; Fri, 6 Dec 2024 23:38:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733528334; cv=none; b=UT8VcIvJmBy9aT6udFIQk557IBwUM0X4yd8+oUh7bUesvmezj0AYsLceY0YnTlXMS7Y227/am8gcVUKgHjcGAqxzGSVVoq7F2+dEHBakbHIHY5iRkSZt4EiBeXB6ZfjY0XxiAzWZiT7hfQR1CuzuLbgGHyD6rLpRDQfcF1YuVck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733528334; c=relaxed/simple; bh=6+NyEvL6eAZBPFSmY7mhSC2CsuuggjLJwPgnKwMrMFU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lU1gbLOxySc2s3BMtOocj4mgKWV74ymXP8D4fyBrbP/vD9sON9N1bU3Eq/8ifaD8WJAVxmV14oZCJruPLdrdTxIkB+klk80GA8+724Vw1EbmGav4mxW4Ec19wyCNjafJ2X29rrxBua6Y4e0zerg/rNgSWpfnI2keHfb2uo9s4iI= 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=DPwSNaB0; arc=none smtp.client-ip=209.85.210.178 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="DPwSNaB0" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-725abf74334so2252038b3a.3 for ; Fri, 06 Dec 2024 15:38:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733528332; x=1734133132; 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=0cXxXwV88rKJWL8fa6OSxTwQgplbClYmPHZMXrsR3gI=; b=DPwSNaB0gyrQBqYinkChfZrOzrdPAbbX5H5qjmwvGY5iQ2LvcjNnbtfGwa/vC71zJM jyiEPoCAZ7tZkPOvS3HcldaqscaJDGkDIAuwFVMQXcBAMg6HyWMEXwwzKYCRBNA2Dl1P IONJEDSxZNtYgXC/nIQ2CkaUZrFefMhATZrKU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733528332; x=1734133132; 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=0cXxXwV88rKJWL8fa6OSxTwQgplbClYmPHZMXrsR3gI=; b=pRFW+4Xl6H7TBJEY+WiJbie58x5PJYFAVKWq7KTR4IwGVjh61mphKk/EcZe5T06Ow0 21FKvGE0RQLUqwhG5N8K6p3p6Std+dJaslcHm1Scy3ykMUt1F7iB71NR50f16k945eZq WswQvVAITa36L8dq5XqDgweXYRoExgjaJU1moOkbqt2is7iy0XHhfpqBSvpSiBG7LrYY pEBOTqphBbbfyDyNThmuMFDifrqJXLEcd+BBVGnNBS7JAl5LXhAOPNq746J85zFW5MGY ByrMvRG8mCmPQLWV2SqmrhPLz/VvOoTN6ykgmtyCjxZZWaO3kBqG6HNYSAtj8IAIJsxW 2RTA== X-Forwarded-Encrypted: i=1; AJvYcCXtLPHHAondQLYM4I8JyJ21r/Fc98kSRecKLldXXiHNB41tA/KfjW0+fKjfTpp1GAaR226bZyVtqHZuwLY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz+RdmWt1a4tllq9t/YX0EHeSkMnwsOusygE5ZEP9bTMrHCTdRJ Q+aQMADNz6GALk3jt8ob8eSK1zk/voRNT+Uq5SOJF12qtUq2X1RzpHHO8ACQsw== X-Gm-Gg: ASbGncueSJYSoKothJJqk7uHZU1qwV28PqDt3Wiaq59VHYLrdMm4Mjf3kDd8uwZe37S HUg/tAe8hQQ+56SblYdAAkC27/xW18AM43QvAafIE7XRU87Avf6WkusqUgjYhO48kqhbwE+ycmp L0IPh+MFZddus0uZn9tOXeNlvHfDIKisOKkeV2U4Vu9jS5jMYUXWJART+Lec1gZEJVvUqNxhdLC 5zAE5nUdfSn+qRqpDBkoKPayUf4b7ZUwz3wp2pA3sBMPsl9vKg29g4VycLUfpxGONfG3Efq21Cq dH9J1RD2+tt2S8HrTMED/gnl X-Google-Smtp-Source: AGHT+IH8xcV7cYwWQtC1JOe0BM7HHwigw7bQUPK2dXGpE1ZFhAik0USRvFsiz7kjlqwsVcZvthr8sQ== X-Received: by 2002:a05:6a00:2d0b:b0:724:6cd2:cdcf with SMTP id d2e1a72fcca58-725b81f2d33mr7077111b3a.24.1733528331999; Fri, 06 Dec 2024 15:38:51 -0800 (PST) Received: from localhost (227.180.227.35.bc.googleusercontent.com. [35.227.180.227]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-725a2cc52f9sm3469025b3a.172.2024.12.06.15.38.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Dec 2024 15:38: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: akuchynski@google.com, pmalani@chromium.org, jthies@google.com, dmitry.baryshkov@linaro.org, badhri@google.com, rdbabiera@google.com, Abhishek Pandit-Subedi , Benson Leung , Guenter Roeck , linux-kernel@vger.kernel.org Subject: [PATCH v4 6/7] platform/chrome: cros_ec_typec: Thunderbolt support Date: Fri, 6 Dec 2024 15:38:17 -0800 Message-ID: <20241206153813.v4.6.Ic61ced3cdfb5d6776435356061f12307da719829@changeid> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog In-Reply-To: <20241206233830.2401638-1-abhishekpandit@chromium.org> References: <20241206233830.2401638-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 v4: - Update Makefile + Kconfig to use CONFIG_CROS_EC_TYPEC_ALTMODES - Add locking in vdm function 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/Kconfig | 1 + drivers/platform/chrome/cros_ec_typec.c | 23 ++--- drivers/platform/chrome/cros_typec_altmode.c | 88 ++++++++++++++++++++ drivers/platform/chrome/cros_typec_altmode.h | 14 ++++ 4 files changed, 115 insertions(+), 11 deletions(-) diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kcon= fig index 984f843ea7a2..3eef4b5c2f60 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -238,6 +238,7 @@ config CROS_EC_TYPEC depends on USB_ROLE_SWITCH default MFD_CROS_EC_DEV select CROS_EC_TYPEC_ALTMODES if TYPEC_DP_ALTMODE + select CROS_EC_TYPEC_ALTMODES if TYPEC_TBT_ALTMODE help If you say Y here, you get support for accessing Type C connector information from the Chrome OS EC. diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chr= ome/cros_ec_typec.c index 0f3bc335f583..0b87be52e1db 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -303,18 +303,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 bb7c7ad2ff6e..4db655465a86 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" @@ -70,6 +71,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 @@ -194,6 +197,56 @@ 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; + + mutex_lock(&adata->lock); + + 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; + } + + mutex_unlock(&adata->lock); + return 0; +} + + static int cros_typec_altmode_vdm(struct typec_altmode *alt, u32 header, const u32 *data, int count) { @@ -205,6 +258,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 @@ -279,3 +335,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.338.g60cca15819-goog From nobody Wed Dec 17 19:37:26 2025 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D49521507A for ; Fri, 6 Dec 2024 23:38:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733528335; cv=none; b=CQsSYnSRQU0JqCx9YvxhVDeTU55PBxWEfCEMYj3YUzv+6AvWC1d5jBqZr2JPZInMFQeWAXyN+hmhPmr5YFG56Ks4ycV3ctARIIERGK+gdu1SJzHrdDsb4T1nARk1iRIBl/HTLreLeDOhzOv4MZxF3tEGW2vT+8ZoKAdlmKn27nE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733528335; c=relaxed/simple; bh=Ulzg2xjkFRD+wiTK/aYzwa6zKISjF0fC6sX0+p179fU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gRAOiBJPn0HtcFzJTQkidu9LoFah3jV+HpwWq8q5RhOHNyuCwGUPQfQJwCvkldBjZNJKuSwTpy0XMJWRRWVowuqTIAWxE6O8YrX5P3wfxFdh1wURPPhC5np2x6Azu0pLv/+3THQmdy0Zpd4eLMHkP5LxTayRjYs5iWtS3GbmYVc= 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=Mkia7qtb; arc=none smtp.client-ip=209.85.216.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Mkia7qtb" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2ee709715d9so1912563a91.3 for ; Fri, 06 Dec 2024 15:38:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733528333; x=1734133133; 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=M7ywRolWY01/rWUFSkYNRJ4dfXAYAQRxZrdC+AkeGz8=; b=Mkia7qtbbAYsJnWuRQW3YE7McQb5m37n4t+1A0y9k6j1GcdGk2K+cpWVtq6F9Z9m1P e32wjOAB9QVFD2Lt4JEkXx/FmU5b3wgXRbogGWFzVB8tx6/Cay+2K8LVWTKMpcclUQ4M WR+Yx1v+a3Z0luCJtO7Vk7UW6DW7t/m/iYOUI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733528333; x=1734133133; 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=M7ywRolWY01/rWUFSkYNRJ4dfXAYAQRxZrdC+AkeGz8=; b=FTw/2iq7kkzGCEVIe7yubLZ2zYp8GIP/3ieMgJKlb2wTZigNwB8oGvoYQZ6kmayDWb EkXfRMpVRJoSHBw2CJoCXoDWe8rBDdj3zqFaU9eoiTq7AaGMZzfzyGR9Wsr3Lopb9E3E JAZL3nuwrBiTqf+MRSh76JwZqvfNQI0tLaapeWxQAs0yhbU5QPWuB/qij9AeVyTNpvpK OCyDCJPHOSJMCGJKyDXVqRg3sCQT4UluCYbMOyA4VI2Rp20R1KBJWTPTNcP5so95kBJu iWymEBY0Zq3Wi7GMVqudahqCpmk9RsKLw0CCpVsekLyXaT8J9hGksh7KQeFIxW7/g8N/ OW7Q== X-Forwarded-Encrypted: i=1; AJvYcCWhY3IwQloAmlmvTMlvEukMefe7HmJhtlh1ZiE8zBBPwohGLOO47Y160w0LBeTt90Q/g5YeNKxlGQ4XwUQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyhJlcY7OPRBNTi8OLROUCfIPFdCO7X5cU4jC8DIZ1XqzeEm8FE oZ/Y9puvzIDX5Zt8xGw4AEdmF1p/2eC5Ff430l/laWtEAkLUjn2tW61+bR16Bw== X-Gm-Gg: ASbGncu31thBLW5ufIhRj25XCzMkjvRQwdjdiDEf+PEHFRhmLk2I9LjPivxxdFUeXVe IfRzdMeGwIuVSjCdPvTZXbqJd+GapGr8/N5TLTq8yg67+VuvIIk5PN+MoLxfBIZskTKxFfYfNJ+ TNTs8D8YZEsLnwn4CpiVmaCwnlbap0rmzVOmPwQJhHccClQOQIUtGrz0TeBO8rdJPt/62pjxELv wymmDY0IeI6QLKaSqFaJ1Wv2DoQn215aHIHa9hB88VIgn4/G0Th5iQSoQU6ZxAdJyQyyKQviPFQ G30mSG8L1JES0cMhBnu3iMDt X-Google-Smtp-Source: AGHT+IE2pYezOEFHi20tWshTX8jQdgxLAviowJebOf0BsxXK7byF4aVYK7F4ypRAUugG9hj/xkBzoA== X-Received: by 2002:a17:90a:d445:b0:2eb:140d:f6df with SMTP id 98e67ed59e1d1-2ef693676demr7738327a91.1.1733528332939; Fri, 06 Dec 2024 15:38:52 -0800 (PST) Received: from localhost (227.180.227.35.bc.googleusercontent.com. [35.227.180.227]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2ef4600ead7sm3702702a91.53.2024.12.06.15.38.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Dec 2024 15:38:52 -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: akuchynski@google.com, pmalani@chromium.org, jthies@google.com, dmitry.baryshkov@linaro.org, badhri@google.com, rdbabiera@google.com, Abhishek Pandit-Subedi , Benson Leung , Guenter Roeck , linux-kernel@vger.kernel.org Subject: [PATCH v4 7/7] platform/chrome: cros_ec_typec: Disable tbt on port Date: Fri, 6 Dec 2024 15:38:18 -0800 Message-ID: <20241206153813.v4.7.Ic14738918e3d026fa2d85e95fb68f8e07a0828d0@changeid> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog In-Reply-To: <20241206233830.2401638-1-abhishekpandit@chromium.org> References: <20241206233830.2401638-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 --- (no changes since v3) 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 0b87be52e1db..743cb5a9fe51 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -311,6 +311,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.338.g60cca15819-goog