2022-08-01 10:44:33

by Gene Chen

[permalink] [raw]
Subject: [PATCH v3 0/7] usb: typec: tcpci_rt1711h: Add compatible with rt1715

This patch series add binding document for rt1711h and compatible driver with
rt1715. Also add different remote rp workaround and initial phy setting.

Gene Chen (7)
- dt-bindings usb: typec: rt1711h: Add binding for Richtek RT1711H
- usb: typec: tcpci_rt1711h: Fix vendor setting when set vconn
- usb: typec: tcpci_rt1711h: Add regulator support when source vbus
- usb: typec: tcpci_rt1711h: Add initial phy setting
- usb: typec: tcpci_rt1711h: Add compatible id with rt1715
- usb: typec: tcpci: Move function "tcpci_to_typec_cc" to common
- usb: typec: tcpci_rt1711h: Fix CC PHY noise filter of voltage level

Documentation/devicetree/bindings/usb/richtek,rt1711h.yaml | 100 ++++++++
drivers/usb/typec/tcpm/tcpci.c | 22 -
drivers/usb/typec/tcpm/tcpci.h | 23 +
drivers/usb/typec/tcpm/tcpci_rt1711h.c | 159 +++++++++++--
4 files changed, 265 insertions(+), 39 deletions(-)

changelogs between v2 & v3
- binding compatible name with did to validate chip
- remove postfix name "_mask"
- move get cc status macro to header

changelogs between v1 & v2
- Seperate patch by specific purpose
- Fix binding document error
- Set cc change woakaround without using tcpci ops callback




2022-08-01 10:44:47

by Gene Chen

[permalink] [raw]
Subject: [PATCH v3 3/7] usb: typec: tcpci_rt1711h: Add regulator support when source vbus

From: Gene Chen <[email protected]>

Add regulator support when source vbus

Signed-off-by: Gene Chen <[email protected]>
---
drivers/usb/typec/tcpm/tcpci_rt1711h.c | 28 ++++++++++++++++++++++++++
1 file changed, 28 insertions(+)

diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
index 6197d9a05d36..df7bfe299987 100644
--- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c
+++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
@@ -12,6 +12,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
#include <linux/usb/tcpm.h>

#include "tcpci.h"
@@ -42,6 +43,8 @@ struct rt1711h_chip {
struct tcpci_data data;
struct tcpci *tcpci;
struct device *dev;
+ struct regulator *vbus;
+ bool src_en;
};

static int rt1711h_read16(struct rt1711h_chip *chip, unsigned int reg, u16 *val)
@@ -105,6 +108,26 @@ static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata)

/* dcSRC.DRP : 33% */
return rt1711h_write16(chip, RT1711H_RTCTRL16, 330);
+
+}
+
+static int rt1711h_set_vbus(struct tcpci *tcpci, struct tcpci_data *tdata,
+ bool src, bool snk)
+{
+ struct rt1711h_chip *chip = tdata_to_rt1711h(tdata);
+ int ret;
+
+ if (chip->src_en == src)
+ return 0;
+
+ if (src)
+ ret = regulator_enable(chip->vbus);
+ else
+ ret = regulator_disable(chip->vbus);
+
+ if (!ret)
+ chip->src_en = src;
+ return ret;
}

static int rt1711h_set_vconn(struct tcpci *tcpci, struct tcpci_data *tdata,
@@ -248,7 +271,12 @@ static int rt1711h_probe(struct i2c_client *client,
if (ret < 0)
return ret;

+ chip->vbus = devm_regulator_get(&client->dev, "vbus");
+ if (IS_ERR(chip->vbus))
+ return PTR_ERR(chip->vbus);
+
chip->data.init = rt1711h_init;
+ chip->data.set_vbus = rt1711h_set_vbus;
chip->data.set_vconn = rt1711h_set_vconn;
chip->data.start_drp_toggling = rt1711h_start_drp_toggling;
chip->tcpci = tcpci_register_port(chip->dev, &chip->data);
--
2.25.1


2022-08-01 11:14:33

by Gene Chen

[permalink] [raw]
Subject: [PATCH v3 1/7] dt-bindings usb: typec: rt1711h: Add binding for Richtek RT1711H

From: Gene Chen <[email protected]>

Add binding for Richtek RT1711H

Signed-off-by: Gene Chen <[email protected]>
Reviewed-by: Rob Herring <[email protected]>
---
.../bindings/usb/richtek,rt1711h.yaml | 100 ++++++++++++++++++
1 file changed, 100 insertions(+)
create mode 100644 Documentation/devicetree/bindings/usb/richtek,rt1711h.yaml

diff --git a/Documentation/devicetree/bindings/usb/richtek,rt1711h.yaml b/Documentation/devicetree/bindings/usb/richtek,rt1711h.yaml
new file mode 100644
index 000000000000..1999f614c89b
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/richtek,rt1711h.yaml
@@ -0,0 +1,100 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/usb/richtek,rt1711h.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: Richtek RT1711H Type-C Port Switch and Power Delivery controller
+
+maintainers:
+ - Gene Chen <[email protected]>
+
+description: |
+ The RT1711H is a USB Type-C controller that complies with the latest
+ USB Type-C and PD standards. It does the USB Type-C detection including attach
+ and orientation. It integrates the physical layer of the USB BMC power
+ delivery protocol to allow up to 100W of power. The BMC PD block enables full
+ support for alternative interfaces of the Type-C specification.
+
+properties:
+ compatible:
+ enum:
+ - richtek,rt1711h
+ - richtek,rt1715
+ description:
+ RT1711H support PD20, RT1715 support PD30 except Fast Role Swap.
+
+ reg:
+ maxItems: 1
+
+ interrupts:
+ maxItems: 1
+
+ wakeup-source:
+ type: boolean
+
+ connector:
+ type: object
+ $ref: /schemas/connector/usb-connector.yaml#
+ description:
+ Properties for usb c connector.
+
+additionalProperties: false
+
+required:
+ - compatible
+ - reg
+ - connector
+ - interrupts
+
+examples:
+ - |
+ #include <dt-bindings/interrupt-controller/irq.h>
+ #include <dt-bindings/usb/pd.h>
+ i2c0 {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ rt1711h@4e {
+ compatible = "richtek,rt1711h";
+ reg = <0x4e>;
+ interrupts-extended = <&gpio26 3 IRQ_TYPE_LEVEL_LOW>;
+ wakeup-source;
+
+ connector {
+ compatible = "usb-c-connector";
+ label = "USB-C";
+ data-role = "dual";
+ power-role = "dual";
+ try-power-role = "sink";
+ source-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP)>;
+ sink-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP)>;
+ op-sink-microwatt = <10000000>;
+
+ ports {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ port@0 {
+ reg = <0>;
+ endpoint {
+ remote-endpoint = <&usb_hs>;
+ };
+ };
+ port@1 {
+ reg = <1>;
+ endpoint {
+ remote-endpoint = <&usb_ss>;
+ };
+ };
+ port@2 {
+ reg = <2>;
+ endpoint {
+ remote-endpoint = <&dp_aux>;
+ };
+ };
+ };
+ };
+ };
+ };
+...
--
2.25.1


2022-08-01 11:15:25

by Gene Chen

[permalink] [raw]
Subject: [PATCH v3 2/7] usb: typec: tcpci_rt1711h: Fix vendor setting when set vconn

From: Gene Chen <[email protected]>

replace overwrite whole register with update bits

Signed-off-by: Gene Chen <[email protected]>
---
drivers/usb/typec/tcpm/tcpci_rt1711h.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
index b56a0880a044..6197d9a05d36 100644
--- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c
+++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
@@ -5,13 +5,15 @@
* Richtek RT1711H Type-C Chip Driver
*/

-#include <linux/kernel.h>
-#include <linux/module.h>
+#include <linux/bits.h>
+#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/interrupt.h>
-#include <linux/gpio/consumer.h>
-#include <linux/usb/tcpm.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
#include <linux/regmap.h>
+#include <linux/usb/tcpm.h>
+
#include "tcpci.h"

#define RT1711H_VID 0x29CF
@@ -23,6 +25,7 @@
#define RT1711H_RTCTRL8_SET(ck300, ship_off, auto_idle, tout) \
(((ck300) << 7) | ((ship_off) << 5) | \
((auto_idle) << 3) | ((tout) & 0x07))
+#define RT1711H_AUTOIDLEEN BIT(3)

#define RT1711H_RTCTRL11 0x9E

@@ -109,8 +112,8 @@ static int rt1711h_set_vconn(struct tcpci *tcpci, struct tcpci_data *tdata,
{
struct rt1711h_chip *chip = tdata_to_rt1711h(tdata);

- return rt1711h_write8(chip, RT1711H_RTCTRL8,
- RT1711H_RTCTRL8_SET(0, 1, !enable, 2));
+ return regmap_update_bits(chip->data.regmap, RT1711H_RTCTRL8,
+ RT1711H_AUTOIDLEEN, enable ? 0 : RT1711H_AUTOIDLEEN);
}

static int rt1711h_start_drp_toggling(struct tcpci *tcpci,
--
2.25.1


2022-08-02 08:02:13

by Heikki Krogerus

[permalink] [raw]
Subject: Re: [PATCH v3 2/7] usb: typec: tcpci_rt1711h: Fix vendor setting when set vconn

Hi Gene,

On Mon, Aug 01, 2022 at 06:14:42PM +0800, Gene Chen wrote:
> From: Gene Chen <[email protected]>
>
> replace overwrite whole register with update bits
>
> Signed-off-by: Gene Chen <[email protected]>
> ---
> drivers/usb/typec/tcpm/tcpci_rt1711h.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> index b56a0880a044..6197d9a05d36 100644
> --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> @@ -5,13 +5,15 @@
> * Richtek RT1711H Type-C Chip Driver
> */
>
> -#include <linux/kernel.h>
> -#include <linux/module.h>
> +#include <linux/bits.h>
> +#include <linux/gpio/consumer.h>
> #include <linux/i2c.h>
> #include <linux/interrupt.h>
> -#include <linux/gpio/consumer.h>
> -#include <linux/usb/tcpm.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> #include <linux/regmap.h>
> +#include <linux/usb/tcpm.h>

That header reshuffling is not necessary for this change - at least you
are not giving any reason for it in your commit message.

If there is no real need for that in this patch, then please leave the
headers as they are. You can propose changing the order of the headers
in a separate patch. Though, I would not bother with it unless there
is some real benefit in doing so, and I'm pretty sure there isn't any.

> #include "tcpci.h"
>
> #define RT1711H_VID 0x29CF
> @@ -23,6 +25,7 @@
> #define RT1711H_RTCTRL8_SET(ck300, ship_off, auto_idle, tout) \
> (((ck300) << 7) | ((ship_off) << 5) | \
> ((auto_idle) << 3) | ((tout) & 0x07))
> +#define RT1711H_AUTOIDLEEN BIT(3)
>
> #define RT1711H_RTCTRL11 0x9E
>
> @@ -109,8 +112,8 @@ static int rt1711h_set_vconn(struct tcpci *tcpci, struct tcpci_data *tdata,
> {
> struct rt1711h_chip *chip = tdata_to_rt1711h(tdata);
>
> - return rt1711h_write8(chip, RT1711H_RTCTRL8,
> - RT1711H_RTCTRL8_SET(0, 1, !enable, 2));
> + return regmap_update_bits(chip->data.regmap, RT1711H_RTCTRL8,
> + RT1711H_AUTOIDLEEN, enable ? 0 : RT1711H_AUTOIDLEEN);
> }
>
> static int rt1711h_start_drp_toggling(struct tcpci *tcpci,
> --
> 2.25.1

thanks,

--
heikki

2022-08-02 08:24:47

by Heikki Krogerus

[permalink] [raw]
Subject: Re: [PATCH v3 3/7] usb: typec: tcpci_rt1711h: Add regulator support when source vbus

On Mon, Aug 01, 2022 at 06:14:43PM +0800, Gene Chen wrote:
> From: Gene Chen <[email protected]>
>
> Add regulator support when source vbus
>
> Signed-off-by: Gene Chen <[email protected]>

Acked-by: Heikki Krogerus <[email protected]>

> ---
> drivers/usb/typec/tcpm/tcpci_rt1711h.c | 28 ++++++++++++++++++++++++++
> 1 file changed, 28 insertions(+)
>
> diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> index 6197d9a05d36..df7bfe299987 100644
> --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> @@ -12,6 +12,7 @@
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
> #include <linux/usb/tcpm.h>
>
> #include "tcpci.h"
> @@ -42,6 +43,8 @@ struct rt1711h_chip {
> struct tcpci_data data;
> struct tcpci *tcpci;
> struct device *dev;
> + struct regulator *vbus;
> + bool src_en;
> };
>
> static int rt1711h_read16(struct rt1711h_chip *chip, unsigned int reg, u16 *val)
> @@ -105,6 +108,26 @@ static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata)
>
> /* dcSRC.DRP : 33% */
> return rt1711h_write16(chip, RT1711H_RTCTRL16, 330);
> +
> +}
> +
> +static int rt1711h_set_vbus(struct tcpci *tcpci, struct tcpci_data *tdata,
> + bool src, bool snk)
> +{
> + struct rt1711h_chip *chip = tdata_to_rt1711h(tdata);
> + int ret;
> +
> + if (chip->src_en == src)
> + return 0;
> +
> + if (src)
> + ret = regulator_enable(chip->vbus);
> + else
> + ret = regulator_disable(chip->vbus);
> +
> + if (!ret)
> + chip->src_en = src;
> + return ret;
> }
>
> static int rt1711h_set_vconn(struct tcpci *tcpci, struct tcpci_data *tdata,
> @@ -248,7 +271,12 @@ static int rt1711h_probe(struct i2c_client *client,
> if (ret < 0)
> return ret;
>
> + chip->vbus = devm_regulator_get(&client->dev, "vbus");
> + if (IS_ERR(chip->vbus))
> + return PTR_ERR(chip->vbus);
> +
> chip->data.init = rt1711h_init;
> + chip->data.set_vbus = rt1711h_set_vbus;
> chip->data.set_vconn = rt1711h_set_vconn;
> chip->data.start_drp_toggling = rt1711h_start_drp_toggling;
> chip->tcpci = tcpci_register_port(chip->dev, &chip->data);
> --
> 2.25.1

--
heikki

2022-08-03 06:42:06

by Gene Chen

[permalink] [raw]
Subject: Re: [PATCH v3 2/7] usb: typec: tcpci_rt1711h: Fix vendor setting when set vconn

Heikki Krogerus <[email protected]> 於 2022年8月2日 週二 下午3:57寫道:
>
> Hi Gene,
>
> On Mon, Aug 01, 2022 at 06:14:42PM +0800, Gene Chen wrote:
> > From: Gene Chen <[email protected]>
> >
> > replace overwrite whole register with update bits
> >
> > Signed-off-by: Gene Chen <[email protected]>
> > ---
> > drivers/usb/typec/tcpm/tcpci_rt1711h.c | 15 +++++++++------
> > 1 file changed, 9 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> > index b56a0880a044..6197d9a05d36 100644
> > --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> > +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> > @@ -5,13 +5,15 @@
> > * Richtek RT1711H Type-C Chip Driver
> > */
> >
> > -#include <linux/kernel.h>
> > -#include <linux/module.h>
> > +#include <linux/bits.h>
> > +#include <linux/gpio/consumer.h>
> > #include <linux/i2c.h>
> > #include <linux/interrupt.h>
> > -#include <linux/gpio/consumer.h>
> > -#include <linux/usb/tcpm.h>
> > +#include <linux/kernel.h>
> > +#include <linux/module.h>
> > #include <linux/regmap.h>
> > +#include <linux/usb/tcpm.h>
>
> That header reshuffling is not necessary for this change - at least you
> are not giving any reason for it in your commit message.
>
> If there is no real need for that in this patch, then please leave the
> headers as they are. You can propose changing the order of the headers
> in a separate patch. Though, I would not bother with it unless there
> is some real benefit in doing so, and I'm pretty sure there isn't any.
>

ACK, I will remove reshuffling.
It was suggested coding style by other reviewer in other driver.

> > #include "tcpci.h"
> >
> > #define RT1711H_VID 0x29CF
> > @@ -23,6 +25,7 @@
> > #define RT1711H_RTCTRL8_SET(ck300, ship_off, auto_idle, tout) \
> > (((ck300) << 7) | ((ship_off) << 5) | \
> > ((auto_idle) << 3) | ((tout) & 0x07))
> > +#define RT1711H_AUTOIDLEEN BIT(3)
> >
> > #define RT1711H_RTCTRL11 0x9E
> >
> > @@ -109,8 +112,8 @@ static int rt1711h_set_vconn(struct tcpci *tcpci, struct tcpci_data *tdata,
> > {
> > struct rt1711h_chip *chip = tdata_to_rt1711h(tdata);
> >
> > - return rt1711h_write8(chip, RT1711H_RTCTRL8,
> > - RT1711H_RTCTRL8_SET(0, 1, !enable, 2));
> > + return regmap_update_bits(chip->data.regmap, RT1711H_RTCTRL8,
> > + RT1711H_AUTOIDLEEN, enable ? 0 : RT1711H_AUTOIDLEEN);
> > }
> >
> > static int rt1711h_start_drp_toggling(struct tcpci *tcpci,
> > --
> > 2.25.1
>
> thanks,
>
> --
> heikki