Message ID | 20240205164316.805408-5-m.felsch@pengutronix.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-53032-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp997412dyb; Mon, 5 Feb 2024 08:45:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8TUVP1d4K2YAbPQN4UN3zjkUCY0STu+k9E1tL9vcKms6wVYFp0BP00UbjqHwMB/4WkgWL X-Received: by 2002:a17:90b:d8b:b0:296:6ea5:9c92 with SMTP id bg11-20020a17090b0d8b00b002966ea59c92mr4211545pjb.15.1707151553783; Mon, 05 Feb 2024 08:45:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707151553; cv=pass; d=google.com; s=arc-20160816; b=dppKe2SVVEjT/CiMaMJNablzRNTu5DXPtVxSOI+VBGPfZDQUjyELkNgxUjrImfPNYT oxu4cKLYxxvdaUuE/+nuWGDOZbTcAJre3LThI8DOYf7cj6N0Ek8NUJ3uX+8dMgNgZCka QkvvtzolfNglVD9ic7e9nB6BcWpiZ+aeeppcTAs9Dcfux9XszDYEgkR7xVQKOLDQWHgG /cTz2hEfFxjlNg2ifA6xpwlVNxFswSrrNg6Nqv+aVjxUbumuDws5x1dTApv4k2LfJgih EgCRProluIwL2zJVnSr7iXPTZat6yJwt+uV/CwfnbZMtTs6fgMGA+YQHT0qXec4hw2iF /MLQ== 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=5ghmBjaAVLqXjGHBG7Gy01t+ZFFhaSSY97mJV6Ju8TM=; fh=1u0CvspMcLz+xshlFoZolJDh1LJXgDq9Peayc1r7UeY=; b=jo77Yu66g/7ax2nXJYnwNOzmWX9RYYA9K/BWVYUvEUmC+szOruuHyS4coemFNcfVNq gZSy5C/Bz3moWEERuVaYT03p8BvQW23hLSRJ3BltzbN1E9n7NzdijbbLkLFCFYtm4YUP GPVTuYGE+1i4FGxCi3Zh+HwEvGRNNKYm20E6M2nJ7vBHQSRCzQRe5deEjtTzAo4VF+1Q jlgCC6X4bAs+1nom28xAbFA+lG7bPb1DT4TN755By4DlEjNWojRg2b1BnhjK4riM/K7g YMT8S9zTvfjm57sddWD+/Bn9eSg3pfSGQAqFLsQ7WcqTuO2h1MyXujQNEYx1eBsgSbqT 1uqQ==; 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-53032-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53032-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXaUq58eBtw2GF9RDeDSzgZ6kprmsTb4GHTEJ2N4gkZ+7QP57qdp6hmx/YCQau38cXyb8Gb03pHzcPUza7iH6Eq5Rk1rQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f7-20020a17090ab94700b00296a5bf4d4dsi1413337pjw.92.2024.02.05.08.45.53 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 08:45:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53032-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-53032-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53032-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 6C5112847DD for <ouuuleilei@gmail.com>; Mon, 5 Feb 2024 16:45:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A12CD482CC; Mon, 5 Feb 2024 16:43:45 +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 337DF45035 for <linux-kernel@vger.kernel.org>; Mon, 5 Feb 2024 16:43:42 +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=1707151423; cv=none; b=nPzshe9y6Q3HwsrulSL7dxdEiH/vdDpFPmCSwFuCDi0WIlbAvNWCVt8emiEUTHL6ZIkFSPRz6FursiCyOipkgP8dSeb8LQLlRB1bNcbliiSzdgX7sQKQ1mUW24lDvulNbmasYHqBS/Bb9sKVnjaCSYSIcDS80iL4DhS2nZl+HPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707151423; c=relaxed/simple; bh=4GHUITov1D4E/JQZU7O2PuGsE/9LeCQp7fnZyPsU8lM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SpbZ2M9NUW57QPCkiGzSPnjoW3NtFtE9IWtnXzOMCPh0zujQq0f7FEF0WknfIlke/w7IO72/8rFHjKgvtpaGYhQPLx+SNyUJtSFATFTlEQnwb0CX1qKlccyFXSt6l1VgfZ7kXNuvgwcf0FMbDOFPxLHhiaJxYn2UbXqOE9CHxFQ= 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 <m.felsch@pengutronix.de>) id 1rX240-0004Lp-Fe; Mon, 05 Feb 2024 17:43:20 +0100 From: Marco Felsch <m.felsch@pengutronix.de> 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 Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH 4/4] usb: typec: tcpci: add support to set connector orientation Date: Mon, 5 Feb 2024 17:43:16 +0100 Message-Id: <20240205164316.805408-5-m.felsch@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240205164316.805408-1-m.felsch@pengutronix.de> References: <20240205164316.805408-1-m.felsch@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790078147803074981 X-GMAIL-MSGID: 1790078147803074981 |
Series |
USB-C TCPM Orientation Support
|
|
Commit Message
Marco Felsch
Feb. 5, 2024, 4:43 p.m. UTC
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 <m.felsch@pengutronix.de>
---
drivers/usb/typec/tcpm/tcpci.c | 43 ++++++++++++++++++++++++++++++++++
include/linux/usb/tcpci.h | 8 +++++++
2 files changed, 51 insertions(+)
Comments
* Marco Felsch (m.felsch@pengutronix.de) wrote: > 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 <m.felsch@pengutronix.de> > --- > drivers/usb/typec/tcpm/tcpci.c | 43 ++++++++++++++++++++++++++++++++++ > include/linux/usb/tcpci.h | 8 +++++++ > 2 files changed, 51 insertions(+) > > diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c > index 7118551827f6..7ce9d4923bc7 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,27 @@ 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 */ Is that intended to be a fallthrough? If so I guess it needs marking as such with a fallthrough; Dave > + 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 +841,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 +887,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 > >
Hi David, On 24-02-05, Dr. David Alan Gilbert wrote: > * Marco Felsch (m.felsch@pengutronix.de) wrote: > > 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 <m.felsch@pengutronix.de> > > --- > > drivers/usb/typec/tcpm/tcpci.c | 43 ++++++++++++++++++++++++++++++++++ > > include/linux/usb/tcpci.h | 8 +++++++ > > 2 files changed, 51 insertions(+) > > > > diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c > > index 7118551827f6..7ce9d4923bc7 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,27 @@ 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 */ > > Is that intended to be a fallthrough? If so I guess it needs > marking as such with a > fallthrough; You need to add it if there is code in between. Since there is no code, just this comment, it shouldn't be necessary. Regards, Marco > > Dave > > > + 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 +841,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 +887,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 > > > > > -- > -----Open up your eyes, open up your mind, open up your code ------- > / Dr. David Alan Gilbert | Running GNU/Linux | Happy \ > \ dave @ treblig.org | | In Hex / > \ _________________________|_____ http://www.treblig.org |_______/ >
On 2/5/24 08:54, Marco Felsch wrote: > Hi David, > > On 24-02-05, Dr. David Alan Gilbert wrote: >> * Marco Felsch (m.felsch@pengutronix.de) wrote: >>> 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 <m.felsch@pengutronix.de> >>> --- >>> drivers/usb/typec/tcpm/tcpci.c | 43 ++++++++++++++++++++++++++++++++++ >>> include/linux/usb/tcpci.h | 8 +++++++ >>> 2 files changed, 51 insertions(+) >>> >>> diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c >>> index 7118551827f6..7ce9d4923bc7 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,27 @@ 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 */ >> >> Is that intended to be a fallthrough? If so I guess it needs >> marking as such with a >> fallthrough; > > You need to add it if there is code in between. Since there is no code, > just this comment, it shouldn't be necessary. > Still, I think it would be desirable here to clarify that this is not a lost return but intentionally sets TCPC_CONFIG_STD_OUTPUT_ORIENTATION_NORMAL. Guenter > Regards, > Marco > >> >> Dave >> >>> + 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 +841,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 +887,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 >>> >>> >> -- >> -----Open up your eyes, open up your mind, open up your code ------- >> / Dr. David Alan Gilbert | Running GNU/Linux | Happy \ >> \ dave @ treblig.org | | In Hex / >> \ _________________________|_____ http://www.treblig.org |_______/ >>
On 24-02-05, Guenter Roeck wrote: > On 2/5/24 08:54, Marco Felsch wrote: > > Hi David, > > > > On 24-02-05, Dr. David Alan Gilbert wrote: > > > * Marco Felsch (m.felsch@pengutronix.de) wrote: > > > > 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 <m.felsch@pengutronix.de> > > > > --- > > > > drivers/usb/typec/tcpm/tcpci.c | 43 ++++++++++++++++++++++++++++++++++ > > > > include/linux/usb/tcpci.h | 8 +++++++ > > > > 2 files changed, 51 insertions(+) > > > > > > > > diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c > > > > index 7118551827f6..7ce9d4923bc7 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,27 @@ 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 */ > > > > > > Is that intended to be a fallthrough? If so I guess it needs > > > marking as such with a > > > fallthrough; > > > > You need to add it if there is code in between. Since there is no code, > > just this comment, it shouldn't be necessary. > > > > Still, I think it would be desirable here to clarify that this > is not a lost return but intentionally sets > TCPC_CONFIG_STD_OUTPUT_ORIENTATION_NORMAL. Sure, I will adapt it once the complete patchset is reviewed. Regards, Marco > Guenter > > > Regards, > > Marco > > > > > > > > Dave > > > > > > > + 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 +841,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 +887,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 > > > > > > > > > > > -- > > > -----Open up your eyes, open up your mind, open up your code ------- > > > / Dr. David Alan Gilbert | Running GNU/Linux | Happy \ > > > \ dave @ treblig.org | | In Hex / > > > \ _________________________|_____ http://www.treblig.org |_______/ > > > > >
diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index 7118551827f6..7ce9d4923bc7 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,27 @@ 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 */ + 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 +841,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 +887,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,