linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] extcon: palmas: am57xx-beagle-x15: use palmas for VBUS/ID detection
@ 2015-07-27 13:10 Roger Quadros
  2015-07-27 13:10 ` [PATCH v2 1/2] extcon: palmas: Support GPIO based USB ID detection Roger Quadros
  2015-07-27 13:10 ` [PATCH v2 2/2] ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2 Roger Quadros
  0 siblings, 2 replies; 16+ messages in thread
From: Roger Quadros @ 2015-07-27 13:10 UTC (permalink / raw)
  To: myungjoo.ham, cw00.choi, tony
  Cc: nm, balbi, linux-omap, linux-kernel, Roger Quadros

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(-)

-- 
2.1.4


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v2 1/2] extcon: palmas: Support GPIO based USB ID detection
  2015-07-27 13:10 [PATCH v2 0/2] extcon: palmas: am57xx-beagle-x15: use palmas for VBUS/ID detection Roger Quadros
@ 2015-07-27 13:10 ` Roger Quadros
  2015-07-31  7:46   ` Chanwoo Choi
  2015-07-31 11:08   ` [PATCH v3 " Roger Quadros
  2015-07-27 13:10 ` [PATCH v2 2/2] ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2 Roger Quadros
  1 sibling, 2 replies; 16+ messages in thread
From: Roger Quadros @ 2015-07-27 13:10 UTC (permalink / raw)
  To: myungjoo.ham, cw00.choi, tony
  Cc: nm, balbi, linux-omap, linux-kernel, 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 <rogerq@ti.com>
---
 .../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(-)

diff --git a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
index 45414bb..f61d5af 100644
--- a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
+++ b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
@@ -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";
diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
index 080d5cc..d0ed764 100644
--- a/drivers/extcon/extcon-palmas.c
+++ b/drivers/extcon/extcon-palmas.c
@@ -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)
+{
+	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);
+		dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
+	} else {
+		extcon_set_cable_state(palmas_usb->edev, "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;
+
+	if (palmas_usb->sw_debounce_ms)
+		mdelay(palmas_usb->sw_debounce_ms);
+
+	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);
@@ -171,20 +207,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);
@@ -205,6 +255,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,
@@ -217,9 +271,33 @@ static int palmas_usb_probe(struct platform_device *pdev)
 			kfree(palmas_usb->edev->name);
 			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,
@@ -235,6 +313,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;
 }
@@ -258,6 +338,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;
 }
@@ -271,6 +353,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;
 };
diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
index bb270bd..1a202a6 100644
--- a/include/linux/mfd/palmas.h
+++ b/include/linux/mfd/palmas.h
@@ -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)
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v2 2/2] ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2
  2015-07-27 13:10 [PATCH v2 0/2] extcon: palmas: am57xx-beagle-x15: use palmas for VBUS/ID detection Roger Quadros
  2015-07-27 13:10 ` [PATCH v2 1/2] extcon: palmas: Support GPIO based USB ID detection Roger Quadros
@ 2015-07-27 13:10 ` Roger Quadros
  2015-08-05 10:37   ` Tony Lindgren
  1 sibling, 1 reply; 16+ messages in thread
From: Roger Quadros @ 2015-07-27 13:10 UTC (permalink / raw)
  To: myungjoo.ham, cw00.choi, tony
  Cc: nm, balbi, linux-omap, linux-kernel, 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 <rogerq@ti.com>
---
 arch/arm/boot/dts/am57xx-beagle-x15.dts | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/arch/arm/boot/dts/am57xx-beagle-x15.dts b/arch/arm/boot/dts/am57xx-beagle-x15.dts
index a63bf78..f32cf20 100644
--- a/arch/arm/boot/dts/am57xx-beagle-x15.dts
+++ b/arch/arm/boot/dts/am57xx-beagle-x15.dts
@@ -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";
 };
 
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 1/2] extcon: palmas: Support GPIO based USB ID detection
  2015-07-27 13:10 ` [PATCH v2 1/2] extcon: palmas: Support GPIO based USB ID detection Roger Quadros
@ 2015-07-31  7:46   ` Chanwoo Choi
  2015-07-31  9:05     ` Roger Quadros
  2015-07-31 11:08   ` [PATCH v3 " Roger Quadros
  1 sibling, 1 reply; 16+ messages in thread
From: Chanwoo Choi @ 2015-07-31  7:46 UTC (permalink / raw)
  To: Roger Quadros; +Cc: myungjoo.ham, tony, nm, balbi, linux-omap, linux-kernel

Hi Roger,

When I apply it for build test, merge conflict happen.
So, I recommend that you rebase this patchset on extcon-next branch.

On 07/27/2015 10:10 PM, Roger Quadros wrote:
> 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 <rogerq@ti.com>
> ---
>  .../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(-)
> 
> diff --git a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
> index 45414bb..f61d5af 100644
> --- a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
> +++ b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
> @@ -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";
> diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
> index 080d5cc..d0ed764 100644
> --- a/drivers/extcon/extcon-palmas.c
> +++ b/drivers/extcon/extcon-palmas.c
> @@ -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)
> +{
> +	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.

> +		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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 1/2] extcon: palmas: Support GPIO based USB ID detection
  2015-07-31  7:46   ` Chanwoo Choi
@ 2015-07-31  9:05     ` Roger Quadros
  0 siblings, 0 replies; 16+ messages in thread
From: Roger Quadros @ 2015-07-31  9:05 UTC (permalink / raw)
  To: Chanwoo Choi; +Cc: myungjoo.ham, tony, nm, balbi, linux-omap, linux-kernel

Hi Chanwoo,

On 31/07/15 10:46, Chanwoo Choi wrote:
> 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.

> 
> On 07/27/2015 10:10 PM, Roger Quadros wrote:
>> 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 <rogerq@ti.com>
>> ---
>>  .../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(-)
>>
>> diff --git a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
>> index 45414bb..f61d5af 100644
>> --- a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
>> +++ b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
>> @@ -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";
>> diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
>> index 080d5cc..d0ed764 100644
>> --- a/drivers/extcon/extcon-palmas.c
>> +++ b/drivers/extcon/extcon-palmas.c
>> @@ -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)
>> +{
>> +	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.

OK.

cheers,
-roger

> 
>> +		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
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v3 1/2] extcon: palmas: Support GPIO based USB ID detection
  2015-07-27 13:10 ` [PATCH v2 1/2] extcon: palmas: Support GPIO based USB ID detection Roger Quadros
  2015-07-31  7:46   ` Chanwoo Choi
@ 2015-07-31 11:08   ` Roger Quadros
  2015-07-31 15:34     ` Chanwoo Choi
  2015-08-03 14:40     ` [PATCH v4 " Roger Quadros
  1 sibling, 2 replies; 16+ messages in thread
From: Roger Quadros @ 2015-07-31 11:08 UTC (permalink / raw)
  To: myungjoo.ham, cw00.choi, tony; +Cc: nm, balbi, linux-omap, linux-kernel, rogerq

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 <rogerq@ti.com>
---

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(-)

diff --git a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
index 45414bb..f61d5af 100644
--- a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
+++ b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
@@ -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";
diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
index 8933e7e..b948984 100644
--- a/drivers/extcon/extcon-palmas.c
+++ b/drivers/extcon/extcon-palmas.c
@@ -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);
+		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);
+
+	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;
 };
diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
index bb270bd..1a202a6 100644
--- a/include/linux/mfd/palmas.h
+++ b/include/linux/mfd/palmas.h
@@ -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)
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 1/2] extcon: palmas: Support GPIO based USB ID detection
  2015-07-31 11:08   ` [PATCH v3 " Roger Quadros
@ 2015-07-31 15:34     ` Chanwoo Choi
  2015-08-03 14:40     ` [PATCH v4 " Roger Quadros
  1 sibling, 0 replies; 16+ messages in thread
From: Chanwoo Choi @ 2015-07-31 15:34 UTC (permalink / raw)
  To: Roger Quadros
  Cc: myungjoo.ham, Tony Lindgren, nm, Felipe Balbi, linux-omap,
	linux-kernel, Lee Jones

Hi Roger,

Looks good to me. But, I add one comment about mdelay.
If you modify it, you can add my acked-by message.

Acked-by: Chanwoo Choi <cw00.choi@samsung.com>

Also, You must recevie the ack message from MFD maintainer (Lee Jones).

On Fri, Jul 31, 2015 at 8:08 PM, Roger Quadros <rogerq@ti.com> wrote:
> 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 <rogerq@ti.com>
> ---
>
> 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(-)
>
> diff --git a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
> index 45414bb..f61d5af 100644
> --- a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
> +++ b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
> @@ -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";
> diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
> index 8933e7e..b948984 100644
> --- a/drivers/extcon/extcon-palmas.c
> +++ b/drivers/extcon/extcon-palmas.c
> @@ -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);
> +               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

> +
> +       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;
>  };
> diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
> index bb270bd..1a202a6 100644
> --- a/include/linux/mfd/palmas.h
> +++ b/include/linux/mfd/palmas.h
> @@ -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)

Thanks,
Chanwoo Choi

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v4 1/2] extcon: palmas: Support GPIO based USB ID detection
  2015-07-31 11:08   ` [PATCH v3 " Roger Quadros
  2015-07-31 15:34     ` Chanwoo Choi
@ 2015-08-03 14:40     ` Roger Quadros
  2015-08-07  8:24       ` Roger Quadros
  2015-08-10  8:35       ` Lee Jones
  1 sibling, 2 replies; 16+ messages in thread
From: Roger Quadros @ 2015-08-03 14:40 UTC (permalink / raw)
  To: myungjoo.ham, cw00.choi, tony, lee.jones
  Cc: nm, balbi, linux-omap, linux-kernel, rogerq

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 <cw00.choi@samsung.com>
Signed-off-by: Roger Quadros <rogerq@ti.com>
---
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(-)

diff --git a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
index 45414bb..f61d5af 100644
--- a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
+++ b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
@@ -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";
diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
index 8933e7e..662e917 100644
--- a/drivers/extcon/extcon-palmas.c
+++ b/drivers/extcon/extcon-palmas.c
@@ -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,
diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
index a2a4453..2b2fecf 100644
--- a/drivers/extcon/extcon-usb-gpio.c
+++ b/drivers/extcon/extcon-usb-gpio.c
@@ -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>
diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
index bb270bd..13e1d96 100644
--- a/include/linux/mfd/palmas.h
+++ b/include/linux/mfd/palmas.h
@@ -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)
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/2] ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2
  2015-07-27 13:10 ` [PATCH v2 2/2] ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2 Roger Quadros
@ 2015-08-05 10:37   ` Tony Lindgren
  2015-08-05 23:36     ` Chanwoo Choi
  0 siblings, 1 reply; 16+ messages in thread
From: Tony Lindgren @ 2015-08-05 10:37 UTC (permalink / raw)
  To: Roger Quadros
  Cc: myungjoo.ham, cw00.choi, nm, balbi, linux-omap, linux-kernel

* Roger Quadros <rogerq@ti.com> [150727 06:13]:
> 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 <rogerq@ti.com>

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 <tony@atomide.com>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/2] ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2
  2015-08-05 10:37   ` Tony Lindgren
@ 2015-08-05 23:36     ` Chanwoo Choi
  2015-09-03  7:36       ` Roger Quadros
  0 siblings, 1 reply; 16+ messages in thread
From: Chanwoo Choi @ 2015-08-05 23:36 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: Roger Quadros, myungjoo.ham, nm, balbi, linux-omap, linux-kernel

On 08/05/2015 07:37 PM, Tony Lindgren wrote:
> * Roger Quadros <rogerq@ti.com> [150727 06:13]:
>> 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 <rogerq@ti.com>
> 
> 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 <tony@atomide.com>
> 

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 1/2] extcon: palmas: Support GPIO based USB ID detection
  2015-08-03 14:40     ` [PATCH v4 " Roger Quadros
@ 2015-08-07  8:24       ` Roger Quadros
  2015-08-10  2:46         ` Chanwoo Choi
  2015-08-10  8:35       ` Lee Jones
  1 sibling, 1 reply; 16+ messages in thread
From: Roger Quadros @ 2015-08-07  8:24 UTC (permalink / raw)
  To: lee.jones, sameo
  Cc: myungjoo.ham, cw00.choi, tony, nm, balbi, linux-omap, linux-kernel

Hi Lee / Samuel,

On 03/08/15 17:40, Roger Quadros wrote:
> 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 <cw00.choi@samsung.com>
> Signed-off-by: Roger Quadros <rogerq@ti.com>

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

> ---
> 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(-)
> 
> diff --git a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
> index 45414bb..f61d5af 100644
> --- a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
> +++ b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
> @@ -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";
> diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
> index 8933e7e..662e917 100644
> --- a/drivers/extcon/extcon-palmas.c
> +++ b/drivers/extcon/extcon-palmas.c
> @@ -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,
> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
> index a2a4453..2b2fecf 100644
> --- a/drivers/extcon/extcon-usb-gpio.c
> +++ b/drivers/extcon/extcon-usb-gpio.c
> @@ -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>
> diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
> index bb270bd..13e1d96 100644
> --- a/include/linux/mfd/palmas.h
> +++ b/include/linux/mfd/palmas.h
> @@ -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)
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 1/2] extcon: palmas: Support GPIO based USB ID detection
  2015-08-07  8:24       ` Roger Quadros
@ 2015-08-10  2:46         ` Chanwoo Choi
  0 siblings, 0 replies; 16+ messages in thread
From: Chanwoo Choi @ 2015-08-10  2:46 UTC (permalink / raw)
  To: Roger Quadros, lee.jones
  Cc: sameo, myungjoo.ham, tony, nm, balbi, linux-omap, linux-kernel

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


On 08/07/2015 05:24 PM, Roger Quadros wrote:
> Hi Lee / Samuel,
> 
> On 03/08/15 17:40, Roger Quadros wrote:
>> 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 <cw00.choi@samsung.com>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
> 
> 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
> 
>> ---
>> 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(-)
>>
>> diff --git a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
>> index 45414bb..f61d5af 100644
>> --- a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
>> +++ b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
>> @@ -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";
>> diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
>> index 8933e7e..662e917 100644
>> --- a/drivers/extcon/extcon-palmas.c
>> +++ b/drivers/extcon/extcon-palmas.c
>> @@ -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,
>> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
>> index a2a4453..2b2fecf 100644
>> --- a/drivers/extcon/extcon-usb-gpio.c
>> +++ b/drivers/extcon/extcon-usb-gpio.c
>> @@ -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>
>> diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
>> index bb270bd..13e1d96 100644
>> --- a/include/linux/mfd/palmas.h
>> +++ b/include/linux/mfd/palmas.h
>> @@ -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)
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 1/2] extcon: palmas: Support GPIO based USB ID detection
  2015-08-03 14:40     ` [PATCH v4 " Roger Quadros
  2015-08-07  8:24       ` Roger Quadros
@ 2015-08-10  8:35       ` Lee Jones
  1 sibling, 0 replies; 16+ messages in thread
From: Lee Jones @ 2015-08-10  8:35 UTC (permalink / raw)
  To: Roger Quadros
  Cc: myungjoo.ham, cw00.choi, tony, nm, balbi, linux-omap, linux-kernel

On Mon, 03 Aug 2015, Roger Quadros wrote:

> 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 <cw00.choi@samsung.com>
> Signed-off-by: Roger Quadros <rogerq@ti.com>
> ---
> 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(-)

Acked-by: Lee Jones <lee.jones@linaro.org>

> diff --git a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
> index 45414bb..f61d5af 100644
> --- a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
> +++ b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
> @@ -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";
> diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
> index 8933e7e..662e917 100644
> --- a/drivers/extcon/extcon-palmas.c
> +++ b/drivers/extcon/extcon-palmas.c
> @@ -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,
> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
> index a2a4453..2b2fecf 100644
> --- a/drivers/extcon/extcon-usb-gpio.c
> +++ b/drivers/extcon/extcon-usb-gpio.c
> @@ -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>
> diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
> index bb270bd..13e1d96 100644
> --- a/include/linux/mfd/palmas.h
> +++ b/include/linux/mfd/palmas.h
> @@ -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)

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/2] ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2
  2015-08-05 23:36     ` Chanwoo Choi
@ 2015-09-03  7:36       ` Roger Quadros
  2015-09-15 10:43         ` Roger Quadros
  0 siblings, 1 reply; 16+ messages in thread
From: Roger Quadros @ 2015-09-03  7:36 UTC (permalink / raw)
  To: Chanwoo Choi, Tony Lindgren
  Cc: myungjoo.ham, nm, balbi, linux-omap, linux-kernel

Chanwoo,

On 06/08/15 02:36, Chanwoo Choi wrote:
> On 08/05/2015 07:37 PM, Tony Lindgren wrote:
>> * Roger Quadros <rogerq@ti.com> [150727 06:13]:
>>> 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 <rogerq@ti.com>
>>
>> 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 <tony@atomide.com>
>>
> 
> 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.

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/2] ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2
  2015-09-03  7:36       ` Roger Quadros
@ 2015-09-15 10:43         ` Roger Quadros
  2015-09-17  0:06           ` Tony Lindgren
  0 siblings, 1 reply; 16+ messages in thread
From: Roger Quadros @ 2015-09-15 10:43 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: Chanwoo Choi, myungjoo.ham, nm, balbi, linux-omap, linux-kernel

Tony,

On 03/09/15 10:36, Roger Quadros wrote:
> Chanwoo,
> 
> On 06/08/15 02:36, Chanwoo Choi wrote:
>> On 08/05/2015 07:37 PM, Tony Lindgren wrote:
>>> * Roger Quadros <rogerq@ti.com> [150727 06:13]:
>>>> 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 <rogerq@ti.com>
>>>
>>> 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 <tony@atomide.com>
>>>
>>,
>> 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.
> 
> 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v2 2/2] ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2
  2015-09-15 10:43         ` Roger Quadros
@ 2015-09-17  0:06           ` Tony Lindgren
  0 siblings, 0 replies; 16+ messages in thread
From: Tony Lindgren @ 2015-09-17  0:06 UTC (permalink / raw)
  To: Roger Quadros
  Cc: Chanwoo Choi, myungjoo.ham, nm, balbi, linux-omap, linux-kernel

* Roger Quadros <rogerq@ti.com> [150915 03:46]:
> Tony,
> 
> On 03/09/15 10:36, Roger Quadros wrote:
> > Chanwoo,
> > 
> > On 06/08/15 02:36, Chanwoo Choi wrote:
> >> On 08/05/2015 07:37 PM, Tony Lindgren wrote:
> >>> * Roger Quadros <rogerq@ti.com> [150727 06:13]:
> >>>> 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 <rogerq@ti.com>
> >>>
> >>> 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 <tony@atomide.com>
> >>>
> >>,
> >> 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.
> > 
> > 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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2015-09-17  0:06 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-27 13:10 [PATCH v2 0/2] extcon: palmas: am57xx-beagle-x15: use palmas for VBUS/ID detection Roger Quadros
2015-07-27 13:10 ` [PATCH v2 1/2] extcon: palmas: Support GPIO based USB ID detection Roger Quadros
2015-07-31  7:46   ` Chanwoo Choi
2015-07-31  9:05     ` Roger Quadros
2015-07-31 11:08   ` [PATCH v3 " Roger Quadros
2015-07-31 15:34     ` Chanwoo Choi
2015-08-03 14:40     ` [PATCH v4 " Roger Quadros
2015-08-07  8:24       ` Roger Quadros
2015-08-10  2:46         ` Chanwoo Choi
2015-08-10  8:35       ` Lee Jones
2015-07-27 13:10 ` [PATCH v2 2/2] ARM: dts: am57xx-beagle-x15: use palmas-usb for USB2 Roger Quadros
2015-08-05 10:37   ` Tony Lindgren
2015-08-05 23:36     ` Chanwoo Choi
2015-09-03  7:36       ` Roger Quadros
2015-09-15 10:43         ` Roger Quadros
2015-09-17  0:06           ` Tony Lindgren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).