2022-08-05 07:22:04

by Gene Chen

[permalink] [raw]
Subject: [PATCH v4 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_rt1711h.c | 150 +++++++++++--
include/linux/usb/tcpci.h | 22 +
4 files changed, 259 insertions(+), 35 deletions(-)

changelogs between v3 & v4
- remove reshuffling header
- fix commit message typo

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-05 07:22:28

by Gene Chen

[permalink] [raw]
Subject: [PATCH v4 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]>
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 f2f1fb0..fb19d7b 100644
--- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c
+++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
@@ -14,6 +14,7 @@
#include <linux/usb/tcpci.h>
#include <linux/usb/tcpm.h>
#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>

#define RT1711H_VID 0x29CF
#define RT1711H_PID 0x1711
@@ -41,6 +42,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)
@@ -104,6 +107,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,
@@ -247,7 +270,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.7.4


2022-08-05 07:32:43

by Gene Chen

[permalink] [raw]
Subject: [PATCH v4 6/7] usb: typec: tcpci: Move function "tcpci_to_typec_cc" to common

From: Gene Chen <[email protected]>

Move transition function "tcpci_to_typec_cc" to common header

Signed-off-by: Gene Chen <[email protected]>
Acked-by: Heikki Krogerus <[email protected]>
---
drivers/usb/typec/tcpm/tcpci.c | 22 ----------------------
include/linux/usb/tcpci.h | 22 ++++++++++++++++++++++
2 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
index 8127847..50674ec 100644
--- a/drivers/usb/typec/tcpm/tcpci.c
+++ b/drivers/usb/typec/tcpm/tcpci.c
@@ -27,11 +27,6 @@
#define VPPS_VALID_MIN_MV 100
#define VSINKDISCONNECT_PD_MIN_PERCENT 90

-#define tcpc_presenting_rd(reg, cc) \
- (!(TCPC_ROLE_CTRL_DRP & (reg)) && \
- (((reg) & (TCPC_ROLE_CTRL_## cc ##_MASK << TCPC_ROLE_CTRL_## cc ##_SHIFT)) == \
- (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_## cc ##_SHIFT)))
-
struct tcpci {
struct device *dev;

@@ -218,23 +213,6 @@ static int tcpci_start_toggling(struct tcpc_dev *tcpc,
TCPC_CMD_LOOK4CONNECTION);
}

-static enum typec_cc_status tcpci_to_typec_cc(unsigned int cc, bool sink)
-{
- switch (cc) {
- case 0x1:
- return sink ? TYPEC_CC_RP_DEF : TYPEC_CC_RA;
- case 0x2:
- return sink ? TYPEC_CC_RP_1_5 : TYPEC_CC_RD;
- case 0x3:
- if (sink)
- return TYPEC_CC_RP_3_0;
- fallthrough;
- case 0x0:
- default:
- return TYPEC_CC_OPEN;
- }
-}
-
static int tcpci_get_cc(struct tcpc_dev *tcpc,
enum typec_cc_status *cc1, enum typec_cc_status *cc2)
{
diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h
index 20c0bed..1765745 100644
--- a/include/linux/usb/tcpci.h
+++ b/include/linux/usb/tcpci.h
@@ -167,6 +167,11 @@
/* I2C_WRITE_BYTE_COUNT + 1 when TX_BUF_BYTE_x is only accessible I2C_WRITE_BYTE_COUNT */
#define TCPC_TRANSMIT_BUFFER_MAX_LEN 31

+#define tcpc_presenting_rd(reg, cc) \
+ (!(TCPC_ROLE_CTRL_DRP & (reg)) && \
+ (((reg) & (TCPC_ROLE_CTRL_## cc ##_MASK << TCPC_ROLE_CTRL_## cc ##_SHIFT)) == \
+ (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_## cc ##_SHIFT)))
+
struct tcpci;

/*
@@ -207,4 +212,21 @@ irqreturn_t tcpci_irq(struct tcpci *tcpci);

struct tcpm_port;
struct tcpm_port *tcpci_get_tcpm_port(struct tcpci *tcpci);
+
+static inline enum typec_cc_status tcpci_to_typec_cc(unsigned int cc, bool sink)
+{
+ switch (cc) {
+ case 0x1:
+ return sink ? TYPEC_CC_RP_DEF : TYPEC_CC_RA;
+ case 0x2:
+ return sink ? TYPEC_CC_RP_1_5 : TYPEC_CC_RD;
+ case 0x3:
+ if (sink)
+ return TYPEC_CC_RP_3_0;
+ fallthrough;
+ case 0x0:
+ default:
+ return TYPEC_CC_OPEN;
+ }
+}
#endif /* __LINUX_USB_TCPCI_H */
--
2.7.4


2022-08-05 07:32:51

by Gene Chen

[permalink] [raw]
Subject: [PATCH v4 5/7] usb: typec: tcpci_rt1711h: Add compatible id with rt1715

From: Gene Chen <[email protected]>

Add compatible id with rt1715, and add initial setting for
specific support PD30 command.

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

diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
index 5c51d04..ff7deae 100644
--- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c
+++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
@@ -18,6 +18,8 @@

#define RT1711H_VID 0x29CF
#define RT1711H_PID 0x1711
+#define RT1711H_DID 0x2171
+#define RT1715_DID 0x2173

#define RT1711H_PHYCTRL1 0x80
#define RT1711H_PHYCTRL2 0x81
@@ -29,6 +31,7 @@
(((ck300) << 7) | ((ship_off) << 5) | \
((auto_idle) << 3) | ((tout) & 0x07))
#define RT1711H_AUTOIDLEEN BIT(3)
+#define RT1711H_ENEXTMSG BIT(4)

#define RT1711H_RTCTRL11 0x9E

@@ -47,6 +50,7 @@ struct rt1711h_chip {
struct device *dev;
struct regulator *vbus;
bool src_en;
+ u16 did;
};

static int rt1711h_read16(struct rt1711h_chip *chip, unsigned int reg, u16 *val)
@@ -83,8 +87,9 @@ static struct rt1711h_chip *tdata_to_rt1711h(struct tcpci_data *tdata)

static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata)
{
- int ret;
struct rt1711h_chip *chip = tdata_to_rt1711h(tdata);
+ struct regmap *regmap = chip->data.regmap;
+ int ret;

/* CK 300K from 320K, shipping off, auto_idle enable, tout = 32ms */
ret = rt1711h_write8(chip, RT1711H_RTCTRL8,
@@ -92,6 +97,14 @@ static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata)
if (ret < 0)
return ret;

+ /* Enable PD30 extended message for RT1715 */
+ if (chip->did == RT1715_DID) {
+ ret = regmap_update_bits(regmap, RT1711H_RTCTRL8,
+ RT1711H_ENEXTMSG, RT1711H_ENEXTMSG);
+ if (ret < 0)
+ return ret;
+ }
+
/* I2C reset : (val + 1) * 12.5ms */
ret = rt1711h_write8(chip, RT1711H_RTCTRL11,
RT1711H_RTCTRL11_SET(1, 0x0F));
@@ -229,7 +242,7 @@ static int rt1711h_sw_reset(struct rt1711h_chip *chip)
return 0;
}

-static int rt1711h_check_revision(struct i2c_client *i2c)
+static int rt1711h_check_revision(struct i2c_client *i2c, struct rt1711h_chip *chip)
{
int ret;

@@ -247,7 +260,15 @@ static int rt1711h_check_revision(struct i2c_client *i2c)
dev_err(&i2c->dev, "pid is not correct, 0x%04x\n", ret);
return -ENODEV;
}
- return 0;
+ ret = i2c_smbus_read_word_data(i2c, TCPC_BCD_DEV);
+ if (ret < 0)
+ return ret;
+ if (ret != chip->did) {
+ dev_err(&i2c->dev, "did is not correct, 0x%04x\n", ret);
+ return -ENODEV;
+ }
+ dev_dbg(&i2c->dev, "did is 0x%04x\n", ret);
+ return ret;
}

static int rt1711h_probe(struct i2c_client *client,
@@ -256,16 +277,18 @@ static int rt1711h_probe(struct i2c_client *client,
int ret;
struct rt1711h_chip *chip;

- ret = rt1711h_check_revision(client);
+ chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
+ if (!chip)
+ return -ENOMEM;
+
+ chip->did = (size_t)device_get_match_data(&client->dev);
+
+ ret = rt1711h_check_revision(client, chip);
if (ret < 0) {
dev_err(&client->dev, "check vid/pid fail\n");
return ret;
}

- chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
- if (!chip)
- return -ENOMEM;
-
chip->data.regmap = devm_regmap_init_i2c(client,
&rt1711h_regmap_config);
if (IS_ERR(chip->data.regmap))
@@ -316,13 +339,15 @@ static int rt1711h_remove(struct i2c_client *client)

static const struct i2c_device_id rt1711h_id[] = {
{ "rt1711h", 0 },
+ { "rt1715", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, rt1711h_id);

#ifdef CONFIG_OF
static const struct of_device_id rt1711h_of_match[] = {
- { .compatible = "richtek,rt1711h", },
+ { .compatible = "richtek,rt1711h", .data = (void *)RT1711H_DID },
+ { .compatible = "richtek,rt1715", .data = (void *)RT1715_DID },
{},
};
MODULE_DEVICE_TABLE(of, rt1711h_of_match);
--
2.7.4


2022-08-05 07:40:41

by Gene Chen

[permalink] [raw]
Subject: [PATCH v4 7/7] usb: typec: tcpci_rt1711h: Fix CC PHY noise filter of voltage level

From: Gene Chen <[email protected]>

Fix CC PHY noise filter of voltage level according to
current cc voltage level

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

diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
index ff7deae..5dc34f9 100644
--- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c
+++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
@@ -24,8 +24,11 @@
#define RT1711H_PHYCTRL1 0x80
#define RT1711H_PHYCTRL2 0x81

-#define RT1711H_RTCTRL8 0x9B
+#define RT1711H_RTCTRL4 0x93
+/* rx threshold of rd/rp: 1b0 for level 0.4V/0.7V, 1b1 for 0.35V/0.75V */
+#define RT1711H_BMCIO_RXDZSEL BIT(0)

+#define RT1711H_RTCTRL8 0x9B
/* Autoidle timeout = (tout * 2 + 1) * 6.4ms */
#define RT1711H_RTCTRL8_SET(ck300, ship_off, auto_idle, tout) \
(((ck300) << 7) | ((ship_off) << 5) | \
@@ -44,6 +47,10 @@
#define RT1711H_RTCTRL15 0xA2
#define RT1711H_RTCTRL16 0xA3

+#define RT1711H_RTCTRL18 0xAF
+/* 1b0 as fixed rx threshold of rd/rp 0.55V, 1b1 depends on RTCRTL4[0] */
+#define BMCIO_RXDZEN BIT(0)
+
struct rt1711h_chip {
struct tcpci_data data;
struct tcpci *tcpci;
@@ -164,6 +171,53 @@ static int rt1711h_set_vconn(struct tcpci *tcpci, struct tcpci_data *tdata,
RT1711H_AUTOIDLEEN, enable ? 0 : RT1711H_AUTOIDLEEN);
}

+/*
+ * Selects the CC PHY noise filter voltage level according to the remote current
+ * CC voltage level.
+ *
+ * @status: The port's current cc status read from IC
+ * Return 0 if writes succeed; failure code otherwise
+ */
+static inline int rt1711h_init_cc_params(struct rt1711h_chip *chip, u8 status)
+{
+ int ret, cc1, cc2;
+ u8 role = 0;
+ u32 rxdz_en, rxdz_sel;
+
+ ret = rt1711h_read8(chip, TCPC_ROLE_CTRL, &role);
+ if (ret < 0)
+ return ret;
+
+ cc1 = tcpci_to_typec_cc((status >> TCPC_CC_STATUS_CC1_SHIFT) &
+ TCPC_CC_STATUS_CC1_MASK,
+ status & TCPC_CC_STATUS_TERM ||
+ tcpc_presenting_rd(role, CC1));
+ cc2 = tcpci_to_typec_cc((status >> TCPC_CC_STATUS_CC2_SHIFT) &
+ TCPC_CC_STATUS_CC2_MASK,
+ status & TCPC_CC_STATUS_TERM ||
+ tcpc_presenting_rd(role, CC2));
+
+ if ((cc1 >= TYPEC_CC_RP_1_5 && cc2 < TYPEC_CC_RP_DEF) ||
+ (cc2 >= TYPEC_CC_RP_1_5 && cc1 < TYPEC_CC_RP_DEF)) {
+ rxdz_en = BMCIO_RXDZEN;
+ if (chip->did == RT1715_DID)
+ rxdz_sel = RT1711H_BMCIO_RXDZSEL;
+ else
+ rxdz_sel = 0;
+ } else {
+ rxdz_en = 0;
+ rxdz_sel = RT1711H_BMCIO_RXDZSEL;
+ }
+
+ ret = regmap_update_bits(chip->data.regmap, RT1711H_RTCTRL18,
+ BMCIO_RXDZEN, rxdz_en);
+ if (ret < 0)
+ return ret;
+
+ return regmap_update_bits(chip->data.regmap, RT1711H_RTCTRL4,
+ RT1711H_BMCIO_RXDZSEL, rxdz_sel);
+}
+
static int rt1711h_start_drp_toggling(struct tcpci *tcpci,
struct tcpci_data *tdata,
enum typec_cc_status cc)
@@ -224,6 +278,8 @@ static irqreturn_t rt1711h_irq(int irq, void *dev_id)
/* Clear cc change event triggered by starting toggling */
if (status & TCPC_CC_STATUS_TOGGLING)
rt1711h_write8(chip, TCPC_ALERT, TCPC_ALERT_CC_STATUS);
+ else
+ rt1711h_init_cc_params(chip, status);
}

out:
--
2.7.4


2022-08-05 11:43:42

by Guenter Roeck

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

On Fri, Aug 05, 2022 at 03:17:09PM +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 f2f1fb0..fb19d7b 100644
> --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> @@ -14,6 +14,7 @@
> #include <linux/usb/tcpci.h>
> #include <linux/usb/tcpm.h>
> #include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
>
> #define RT1711H_VID 0x29CF
> #define RT1711H_PID 0x1711
> @@ -41,6 +42,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)
> @@ -104,6 +107,26 @@ static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata)
>
> /* dcSRC.DRP : 33% */
> return rt1711h_write16(chip, RT1711H_RTCTRL16, 330);
> +

Nit: unnecessary empty line

Otherwise

Reviewed-by: Guenter Roeck <[email protected]>

> +}
> +
> +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,
> @@ -247,7 +270,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.7.4
>

2022-08-05 11:43:53

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v4 5/7] usb: typec: tcpci_rt1711h: Add compatible id with rt1715

On Fri, Aug 05, 2022 at 03:17:11PM +0800, Gene Chen wrote:
> From: Gene Chen <[email protected]>
>
> Add compatible id with rt1715, and add initial setting for
> specific support PD30 command.
>
> Signed-off-by: Gene Chen <[email protected]>
> Acked-by: Heikki Krogerus <[email protected]>

Reviewed-by: Guenter Roeck <[email protected]>

> ---
> drivers/usb/typec/tcpm/tcpci_rt1711h.c | 43 +++++++++++++++++++++++++++-------
> 1 file changed, 34 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> index 5c51d04..ff7deae 100644
> --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> @@ -18,6 +18,8 @@
>
> #define RT1711H_VID 0x29CF
> #define RT1711H_PID 0x1711
> +#define RT1711H_DID 0x2171
> +#define RT1715_DID 0x2173
>
> #define RT1711H_PHYCTRL1 0x80
> #define RT1711H_PHYCTRL2 0x81
> @@ -29,6 +31,7 @@
> (((ck300) << 7) | ((ship_off) << 5) | \
> ((auto_idle) << 3) | ((tout) & 0x07))
> #define RT1711H_AUTOIDLEEN BIT(3)
> +#define RT1711H_ENEXTMSG BIT(4)
>
> #define RT1711H_RTCTRL11 0x9E
>
> @@ -47,6 +50,7 @@ struct rt1711h_chip {
> struct device *dev;
> struct regulator *vbus;
> bool src_en;
> + u16 did;
> };
>
> static int rt1711h_read16(struct rt1711h_chip *chip, unsigned int reg, u16 *val)
> @@ -83,8 +87,9 @@ static struct rt1711h_chip *tdata_to_rt1711h(struct tcpci_data *tdata)
>
> static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata)
> {
> - int ret;
> struct rt1711h_chip *chip = tdata_to_rt1711h(tdata);
> + struct regmap *regmap = chip->data.regmap;
> + int ret;
>
> /* CK 300K from 320K, shipping off, auto_idle enable, tout = 32ms */
> ret = rt1711h_write8(chip, RT1711H_RTCTRL8,
> @@ -92,6 +97,14 @@ static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata)
> if (ret < 0)
> return ret;
>
> + /* Enable PD30 extended message for RT1715 */
> + if (chip->did == RT1715_DID) {
> + ret = regmap_update_bits(regmap, RT1711H_RTCTRL8,
> + RT1711H_ENEXTMSG, RT1711H_ENEXTMSG);
> + if (ret < 0)
> + return ret;
> + }
> +
> /* I2C reset : (val + 1) * 12.5ms */
> ret = rt1711h_write8(chip, RT1711H_RTCTRL11,
> RT1711H_RTCTRL11_SET(1, 0x0F));
> @@ -229,7 +242,7 @@ static int rt1711h_sw_reset(struct rt1711h_chip *chip)
> return 0;
> }
>
> -static int rt1711h_check_revision(struct i2c_client *i2c)
> +static int rt1711h_check_revision(struct i2c_client *i2c, struct rt1711h_chip *chip)
> {
> int ret;
>
> @@ -247,7 +260,15 @@ static int rt1711h_check_revision(struct i2c_client *i2c)
> dev_err(&i2c->dev, "pid is not correct, 0x%04x\n", ret);
> return -ENODEV;
> }
> - return 0;
> + ret = i2c_smbus_read_word_data(i2c, TCPC_BCD_DEV);
> + if (ret < 0)
> + return ret;
> + if (ret != chip->did) {
> + dev_err(&i2c->dev, "did is not correct, 0x%04x\n", ret);
> + return -ENODEV;
> + }
> + dev_dbg(&i2c->dev, "did is 0x%04x\n", ret);
> + return ret;
> }
>
> static int rt1711h_probe(struct i2c_client *client,
> @@ -256,16 +277,18 @@ static int rt1711h_probe(struct i2c_client *client,
> int ret;
> struct rt1711h_chip *chip;
>
> - ret = rt1711h_check_revision(client);
> + chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
> + if (!chip)
> + return -ENOMEM;
> +
> + chip->did = (size_t)device_get_match_data(&client->dev);
> +
> + ret = rt1711h_check_revision(client, chip);
> if (ret < 0) {
> dev_err(&client->dev, "check vid/pid fail\n");
> return ret;
> }
>
> - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
> - if (!chip)
> - return -ENOMEM;
> -
> chip->data.regmap = devm_regmap_init_i2c(client,
> &rt1711h_regmap_config);
> if (IS_ERR(chip->data.regmap))
> @@ -316,13 +339,15 @@ static int rt1711h_remove(struct i2c_client *client)
>
> static const struct i2c_device_id rt1711h_id[] = {
> { "rt1711h", 0 },
> + { "rt1715", 0 },
> { }
> };
> MODULE_DEVICE_TABLE(i2c, rt1711h_id);
>
> #ifdef CONFIG_OF
> static const struct of_device_id rt1711h_of_match[] = {
> - { .compatible = "richtek,rt1711h", },
> + { .compatible = "richtek,rt1711h", .data = (void *)RT1711H_DID },
> + { .compatible = "richtek,rt1715", .data = (void *)RT1715_DID },
> {},
> };
> MODULE_DEVICE_TABLE(of, rt1711h_of_match);
> --
> 2.7.4
>

2022-08-05 11:43:58

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v4 6/7] usb: typec: tcpci: Move function "tcpci_to_typec_cc" to common

On Fri, Aug 05, 2022 at 03:17:12PM +0800, Gene Chen wrote:
> From: Gene Chen <[email protected]>
>
> Move transition function "tcpci_to_typec_cc" to common header
>
> Signed-off-by: Gene Chen <[email protected]>
> Acked-by: Heikki Krogerus <[email protected]>

Reviewed-by: Guenter Roeck <[email protected]>

> ---
> drivers/usb/typec/tcpm/tcpci.c | 22 ----------------------
> include/linux/usb/tcpci.h | 22 ++++++++++++++++++++++
> 2 files changed, 22 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
> index 8127847..50674ec 100644
> --- a/drivers/usb/typec/tcpm/tcpci.c
> +++ b/drivers/usb/typec/tcpm/tcpci.c
> @@ -27,11 +27,6 @@
> #define VPPS_VALID_MIN_MV 100
> #define VSINKDISCONNECT_PD_MIN_PERCENT 90
>
> -#define tcpc_presenting_rd(reg, cc) \
> - (!(TCPC_ROLE_CTRL_DRP & (reg)) && \
> - (((reg) & (TCPC_ROLE_CTRL_## cc ##_MASK << TCPC_ROLE_CTRL_## cc ##_SHIFT)) == \
> - (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_## cc ##_SHIFT)))
> -
> struct tcpci {
> struct device *dev;
>
> @@ -218,23 +213,6 @@ static int tcpci_start_toggling(struct tcpc_dev *tcpc,
> TCPC_CMD_LOOK4CONNECTION);
> }
>
> -static enum typec_cc_status tcpci_to_typec_cc(unsigned int cc, bool sink)
> -{
> - switch (cc) {
> - case 0x1:
> - return sink ? TYPEC_CC_RP_DEF : TYPEC_CC_RA;
> - case 0x2:
> - return sink ? TYPEC_CC_RP_1_5 : TYPEC_CC_RD;
> - case 0x3:
> - if (sink)
> - return TYPEC_CC_RP_3_0;
> - fallthrough;
> - case 0x0:
> - default:
> - return TYPEC_CC_OPEN;
> - }
> -}
> -
> static int tcpci_get_cc(struct tcpc_dev *tcpc,
> enum typec_cc_status *cc1, enum typec_cc_status *cc2)
> {
> diff --git a/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h
> index 20c0bed..1765745 100644
> --- a/include/linux/usb/tcpci.h
> +++ b/include/linux/usb/tcpci.h
> @@ -167,6 +167,11 @@
> /* I2C_WRITE_BYTE_COUNT + 1 when TX_BUF_BYTE_x is only accessible I2C_WRITE_BYTE_COUNT */
> #define TCPC_TRANSMIT_BUFFER_MAX_LEN 31
>
> +#define tcpc_presenting_rd(reg, cc) \
> + (!(TCPC_ROLE_CTRL_DRP & (reg)) && \
> + (((reg) & (TCPC_ROLE_CTRL_## cc ##_MASK << TCPC_ROLE_CTRL_## cc ##_SHIFT)) == \
> + (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_## cc ##_SHIFT)))
> +
> struct tcpci;
>
> /*
> @@ -207,4 +212,21 @@ irqreturn_t tcpci_irq(struct tcpci *tcpci);
>
> struct tcpm_port;
> struct tcpm_port *tcpci_get_tcpm_port(struct tcpci *tcpci);
> +
> +static inline enum typec_cc_status tcpci_to_typec_cc(unsigned int cc, bool sink)
> +{
> + switch (cc) {
> + case 0x1:
> + return sink ? TYPEC_CC_RP_DEF : TYPEC_CC_RA;
> + case 0x2:
> + return sink ? TYPEC_CC_RP_1_5 : TYPEC_CC_RD;
> + case 0x3:
> + if (sink)
> + return TYPEC_CC_RP_3_0;
> + fallthrough;
> + case 0x0:
> + default:
> + return TYPEC_CC_OPEN;
> + }
> +}
> #endif /* __LINUX_USB_TCPCI_H */
> --
> 2.7.4
>

2022-08-05 11:45:42

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v4 7/7] usb: typec: tcpci_rt1711h: Fix CC PHY noise filter of voltage level

On Fri, Aug 05, 2022 at 03:17:13PM +0800, Gene Chen wrote:
> From: Gene Chen <[email protected]>
>
> Fix CC PHY noise filter of voltage level according to
> current cc voltage level
>
> Signed-off-by: Gene Chen <[email protected]>
> Acked-by: Heikki Krogerus <[email protected]>

Reviewed-by: Guenter Roeck <[email protected]>

> ---
> drivers/usb/typec/tcpm/tcpci_rt1711h.c | 58 +++++++++++++++++++++++++++++++++-
> 1 file changed, 57 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> index ff7deae..5dc34f9 100644
> --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c
> @@ -24,8 +24,11 @@
> #define RT1711H_PHYCTRL1 0x80
> #define RT1711H_PHYCTRL2 0x81
>
> -#define RT1711H_RTCTRL8 0x9B
> +#define RT1711H_RTCTRL4 0x93
> +/* rx threshold of rd/rp: 1b0 for level 0.4V/0.7V, 1b1 for 0.35V/0.75V */
> +#define RT1711H_BMCIO_RXDZSEL BIT(0)
>
> +#define RT1711H_RTCTRL8 0x9B
> /* Autoidle timeout = (tout * 2 + 1) * 6.4ms */
> #define RT1711H_RTCTRL8_SET(ck300, ship_off, auto_idle, tout) \
> (((ck300) << 7) | ((ship_off) << 5) | \
> @@ -44,6 +47,10 @@
> #define RT1711H_RTCTRL15 0xA2
> #define RT1711H_RTCTRL16 0xA3
>
> +#define RT1711H_RTCTRL18 0xAF
> +/* 1b0 as fixed rx threshold of rd/rp 0.55V, 1b1 depends on RTCRTL4[0] */
> +#define BMCIO_RXDZEN BIT(0)
> +
> struct rt1711h_chip {
> struct tcpci_data data;
> struct tcpci *tcpci;
> @@ -164,6 +171,53 @@ static int rt1711h_set_vconn(struct tcpci *tcpci, struct tcpci_data *tdata,
> RT1711H_AUTOIDLEEN, enable ? 0 : RT1711H_AUTOIDLEEN);
> }
>
> +/*
> + * Selects the CC PHY noise filter voltage level according to the remote current
> + * CC voltage level.
> + *
> + * @status: The port's current cc status read from IC
> + * Return 0 if writes succeed; failure code otherwise
> + */
> +static inline int rt1711h_init_cc_params(struct rt1711h_chip *chip, u8 status)
> +{
> + int ret, cc1, cc2;
> + u8 role = 0;
> + u32 rxdz_en, rxdz_sel;
> +
> + ret = rt1711h_read8(chip, TCPC_ROLE_CTRL, &role);
> + if (ret < 0)
> + return ret;
> +
> + cc1 = tcpci_to_typec_cc((status >> TCPC_CC_STATUS_CC1_SHIFT) &
> + TCPC_CC_STATUS_CC1_MASK,
> + status & TCPC_CC_STATUS_TERM ||
> + tcpc_presenting_rd(role, CC1));
> + cc2 = tcpci_to_typec_cc((status >> TCPC_CC_STATUS_CC2_SHIFT) &
> + TCPC_CC_STATUS_CC2_MASK,
> + status & TCPC_CC_STATUS_TERM ||
> + tcpc_presenting_rd(role, CC2));
> +
> + if ((cc1 >= TYPEC_CC_RP_1_5 && cc2 < TYPEC_CC_RP_DEF) ||
> + (cc2 >= TYPEC_CC_RP_1_5 && cc1 < TYPEC_CC_RP_DEF)) {
> + rxdz_en = BMCIO_RXDZEN;
> + if (chip->did == RT1715_DID)
> + rxdz_sel = RT1711H_BMCIO_RXDZSEL;
> + else
> + rxdz_sel = 0;
> + } else {
> + rxdz_en = 0;
> + rxdz_sel = RT1711H_BMCIO_RXDZSEL;
> + }
> +
> + ret = regmap_update_bits(chip->data.regmap, RT1711H_RTCTRL18,
> + BMCIO_RXDZEN, rxdz_en);
> + if (ret < 0)
> + return ret;
> +
> + return regmap_update_bits(chip->data.regmap, RT1711H_RTCTRL4,
> + RT1711H_BMCIO_RXDZSEL, rxdz_sel);
> +}
> +
> static int rt1711h_start_drp_toggling(struct tcpci *tcpci,
> struct tcpci_data *tdata,
> enum typec_cc_status cc)
> @@ -224,6 +278,8 @@ static irqreturn_t rt1711h_irq(int irq, void *dev_id)
> /* Clear cc change event triggered by starting toggling */
> if (status & TCPC_CC_STATUS_TOGGLING)
> rt1711h_write8(chip, TCPC_ALERT, TCPC_ALERT_CC_STATUS);
> + else
> + rt1711h_init_cc_params(chip, status);
> }
>
> out:
> --
> 2.7.4
>