Re: [PATCH] staging: typec: rt1711h typec chip driver
Hi Heikki, 2018-03-16 23:05 GMT+08:00 Heikki Krogerus: > Hi ShuFan, > > On Fri, Mar 16, 2018 at 05:12:49PM +0800, ShuFan Lee wrote: >> +static int rt1711h_init_gpio(struct rt1711h_chip *chip) >> +{ >> + int ret; >> + struct device_node *np = chip->dev->of_node; >> + >> + ret = of_get_named_gpio(np, "rt,intr_gpio", 0); >> + if (ret < 0) { >> + dev_err(chip->dev, "%s get int gpio fail(%d)\n", __func__, >> ret); >> + return ret; >> + } >> + chip->irq_gpio = ret; >> + >> + ret = devm_gpio_request_one(chip->dev, chip->irq_gpio, GPIOF_IN, >> + dev_name(chip->dev)); >> + if (ret < 0) { >> + dev_err(chip->dev, "%s request gpio fail(%d)\n", __func__, >> ret); >> + return ret; >> + } >> + >> + chip->irq = gpio_to_irq(chip->irq_gpio); >> + if (chip->irq <= 0) { >> + dev_err(chip->dev, "%s gpio2irq fail(%d)\n", __func__, >> + chip->irq); >> + return -EINVAL; >> + } >> + return 0; > > "rt,intr_gpio" should probable be "rt,intr-gpio". Then this function > can be prepared for all types of platforms: > > static int rt1711h_init_gpio(struct rt1711h_chip *chip) > { > struct gpio_desc *gpio; > > gpio = devm_gpiod_get(chip->dev, "rt,intr", GFP_KERNEL); > if (IS_ERR(gpio)) > return PTR_ERR(gpio); > > chip->irq = gpiod_to_irq(gpio); > if (chip->irq < 0) > return chip->irq; > > return 0; > } > > > Thanks, > > -- > heikki Thank you, I've changed it in PATCH v2. May I add you to Suggested-by list? -- Best Regards, 書帆
Re: [PATCH] staging: typec: rt1711h typec chip driver
Hi Heikki, 2018-03-16 23:05 GMT+08:00 Heikki Krogerus : > Hi ShuFan, > > On Fri, Mar 16, 2018 at 05:12:49PM +0800, ShuFan Lee wrote: >> +static int rt1711h_init_gpio(struct rt1711h_chip *chip) >> +{ >> + int ret; >> + struct device_node *np = chip->dev->of_node; >> + >> + ret = of_get_named_gpio(np, "rt,intr_gpio", 0); >> + if (ret < 0) { >> + dev_err(chip->dev, "%s get int gpio fail(%d)\n", __func__, >> ret); >> + return ret; >> + } >> + chip->irq_gpio = ret; >> + >> + ret = devm_gpio_request_one(chip->dev, chip->irq_gpio, GPIOF_IN, >> + dev_name(chip->dev)); >> + if (ret < 0) { >> + dev_err(chip->dev, "%s request gpio fail(%d)\n", __func__, >> ret); >> + return ret; >> + } >> + >> + chip->irq = gpio_to_irq(chip->irq_gpio); >> + if (chip->irq <= 0) { >> + dev_err(chip->dev, "%s gpio2irq fail(%d)\n", __func__, >> + chip->irq); >> + return -EINVAL; >> + } >> + return 0; > > "rt,intr_gpio" should probable be "rt,intr-gpio". Then this function > can be prepared for all types of platforms: > > static int rt1711h_init_gpio(struct rt1711h_chip *chip) > { > struct gpio_desc *gpio; > > gpio = devm_gpiod_get(chip->dev, "rt,intr", GFP_KERNEL); > if (IS_ERR(gpio)) > return PTR_ERR(gpio); > > chip->irq = gpiod_to_irq(gpio); > if (chip->irq < 0) > return chip->irq; > > return 0; > } > > > Thanks, > > -- > heikki Thank you, I've changed it in PATCH v2. May I add you to Suggested-by list? -- Best Regards, 書帆
Re: [PATCH] staging: typec: rt1711h typec chip driver
Hi ShuFan, On Fri, Mar 16, 2018 at 05:12:49PM +0800, ShuFan Lee wrote: > +static int rt1711h_init_gpio(struct rt1711h_chip *chip) > +{ > + int ret; > + struct device_node *np = chip->dev->of_node; > + > + ret = of_get_named_gpio(np, "rt,intr_gpio", 0); > + if (ret < 0) { > + dev_err(chip->dev, "%s get int gpio fail(%d)\n", __func__, ret); > + return ret; > + } > + chip->irq_gpio = ret; > + > + ret = devm_gpio_request_one(chip->dev, chip->irq_gpio, GPIOF_IN, > + dev_name(chip->dev)); > + if (ret < 0) { > + dev_err(chip->dev, "%s request gpio fail(%d)\n", __func__, ret); > + return ret; > + } > + > + chip->irq = gpio_to_irq(chip->irq_gpio); > + if (chip->irq <= 0) { > + dev_err(chip->dev, "%s gpio2irq fail(%d)\n", __func__, > + chip->irq); > + return -EINVAL; > + } > + return 0; "rt,intr_gpio" should probable be "rt,intr-gpio". Then this function can be prepared for all types of platforms: static int rt1711h_init_gpio(struct rt1711h_chip *chip) { struct gpio_desc *gpio; gpio = devm_gpiod_get(chip->dev, "rt,intr", GFP_KERNEL); if (IS_ERR(gpio)) return PTR_ERR(gpio); chip->irq = gpiod_to_irq(gpio); if (chip->irq < 0) return chip->irq; return 0; } Thanks, -- heikki
Re: [PATCH] staging: typec: rt1711h typec chip driver
Hi ShuFan, On Fri, Mar 16, 2018 at 05:12:49PM +0800, ShuFan Lee wrote: > +static int rt1711h_init_gpio(struct rt1711h_chip *chip) > +{ > + int ret; > + struct device_node *np = chip->dev->of_node; > + > + ret = of_get_named_gpio(np, "rt,intr_gpio", 0); > + if (ret < 0) { > + dev_err(chip->dev, "%s get int gpio fail(%d)\n", __func__, ret); > + return ret; > + } > + chip->irq_gpio = ret; > + > + ret = devm_gpio_request_one(chip->dev, chip->irq_gpio, GPIOF_IN, > + dev_name(chip->dev)); > + if (ret < 0) { > + dev_err(chip->dev, "%s request gpio fail(%d)\n", __func__, ret); > + return ret; > + } > + > + chip->irq = gpio_to_irq(chip->irq_gpio); > + if (chip->irq <= 0) { > + dev_err(chip->dev, "%s gpio2irq fail(%d)\n", __func__, > + chip->irq); > + return -EINVAL; > + } > + return 0; "rt,intr_gpio" should probable be "rt,intr-gpio". Then this function can be prepared for all types of platforms: static int rt1711h_init_gpio(struct rt1711h_chip *chip) { struct gpio_desc *gpio; gpio = devm_gpiod_get(chip->dev, "rt,intr", GFP_KERNEL); if (IS_ERR(gpio)) return PTR_ERR(gpio); chip->irq = gpiod_to_irq(gpio); if (chip->irq < 0) return chip->irq; return 0; } Thanks, -- heikki
Re: [PATCH] staging: typec: rt1711h typec chip driver
Hi Greg, 2018-03-16 21:29 GMT+08:00 Mats Karrman: > Hi, > > On 2018-03-16 13:58, Greg KH wrote: > >> On Fri, Mar 16, 2018 at 05:12:49PM +0800, ShuFan Lee wrote: >>> >>> From: ShuFan Lee >>> >>> Richtek RT1711H Type-C chip driver that works with >>> Type-C Port Controller Manager to provide USB PD and >>> USB Type-C functionalities. >>> Add definition of TCPC_CC_STATUS_TOGGLING. >>> >>> Signed-off-by: ShuFan Lee >>> --- >>> drivers/staging/typec/Kconfig | 8 + >>> drivers/staging/typec/Makefile| 1 + >>> drivers/staging/typec/tcpci.h | 1 + >>> drivers/staging/typec/tcpci_rt1711h.c | 344 >>> ++ >>> 4 files changed, 354 insertions(+) >>> create mode 100644 drivers/staging/typec/tcpci_rt1711h.c >> >> This looks nice and simple to me, any reason it has to live in >> drivers/staging/ and we can't just move it to drivers/usb/typec/ now? >> >> Or are there still api things that need to be resolved with the existing >> drivers/staging/typec/ code? > > > For one thing it depends on the tcpci driver that is still in staging until > Jun Li's patches, [1], comes through. > > // Mats > > [1] https://marc.info/?l=linux-usb=152093458605648=2 > >> thanks, >> >> greg k-h >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-usb" in >> the body of a message to majord...@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> > Just like Mats said. Because tcpci_rt1711h.c depends on tcpci driver. I'm not sure if I can put it to drivers/usb/typec/. So, I put it staging first and move out after Jun's patches. -- Best Regards, 書帆
Re: [PATCH] staging: typec: rt1711h typec chip driver
Hi Greg, 2018-03-16 21:29 GMT+08:00 Mats Karrman : > Hi, > > On 2018-03-16 13:58, Greg KH wrote: > >> On Fri, Mar 16, 2018 at 05:12:49PM +0800, ShuFan Lee wrote: >>> >>> From: ShuFan Lee >>> >>> Richtek RT1711H Type-C chip driver that works with >>> Type-C Port Controller Manager to provide USB PD and >>> USB Type-C functionalities. >>> Add definition of TCPC_CC_STATUS_TOGGLING. >>> >>> Signed-off-by: ShuFan Lee >>> --- >>> drivers/staging/typec/Kconfig | 8 + >>> drivers/staging/typec/Makefile| 1 + >>> drivers/staging/typec/tcpci.h | 1 + >>> drivers/staging/typec/tcpci_rt1711h.c | 344 >>> ++ >>> 4 files changed, 354 insertions(+) >>> create mode 100644 drivers/staging/typec/tcpci_rt1711h.c >> >> This looks nice and simple to me, any reason it has to live in >> drivers/staging/ and we can't just move it to drivers/usb/typec/ now? >> >> Or are there still api things that need to be resolved with the existing >> drivers/staging/typec/ code? > > > For one thing it depends on the tcpci driver that is still in staging until > Jun Li's patches, [1], comes through. > > // Mats > > [1] https://marc.info/?l=linux-usb=152093458605648=2 > >> thanks, >> >> greg k-h >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-usb" in >> the body of a message to majord...@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >> > Just like Mats said. Because tcpci_rt1711h.c depends on tcpci driver. I'm not sure if I can put it to drivers/usb/typec/. So, I put it staging first and move out after Jun's patches. -- Best Regards, 書帆
Re: [PATCH] staging: typec: rt1711h typec chip driver
Hi, On 2018-03-16 13:58, Greg KH wrote: On Fri, Mar 16, 2018 at 05:12:49PM +0800, ShuFan Lee wrote: From: ShuFan LeeRichtek RT1711H Type-C chip driver that works with Type-C Port Controller Manager to provide USB PD and USB Type-C functionalities. Add definition of TCPC_CC_STATUS_TOGGLING. Signed-off-by: ShuFan Lee --- drivers/staging/typec/Kconfig | 8 + drivers/staging/typec/Makefile| 1 + drivers/staging/typec/tcpci.h | 1 + drivers/staging/typec/tcpci_rt1711h.c | 344 ++ 4 files changed, 354 insertions(+) create mode 100644 drivers/staging/typec/tcpci_rt1711h.c This looks nice and simple to me, any reason it has to live in drivers/staging/ and we can't just move it to drivers/usb/typec/ now? Or are there still api things that need to be resolved with the existing drivers/staging/typec/ code? For one thing it depends on the tcpci driver that is still in staging until Jun Li's patches, [1], comes through. // Mats [1] https://marc.info/?l=linux-usb=152093458605648=2 thanks, greg k-h -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] staging: typec: rt1711h typec chip driver
Hi, On 2018-03-16 13:58, Greg KH wrote: On Fri, Mar 16, 2018 at 05:12:49PM +0800, ShuFan Lee wrote: From: ShuFan Lee Richtek RT1711H Type-C chip driver that works with Type-C Port Controller Manager to provide USB PD and USB Type-C functionalities. Add definition of TCPC_CC_STATUS_TOGGLING. Signed-off-by: ShuFan Lee --- drivers/staging/typec/Kconfig | 8 + drivers/staging/typec/Makefile| 1 + drivers/staging/typec/tcpci.h | 1 + drivers/staging/typec/tcpci_rt1711h.c | 344 ++ 4 files changed, 354 insertions(+) create mode 100644 drivers/staging/typec/tcpci_rt1711h.c This looks nice and simple to me, any reason it has to live in drivers/staging/ and we can't just move it to drivers/usb/typec/ now? Or are there still api things that need to be resolved with the existing drivers/staging/typec/ code? For one thing it depends on the tcpci driver that is still in staging until Jun Li's patches, [1], comes through. // Mats [1] https://marc.info/?l=linux-usb=152093458605648=2 thanks, greg k-h -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] staging: typec: rt1711h typec chip driver
On Fri, Mar 16, 2018 at 05:12:49PM +0800, ShuFan Lee wrote: > From: ShuFan Lee> > Richtek RT1711H Type-C chip driver that works with > Type-C Port Controller Manager to provide USB PD and > USB Type-C functionalities. > Add definition of TCPC_CC_STATUS_TOGGLING. > > Signed-off-by: ShuFan Lee > --- > drivers/staging/typec/Kconfig | 8 + > drivers/staging/typec/Makefile| 1 + > drivers/staging/typec/tcpci.h | 1 + > drivers/staging/typec/tcpci_rt1711h.c | 344 > ++ > 4 files changed, 354 insertions(+) > create mode 100644 drivers/staging/typec/tcpci_rt1711h.c This looks nice and simple to me, any reason it has to live in drivers/staging/ and we can't just move it to drivers/usb/typec/ now? Or are there still api things that need to be resolved with the existing drivers/staging/typec/ code? thanks, greg k-h
Re: [PATCH] staging: typec: rt1711h typec chip driver
On Fri, Mar 16, 2018 at 05:12:49PM +0800, ShuFan Lee wrote: > From: ShuFan Lee > > Richtek RT1711H Type-C chip driver that works with > Type-C Port Controller Manager to provide USB PD and > USB Type-C functionalities. > Add definition of TCPC_CC_STATUS_TOGGLING. > > Signed-off-by: ShuFan Lee > --- > drivers/staging/typec/Kconfig | 8 + > drivers/staging/typec/Makefile| 1 + > drivers/staging/typec/tcpci.h | 1 + > drivers/staging/typec/tcpci_rt1711h.c | 344 > ++ > 4 files changed, 354 insertions(+) > create mode 100644 drivers/staging/typec/tcpci_rt1711h.c This looks nice and simple to me, any reason it has to live in drivers/staging/ and we can't just move it to drivers/usb/typec/ now? Or are there still api things that need to be resolved with the existing drivers/staging/typec/ code? thanks, greg k-h
[PATCH] staging: typec: rt1711h typec chip driver
From: ShuFan LeeRichtek RT1711H Type-C chip driver that works with Type-C Port Controller Manager to provide USB PD and USB Type-C functionalities. Add definition of TCPC_CC_STATUS_TOGGLING. Signed-off-by: ShuFan Lee --- drivers/staging/typec/Kconfig | 8 + drivers/staging/typec/Makefile| 1 + drivers/staging/typec/tcpci.h | 1 + drivers/staging/typec/tcpci_rt1711h.c | 344 ++ 4 files changed, 354 insertions(+) create mode 100644 drivers/staging/typec/tcpci_rt1711h.c diff --git a/drivers/staging/typec/Kconfig b/drivers/staging/typec/Kconfig index 5359f556d203..3aa981fbc8f5 100644 --- a/drivers/staging/typec/Kconfig +++ b/drivers/staging/typec/Kconfig @@ -9,6 +9,14 @@ config TYPEC_TCPCI help Type-C Port Controller driver for TCPCI-compliant controller. +config TYPEC_RT1711H + tristate "Richtek RT1711H Type-C chip driver" + select TYPEC_TCPCI + help + Richtek RT1711H Type-C chip driver that works with + Type-C Port Controller Manager to provide USB PD and USB + Type-C functionalities. + endif endmenu diff --git a/drivers/staging/typec/Makefile b/drivers/staging/typec/Makefile index 53d649abcb53..7803d485e1b3 100644 --- a/drivers/staging/typec/Makefile +++ b/drivers/staging/typec/Makefile @@ -1 +1,2 @@ obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o +obj-$(CONFIG_TYPEC_RT1711H)+= tcpci_rt1711h.o diff --git a/drivers/staging/typec/tcpci.h b/drivers/staging/typec/tcpci.h index 34c865f0dcf6..303ebde26546 100644 --- a/drivers/staging/typec/tcpci.h +++ b/drivers/staging/typec/tcpci.h @@ -59,6 +59,7 @@ #define TCPC_POWER_CTRL_VCONN_ENABLE BIT(0) #define TCPC_CC_STATUS 0x1d +#define TCPC_CC_STATUS_TOGGLINGBIT(5) #define TCPC_CC_STATUS_TERMBIT(4) #define TCPC_CC_STATUS_CC2_SHIFT 2 #define TCPC_CC_STATUS_CC2_MASK0x3 diff --git a/drivers/staging/typec/tcpci_rt1711h.c b/drivers/staging/typec/tcpci_rt1711h.c new file mode 100644 index ..ab5c2457f149 --- /dev/null +++ b/drivers/staging/typec/tcpci_rt1711h.c @@ -0,0 +1,344 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018, Richtek Technology Corporation + * + * Richtek RT1711H Type-C Chip Driver + */ + +#include +#include +#include +#include +#include +#include +#include +#include "tcpci.h" + +#define RT1711H_RTCTRL80x9B + +/* Autoidle timeout = (tout * 2 + 1) * 6.4ms */ +#define RT1711H_RTCTRL8_SET(ck300, ship_off, auto_idle, tout) \ + (((ck300) << 7) | ((ship_off) << 5) | \ + ((auto_idle) << 3) | ((tout) & 0x07)) + +#define RT1711H_RTCTRL11 0x9E + +/* I2C timeout = (tout + 1) * 12.5ms */ +#define RT1711H_RTCTRL11_SET(en, tout) \ +(((en) << 7) | ((tout) & 0x0F)) + +#define RT1711H_RTCTRL13 0xA0 +#define RT1711H_RTCTRL14 0xA1 +#define RT1711H_RTCTRL15 0xA2 +#define RT1711H_RTCTRL16 0xA3 + +struct rt1711h_chip { + struct tcpci_data data; + struct tcpci *tcpci; + struct device *dev; + int irq_gpio; + int irq; +}; + +static int rt1711h_read16(struct rt1711h_chip *chip, unsigned int reg, u16 *val) +{ + return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u16)); +} + +static int rt1711h_write16(struct rt1711h_chip *chip, unsigned int reg, u16 val) +{ + return regmap_raw_write(chip->data.regmap, reg, , sizeof(u16)); +} + +static int rt1711h_read8(struct rt1711h_chip *chip, unsigned int reg, u8 *val) +{ + return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u8)); +} + +static int rt1711h_write8(struct rt1711h_chip *chip, unsigned int reg, u8 val) +{ + return regmap_raw_write(chip->data.regmap, reg, , sizeof(u8)); +} + +static const struct regmap_config rt1711h_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + + .max_register = 0xFF, /* 0x80 .. 0xFF are vendor defined */ +}; + +static struct rt1711h_chip *tdata_to_rt1711h(struct tcpci_data *tdata) +{ + return container_of(tdata, struct rt1711h_chip, data); +} + +static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata) +{ + int ret; + struct rt1711h_chip *chip = tdata_to_rt1711h(tdata); + + /* CK 300K from 320K, shipping off, auto_idle enable, tout = 32ms */ + ret = rt1711h_write8(chip, RT1711H_RTCTRL8, +RT1711H_RTCTRL8_SET(0, 1, 1, 2)); + if (ret < 0) + return ret; + + /* I2C reset : (val + 1) * 12.5ms */ + ret = rt1711h_write8(chip, RT1711H_RTCTRL11, +RT1711H_RTCTRL11_SET(1, 0x0F)); + if (ret < 0) + return ret; + + /* tTCPCfilter : (26.7 * val) us */ + ret = rt1711h_write8(chip, RT1711H_RTCTRL14, 0x0F); + if (ret < 0) + return ret; + + /*
[PATCH] staging: typec: rt1711h typec chip driver
From: ShuFan Lee Richtek RT1711H Type-C chip driver that works with Type-C Port Controller Manager to provide USB PD and USB Type-C functionalities. Add definition of TCPC_CC_STATUS_TOGGLING. Signed-off-by: ShuFan Lee --- drivers/staging/typec/Kconfig | 8 + drivers/staging/typec/Makefile| 1 + drivers/staging/typec/tcpci.h | 1 + drivers/staging/typec/tcpci_rt1711h.c | 344 ++ 4 files changed, 354 insertions(+) create mode 100644 drivers/staging/typec/tcpci_rt1711h.c diff --git a/drivers/staging/typec/Kconfig b/drivers/staging/typec/Kconfig index 5359f556d203..3aa981fbc8f5 100644 --- a/drivers/staging/typec/Kconfig +++ b/drivers/staging/typec/Kconfig @@ -9,6 +9,14 @@ config TYPEC_TCPCI help Type-C Port Controller driver for TCPCI-compliant controller. +config TYPEC_RT1711H + tristate "Richtek RT1711H Type-C chip driver" + select TYPEC_TCPCI + help + Richtek RT1711H Type-C chip driver that works with + Type-C Port Controller Manager to provide USB PD and USB + Type-C functionalities. + endif endmenu diff --git a/drivers/staging/typec/Makefile b/drivers/staging/typec/Makefile index 53d649abcb53..7803d485e1b3 100644 --- a/drivers/staging/typec/Makefile +++ b/drivers/staging/typec/Makefile @@ -1 +1,2 @@ obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o +obj-$(CONFIG_TYPEC_RT1711H)+= tcpci_rt1711h.o diff --git a/drivers/staging/typec/tcpci.h b/drivers/staging/typec/tcpci.h index 34c865f0dcf6..303ebde26546 100644 --- a/drivers/staging/typec/tcpci.h +++ b/drivers/staging/typec/tcpci.h @@ -59,6 +59,7 @@ #define TCPC_POWER_CTRL_VCONN_ENABLE BIT(0) #define TCPC_CC_STATUS 0x1d +#define TCPC_CC_STATUS_TOGGLINGBIT(5) #define TCPC_CC_STATUS_TERMBIT(4) #define TCPC_CC_STATUS_CC2_SHIFT 2 #define TCPC_CC_STATUS_CC2_MASK0x3 diff --git a/drivers/staging/typec/tcpci_rt1711h.c b/drivers/staging/typec/tcpci_rt1711h.c new file mode 100644 index ..ab5c2457f149 --- /dev/null +++ b/drivers/staging/typec/tcpci_rt1711h.c @@ -0,0 +1,344 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018, Richtek Technology Corporation + * + * Richtek RT1711H Type-C Chip Driver + */ + +#include +#include +#include +#include +#include +#include +#include +#include "tcpci.h" + +#define RT1711H_RTCTRL80x9B + +/* Autoidle timeout = (tout * 2 + 1) * 6.4ms */ +#define RT1711H_RTCTRL8_SET(ck300, ship_off, auto_idle, tout) \ + (((ck300) << 7) | ((ship_off) << 5) | \ + ((auto_idle) << 3) | ((tout) & 0x07)) + +#define RT1711H_RTCTRL11 0x9E + +/* I2C timeout = (tout + 1) * 12.5ms */ +#define RT1711H_RTCTRL11_SET(en, tout) \ +(((en) << 7) | ((tout) & 0x0F)) + +#define RT1711H_RTCTRL13 0xA0 +#define RT1711H_RTCTRL14 0xA1 +#define RT1711H_RTCTRL15 0xA2 +#define RT1711H_RTCTRL16 0xA3 + +struct rt1711h_chip { + struct tcpci_data data; + struct tcpci *tcpci; + struct device *dev; + int irq_gpio; + int irq; +}; + +static int rt1711h_read16(struct rt1711h_chip *chip, unsigned int reg, u16 *val) +{ + return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u16)); +} + +static int rt1711h_write16(struct rt1711h_chip *chip, unsigned int reg, u16 val) +{ + return regmap_raw_write(chip->data.regmap, reg, , sizeof(u16)); +} + +static int rt1711h_read8(struct rt1711h_chip *chip, unsigned int reg, u8 *val) +{ + return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u8)); +} + +static int rt1711h_write8(struct rt1711h_chip *chip, unsigned int reg, u8 val) +{ + return regmap_raw_write(chip->data.regmap, reg, , sizeof(u8)); +} + +static const struct regmap_config rt1711h_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + + .max_register = 0xFF, /* 0x80 .. 0xFF are vendor defined */ +}; + +static struct rt1711h_chip *tdata_to_rt1711h(struct tcpci_data *tdata) +{ + return container_of(tdata, struct rt1711h_chip, data); +} + +static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata) +{ + int ret; + struct rt1711h_chip *chip = tdata_to_rt1711h(tdata); + + /* CK 300K from 320K, shipping off, auto_idle enable, tout = 32ms */ + ret = rt1711h_write8(chip, RT1711H_RTCTRL8, +RT1711H_RTCTRL8_SET(0, 1, 1, 2)); + if (ret < 0) + return ret; + + /* I2C reset : (val + 1) * 12.5ms */ + ret = rt1711h_write8(chip, RT1711H_RTCTRL11, +RT1711H_RTCTRL11_SET(1, 0x0F)); + if (ret < 0) + return ret; + + /* tTCPCfilter : (26.7 * val) us */ + ret = rt1711h_write8(chip, RT1711H_RTCTRL14, 0x0F); + if (ret < 0) + return ret; + + /* tDRP : (51.2 + 6.4 * val) ms */ + ret =