Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp3895375rwl; Tue, 27 Dec 2022 17:39:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXvIyGYUv9qMOO1flC20Zyx4+9b3Dv/w10ry5SktbMPiwmQ9M0EV3b2jHHrItr9oTr+Nbqwk X-Received: by 2002:a05:6a20:bc85:b0:a3:7177:b4bb with SMTP id fx5-20020a056a20bc8500b000a37177b4bbmr32230601pzb.29.1672191549387; Tue, 27 Dec 2022 17:39:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672191549; cv=none; d=google.com; s=arc-20160816; b=ErcZbFV3ulUy9xYBMmzNpjJuJ46C6o8xtnwTc7W5xTlHFUSQB6B4zeJKLhc4wja7nD dQjLsONNSatqRhO8QvMLqsw6sesw0pgjPo68DGjlJNJDBd343ZL6BDLId2aPLrqlDI4P 8sPaWFu1DFumVclsQgIFjr5Y1DhSCBW+golxq0ljw0lPFHI5UQORCVc/Ch5FvDE27SiT rvNN2lmDLMZogOaBeboiEhEPHPh5TvUhRPFt7q8Pskhz/Wh9gRQoA22KUBw3aVKXzDay zMP7A7tc7TSGp111H8WwJpEFClvdy3f0BZODmBT1NvsmeP2+RYnQYCSKYRLC/QjbhEB7 3Qfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Oi/kOlETPyv2MAO1V2HCLkw/mua4WIbZ/Rd76axTkmw=; b=CpFnDmlGh80lQlClqWkhInDmP78YyI/o2iUC6e7RN7JLNFz2YrP7Mf9NvB5Jk/PyOA fb/S0tyn/qErX4S8h7V2LqIuvjXeuNOGTBUvtltz3lNfsygtG47Gf+fmqJ5z4Zi/6+Q5 /q/3iHAZoE8k1XHag5eh2G9mVVhT4lqn2QDi89Tb0NKfgOu/f2SKRtYs2dyz0rr/rGa5 vpLPIWomq7uq62CoUIaiK/5A0bC5jozezlU2wwElo8ZFwvfg0VNtvD7GHboHHMIafVht Z1fkhygmOA42da7Hk380E5zWCygFiK3cUx6bIcZqR0n8pBxAmbmQYjnl2yLV2+DDTSrQ je2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="XPNNK/pd"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b10-20020a6541ca000000b00478750e1a4esi14578673pgq.877.2022.12.27.17.39.00; Tue, 27 Dec 2022 17:39:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="XPNNK/pd"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231167AbiL1BJz (ORCPT + 65 others); Tue, 27 Dec 2022 20:09:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229526AbiL1BJx (ORCPT ); Tue, 27 Dec 2022 20:09:53 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83483E01D for ; Tue, 27 Dec 2022 17:09:52 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id k137so5031114pfd.8 for ; Tue, 27 Dec 2022 17:09:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=Oi/kOlETPyv2MAO1V2HCLkw/mua4WIbZ/Rd76axTkmw=; b=XPNNK/pdpQNeuytYJsaqiYwaemm2ickjJ1kbCPbCpJWFnmHwC6uAaZ28x8m+64qwaz FFUtco2Gwgngd8D+vIcoWIxYtQtyVLOwfdSWTCyUVqp55cjssGMrbyBnog5eY7EXtDe0 RfbbXbxdQiJxzrOBANsD10JSlZIHMgGVzM1e0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Oi/kOlETPyv2MAO1V2HCLkw/mua4WIbZ/Rd76axTkmw=; b=xomE3gbuDTY3AA8VcyHNZ8vY6XHW4NYEllp3TwE+6Z7/zzhWcjTH4WJSMHOlpBRhzy AqfIc7+lj6qbHgVo2BfU9+MfY0XvXzGrcgaErPgV0e6Om7qblHf3Zy+nxdEGmFMx85A9 BCS+Z298IHBsrgS/crtNzTGKPab242vvWsU/q4JOEVnmmuKLucXzLmlqW/MW+BkYa6hT pztVKy2oGkFN0gC/rqa9YpSDIF9Qv1GvTDl5pMD9KjfGBj8+i6XWjiJM5L91oUntNcaX tzlkWv5swpOFoTCG5G1V2aM1xgYguOVL7KfK8k48Yvj1DhNQjIhzixYZ2Oem+pwqfuJO nElA== X-Gm-Message-State: AFqh2kpEa+29/jUZRGI5r1TmKLMe2FBAKIgAZx9vuJfd2mI8y20Fo8cL Tx5/Fa4BKfMoVJu/OmB5r+7jEwPCqdsBtGX9 X-Received: by 2002:a62:a21e:0:b0:581:95a7:d2f4 with SMTP id m30-20020a62a21e000000b0058195a7d2f4mr757839pff.9.1672189791828; Tue, 27 Dec 2022 17:09:51 -0800 (PST) Received: from pmalani.c.googlers.com.com (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id 68-20020a621947000000b00580e679dcf2sm6045566pfz.157.2022.12.27.17.09.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Dec 2022 17:09:51 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, chrome-platform@lists.linux.dev Cc: heikki.krogerus@linux.intel.com, Prashant Malani , Benson Leung , Daisuke Nojiri , "Dustin L. Howett" , Evan Green , Greg Kroah-Hartman , Guenter Roeck , "Gustavo A. R. Silva" , Lee Jones , Lee Jones , Stephen Boyd , Tinghan Shen , Tzung-Bi Shih , Xiang wangx Subject: [PATCH 08/10] platform/chrome: cros_ec_typec: Add initial VDM support Date: Wed, 28 Dec 2022 00:45:11 +0000 Message-Id: <20221228004648.793339-9-pmalani@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20221228004648.793339-1-pmalani@chromium.org> References: <20221228004648.793339-1-pmalani@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add ops to support USB PD VDM (Vendor Defined Message) from the port driver. This enables the port driver to interface with alternate mode drivers and communicate with connected peripherals. The initial support just contains an implementation of the Enter Mode command. Cc: Heikki Krogerus Signed-off-by: Prashant Malani --- MAINTAINERS | 1 + drivers/platform/chrome/Makefile | 2 +- drivers/platform/chrome/cros_ec_typec.c | 3 ++ drivers/platform/chrome/cros_typec_vdm.c | 43 ++++++++++++++++++++++++ drivers/platform/chrome/cros_typec_vdm.h | 10 ++++++ 5 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/chrome/cros_typec_vdm.c create mode 100644 drivers/platform/chrome/cros_typec_vdm.h diff --git a/MAINTAINERS b/MAINTAINERS index 8219b646ab50..cfccbbbb083f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5000,6 +5000,7 @@ 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.* CHROMEOS EC USB PD NOTIFY DRIVER M: Prashant Malani diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile index fd29fa74ba33..dae0ed3c8656 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -16,7 +16,7 @@ obj-$(CONFIG_CROS_TYPEC_SWITCH) += cros_typec_switch.o obj-$(CONFIG_CROS_EC_RPMSG) += cros_ec_rpmsg.o obj-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o cros_ec_lpcs-objs := cros_ec_lpc.o cros_ec_lpc_mec.o -cros-ec-typec-objs := cros_ec_typec.o +cros-ec-typec-objs := cros_ec_typec.o cros_typec_vdm.o obj-$(CONFIG_CROS_EC_TYPEC) += cros-ec-typec.o obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o cros_ec_trace.o diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index a4eff590ca56..1e28d56b094d 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -17,6 +17,7 @@ #include #include "cros_ec_typec.h" +#include "cros_typec_vdm.h" #define DRV_NAME "cros-ec-typec" @@ -272,6 +273,7 @@ static int cros_typec_register_port_altmodes(struct cros_typec_data *typec, return PTR_ERR(amode); port->port_altmode[CROS_EC_ALTMODE_DP] = amode; typec_altmode_set_drvdata(amode, port); + amode->ops = &port_amode_ops; /* * Register TBT compatibility alt mode. The EC will not enter the mode @@ -286,6 +288,7 @@ static int cros_typec_register_port_altmodes(struct cros_typec_data *typec, return PTR_ERR(amode); port->port_altmode[CROS_EC_ALTMODE_TBT] = amode; typec_altmode_set_drvdata(amode, port); + amode->ops = &port_amode_ops; port->state.alt = NULL; port->state.mode = TYPEC_STATE_USB; diff --git a/drivers/platform/chrome/cros_typec_vdm.c b/drivers/platform/chrome/cros_typec_vdm.c new file mode 100644 index 000000000000..df0102ca3a18 --- /dev/null +++ b/drivers/platform/chrome/cros_typec_vdm.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * USB Power Delivery Vendor Defined Message (VDM) support code. + * + * Copyright 2023 Google LLC + * Author: Prashant Malani + */ + +#include +#include +#include + +#include "cros_ec_typec.h" +#include "cros_typec_vdm.h" + +static int cros_typec_port_amode_enter(struct typec_altmode *amode, u32 *vdo) +{ + struct cros_typec_port *port = typec_altmode_get_drvdata(amode); + struct ec_params_typec_control req = { + .port = port->port_num, + .command = TYPEC_CONTROL_COMMAND_SEND_VDM_REQ, + }; + struct typec_vdm_req vdm_req = {}; + u32 hdr; + + hdr = VDO(amode->svid, 1, SVDM_VER_2_0, CMD_ENTER_MODE); + hdr |= VDO_OPOS(amode->mode); + + vdm_req.vdm_data[0] = hdr; + vdm_req.vdm_data_objects = 1; + vdm_req.partner_type = TYPEC_PARTNER_SOP; + req.vdm_req_params = vdm_req; + + dev_dbg(port->typec_data->dev, "Sending EnterMode VDM, hdr: %x, port: %d\n", + hdr, port->port_num); + + return cros_ec_cmd(port->typec_data->ec, 0, EC_CMD_TYPEC_CONTROL, &req, + sizeof(req), NULL, 0); +} + +struct typec_altmode_ops port_amode_ops = { + .enter = cros_typec_port_amode_enter, +}; diff --git a/drivers/platform/chrome/cros_typec_vdm.h b/drivers/platform/chrome/cros_typec_vdm.h new file mode 100644 index 000000000000..7e282d168a98 --- /dev/null +++ b/drivers/platform/chrome/cros_typec_vdm.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __CROS_TYPEC_VDM__ +#define __CROS_TYPEC_VDM__ + +#include + +extern struct typec_altmode_ops port_amode_ops; + +#endif /* __CROS_TYPEC_VDM__ */ -- 2.39.0.314.g84b9a713c41-goog