From nobody Fri Nov 29 00:38:11 2024 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 A5C6C3B298 for ; Wed, 25 Sep 2024 16:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727281518; cv=none; b=MoKOgDgl7zgFEZy+9Yj+6uVFmbXECHoLkMLnta7/z/veCF1gjfhIjukjFCTl9KiBq2Mm/S3OiTSbqmwuYFh6C2YABI8jq817HIMBLjqj4mttp3xXr1QclPcWI7XtMmmuNb1o6NwB8Q0JXf+OMexOsF1eryb6v/5aJwhm68P71ks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727281518; c=relaxed/simple; bh=T4RnOjnnRlXT9AkkzqwUs+wqJYYyJuCdRXXu/NmJ5tw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eSk0rGvGa3S2xkPRoa+0cLPLxL0t5fUYScPzydynYnA5BFjckkRuAV3f+gdvb+hDWR8DESAk975PSyiNUr6CvmH4obV3lCt8SS8ZZ0BlM5TIS0S//UjGgaK7nw8GWmIkZPTPxJE+C+nBqVECMZgjcpm84UXsynSeYrMSNIr0Ma0= 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=Drju13rI; arc=none smtp.client-ip=209.85.210.179 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="Drju13rI" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-71b08405187so74807b3a.3 for ; Wed, 25 Sep 2024 09:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1727281516; x=1727886316; 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=v+fzEPtpiDuBZH77Ojs0eNit0iDR4Bt4bD2UwQhL7js=; b=Drju13rI7uOnThPXYGqAok5hHbtACcIHSJDAB1hqIRSCSNN0KwiX1JsDBL4cYhhhp5 zci7w6ubMBpb7tIzyUNE14vRddvvH4653EcKu6RayZyhZJVSd5JkoRxCDQ2e8sSFdHpw WS24Detq1T6EbsIJs2L004Ux6EfzL5hlJObNA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727281516; x=1727886316; 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=v+fzEPtpiDuBZH77Ojs0eNit0iDR4Bt4bD2UwQhL7js=; b=uwx61SAkW2lZ4hzlnkxb679Yx/vMADRCFvEx2DzDDLpjTaXqa7J3kj2L8qgln0Mrsp CiD1UoXLXxQsW13/BbE7T4LHd5hl3El41fk1WMB5RY5SH1zLUqsV3ncN2ZC17Am7A3oW WOwxshbQEUlLEJnPPy9C4BqfW4CubddsfiiK8kLcUU1R4vSEP2HvcMpq8rnbIGGgeJv5 vhAi50KcCw3vdpFx1tM6wi6g2+u7YAft4M6Q5P3VZF7YB5NnDYI4a9v3qjN6mPFPgjfC LeeM9n+JL7Jlv1gZXAWWUiMFFL8y4r75FtB+FMmVZ5OQ/0Gap7w70BNbGzi5wc8Sfqg9 iGvQ== X-Forwarded-Encrypted: i=1; AJvYcCXiP2dNxRL1slFN/Yl+cMIL528XBJOxJbwCES9nkS6tWfzhpfdJCscQS+ZC8VuPFMd2MDxDKC85VqrG+w4=@vger.kernel.org X-Gm-Message-State: AOJu0YxtBvNstOch079nbXai8AujSjcoKw5bPm19H226D7BCkBvG1nvW +AXh9NHuN2Po9zIwajbQ6smwONtrRQpNlbILUm7alyqnSSZmTZ8eUPkJDvNSIQ== X-Google-Smtp-Source: AGHT+IG75Vy5hIcFYdYhSgVz+KBWwgeHqFcnz9r+B+MSJzNpY0kWW+NHCzlYyYQL8Grxr4Ppix+Dag== X-Received: by 2002:a05:6a00:2292:b0:717:950e:b589 with SMTP id d2e1a72fcca58-71b0ac57543mr5840836b3a.19.1727281515857; Wed, 25 Sep 2024 09:25:15 -0700 (PDT) Received: from localhost (226.75.127.34.bc.googleusercontent.com. [34.127.75.226]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7e6b7c3f161sm2912617a12.27.2024.09.25.09.25.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Sep 2024 09:25:15 -0700 (PDT) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org Cc: jthies@google.com, pmalani@chromium.org, akuchynski@google.com, Abhishek Pandit-Subedi , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 1/8] usb: typec: Add driver for Thunderbolt 3 Alternate Mode Date: Wed, 25 Sep 2024 09:25:02 -0700 Message-ID: <20240925092505.1.I3080b036e8de0b9957c57c1c3059db7149c5e549@changeid> X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog In-Reply-To: <20240925162513.435177-1-abhishekpandit@chromium.org> References: <20240925162513.435177-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 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. drivers/usb/typec/altmodes/Kconfig | 9 + drivers/usb/typec/altmodes/Makefile | 2 + drivers/usb/typec/altmodes/thunderbolt.c | 321 +++++++++++++++++++++++ 3 files changed, 332 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..515e775ee41a --- /dev/null +++ b/drivers/usb/typec/altmodes/thunderbolt.c @@ -0,0 +1,321 @@ +// 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 + +#define USB_TYPEC_VENDOR_INTEL 0x8087 + +/* TBT3 Device Discover Mode VDO bits */ +#define TBT_MODE BIT(0) +#define TBT_ADAPTER(_vdo_) (((_vdo_) & BIT(16)) >> 16) +#define TBT_ADAPTER_LEGACY 0 +#define TBT_ADAPTER_TBT3 1 +#define TBT_INTEL_SPECIFIC_B0 BIT(26) +#define TBT_VENDOR_SPECIFIC_B0 BIT(30) +#define TBT_VENDOR_SPECIFIC_B1 BIT(31) + +/* TBT3 Cable Discover Mode VDO bits */ +#define TBT_CABLE_SPEED(_vdo_) (((_vdo_) & GENMASK(18, 16)) >> 16) +#define TBT_CABLE_USB3_GEN1 1 +#define TBT_CABLE_USB3_PASSIVE 2 +#define TBT_CABLE_10_AND_20GBPS 3 +#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) + +/* TBT3 Device Enter Mode VDO bits */ +#define TBT_ENTER_MODE_CABLE_SPEED(_s_) (((_s_) & GENMASK(2, 0)) << 16) +#define TBT_ENTER_MODE_ACTIVE_CABLE BIT(24) + +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]; + + 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); + } + + 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 { + typec_altmode_notify(alt, TYPEC_STATE_MODAL, + NULL); + } + 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_VENDOR_INTEL, TYPEC_ANY_MODE }, + { } +}; +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 v2"); +MODULE_DESCRIPTION("Thunderbolt3 USB Type-C Alternate Mode"); --=20 2.46.0.792.g87dc391469-goog From nobody Fri Nov 29 00:38:11 2024 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA17C44C86 for ; Wed, 25 Sep 2024 16:25:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727281519; cv=none; b=DOj3uq45OwkyKWbc0KpYRvQvXDmzXqsmZRUJP9DLCdAINsOIHI7dcavTQNZ6IxEl+cARZXcbwVd3iIO6ZI7cnTw4C1vQRdHiuyVXEBQ6CIwyNdf5FehjuxK7O3Y+FtvoF6RGFtj1Bfc2AS5YLQeqsrwo0TzjMF7VROwCiH3YXhY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727281519; c=relaxed/simple; bh=+2FSnKyNki+fw/fhnexvjl1DNdJwIpxfKSde39h02Gw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b99QxA6TfVrVNPzfIn3z0qd+EhOocWX2svxcpFCk92PSUhi7m9A6S92ov2+KEnb+X0b0NQkJIBvUBKogiRzTPjiHANAHhYL76UKkQWT1iE9stJrdJevbpABIMTeDlx1w+hBd2nVKmLOCX68ZNTRewCounuy7HmeeNshyhxdsZCw= 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=hET3XnAM; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="hET3XnAM" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2e08a0679b1so68342a91.2 for ; Wed, 25 Sep 2024 09:25:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1727281517; x=1727886317; 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=+mQegUT00US8bGAhFrzBaDDODW/YQTCJrsGeC6HyUig=; b=hET3XnAMejBpTEn7kA7S66NEHupBV8vQRoNFZgUNsve5JoLvTRyb/XNf+CsjuNTHvI 5j3Lu83rgRbPo0vuviKn3otCHyE0cK2N6MRQGscPsOj2aTlTnB4dts9YHyirG6hddJD/ 3WiuRlQxoveqmfCPVARDq4eUzcFJd5l4P7rS8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727281517; x=1727886317; 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=+mQegUT00US8bGAhFrzBaDDODW/YQTCJrsGeC6HyUig=; b=LUoiK7sHLg5MvEG8SfY6Qs6U6ZRCGzLLdEwbSnY2KPvDVXWyQPYu4vFtPpXBpjSpm2 FcQAxT4qpk+I6iiBNlciWwdynAPtqB2j8JTVk1rjzUtdaATZa3RjP6E0mmK5LElXwQWB ixpVqViyYfBHToDh4FGNL1PTaoE5JKP8iB/Siz3vq7skYvunzhkEGI2Hm2pMn7Yh4AkY CfhTSHsuaegfFQX4JcbldWE4XzG21iKEOvuit1WxChGXIUDnPnRfiUpupmArVEqICW0G KcUiHx0AVKdhG/2XwXG4TsKORtbMPoQadYxlpUEMOZ+shp0E2GekoojDWrbnCo4FHtXS +0bQ== X-Forwarded-Encrypted: i=1; AJvYcCUB/WM9Ox9fuH7k/nJe1qJosHRT7mT3/cdmKYURvnBcMd9By9CIw1/nlrDYM0zAH/d3ehGfDW4u1Epe0zs=@vger.kernel.org X-Gm-Message-State: AOJu0YwE1lYoLrjIkwhhnYicxZ/izkQ9vHFwTrlH48jSuCi1x533UHG8 x3ALRLRLgvSBQ649T88e5rMDrtAStmuCNhuj/fxjZU1CkvS+LbMf7Vc6rU/8lQ== X-Google-Smtp-Source: AGHT+IGPeP9YvzCBtyDelDQm+zN1EEUMTA4n09WeOUuCb+QBT8Nn/5HPs5f7loDRRi7Ku1Gj6nZnTQ== X-Received: by 2002:a17:90b:17c6:b0:2cf:fe5d:ea12 with SMTP id 98e67ed59e1d1-2e06ae7b726mr4165481a91.24.1727281517224; Wed, 25 Sep 2024 09:25:17 -0700 (PDT) Received: from localhost (226.75.127.34.bc.googleusercontent.com. [34.127.75.226]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2e06e31477fsm1705449a91.54.2024.09.25.09.25.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Sep 2024 09:25:16 -0700 (PDT) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org Cc: jthies@google.com, pmalani@chromium.org, akuchynski@google.com, Abhishek Pandit-Subedi , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 2/8] usb: typec: altmode_match should handle TYPEC_ANY_MODE Date: Wed, 25 Sep 2024 09:25:03 -0700 Message-ID: <20240925092505.2.Ie0d37646f18461234777d88b4c3e21faed92ed4f@changeid> X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog In-Reply-To: <20240925162513.435177-1-abhishekpandit@chromium.org> References: <20240925162513.435177-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" altmode_match is used when searching for the first port altmode that matches the partner or plug altmode. If the port registered with mode set to TYPEC_ANY_MODE, it should always match if the SVID matches. Signed-off-by: Abhishek Pandit-Subedi --- drivers/usb/typec/class.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 9262fcd4144f..179856503d5d 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -230,7 +230,8 @@ static int altmode_match(struct device *dev, void *data) 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) && + (adev->mode =3D=3D id->mode || adev->mode =3D=3D TYPEC_ANY_MODE)); } =20 static void typec_altmode_set_partner(struct altmode *altmode) --=20 2.46.0.792.g87dc391469-goog From nobody Fri Nov 29 00:38:11 2024 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1703F4C618 for ; Wed, 25 Sep 2024 16:25:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727281520; cv=none; b=EWTpzquot9PosndbwJJhTZWPBSV69Dr0xvQ3DzwCyl6oYAsRkgIBK3akxs6ixLt6qfmyYoABFPU9xfB4LeUy6L/vqVgn99JFxZgUY1ooQeB8fjx+Xc4nQ09TYfrmhRZgTYFzN5lG8jzurKe3j4VZrFju2XMBC8itbuUQ7U1Vxj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727281520; c=relaxed/simple; bh=B/aYBTa60A9g90oBOpffUDM7pG4axnORwfirwaLuURI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YEVwli6o40fACbZoACDJbWd6+6M1B309FrVvuI3FA6WH2gi27q29TIUajH5ME7bY9qCTi55e35jDHJqJKqjsPPMrWfNS2PZRIoN0+JmWm9+/PFGofFZoSAlT+hF1zfr8j+VAT8f1+3qawH7yoeNnEFTU96zgaKENohr/Gq7lBhw= 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=CeItgtvB; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="CeItgtvB" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-20b01da232aso676285ad.1 for ; Wed, 25 Sep 2024 09:25:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1727281518; x=1727886318; 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=li8IhGzdBecmdmZEMsV/NksrzGw4yHw1ja6oPqU+zCY=; b=CeItgtvB2mVjg7AZzpg/MNIpruRwGVF5e0cMpKNL9fG05Tsl8K9HdONfCshVW6ZiHX K9jUywR71TygRNecDH9mhFmhI/guIShGQyYELN0gJUCuUcSssSHOHBhg1A1oVUK1ZuMV WF8UylFgWmKR3HhDjA5nnwd4uWaTScvqiHa0E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727281518; x=1727886318; 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=li8IhGzdBecmdmZEMsV/NksrzGw4yHw1ja6oPqU+zCY=; b=DGj7pDdq8QeyRKRFVKViAmLPArdoCIbPg1wAg86cmcrefYZaGfSXUvC49puXkw4Wox +S9MrdUA0HCcUMMU2sqg6Ny6b/w15GEvqNrear1ce7rGUzJ+Oqgx4zO709Mhtwu2n8++ ycAJtfiZ2nPnjjdiyJGAiz+0iCrFXhIgHYnswTwGOxAInSuGuKNAZEq7Lg6xY8OgWCz3 H+Kf786xw15r9e1qxwdnn8JFoCoWiubyr1dAcjSC9jKm6OZuOKGCs/Squ3oktNPRH7E6 kst06vOOyAEffYdDufHk/0uJilbXByQ80iGeasUuT1GqfSroMmBYiuRzc8nP4pgsGVDm FUtw== X-Forwarded-Encrypted: i=1; AJvYcCW4llCOqjvxtcsedorMsMefOTQgXgCyf8AzKEKIPIkz4sHP1+G51Dh49plyGHuCvuKvnFOBfffO19M+TKQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxzOcR9thVySAkQQWii3VPf7Fxda3lX0dbESq2B7TqS+fHFjUvS D0evAoHANhyB6L7n5ZDnJCoJL6H4g8z8cQi3i/QMvcuC1x5bTr+455zgUEip/w== X-Google-Smtp-Source: AGHT+IFMT5cF7Fy101YbQOPVWEhNSeZB2W0BjXha7Z4XNH7qjSAj0pLjLalziUhJFRR8caZAYC5Zfw== X-Received: by 2002:a17:903:28c6:b0:205:841d:1221 with SMTP id d9443c01a7336-20b19c6f3f0mr1932145ad.24.1727281518406; Wed, 25 Sep 2024 09:25:18 -0700 (PDT) Received: from localhost (226.75.127.34.bc.googleusercontent.com. [34.127.75.226]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-20b0e4ed6c2sm7061535ad.271.2024.09.25.09.25.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Sep 2024 09:25:18 -0700 (PDT) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org Cc: jthies@google.com, pmalani@chromium.org, akuchynski@google.com, Abhishek Pandit-Subedi , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 3/8] usb: typec: intel_pmc_mux: Null check before use Date: Wed, 25 Sep 2024 09:25:04 -0700 Message-ID: <20240925092505.3.Ib7a83adb069df1cb0a40dcddff29618bf3255700@changeid> X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog In-Reply-To: <20240925162513.435177-1-abhishekpandit@chromium.org> References: <20240925162513.435177-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" Make sure the data pointer in typec_mux_state is not null before accessing it. Signed-off-by: Abhishek Pandit-Subedi --- drivers/usb/typec/mux/intel_pmc_mux.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/mux/intel_pmc_mux.c b/drivers/usb/typec/mux/= intel_pmc_mux.c index 56989a0d0f43..4283fead9a69 100644 --- a/drivers/usb/typec/mux/intel_pmc_mux.c +++ b/drivers/usb/typec/mux/intel_pmc_mux.c @@ -331,14 +331,19 @@ static int pmc_usb_mux_tbt(struct pmc_usb_port *port, struct typec_mux_state *state) { struct typec_thunderbolt_data *data =3D state->data; - u8 cable_rounded =3D TBT_CABLE_ROUNDED_SUPPORT(data->cable_mode); - u8 cable_speed =3D TBT_CABLE_SPEED(data->cable_mode); + u8 cable_rounded, cable_speed; struct altmode_req req =3D { }; =20 + if (!data) + return 0; + if (IOM_PORT_ACTIVITY_IS(port->iom_status, TBT) || IOM_PORT_ACTIVITY_IS(port->iom_status, ALT_MODE_TBT_USB)) return 0; =20 + cable_rounded =3D TBT_CABLE_ROUNDED_SUPPORT(data->cable_mode); + cable_speed =3D TBT_CABLE_SPEED(data->cable_mode); + req.usage =3D PMC_USB_ALT_MODE; req.usage |=3D port->usb3_port << PMC_USB_MSG_USB3_PORT_SHIFT; req.mode_type =3D PMC_USB_MODE_TYPE_TBT << PMC_USB_MODE_TYPE_SHIFT; --=20 2.46.0.792.g87dc391469-goog From nobody Fri Nov 29 00:38:11 2024 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 069E86F305 for ; Wed, 25 Sep 2024 16:25:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727281521; cv=none; b=iQBFFZbi8KLrEZEdYrtpZPmuUYFjZqTiphl1Hs7l55JqpjpRIxJr/OMlkMzXEexFcGM4xf1Y52gbijDpMVKVhnlxfQCuLdawqpkVSHtJeDYEb4AyjpwkYzVTeZRaR0k1kF/MYWo6oSPzr4apcrXer7iDMTksFbGUtZ2wmqTbwFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727281521; c=relaxed/simple; bh=bTqNKaJ0zrSNVrgzbJdNqFzrk1uq/TCe0Tw0ffqNEi8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kp8iB0DRm+tSYS/QgmninyIBGJNd6qDIxgvfkXlqWn+0eYMhf8wtUECdNHKnNnqU0Vy9VR5ZMgpJWkDMbVZ5uyRR0civBqAmE4MAGBfT+mOgTd/l/wb3Sv+P68zMui8YXZJxW4ZlyVj8Un7GOFBcvkRFoq5ghxd0EryzD5sorv8= 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=FPkWzjSk; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="FPkWzjSk" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-20b1335e4e4so4678245ad.0 for ; Wed, 25 Sep 2024 09:25:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1727281519; x=1727886319; 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=soh9tpwQeZYCRkIZ0qsRPLYdoMt3WX+ET4bADOa1Pug=; b=FPkWzjSkyeTHv7HGzlx50ZCWX8Y9VF7D3DDzZwIo4yFztfNIsTJk6j7Wc4LVLkQsTp YgXg0Q527zkFecQSh+1DE3jKxWQ3VHzn+/vfMZNmAHoC1hYHjUv78IrMCp+MPrb0BWni xw5K/S0TLywDGF9i6ge5Fo+dhkUemUT8DVT7Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727281519; x=1727886319; 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=soh9tpwQeZYCRkIZ0qsRPLYdoMt3WX+ET4bADOa1Pug=; b=XPRmYye7FPjzFZHFSl5QhybAlRnWiVU5uYZdvXlWxFu1heE7bsEhEZzeslYtOL66Bw +EfnTQh3jAhraj2Xg90Nw6MWQZZbUAs8Epv6naGC4MDA16akPwLBqw/dNVUTn3Qa0MQM BpJVVAlYxAXCZV594pndoSUigO3E3KzgfHDY8PjAkeU6j9CF1EPn5j+Sq72oWd/hn87k NNkJZRacooR+gViI+PiCUe7c3EQ5Gb4R9L+nv8Nb9Br/U9oULZSXNxp6G+gqMIeY6UGy I3qGj4qZt7san0LOtPZJwQ37Jn7CSGB86PBlgTf5HJUYt0luiQZXf7k8y9X4O7DZYOmq Z2kA== X-Forwarded-Encrypted: i=1; AJvYcCV5kb8YPE1FvxgQ/0mMzxnwBNCHTmRspIABQ4J4p15tehKX6UIVm8+OXgNIvSxJxM+4sbpQ64eTBDQ4sMU=@vger.kernel.org X-Gm-Message-State: AOJu0YykMVCECN4W8ArmHWoQYyZwra9O+wVPZdw3pp6VZqyYjlrAIFCe qwchASgZ6cnhtpLKhX0Eh2PjySWLGW8zaiFrPLpmRWPxj4qyj87040Qek+jGUA== X-Google-Smtp-Source: AGHT+IGr3cGE4FriIync0xkl+vrO6tr5K8eOoarCEoEgywCGg+W4iCeJ35U6sKFdtVDSZmLZ3EJmfg== X-Received: by 2002:a17:903:11c4:b0:1fd:69e0:a8e5 with SMTP id d9443c01a7336-20afc4c83c5mr46503105ad.41.1727281519237; Wed, 25 Sep 2024 09:25:19 -0700 (PDT) Received: from localhost (226.75.127.34.bc.googleusercontent.com. [34.127.75.226]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-20af17dffdasm26422195ad.176.2024.09.25.09.25.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Sep 2024 09:25:18 -0700 (PDT) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org Cc: jthies@google.com, pmalani@chromium.org, akuchynski@google.com, Abhishek Pandit-Subedi , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 4/8] usb: typec: Auto enter control for alternate modes Date: Wed, 25 Sep 2024 09:25:05 -0700 Message-ID: <20240925092505.4.I439cffc7bf76d94f5850eb85980f1197c4f9154c@changeid> X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog In-Reply-To: <20240925162513.435177-1-abhishekpandit@chromium.org> References: <20240925162513.435177-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 controls for whether an alternate mode is automatically entered when a partner connects. The auto_enter control is only available on ports and applies immediately after a partner connects. The default behavior is to enable auto enter and drivers must explicitly disable it. Signed-off-by: Abhishek Pandit-Subedi --- Documentation/ABI/testing/sysfs-bus-typec | 9 +++++++ drivers/usb/typec/altmodes/displayport.c | 6 +++-- drivers/usb/typec/altmodes/thunderbolt.c | 3 ++- drivers/usb/typec/class.c | 31 +++++++++++++++++++++++ include/linux/usb/typec.h | 2 ++ include/linux/usb/typec_altmode.h | 2 ++ 6 files changed, 50 insertions(+), 3 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-bus-typec b/Documentation/ABI/= testing/sysfs-bus-typec index 205d9c91e2e1..f09d05727b82 100644 --- a/Documentation/ABI/testing/sysfs-bus-typec +++ b/Documentation/ABI/testing/sysfs-bus-typec @@ -12,6 +12,15 @@ Description: =20 Valid values are boolean. =20 +What: /sys/bus/typec/devices/.../auto_enter +Date: September 2024 +Contact: Heikki Krogerus +Description: + Controls whether a mode will be automatically entered when a partner is + connected. + + This field is only valid and displayed on a port. Valid values are boole= an. + What: /sys/bus/typec/devices/.../description Date: July 2018 Contact: Heikki Krogerus diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/a= ltmodes/displayport.c index 92cc1b136120..7b164086bbbb 100644 --- a/drivers/usb/typec/altmodes/displayport.c +++ b/drivers/usb/typec/altmodes/displayport.c @@ -767,8 +767,10 @@ int dp_altmode_probe(struct typec_altmode *alt) if (plug) typec_altmode_set_drvdata(plug, dp); =20 - dp->state =3D plug ? DP_STATE_ENTER_PRIME : DP_STATE_ENTER; - schedule_work(&dp->work); + if (port->auto_enter) { + 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 515e775ee41a..ba2ddaf3245e 100644 --- a/drivers/usb/typec/altmodes/thunderbolt.c +++ b/drivers/usb/typec/altmodes/thunderbolt.c @@ -225,6 +225,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); @@ -239,7 +240,7 @@ 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)) { + if (port->auto_enter && 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 179856503d5d..a7ae0cdecca0 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -397,6 +397,31 @@ static ssize_t active_store(struct device *dev, struct= device_attribute *attr, } static DEVICE_ATTR_RW(active); =20 +static ssize_t +auto_enter_show(struct device *dev, struct device_attribute *attr, char *b= uf) +{ + struct typec_altmode *alt =3D to_typec_altmode(dev); + + return sprintf(buf, "%s\n", alt->auto_enter ? "yes" : "no"); +} + +static ssize_t auto_enter_store(struct device *dev, struct device_attribut= e *attr, + const char *buf, size_t size) +{ + struct typec_altmode *adev =3D to_typec_altmode(dev); + bool auto_enter; + int ret; + + ret =3D kstrtobool(buf, &auto_enter); + if (ret) + return ret; + + adev->auto_enter =3D auto_enter; + + return size; +} +static DEVICE_ATTR_RW(auto_enter); + static ssize_t supported_roles_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -440,6 +465,7 @@ static DEVICE_ATTR_RO(svid); =20 static struct attribute *typec_altmode_attrs[] =3D { &dev_attr_active.attr, + &dev_attr_auto_enter.attr, &dev_attr_mode.attr, &dev_attr_svid.attr, &dev_attr_vdo.attr, @@ -455,6 +481,10 @@ static umode_t typec_altmode_attr_is_visible(struct ko= bject *kobj, if (!adev->ops || !adev->ops->activate) return 0444; =20 + if (attr =3D=3D &dev_attr_auto_enter.attr) + if (!is_typec_port(adev->dev.parent)) + return 0; + return attr->mode; } =20 @@ -557,6 +587,7 @@ typec_register_altmode(struct device *parent, if (is_port) { alt->attrs[3] =3D &dev_attr_supported_roles.attr; alt->adev.active =3D true; /* Enabled by default */ + alt->adev.auto_enter =3D !desc->no_auto_enter; } =20 sprintf(alt->group_name, "mode%d", desc->mode); diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index 549275f8ac1b..67242355f78e 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -128,6 +128,7 @@ int typec_cable_set_identity(struct typec_cable *cable); * @svid: Standard or Vendor ID * @mode: Index of the Mode * @vdo: VDO returned by Discover Modes USB PD command + * @no_auto_enter: Only for ports. Disables auto enter which is default be= havior. * @roles: Only for ports. DRP if the mode is available in both roles * * Description of an Alternate Mode which a connector, cable plug or partn= er @@ -137,6 +138,7 @@ struct typec_altmode_desc { u16 svid; u8 mode; u32 vdo; + bool no_auto_enter; /* Only used with ports */ enum typec_port_data roles; }; diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_al= tmode.h index b3c0866ea70f..ab7c3ebe4926 100644 --- a/include/linux/usb/typec_altmode.h +++ b/include/linux/usb/typec_altmode.h @@ -18,6 +18,7 @@ struct typec_altmode_ops; * @mode: Index of the Mode * @vdo: VDO returned by Discover Modes USB PD command * @active: Tells has the mode been entered or not + * @auto_enter: Tells whether to auto-enter mode (only valid for port mode= ). * @desc: Optional human readable description of the mode * @ops: Operations vector from the driver * @cable_ops: Cable operations vector from the driver. @@ -28,6 +29,7 @@ struct typec_altmode { int mode; u32 vdo; unsigned int active:1; + unsigned int auto_enter:1; =20 char *desc; const struct typec_altmode_ops *ops; --=20 2.46.0.792.g87dc391469-goog From nobody Fri Nov 29 00:38:11 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 EA8CF82499 for ; Wed, 25 Sep 2024 16:25:20 +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=1727281522; cv=none; b=N8PpPAO3mISXJ8oTSYftdnfxOuQG8fwyNcm2bICwnKsK30gVruONN4x1OL+MV84TJgDJP9+Xl2lcJjFhv+HSUZdsk6rqSe0FQeGy2NS2brw/3gh9pa9YXD7uW5Md3HeR8BPl+/YkuvLEi3FqnNl1qmVZd23giuo86sztZ/wsHbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727281522; c=relaxed/simple; bh=5KNMEDZa878kPVqTQYAgt5rJ1bRAcDhbeuuRaAZ6pXg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uw+ZLfFB6Ffke1DwIkLw1YwQ+Q4keo6iQAaMPgZdKclsj9H7g4sQbt3ib84iMXAkJXiphzwcum+Cr1QThTxAK+VJ6ijHxkZU6VBeT3LyQTeSASHT2Hmy2oYj5eaZh2Q7+Bcop2tjszlbHSdFSCFBWR82mjkt7+MchfgN9ab01H4= 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=WRuEj+Rl; 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="WRuEj+Rl" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-718e285544fso85496b3a.1 for ; Wed, 25 Sep 2024 09:25:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1727281520; x=1727886320; 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=SUxUAUbV9VGCkZrJxGOz2FTlolmwHOuBYZDZ/Je7+jc=; b=WRuEj+Rlt6NjnPbOC7JFbZTUaxcPjkRfxM5odadzg5rQ8tbYlPYcihsf7LqOji8fKe jORq+U3RbGqhuLJ8Yo3CVmFDfYekk6M/zlEikb2JGvVQrgvoM8WLRaTSnuZLXKG2HYS1 LjA5ls5M8YbNCPm9tOKMmgc3yIZzH3yMmueUc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727281520; x=1727886320; 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=SUxUAUbV9VGCkZrJxGOz2FTlolmwHOuBYZDZ/Je7+jc=; b=LeIWPKDxZw1EgxztvYBaJMItmd8EcDCCDOFtTKeaSaBemAYISSu9OdpFtJd61blUdO XKoUvifVgSHmv0gOiPQqQt169bmkiXyC3uN8V1OUqTl5eTY9RLqOnHWVVsigBl2jaUT5 fFOEfZVFs/PEO+LPMfKKzJfODyFF3kxvsQjq5BDwomzYV4VsUYXE7QFYWXD8b3gVnTVP sQfdRVdCqO2WIZ6JQXCPtFpkBdzOHe2Rgu3l604Uix0A7YXgnk6JIZNA90fU6J3OcIVZ j0QGxeGobQQgR58oxSwTESnxOuGiNyVJBnDkZSnb8KPAjcIf9A1ECsfVV9XCmIvVn0vS XsoQ== X-Forwarded-Encrypted: i=1; AJvYcCWsB/hbRYoglQb5jnpWjI+osHQcpnPu7JheSInAHaM9toCDqqdJb00HI+FRhDHmhQAUiKFexMygLnB1W3w=@vger.kernel.org X-Gm-Message-State: AOJu0YzyPQhGAWpWuEWgyKV3leQTHs+6Hvyeo+RxsCj9aKjA6eQ49y3n moTc8hGrRhuWxUJRp1U3RgRTbJsk0uvx8fL9qF6SPPhnWr9pTvw+n8an8F2YPg== X-Google-Smtp-Source: AGHT+IGe9zjfGh22fxAYaBDNZiLrvl1zf40GR5xv1xmX2iPdogkak7P63JpyCmzW9gYeMq4h5sj9ZA== X-Received: by 2002:a05:6a00:802:b0:714:1bd8:35f7 with SMTP id d2e1a72fcca58-71b0aae9a98mr4345517b3a.15.1727281520057; Wed, 25 Sep 2024 09:25:20 -0700 (PDT) Received: from localhost (226.75.127.34.bc.googleusercontent.com. [34.127.75.226]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-71afc9c7a14sm2923078b3a.218.2024.09.25.09.25.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Sep 2024 09:25:19 -0700 (PDT) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org Cc: jthies@google.com, pmalani@chromium.org, akuchynski@google.com, Abhishek Pandit-Subedi , Benson Leung , Guenter Roeck , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 5/8] platform/chrome: cros_ec_typec: Update partner altmode active Date: Wed, 25 Sep 2024 09:25:06 -0700 Message-ID: <20240925092505.5.I083bf9188947be8cb7460211cfdf3233370a28f6@changeid> X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog In-Reply-To: <20240925162513.435177-1-abhishekpandit@chromium.org> References: <20240925162513.435177-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 --- 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 4d305876ec08..6c0228981627 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.46.0.792.g87dc391469-goog From nobody Fri Nov 29 00:38:11 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 C9A8A12CDBF for ; Wed, 25 Sep 2024 16:25:21 +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=1727281523; cv=none; b=TPgeDIgUuL4bSBgyLdFOwGGLhDniwdt8zzWJy+brpnoH8x9nnLhqjMFU1+dBTFXNjAyIwQfYDjK2IL9V2GRZreshtWNeLniUIQOO9WMRCm6szCvxDvZcNXZWsSzwPVx+iFhQq5hftc8wJkjtVSkBTpbQVTP6Gxi8o3jsqw1DqRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727281523; c=relaxed/simple; bh=bkyZ9ZDSwtJW3YVcxQDnmy3QDNnpmwj3JZoEu7Pj5cs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vw4Lx3/gBmj6lwBG4ao3enQeVA01CeYG9RiFBkQnkNnyuYLO/vQ+UzLV/GaQY2FfkZo3CZLCbR1AKCIo1OjGXyHcpC69oaSpw+JeBOOdBQ4GRxlqLaUc8esmrOBGJGyPA0pfMkB4wMj21/NyfPBD5hjpVnSU2Fhq+bYZe5duJjs= 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=RRQ9sOzM; 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="RRQ9sOzM" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-71798661a52so97637b3a.0 for ; Wed, 25 Sep 2024 09:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1727281521; x=1727886321; 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=+7njd5uGAB08nW3CyyAe8XQE/+AB60p3g0lfb6j9aI4=; b=RRQ9sOzMRePpavKs96W5FQjxftmfOR0lOxxFJQ6lVbKaw5PTuUvE3OF6u7FhxmVEuS 82wZVROXJRbdP4HVnrt8MCrXYEQcJSLeAb3mXOM6CAbXETzqqo3czy//qPu2jOBg5BzK Gqn81CmJDoqg0HuwPvtrSD/yiI0RwIOsL6CrU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727281521; x=1727886321; 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=+7njd5uGAB08nW3CyyAe8XQE/+AB60p3g0lfb6j9aI4=; b=pnFSHFRGJS05AtHn/+cBxNhpNhTmpTfgJ0VMpcShNJ/vjb+jslg6njfvbrqWeZSkiJ B6+kYQVRfdhi2DZ9Ct7R/3k0abEffxWMmobTSVxv+K0q9gvW7jv9Er900f8MWVUARSjn wrmFOODCLhq5rMssjTMYswM8L6nHOf7mhCxh4FptMDhzcHnFcCWR37BxgEE0Yd2osCdQ SM743hJOVo9zJHPl2skiWGfhD39m450+lndGzKedj18X4mPuip/tI0Mmuxj9Bo8GDJTc 2l0++FsrKgk1mtJVFj0ipCQEvKjYbu8CKggKL4RSm5obZdk4Sbn6oV/D3ACiGh7bLrp/ xLRw== X-Forwarded-Encrypted: i=1; AJvYcCU2zQJTy7ktdJP37QPxEYljxjcfDapPJNZeM+fvLj7C7cfA6mSL6cbLotwQFtTmo2OuVnenWRphbmTUMw4=@vger.kernel.org X-Gm-Message-State: AOJu0Yyu4jpgkkxE1qONoIa40PqLBMdtSDPKL468a/J3cAynxpdlm78f kE1l+TT2sp9sjP/ToMCtKDhGeTeOOLcU2RewMWyMxNHuiIfVnoOskoFQ6TdSnw== X-Google-Smtp-Source: AGHT+IEaVeEK6z0ZYLb5SCEy1Mb0P3dcErpBaGT2V8h4jllv9PEeYo8ay6xtZlOSUTmdt0lIwAG7HA== X-Received: by 2002:a05:6a00:10d0:b0:70d:2a1b:422c with SMTP id d2e1a72fcca58-71b1931af7dmr302805b3a.7.1727281521035; Wed, 25 Sep 2024 09:25:21 -0700 (PDT) Received: from localhost (226.75.127.34.bc.googleusercontent.com. [34.127.75.226]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-71afc834196sm3045610b3a.13.2024.09.25.09.25.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Sep 2024 09:25:20 -0700 (PDT) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org Cc: jthies@google.com, pmalani@chromium.org, akuchynski@google.com, Abhishek Pandit-Subedi , Benson Leung , Guenter Roeck , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 6/8] platform/chrome: cros_ec_typec: Displayport support Date: Wed, 25 Sep 2024 09:25:07 -0700 Message-ID: <20240925092505.6.I142fc0c09df58689b98f0cebf1c5e48b9d4fa800@changeid> X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog In-Reply-To: <20240925162513.435177-1-abhishekpandit@chromium.org> References: <20240925162513.435177-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 --- MAINTAINERS | 5 +- drivers/platform/chrome/Makefile | 2 + drivers/platform/chrome/cros_ec_typec.c | 13 +- drivers/platform/chrome/cros_ec_typec.h | 1 + drivers/platform/chrome/cros_typec_altmode.h | 34 +++ .../platform/chrome/cros_typec_displayport.c | 247 ++++++++++++++++++ 6 files changed, 299 insertions(+), 3 deletions(-) create mode 100644 drivers/platform/chrome/cros_typec_altmode.h create mode 100644 drivers/platform/chrome/cros_typec_displayport.c diff --git a/MAINTAINERS b/MAINTAINERS index 10430778c998..d8baf38cacc6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5282,11 +5282,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_switch.c -F: drivers/platform/chrome/cros_typec_vdm.* +F: drivers/platform/chrome/cros_typec_* =20 CHROMEOS HPS DRIVER M: Dan Callaghan diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Mak= efile index 2dcc6ccc2302..fe6c5234ac27 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -18,7 +18,9 @@ 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 +cros-ec-typec-$(CONFIG_TYPEC_DP_ALTMODE) +=3D cros_typec_displayport.o 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 6c0228981627..f9221d0d95f5 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,16 @@ 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; + +#if !IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE) typec_altmode_set_drvdata(amode, port); amode->ops =3D &port_amode_ops; +#endif =20 /* * Register TBT compatibility alt mode. The EC will not enter the mode @@ -575,6 +580,10 @@ static int cros_typec_enable_dp(struct cros_typec_data= *typec, if (!ret) ret =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 +1263,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.h b/drivers/platfor= m/chrome/cros_typec_altmode.h new file mode 100644 index 000000000000..a8b37a18c83a --- /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 +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); +} + +int cros_typec_displayport_status_update(struct typec_altmode *altmode, + struct typec_displayport_data *data) +{ + return 0; +} +#endif +#endif /* __CROS_TYPEC_ALTMODE_H__ */ diff --git a/drivers/platform/chrome/cros_typec_displayport.c b/drivers/pla= tform/chrome/cros_typec_displayport.c new file mode 100644 index 000000000000..bccd57290601 --- /dev/null +++ b/drivers/platform/chrome/cros_typec_displayport.c @@ -0,0 +1,247 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Alt-mode implementation for Displayport on ChromeOS EC. + * + * Copyright 2024 Google LLC + * Author: Abhishek Pandit-Subedi + */ +#include "cros_ec_typec.h" + +#include +#include + +#include "cros_typec_altmode.h" + +struct typec_dp_data { + struct typec_displayport_data data; + struct work_struct work; + + struct cros_typec_port *port; + struct typec_altmode *alt; + bool ap_mode_entry; + bool configured; + bool pending_status_update; + + u32 header; + u32 *vdo_data; + u8 vdo_size; +}; + +static void cros_typec_displayport_work(struct work_struct *work) +{ + struct typec_dp_data *data =3D + container_of(work, struct typec_dp_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_displayport_enter(struct typec_altmode *alt, u32 *vd= o) +{ + struct typec_dp_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, + .mode_to_enter =3D CROS_EC_ALTMODE_DP, + }; + 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(USB_TYPEC_DP_SID, 1, svdm_version, CMD_ENTER_MODE); + data->header |=3D VDO_OPOS(USB_TYPEC_DP_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_exit(struct typec_altmode *alt) +{ + struct typec_dp_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(USB_TYPEC_DP_SID, 1, svdm_version, CMD_EXIT_MODE); + data->header |=3D VDO_OPOS(USB_TYPEC_DP_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; +} + +int cros_typec_displayport_status_update(struct typec_altmode *altmode, + struct typec_displayport_data *data) +{ + struct typec_dp_data *dp_data =3D typec_altmode_get_drvdata(altmode); + + 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->header |=3D VDO_CMDT(CMDT_RSP_ACK); + dp_data->data =3D *data; + dp_data->vdo_data =3D &dp_data->data.status; + dp_data->vdo_size =3D 2; + dp_data->pending_status_update =3D false; + + schedule_work(&dp_data->work); + return 0; +} + +static int cros_typec_displayport_vdm(struct typec_altmode *alt, u32 heade= r, + const u32 *data, int count) +{ + struct typec_dp_data *dp_data =3D typec_altmode_get_drvdata(alt); + + int cmd_type =3D PD_VDO_CMDT(header); + int cmd =3D PD_VDO_CMD(header); + int svdm_version; + + if (!dp_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; + } + + 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(dp_data->port->partner, + PD_VDO_SVDM_VER(header)); + svdm_version =3D PD_VDO_SVDM_VER(header); + } + + dp_data->header =3D VDO(USB_TYPEC_DP_SID, 1, svdm_version, cmd); + dp_data->header |=3D VDO_OPOS(USB_TYPEC_DP_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; + dp_data->header |=3D VDO_CMDT(CMDT_RSP_ACK); + dp_data->configured =3D true; + schedule_work(&dp_data->work); + break; + case DP_CMD_STATUS_UPDATE: + dp_data->pending_status_update =3D true; + break; + default: + dp_data->header |=3D VDO_CMDT(CMDT_RSP_ACK); + schedule_work(&dp_data->work); + break; + } + + break; + default: + break; + } + + return 0; +} + +static const struct typec_altmode_ops cros_typec_displayport_ops =3D { + .enter =3D cros_typec_displayport_enter, + .exit =3D cros_typec_displayport_exit, + .vdm =3D cros_typec_displayport_vdm, +}; + +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 typec_dp_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_displayport_work); + data->alt =3D alt; + data->port =3D port; + data->ap_mode_entry =3D ap_mode_entry; + data->configured =3D false; + + typec_altmode_set_ops(alt, &cros_typec_displayport_ops); + typec_altmode_set_drvdata(alt, data); + + return alt; +} --=20 2.46.0.792.g87dc391469-goog From nobody Fri Nov 29 00:38:11 2024 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 921D213AD2A for ; Wed, 25 Sep 2024 16:25:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727281524; cv=none; b=ZlR8awFL2cbD9p3g4EofSuEtuVWTRtX99bLfbUFEJgwvrhivBQoooctNWSJKVnQnOp6uMKGRK/vGeyBWfc/N+yadmCmrA/Ko6KIB461FayQi+MfXGlVFM8YapnTCXnJBSbE1JI+vIHAuyNB5sqLKEGFMfo2sXkLHLVAWVoDgfc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727281524; c=relaxed/simple; bh=XShPODdNj2Tf9rZfMcEFuuLjURIarutPgKFC56sORnI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cUcco/pmzAYLfr4k0ZJdYaYlJuM3B3ZayMjcQV0klf3ZuazUJ2JLwpVWs6gfSWowjbfE1fV62H461Bnj9vt8xvAZH7HWg/FPul2MVr3UclKGmk5XCYBXG+wSU0p5SMcst1j+0Sy7pDFw74rerLziiWRQ2/uFES+yzWLGATQwFVM= 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=L301Iirq; arc=none smtp.client-ip=209.85.216.44 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="L301Iirq" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2dee9d86f4dso65686a91.3 for ; Wed, 25 Sep 2024 09:25:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1727281522; x=1727886322; 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=K73Cjc7PLjHS+1dDna4qVLCGonPYM/7iYy8MOw2IBTo=; b=L301IirqtxZAfaO71EUsINwWxlewKhbJ4WsmtZjlBrbwEBJCXJ7AUs1U650WGWFfM0 7XxKOFbN14vtpwnGhwjUd+lZ/DHqOkLVJ+twMihzoKr1hKk5OQAp8e4vxO5FgStoJjfL FLynQHJX8Sl6GXd8Txf18UjBqXHhBSJJVINbk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727281522; x=1727886322; 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=K73Cjc7PLjHS+1dDna4qVLCGonPYM/7iYy8MOw2IBTo=; b=kqGpIkM4nsz+xny2N26XgfkFfUSm/lnpWzUhWMC+z+6aaKc6I6ZPvlvTGGmOxYYT3y aurQD/k9iyM8UNpLU7Tmh2EdRG551e5vjq6QRt6pJNZL7OAWEddaTApS9stKKoFlnRxd YaFpdxQaEr3cnis4w2CR+aYzBktRbkIR6Mq6LCpekLDs9tuiPYlAJEkcqdpsS5rujOjC l5F8iJv77Hahr7cyDhAsii6ZEE4ZcCARxJ/3XK6AtecaxGi3CHHce08bh9DYG9PfWIL+ pyriVAPB7uXzVF6BCZCr5XVHZLyFwmTiceHDEp9uld/8Z3xU2MGoUrfb2yE0SMN+YNlE 49jQ== X-Forwarded-Encrypted: i=1; AJvYcCVFjbWwnRx5PmZ45PU6ZJXYqgDrojqEY6ekKyGvr1pdyutgcvyXnxUXDUN4JUL5fUop/SysjcAm2oSPY+4=@vger.kernel.org X-Gm-Message-State: AOJu0YwzJZIviv8TNFfVYP1KTM5FFzJJ3I0p+pCiyFMRdmVis/qQNENw zI1X6CvDNJFGgPW7HBxn1XbFf16+OLZnCV7s6BeMRFhAiHAwkORMR5GYUqS95Q== X-Google-Smtp-Source: AGHT+IEHZ96lmdEI1m3y/ql4Lx3rthD1wM7Mk3XKb4mr67RO++qDDNKQCQNPjUKcSRGpHp5K+WTlYw== X-Received: by 2002:a17:90a:ca91:b0:2d8:27c1:1d4a with SMTP id 98e67ed59e1d1-2e06ae79400mr3891142a91.24.1727281521942; Wed, 25 Sep 2024 09:25:21 -0700 (PDT) Received: from localhost (226.75.127.34.bc.googleusercontent.com. [34.127.75.226]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2e06ccf0505sm1750144a91.0.2024.09.25.09.25.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Sep 2024 09:25:21 -0700 (PDT) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org Cc: jthies@google.com, pmalani@chromium.org, akuchynski@google.com, Abhishek Pandit-Subedi , Benson Leung , Guenter Roeck , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 7/8] platform/chrome: cros_ec_typec: Thunderbolt support Date: Wed, 25 Sep 2024 09:25:08 -0700 Message-ID: <20240925092505.7.Ic61ced3cdfb5d6776435356061f12307da719829@changeid> X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog In-Reply-To: <20240925162513.435177-1-abhishekpandit@chromium.org> References: <20240925162513.435177-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 --- drivers/platform/chrome/Makefile | 1 + drivers/platform/chrome/cros_ec_typec.c | 29 +-- drivers/platform/chrome/cros_typec_altmode.h | 14 ++ .../platform/chrome/cros_typec_thunderbolt.c | 184 ++++++++++++++++++ 4 files changed, 216 insertions(+), 12 deletions(-) create mode 100644 drivers/platform/chrome/cros_typec_thunderbolt.c diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Mak= efile index fe6c5234ac27..da7a44738171 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -19,6 +19,7 @@ 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 cros-ec-typec-$(CONFIG_TYPEC_DP_ALTMODE) +=3D cros_typec_displayport.o +cros-ec-typec-$(CONFIG_TYPEC_TBT_ALTMODE) +=3D cros_typec_thunderbolt.o 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 f9221d0d95f5..ec13d84d11b8 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -304,21 +304,26 @@ static int cros_typec_register_port_altmodes(struct c= ros_typec_data *typec, typec_altmode_set_drvdata(amode, port); amode->ops =3D &port_amode_ops; #endif - /* * Register TBT compatibility alt mode. The EC will not enter the mode - * if it doesn't support it, so it's safe to register it unconditionally - * here for now. + * if it doesn't support it and it will not enter automatically by + * design so we can use the |ap_driven_altmode| feature to check if we + * should register it. */ - memset(&desc, 0, sizeof(desc)); - desc.svid =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 TYPEC_ANY_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; + +#if !IS_ENABLED(CONFIG_TYPEC_TBT_ALTMODE) + typec_altmode_set_drvdata(amode, port); + amode->ops =3D &port_amode_ops; +#endif + } =20 port->state.alt =3D NULL; port->state.mode =3D TYPEC_STATE_USB; diff --git a/drivers/platform/chrome/cros_typec_altmode.h b/drivers/platfor= m/chrome/cros_typec_altmode.h index a8b37a18c83a..24e766189211 100644 --- a/drivers/platform/chrome/cros_typec_altmode.h +++ b/drivers/platform/chrome/cros_typec_altmode.h @@ -31,4 +31,18 @@ int cros_typec_displayport_status_update(struct typec_al= tmode *altmode, return 0; } #endif + +#if IS_ENABLED(CONFIG_TYPEC_TBT_ALTMODE) +struct typec_altmode * +cros_typec_register_thunderbolt(struct cros_typec_port *port, + struct typec_altmode_desc *desc); +#else +struct typec_altmode * +cros_typec_register_thunderbolt(struct cros_typec_port *port, + struct typec_altmode_desc *desc) +{ + return typec_port_register_altmode(port->port, desc); +} +#endif + #endif /* __CROS_TYPEC_ALTMODE_H__ */ diff --git a/drivers/platform/chrome/cros_typec_thunderbolt.c b/drivers/pla= tform/chrome/cros_typec_thunderbolt.c new file mode 100644 index 000000000000..b399237b773f --- /dev/null +++ b/drivers/platform/chrome/cros_typec_thunderbolt.c @@ -0,0 +1,184 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Alt-mode implementation for Thunderbolt on ChromeOS EC. + * + * Copyright 2024 Google LLC + * Author: Abhishek Pandit-Subedi + */ +#include "cros_ec_typec.h" + +#include +#include + +#include "cros_typec_altmode.h" + +struct typec_tbt_data { + struct work_struct work; + + struct cros_typec_port *port; + struct typec_altmode *alt; + + u32 header; + u32 *vdo_data; + u8 vdo_size; +}; + +static void cros_typec_thunderbolt_work(struct work_struct *work) +{ + struct typec_tbt_data *data =3D + container_of(work, struct typec_tbt_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_thunderbolt_enter(struct typec_altmode *alt, u32 *vd= o) +{ + struct typec_tbt_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, + .mode_to_enter =3D CROS_EC_ALTMODE_TBT, + }; + int svdm_version; + int ret; + + 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(USB_TYPEC_TBT_SID, 1, svdm_version, CMD_ENTER_MODE); + data->header |=3D VDO_OPOS(TYPEC_TBT_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_thunderbolt_exit(struct typec_altmode *alt) +{ + struct typec_tbt_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; + + 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(USB_TYPEC_TBT_SID, 1, svdm_version, CMD_EXIT_MODE); + data->header |=3D VDO_OPOS(TYPEC_TBT_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_thunderbolt_vdm(struct typec_altmode *alt, u32 heade= r, + const u32 *data, int count) +{ + struct typec_tbt_data *tbt_data =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(tbt_data->port->partner, + PD_VDO_SVDM_VER(header)); + svdm_version =3D PD_VDO_SVDM_VER(header); + } + + tbt_data->header =3D VDO(USB_TYPEC_TBT_SID, 1, svdm_version, cmd); + tbt_data->header |=3D VDO_OPOS(TYPEC_TBT_MODE); + + /* + * TODO - Just always reply to the VDMs that we are done. + */ + 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: + tbt_data->header |=3D VDO_CMDT(CMDT_RSP_ACK); + schedule_work(&tbt_data->work); + break; + } + + break; + default: + break; + } + + return 0; +} + +static const struct typec_altmode_ops cros_typec_thunderbolt_ops =3D { + .enter =3D cros_typec_thunderbolt_enter, + .exit =3D cros_typec_thunderbolt_exit, + .vdm =3D cros_typec_thunderbolt_vdm, +}; + +struct typec_altmode * +cros_typec_register_thunderbolt(struct cros_typec_port *port, + struct typec_altmode_desc *desc) +{ + struct typec_altmode *alt; + struct typec_tbt_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_thunderbolt_work); + data->alt =3D alt; + data->port =3D port; + + typec_altmode_set_ops(alt, &cros_typec_thunderbolt_ops); + typec_altmode_set_drvdata(alt, data); + + return alt; +} --=20 2.46.0.792.g87dc391469-goog From nobody Fri Nov 29 00:38:11 2024 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 744AD13C8F6 for ; Wed, 25 Sep 2024 16:25:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727281524; cv=none; b=DBuEqDxTLQr7GTVVmQC5+Sxonil/8dRbBz0PQk8BeujtNvA28/kWtKs0Dh0cjHcJO2NVbHVN68pE03d7DwWBZ+2vzd1FxPlrDLVkL6v5EEQZAnZqmnGaqqBHAldOLusQWCKeFwl7syuO0U7uD/xbCZ95XAXOJoYpfWhOaYY9ryE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727281524; c=relaxed/simple; bh=4IztXoDnmzedD/DGGwCbWuMnFco0zL0LtDzIkgaMdFQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rsE0nwJrDdAxKEq0p4VDrwQufVwuTT/JnJQzS9vnIdHocBv0M4+HREjt/KD5QOD4dHEAxB+sQG4txy7ekB+OHVFIrWgoJgnEZW+q7NNJvkVvewQG07L/xtEL1/FJeQeoJRKLej6Bi4fR3Qx2v0P5lVKUcIQIv+P7NZw/XzzfaEM= 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=S0zW/CNR; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="S0zW/CNR" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-20551e2f1f8so82173595ad.2 for ; Wed, 25 Sep 2024 09:25:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1727281523; x=1727886323; 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=/FZ5g7QcrBKoaqiirz8r6L7CjueOS/LSXhKJhnt7qrY=; b=S0zW/CNR7ueoKi0yyuROtCGZEPWO9p3+AV/MV2EAigPY5e86/UsCBtfZRwA4UIDWma S1PgdZqJsEqdCCK4oIW5Dx3OCxWYVAfN0ez+drz8vCsP5+rY5Ak/gdp1XWnTb0sf6dST yo13c0TsHee/86fP9Pw3FDuUl6c01qj+R34CM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727281523; x=1727886323; 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=/FZ5g7QcrBKoaqiirz8r6L7CjueOS/LSXhKJhnt7qrY=; b=kusstv0KsdIGXPavpyvR8fb3umfNI7YDOwPwYOUHW2CzpRwpoPqGW7V+uPB7525adt Dctv/mbR/0//63KiMDUqFkITlYDKbVciK/8lE4QeU4zFtu8DXdAHkPree5QNQZmSjH0S h1hUG7F/apCOCI4+KFJyfOtbDrLQbPVJq8yuVe1GFCnrFKAl1+ZKkagNzWBY/RjmQXAZ PRyonrXAlndzPeeRdq5q+HLLzRM5X37aCVW0xZjWnp09EAP/kg9i47EIscXL8vvm62lR /Y0c30GiOYKeC4Qx7wT6iUoPRBRPT+1J+E+JJ3NjE9YJjdPQlQZCQChelgdd9UYnJBnI 0FsQ== X-Forwarded-Encrypted: i=1; AJvYcCXc8nQFaQjCXnK7k/KrDd8Aim1Um5wcV87VVqvej71QMR49LKYqXfi1QroFqQEw05PYvPMre62ox+9AEms=@vger.kernel.org X-Gm-Message-State: AOJu0YwUVb+xdNZML6Cqiu40UplL1BFl5rPLfoHOVMVL4PkKcL1+bFbg XttNDf4QUU3ucamaXu2OLT+vXWSN4ugV0ZBwSdtWzoNPhpZskkxRZYflg1gGZg== X-Google-Smtp-Source: AGHT+IEuLsG3mUIBakDR0Qtj5wgz2xldoqosHu1rfjf/OYnO62itqm43VkTh6/qg5gZfBIHNmBOf9A== X-Received: by 2002:a17:903:1cc:b0:1fd:791d:1437 with SMTP id d9443c01a7336-20afc415addmr48913755ad.6.1727281522770; Wed, 25 Sep 2024 09:25:22 -0700 (PDT) Received: from localhost (226.75.127.34.bc.googleusercontent.com. [34.127.75.226]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-20af1858b4dsm26217325ad.263.2024.09.25.09.25.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Sep 2024 09:25:22 -0700 (PDT) From: Abhishek Pandit-Subedi To: heikki.krogerus@linux.intel.com, tzungbi@kernel.org Cc: jthies@google.com, pmalani@chromium.org, akuchynski@google.com, Abhishek Pandit-Subedi , Benson Leung , Guenter Roeck , chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 8/8] platform/chrome: cros_ec_typec: Disable auto_enter Date: Wed, 25 Sep 2024 09:25:09 -0700 Message-ID: <20240925092505.8.Ic14738918e3d026fa2d85e95fb68f8e07a0828d0@changeid> X-Mailer: git-send-email 2.46.0.792.g87dc391469-goog In-Reply-To: <20240925162513.435177-1-abhishekpandit@chromium.org> References: <20240925162513.435177-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 typecd in userspace so we should not auto enter from the kernel. Signed-off-by: Abhishek Pandit-Subedi --- drivers/platform/chrome/cros_ec_typec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chr= ome/cros_ec_typec.c index ec13d84d11b8..e06a0f2712ce 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -294,6 +294,7 @@ static int cros_typec_register_port_altmodes(struct cro= s_typec_data *typec, desc.svid =3D USB_TYPEC_DP_SID; desc.mode =3D USB_TYPEC_DP_MODE; desc.vdo =3D DP_PORT_VDO; + desc.no_auto_enter =3D true; amode =3D cros_typec_register_displayport(port, &desc, typec->ap_driven_altmode); if (IS_ERR(amode)) @@ -314,6 +315,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 TYPEC_ANY_MODE; + desc.no_auto_enter =3D true; amode =3D cros_typec_register_thunderbolt(port, &desc); if (IS_ERR(amode)) return PTR_ERR(amode); --=20 2.46.0.792.g87dc391469-goog