extcon: palmas: am57xx-beagle-x15: use palmas for VBUS/ID detection
Subsystems (3)
v2 cover extcon: palmas: am57xx-beagle-x15: use palmas for VBUS/ID detection
Hi,
am57xx-beagle-x15 uses a variant of the Palmas chip and has USB1 port's VBUS and ID connected to it.
However this Palmas variant does not support OTG ID detection but does have GPIO support on the pin where ID line is connected.
This series adds GPIO based ID detection to the Palmas extcon driver and updates am57xx-beagle-x15.dts to use Palmas for VBUS and ID detection for USB1 port.
v2:
- Add debounce-delay-ms property. Re-use enable-id-detection property to enable GPIO based ID detection based on availability of id-gpio.
cheers,
-roger
Roger Quadros (2):
extcon: palmas: Support GPIO based USB ID detection
ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2
.../devicetree/bindings/extcon/extcon-palmas.txt | 5 +- arch/arm/boot/dts/am57xx-beagle-x15.dts | 29 +++--- drivers/extcon/extcon-palmas.c | 114 ++++++++++++++++++--- include/linux/mfd/palmas.h | 6 ++ 4 files changed, 125 insertions(+), 29 deletions(-)
Signature · 1 line
2.1.4
PATCH v2 1/2 extcon: palmas: Support GPIO based USB ID detection
Some palmas based chip variants do not have OTG based ID logic. For these variants we rely on GPIO based USB ID detection.
These chips do have VBUS comparator for VBUS detection so we continue to use the old way of detecting VBUS.
--- .../devicetree/bindings/extcon/extcon-palmas.txt | 5 +- drivers/extcon/extcon-palmas.c | 114 ++++++++++++++++++--- include/linux/mfd/palmas.h | 6 ++ 3 files changed, 109 insertions(+), 16 deletions(-)
Documentation/devicetree/bindings/extcon/extcon-palmas.txt +4 -1
@@ -10,8 +10,11 @@ Required Properties: Optional Properties: - ti,wakeup : To enable the wakeup comparator in probe - - ti,enable-id-detection: Perform ID detection. + - ti,enable-id-detection: Perform ID detection. If id-gpio is specified + it performs id-detection using GPIO else using OTG core. - ti,enable-vbus-detection: Perform VBUS detection. + - id-gpio: gpio for GPIO ID detection. See gpio binding. + - debounce-delay-ms: debounce delay for GPIO ID pin in milliseconds. palmas-usb { compatible = "ti,twl6035-usb", "ti,palmas-usb";
drivers/extcon/extcon-palmas.c +99 -15
177 lines not on this page · raw message
include/linux/mfd/palmas.h +6 -0
@@ -21,6 +21,7 @@#include <linux/regmap.h> #include <linux/regulator/driver.h> #include <linux/extcon.h> +#include <linux/of_gpio.h> #include <linux/usb/phy_companion.h> #define PALMAS_NUM_CLIENTS 3
@@ -551,10 +552,15 @@ struct palmas_usb {int vbus_otg_irq;int vbus_irq; +int gpio_id_irq; +struct gpio_desc *id_gpiod; +int sw_debounce_ms; +enum palmas_usb_state linkstat;int wakeup;bool enable_vbus_detection;bool enable_id_detection; +bool enable_gpio_id_detection; };#define comparator_to_palmas (x) container_of((x), struct palmas_usb, comparator)
Signature · 1 line
2.1.4
Chanwoo Choi
maintainerRe: [PATCH v2 1/2] extcon: palmas: Support GPIO based USB ID detection
Hi Roger,
When I apply it for build test, merge conflict happen. So, I recommend that you rebase this patchset on extcon-next branch.
Quoted 49 lines · Roger Quadros
Some palmas based chip variants do not have OTG based ID logic. For these variants we rely on GPIO based USB ID detection.
These chips do have VBUS comparator for VBUS detection so we continue to use the old way of detecting VBUS.
Signed-off-by Roger Quadros <[email protected]>--- .../devicetree/bindings/extcon/extcon-palmas.txt | 5 +- drivers/extcon/extcon-palmas.c | 114 ++++++++++++++++++--- include/linux/mfd/palmas.h | 6 ++ 3 files changed, 109 insertions(+), 16 deletions(-)Documentation/devicetree/bindings/extcon/extcon-palmas.txt +4
-1@@ -10,8 +10,11 @@ Required Properties: Optional Properties: - ti,wakeup : To enable the wakeup comparator in probe - - ti,enable-id-detection: Perform ID detection. + - ti,enable-id-detection: Perform ID detection. If id-gpio is specified + it performs id-detection using GPIO else using OTG core. - ti,enable-vbus-detection: Perform VBUS detection. + - id-gpio: gpio for GPIO ID detection. See gpio binding. + - debounce-delay-ms: debounce delay for GPIO ID pin in milliseconds. palmas-usb { compatible = "ti,twl6035-usb", "ti,palmas-usb";drivers/extcon/extcon-palmas.c +4
-0@@ -28,6 +28,9 @@#include <linux/mfd/palmas.h> #include <linux/of.h> #include <linux/of_platform.h> +#include <linux/of_gpio.h> + +#define USB_GPIO_DEBOUNCE_MS 20/* ms */ static const unsigned int palmas_extcon_cable[] = {EXTCON_USB ,@@ -120,19 +123,52 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)return IRQ_HANDLED ; } +static void palmas_gpio_id_detect (struct palmas_usb *palmas_usb)
drivers/extcon/extcon-palmas.c static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb) · line 136
Quoted 10 lines
drivers/extcon/extcon-palmas.c +10
-0+{ +int id; + +if (!palmas_usb->id_gpiod) +return ; + + id =gpiod_get_value_cansleep (palmas_usb->id_gpiod); + +if (id) { +extcon_set_cable_state (palmas_usb->edev,"USB-HOST" , false);
Use the extcon_set_cable_state_() because extcon_set_cable_state() with cable name is deprecated.
drivers/extcon/extcon-palmas.c static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb) · line 139
Quoted 3 lines
drivers/extcon/extcon-palmas.c +3
-0+dev_info (palmas_usb->dev,"USB-HOST cable is detached\n" ); + }else { +extcon_set_cable_state (palmas_usb->edev,"USB-HOST" , true);
ditto. Use the extcon_set_cable_state_() with extcon id.
[snip]
Thanks,
Chanwoo Choi
Re: [PATCH v2 1/2] extcon: palmas: Support GPIO based USB ID detection
Hi Chanwoo,
Quoted 4 lines · Chanwoo Choi
Hi Roger,
When I apply it for build test, merge conflict happen. So, I recommend that you rebase this patchset on extcon-next branch.
Alright.
Quoted 50 lines · Roger Quadros
Quoted 48 lines
Some palmas based chip variants do not have OTG based ID logic. For these variants we rely on GPIO based USB ID detection.
These chips do have VBUS comparator for VBUS detection so we continue to use the old way of detecting VBUS.
Signed-off-by Roger Quadros <[email protected]>--- .../devicetree/bindings/extcon/extcon-palmas.txt | 5 +- drivers/extcon/extcon-palmas.c | 114 ++++++++++++++++++--- include/linux/mfd/palmas.h | 6 ++ 3 files changed, 109 insertions(+), 16 deletions(-)Documentation/devicetree/bindings/extcon/extcon-palmas.txt +4
-1@@ -10,8 +10,11 @@ Required Properties: Optional Properties: - ti,wakeup : To enable the wakeup comparator in probe - - ti,enable-id-detection: Perform ID detection. + - ti,enable-id-detection: Perform ID detection. If id-gpio is specified + it performs id-detection using GPIO else using OTG core. - ti,enable-vbus-detection: Perform VBUS detection. + - id-gpio: gpio for GPIO ID detection. See gpio binding. + - debounce-delay-ms: debounce delay for GPIO ID pin in milliseconds. palmas-usb { compatible = "ti,twl6035-usb", "ti,palmas-usb";drivers/extcon/extcon-palmas.c +3
-0@@ -28,6 +28,9 @@#include <linux/mfd/palmas.h> #include <linux/of.h> #include <linux/of_platform.h> +#include <linux/of_gpio.h> + +#define USB_GPIO_DEBOUNCE_MS 20/* ms */ static const unsigned int palmas_extcon_cable[] = {EXTCON_USB ,@@ -120,19 +123,52 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)return IRQ_HANDLED ; }
Quoted 14 lines
drivers/extcon/extcon-palmas.c static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb) · line 136
Quoted 11 lines
drivers/extcon/extcon-palmas.c +11
-0+static void palmas_gpio_id_detect (struct palmas_usb *palmas_usb) +{ +int id; + +if (!palmas_usb->id_gpiod) +return ; + + id =gpiod_get_value_cansleep (palmas_usb->id_gpiod); + +if (id) { +extcon_set_cable_state (palmas_usb->edev,"USB-HOST" , false);Use the
extcon_set_cable_state_()becauseextcon_set_cable_state()with cable name is deprecated.
OK.
cheers,
-roger
Quoted 12 lines
drivers/extcon/extcon-palmas.c static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb) · line 139
Quoted 4 lines
drivers/extcon/extcon-palmas.c +3
-0+dev_info (palmas_usb->dev,"USB-HOST cable is detached\n" ); + }else { +extcon_set_cable_state (palmas_usb->edev,"USB-HOST" , true);ditto. Use the
extcon_set_cable_state_()with extcon id.[snip]
Thanks,
Chanwoo Choi
PATCH v3 1/2 extcon: palmas: Support GPIO based USB ID detection
In reply to Roger QuadrosSome palmas based chip variants do not have OTG based ID logic. For these variants we rely on GPIO based USB ID detection.
These chips do have VBUS comparator for VBUS detection so we continue to use the old way of detecting VBUS.
---
v3:
-rebased on extcon-next.
-don't use deperecated name based extcon_set_cable_state()
.../devicetree/bindings/extcon/extcon-palmas.txt | 5 +- drivers/extcon/extcon-palmas.c | 115 ++++++++++++++++++--- include/linux/mfd/palmas.h | 6 ++ 3 files changed, 110 insertions(+), 16 deletions(-)
Documentation/devicetree/bindings/extcon/extcon-palmas.txt +4 -1
@@ -10,8 +10,11 @@ Required Properties: Optional Properties: - ti,wakeup : To enable the wakeup comparator in probe - - ti,enable-id-detection: Perform ID detection. + - ti,enable-id-detection: Perform ID detection. If id-gpio is specified + it performs id-detection using GPIO else using OTG core. - ti,enable-vbus-detection: Perform VBUS detection. + - id-gpio: gpio for GPIO ID detection. See gpio binding. + - debounce-delay-ms: debounce delay for GPIO ID pin in milliseconds. palmas-usb { compatible = "ti,twl6035-usb", "ti,palmas-usb";
drivers/extcon/extcon-palmas.c +100 -15
178 lines not on this page · raw message
include/linux/mfd/palmas.h +6 -0
@@ -21,6 +21,7 @@#include <linux/regmap.h> #include <linux/regulator/driver.h> #include <linux/extcon.h> +#include <linux/of_gpio.h> #include <linux/usb/phy_companion.h> #define PALMAS_NUM_CLIENTS 3
@@ -551,10 +552,15 @@ struct palmas_usb {int vbus_otg_irq;int vbus_irq; +int gpio_id_irq; +struct gpio_desc *id_gpiod; +int sw_debounce_ms; +enum palmas_usb_state linkstat;int wakeup;bool enable_vbus_detection;bool enable_id_detection; +bool enable_gpio_id_detection; };#define comparator_to_palmas (x) container_of((x), struct palmas_usb, comparator)
Signature · 1 line
2.1.4
Re: [PATCH v3 1/2] extcon: palmas: Support GPIO based USB ID detection
Hi Roger,
Looks good to me. But, I add one comment about mdelay. If you modify it, you can add my acked-by message.
Also, You must recevie the ack message from MFD maintainer (Lee Jones).
Quoted 68 lines · Roger Quadros
Some palmas based chip variants do not have OTG based ID logic. For these variants we rely on GPIO based USB ID detection.
These chips do have VBUS comparator for VBUS detection so we continue to use the old way of detecting VBUS.
Signed-off-by Roger Quadros <[email protected]>---
v3:
(quoted diff) +0
-2-rebased on extcon-next. -don't use deperecated name based extcon_set_cable_state() .../devicetree/bindings/extcon/extcon-palmas.txt | 5 +- drivers/extcon/extcon-palmas.c | 115 ++++++++++++++++++--- include/linux/mfd/palmas.h | 6 ++ 3 files changed, 110 insertions(+), 16 deletions(-)Documentation/devicetree/bindings/extcon/extcon-palmas.txt +4
-1@@ -10,8 +10,11 @@ Required Properties: Optional Properties: - ti,wakeup : To enable the wakeup comparator in probe - - ti,enable-id-detection: Perform ID detection. + - ti,enable-id-detection: Perform ID detection. If id-gpio is specified + it performs id-detection using GPIO else using OTG core. - ti,enable-vbus-detection: Perform VBUS detection. + - id-gpio: gpio for GPIO ID detection. See gpio binding. + - debounce-delay-ms: debounce delay for GPIO ID pin in milliseconds. palmas-usb { compatible = "ti,twl6035-usb", "ti,palmas-usb";drivers/extcon/extcon-palmas.c +18
-0@@ -28,6 +28,9 @@#include <linux/mfd/palmas.h> #include <linux/of.h> #include <linux/of_platform.h> +#include <linux/of_gpio.h> + +#define USB_GPIO_DEBOUNCE_MS 20/* ms */ static const unsigned int palmas_extcon_cable[] = {EXTCON_USB ,@@ -118,19 +121,53 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)return IRQ_HANDLED ; } +static void palmas_gpio_id_detect (struct palmas_usb *palmas_usb) +{ +int id; +struct extcon_dev *edev = palmas_usb->edev; + +if (!palmas_usb->id_gpiod) +return ; + + id =gpiod_get_value_cansleep (palmas_usb->id_gpiod); + +if (id) { +extcon_set_cable_state_ (edev,EXTCON_USB_HOST , false); +dev_info (palmas_usb->dev,"USB-HOST cable is detached\n" ); + }else { +extcon_set_cable_state_ (edev,EXTCON_USB_HOST , true);
drivers/extcon/extcon-palmas.c static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb) · line 148
Quoted 10 lines
drivers/extcon/extcon-palmas.c +10
-0+dev_info (palmas_usb->dev,"USB-HOST cable is attached\n" ); + } +} + +static irqreturn_t palmas_gpio_id_irq_handler (int irq,void *_palmas_usb) +{ +struct palmas_usb *palmas_usb = _palmas_usb; + +if (palmas_usb->sw_debounce_ms) +mdelay (palmas_usb->sw_debounce_ms);
I recommend that you use the workqueue instead of mdelay(). If using the mdelay(), CPU is busy waiting for sw_debounce_ms.
- you can refer the drivers/extcon/extcon-usb-gpio.c
Quoted 165 lines
drivers/extcon/extcon-palmas.c +72
-15+ +palmas_gpio_id_detect (palmas_usb); + +return IRQ_HANDLED ; +} +static void palmas_enable_irq (struct palmas_usb *palmas_usb) {palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE ,PALMAS_USB_VBUS_CTRL_SET ,PALMAS_USB_VBUS_CTRL_SET_VBUS_ACT_COMP ); -palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE , -PALMAS_USB_ID_CTRL_SET ,PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP ); +if (palmas_usb->enable_id_detection) { +palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE , +PALMAS_USB_ID_CTRL_SET , +PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP ); -palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE , -PALMAS_USB_ID_INT_EN_HI_SET , -PALMAS_USB_ID_INT_EN_HI_SET_ID_GND | -PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT ); +palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE , +PALMAS_USB_ID_INT_EN_HI_SET , +PALMAS_USB_ID_INT_EN_HI_SET_ID_GND | +PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT ); + }if (palmas_usb->enable_vbus_detection)palmas_vbus_irq_handler (palmas_usb->vbus_irq, palmas_usb);@@ -169,20 +206,34 @@ static int palmas_usb_probe(struct platform_device *pdev) palmas_usb->wakeup = pdata->wakeup; } + palmas_usb->id_gpiod =devm_gpiod_get_optional (&pdev->dev,"id" ); +if (IS_ERR (palmas_usb->id_gpiod)) { +dev_err (&pdev->dev,"failed to get id gpio\n" ); +return PTR_ERR (palmas_usb->id_gpiod); + } + +if (palmas_usb->enable_id_detection && palmas_usb->id_gpiod) { + palmas_usb->enable_id_detection = false; + palmas_usb->enable_gpio_id_detection = true; + } + +if (palmas_usb->enable_gpio_id_detection) { +u32 debounce; + +if (of_property_read_u32 (node,"debounce-delay-ms" , &debounce)) + debounce =USB_GPIO_DEBOUNCE_MS ; + + status =gpiod_set_debounce (palmas_usb->id_gpiod, + debounce *1000 ); +if (status <0 ) + palmas_usb->sw_debounce_ms = debounce; + } + palmas->usb = palmas_usb; palmas_usb->palmas = palmas; palmas_usb->dev = &pdev->dev; - palmas_usb->id_otg_irq =regmap_irq_get_virq (palmas->irq_data, -PALMAS_ID_OTG_IRQ ); - palmas_usb->id_irq =regmap_irq_get_virq (palmas->irq_data, -PALMAS_ID_IRQ ); - palmas_usb->vbus_otg_irq =regmap_irq_get_virq (palmas->irq_data, -PALMAS_VBUS_OTG_IRQ ); - palmas_usb->vbus_irq =regmap_irq_get_virq (palmas->irq_data, -PALMAS_VBUS_IRQ ); -palmas_usb_wakeup (palmas, palmas_usb->wakeup);platform_set_drvdata (pdev, palmas_usb);@@ -201,6 +252,10 @@ static int palmas_usb_probe(struct platform_device *pdev) }if (palmas_usb->enable_id_detection) { + palmas_usb->id_otg_irq =regmap_irq_get_virq (palmas->irq_data, +PALMAS_ID_OTG_IRQ ); + palmas_usb->id_irq =regmap_irq_get_virq (palmas->irq_data, +PALMAS_ID_IRQ ); status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->id_irq, NULL, palmas_id_irq_handler,@@ -212,9 +267,33 @@ static int palmas_usb_probe(struct platform_device *pdev) palmas_usb->id_irq, status);return status; } + }else if (palmas_usb->enable_gpio_id_detection) { + palmas_usb->gpio_id_irq =gpiod_to_irq (palmas_usb->id_gpiod); +if (palmas_usb->gpio_id_irq <0 ) { +dev_err (&pdev->dev,"failed to get id irq\n" ); +return palmas_usb->gpio_id_irq; + } + status =devm_request_threaded_irq (&pdev->dev, + palmas_usb->gpio_id_irq, +NULL , + palmas_gpio_id_irq_handler, +IRQF_TRIGGER_RISING | +IRQF_TRIGGER_FALLING | +IRQF_ONESHOT , +"palmas_usb_id" , + palmas_usb); +if (status <0 ) { +dev_err (&pdev->dev, +"failed to request handler for id irq\n" ); +return status; + } }if (palmas_usb->enable_vbus_detection) { + palmas_usb->vbus_otg_irq =regmap_irq_get_virq (palmas->irq_data, +PALMAS_VBUS_OTG_IRQ ); + palmas_usb->vbus_irq =regmap_irq_get_virq (palmas->irq_data, +PALMAS_VBUS_IRQ ); status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->vbus_irq, NULL, palmas_vbus_irq_handler,@@ -229,6 +308,8 @@ static int palmas_usb_probe(struct platform_device *pdev) }palmas_enable_irq (palmas_usb); +/* perform initial detection */ +palmas_gpio_id_detect (palmas_usb);device_set_wakeup_capable (&pdev->dev, true);return 0 ; }@@ -243,6 +324,8 @@ static int palmas_usb_suspend(struct device *dev)enable_irq_wake (palmas_usb->vbus_irq);if (palmas_usb->enable_id_detection)enable_irq_wake (palmas_usb->id_irq); +if (palmas_usb->enable_gpio_id_detection) +enable_irq_wake (palmas_usb->gpio_id_irq); }return 0 ; }@@ -256,6 +339,8 @@ static int palmas_usb_resume(struct device *dev)disable_irq_wake (palmas_usb->vbus_irq);if (palmas_usb->enable_id_detection)disable_irq_wake (palmas_usb->id_irq); +if (palmas_usb->enable_gpio_id_detection) +disable_irq_wake (palmas_usb->gpio_id_irq); }return 0 ; };include/linux/mfd/palmas.h +3
-0@@ -21,6 +21,7 @@#include <linux/regmap.h> #include <linux/regulator/driver.h> #include <linux/extcon.h> +#include <linux/of_gpio.h> #include <linux/usb/phy_companion.h> #define PALMAS_NUM_CLIENTS 3@@ -551,10 +552,15 @@ struct palmas_usb {int vbus_otg_irq;int vbus_irq; +int gpio_id_irq; +struct gpio_desc *id_gpiod;
include/linux/mfd/palmas.h struct palmas_usb { · line 566
Quoted 10 lines
include/linux/mfd/palmas.h +3
-0+int sw_debounce_ms; +enum palmas_usb_state linkstat;int wakeup;bool enable_vbus_detection;bool enable_id_detection; +bool enable_gpio_id_detection; };#define comparator_to_palmas (x) container_of((x), struct palmas_usb, comparator)
Thanks,
Chanwoo Choi
PATCH v4 1/2 extcon: palmas: Support GPIO based USB ID detection
In reply to Roger QuadrosSome palmas based chip variants do not have OTG based ID logic. For these variants we rely on GPIO based USB ID detection.
These chips do have VBUS comparator for VBUS detection so we continue to use the old way of detecting VBUS.
---
v4: updated gpio debounce logic to use delayed_workqueue.
.../devicetree/bindings/extcon/extcon-palmas.txt | 5 +- drivers/extcon/extcon-palmas.c | 129 ++++++++++++++++++--- drivers/extcon/extcon-usb-gpio.c | 1 + include/linux/mfd/palmas.h | 7 ++ 4 files changed, 126 insertions(+), 16 deletions(-)
Documentation/devicetree/bindings/extcon/extcon-palmas.txt +4 -1
@@ -10,8 +10,11 @@ Required Properties: Optional Properties: - ti,wakeup : To enable the wakeup comparator in probe - - ti,enable-id-detection: Perform ID detection. + - ti,enable-id-detection: Perform ID detection. If id-gpio is specified + it performs id-detection using GPIO else using OTG core. - ti,enable-vbus-detection: Perform VBUS detection. + - id-gpio: gpio for GPIO ID detection. See gpio binding. + - debounce-delay-ms: debounce delay for GPIO ID pin in milliseconds. palmas-usb { compatible = "ti,twl6035-usb", "ti,palmas-usb";
drivers/extcon/extcon-palmas.c +114 -15
202 lines not on this page · raw message
drivers/extcon/extcon-usb-gpio.c +1 -0
@@ -15,6 +15,7 @@*/ #include <linux/extcon.h> +#include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/init.h> #include <linux/interrupt.h>
include/linux/mfd/palmas.h +7 -0
@@ -21,6 +21,7 @@#include <linux/regmap.h> #include <linux/regulator/driver.h> #include <linux/extcon.h> +#include <linux/of_gpio.h> #include <linux/usb/phy_companion.h> #define PALMAS_NUM_CLIENTS 3
@@ -551,10 +552,16 @@ struct palmas_usb {int vbus_otg_irq;int vbus_irq; +int gpio_id_irq; +struct gpio_desc *id_gpiod; +unsigned long sw_debounce_jiffies; +struct delayed_work wq_detectid; +enum palmas_usb_state linkstat;int wakeup;bool enable_vbus_detection;bool enable_id_detection; +bool enable_gpio_id_detection; };#define comparator_to_palmas (x) container_of((x), struct palmas_usb, comparator)
Signature · 1 line
2.1.4
Re: [PATCH v4 1/2] extcon: palmas: Support GPIO based USB ID detection
Hi Lee / Samuel,
Quoted 8 lines · Roger Quadros
Some palmas based chip variants do not have OTG based ID logic. For these variants we rely on GPIO based USB ID detection.
These chips do have VBUS comparator for VBUS detection so we continue to use the old way of detecting VBUS.
Acked-by Chanwoo Choi <[email protected]>Signed-off-by Roger Quadros <[email protected]>
It seems the extcon maintainer Chanwoo needs either of your Ack to accept this patch.
Can you please take a look and Ack if OK? Thanks.
cheers,
-roger
Quoted 283 lines
---
v4: updated gpio debounce logic to usedelayed_workqueue..../devicetree/bindings/extcon/extcon-palmas.txt | 5 +- drivers/extcon/extcon-palmas.c | 129 ++++++++++++++++++--- drivers/extcon/extcon-usb-gpio.c | 1 + include/linux/mfd/palmas.h | 7 ++ 4 files changed, 126 insertions(+), 16 deletions(-)Documentation/devicetree/bindings/extcon/extcon-palmas.txt +4
-1@@ -10,8 +10,11 @@ Required Properties: Optional Properties: - ti,wakeup : To enable the wakeup comparator in probe - - ti,enable-id-detection: Perform ID detection. + - ti,enable-id-detection: Perform ID detection. If id-gpio is specified + it performs id-detection using GPIO else using OTG core. - ti,enable-vbus-detection: Perform VBUS detection. + - id-gpio: gpio for GPIO ID detection. See gpio binding. + - debounce-delay-ms: debounce delay for GPIO ID pin in milliseconds. palmas-usb { compatible = "ti,twl6035-usb", "ti,palmas-usb";drivers/extcon/extcon-palmas.c +114
-15@@ -28,6 +28,10 @@#include <linux/mfd/palmas.h> #include <linux/of.h> #include <linux/of_platform.h> +#include <linux/of_gpio.h> +#include <linux/workqueue.h> + +#define USB_GPIO_DEBOUNCE_MS 20/* ms */ static const unsigned int palmas_extcon_cable[] = {EXTCON_USB ,@@ -118,19 +122,54 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)return IRQ_HANDLED ; } +static void palmas_gpio_id_detect (struct work_struct *work) +{ +int id; +struct palmas_usb *palmas_usb =container_of (to_delayed_work (work), + struct palmas_usb, + wq_detectid); +struct extcon_dev *edev = palmas_usb->edev; + +if (!palmas_usb->id_gpiod) +return ; + + id =gpiod_get_value_cansleep (palmas_usb->id_gpiod); + +if (id) { +extcon_set_cable_state_ (edev,EXTCON_USB_HOST , false); +dev_info (palmas_usb->dev,"USB-HOST cable is detached\n" ); + }else { +extcon_set_cable_state_ (edev,EXTCON_USB_HOST , true); +dev_info (palmas_usb->dev,"USB-HOST cable is attached\n" ); + } +} + +static irqreturn_t palmas_gpio_id_irq_handler (int irq,void *_palmas_usb) +{ +struct palmas_usb *palmas_usb = _palmas_usb; + +queue_delayed_work (system_power_efficient_wq, &palmas_usb->wq_detectid, + palmas_usb->sw_debounce_jiffies); + +return IRQ_HANDLED ; +} +static void palmas_enable_irq (struct palmas_usb *palmas_usb) {palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE ,PALMAS_USB_VBUS_CTRL_SET ,PALMAS_USB_VBUS_CTRL_SET_VBUS_ACT_COMP ); -palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE , -PALMAS_USB_ID_CTRL_SET ,PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP ); +if (palmas_usb->enable_id_detection) { +palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE , +PALMAS_USB_ID_CTRL_SET , +PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP ); -palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE , -PALMAS_USB_ID_INT_EN_HI_SET , -PALMAS_USB_ID_INT_EN_HI_SET_ID_GND | -PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT ); +palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE , +PALMAS_USB_ID_INT_EN_HI_SET , +PALMAS_USB_ID_INT_EN_HI_SET_ID_GND | +PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT ); + }if (palmas_usb->enable_vbus_detection)palmas_vbus_irq_handler (palmas_usb->vbus_irq, palmas_usb);@@ -169,20 +208,36 @@ static int palmas_usb_probe(struct platform_device *pdev) palmas_usb->wakeup = pdata->wakeup; } + palmas_usb->id_gpiod =devm_gpiod_get_optional (&pdev->dev,"id" ); +if (IS_ERR (palmas_usb->id_gpiod)) { +dev_err (&pdev->dev,"failed to get id gpio\n" ); +return PTR_ERR (palmas_usb->id_gpiod); + } + +if (palmas_usb->enable_id_detection && palmas_usb->id_gpiod) { + palmas_usb->enable_id_detection = false; + palmas_usb->enable_gpio_id_detection = true; + } + +if (palmas_usb->enable_gpio_id_detection) { +u32 debounce; + +if (of_property_read_u32 (node,"debounce-delay-ms" , &debounce)) + debounce =USB_GPIO_DEBOUNCE_MS ; + + status =gpiod_set_debounce (palmas_usb->id_gpiod, + debounce *1000 ); +if (status <0 ) + palmas_usb->sw_debounce_jiffies =msecs_to_jiffies (debounce); + } + +INIT_DELAYED_WORK (&palmas_usb->wq_detectid, palmas_gpio_id_detect); + palmas->usb = palmas_usb; palmas_usb->palmas = palmas; palmas_usb->dev = &pdev->dev; - palmas_usb->id_otg_irq =regmap_irq_get_virq (palmas->irq_data, -PALMAS_ID_OTG_IRQ ); - palmas_usb->id_irq =regmap_irq_get_virq (palmas->irq_data, -PALMAS_ID_IRQ ); - palmas_usb->vbus_otg_irq =regmap_irq_get_virq (palmas->irq_data, -PALMAS_VBUS_OTG_IRQ ); - palmas_usb->vbus_irq =regmap_irq_get_virq (palmas->irq_data, -PALMAS_VBUS_IRQ ); -palmas_usb_wakeup (palmas, palmas_usb->wakeup);platform_set_drvdata (pdev, palmas_usb);@@ -201,6 +256,10 @@ static int palmas_usb_probe(struct platform_device *pdev) }if (palmas_usb->enable_id_detection) { + palmas_usb->id_otg_irq =regmap_irq_get_virq (palmas->irq_data, +PALMAS_ID_OTG_IRQ ); + palmas_usb->id_irq =regmap_irq_get_virq (palmas->irq_data, +PALMAS_ID_IRQ ); status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->id_irq, NULL, palmas_id_irq_handler,@@ -212,9 +271,33 @@ static int palmas_usb_probe(struct platform_device *pdev) palmas_usb->id_irq, status);return status; } + }else if (palmas_usb->enable_gpio_id_detection) { + palmas_usb->gpio_id_irq =gpiod_to_irq (palmas_usb->id_gpiod); +if (palmas_usb->gpio_id_irq <0 ) { +dev_err (&pdev->dev,"failed to get id irq\n" ); +return palmas_usb->gpio_id_irq; + } + status =devm_request_threaded_irq (&pdev->dev, + palmas_usb->gpio_id_irq, +NULL , + palmas_gpio_id_irq_handler, +IRQF_TRIGGER_RISING | +IRQF_TRIGGER_FALLING | +IRQF_ONESHOT , +"palmas_usb_id" , + palmas_usb); +if (status <0 ) { +dev_err (&pdev->dev, +"failed to request handler for id irq\n" ); +return status; + } }if (palmas_usb->enable_vbus_detection) { + palmas_usb->vbus_otg_irq =regmap_irq_get_virq (palmas->irq_data, +PALMAS_VBUS_OTG_IRQ ); + palmas_usb->vbus_irq =regmap_irq_get_virq (palmas->irq_data, +PALMAS_VBUS_IRQ ); status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->vbus_irq, NULL, palmas_vbus_irq_handler,@@ -229,10 +312,21 @@ static int palmas_usb_probe(struct platform_device *pdev) }palmas_enable_irq (palmas_usb); +/* perform initial detection */ +palmas_gpio_id_detect (&palmas_usb->wq_detectid.work);device_set_wakeup_capable (&pdev->dev, true);return 0 ; } +static int palmas_usb_remove (struct platform_device *pdev) +{ +struct palmas_usb *palmas_usb =platform_get_drvdata (pdev); + +cancel_delayed_work_sync (&palmas_usb->wq_detectid); + +return 0 ; +} +#ifdef CONFIG_PM_SLEEP static int palmas_usb_suspend (struct device *dev) {@@ -243,6 +337,8 @@ static int palmas_usb_suspend(struct device *dev)enable_irq_wake (palmas_usb->vbus_irq);if (palmas_usb->enable_id_detection)enable_irq_wake (palmas_usb->id_irq); +if (palmas_usb->enable_gpio_id_detection) +enable_irq_wake (palmas_usb->gpio_id_irq); }return 0 ; }@@ -256,6 +352,8 @@ static int palmas_usb_resume(struct device *dev)disable_irq_wake (palmas_usb->vbus_irq);if (palmas_usb->enable_id_detection)disable_irq_wake (palmas_usb->id_irq); +if (palmas_usb->enable_gpio_id_detection) +disable_irq_wake (palmas_usb->gpio_id_irq); }return 0 ; };@@ -273,6 +371,7 @@ static const struct of_device_id of_palmas_match_tbl[] = {static struct platform_driver palmas_usb_driver = { .probe = palmas_usb_probe, + .remove = palmas_usb_remove, .driver = { .name ="palmas-usb" , .of_match_table = of_palmas_match_tbl,drivers/extcon/extcon-usb-gpio.c +1
-0@@ -15,6 +15,7 @@*/ #include <linux/extcon.h> +#include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/init.h> #include <linux/interrupt.h> include/linux/mfd/palmas.h +7
-0@@ -21,6 +21,7 @@#include <linux/regmap.h> #include <linux/regulator/driver.h> #include <linux/extcon.h> +#include <linux/of_gpio.h> #include <linux/usb/phy_companion.h> #define PALMAS_NUM_CLIENTS 3@@ -551,10 +552,16 @@ struct palmas_usb {int vbus_otg_irq;int vbus_irq; +int gpio_id_irq; +struct gpio_desc *id_gpiod; +unsigned long sw_debounce_jiffies; +struct delayed_work wq_detectid; +enum palmas_usb_state linkstat;int wakeup;bool enable_vbus_detection;bool enable_id_detection; +bool enable_gpio_id_detection; };#define comparator_to_palmas (x) container_of((x), struct palmas_usb, comparator)
Chanwoo Choi
maintainerRe: [PATCH v4 1/2] extcon: palmas: Support GPIO based USB ID detection
Hi Lee,
This patch modified the header file in the MFD directory (include/linux/mfd/palmas.h). After you review this patch, I'll apply it on extcon-next and sent the pull request for Linux 4.3.
Thanks,
Chanwoo Choi
Quoted 309 lines · Roger Quadros
Hi Lee / Samuel,
Quoted 8 lines · Roger Quadros
Some palmas based chip variants do not have OTG based ID logic. For these variants we rely on GPIO based USB ID detection.
These chips do have VBUS comparator for VBUS detection so we continue to use the old way of detecting VBUS.
Acked-by Chanwoo Choi <[email protected]>Signed-off-by Roger Quadros <[email protected]>It seems the extcon maintainer Chanwoo needs either of your Ack to accept this patch.
Can you please take a look and Ack if OK? Thanks.
cheers,
-rogerQuoted 273 lines
---
v4: updated gpio debounce logic to usedelayed_workqueue..../devicetree/bindings/extcon/extcon-palmas.txt | 5 +- drivers/extcon/extcon-palmas.c | 129 ++++++++++++++++++--- drivers/extcon/extcon-usb-gpio.c | 1 + include/linux/mfd/palmas.h | 7 ++ 4 files changed, 126 insertions(+), 16 deletions(-)Documentation/devicetree/bindings/extcon/extcon-palmas.txt +4
-1@@ -10,8 +10,11 @@ Required Properties: Optional Properties: - ti,wakeup : To enable the wakeup comparator in probe - - ti,enable-id-detection: Perform ID detection. + - ti,enable-id-detection: Perform ID detection. If id-gpio is specified + it performs id-detection using GPIO else using OTG core. - ti,enable-vbus-detection: Perform VBUS detection. + - id-gpio: gpio for GPIO ID detection. See gpio binding. + - debounce-delay-ms: debounce delay for GPIO ID pin in milliseconds. palmas-usb { compatible = "ti,twl6035-usb", "ti,palmas-usb";drivers/extcon/extcon-palmas.c +114
-15@@ -28,6 +28,10 @@#include <linux/mfd/palmas.h> #include <linux/of.h> #include <linux/of_platform.h> +#include <linux/of_gpio.h> +#include <linux/workqueue.h> + +#define USB_GPIO_DEBOUNCE_MS 20/* ms */ static const unsigned int palmas_extcon_cable[] = {EXTCON_USB ,@@ -118,19 +122,54 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)return IRQ_HANDLED ; } +static void palmas_gpio_id_detect (struct work_struct *work) +{ +int id; +struct palmas_usb *palmas_usb =container_of (to_delayed_work (work), + struct palmas_usb, + wq_detectid); +struct extcon_dev *edev = palmas_usb->edev; + +if (!palmas_usb->id_gpiod) +return ; + + id =gpiod_get_value_cansleep (palmas_usb->id_gpiod); + +if (id) { +extcon_set_cable_state_ (edev,EXTCON_USB_HOST , false); +dev_info (palmas_usb->dev,"USB-HOST cable is detached\n" ); + }else { +extcon_set_cable_state_ (edev,EXTCON_USB_HOST , true); +dev_info (palmas_usb->dev,"USB-HOST cable is attached\n" ); + } +} + +static irqreturn_t palmas_gpio_id_irq_handler (int irq,void *_palmas_usb) +{ +struct palmas_usb *palmas_usb = _palmas_usb; + +queue_delayed_work (system_power_efficient_wq, &palmas_usb->wq_detectid, + palmas_usb->sw_debounce_jiffies); + +return IRQ_HANDLED ; +} +static void palmas_enable_irq (struct palmas_usb *palmas_usb) {palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE ,PALMAS_USB_VBUS_CTRL_SET ,PALMAS_USB_VBUS_CTRL_SET_VBUS_ACT_COMP ); -palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE , -PALMAS_USB_ID_CTRL_SET ,PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP ); +if (palmas_usb->enable_id_detection) { +palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE , +PALMAS_USB_ID_CTRL_SET , +PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP ); -palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE , -PALMAS_USB_ID_INT_EN_HI_SET , -PALMAS_USB_ID_INT_EN_HI_SET_ID_GND | -PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT ); +palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE , +PALMAS_USB_ID_INT_EN_HI_SET , +PALMAS_USB_ID_INT_EN_HI_SET_ID_GND | +PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT ); + }if (palmas_usb->enable_vbus_detection)palmas_vbus_irq_handler (palmas_usb->vbus_irq, palmas_usb);@@ -169,20 +208,36 @@ static int palmas_usb_probe(struct platform_device *pdev) palmas_usb->wakeup = pdata->wakeup; } + palmas_usb->id_gpiod =devm_gpiod_get_optional (&pdev->dev,"id" ); +if (IS_ERR (palmas_usb->id_gpiod)) { +dev_err (&pdev->dev,"failed to get id gpio\n" ); +return PTR_ERR (palmas_usb->id_gpiod); + } + +if (palmas_usb->enable_id_detection && palmas_usb->id_gpiod) { + palmas_usb->enable_id_detection = false; + palmas_usb->enable_gpio_id_detection = true; + } + +if (palmas_usb->enable_gpio_id_detection) { +u32 debounce; + +if (of_property_read_u32 (node,"debounce-delay-ms" , &debounce)) + debounce =USB_GPIO_DEBOUNCE_MS ; + + status =gpiod_set_debounce (palmas_usb->id_gpiod, + debounce *1000 ); +if (status <0 ) + palmas_usb->sw_debounce_jiffies =msecs_to_jiffies (debounce); + } + +INIT_DELAYED_WORK (&palmas_usb->wq_detectid, palmas_gpio_id_detect); + palmas->usb = palmas_usb; palmas_usb->palmas = palmas; palmas_usb->dev = &pdev->dev; - palmas_usb->id_otg_irq =regmap_irq_get_virq (palmas->irq_data, -PALMAS_ID_OTG_IRQ ); - palmas_usb->id_irq =regmap_irq_get_virq (palmas->irq_data, -PALMAS_ID_IRQ ); - palmas_usb->vbus_otg_irq =regmap_irq_get_virq (palmas->irq_data, -PALMAS_VBUS_OTG_IRQ ); - palmas_usb->vbus_irq =regmap_irq_get_virq (palmas->irq_data, -PALMAS_VBUS_IRQ ); -palmas_usb_wakeup (palmas, palmas_usb->wakeup);platform_set_drvdata (pdev, palmas_usb);@@ -201,6 +256,10 @@ static int palmas_usb_probe(struct platform_device *pdev) }if (palmas_usb->enable_id_detection) { + palmas_usb->id_otg_irq =regmap_irq_get_virq (palmas->irq_data, +PALMAS_ID_OTG_IRQ ); + palmas_usb->id_irq =regmap_irq_get_virq (palmas->irq_data, +PALMAS_ID_IRQ ); status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->id_irq, NULL, palmas_id_irq_handler,@@ -212,9 +271,33 @@ static int palmas_usb_probe(struct platform_device *pdev) palmas_usb->id_irq, status);return status; } + }else if (palmas_usb->enable_gpio_id_detection) { + palmas_usb->gpio_id_irq =gpiod_to_irq (palmas_usb->id_gpiod); +if (palmas_usb->gpio_id_irq <0 ) { +dev_err (&pdev->dev,"failed to get id irq\n" ); +return palmas_usb->gpio_id_irq; + } + status =devm_request_threaded_irq (&pdev->dev, + palmas_usb->gpio_id_irq, +NULL , + palmas_gpio_id_irq_handler, +IRQF_TRIGGER_RISING | +IRQF_TRIGGER_FALLING | +IRQF_ONESHOT , +"palmas_usb_id" , + palmas_usb); +if (status <0 ) { +dev_err (&pdev->dev, +"failed to request handler for id irq\n" ); +return status; + } }if (palmas_usb->enable_vbus_detection) { + palmas_usb->vbus_otg_irq =regmap_irq_get_virq (palmas->irq_data, +PALMAS_VBUS_OTG_IRQ ); + palmas_usb->vbus_irq =regmap_irq_get_virq (palmas->irq_data, +PALMAS_VBUS_IRQ ); status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->vbus_irq, NULL, palmas_vbus_irq_handler,@@ -229,10 +312,21 @@ static int palmas_usb_probe(struct platform_device *pdev) }palmas_enable_irq (palmas_usb); +/* perform initial detection */ +palmas_gpio_id_detect (&palmas_usb->wq_detectid.work);device_set_wakeup_capable (&pdev->dev, true);return 0 ; } +static int palmas_usb_remove (struct platform_device *pdev) +{ +struct palmas_usb *palmas_usb =platform_get_drvdata (pdev); + +cancel_delayed_work_sync (&palmas_usb->wq_detectid); + +return 0 ; +} +#ifdef CONFIG_PM_SLEEP static int palmas_usb_suspend (struct device *dev) {@@ -243,6 +337,8 @@ static int palmas_usb_suspend(struct device *dev)enable_irq_wake (palmas_usb->vbus_irq);if (palmas_usb->enable_id_detection)enable_irq_wake (palmas_usb->id_irq); +if (palmas_usb->enable_gpio_id_detection) +enable_irq_wake (palmas_usb->gpio_id_irq); }return 0 ; }@@ -256,6 +352,8 @@ static int palmas_usb_resume(struct device *dev)disable_irq_wake (palmas_usb->vbus_irq);if (palmas_usb->enable_id_detection)disable_irq_wake (palmas_usb->id_irq); +if (palmas_usb->enable_gpio_id_detection) +disable_irq_wake (palmas_usb->gpio_id_irq); }return 0 ; };@@ -273,6 +371,7 @@ static const struct of_device_id of_palmas_match_tbl[] = {static struct platform_driver palmas_usb_driver = { .probe = palmas_usb_probe, + .remove = palmas_usb_remove, .driver = { .name ="palmas-usb" , .of_match_table = of_palmas_match_tbl,drivers/extcon/extcon-usb-gpio.c +1
-0@@ -15,6 +15,7 @@*/ #include <linux/extcon.h> +#include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/init.h> #include <linux/interrupt.h> include/linux/mfd/palmas.h +4
-0@@ -21,6 +21,7 @@#include <linux/regmap.h> #include <linux/regulator/driver.h> #include <linux/extcon.h> +#include <linux/of_gpio.h> #include <linux/usb/phy_companion.h> #define PALMAS_NUM_CLIENTS 3@@ -551,10 +552,16 @@ struct palmas_usb {int vbus_otg_irq;int vbus_irq; +int gpio_id_irq; +struct gpio_desc *id_gpiod; +unsigned long sw_debounce_jiffies;include/linux/mfd/palmas.h struct palmas_usb { · line 567
Quoted 10 lines
include/linux/mfd/palmas.h +3
-0+struct delayed_work wq_detectid; +enum palmas_usb_state linkstat;int wakeup;bool enable_vbus_detection;bool enable_id_detection; +bool enable_gpio_id_detection; };#define comparator_to_palmas (x) container_of((x), struct palmas_usb, comparator)--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v4 1/2] extcon: palmas: Support GPIO based USB ID detection
In reply to Roger QuadrosQuoted 8 lines · Roger Quadros
Some palmas based chip variants do not have OTG based ID logic. For these variants we rely on GPIO based USB ID detection.
These chips do have VBUS comparator for VBUS detection so we continue to use the old way of detecting VBUS.
Acked-by Chanwoo Choi <[email protected]>Signed-off-by Roger Quadros <[email protected]>
Quoted 8 lines
---
v4: updated gpio debounce logic to usedelayed_workqueue..../devicetree/bindings/extcon/extcon-palmas.txt | 5 +- drivers/extcon/extcon-palmas.c | 129 ++++++++++++++++++--- drivers/extcon/extcon-usb-gpio.c | 1 + include/linux/mfd/palmas.h | 7 ++ 4 files changed, 126 insertions(+), 16 deletions(-)
Quoted 273 lines
Documentation/devicetree/bindings/extcon/extcon-palmas.txt +4
-1@@ -10,8 +10,11 @@ Required Properties: Optional Properties: - ti,wakeup : To enable the wakeup comparator in probe - - ti,enable-id-detection: Perform ID detection. + - ti,enable-id-detection: Perform ID detection. If id-gpio is specified + it performs id-detection using GPIO else using OTG core. - ti,enable-vbus-detection: Perform VBUS detection. + - id-gpio: gpio for GPIO ID detection. See gpio binding. + - debounce-delay-ms: debounce delay for GPIO ID pin in milliseconds. palmas-usb { compatible = "ti,twl6035-usb", "ti,palmas-usb";drivers/extcon/extcon-palmas.c +114
-15@@ -28,6 +28,10 @@#include <linux/mfd/palmas.h> #include <linux/of.h> #include <linux/of_platform.h> +#include <linux/of_gpio.h> +#include <linux/workqueue.h> + +#define USB_GPIO_DEBOUNCE_MS 20/* ms */ static const unsigned int palmas_extcon_cable[] = {EXTCON_USB ,@@ -118,19 +122,54 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)return IRQ_HANDLED ; } +static void palmas_gpio_id_detect (struct work_struct *work) +{ +int id; +struct palmas_usb *palmas_usb =container_of (to_delayed_work (work), + struct palmas_usb, + wq_detectid); +struct extcon_dev *edev = palmas_usb->edev; + +if (!palmas_usb->id_gpiod) +return ; + + id =gpiod_get_value_cansleep (palmas_usb->id_gpiod); + +if (id) { +extcon_set_cable_state_ (edev,EXTCON_USB_HOST , false); +dev_info (palmas_usb->dev,"USB-HOST cable is detached\n" ); + }else { +extcon_set_cable_state_ (edev,EXTCON_USB_HOST , true); +dev_info (palmas_usb->dev,"USB-HOST cable is attached\n" ); + } +} + +static irqreturn_t palmas_gpio_id_irq_handler (int irq,void *_palmas_usb) +{ +struct palmas_usb *palmas_usb = _palmas_usb; + +queue_delayed_work (system_power_efficient_wq, &palmas_usb->wq_detectid, + palmas_usb->sw_debounce_jiffies); + +return IRQ_HANDLED ; +} +static void palmas_enable_irq (struct palmas_usb *palmas_usb) {palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE ,PALMAS_USB_VBUS_CTRL_SET ,PALMAS_USB_VBUS_CTRL_SET_VBUS_ACT_COMP ); -palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE , -PALMAS_USB_ID_CTRL_SET ,PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP ); +if (palmas_usb->enable_id_detection) { +palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE , +PALMAS_USB_ID_CTRL_SET , +PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP ); -palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE , -PALMAS_USB_ID_INT_EN_HI_SET , -PALMAS_USB_ID_INT_EN_HI_SET_ID_GND | -PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT ); +palmas_write (palmas_usb->palmas,PALMAS_USB_OTG_BASE , +PALMAS_USB_ID_INT_EN_HI_SET , +PALMAS_USB_ID_INT_EN_HI_SET_ID_GND | +PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT ); + }if (palmas_usb->enable_vbus_detection)palmas_vbus_irq_handler (palmas_usb->vbus_irq, palmas_usb);@@ -169,20 +208,36 @@ static int palmas_usb_probe(struct platform_device *pdev) palmas_usb->wakeup = pdata->wakeup; } + palmas_usb->id_gpiod =devm_gpiod_get_optional (&pdev->dev,"id" ); +if (IS_ERR (palmas_usb->id_gpiod)) { +dev_err (&pdev->dev,"failed to get id gpio\n" ); +return PTR_ERR (palmas_usb->id_gpiod); + } + +if (palmas_usb->enable_id_detection && palmas_usb->id_gpiod) { + palmas_usb->enable_id_detection = false; + palmas_usb->enable_gpio_id_detection = true; + } + +if (palmas_usb->enable_gpio_id_detection) { +u32 debounce; + +if (of_property_read_u32 (node,"debounce-delay-ms" , &debounce)) + debounce =USB_GPIO_DEBOUNCE_MS ; + + status =gpiod_set_debounce (palmas_usb->id_gpiod, + debounce *1000 ); +if (status <0 ) + palmas_usb->sw_debounce_jiffies =msecs_to_jiffies (debounce); + } + +INIT_DELAYED_WORK (&palmas_usb->wq_detectid, palmas_gpio_id_detect); + palmas->usb = palmas_usb; palmas_usb->palmas = palmas; palmas_usb->dev = &pdev->dev; - palmas_usb->id_otg_irq =regmap_irq_get_virq (palmas->irq_data, -PALMAS_ID_OTG_IRQ ); - palmas_usb->id_irq =regmap_irq_get_virq (palmas->irq_data, -PALMAS_ID_IRQ ); - palmas_usb->vbus_otg_irq =regmap_irq_get_virq (palmas->irq_data, -PALMAS_VBUS_OTG_IRQ ); - palmas_usb->vbus_irq =regmap_irq_get_virq (palmas->irq_data, -PALMAS_VBUS_IRQ ); -palmas_usb_wakeup (palmas, palmas_usb->wakeup);platform_set_drvdata (pdev, palmas_usb);@@ -201,6 +256,10 @@ static int palmas_usb_probe(struct platform_device *pdev) }if (palmas_usb->enable_id_detection) { + palmas_usb->id_otg_irq =regmap_irq_get_virq (palmas->irq_data, +PALMAS_ID_OTG_IRQ ); + palmas_usb->id_irq =regmap_irq_get_virq (palmas->irq_data, +PALMAS_ID_IRQ ); status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->id_irq, NULL, palmas_id_irq_handler,@@ -212,9 +271,33 @@ static int palmas_usb_probe(struct platform_device *pdev) palmas_usb->id_irq, status);return status; } + }else if (palmas_usb->enable_gpio_id_detection) { + palmas_usb->gpio_id_irq =gpiod_to_irq (palmas_usb->id_gpiod); +if (palmas_usb->gpio_id_irq <0 ) { +dev_err (&pdev->dev,"failed to get id irq\n" ); +return palmas_usb->gpio_id_irq; + } + status =devm_request_threaded_irq (&pdev->dev, + palmas_usb->gpio_id_irq, +NULL , + palmas_gpio_id_irq_handler, +IRQF_TRIGGER_RISING | +IRQF_TRIGGER_FALLING | +IRQF_ONESHOT , +"palmas_usb_id" , + palmas_usb); +if (status <0 ) { +dev_err (&pdev->dev, +"failed to request handler for id irq\n" ); +return status; + } }if (palmas_usb->enable_vbus_detection) { + palmas_usb->vbus_otg_irq =regmap_irq_get_virq (palmas->irq_data, +PALMAS_VBUS_OTG_IRQ ); + palmas_usb->vbus_irq =regmap_irq_get_virq (palmas->irq_data, +PALMAS_VBUS_IRQ ); status = devm_request_threaded_irq(palmas_usb->dev, palmas_usb->vbus_irq, NULL, palmas_vbus_irq_handler,@@ -229,10 +312,21 @@ static int palmas_usb_probe(struct platform_device *pdev) }palmas_enable_irq (palmas_usb); +/* perform initial detection */ +palmas_gpio_id_detect (&palmas_usb->wq_detectid.work);device_set_wakeup_capable (&pdev->dev, true);return 0 ; } +static int palmas_usb_remove (struct platform_device *pdev) +{ +struct palmas_usb *palmas_usb =platform_get_drvdata (pdev); + +cancel_delayed_work_sync (&palmas_usb->wq_detectid); + +return 0 ; +} +#ifdef CONFIG_PM_SLEEP static int palmas_usb_suspend (struct device *dev) {@@ -243,6 +337,8 @@ static int palmas_usb_suspend(struct device *dev)enable_irq_wake (palmas_usb->vbus_irq);if (palmas_usb->enable_id_detection)enable_irq_wake (palmas_usb->id_irq); +if (palmas_usb->enable_gpio_id_detection) +enable_irq_wake (palmas_usb->gpio_id_irq); }return 0 ; }@@ -256,6 +352,8 @@ static int palmas_usb_resume(struct device *dev)disable_irq_wake (palmas_usb->vbus_irq);if (palmas_usb->enable_id_detection)disable_irq_wake (palmas_usb->id_irq); +if (palmas_usb->enable_gpio_id_detection) +disable_irq_wake (palmas_usb->gpio_id_irq); }return 0 ; };@@ -273,6 +371,7 @@ static const struct of_device_id of_palmas_match_tbl[] = {static struct platform_driver palmas_usb_driver = { .probe = palmas_usb_probe, + .remove = palmas_usb_remove, .driver = { .name ="palmas-usb" , .of_match_table = of_palmas_match_tbl,drivers/extcon/extcon-usb-gpio.c +1
-0@@ -15,6 +15,7 @@*/ #include <linux/extcon.h> +#include <linux/gpio.h> #include <linux/gpio/consumer.h> #include <linux/init.h> #include <linux/interrupt.h> include/linux/mfd/palmas.h +7
-0@@ -21,6 +21,7 @@#include <linux/regmap.h> #include <linux/regulator/driver.h> #include <linux/extcon.h> +#include <linux/of_gpio.h> #include <linux/usb/phy_companion.h> #define PALMAS_NUM_CLIENTS 3@@ -551,10 +552,16 @@ struct palmas_usb {int vbus_otg_irq;int vbus_irq; +int gpio_id_irq; +struct gpio_desc *id_gpiod; +unsigned long sw_debounce_jiffies; +struct delayed_work wq_detectid; +enum palmas_usb_state linkstat;int wakeup;bool enable_vbus_detection;bool enable_id_detection; +bool enable_gpio_id_detection; };#define comparator_to_palmas (x) container_of((x), struct palmas_usb, comparator)
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH v2 2/2 ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2
In reply to Roger QuadrosThe VBUS line of USB2 is connected to VBUS detect logic on the PMIC. Use the palmas-usb driver to report VBUS events to the USB driver.
As the palmas-usb driver supports GPIO based ID reporting provide the GPIO for ID pin as well.
--- arch/arm/boot/dts/am57xx-beagle-x15.dts | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)
arch/arm/boot/dts/am57xx-beagle-x15.dts +16 -13
@@ -98,13 +98,6 @@ pinctrl-0 = <&extcon_usb1_pins>; }; - extcon_usb2: extcon_usb2 { - compatible = "linux,extcon-usb-gpio"; - id-gpio = <&gpio7 24 GPIO_ACTIVE_HIGH>; - pinctrl-names = "default"; - pinctrl-0 = <&extcon_usb2_pins>; - }; - hdmi0: connector { compatible = "hdmi-connector"; label = "hdmi";
@@ -326,12 +319,6 @@ >; }; - extcon_usb2_pins: extcon_usb2_pins { - pinctrl-single,pins = < - 0x3e8 (PIN_INPUT_PULLUP | MUX_MODE14) /* uart1_ctsn.gpio7_24 */ - >; - }; - tpd12s015_pins: pinmux_tpd12s015_pins { pinctrl-single,pins = < 0x3b0 (PIN_OUTPUT | MUX_MODE14) /* gpio7_10 CT_CP_HPD */
@@ -495,6 +482,14 @@ gpio-controller; #gpio-cells = <2>; }; + + extcon_usb2: tps659038_usb { + compatible = "ti,palmas-usb-vid"; + ti,enable-vbus-detection; + ti,enable-id-detection; + id-gpios = <&gpio7 24 GPIO_ACTIVE_HIGH>; + }; + }; tmp102: tmp102@48 {
@@ -624,6 +619,14 @@ }; &usb2 { + /* + * Stand alone usage is peripheral only. + * However, with some resistor modifications + * this port can be used via expansion connectors + * as "host" or "dual-role". If so, provide + * the necessary dr_mode override in the expansion + * board's DT. + */ dr_mode = "peripheral"; };
Signature · 1 line
2.1.4
Re: [PATCH v2 2/2] ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2
Quoted 8 lines · Roger Quadros
The VBUS line of USB2 is connected to VBUS detect logic on the PMIC. Use the palmas-usb driver to report VBUS events to the USB driver.
As the palmas-usb driver supports GPIO based ID reporting provide the GPIO for ID pin as well.
Signed-off-by Roger Quadros <[email protected]>
This should not cause merge conflicts with what I have queeud for v4.3, so Chanwoo please feel free to apply with the rest of the extcon series:
Chanwoo Choi
maintainerRe: [PATCH v2 2/2] ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2
Quoted 8 lines · Tony Lindgren
Quoted 7 lines · Roger Quadros
The VBUS line of USB2 is connected to VBUS detect logic on the PMIC. Use the palmas-usb driver to report VBUS events to the USB driver.
As the palmas-usb driver supports GPIO based ID reporting provide the GPIO for ID pin as well.
Quoted 8 lines
Quoted 1 line
Signed-off-by Roger Quadros <[email protected]>This should not cause merge conflicts with what I have queeud for v4.3, so Chanwoo please feel free to apply with the rest of the extcon series:
Acked-by Tony Lindgren <[email protected]>
I reviewd this patchset related to extcon and give the acked-by message. but patch1 must need the acked-by message from MFD maintainer.
If patch1 receive the acked-by message from MFD maintainer, I'll apply it for v4.3.
Roger,
I think that you better to recevie the acked-by message before v4.2-rc6 release. I have the plan about pull request of extcon for v4.3 after v4.2-rc6 releas.
Thanks,
Chanwoo Choi
Re: [PATCH v2 2/2] ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2
Chanwoo,
Quoted 21 lines · Chanwoo Choi
Quoted 8 lines · Tony Lindgren
Quoted 7 lines · Roger Quadros
The VBUS line of USB2 is connected to VBUS detect logic on the PMIC. Use the palmas-usb driver to report VBUS events to the USB driver.
As the palmas-usb driver supports GPIO based ID reporting provide the GPIO for ID pin as well.
Quoted 8 lines
Quoted 1 line
Signed-off-by Roger Quadros <[email protected]>This should not cause merge conflicts with what I have queeud for v4.3, so Chanwoo please feel free to apply with the rest of the extcon series:
Acked-by Tony Lindgren <[email protected]>I reviewd this patchset related to extcon and give the acked-by message. but patch1 must need the acked-by message from MFD maintainer.
Quoted 6 lines
If patch1 receive the acked-by message from MFD maintainer, I'll apply it for v4.3.
Roger,
I think that you better to recevie the acked-by message before v4.2-rc6 release. I have the plan about pull request of extcon for v4.3 after v4.2-rc6 releas.
Seems like you picked patch 1 but not this one. As Tony has already Acked it can you please include patch 2 as well in your tree for -next? Thanks.
cheers,
-roger
Re: [PATCH v2 2/2] ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2
Tony,
Quoted 27 lines · Roger Quadros
Chanwoo,
Quoted 24 lines · Chanwoo Choi
Quoted 8 lines · Tony Lindgren
Quoted 7 lines · Roger Quadros
The VBUS line of USB2 is connected to VBUS detect logic on the PMIC. Use the palmas-usb driver to report VBUS events to the USB driver.
As the palmas-usb driver supports GPIO based ID reporting provide the GPIO for ID pin as well.
Quoted 8 lines
Quoted 1 line
Signed-off-by Roger Quadros <[email protected]>This should not cause merge conflicts with what I have queeud for v4.3, so Chanwoo please feel free to apply with the rest of the extcon series:
Acked-by Tony Lindgren <[email protected]>,
I reviewd this patchset related to extcon and give the acked-by message. but patch1 must need the acked-by message from MFD maintainer.If patch1 receive the acked-by message from MFD maintainer, I'll apply it for v4.3.
Quoted 7 lines
Quoted 3 lines
Roger,
I think that you better to recevie the acked-by message before v4.2-rc6 release. I have the plan about pull request of extcon for v4.3 after v4.2-rc6 releas.Seems like you picked patch 1 but not this one. As Tony has already Acked it can you please include patch 2 as well in your tree for -next? Thanks.
Is it possible for you to pick this up for -rc cycle via omap-soc tree? Thanks.
--
cheers,
-roger
Re: [PATCH v2 2/2] ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2
Quoted 34 lines · Roger Quadros
Tony,
Quoted 31 lines · Roger Quadros
Chanwoo,
Quoted 27 lines · Chanwoo Choi
Quoted 8 lines · Tony Lindgren
Quoted 7 lines · Roger Quadros
The VBUS line of USB2 is connected to VBUS detect logic on the PMIC. Use the palmas-usb driver to report VBUS events to the USB driver.
As the palmas-usb driver supports GPIO based ID reporting provide the GPIO for ID pin as well.
Quoted 8 lines
Quoted 1 line
Signed-off-by Roger Quadros <[email protected]>This should not cause merge conflicts with what I have queeud for v4.3, so Chanwoo please feel free to apply with the rest of the extcon series:
Acked-by Tony Lindgren <[email protected]>,
I reviewd this patchset related to extcon and give the acked-by message. but patch1 must need the acked-by message from MFD maintainer.If patch1 receive the acked-by message from MFD maintainer, I'll apply it for v4.3.
Roger,
I think that you better to recevie the acked-by message before v4.2-rc6 release. I have the plan about pull request of extcon for v4.3 after v4.2-rc6 releas.
Quoted 6 lines
Quoted 3 lines
Seems like you picked patch 1 but not this one. As Tony has already Acked it can you please include patch 2 as well in your tree for -next? Thanks.
Is it possible for you to pick this up for -rc cycle via omap-soc tree? Thanks.
OK picking up the second patch into omap-for-v4.3/fixes thanks.
Tony