Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp726821rdb; Thu, 15 Feb 2024 13:36:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWJ6HBXmMu9S6uCByDImoux/GospUdV3fv3QkvnowrxfMPp2WBHHQUc+ot8ncX1WuUcbr7IcaloxsAyMNEIssHwpb/VzoPIzvarH/TDvQ== X-Google-Smtp-Source: AGHT+IEtYjmFXsNlxKmVe/AN2x3qoo+j/beaLIoetmabUkHs8v2fY22UExSTw0TCgAq/tgfB1bc6 X-Received: by 2002:a05:6358:620c:b0:178:6363:5c67 with SMTP id a12-20020a056358620c00b0017863635c67mr3236413rwh.21.1708033008698; Thu, 15 Feb 2024 13:36:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708033008; cv=pass; d=google.com; s=arc-20160816; b=aiyuYEUsrGQXO1SdhuVjc3jpVG2unmkHmZNo3OpGuPBCj2gSkHKlNs4PLqXcs/yF6T 2mLwFHe6feggmuRM3i02ArwPRN5Xl6g6BPPlGKSwc/fvUGq7u6bi+BkQNQcp0t6IhF4K TgFVCx7rVBpvR+WQRs7CbtJaHzaN/F6c3qTGfeLQTj6zR3vQQoXo7rQsyBBqxXiBXknk YG6h3dyylRWWF+BYwNvmwnnWKNpRuDKxLjvL6Vu2NtF+rCiYD4SSyqtCXvn5OpL3pbBj T4O1uh7diVXyNBIzwG4NgBjWOfxxMwqSAZPdKYnFpGa+P06s7aOP7azFnfTnCFa8Rb8k 9yvg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Eb/lWCZ+5T2hEAClmmS1kGT79DhkLCWk2AHk014ASXE=; fh=/cbLjW7Rfwzb3I2vrEK+NHt6YgOcJ+Bp+XUtKNVrstM=; b=PJ9KgJQjVlGtkPebSMsDaMduEM/gdAsRzcYGH5b9XhkcqYXqZnR9QuQwTLbNIEIf+K Qb7nzU+NYDZez7Kb/CUHnX//fziiPIcwoN8GPZPn32hceR8j1mfrvFxtS+CjfuiU8fzK K5RIPYmBAeh2LOTpUOyzr5oyygeNDl5ZqWXCElsJ01qjC2T5e9ZEImJimxO7eDEHchdr ts25rToarzRiXxjVP1xjy3zaZUvesYpbs95E8ZcnqeZz3FePmQ9H0qGFDfH7xTgVcQmy RSqCsujPZwq+W2ddIIVV7HSLw0804lE6eRv1kznbMtOazoiBPKoBkENi70R9JHtNb+PL PLKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-67698-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67698-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id n23-20020a638f17000000b005dc55690b2bsi1706148pgd.324.2024.02.15.13.36.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 13:36:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67698-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-67698-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67698-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 4F46DB22A95 for ; Thu, 15 Feb 2024 21:30:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D2E0145FE3; Thu, 15 Feb 2024 21:29:15 +0000 (UTC) Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51E73145336 for ; Thu, 15 Feb 2024 21:29:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708032554; cv=none; b=TIQtMGfWq9Kz3ZmTicoCcnePOQOLik11N7dm+vbSMO+5HXUlUhMiDCx5KtxAsSVfgbsCCgeoir7I5tJ7Wn3YTxOGahv0axCntE76I/DDj83jJ513KMuGXmpcvqJUVRLFZ+bPYzWNoJpcYbVc+XNsDD6hF/fQI7NQvvY8MY/pBI0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708032554; c=relaxed/simple; bh=wdfDYbwXdmf30ZCyxHt+C8YT25tN2OJ3GnO7DFGD1Uk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=a25ORLcrL+3sGExs+hKrIQFPq5J8iymqwSC9uz96bJA2rz7EzNVjv0HQWR2Lf3T+BxWKV0F6r+GlKeWAI1N5yttzvbGAR6wgm/2YT9kOxAD1X77VtdOjCAmtBh2095pr22YDsVaWb7ubl87tytvyZr203NIIreiA0tzsOIyXNLI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1rajHr-0001xh-K9; Thu, 15 Feb 2024 22:28:55 +0100 From: Marco Felsch To: gregkh@linuxfoundation.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, linux@roeck-us.net, heikki.krogerus@linux.intel.com, jun.li@nxp.com Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH v2 4/4] usb: typec: tcpci: add support to set connector orientation Date: Thu, 15 Feb 2024 22:28:52 +0100 Message-Id: <20240215212852.1202339-5-m.felsch@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215212852.1202339-1-m.felsch@pengutronix.de> References: <20240215212852.1202339-1-m.felsch@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::28 X-SA-Exim-Mail-From: m.felsch@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org This add the support to set the optional connector orientation bit which is part of the optional CONFIG_STANDARD_OUTPUT register 0x18 [1]. This allows system designers to connect the tcpc orientation pin directly to the 2:1 ss-mux. [1] https://www.usb.org/sites/default/files/documents/usb-port_controller_specification_rev2.0_v1.0_0.pdf Signed-off-by: Marco Felsch --- v2: - Make use of fallthrough drivers/usb/typec/tcpm/tcpci.c | 44 ++++++++++++++++++++++++++++++++++ include/linux/usb/tcpci.h | 8 +++++++ 2 files changed, 52 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index 7118551827f6..73a52e7f95c2 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -67,6 +67,18 @@ static int tcpci_write16(struct tcpci *tcpci, unsigned int reg, u16 val) return regmap_raw_write(tcpci->regmap, reg, &val, sizeof(u16)); } +static bool tcpci_check_std_output_cap(struct regmap *regmap, u8 mask) +{ + unsigned int reg; + int ret; + + ret = regmap_read(regmap, TCPC_STD_OUTPUT_CAP, ®); + if (ret < 0) + return ret; + + return (reg & mask) == mask; +} + static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc) { struct tcpci *tcpci = tcpc_to_tcpci(tcpc); @@ -301,6 +313,28 @@ static int tcpci_set_polarity(struct tcpc_dev *tcpc, TCPC_TCPC_CTRL_ORIENTATION : 0); } +static int tcpci_set_orientation(struct tcpc_dev *tcpc, + enum typec_orientation orientation) +{ + struct tcpci *tcpci = tcpc_to_tcpci(tcpc); + unsigned int reg; + + switch (orientation) { + case TYPEC_ORIENTATION_NONE: + /* We can't put a single output into high impedance */ + fallthrough; + case TYPEC_ORIENTATION_NORMAL: + reg = TCPC_CONFIG_STD_OUTPUT_ORIENTATION_NORMAL; + break; + case TYPEC_ORIENTATION_REVERSE: + reg = TCPC_CONFIG_STD_OUTPUT_ORIENTATION_FLIPPED; + break; + } + + return regmap_update_bits(tcpci->regmap, TCPC_CONFIG_STD_OUTPUT, + TCPC_CONFIG_STD_OUTPUT_ORIENTATION_MASK, reg); +} + static void tcpci_set_partner_usb_comm_capable(struct tcpc_dev *tcpc, bool capable) { struct tcpci *tcpci = tcpc_to_tcpci(tcpc); @@ -808,6 +842,9 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data) if (tcpci->data->vbus_vsafe0v) tcpci->tcpc.is_vbus_vsafe0v = tcpci_is_vbus_vsafe0v; + if (tcpci->data->set_orientation) + tcpci->tcpc.set_orientation = tcpci_set_orientation; + err = tcpci_parse_config(tcpci); if (err < 0) return ERR_PTR(err); @@ -851,6 +888,13 @@ static int tcpci_probe(struct i2c_client *client) if (err < 0) return err; + err = tcpci_check_std_output_cap(chip->data.regmap, + TCPC_STD_OUTPUT_CAP_ORIENTATION); + if (err < 0) + return err; + + chip->data.set_orientation = err; + chip->tcpci = tcpci_register_port(&client->dev, &chip->data); if (IS_ERR(chip->tcpci)) return PTR_ERR(chip->tcpci); diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h index 467e8045e9f8..f2bfb4250366 100644 --- a/include/linux/usb/tcpci.h +++ b/include/linux/usb/tcpci.h @@ -47,6 +47,9 @@ #define TCPC_SINK_FAST_ROLE_SWAP BIT(0) #define TCPC_CONFIG_STD_OUTPUT 0x18 +#define TCPC_CONFIG_STD_OUTPUT_ORIENTATION_MASK BIT(0) +#define TCPC_CONFIG_STD_OUTPUT_ORIENTATION_NORMAL 0 +#define TCPC_CONFIG_STD_OUTPUT_ORIENTATION_FLIPPED 1 #define TCPC_TCPC_CTRL 0x19 #define TCPC_TCPC_CTRL_ORIENTATION BIT(0) @@ -127,6 +130,7 @@ #define TCPC_DEV_CAP_2 0x26 #define TCPC_STD_INPUT_CAP 0x28 #define TCPC_STD_OUTPUT_CAP 0x29 +#define TCPC_STD_OUTPUT_CAP_ORIENTATION BIT(0) #define TCPC_MSG_HDR_INFO 0x2e #define TCPC_MSG_HDR_INFO_DATA_ROLE BIT(3) @@ -198,12 +202,16 @@ struct tcpci; * Chip level drivers are expected to check for contaminant and call * tcpm_clean_port when the port is clean to put the port back into * toggling state. + * @set_orientation: + * Optional; Enable setting the connector orientation + * CONFIG_STANDARD_OUTPUT (0x18) bit0. */ struct tcpci_data { struct regmap *regmap; unsigned char TX_BUF_BYTE_x_hidden:1; unsigned char auto_discharge_disconnect:1; unsigned char vbus_vsafe0v:1; + unsigned char set_orientation:1; int (*init)(struct tcpci *tcpci, struct tcpci_data *data); int (*set_vconn)(struct tcpci *tcpci, struct tcpci_data *data, -- 2.39.2