linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/4] USB-C TCPM Orientation Support
@ 2024-02-22 21:08 Marco Felsch
  2024-02-22 21:09 ` [PATCH v3 1/4] dt-bindings: usb: typec-tcpci: add tcpci fallback binding Marco Felsch
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Marco Felsch @ 2024-02-22 21:08 UTC (permalink / raw)
  To: gregkh, robh+dt, krzysztof.kozlowski+dt, conor+dt, linux,
	heikki.krogerus, jun.li
  Cc: devicetree, linux-usb, linux-kernel, kernel

Hi,

this adds the support to control the optional connector-orientation
available on some TCPC from the TCPM.

I used an custom board with OnSemi FUSB307B TCPC which is spec [1]
compatible but albeit the spec [1] says that this pin is controlled by
the TCPC if 'TCPC_CONTROL.DebugAccessoryControl = 0' it isn't at least
for this device.

I'm unsure if the usb tcpci spec has an copy'n'paste failure since
'TCPC_CONTROL.DebugAccessoryControl' shouldn't control the state of the
'connector orientation' pin or if the OnSemi FUSB307B has an HW bug.
Since on my device the 'TCPC_CONTROL.DebugAccessoryControl' is set to
0 but the register wasn't updated automatically.

The patch adapting the existing dts files is send separately, as
requested.

Regards,
  Marco

[1] https://www.usb.org/sites/default/files/documents/usb-port_controller_specification_rev2.0_v1.0_0.pdf

Marco Felsch (4):
  dt-bindings: usb: typec-tcpci: add tcpci fallback binding
  usb: typec: tcpci: add generic tcpci fallback compatible
  usb: typec: tcpm: add support to set tcpc connector orientatition
  usb: typec: tcpci: add support to set connector orientation

 .../devicetree/bindings/usb/nxp,ptn5110.yaml  |  6 ++-
 drivers/usb/typec/tcpm/tcpci.c                | 45 +++++++++++++++++++
 drivers/usb/typec/tcpm/tcpm.c                 |  6 +++
 include/linux/usb/tcpci.h                     |  8 ++++
 include/linux/usb/tcpm.h                      |  2 +
 5 files changed, 65 insertions(+), 2 deletions(-)

-- 
2.39.2


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v3 1/4] dt-bindings: usb: typec-tcpci: add tcpci fallback binding
  2024-02-22 21:08 [PATCH v3 0/4] USB-C TCPM Orientation Support Marco Felsch
@ 2024-02-22 21:09 ` Marco Felsch
  2024-02-26  8:56   ` Krzysztof Kozlowski
  2024-02-22 21:09 ` [PATCH v3 2/4] usb: typec: tcpci: add generic tcpci fallback compatible Marco Felsch
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Marco Felsch @ 2024-02-22 21:09 UTC (permalink / raw)
  To: gregkh, robh+dt, krzysztof.kozlowski+dt, conor+dt, linux,
	heikki.krogerus, jun.li
  Cc: devicetree, linux-usb, linux-kernel, kernel

The NXP PTN5110 [1] is an TCPCI [2] compatible chip, so add the fallback
binding.

[1] https://www.nxp.com/docs/en/data-sheet/PTN5110.pdf
[2] 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>
---
v3:
- use items
- adapt example

v2:
- rephrase commit message

 Documentation/devicetree/bindings/usb/nxp,ptn5110.yaml | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/nxp,ptn5110.yaml b/Documentation/devicetree/bindings/usb/nxp,ptn5110.yaml
index eaedb4cc6b6c..65a8632b4d9e 100644
--- a/Documentation/devicetree/bindings/usb/nxp,ptn5110.yaml
+++ b/Documentation/devicetree/bindings/usb/nxp,ptn5110.yaml
@@ -11,7 +11,9 @@ maintainers:
 
 properties:
   compatible:
-    const: nxp,ptn5110
+    items:
+      - const: nxp,ptn5110
+      - const: tcpci
 
   reg:
     maxItems: 1
@@ -41,7 +43,7 @@ examples:
         #size-cells = <0>;
 
         tcpci@50 {
-            compatible = "nxp,ptn5110";
+            compatible = "nxp,ptn5110", "tcpci";
             reg = <0x50>;
             interrupt-parent = <&gpio3>;
             interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 2/4] usb: typec: tcpci: add generic tcpci fallback compatible
  2024-02-22 21:08 [PATCH v3 0/4] USB-C TCPM Orientation Support Marco Felsch
  2024-02-22 21:09 ` [PATCH v3 1/4] dt-bindings: usb: typec-tcpci: add tcpci fallback binding Marco Felsch
@ 2024-02-22 21:09 ` Marco Felsch
  2024-02-26  8:02   ` Heikki Krogerus
  2024-02-22 21:09 ` [PATCH v3 3/4] usb: typec: tcpm: add support to set tcpc connector orientatition Marco Felsch
  2024-02-22 21:09 ` [PATCH v3 4/4] usb: typec: tcpci: add support to set connector orientation Marco Felsch
  3 siblings, 1 reply; 13+ messages in thread
From: Marco Felsch @ 2024-02-22 21:09 UTC (permalink / raw)
  To: gregkh, robh+dt, krzysztof.kozlowski+dt, conor+dt, linux,
	heikki.krogerus, jun.li
  Cc: devicetree, linux-usb, linux-kernel, kernel

The driver already support the tcpci binding for the i2c_device_id so
add the support for the of_device_id too.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
v3:
- no changes
v2:
- no changes

 drivers/usb/typec/tcpm/tcpci.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
index 0ee3e6e29bb1..7118551827f6 100644
--- a/drivers/usb/typec/tcpm/tcpci.c
+++ b/drivers/usb/typec/tcpm/tcpci.c
@@ -889,6 +889,7 @@ MODULE_DEVICE_TABLE(i2c, tcpci_id);
 #ifdef CONFIG_OF
 static const struct of_device_id tcpci_of_match[] = {
 	{ .compatible = "nxp,ptn5110", },
+	{ .compatible = "tcpci", },
 	{},
 };
 MODULE_DEVICE_TABLE(of, tcpci_of_match);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 3/4] usb: typec: tcpm: add support to set tcpc connector orientatition
  2024-02-22 21:08 [PATCH v3 0/4] USB-C TCPM Orientation Support Marco Felsch
  2024-02-22 21:09 ` [PATCH v3 1/4] dt-bindings: usb: typec-tcpci: add tcpci fallback binding Marco Felsch
  2024-02-22 21:09 ` [PATCH v3 2/4] usb: typec: tcpci: add generic tcpci fallback compatible Marco Felsch
@ 2024-02-22 21:09 ` Marco Felsch
  2024-02-26  8:03   ` Heikki Krogerus
  2024-02-22 21:09 ` [PATCH v3 4/4] usb: typec: tcpci: add support to set connector orientation Marco Felsch
  3 siblings, 1 reply; 13+ messages in thread
From: Marco Felsch @ 2024-02-22 21:09 UTC (permalink / raw)
  To: gregkh, robh+dt, krzysztof.kozlowski+dt, conor+dt, linux,
	heikki.krogerus, jun.li
  Cc: devicetree, linux-usb, linux-kernel, kernel

This adds the support to set the connector orientation value
accordingly. This is part of the optional CONFIG_STANDARD_OUTPUT
register 0x18, specified within the USB port controller spsicification
rev. 2.0 [1].

[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>
---
v3:
- no changes
v2:
- no changes

 drivers/usb/typec/tcpm/tcpm.c | 6 ++++++
 include/linux/usb/tcpm.h      | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 5945e3a2b0f7..85ca26687324 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -1099,6 +1099,12 @@ static int tcpm_set_roles(struct tcpm_port *port, bool attached,
 	if (ret < 0)
 		return ret;
 
+	if (port->tcpc->set_orientation) {
+		ret = port->tcpc->set_orientation(port->tcpc, orientation);
+		if (ret < 0)
+			return ret;
+	}
+
 	port->pwr_role = role;
 	port->data_role = data;
 	typec_set_data_role(port->typec_port, data);
diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h
index 65fac5e1f317..93b681ff3ef9 100644
--- a/include/linux/usb/tcpm.h
+++ b/include/linux/usb/tcpm.h
@@ -133,6 +133,8 @@ struct tcpc_dev {
 		      enum typec_cc_status *cc2);
 	int (*set_polarity)(struct tcpc_dev *dev,
 			    enum typec_cc_polarity polarity);
+	int (*set_orientation)(struct tcpc_dev *dev,
+			       enum typec_orientation orientation);
 	int (*set_vconn)(struct tcpc_dev *dev, bool on);
 	int (*set_vbus)(struct tcpc_dev *dev, bool on, bool charge);
 	int (*set_current_limit)(struct tcpc_dev *dev, u32 max_ma, u32 mv);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v3 4/4] usb: typec: tcpci: add support to set connector orientation
  2024-02-22 21:08 [PATCH v3 0/4] USB-C TCPM Orientation Support Marco Felsch
                   ` (2 preceding siblings ...)
  2024-02-22 21:09 ` [PATCH v3 3/4] usb: typec: tcpm: add support to set tcpc connector orientatition Marco Felsch
@ 2024-02-22 21:09 ` Marco Felsch
  2024-02-26  8:13   ` Heikki Krogerus
  2024-03-12 11:28   ` Heikki Krogerus
  3 siblings, 2 replies; 13+ messages in thread
From: Marco Felsch @ 2024-02-22 21:09 UTC (permalink / raw)
  To: gregkh, robh+dt, krzysztof.kozlowski+dt, conor+dt, linux,
	heikki.krogerus, jun.li
  Cc: devicetree, linux-usb, linux-kernel, kernel

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>
---
v3:
- no changes
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, &reg);
+	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


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 2/4] usb: typec: tcpci: add generic tcpci fallback compatible
  2024-02-22 21:09 ` [PATCH v3 2/4] usb: typec: tcpci: add generic tcpci fallback compatible Marco Felsch
@ 2024-02-26  8:02   ` Heikki Krogerus
  0 siblings, 0 replies; 13+ messages in thread
From: Heikki Krogerus @ 2024-02-26  8:02 UTC (permalink / raw)
  To: Marco Felsch
  Cc: gregkh, robh+dt, krzysztof.kozlowski+dt, conor+dt, linux, jun.li,
	devicetree, linux-usb, linux-kernel, kernel

On Thu, Feb 22, 2024 at 10:09:01PM +0100, Marco Felsch wrote:
> The driver already support the tcpci binding for the i2c_device_id so
> add the support for the of_device_id too.
> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
> v3:
> - no changes
> v2:
> - no changes
> 
>  drivers/usb/typec/tcpm/tcpci.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
> index 0ee3e6e29bb1..7118551827f6 100644
> --- a/drivers/usb/typec/tcpm/tcpci.c
> +++ b/drivers/usb/typec/tcpm/tcpci.c
> @@ -889,6 +889,7 @@ MODULE_DEVICE_TABLE(i2c, tcpci_id);
>  #ifdef CONFIG_OF
>  static const struct of_device_id tcpci_of_match[] = {
>  	{ .compatible = "nxp,ptn5110", },
> +	{ .compatible = "tcpci", },
>  	{},
>  };
>  MODULE_DEVICE_TABLE(of, tcpci_of_match);
> -- 
> 2.39.2

-- 
heikki

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 3/4] usb: typec: tcpm: add support to set tcpc connector orientatition
  2024-02-22 21:09 ` [PATCH v3 3/4] usb: typec: tcpm: add support to set tcpc connector orientatition Marco Felsch
@ 2024-02-26  8:03   ` Heikki Krogerus
  0 siblings, 0 replies; 13+ messages in thread
From: Heikki Krogerus @ 2024-02-26  8:03 UTC (permalink / raw)
  To: Marco Felsch
  Cc: gregkh, robh+dt, krzysztof.kozlowski+dt, conor+dt, linux, jun.li,
	devicetree, linux-usb, linux-kernel, kernel

On Thu, Feb 22, 2024 at 10:09:02PM +0100, Marco Felsch wrote:
> This adds the support to set the connector orientation value
> accordingly. This is part of the optional CONFIG_STANDARD_OUTPUT
> register 0x18, specified within the USB port controller spsicification
> rev. 2.0 [1].
> 
> [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>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
> v3:
> - no changes
> v2:
> - no changes
> 
>  drivers/usb/typec/tcpm/tcpm.c | 6 ++++++
>  include/linux/usb/tcpm.h      | 2 ++
>  2 files changed, 8 insertions(+)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 5945e3a2b0f7..85ca26687324 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -1099,6 +1099,12 @@ static int tcpm_set_roles(struct tcpm_port *port, bool attached,
>  	if (ret < 0)
>  		return ret;
>  
> +	if (port->tcpc->set_orientation) {
> +		ret = port->tcpc->set_orientation(port->tcpc, orientation);
> +		if (ret < 0)
> +			return ret;
> +	}
> +
>  	port->pwr_role = role;
>  	port->data_role = data;
>  	typec_set_data_role(port->typec_port, data);
> diff --git a/include/linux/usb/tcpm.h b/include/linux/usb/tcpm.h
> index 65fac5e1f317..93b681ff3ef9 100644
> --- a/include/linux/usb/tcpm.h
> +++ b/include/linux/usb/tcpm.h
> @@ -133,6 +133,8 @@ struct tcpc_dev {
>  		      enum typec_cc_status *cc2);
>  	int (*set_polarity)(struct tcpc_dev *dev,
>  			    enum typec_cc_polarity polarity);
> +	int (*set_orientation)(struct tcpc_dev *dev,
> +			       enum typec_orientation orientation);
>  	int (*set_vconn)(struct tcpc_dev *dev, bool on);
>  	int (*set_vbus)(struct tcpc_dev *dev, bool on, bool charge);
>  	int (*set_current_limit)(struct tcpc_dev *dev, u32 max_ma, u32 mv);
> -- 
> 2.39.2

-- 
heikki

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 4/4] usb: typec: tcpci: add support to set connector orientation
  2024-02-22 21:09 ` [PATCH v3 4/4] usb: typec: tcpci: add support to set connector orientation Marco Felsch
@ 2024-02-26  8:13   ` Heikki Krogerus
  2024-02-26 12:27     ` Marco Felsch
  2024-03-12 11:28   ` Heikki Krogerus
  1 sibling, 1 reply; 13+ messages in thread
From: Heikki Krogerus @ 2024-02-26  8:13 UTC (permalink / raw)
  To: Marco Felsch
  Cc: gregkh, robh+dt, krzysztof.kozlowski+dt, conor+dt, linux, jun.li,
	devicetree, linux-usb, linux-kernel, kernel

On Thu, Feb 22, 2024 at 10:09:03PM +0100, Marco Felsch 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>
> ---
> v3:
> - no changes
> 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, &reg);
> +	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;

I don't think that flag is needed - not yet at least. Please just call
tcpci_check_std_output_cap() directly from here.

>  	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

-- 
heikki

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 1/4] dt-bindings: usb: typec-tcpci: add tcpci fallback binding
  2024-02-22 21:09 ` [PATCH v3 1/4] dt-bindings: usb: typec-tcpci: add tcpci fallback binding Marco Felsch
@ 2024-02-26  8:56   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 13+ messages in thread
From: Krzysztof Kozlowski @ 2024-02-26  8:56 UTC (permalink / raw)
  To: Marco Felsch, gregkh, robh+dt, krzysztof.kozlowski+dt, conor+dt,
	linux, heikki.krogerus, jun.li
  Cc: devicetree, linux-usb, linux-kernel, kernel

On 22/02/2024 22:09, Marco Felsch wrote:
> The NXP PTN5110 [1] is an TCPCI [2] compatible chip, so add the fallback
> binding.
> 

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 4/4] usb: typec: tcpci: add support to set connector orientation
  2024-02-26  8:13   ` Heikki Krogerus
@ 2024-02-26 12:27     ` Marco Felsch
  2024-03-07  9:46       ` Marco Felsch
  2024-03-12 11:27       ` Heikki Krogerus
  0 siblings, 2 replies; 13+ messages in thread
From: Marco Felsch @ 2024-02-26 12:27 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: gregkh, robh+dt, krzysztof.kozlowski+dt, conor+dt, linux, jun.li,
	devicetree, linux-usb, linux-kernel, kernel

Hi,

On 24-02-26, Heikki Krogerus wrote:
> On Thu, Feb 22, 2024 at 10:09:03PM +0100, Marco Felsch 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>
> > ---
> > v3:
> > - no changes
> > 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, &reg);
> > +	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;
> 
> I don't think that flag is needed - not yet at least. Please just call
> tcpci_check_std_output_cap() directly from here.

The reason for having it this way was to not break exsisting user like:
tcpci_rt1711h, tcpci_mt6370, tcpci_maxim which may or may not implement
the TCPC_STD_OUTPUT_CAP_ORIENTATION. This way the users of
tcpci_register_port() can decide by on its own if they do have this
feature or not and how this is checked. I'm fine with your proposal if
you still think that we can check this unconditional.

Regards,
  Marco

> >  	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
> 
> -- 
> heikki
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 4/4] usb: typec: tcpci: add support to set connector orientation
  2024-02-26 12:27     ` Marco Felsch
@ 2024-03-07  9:46       ` Marco Felsch
  2024-03-12 11:27       ` Heikki Krogerus
  1 sibling, 0 replies; 13+ messages in thread
From: Marco Felsch @ 2024-03-07  9:46 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: devicetree, conor+dt, kernel, gregkh, linux-usb, linux-kernel,
	robh+dt, krzysztof.kozlowski+dt, linux, jun.li

Hi,

gentle ping, since Greg started to pick the other patches.

On 24-02-26, Marco Felsch wrote:
> Hi,
> 
> On 24-02-26, Heikki Krogerus wrote:
> > On Thu, Feb 22, 2024 at 10:09:03PM +0100, Marco Felsch 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>
> > > ---
> > > v3:
> > > - no changes
> > > 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, &reg);
> > > +	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;
> > 
> > I don't think that flag is needed - not yet at least. Please just call
> > tcpci_check_std_output_cap() directly from here.
> 
> The reason for having it this way was to not break exsisting user like:
> tcpci_rt1711h, tcpci_mt6370, tcpci_maxim which may or may not implement
> the TCPC_STD_OUTPUT_CAP_ORIENTATION. This way the users of
> tcpci_register_port() can decide by on its own if they do have this
> feature or not and how this is checked. I'm fine with your proposal if
> you still think that we can check this unconditional.
						      ^
						      ?

Regards,
  Marco

> Regards,
>   Marco
> 
> > >  	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
> > 
> > -- 
> > heikki
> > 
> 
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 4/4] usb: typec: tcpci: add support to set connector orientation
  2024-02-26 12:27     ` Marco Felsch
  2024-03-07  9:46       ` Marco Felsch
@ 2024-03-12 11:27       ` Heikki Krogerus
  1 sibling, 0 replies; 13+ messages in thread
From: Heikki Krogerus @ 2024-03-12 11:27 UTC (permalink / raw)
  To: Marco Felsch
  Cc: gregkh, robh+dt, krzysztof.kozlowski+dt, conor+dt, linux, jun.li,
	devicetree, linux-usb, linux-kernel, kernel

Hi,

I'm sorry to keep you waiting.

On Mon, Feb 26, 2024 at 01:27:01PM +0100, Marco Felsch wrote:
> Hi,
> 
> On 24-02-26, Heikki Krogerus wrote:
> > On Thu, Feb 22, 2024 at 10:09:03PM +0100, Marco Felsch 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>
> > > ---
> > > v3:
> > > - no changes
> > > 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, &reg);
> > > +	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;
> > 
> > I don't think that flag is needed - not yet at least. Please just call
> > tcpci_check_std_output_cap() directly from here.
> 
> The reason for having it this way was to not break exsisting user like:
> tcpci_rt1711h, tcpci_mt6370, tcpci_maxim which may or may not implement
> the TCPC_STD_OUTPUT_CAP_ORIENTATION. This way the users of
> tcpci_register_port() can decide by on its own if they do have this
> feature or not and how this is checked. I'm fine with your proposal if
> you still think that we can check this unconditional.

Ah, I failed to consider those other glue drivers. This is fine as it
is. I'm really sorry about the delay.

Br,

-- 
heikki

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v3 4/4] usb: typec: tcpci: add support to set connector orientation
  2024-02-22 21:09 ` [PATCH v3 4/4] usb: typec: tcpci: add support to set connector orientation Marco Felsch
  2024-02-26  8:13   ` Heikki Krogerus
@ 2024-03-12 11:28   ` Heikki Krogerus
  1 sibling, 0 replies; 13+ messages in thread
From: Heikki Krogerus @ 2024-03-12 11:28 UTC (permalink / raw)
  To: Marco Felsch
  Cc: gregkh, robh+dt, krzysztof.kozlowski+dt, conor+dt, linux, jun.li,
	devicetree, linux-usb, linux-kernel, kernel

On Thu, Feb 22, 2024 at 10:09:03PM +0100, Marco Felsch 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>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>


-- 
heikki

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-03-12 11:28 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-22 21:08 [PATCH v3 0/4] USB-C TCPM Orientation Support Marco Felsch
2024-02-22 21:09 ` [PATCH v3 1/4] dt-bindings: usb: typec-tcpci: add tcpci fallback binding Marco Felsch
2024-02-26  8:56   ` Krzysztof Kozlowski
2024-02-22 21:09 ` [PATCH v3 2/4] usb: typec: tcpci: add generic tcpci fallback compatible Marco Felsch
2024-02-26  8:02   ` Heikki Krogerus
2024-02-22 21:09 ` [PATCH v3 3/4] usb: typec: tcpm: add support to set tcpc connector orientatition Marco Felsch
2024-02-26  8:03   ` Heikki Krogerus
2024-02-22 21:09 ` [PATCH v3 4/4] usb: typec: tcpci: add support to set connector orientation Marco Felsch
2024-02-26  8:13   ` Heikki Krogerus
2024-02-26 12:27     ` Marco Felsch
2024-03-07  9:46       ` Marco Felsch
2024-03-12 11:27       ` Heikki Krogerus
2024-03-12 11:28   ` Heikki Krogerus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).