usb typec: mt6360: Add support for mt6360 Type-C driver
Subsystems (5)
PATCH v2 1/2 usb typec: mt6360: Add support for mt6360 Type-C driver
From: ChiYuan Huang <[email protected]>
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.
--- 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
drivers/usb/typec/tcpm/Kconfig +8 -0
@@ -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
drivers/usb/typec/tcpm/Makefile +1 -0
@@ -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
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +213 -0
213 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 2/2 usb typec: mt6360: Add MT6360 Type-C DT binding documentation
From: ChiYuan Huang <[email protected]>
Add a devicetree binding documentation for the MT6360 Type-C driver.
--- .../bindings/usb/mediatek,mt6360-tcpc.yaml | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/mediatek,mt6360-tcpc.yaml
Documentation/devicetree/bindings/usb/mediatek,mt6360-tcpc.yaml new file +73 -0
@@ -0,0 +1,73 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/usb/mediatek,mt6360-tcpc.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: Mediatek MT6360 Type-C Port Switch and Power Delivery controller DT bindings + +maintainers: + - ChiYuan Huang <[email protected]> + +description: | + Mediatek MT6360 is a multi-functional device. It integrates charger, ADC, flash, RGB indicators, + regulators (BUCKs/LDOs), and TypeC Port Switch with Power Delivery controller. + This document only describes MT6360 Type-C Port Switch and Power Delivery controller. + +properties: + compatible: + enum: + - mediatek,mt6360-tcpc + + interrupts-extended: + maxItems: 1 + + interrupt-names: + items: + - const: PD_IRQB + +patternProperties: + "connector": + type: object + $ref: ../connector/usb-connector.yaml# + description: + Properties for usb c connector. + +additionalProperties: false + +required: + - compatible + - interrupts-extended + - interrupt-names + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/usb/pd.h> + i2c0 { + #address-cells = <1>; + #size-cells = <0>; + + mt6360@34 { + compatible = "mediatek,mt6360"; + reg = <0x34>; + + tcpc { + compatible = "mediatek,mt6360-tcpc"; + interrupts-extended = <&gpio26 3 IRQ_TYPE_LEVEL_LOW>; + interrupt-names = "PD_IRQB"; + + connector { + compatible = "usb-c-connector"; + label = "USB-C"; + data-role = "dual"; + power-role = "dual"; + try-power-role = "sink"; + source-pdos = <PDO_FIXED(5000, 1000, 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>; + }; + }; + }; + }; +...
Signature · 1 line
2.7.4
Heikki Krogerus
maintainerQuoted 8 lines · cy_huang
From: ChiYuan Huang <[email protected]>
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,
Signature · 1 line
heikki
Heikki Krogerus <[email protected]> 於 2020年8月27日 週四 下午3:00寫道:
Quoted 8 lines · cy_huang
Quoted 6 lines
From: ChiYuan Huang <[email protected]>
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.
Quoted 5 lines
Quoted 2 lines
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.
Quoted 5 lines
thanks,
--
heikki
Chunfeng Yun
maintainerQuoted 6 lines · cy_huang
From: ChiYuan Huang <[email protected]>
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.
Quoted 8 lines
Add fix to Prevent the race condition from interrupt and tcpci port unregister during module remove.
Signed-off-by ChiYuan Huang <[email protected]>--- 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?
Quoted 37 lines
3 files changed, 222 insertions(+) create mode 100644 drivers/usb/typec/tcpm/tcpci_mt6360.cdrivers/usb/typec/tcpm/Kconfig +8
-0@@ -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_FUSB302drivers/usb/typec/tcpm/Makefile +1
-0@@ -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.odrivers/usb/typec/tcpm/tcpci_mt6360.c new file +0
-0
drivers/usb/typec/tcpm/tcpci_mt6360.c line 5
Quoted 5 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +5
-0@@ -0,0 +1,213 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// Copyright (C) 2020 MediaTek Inc. +// +// Author: ChiYuan Huang <[email protected]>
Use /* */ except SPDX?
Quoted 123 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +123
-0+ +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/usb/tcpm.h> + +#include "tcpci.h" + +#define MT6360_REG_VCONNCTRL1 0x8C +#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_ENABLE BIT(0) +/* MT6360_REG_RXCTRL2 */ +#define MT6360_OPEN40M_ENABLE BIT(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, &val,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 ,MT6360_RPONESHOT_ENABLE , +MT6360_RPONESHOT_ENABLE ); +if (ret) +return ret; + +/* Set shipping mode off, AUTOIDLE on */ +return regmap_write (regmap,MT6360_REG_MODECTRL2 ,0x7A ); +} + +static irqreturn_t mt6360_irq (int irq,void *dev_id) +{ +struct mt6360_tcpc_info *mti = dev_id; + +return tcpci_irq (mti->tcpci); +} + +static int mt6360_tcpc_probe (struct platform_device *pdev) +{ +struct mt6360_tcpc_info *mti; +int ret; + + mti =devm_kzalloc (&pdev->dev,sizeof (*mti),GFP_KERNEL ); +if (!mti) +return -ENOMEM ; + + mti->dev = &pdev->dev;
drivers/usb/typec/tcpm/tcpci_mt6360.c line 138
Quoted 10 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +10
-0+ + mti->tdata.regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!mti->tdata.regmap) { +dev_err (&pdev->dev,"Failed to get parent regmap\n" ); +return -ENODEV ; + } + + mti->irq =platform_get_irq_byname (pdev,"PD_IRQB" ); +if (mti->irq <0 ) { +dev_err (&pdev->dev,"Failed to get PD_IRQB irq\n" );
No need add error log, platform_get_irq_byname will print it
drivers/usb/typec/tcpm/tcpci_mt6360.c line 144
Quoted 6 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +6
-0+return mti->irq; + } + + mti->tdata.init = mt6360_tcpc_init; + mti->tcpci =tcpci_register_port (&pdev->dev, &mti->tdata); +if (IS_ERR_OR_NULL (mti->tcpci)) {
Use IS_ERR()? it seems not return NULL
drivers/usb/typec/tcpm/tcpci_mt6360.c line 146
Quoted 2 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +2
-0+dev_err (&pdev->dev,"Failed to register tcpci port\n" ); +return PTR_ERR (mti->tcpci);
If return NULL, this may return 0?
Quoted 11 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +11
-0+ } + + ret =devm_request_threaded_irq (mti->dev, mti->irq,NULL , mt6360_irq,IRQF_ONESHOT , +dev_name (&pdev->dev), mti); +if (ret) { +dev_err (mti->dev,"Failed to register irq\n" ); +tcpci_unregister_port (mti->tcpci); +return ret; + } + +device_init_wakeup (&pdev->dev, true);
drivers/usb/typec/tcpm/tcpci_mt6360.c line 167
Quoted 10 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +10
-0+platform_set_drvdata (pdev, mti); + +return 0 ; +} + +static int mt6360_tcpc_remove (struct platform_device *pdev) +{ +struct mt6360_tcpc_info *mti =platform_get_drvdata (pdev); + +disable_irq (mti->irq);
need sync?
Quoted 46 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +46
-0+tcpci_unregister_port (mti->tcpci); +return 0 ; +} + +static int __maybe_unused mt6360_tcpc_suspend (struct device *dev) +{ +struct mt6360_tcpc_info *mti =dev_get_drvdata (dev); + +if (device_may_wakeup (dev)) +enable_irq_wake (mti->irq); + +return 0 ; +} + +static int __maybe_unused mt6360_tcpc_resume (struct device *dev) +{ +struct mt6360_tcpc_info *mti =dev_get_drvdata (dev); + +if (device_may_wakeup (dev)) +disable_irq_wake (mti->irq); + +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(mt6360_tcpc_pm_ops, mt6360_tcpc_suspend, mt6360_tcpc_resume); + +static const struct of_device_id __maybe_unused mt6360_tcpc_of_id[] = { + { .compatible ="mediatek,mt6360-tcpc" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, mt6360_tcpc_of_id); + +static struct platform_driver mt6360_tcpc_driver = { + .driver = { + .name ="mt6360-tcpc" , + .pm = &mt6360_tcpc_pm_ops, + .of_match_table = mt6360_tcpc_of_id, + }, + .probe = mt6360_tcpc_probe, + .remove = mt6360_tcpc_remove, +}; +module_platform_driver (mt6360_tcpc_driver); + +MODULE_AUTHOR ("ChiYuan Huang <[email protected]>" ); +MODULE_DESCRIPTION ("MT6360 USB Type-C Port Controller Interface Driver" ); +MODULE_LICENSE ("GPL v2" );
Chunfeng Yun <[email protected]> 於 2020年8月27日 週四 下午4:05寫道:
Quoted 11 lines · cy_huang
Quoted 9 lines
From: ChiYuan Huang <[email protected]>
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.
Quoted 7 lines
Quoted 5 lines
Signed-off-by ChiYuan Huang <[email protected]>--- 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.
Quoted 36 lines
Quoted 36 lines
3 files changed, 222 insertions(+) create mode 100644 drivers/usb/typec/tcpm/tcpci_mt6360.cdrivers/usb/typec/tcpm/Kconfig +8
-0@@ -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_FUSB302drivers/usb/typec/tcpm/Makefile +1
-0@@ -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.odrivers/usb/typec/tcpm/tcpci_mt6360.c new file +0
-1--- /dev/null
Quoted 8 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c line 5
Quoted 7 lines
+++
b/drivers/usb/typec/tcpm/tcpci_mt6360.cdrivers/usb/typec/tcpm/tcpci_mt6360.c new file +5
-0@@ -0,0 +1,213 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// Copyright (C) 2020 MediaTek Inc. +// +// Author: ChiYuan Huang <[email protected]> Use /* */ except SPDX?
Yes, sure.
Quoted 127 lines
Quoted 127 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +126
-0+ +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/usb/tcpm.h> + +#include "tcpci.h" + +#define MT6360_REG_VCONNCTRL1 0x8C +#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_ENABLE BIT(0) +/* MT6360_REG_RXCTRL2 */ +#define MT6360_OPEN40M_ENABLE BIT(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, &val,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 ,MT6360_RPONESHOT_ENABLE , +MT6360_RPONESHOT_ENABLE ); +if (ret) +return ret; + +/* Set shipping mode off, AUTOIDLE on */ +return regmap_write (regmap,MT6360_REG_MODECTRL2 ,0x7A ); +} + +static irqreturn_t mt6360_irq (int irq,void *dev_id) +{ +struct mt6360_tcpc_info *mti = dev_id; + +return tcpci_irq (mti->tcpci); +} + +static int mt6360_tcpc_probe (struct platform_device *pdev) +{ +struct mt6360_tcpc_info *mti; +int ret; + + mti =devm_kzalloc (&pdev->dev,sizeof (*mti),GFP_KERNEL ); +if (!mti) +return -ENOMEM ; + + mti->dev = &pdev->dev; + + mti->tdata.regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!mti->tdata.regmap) {
Quoted 8 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c line 138
Quoted 7 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +7
-0+dev_err (&pdev->dev,"Failed to get parent regmap\n" ); +return -ENODEV ; + } + + mti->irq =platform_get_irq_byname (pdev,"PD_IRQB" ); +if (mti->irq <0 ) { +dev_err (&pdev->dev,"Failed to get PD_IRQB irq\n" );No need add error log,
platform_get_irq_bynamewill print it
I'll remove it in the next revision. Thanks
Quoted 11 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c line 144
Quoted 7 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +6
-0+return mti->irq; + } + + mti->tdata.init = mt6360_tcpc_init; + mti->tcpci =tcpci_register_port (&pdev->dev, &mti->tdata); +if (IS_ERR_OR_NULL (mti->tcpci)) {Use
IS_ERR()? it seems not return NULLdrivers/usb/typec/tcpm/tcpci_mt6360.c line 146
Quoted 2 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +2
-0+dev_err (&pdev->dev,"Failed to register tcpci port\n" ); +return PTR_ERR (mti->tcpci);If return NULL, this may return 0?
Remove it later. you're right.
Quoted 15 lines
Quoted 15 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +14
-0+ } + + ret =devm_request_threaded_irq (mti->dev, mti->irq,NULL , mt6360_irq,IRQF_ONESHOT , +dev_name (&pdev->dev), mti); +if (ret) { +dev_err (mti->dev,"Failed to register irq\n" ); +tcpci_unregister_port (mti->tcpci); +return ret; + } + +device_init_wakeup (&pdev->dev, true); +platform_set_drvdata (pdev, mti); + +return 0 ;
Quoted 8 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c line 167
Quoted 7 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +7
-0+} + +static int mt6360_tcpc_remove (struct platform_device *pdev) +{ +struct mt6360_tcpc_info *mti =platform_get_drvdata (pdev); + +disable_irq (mti->irq);need sync?
Yes, sync must be considered to wait interrupt is really finished. And disable_irq already the sync version.
Quoted 39 lines
Quoted 39 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +38
-0+tcpci_unregister_port (mti->tcpci); +return 0 ; +} + +static int __maybe_unused mt6360_tcpc_suspend (struct device *dev) +{ +struct mt6360_tcpc_info *mti =dev_get_drvdata (dev); + +if (device_may_wakeup (dev)) +enable_irq_wake (mti->irq); + +return 0 ; +} + +static int __maybe_unused mt6360_tcpc_resume (struct device *dev) +{ +struct mt6360_tcpc_info *mti =dev_get_drvdata (dev); + +if (device_may_wakeup (dev)) +disable_irq_wake (mti->irq); + +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(mt6360_tcpc_pm_ops, mt6360_tcpc_suspend, mt6360_tcpc_resume); + +static const struct of_device_id __maybe_unused mt6360_tcpc_of_id[] = { + { .compatible ="mediatek,mt6360-tcpc" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, mt6360_tcpc_of_id); + +static struct platform_driver mt6360_tcpc_driver = { + .driver = { + .name ="mt6360-tcpc" , + .pm = &mt6360_tcpc_pm_ops, + .of_match_table = mt6360_tcpc_of_id, + },
Quoted 9 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c line 213
Quoted 8 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +8
-0+ .probe = mt6360_tcpc_probe, + .remove = mt6360_tcpc_remove, +}; +module_platform_driver (mt6360_tcpc_driver); + +MODULE_AUTHOR ("ChiYuan Huang <[email protected]>" ); +MODULE_DESCRIPTION ("MT6360 USB Type-C Port Controller Interface Driver" ); +MODULE_LICENSE ("GPL v2" );
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
Quoted 17 lines · 啟原黃
Chunfeng Yun <[email protected]> 於 2020年8月27日 週四 下午4:05寫道:
Quoted 16 lines · cy_huang
Quoted 14 lines
From: ChiYuan Huang <[email protected]>
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 <[email protected]>--- drivers/usb/typec/tcpm/Kconfig | 8 ++ drivers/usb/typec/tcpm/Makefile | 1 + drivers/usb/typec/tcpm/tcpci_mt6360.c | 213 ++++++++++++++++++++++++++++++++++
Quoted 4 lines
Quoted 2 lines
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
Quoted 220 lines
Quoted 1 line
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.Quoted 36 lines
Quoted 36 lines
3 files changed, 222 insertions(+) create mode 100644 drivers/usb/typec/tcpm/tcpci_mt6360.cdrivers/usb/typec/tcpm/Kconfig +8
-0@@ -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_FUSB302drivers/usb/typec/tcpm/Makefile +1
-0@@ -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.odrivers/usb/typec/tcpm/tcpci_mt6360.c new file +0
-1--- /dev/nullQuoted 8 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c line 5
Quoted 7 lines
+++
b/drivers/usb/typec/tcpm/tcpci_mt6360.cdrivers/usb/typec/tcpm/tcpci_mt6360.c new file +5
-0@@ -0,0 +1,213 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// Copyright (C) 2020 MediaTek Inc. +// +// Author: ChiYuan Huang <[email protected]> Use /* */ except SPDX?
Yes, sure.
Quoted 127 lines
Quoted 127 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +126
-0+ +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/usb/tcpm.h> + +#include "tcpci.h" + +#define MT6360_REG_VCONNCTRL1 0x8C +#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_ENABLE BIT(0) +/* MT6360_REG_RXCTRL2 */ +#define MT6360_OPEN40M_ENABLE BIT(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, &val,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 ,MT6360_RPONESHOT_ENABLE , +MT6360_RPONESHOT_ENABLE ); +if (ret) +return ret; + +/* Set shipping mode off, AUTOIDLE on */ +return regmap_write (regmap,MT6360_REG_MODECTRL2 ,0x7A ); +} + +static irqreturn_t mt6360_irq (int irq,void *dev_id) +{ +struct mt6360_tcpc_info *mti = dev_id; + +return tcpci_irq (mti->tcpci); +} + +static int mt6360_tcpc_probe (struct platform_device *pdev) +{ +struct mt6360_tcpc_info *mti; +int ret; + + mti =devm_kzalloc (&pdev->dev,sizeof (*mti),GFP_KERNEL ); +if (!mti) +return -ENOMEM ; + + mti->dev = &pdev->dev; + + mti->tdata.regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!mti->tdata.regmap) {Quoted 8 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c line 138
Quoted 7 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +7
-0+dev_err (&pdev->dev,"Failed to get parent regmap\n" ); +return -ENODEV ; + } + + mti->irq =platform_get_irq_byname (pdev,"PD_IRQB" ); +if (mti->irq <0 ) { +dev_err (&pdev->dev,"Failed to get PD_IRQB irq\n" );No need add error log,
platform_get_irq_bynamewill print itI'll remove it in the next revision. Thanks
Quoted 11 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c line 144
Quoted 7 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +6
-0+return mti->irq; + } + + mti->tdata.init = mt6360_tcpc_init; + mti->tcpci =tcpci_register_port (&pdev->dev, &mti->tdata); +if (IS_ERR_OR_NULL (mti->tcpci)) {Use
IS_ERR()? it seems not return NULLdrivers/usb/typec/tcpm/tcpci_mt6360.c line 146
Quoted 2 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +2
-0+dev_err (&pdev->dev,"Failed to register tcpci port\n" ); +return PTR_ERR (mti->tcpci);If return NULL, this may return 0?
Remove it later. you're right.
Quoted 15 lines
Quoted 15 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +14
-0+ } + + ret =devm_request_threaded_irq (mti->dev, mti->irq,NULL , mt6360_irq,IRQF_ONESHOT , +dev_name (&pdev->dev), mti); +if (ret) { +dev_err (mti->dev,"Failed to register irq\n" ); +tcpci_unregister_port (mti->tcpci); +return ret; + } + +device_init_wakeup (&pdev->dev, true); +platform_set_drvdata (pdev, mti); + +return 0 ;Quoted 8 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c line 167
Quoted 7 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +7
-0+} + +static int mt6360_tcpc_remove (struct platform_device *pdev) +{ +struct mt6360_tcpc_info *mti =platform_get_drvdata (pdev); + +disable_irq (mti->irq);need sync?
Quoted 50 lines
Yes, sync must be considered to wait interrupt is really finished. And
disable_irqalready the sync version.Quoted 48 lines
Quoted 47 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +46
-0+tcpci_unregister_port (mti->tcpci); +return 0 ; +} + +static int __maybe_unused mt6360_tcpc_suspend (struct device *dev) +{ +struct mt6360_tcpc_info *mti =dev_get_drvdata (dev); + +if (device_may_wakeup (dev)) +enable_irq_wake (mti->irq); + +return 0 ; +} + +static int __maybe_unused mt6360_tcpc_resume (struct device *dev) +{ +struct mt6360_tcpc_info *mti =dev_get_drvdata (dev); + +if (device_may_wakeup (dev)) +disable_irq_wake (mti->irq); + +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(mt6360_tcpc_pm_ops, mt6360_tcpc_suspend, mt6360_tcpc_resume); + +static const struct of_device_id __maybe_unused mt6360_tcpc_of_id[] = { + { .compatible ="mediatek,mt6360-tcpc" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, mt6360_tcpc_of_id); + +static struct platform_driver mt6360_tcpc_driver = { + .driver = { + .name ="mt6360-tcpc" , + .pm = &mt6360_tcpc_pm_ops, + .of_match_table = mt6360_tcpc_of_id, + }, + .probe = mt6360_tcpc_probe, + .remove = mt6360_tcpc_remove, +}; +module_platform_driver (mt6360_tcpc_driver); + +MODULE_AUTHOR ("ChiYuan Huang <[email protected]>" ); +MODULE_DESCRIPTION ("MT6360 USB Type-C Port Controller Interface Driver" ); +MODULE_LICENSE ("GPL v2" );
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
Guenter Roeck <[email protected]> 於 2020年8月27日 週四 下午9:46寫道:
Quoted 28 lines · 啟原黃
Quoted 17 lines
Chunfeng Yun <[email protected]> 於 2020年8月27日 週四 下午4:05寫道:
Quoted 16 lines · cy_huang
Quoted 14 lines
From: ChiYuan Huang <[email protected]>
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 <[email protected]>--- drivers/usb/typec/tcpm/Kconfig | 8 ++ drivers/usb/typec/tcpm/Makefile | 1 + drivers/usb/typec/tcpm/tcpci_mt6360.c | 213 ++++++++++++++++++++++++++++++++++Quoted 4 lines
Quoted 2 lines
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 ?
Quoted 6 lines
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.
Quoted 263 lines
Quoted 263 lines
Quoted 2 lines
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.Quoted 36 lines
Quoted 36 lines
3 files changed, 222 insertions(+) create mode 100644 drivers/usb/typec/tcpm/tcpci_mt6360.cdrivers/usb/typec/tcpm/Kconfig +8
-0@@ -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_FUSB302drivers/usb/typec/tcpm/Makefile +1
-0@@ -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.odrivers/usb/typec/tcpm/tcpci_mt6360.c new file +0
-1--- /dev/nullQuoted 8 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c line 5
Quoted 7 lines
+++
b/drivers/usb/typec/tcpm/tcpci_mt6360.cdrivers/usb/typec/tcpm/tcpci_mt6360.c new file +5
-0@@ -0,0 +1,213 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// Copyright (C) 2020 MediaTek Inc. +// +// Author: ChiYuan Huang <[email protected]> Use /* */ except SPDX?
Yes, sure.
Quoted 127 lines
Quoted 127 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +126
-0+ +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +#include <linux/usb/tcpm.h> + +#include "tcpci.h" + +#define MT6360_REG_VCONNCTRL1 0x8C +#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_ENABLE BIT(0) +/* MT6360_REG_RXCTRL2 */ +#define MT6360_OPEN40M_ENABLE BIT(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, &val,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 ,MT6360_RPONESHOT_ENABLE , +MT6360_RPONESHOT_ENABLE ); +if (ret) +return ret; + +/* Set shipping mode off, AUTOIDLE on */ +return regmap_write (regmap,MT6360_REG_MODECTRL2 ,0x7A ); +} + +static irqreturn_t mt6360_irq (int irq,void *dev_id) +{ +struct mt6360_tcpc_info *mti = dev_id; + +return tcpci_irq (mti->tcpci); +} + +static int mt6360_tcpc_probe (struct platform_device *pdev) +{ +struct mt6360_tcpc_info *mti; +int ret; + + mti =devm_kzalloc (&pdev->dev,sizeof (*mti),GFP_KERNEL ); +if (!mti) +return -ENOMEM ; + + mti->dev = &pdev->dev; + + mti->tdata.regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!mti->tdata.regmap) {Quoted 8 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c line 138
Quoted 7 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +7
-0+dev_err (&pdev->dev,"Failed to get parent regmap\n" ); +return -ENODEV ; + } + + mti->irq =platform_get_irq_byname (pdev,"PD_IRQB" ); +if (mti->irq <0 ) { +dev_err (&pdev->dev,"Failed to get PD_IRQB irq\n" );No need add error log,
platform_get_irq_bynamewill print itI'll remove it in the next revision. Thanks
Quoted 11 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c line 144
Quoted 7 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +6
-0+return mti->irq; + } + + mti->tdata.init = mt6360_tcpc_init; + mti->tcpci =tcpci_register_port (&pdev->dev, &mti->tdata); +if (IS_ERR_OR_NULL (mti->tcpci)) {Use
IS_ERR()? it seems not return NULLdrivers/usb/typec/tcpm/tcpci_mt6360.c line 146
Quoted 2 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +2
-0+dev_err (&pdev->dev,"Failed to register tcpci port\n" ); +return PTR_ERR (mti->tcpci);If return NULL, this may return 0?
Remove it later. you're right.
Quoted 15 lines
Quoted 15 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +14
-0+ } + + ret =devm_request_threaded_irq (mti->dev, mti->irq,NULL , mt6360_irq,IRQF_ONESHOT , +dev_name (&pdev->dev), mti); +if (ret) { +dev_err (mti->dev,"Failed to register irq\n" ); +tcpci_unregister_port (mti->tcpci); +return ret; + } + +device_init_wakeup (&pdev->dev, true); +platform_set_drvdata (pdev, mti); + +return 0 ;Quoted 8 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c line 167
Quoted 7 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +7
-0+} + +static int mt6360_tcpc_remove (struct platform_device *pdev) +{ +struct mt6360_tcpc_info *mti =platform_get_drvdata (pdev); + +disable_irq (mti->irq);need sync?
Yes, sync must be considered to wait interrupt is really finished. And
disable_irqalready the sync version.Quoted 40 lines
Quoted 40 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +39
-0+tcpci_unregister_port (mti->tcpci); +return 0 ; +} + +static int __maybe_unused mt6360_tcpc_suspend (struct device *dev) +{ +struct mt6360_tcpc_info *mti =dev_get_drvdata (dev); + +if (device_may_wakeup (dev)) +enable_irq_wake (mti->irq); + +return 0 ; +} + +static int __maybe_unused mt6360_tcpc_resume (struct device *dev) +{ +struct mt6360_tcpc_info *mti =dev_get_drvdata (dev); + +if (device_may_wakeup (dev)) +disable_irq_wake (mti->irq); + +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(mt6360_tcpc_pm_ops, mt6360_tcpc_suspend, mt6360_tcpc_resume); + +static const struct of_device_id __maybe_unused mt6360_tcpc_of_id[] = { + { .compatible ="mediatek,mt6360-tcpc" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, mt6360_tcpc_of_id); + +static struct platform_driver mt6360_tcpc_driver = { + .driver = { + .name ="mt6360-tcpc" , + .pm = &mt6360_tcpc_pm_ops, + .of_match_table = mt6360_tcpc_of_id, + }, + .probe = mt6360_tcpc_probe,
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c line 213
Quoted 7 lines
drivers/usb/typec/tcpm/tcpci_mt6360.c new file +7
-0+ .remove = mt6360_tcpc_remove, +}; +module_platform_driver (mt6360_tcpc_driver); + +MODULE_AUTHOR ("ChiYuan Huang <[email protected]>" ); +MODULE_DESCRIPTION ("MT6360 USB Type-C Port Controller Interface Driver" ); +MODULE_LICENSE ("GPL v2" );
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek