Re: [PATCH v2 1/2] usb typec: mt6360: Add support for mt6360 Type-C driver
Chunfeng Yun 於 2020年8月27日 週四 下午4:05寫道: > > On Thu, 2020-08-27 at 12:50 +0800, cy_huang wrote: > > From: ChiYuan Huang > > > > Mediatek MT6360 is a multi-functional IC that includes USB Type-C. > > It works with Type-C Port Controller Manager to provide USB PD > > and USB Type-C functionalities. > > > > Add fix to Prevent the race condition from interrupt and tcpci port > > unregister > > during module remove. > > > > Signed-off-by: ChiYuan Huang > > --- > > drivers/usb/typec/tcpm/Kconfig| 8 ++ > > drivers/usb/typec/tcpm/Makefile | 1 + > > drivers/usb/typec/tcpm/tcpci_mt6360.c | 213 > > ++ > Can you avoid using special SoC name in file name? > It's not clear if you later support new SoC in the driver, e.g. mt63xx? Okay, I will rename it to mt636x. From our SubPMIC generation, currently, naming will be 6360/62/67, etc.. >From our SOC roadmap, one generation can be used for one to two more years. I think the name MT636x is enough. For the next one, I can submit the patch to make it compatible with this driver. Thanks for you comment. > > > 3 files changed, 222 insertions(+) > > create mode 100644 drivers/usb/typec/tcpm/tcpci_mt6360.c > > > > diff --git a/drivers/usb/typec/tcpm/Kconfig b/drivers/usb/typec/tcpm/Kconfig > > index fa3f393..58a64e1 100644 > > --- a/drivers/usb/typec/tcpm/Kconfig > > +++ b/drivers/usb/typec/tcpm/Kconfig > > @@ -27,6 +27,14 @@ config TYPEC_RT1711H > > Type-C Port Controller Manager to provide USB PD and USB > > Type-C functionalities. > > > > +config TYPEC_MT6360 > > + tristate "Mediatek MT6360 Type-C driver" > > + depends on MFD_MT6360 > > + help > > + Mediatek MT6360 is a multi-functional IC that includes > > + USB Type-C. It works with Type-C Port Controller Manager > > + to provide USB PD and USB Type-C functionalities. > > + > > endif # TYPEC_TCPCI > > > > config TYPEC_FUSB302 > > diff --git a/drivers/usb/typec/tcpm/Makefile > > b/drivers/usb/typec/tcpm/Makefile > > index a5ff6c8..7592ccb 100644 > > --- a/drivers/usb/typec/tcpm/Makefile > > +++ b/drivers/usb/typec/tcpm/Makefile > > @@ -5,3 +5,4 @@ obj-$(CONFIG_TYPEC_WCOVE) += typec_wcove.o > > typec_wcove-y:= wcove.o > > obj-$(CONFIG_TYPEC_TCPCI)+= tcpci.o > > obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.o > > +obj-$(CONFIG_TYPEC_MT6360) += tcpci_mt6360.o > > diff --git a/drivers/usb/typec/tcpm/tcpci_mt6360.c > > b/drivers/usb/typec/tcpm/tcpci_mt6360.c > > new file mode 100644 > > index ..a381b5d > > --- /dev/null > > +++ b/drivers/usb/typec/tcpm/tcpci_mt6360.c > > @@ -0,0 +1,213 @@ > > +// SPDX-License-Identifier: GPL-2.0-only > > +// > > +// Copyright (C) 2020 MediaTek Inc. > > +// > > +// Author: ChiYuan Huang > Use /* */ except SPDX? Yes, sure. > > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include "tcpci.h" > > + > > +#define MT6360_REG_VCONNCTRL10x8C > > +#define MT6360_REG_MODECTRL2 0x8F > > +#define MT6360_REG_SWRESET 0xA0 > > +#define MT6360_REG_DEBCTRL1 0xA1 > > +#define MT6360_REG_DRPCTRL1 0xA2 > > +#define MT6360_REG_DRPCTRL2 0xA3 > > +#define MT6360_REG_I2CTORST 0xBF > > +#define MT6360_REG_RXCTRL2 0xCF > > +#define MT6360_REG_CTDCTRL2 0xEC > > + > > +/* MT6360_REG_VCONNCTRL1 */ > > +#define MT6360_VCONNCL_ENABLEBIT(0) > > +/* MT6360_REG_RXCTRL2 */ > > +#define MT6360_OPEN40M_ENABLEBIT(7) > > +/* MT6360_REG_CTDCTRL2 */ > > +#define MT6360_RPONESHOT_ENABLE BIT(6) > > + > > +struct mt6360_tcpc_info { > > + struct tcpci_data tdata; > > + struct tcpci *tcpci; > > + struct device *dev; > > + int irq; > > +}; > > + > > +static inline int mt6360_tcpc_read16(struct regmap *regmap, > > + unsigned int reg, u16 *val) > > +{ > > + return regmap_raw_read(regmap, reg, val, sizeof(u16)); > > +} > > + > > +static inline int mt6360_tcpc_write16(struct regmap *regmap, > > + unsigned int reg, u16 val) > > +{ > > + return regmap_raw_write(regmap, reg, , sizeof(u16)); > > +} > > + > > +static int mt6360_tcpc_init(struct tcpci *tcpci, struct tcpci_data *tdata) > > +{ > > + struct regmap *regmap = tdata->regmap; > > + int ret; > > + > > + ret = regmap_write(regmap, MT6360_REG_SWRESET, 0x01); > > + if (ret) > > + return ret; > > + > > + /* after reset command, wait 1~2ms to wait IC action */ > > + usleep_range(1000, 2000); > > + > > + /* write all alert to masked */ > > + ret = mt6360_tcpc_write16(regmap, TCPC_ALERT_MASK, 0); > > + if (ret) > > + return ret; > > + > > + /* config I2C timeout reset enable , and timeout to 200ms */ > > + ret = regmap_write(regmap, MT6360_REG_I2CTORST, 0x8F); > > + if (ret) > > + return ret; > > + > > + /* config CC Detect Debounce : 26.7*val us */ > > + ret =
Re: [PATCH v2 1/2] usb typec: mt6360: Add support for mt6360 Type-C driver
Guenter Roeck 於 2020年8月27日 週四 下午9:46寫道: > > On 8/27/20 4:32 AM, 啟原黃 wrote: > > Chunfeng Yun 於 2020年8月27日 週四 下午4:05寫道: > >> > >> On Thu, 2020-08-27 at 12:50 +0800, cy_huang wrote: > >>> From: ChiYuan Huang > >>> > >>> Mediatek MT6360 is a multi-functional IC that includes USB Type-C. > >>> It works with Type-C Port Controller Manager to provide USB PD > >>> and USB Type-C functionalities. > >>> > >>> Add fix to Prevent the race condition from interrupt and tcpci port > >>> unregister > >>> during module remove. > >>> > >>> Signed-off-by: ChiYuan Huang > >>> --- > >>> drivers/usb/typec/tcpm/Kconfig| 8 ++ > >>> drivers/usb/typec/tcpm/Makefile | 1 + > >>> drivers/usb/typec/tcpm/tcpci_mt6360.c | 213 > >>> ++ > >> Can you avoid using special SoC name in file name? > >> It's not clear if you later support new SoC in the driver, e.g. mt63xx? > > Okay, I will rename it to mt636x. From our SubPMIC generation, > > currently, naming will be 6360/62/67, etc.. > > What if 6361 or 6365 or 6369 will require a different driver ? > What if 6371 will, in the future, be supported by the same driver ? > Or, for that matter, 7360 ? 6537 ? > > We usually try to avoid "x" in driver names because it can never be > guaranteed that it will apply to x={0..9}. The current file name is > just fine; it is customary to name drivers after the first chip they > support. > > Guenter Thanks. it means the current file name and description is okay I'll start to revert the rename work. > > >>From our SOC roadmap, one generation can be used for one to two more years. > > I think the name MT636x is enough. > > For the next one, I can submit the patch to make it compatible with this > > driver. > > Thanks for you comment. > >> > >>> 3 files changed, 222 insertions(+) > >>> create mode 100644 drivers/usb/typec/tcpm/tcpci_mt6360.c > >>> > >>> diff --git a/drivers/usb/typec/tcpm/Kconfig > >>> b/drivers/usb/typec/tcpm/Kconfig > >>> index fa3f393..58a64e1 100644 > >>> --- a/drivers/usb/typec/tcpm/Kconfig > >>> +++ b/drivers/usb/typec/tcpm/Kconfig > >>> @@ -27,6 +27,14 @@ config TYPEC_RT1711H > >>> Type-C Port Controller Manager to provide USB PD and USB > >>> Type-C functionalities. > >>> > >>> +config TYPEC_MT6360 > >>> + tristate "Mediatek MT6360 Type-C driver" > >>> + depends on MFD_MT6360 > >>> + help > >>> + Mediatek MT6360 is a multi-functional IC that includes > >>> + USB Type-C. It works with Type-C Port Controller Manager > >>> + to provide USB PD and USB Type-C functionalities. > >>> + > >>> endif # TYPEC_TCPCI > >>> > >>> config TYPEC_FUSB302 > >>> diff --git a/drivers/usb/typec/tcpm/Makefile > >>> b/drivers/usb/typec/tcpm/Makefile > >>> index a5ff6c8..7592ccb 100644 > >>> --- a/drivers/usb/typec/tcpm/Makefile > >>> +++ b/drivers/usb/typec/tcpm/Makefile > >>> @@ -5,3 +5,4 @@ obj-$(CONFIG_TYPEC_WCOVE) += typec_wcove.o > >>> typec_wcove-y:= wcove.o > >>> obj-$(CONFIG_TYPEC_TCPCI)+= tcpci.o > >>> obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.o > >>> +obj-$(CONFIG_TYPEC_MT6360) += tcpci_mt6360.o > >>> diff --git a/drivers/usb/typec/tcpm/tcpci_mt6360.c > >>> b/drivers/usb/typec/tcpm/tcpci_mt6360.c > >>> new file mode 100644 > >>> index ..a381b5d > >>> --- /dev/null > >>> +++ b/drivers/usb/typec/tcpm/tcpci_mt6360.c > >>> @@ -0,0 +1,213 @@ > >>> +// SPDX-License-Identifier: GPL-2.0-only > >>> +// > >>> +// Copyright (C) 2020 MediaTek Inc. > >>> +// > >>> +// Author: ChiYuan Huang > >> Use /* */ except SPDX? > > Yes, sure. > >> > >>> + > >>> +#include > >>> +#include > >>> +#include > >>> +#include > >>> +#include > >>> +#include > >>> +#include > >>> + > >>> +#include "tcpci.h" > >>> + > >>> +#define MT6360_REG_VCONNCTRL10x8C > >>> +#define MT6360_REG_MODECTRL2 0x8F > >>> +#define MT6360_REG_SWRESET 0xA0 > >>> +#define MT6360_REG_DEBCTRL1 0xA1 > >>> +#define MT6360_REG_DRPCTRL1 0xA2 > >>> +#define MT6360_REG_DRPCTRL2 0xA3 > >>> +#define MT6360_REG_I2CTORST 0xBF > >>> +#define MT6360_REG_RXCTRL2 0xCF > >>> +#define MT6360_REG_CTDCTRL2 0xEC > >>> + > >>> +/* MT6360_REG_VCONNCTRL1 */ > >>> +#define MT6360_VCONNCL_ENABLEBIT(0) > >>> +/* MT6360_REG_RXCTRL2 */ > >>> +#define MT6360_OPEN40M_ENABLEBIT(7) > >>> +/* MT6360_REG_CTDCTRL2 */ > >>> +#define MT6360_RPONESHOT_ENABLE BIT(6) > >>> + > >>> +struct mt6360_tcpc_info { > >>> + struct tcpci_data tdata; > >>> + struct tcpci *tcpci; > >>> + struct device *dev; > >>> + int irq; > >>> +}; > >>> + > >>> +static inline int mt6360_tcpc_read16(struct regmap *regmap, > >>> + unsigned int reg, u16 *val) > >>> +{ > >>> + return regmap_raw_read(regmap, reg, val, sizeof(u16)); > >>> +} > >>> + > >>> +static inline int mt6360_tcpc_write16(struct regmap *regmap, > >>> + unsigned int reg, u16 val) > >>> +{ > >>> + return
Re: [PATCH v2 1/2] usb typec: mt6360: Add support for mt6360 Type-C driver
On 8/27/20 4:32 AM, 啟原黃 wrote: > Chunfeng Yun 於 2020年8月27日 週四 下午4:05寫道: >> >> On Thu, 2020-08-27 at 12:50 +0800, cy_huang wrote: >>> From: ChiYuan Huang >>> >>> Mediatek MT6360 is a multi-functional IC that includes USB Type-C. >>> It works with Type-C Port Controller Manager to provide USB PD >>> and USB Type-C functionalities. >>> >>> Add fix to Prevent the race condition from interrupt and tcpci port >>> unregister >>> during module remove. >>> >>> Signed-off-by: ChiYuan Huang >>> --- >>> drivers/usb/typec/tcpm/Kconfig| 8 ++ >>> drivers/usb/typec/tcpm/Makefile | 1 + >>> drivers/usb/typec/tcpm/tcpci_mt6360.c | 213 >>> ++ >> Can you avoid using special SoC name in file name? >> It's not clear if you later support new SoC in the driver, e.g. mt63xx? > Okay, I will rename it to mt636x. From our SubPMIC generation, > currently, naming will be 6360/62/67, etc.. What if 6361 or 6365 or 6369 will require a different driver ? What if 6371 will, in the future, be supported by the same driver ? Or, for that matter, 7360 ? 6537 ? We usually try to avoid "x" in driver names because it can never be guaranteed that it will apply to x={0..9}. The current file name is just fine; it is customary to name drivers after the first chip they support. Guenter >>From our SOC roadmap, one generation can be used for one to two more years. > I think the name MT636x is enough. > For the next one, I can submit the patch to make it compatible with this > driver. > Thanks for you comment. >> >>> 3 files changed, 222 insertions(+) >>> create mode 100644 drivers/usb/typec/tcpm/tcpci_mt6360.c >>> >>> diff --git a/drivers/usb/typec/tcpm/Kconfig b/drivers/usb/typec/tcpm/Kconfig >>> index fa3f393..58a64e1 100644 >>> --- a/drivers/usb/typec/tcpm/Kconfig >>> +++ b/drivers/usb/typec/tcpm/Kconfig >>> @@ -27,6 +27,14 @@ config TYPEC_RT1711H >>> Type-C Port Controller Manager to provide USB PD and USB >>> Type-C functionalities. >>> >>> +config TYPEC_MT6360 >>> + tristate "Mediatek MT6360 Type-C driver" >>> + depends on MFD_MT6360 >>> + help >>> + Mediatek MT6360 is a multi-functional IC that includes >>> + USB Type-C. It works with Type-C Port Controller Manager >>> + to provide USB PD and USB Type-C functionalities. >>> + >>> endif # TYPEC_TCPCI >>> >>> config TYPEC_FUSB302 >>> diff --git a/drivers/usb/typec/tcpm/Makefile >>> b/drivers/usb/typec/tcpm/Makefile >>> index a5ff6c8..7592ccb 100644 >>> --- a/drivers/usb/typec/tcpm/Makefile >>> +++ b/drivers/usb/typec/tcpm/Makefile >>> @@ -5,3 +5,4 @@ obj-$(CONFIG_TYPEC_WCOVE) += typec_wcove.o >>> typec_wcove-y:= wcove.o >>> obj-$(CONFIG_TYPEC_TCPCI)+= tcpci.o >>> obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.o >>> +obj-$(CONFIG_TYPEC_MT6360) += tcpci_mt6360.o >>> diff --git a/drivers/usb/typec/tcpm/tcpci_mt6360.c >>> b/drivers/usb/typec/tcpm/tcpci_mt6360.c >>> new file mode 100644 >>> index ..a381b5d >>> --- /dev/null >>> +++ b/drivers/usb/typec/tcpm/tcpci_mt6360.c >>> @@ -0,0 +1,213 @@ >>> +// SPDX-License-Identifier: GPL-2.0-only >>> +// >>> +// Copyright (C) 2020 MediaTek Inc. >>> +// >>> +// Author: ChiYuan Huang >> Use /* */ except SPDX? > Yes, sure. >> >>> + >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> +#include >>> + >>> +#include "tcpci.h" >>> + >>> +#define MT6360_REG_VCONNCTRL10x8C >>> +#define MT6360_REG_MODECTRL2 0x8F >>> +#define MT6360_REG_SWRESET 0xA0 >>> +#define MT6360_REG_DEBCTRL1 0xA1 >>> +#define MT6360_REG_DRPCTRL1 0xA2 >>> +#define MT6360_REG_DRPCTRL2 0xA3 >>> +#define MT6360_REG_I2CTORST 0xBF >>> +#define MT6360_REG_RXCTRL2 0xCF >>> +#define MT6360_REG_CTDCTRL2 0xEC >>> + >>> +/* MT6360_REG_VCONNCTRL1 */ >>> +#define MT6360_VCONNCL_ENABLEBIT(0) >>> +/* MT6360_REG_RXCTRL2 */ >>> +#define MT6360_OPEN40M_ENABLEBIT(7) >>> +/* MT6360_REG_CTDCTRL2 */ >>> +#define MT6360_RPONESHOT_ENABLE BIT(6) >>> + >>> +struct mt6360_tcpc_info { >>> + struct tcpci_data tdata; >>> + struct tcpci *tcpci; >>> + struct device *dev; >>> + int irq; >>> +}; >>> + >>> +static inline int mt6360_tcpc_read16(struct regmap *regmap, >>> + unsigned int reg, u16 *val) >>> +{ >>> + return regmap_raw_read(regmap, reg, val, sizeof(u16)); >>> +} >>> + >>> +static inline int mt6360_tcpc_write16(struct regmap *regmap, >>> + unsigned int reg, u16 val) >>> +{ >>> + return regmap_raw_write(regmap, reg, , sizeof(u16)); >>> +} >>> + >>> +static int mt6360_tcpc_init(struct tcpci *tcpci, struct tcpci_data *tdata) >>> +{ >>> + struct regmap *regmap = tdata->regmap; >>> + int ret; >>> + >>> + ret = regmap_write(regmap, MT6360_REG_SWRESET, 0x01); >>> + if (ret) >>> + return ret; >>> + >>> + /* after reset command, wait 1~2ms to wait IC action */ >>> +
Re: [PATCH v2 1/2] usb typec: mt6360: Add support for mt6360 Type-C driver
On Thu, 2020-08-27 at 12:50 +0800, cy_huang wrote: > From: ChiYuan Huang > > Mediatek MT6360 is a multi-functional IC that includes USB Type-C. > It works with Type-C Port Controller Manager to provide USB PD > and USB Type-C functionalities. > > Add fix to Prevent the race condition from interrupt and tcpci port unregister > during module remove. > > Signed-off-by: ChiYuan Huang > --- > drivers/usb/typec/tcpm/Kconfig| 8 ++ > drivers/usb/typec/tcpm/Makefile | 1 + > drivers/usb/typec/tcpm/tcpci_mt6360.c | 213 > ++ Can you avoid using special SoC name in file name? It's not clear if you later support new SoC in the driver, e.g. mt63xx? > 3 files changed, 222 insertions(+) > create mode 100644 drivers/usb/typec/tcpm/tcpci_mt6360.c > > diff --git a/drivers/usb/typec/tcpm/Kconfig b/drivers/usb/typec/tcpm/Kconfig > index fa3f393..58a64e1 100644 > --- a/drivers/usb/typec/tcpm/Kconfig > +++ b/drivers/usb/typec/tcpm/Kconfig > @@ -27,6 +27,14 @@ config TYPEC_RT1711H > Type-C Port Controller Manager to provide USB PD and USB > Type-C functionalities. > > +config TYPEC_MT6360 > + tristate "Mediatek MT6360 Type-C driver" > + depends on MFD_MT6360 > + help > + Mediatek MT6360 is a multi-functional IC that includes > + USB Type-C. It works with Type-C Port Controller Manager > + to provide USB PD and USB Type-C functionalities. > + > endif # TYPEC_TCPCI > > config TYPEC_FUSB302 > diff --git a/drivers/usb/typec/tcpm/Makefile b/drivers/usb/typec/tcpm/Makefile > index a5ff6c8..7592ccb 100644 > --- a/drivers/usb/typec/tcpm/Makefile > +++ b/drivers/usb/typec/tcpm/Makefile > @@ -5,3 +5,4 @@ obj-$(CONFIG_TYPEC_WCOVE) += typec_wcove.o > typec_wcove-y:= wcove.o > obj-$(CONFIG_TYPEC_TCPCI)+= tcpci.o > obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.o > +obj-$(CONFIG_TYPEC_MT6360) += tcpci_mt6360.o > diff --git a/drivers/usb/typec/tcpm/tcpci_mt6360.c > b/drivers/usb/typec/tcpm/tcpci_mt6360.c > new file mode 100644 > index ..a381b5d > --- /dev/null > +++ b/drivers/usb/typec/tcpm/tcpci_mt6360.c > @@ -0,0 +1,213 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +// > +// Copyright (C) 2020 MediaTek Inc. > +// > +// Author: ChiYuan Huang Use /* */ except SPDX? > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "tcpci.h" > + > +#define MT6360_REG_VCONNCTRL10x8C > +#define MT6360_REG_MODECTRL2 0x8F > +#define MT6360_REG_SWRESET 0xA0 > +#define MT6360_REG_DEBCTRL1 0xA1 > +#define MT6360_REG_DRPCTRL1 0xA2 > +#define MT6360_REG_DRPCTRL2 0xA3 > +#define MT6360_REG_I2CTORST 0xBF > +#define MT6360_REG_RXCTRL2 0xCF > +#define MT6360_REG_CTDCTRL2 0xEC > + > +/* MT6360_REG_VCONNCTRL1 */ > +#define MT6360_VCONNCL_ENABLEBIT(0) > +/* MT6360_REG_RXCTRL2 */ > +#define MT6360_OPEN40M_ENABLEBIT(7) > +/* MT6360_REG_CTDCTRL2 */ > +#define MT6360_RPONESHOT_ENABLE BIT(6) > + > +struct mt6360_tcpc_info { > + struct tcpci_data tdata; > + struct tcpci *tcpci; > + struct device *dev; > + int irq; > +}; > + > +static inline int mt6360_tcpc_read16(struct regmap *regmap, > + unsigned int reg, u16 *val) > +{ > + return regmap_raw_read(regmap, reg, val, sizeof(u16)); > +} > + > +static inline int mt6360_tcpc_write16(struct regmap *regmap, > + unsigned int reg, u16 val) > +{ > + return regmap_raw_write(regmap, reg, , sizeof(u16)); > +} > + > +static int mt6360_tcpc_init(struct tcpci *tcpci, struct tcpci_data *tdata) > +{ > + struct regmap *regmap = tdata->regmap; > + int ret; > + > + ret = regmap_write(regmap, MT6360_REG_SWRESET, 0x01); > + if (ret) > + return ret; > + > + /* after reset command, wait 1~2ms to wait IC action */ > + usleep_range(1000, 2000); > + > + /* write all alert to masked */ > + ret = mt6360_tcpc_write16(regmap, TCPC_ALERT_MASK, 0); > + if (ret) > + return ret; > + > + /* config I2C timeout reset enable , and timeout to 200ms */ > + ret = regmap_write(regmap, MT6360_REG_I2CTORST, 0x8F); > + if (ret) > + return ret; > + > + /* config CC Detect Debounce : 26.7*val us */ > + ret = regmap_write(regmap, MT6360_REG_DEBCTRL1, 0x10); > + if (ret) > + return ret; > + > + /* DRP Toggle Cycle : 51.2 + 6.4*val ms */ > + ret = regmap_write(regmap, MT6360_REG_DRPCTRL1, 4); > + if (ret) > + return ret; > + > + /* DRP Duyt Ctrl : dcSRC: /1024 */ > + ret = mt6360_tcpc_write16(regmap, MT6360_REG_DRPCTRL2, 330); > + if (ret) > + return ret; > + > + /* Enable VCONN Current Limit function */ > + ret = regmap_update_bits(regmap, MT6360_REG_VCONNCTRL1, > MT6360_VCONNCL_ENABLE, > + MT6360_VCONNCL_ENABLE); > + if (ret) > +
Re: [PATCH v2 1/2] usb typec: mt6360: Add support for mt6360 Type-C driver
Heikki Krogerus 於 2020年8月27日 週四 下午3:00寫道: > > On Thu, Aug 27, 2020 at 12:50:58PM +0800, cy_huang wrote: > > From: ChiYuan Huang > > > > Mediatek MT6360 is a multi-functional IC that includes USB Type-C. > > It works with Type-C Port Controller Manager to provide USB PD > > and USB Type-C functionalities. > > > > Add fix to Prevent the race condition from interrupt and tcpci port > > unregister > > during module remove. > > You merged two patches from v2 together, so that really makes this > v3. Where is the changelog? changelog Add fix to Prevent the race condition from interrupt and tcpci port unregister during module remove. Do I need to resent the real V3 and mark the first patch for the commit log like as below text? Mediatek MT6360 is a multi-functional IC that includes USB Type-C. It works with Type-C Port Controller Manager to provide USB PD and USB Type-C functionalities. V1 -> V2 1. Add fix to Prevent the race condition from interrupt and tcpci port unregister during module remove. V2 -> V3 1. Merge V2 change into the first patch. If yes, I can use this way to resend patch v3 for the readability. > > thanks, > > -- > heikki
Re: [PATCH v2 1/2] usb typec: mt6360: Add support for mt6360 Type-C driver
On Thu, Aug 27, 2020 at 12:50:58PM +0800, cy_huang wrote: > From: ChiYuan Huang > > Mediatek MT6360 is a multi-functional IC that includes USB Type-C. > It works with Type-C Port Controller Manager to provide USB PD > and USB Type-C functionalities. > > Add fix to Prevent the race condition from interrupt and tcpci port unregister > during module remove. You merged two patches from v2 together, so that really makes this v3. Where is the changelog? thanks, -- heikki
[PATCH v2 1/2] usb typec: mt6360: Add support for mt6360 Type-C driver
From: ChiYuan Huang Mediatek MT6360 is a multi-functional IC that includes USB Type-C. It works with Type-C Port Controller Manager to provide USB PD and USB Type-C functionalities. Add fix to Prevent the race condition from interrupt and tcpci port unregister during module remove. Signed-off-by: ChiYuan Huang --- drivers/usb/typec/tcpm/Kconfig| 8 ++ drivers/usb/typec/tcpm/Makefile | 1 + drivers/usb/typec/tcpm/tcpci_mt6360.c | 213 ++ 3 files changed, 222 insertions(+) create mode 100644 drivers/usb/typec/tcpm/tcpci_mt6360.c diff --git a/drivers/usb/typec/tcpm/Kconfig b/drivers/usb/typec/tcpm/Kconfig index fa3f393..58a64e1 100644 --- a/drivers/usb/typec/tcpm/Kconfig +++ b/drivers/usb/typec/tcpm/Kconfig @@ -27,6 +27,14 @@ config TYPEC_RT1711H Type-C Port Controller Manager to provide USB PD and USB Type-C functionalities. +config TYPEC_MT6360 + tristate "Mediatek MT6360 Type-C driver" + depends on MFD_MT6360 + help + Mediatek MT6360 is a multi-functional IC that includes + USB Type-C. It works with Type-C Port Controller Manager + to provide USB PD and USB Type-C functionalities. + endif # TYPEC_TCPCI config TYPEC_FUSB302 diff --git a/drivers/usb/typec/tcpm/Makefile b/drivers/usb/typec/tcpm/Makefile index a5ff6c8..7592ccb 100644 --- a/drivers/usb/typec/tcpm/Makefile +++ b/drivers/usb/typec/tcpm/Makefile @@ -5,3 +5,4 @@ obj-$(CONFIG_TYPEC_WCOVE) += typec_wcove.o typec_wcove-y := wcove.o obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o obj-$(CONFIG_TYPEC_RT1711H)+= tcpci_rt1711h.o +obj-$(CONFIG_TYPEC_MT6360) += tcpci_mt6360.o diff --git a/drivers/usb/typec/tcpm/tcpci_mt6360.c b/drivers/usb/typec/tcpm/tcpci_mt6360.c new file mode 100644 index ..a381b5d --- /dev/null +++ b/drivers/usb/typec/tcpm/tcpci_mt6360.c @@ -0,0 +1,213 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// Copyright (C) 2020 MediaTek Inc. +// +// Author: ChiYuan Huang + +#include +#include +#include +#include +#include +#include +#include + +#include "tcpci.h" + +#define MT6360_REG_VCONNCTRL1 0x8C +#define MT6360_REG_MODECTRL2 0x8F +#define MT6360_REG_SWRESET 0xA0 +#define MT6360_REG_DEBCTRL10xA1 +#define MT6360_REG_DRPCTRL10xA2 +#define MT6360_REG_DRPCTRL20xA3 +#define MT6360_REG_I2CTORST0xBF +#define MT6360_REG_RXCTRL2 0xCF +#define MT6360_REG_CTDCTRL20xEC + +/* MT6360_REG_VCONNCTRL1 */ +#define MT6360_VCONNCL_ENABLE BIT(0) +/* MT6360_REG_RXCTRL2 */ +#define MT6360_OPEN40M_ENABLE BIT(7) +/* MT6360_REG_CTDCTRL2 */ +#define MT6360_RPONESHOT_ENABLEBIT(6) + +struct mt6360_tcpc_info { + struct tcpci_data tdata; + struct tcpci *tcpci; + struct device *dev; + int irq; +}; + +static inline int mt6360_tcpc_read16(struct regmap *regmap, +unsigned int reg, u16 *val) +{ + return regmap_raw_read(regmap, reg, val, sizeof(u16)); +} + +static inline int mt6360_tcpc_write16(struct regmap *regmap, + unsigned int reg, u16 val) +{ + return regmap_raw_write(regmap, reg, , sizeof(u16)); +} + +static int mt6360_tcpc_init(struct tcpci *tcpci, struct tcpci_data *tdata) +{ + struct regmap *regmap = tdata->regmap; + int ret; + + ret = regmap_write(regmap, MT6360_REG_SWRESET, 0x01); + if (ret) + return ret; + + /* after reset command, wait 1~2ms to wait IC action */ + usleep_range(1000, 2000); + + /* write all alert to masked */ + ret = mt6360_tcpc_write16(regmap, TCPC_ALERT_MASK, 0); + if (ret) + return ret; + + /* config I2C timeout reset enable , and timeout to 200ms */ + ret = regmap_write(regmap, MT6360_REG_I2CTORST, 0x8F); + if (ret) + return ret; + + /* config CC Detect Debounce : 26.7*val us */ + ret = regmap_write(regmap, MT6360_REG_DEBCTRL1, 0x10); + if (ret) + return ret; + + /* DRP Toggle Cycle : 51.2 + 6.4*val ms */ + ret = regmap_write(regmap, MT6360_REG_DRPCTRL1, 4); + if (ret) + return ret; + + /* DRP Duyt Ctrl : dcSRC: /1024 */ + ret = mt6360_tcpc_write16(regmap, MT6360_REG_DRPCTRL2, 330); + if (ret) + return ret; + + /* Enable VCONN Current Limit function */ + ret = regmap_update_bits(regmap, MT6360_REG_VCONNCTRL1, MT6360_VCONNCL_ENABLE, +MT6360_VCONNCL_ENABLE); + if (ret) + return ret; + + /* Enable cc open 40ms when pmic send vsysuv signal */ + ret = regmap_update_bits(regmap, MT6360_REG_RXCTRL2, MT6360_OPEN40M_ENABLE, +MT6360_OPEN40M_ENABLE); + if (ret) + return ret; + + /* Enable Rpdet oneshot detection */ + ret = regmap_update_bits(regmap, MT6360_REG_CTDCTRL2,