Skip to contentSkip to conversation

extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 & AM57xx USB.

PATCH Superseded Roger Quadros 5 participants 44 messages Jan 26, 2015 – Mar 17, 2015

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

v2 cover extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 & AM57xx USB.

Hi,

Still hoping this can make into 3.20 else we have USB peripheral mode broken on DRA7-evm, DRA72-evm and AM57xx-beagle-x15.

On DRA7 and AM57xx EVMs the USB ID pin is connected to a GPIO line. The USB drivers (dwc3 + dwc3-omap) depend on extcon framework to get the USB cable state (USB or USB-Host) to put the controller in the right mode.

There were earlier attempts [1] to get this working by trying to patch up the existing GPIO extcon driver.

This series attemts to take a different approach by introducing a new USB specific extcon driver to handle the USB ID GPIO pin and interpret a right USB cable state.

The reasoning to introduce this new driver is:
1) The existing GPIO extcon driver doesn't understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle at least 2 cable states.
a) USB (attach/detach)
b) USB-Host (attach/detach)
and could possible include more states like
c) Fast-charger (attach/detach)
d) Slow-charger (attach/detach)

2) This USB specific driver can be easily updated in the future to handle VBUS events, or charger detect events, in case it happens to be available on GPIO for any platform.

3) The DT implementation is very easy. You just need one extcon node per USB instead of one extcon node per cable state as in case of [1].

4) The cable state string doesn't need to be encoded in the device tree as in case of [1].

5) With only ID event available, you can simulate a USB-peripheral attach when USB-Host is detacted instead of hacking the USB driver to do the same.

Tested on DRA7-evm, DRA72-evm and AM57xx-beagle-x15

Changelog:
v2
- Addressed review comments.
- Fixed auto load of extcon-usb-gpio driver when used as module.
- Fixed up AM57xx USB.

--
cheers,
-roger
[1] - https://lkml.org/lkml/2014/11/3/513

Roger Quadros (7):
extcon: usb-gpio: Introduce gpio usb extcon driver
usb: extcon: Fix USB-Host cable name
ARM: dts: dra7-evm: Add extcon nodes for USB
ARM: dts: dra72-evm: Add extcon nodes for USB
ARM: dts: am57xx-beagle-x15: Add extcon nodes for USB
ARM: dts: am57xx-beagle-x15: Fix USB2 mode
ARM: omap2plus_defconfig: Enable EXTCON_GPIO_USB

 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  20 ++
 arch/arm/boot/dts/am57xx-beagle-x15.dts            |  37 ++++
 arch/arm/boot/dts/dra7-evm.dts                     |  31 +++
 arch/arm/boot/dts/dra72-evm.dts                    |  31 +++
 arch/arm/configs/omap2plus_defconfig               |   1 +
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-palmas.c                     |  18 +-
 drivers/extcon/extcon-usb-gpio.c                   | 214 +++++++++++++++++++++
 drivers/usb/dwc3/dwc3-omap.c                       |   6 +-
 drivers/usb/phy/phy-omap-otg.c                     |   4 +-
 drivers/usb/phy/phy-tahvo.c                        |   8 +-
 12 files changed, 360 insertions(+), 18 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c
Signature · 1 line
2.1.0
#1 lore raw

PATCH v2 1/7 extcon: usb-gpio: Introduce gpio usb extcon driver

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-Host (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  20 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 214 +++++++++++++++++++++
 4 files changed, 242 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +20 -0
new file mode 100644
index 0000000..ab52a85
@@ -0,0 +1,20 @@
+USB GPIO Extcon device
+
+This is a virtual device used to generate USB cable states from the USB ID pin
+connected to a GPIO pin.
+
+Required properties:
+- compatible: Should be "linux,extcon-usb-gpio"
+- id-gpio: gpio for USB ID pin. See gpio binding.
+
+Example:
+	extcon_usb1 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+	}
+
+	usb@1 {
+		...
+		extcon = <&extcon_usb1>;
+		...
+	};
drivers/extcon/Kconfig +7 -0
index 6a1f7de..e4c01ab 100644
@@ -93,4 +93,11 @@ config EXTCON_SM5502
 	  Silicon Mitus SM5502. The SM5502 is a USB port accessory
 	  detector and switch.
 
+config EXTCON_USB_GPIO
+	tristate "USB GPIO extcon support"
+	depends on GPIOLIB
+	help
+	  Say Y here to enable GPIO based USB cable detection extcon support.
+	  Used typically if GPIO is used for USB ID pin detection.
+
 endif # MULTISTATE_SWITCH
drivers/extcon/Makefile +1 -0
index 0370b42..6a08a98 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_EXTCON_MAX8997)	+= extcon-max8997.o
 obj-$(CONFIG_EXTCON_PALMAS)	+= extcon-palmas.o
 obj-$(CONFIG_EXTCON_RT8973A)	+= extcon-rt8973a.o
 obj-$(CONFIG_EXTCON_SM5502)	+= extcon-sm5502.o
+obj-$(CONFIG_EXTCON_USB_GPIO)	+= extcon-usb-gpio.o
drivers/extcon/extcon-usb-gpio.c new file +214 -0

214 lines not on this page · raw message

Signature · 6 lines
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#29 lore raw

PATCH v2 2/7 usb: extcon: Fix USB-Host cable name

In reply to Roger Quadros

The recommended name for USB-Host cable state is "USB-Host" and not "USB-HOST" as per drivers/extcon/extcon-class.c extcon_cable_name.

Change all instances of "USB-HOST" to "USB-Host".

---
 drivers/extcon/extcon-palmas.c | 18 +++++++++---------
 drivers/usb/dwc3/dwc3-omap.c   |  6 +++---
 drivers/usb/phy/phy-omap-otg.c |  4 ++--
 drivers/usb/phy/phy-tahvo.c    |  8 ++++----
 4 files changed, 18 insertions(+), 18 deletions(-)
drivers/extcon/extcon-palmas.c +9 -9
index 11c6757..6d002c3 100644
@@ -31,7 +31,7 @@
 
 static const char *palmas_extcon_cable[] = {
 	[0] = "USB",
-	[1] = "USB-HOST",
+	[1] = "USB-Host",
 	NULL,
 };
 
@@ -93,26 +93,26 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)
 			PALMAS_USB_ID_INT_LATCH_CLR,
 			PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND);
 		palmas_usb->linkstat = PALMAS_USB_STATE_ID;
-		extcon_set_cable_state(palmas_usb->edev, "USB-HOST", true);
-		dev_info(palmas_usb->dev, "USB-HOST cable is attached\n");
+		extcon_set_cable_state(palmas_usb->edev, "USB-Host", true);
+		dev_info(palmas_usb->dev, "USB-Host cable is attached\n");
 	} else if ((set & PALMAS_USB_ID_INT_SRC_ID_FLOAT) &&
 				(id_src & PALMAS_USB_ID_INT_SRC_ID_FLOAT)) {
 		palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
 			PALMAS_USB_ID_INT_LATCH_CLR,
 			PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT);
 		palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
-		extcon_set_cable_state(palmas_usb->edev, "USB-HOST", false);
-		dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
+		extcon_set_cable_state(palmas_usb->edev, "USB-Host", false);
+		dev_info(palmas_usb->dev, "USB-Host cable is detached\n");
 	} else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) &&
 				(!(set & PALMAS_USB_ID_INT_SRC_ID_GND))) {
 		palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
-		extcon_set_cable_state(palmas_usb->edev, "USB-HOST", false);
-		dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
+		extcon_set_cable_state(palmas_usb->edev, "USB-Host", false);
+		dev_info(palmas_usb->dev, "USB-Host cable is detached\n");
 	} else if ((palmas_usb->linkstat == PALMAS_USB_STATE_DISCONNECT) &&
 				(id_src & PALMAS_USB_ID_INT_SRC_ID_GND)) {
 		palmas_usb->linkstat = PALMAS_USB_STATE_ID;
-		extcon_set_cable_state(palmas_usb->edev, "USB-HOST", true);
-		dev_info(palmas_usb->dev, " USB-HOST cable is attached\n");
+		extcon_set_cable_state(palmas_usb->edev, "USB-Host", true);
+		dev_info(palmas_usb->dev, " USB-Host cable is attached\n");
 	}
 
 	return IRQ_HANDLED;
drivers/usb/dwc3/dwc3-omap.c +3 -3
index 172d64e..6713ad9 100644
@@ -445,14 +445,14 @@ static int dwc3_omap_extcon_register(struct dwc3_omap *omap)
 
 		omap->id_nb.notifier_call = dwc3_omap_id_notifier;
 		ret = extcon_register_interest(&omap->extcon_id_dev,
-					       edev->name, "USB-HOST",
+					       edev->name, "USB-Host",
 					       &omap->id_nb);
 		if (ret < 0)
-			dev_vdbg(omap->dev, "failed to register notifier for USB-HOST\n");
+			dev_vdbg(omap->dev, "failed to register notifier for USB-Host\n");
 
 		if (extcon_get_cable_state(edev, "USB") == true)
 			dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
-		if (extcon_get_cable_state(edev, "USB-HOST") == true)
+		if (extcon_get_cable_state(edev, "USB-Host") == true)
 			dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
 	}
 
drivers/usb/phy/phy-omap-otg.c +2 -2
index 56ee760..53cba3f 100644
@@ -119,7 +119,7 @@ static int omap_otg_probe(struct platform_device *pdev)
 	otg_dev->vbus_nb.notifier_call = omap_otg_vbus_notifier;
 
 	ret = extcon_register_interest(&otg_dev->id_dev, config->extcon,
-				       "USB-HOST", &otg_dev->id_nb);
+				       "USB-Host", &otg_dev->id_nb);
 	if (ret)
 		return ret;
 
@@ -130,7 +130,7 @@ static int omap_otg_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	otg_dev->id = extcon_get_cable_state(extcon, "USB-HOST");
+	otg_dev->id = extcon_get_cable_state(extcon, "USB-Host");
 	otg_dev->vbus = extcon_get_cable_state(extcon, "USB");
 	omap_otg_set_mode(otg_dev);
 
drivers/usb/phy/phy-tahvo.c +4 -4
index 845f658..56d3704 100644
@@ -61,7 +61,7 @@ struct tahvo_usb {
 };
 
 static const char *tahvo_cable[] = {
-	"USB-HOST",
+	"USB-Host",
 	"USB",
 	NULL,
 };
@@ -129,7 +129,7 @@ static void tahvo_usb_become_host(struct tahvo_usb *tu)
 {
 	struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent);
 
-	extcon_set_cable_state(&tu->extcon, "USB-HOST", true);
+	extcon_set_cable_state(&tu->extcon, "USB-Host", true);
 
 	/* Power up the transceiver in USB host mode */
 	retu_write(rdev, TAHVO_REG_USBR, USBR_REGOUT | USBR_NSUSPEND |
@@ -148,7 +148,7 @@ static void tahvo_usb_become_peripheral(struct tahvo_usb *tu)
 {
 	struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent);
 
-	extcon_set_cable_state(&tu->extcon, "USB-HOST", false);
+	extcon_set_cable_state(&tu->extcon, "USB-Host", false);
 
 	/* Power up transceiver and set it in USB peripheral mode */
 	retu_write(rdev, TAHVO_REG_USBR, USBR_SLAVE_CONTROL | USBR_REGOUT |
@@ -376,7 +376,7 @@ static int tahvo_usb_probe(struct platform_device *pdev)
 	}
 
 	/* Set the initial cable state. */
-	extcon_set_cable_state(&tu->extcon, "USB-HOST",
+	extcon_set_cable_state(&tu->extcon, "USB-Host",
 			       tu->tahvo_mode == TAHVO_MODE_HOST);
 	extcon_set_cable_state(&tu->extcon, "USB", tu->vbus_state);
 
Signature · 6 lines
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#37 lore raw

PATCH v2 3/7 ARM: dts: dra7-evm: Add extcon nodes for USB

In reply to Roger Quadros

On this EVM, the USB cable state has to be determined via the ID pin tied to a GPIO line. We use the gpio-usb-extcon driver to read the ID pin and the extcon framework to forward the USB cable state information to the USB driver so the controller can be configured in the right mode (host/peripheral).

Gets USB peripheral mode to work on this EVM.

---
 arch/arm/boot/dts/dra7-evm.dts | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
arch/arm/boot/dts/dra7-evm.dts +31 -0
index ad4118f..746cddb 100644
@@ -26,6 +26,16 @@
 		regulator-max-microvolt = <3300000>;
 	};
 
+	extcon_usb1: extcon_usb1 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&pcf_gpio_21 1 GPIO_ACTIVE_HIGH>;
+	};
+
+	extcon_usb2: extcon_usb2 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&pcf_gpio_21 2 GPIO_ACTIVE_HIGH>;
+	};
+
 	vtt_fixed: fixedregulator-vtt {
 		compatible = "regulator-fixed";
 		regulator-name = "vtt_fixed";
@@ -391,6 +401,19 @@
 			};
 		};
 	};
+
+	pcf_gpio_21: gpio@21 {
+		compatible = "ti,pcf8575";
+		reg = <0x21>;
+		lines-initial-states = <0x1408>;
+		gpio-controller;
+		#gpio-cells = <2>;
+		interrupt-parent = <&gpio6>;
+		interrupts = <11 IRQ_TYPE_EDGE_FALLING>;
+		interrupt-controller;
+		#interrupt-cells = <2>;
+	};
+
 };
 
 &i2c2 {
@@ -520,6 +543,14 @@
 	};
 };
 
+&omap_dwc3_1 {
+	extcon = <&extcon_usb1>;
+};
+
+&omap_dwc3_2 {
+	extcon = <&extcon_usb2>;
+};
+
 &usb1 {
 	dr_mode = "peripheral";
 	pinctrl-names = "default";
Signature · 1 line
2.1.0
#38 lore raw

PATCH v2 4/7 ARM: dts: dra72-evm: Add extcon nodes for USB

In reply to Roger Quadros

On this EVM, the USB cable state has to be determined via the ID pin tied to a GPIO line. We use the gpio-usb-extcon driver to read the ID pin and the extcon framework to forward the USB cable state information to the USB driver so the controller can be configured in the right mode (host/peripheral).

Gets USB peripheral mode to work on this EVM.

---
 arch/arm/boot/dts/dra72-evm.dts | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
arch/arm/boot/dts/dra72-evm.dts +31 -0
index 89085d0..ce8e243 100644
@@ -8,6 +8,7 @@
 /dts-v1/;
 
 #include "dra72x.dtsi"
+#include <dt-bindings/gpio/gpio.h>
 
 / {
 	model = "TI DRA722";
@@ -24,6 +25,16 @@
 		regulator-min-microvolt = <3300000>;
 		regulator-max-microvolt = <3300000>;
 	};
+
+	extcon_usb1: extcon_usb1 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&pcf_gpio_21 1 GPIO_ACTIVE_HIGH>;
+	};
+
+	extcon_usb2: extcon_usb2 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&pcf_gpio_21 2 GPIO_ACTIVE_HIGH>;
+	};
 };
 
 &dra7_pmx_core {
@@ -243,6 +254,18 @@
 			ti,palmas-long-press-seconds = <6>;
 		};
 	};
+
+	pcf_gpio_21: gpio@21 {
+		compatible = "ti,pcf8575";
+		reg = <0x21>;
+		lines-initial-states = <0x1408>;
+		gpio-controller;
+		#gpio-cells = <2>;
+		interrupt-parent = <&gpio6>;
+		interrupts = <11 IRQ_TYPE_EDGE_FALLING>;
+		interrupt-controller;
+		#interrupt-cells = <2>;
+	};
 };
 
 &uart1 {
@@ -345,6 +368,14 @@
 	phy-supply = <&ldo4_reg>;
 };
 
+&omap_dwc3_1 {
+	extcon = <&extcon_usb1>;
+};
+
+&omap_dwc3_2 {
+	extcon = <&extcon_usb2>;
+};
+
 &usb1 {
 	dr_mode = "peripheral";
 	pinctrl-names = "default";
Signature · 1 line
2.1.0
#39 lore raw

PATCH v2 5/7 ARM: dts: am57xx-beagle-x15: Add extcon nodes for USB

In reply to Roger Quadros

On this EVM, the USB cable state has to be determined via the ID pin tied to a GPIO line. We use the gpio-usb-extcon driver to read the ID pin and the extcon framework to forward the USB cable state information to the USB driver so the controller can be configured in the right mode (host/peripheral).

NOTE: the ports on this board cannot switch roles. They are configured either host or peripheral by hardwiring the respective ID pins.

---
 arch/arm/boot/dts/am57xx-beagle-x15.dts | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
arch/arm/boot/dts/am57xx-beagle-x15.dts +33 -0
index 49edbda..ad1833b 100644
@@ -80,6 +80,20 @@
 			default-state = "off";
 		};
 	};
+
+	extcon_usb1: extcon_usb1 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&gpio7 25 GPIO_ACTIVE_HIGH>;
+		pinctrl-names = "default";
+		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>;
+	};
 };
 
 &dra7_pmx_core {
@@ -164,6 +178,17 @@
 		>;
 	};
 
+	extcon_usb1_pins: extcon_usb1_pins {
+		pinctrl-single,pins = <
+			0x3ec (PIN_INPUT_PULLUP | MUX_MODE14) /* uart1_rtsn.gpio7_25 */
+		>;
+	};
+
+	extcon_usb2_pins: extcon_usb2_pins {
+		pinctrl-single,pins = <
+			0x3e8 (PIN_INPUT_PULLUP | MUX_MODE14) /* uart1_ctsn.gpio7_24 */
+		>;
+	};
 };
 
 &i2c1 {
@@ -403,3 +428,11 @@
 	pinctrl-names = "default";
 	pinctrl-0 = <&usb1_pins>;
 };
+
+&omap_dwc3_1 {
+	extcon = <&extcon_usb1>;
+};
+
+&omap_dwc3_2 {
+	extcon = <&extcon_usb2>;
+};
Signature · 1 line
2.1.0
#40 lore raw

PATCH v2 6/7 ARM: dts: am57xx-beagle-x15: Fix USB2 mode

In reply to Roger Quadros

On this board USB2 is meant to be used as peripheral only. The ID pin for USB2 is hardwired HIGH.

---
 arch/arm/boot/dts/am57xx-beagle-x15.dts | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/boot/dts/am57xx-beagle-x15.dts +4 -0
index ad1833b..2115dda 100644
@@ -436,3 +436,7 @@
 &omap_dwc3_2 {
 	extcon = <&extcon_usb2>;
 };
+
+&usb2 {
+	dr_mode = "peripheral";
+};
Signature · 1 line
2.1.0
#41 lore raw

PATCH v2 7/7 ARM: omap2plus_defconfig: Enable EXTCON_GPIO_USB

In reply to Roger Quadros

This driver is needed for USB cable type detection on dra7-evm, dra72-evm and am57xx-beagle-x15.

---
 arch/arm/configs/omap2plus_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/omap2plus_defconfig +1 -0
index 667d9d5..7e10e58 100644
@@ -326,6 +326,7 @@ CONFIG_DMADEVICES=y
 CONFIG_TI_EDMA=y
 CONFIG_DMA_OMAP=y
 CONFIG_EXTCON=y
+CONFIG_EXTCON_USB_GPIO=m
 CONFIG_EXTCON_PALMAS=y
 CONFIG_PWM=y
 CONFIG_PWM_TIECAP=y
Signature · 1 line
2.1.0
#2 lore raw

Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

In reply to Roger Quadros

Hi Roger,

This patch looks good to me. But I add some comment. If you modify some comment, I'll apply this patch on 3.21 queue.

Quoted 39 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-Host (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  20 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 214 +++++++++++++++++++++
 4 files changed, 242 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +9 -0
new file mode 100644
index 0000000..ab52a85
@@ -0,0 +1,20 @@
+USB GPIO Extcon device
+
+This is a virtual device used to generate USB cable states from the USB ID pin
+connected to a GPIO pin.
+
+Required properties:
+- compatible: Should be "linux,extcon-usb-gpio"
+- id-gpio: gpio for USB ID pin. See gpio binding.
+

Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt line 19

Quoted 10 lines
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +10 -0
+Example:
+       extcon_usb1 {
+               compatible = "linux,extcon-usb-gpio";
+               id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+       }
+
+       usb@1 {
+               ...
+               extcon = <&extcon_usb1>;
+               ...

I don' want to use '...' for example.
How about using omap usecase in your patch4[1] as following?
[1] ARM: dts: dra72-evm: Add extcon nodes for USB

            &omap_dwc3_1 {
                        extcon = <&extcon_usb1>;
            };

drivers/extcon/Kconfig config EXTCON_SM5502 · line 98

Quoted 12 lines
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +1 -0
+       };
drivers/extcon/Kconfig +3 -0
index 6a1f7de..e4c01ab 100644
@@ -93,4 +93,11 @@ config EXTCON_SM5502
          Silicon Mitus SM5502. The SM5502 is a USB port accessory
          detector and switch.
 
+config EXTCON_USB_GPIO
+       tristate "USB GPIO extcon support"
+       depends on GPIOLIB

How about use 'select' keyword instead of 'depends on'?
- depends on GPIOLIB -> select GPIOLIB

Quoted 20 lines
drivers/extcon/Kconfig +4 -0
+       help
+         Say Y here to enable GPIO based USB cable detection extcon support.
+         Used typically if GPIO is used for USB ID pin detection.
+
 endif # MULTISTATE_SWITCH
drivers/extcon/Makefile +1 -0
index 0370b42..6a08a98 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_EXTCON_MAX8997)  += extcon-max8997.o
 obj-$(CONFIG_EXTCON_PALMAS)    += extcon-palmas.o
 obj-$(CONFIG_EXTCON_RT8973A)   += extcon-rt8973a.o
 obj-$(CONFIG_EXTCON_SM5502)    += extcon-sm5502.o
+obj-$(CONFIG_EXTCON_USB_GPIO)  += extcon-usb-gpio.o
drivers/extcon/extcon-usb-gpio.c new file +0 -0
new file mode 100644
index 0000000..a20aa39

drivers/extcon/extcon-usb-gpio.c line 2

Quoted 2 lines
drivers/extcon/extcon-usb-gpio.c new file +2 -0
@@ -0,0 +1,214 @@
+/**
+ * drivers/extcon/extcon_usb_gpio.c - USB GPIO extcon driver

You should use the '-' instead of '_'.
- s/extcon_usb_gpio.c/extcon-usb-gpio.c

Quoted 49 lines
drivers/extcon/extcon-usb-gpio.c new file +49 -0
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Roger Quadros <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/extcon.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+
+#define USB_GPIO_DEBOUNCE_MS   20      /* ms */
+
+struct usb_extcon_info {
+       struct device *dev;
+       struct extcon_dev *edev;
+
+       struct gpio_desc *id_gpiod;
+       int id_irq;
+
+       unsigned long debounce_jiffies;
+       struct delayed_work wq_detcable;
+};
+
+/* List of detectable cables */
+enum {
+       EXTCON_CABLE_USB = 0,
+       EXTCON_CABLE_USB_HOST,
+
+       EXTCON_CABLE_END,
+};
+
+static const char *usb_extcon_cable[] = {
+       [EXTCON_CABLE_USB] = "USB",
+       [EXTCON_CABLE_USB_HOST] = "USB-Host",

drivers/extcon/extcon-usb-gpio.c line 61

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+       NULL,
+};
+
+static void usb_extcon_detect_cable(struct work_struct *work)
+{
+       int id;
+       struct usb_extcon_info *info;
+
+       info  = container_of(to_delayed_work(work), struct usb_extcon_info,
+                            wq_detcable);

Simplify container_of statement as following:
struct usb_extcon_info *info = container_of(to_delayed_work(work),
struct
usb_extcon_info, wq_detcable);

Quoted 26 lines
drivers/extcon/extcon-usb-gpio.c new file +26 -0
+
+       /* check ID and update cable state */
+       id = gpiod_get_value_cansleep(info->id_gpiod);
+       if (id) {
+               /*
+                * ID = 1 means USB HOST cable detached.
+                * As we don't have event for USB peripheral cable attached,
+                * we simulate USB peripheral attach here.
+                */
+               extcon_set_cable_state(info->edev,
+                                      usb_extcon_cable[EXTCON_CABLE_USB_HOST],
+                                      false);
+               extcon_set_cable_state(info->edev,
+                                      usb_extcon_cable[EXTCON_CABLE_USB],
+                                      true);
+       } else {
+               /*
+                * ID = 0 means USB HOST cable attached.
+                * As we don't have event for USB peripheral cable detached,
+                * we simulate USB peripheral detach here.
+                */
+               extcon_set_cable_state(info->edev,
+                                      usb_extcon_cable[EXTCON_CABLE_USB],
+                                      false);
+               extcon_set_cable_state(info->edev,
+                                      usb_extcon_cable[EXTCON_CABLE_USB_HOST],

drivers/extcon/extcon-usb-gpio.c line 97

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+                                      true);
+       }
+}
+
+static irqreturn_t usb_irq_handler(int irq, void *dev_id)
+{
+       struct usb_extcon_info *info = dev_id;
+
+       queue_delayed_work(system_power_efficient_wq, &info->wq_detcable,
+                          info->debounce_jiffies);

Need to add blank line.

Quoted 50 lines
drivers/extcon/extcon-usb-gpio.c new file +50 -0
+       return IRQ_HANDLED;
+}
+
+static int usb_extcon_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct device_node *np = dev->of_node;
+       struct usb_extcon_info *info;
+       int ret;
+
+       if (!np)
+               return -EINVAL;
+
+       info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
+       if (!info)
+               return -ENOMEM;
+
+       info->dev = dev;
+       info->id_gpiod = devm_gpiod_get(&pdev->dev, "id");
+       if (IS_ERR(info->id_gpiod)) {
+               dev_err(dev, "failed to get ID GPIO\n");
+               return PTR_ERR(info->id_gpiod);
+       }
+
+       ret = gpiod_set_debounce(info->id_gpiod,
+                                USB_GPIO_DEBOUNCE_MS * 1000);
+       if (ret < 0)
+               info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEBOUNCE_MS);
+
+       INIT_DELAYED_WORK(&info->wq_detcable, usb_extcon_detect_cable);
+
+       info->id_irq = gpiod_to_irq(info->id_gpiod);
+       if (info->id_irq < 0) {
+               dev_err(dev, "failed to get ID IRQ\n");
+               return info->id_irq;
+       }
+
+       ret = devm_request_threaded_irq(dev, info->id_irq, NULL,
+                                       usb_irq_handler,
+                                       IRQF_SHARED | IRQF_ONESHOT |
+                                       IRQF_NO_SUSPEND,
+                                       pdev->name, info);
+       if (ret < 0) {
+               dev_err(dev, "failed to request handler for ID IRQ\n");
+               return ret;
+       }
+
+       info->edev = devm_extcon_dev_allocate(dev, usb_extcon_cable);
+       if (IS_ERR(info->edev)) {
+               dev_err(dev, "failed to allocate extcon device\n");

drivers/extcon/extcon-usb-gpio.c line 157

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+               return -ENOMEM;
+       }
+
+       ret = devm_extcon_dev_register(dev, info->edev);
+       if (ret < 0) {
+               dev_err(dev, "failed to register extcon device\n");
+               return ret;
+       }
+
+       platform_set_drvdata(pdev, info);

I prefer to execute the device_init_wakeup() function as following for suspend/resume function:

            device_init_wakeup(&pdev->dev, 1);

drivers/extcon/extcon-usb-gpio.c line 169

Quoted 12 lines
drivers/extcon/extcon-usb-gpio.c new file +12 -0
+
+       /* Perform initial detection */
+       usb_extcon_detect_cable(&info->wq_detcable.work);
+
+       return 0;
+}
+
+static int usb_extcon_remove(struct platform_device *pdev)
+{
+       struct usb_extcon_info *info = platform_get_drvdata(pdev);
+
+       cancel_delayed_work_sync(&info->wq_detcable);

Need to add blank line.

drivers/extcon/extcon-usb-gpio.c line 178

Quoted 9 lines
drivers/extcon/extcon-usb-gpio.c new file +9 -0
+       return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int usb_extcon_suspend(struct device *dev)
+{
+       struct usb_extcon_info *info = dev_get_drvdata(dev);
+
+       enable_irq_wake(info->id_irq);

I prefer to use device_may_wakeup() function for whether executing enable_irq_wake() or not. Also, The disable_irq() in the suspend function would prevent us from discarding interrupt before wakeup from suspend completely.

            if (device_may_wakeup(dev))
                     enable_irq_wake(info->id_irq);
            disable_irq(info->id_irq);

drivers/extcon/extcon-usb-gpio.c line 186

Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+       return 0;
+}
+
+static int usb_extcon_resume(struct device *dev)
+{
+       struct usb_extcon_info *info = dev_get_drvdata(dev);
+
+       disable_irq_wake(info->id_irq);

ditto as following:

            if (device_may_wakeup(dev))
                     disable_irq_wake(info->id_irq);
            enable_irq(info->id_irq);

drivers/extcon/extcon-usb-gpio.c line 196

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+       return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(usb_extcon_pm_ops,
+                        usb_extcon_suspend, usb_extcon_resume);
+
+static struct of_device_id usb_extcon_dt_match[] = {
+       { .compatible = "linux,extcon-usb-gpio", },
+       { /* end */ }

I prefer to use 'sentinel' word instead of 'end'

Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+};
+MODULE_DEVICE_TABLE(of, usb_extcon_dt_match);
+
+static struct platform_driver usb_extcon_driver = {
+       .probe          = usb_extcon_probe,
+       .remove         = usb_extcon_remove,
+       .driver         = {
+               .name   = "extcon-usb-gpio",

drivers/extcon/extcon-usb-gpio.c line 214

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+               .pm     = &usb_extcon_pm_ops,
+               .of_match_table = usb_extcon_dt_match,
+       },
+};
+
+module_platform_driver(usb_extcon_driver);
+
+MODULE_AUTHOR("Roger Quadros <[email protected]>");
+MODULE_DESCRIPTION("USB GPIO extcon driver");
+MODULE_LICENSE("GPL v2");

Thanks,
Chanwoo Choi
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

Hi Chanwoo,

All your comments are valid. Need some clarification on one comment.

Quoted 30 lines · Chanwoo Choi

Hi Roger,

This patch looks good to me. But I add some comment. If you modify some comment, I'll apply this patch on 3.21 queue.

Quoted 24 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-Host (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  20 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 214 +++++++++++++++++++++
 4 files changed, 242 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c

<snip>

Quoted 32 lines
Quoted 32 lines
drivers/extcon/extcon-usb-gpio.c new file +32 -0
+
+static int usb_extcon_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct device_node *np = dev->of_node;
+       struct usb_extcon_info *info;
+       int ret;
+
+       if (!np)
+               return -EINVAL;
+
+       info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
+       if (!info)
+               return -ENOMEM;
+
+       info->dev = dev;
+       info->id_gpiod = devm_gpiod_get(&pdev->dev, "id");
+       if (IS_ERR(info->id_gpiod)) {
+               dev_err(dev, "failed to get ID GPIO\n");
+               return PTR_ERR(info->id_gpiod);
+       }
+
+       ret = gpiod_set_debounce(info->id_gpiod,
+                                USB_GPIO_DEBOUNCE_MS * 1000);
+       if (ret < 0)
+               info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEBOUNCE_MS);
+
+       INIT_DELAYED_WORK(&info->wq_detcable, usb_extcon_detect_cable);
+
+       info->id_irq = gpiod_to_irq(info->id_gpiod);
+       if (info->id_irq < 0) {
+               dev_err(dev, "failed to get ID IRQ\n");
Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 139

Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+               return info->id_irq;
+       }
+
+       ret = devm_request_threaded_irq(dev, info->id_irq, NULL,
+                                       usb_irq_handler,
+                                       IRQF_SHARED | IRQF_ONESHOT |
+                                       IRQF_NO_SUSPEND,
+                                       pdev->name, info);

use of IRQF_NO_SUSPEND is not recommended to be used together with IRQF_SHARED so I'll remove IRQF_SHARED from here if we decide to stick with IRQF_NO_SUSPEND. More on this below.

Quoted 38 lines
Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+       if (ret < 0) {
+               dev_err(dev, "failed to request handler for ID IRQ\n");
+               return ret;
+       }
+
+       info->edev = devm_extcon_dev_allocate(dev, usb_extcon_cable);
+       if (IS_ERR(info->edev)) {
+               dev_err(dev, "failed to allocate extcon device\n");

drivers/extcon/extcon-usb-gpio.c line 157

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+               return -ENOMEM;
+       }
+
+       ret = devm_extcon_dev_register(dev, info->edev);
+       if (ret < 0) {
+               dev_err(dev, "failed to register extcon device\n");
+               return ret;
+       }
+
+       platform_set_drvdata(pdev, info);

I prefer to execute the device_init_wakeup() function as following for suspend/resume function:

            device_init_wakeup(&pdev->dev, 1);

drivers/extcon/extcon-usb-gpio.c line 169

Quoted 12 lines
drivers/extcon/extcon-usb-gpio.c new file +12 -0
+
+       /* Perform initial detection */
+       usb_extcon_detect_cable(&info->wq_detcable.work);
+
+       return 0;
+}
+
+static int usb_extcon_remove(struct platform_device *pdev)
+{
+       struct usb_extcon_info *info = platform_get_drvdata(pdev);
+
+       cancel_delayed_work_sync(&info->wq_detcable);

Need to add blank line.

Quoted 15 lines

drivers/extcon/extcon-usb-gpio.c line 178

Quoted 9 lines
drivers/extcon/extcon-usb-gpio.c new file +9 -0
+       return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int usb_extcon_suspend(struct device *dev)
+{
+       struct usb_extcon_info *info = dev_get_drvdata(dev);
+
+       enable_irq_wake(info->id_irq);

I prefer to use device_may_wakeup() function for whether executing enable_irq_wake() or not. Also, The disable_irq() in the suspend function would prevent us from discarding interrupt before wakeup from suspend completely.

I need more clarification here.

If we are going to use enable_irq_wake() here then what is the point of IRQF_NO_SUSPEND?

Quoted 1 line

From Documentation/power/suspend-and-interrupts.txt I see that interrupts marked

as IRQF_NO_SUSPEND should not be configured for system wakeup using enable_irq_wake().

what is your preference?

Is it good enough to not use IRQF_NO_SUSPEND but use enable_irq_wake() instead to enable system wakeup for that IRQ.

Quoted 3 lines
            if (device_may_wakeup(dev))
                     enable_irq_wake(info->id_irq);
            disable_irq(info->id_irq);

why do we need to disable irq here? How will the system wakeup if IRQ is disabled?

Quoted 5 lines

drivers/extcon/extcon-usb-gpio.c line 164

Quoted 5 lines
drivers/extcon/extcon-usb-gpio.c new file +3 -0
+       return 0;
+}
+

<snip>

cheers,
-roger

maintainer
#4 lore raw

Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

Hi Roger,

Quoted 141 lines · Roger Quadros

Hi Chanwoo,

All your comments are valid. Need some clarification on one comment.

Quoted 30 lines · Chanwoo Choi

Hi Roger,

This patch looks good to me. But I add some comment. If you modify some comment, I'll apply this patch on 3.21 queue.

Quoted 24 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-Host (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  20 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 214 +++++++++++++++++++++
 4 files changed, 242 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c

<snip>

Quoted 32 lines
Quoted 32 lines
drivers/extcon/extcon-usb-gpio.c new file +32 -0
+
+static int usb_extcon_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct device_node *np = dev->of_node;
+       struct usb_extcon_info *info;
+       int ret;
+
+       if (!np)
+               return -EINVAL;
+
+       info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
+       if (!info)
+               return -ENOMEM;
+
+       info->dev = dev;
+       info->id_gpiod = devm_gpiod_get(&pdev->dev, "id");
+       if (IS_ERR(info->id_gpiod)) {
+               dev_err(dev, "failed to get ID GPIO\n");
+               return PTR_ERR(info->id_gpiod);
+       }
+
+       ret = gpiod_set_debounce(info->id_gpiod,
+                                USB_GPIO_DEBOUNCE_MS * 1000);
+       if (ret < 0)
+               info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEBOUNCE_MS);
+
+       INIT_DELAYED_WORK(&info->wq_detcable, usb_extcon_detect_cable);
+
+       info->id_irq = gpiod_to_irq(info->id_gpiod);
+       if (info->id_irq < 0) {
+               dev_err(dev, "failed to get ID IRQ\n");
Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 139

Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+               return info->id_irq;
+       }
+
+       ret = devm_request_threaded_irq(dev, info->id_irq, NULL,
+                                       usb_irq_handler,
+                                       IRQF_SHARED | IRQF_ONESHOT |
+                                       IRQF_NO_SUSPEND,
+                                       pdev->name, info);

use of IRQF_NO_SUSPEND is not recommended to be used together with IRQF_SHARED so I'll remove IRQF_SHARED from here if we decide to stick with IRQF_NO_SUSPEND. More on this below.

Quoted 38 lines
Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+       if (ret < 0) {
+               dev_err(dev, "failed to request handler for ID IRQ\n");
+               return ret;
+       }
+
+       info->edev = devm_extcon_dev_allocate(dev, usb_extcon_cable);
+       if (IS_ERR(info->edev)) {
+               dev_err(dev, "failed to allocate extcon device\n");

drivers/extcon/extcon-usb-gpio.c line 157

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+               return -ENOMEM;
+       }
+
+       ret = devm_extcon_dev_register(dev, info->edev);
+       if (ret < 0) {
+               dev_err(dev, "failed to register extcon device\n");
+               return ret;
+       }
+
+       platform_set_drvdata(pdev, info);

I prefer to execute the device_init_wakeup() function as following for suspend/resume function:

            device_init_wakeup(&pdev->dev, 1);

drivers/extcon/extcon-usb-gpio.c line 169

Quoted 12 lines
drivers/extcon/extcon-usb-gpio.c new file +12 -0
+
+       /* Perform initial detection */
+       usb_extcon_detect_cable(&info->wq_detcable.work);
+
+       return 0;
+}
+
+static int usb_extcon_remove(struct platform_device *pdev)
+{
+       struct usb_extcon_info *info = platform_get_drvdata(pdev);
+
+       cancel_delayed_work_sync(&info->wq_detcable);

Need to add blank line.

Quoted 15 lines

drivers/extcon/extcon-usb-gpio.c line 178

Quoted 9 lines
drivers/extcon/extcon-usb-gpio.c new file +9 -0
+       return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int usb_extcon_suspend(struct device *dev)
+{
+       struct usb_extcon_info *info = dev_get_drvdata(dev);
+
+       enable_irq_wake(info->id_irq);

I prefer to use device_may_wakeup() function for whether executing enable_irq_wake() or not. Also, The disable_irq() in the suspend function would prevent us from discarding interrupt before wakeup from suspend completely.

I need more clarification here.

If we are going to use enable_irq_wake() here then what is the point of IRQF_NO_SUSPEND?

Quoted 7 lines
Quoted 1 line

From Documentation/power/suspend-and-interrupts.txt I see that interrupts marked

as IRQF_NO_SUSPEND should not be configured for system wakeup using enable_irq_wake().

what is your preference?

Is it good enough to not use IRQF_NO_SUSPEND but use enable_irq_wake() instead to enable system wakeup for that IRQ.

I'm sorry for confusion about usage both IRQF_NO_SUSPEND and enable_irq_wake(). If suspend() function in device driver executes the enable_irq_wake(), IRQF_NO_SUSPEND flag is not necessary.

I think that we better use enable_irq_wake() instead of adding IRQF_NO_SUSPEND flag. I'll expect to remove IRQF_NO_SUSPEND flag when requesting gpio interrupt.

Quoted 6 lines
Quoted 4 lines
            if (device_may_wakeup(dev))
                     enable_irq_wake(info->id_irq);
            disable_irq(info->id_irq);

why do we need to disable irq here? How will the system wakeup if IRQ is disabled?

The disable_irq() may make the interrupt as masking state. Although interrput is masking state(disable), interrup can happen. but, the interrupt may remain the pending state without discarding it.

And then,
When resume() function in extcon-usb-gpio.c executes enable_irq(info->id_irq), pending interrupt will happen and executes the interrupt handler(usb_irq_handler).

If we don't execute disable_irq() in suspend function, info->id->irq interrupt might happen before completing the resume sequence of extcon-gpio-usb driver.

Thanks,
Chanwoo Choi
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

Chanwoo,

Quoted 152 lines · Chanwoo Choi

Hi Roger,

Quoted 141 lines · Roger Quadros

Hi Chanwoo,

All your comments are valid. Need some clarification on one comment.

Quoted 30 lines · Chanwoo Choi

Hi Roger,

This patch looks good to me. But I add some comment. If you modify some comment, I'll apply this patch on 3.21 queue.

Quoted 24 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-Host (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  20 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 214 +++++++++++++++++++++
 4 files changed, 242 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c

<snip>

Quoted 32 lines
Quoted 32 lines
drivers/extcon/extcon-usb-gpio.c new file +32 -0
+
+static int usb_extcon_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct device_node *np = dev->of_node;
+       struct usb_extcon_info *info;
+       int ret;
+
+       if (!np)
+               return -EINVAL;
+
+       info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
+       if (!info)
+               return -ENOMEM;
+
+       info->dev = dev;
+       info->id_gpiod = devm_gpiod_get(&pdev->dev, "id");
+       if (IS_ERR(info->id_gpiod)) {
+               dev_err(dev, "failed to get ID GPIO\n");
+               return PTR_ERR(info->id_gpiod);
+       }
+
+       ret = gpiod_set_debounce(info->id_gpiod,
+                                USB_GPIO_DEBOUNCE_MS * 1000);
+       if (ret < 0)
+               info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEBOUNCE_MS);
+
+       INIT_DELAYED_WORK(&info->wq_detcable, usb_extcon_detect_cable);
+
+       info->id_irq = gpiod_to_irq(info->id_gpiod);
+       if (info->id_irq < 0) {
+               dev_err(dev, "failed to get ID IRQ\n");
Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 139

Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+               return info->id_irq;
+       }
+
+       ret = devm_request_threaded_irq(dev, info->id_irq, NULL,
+                                       usb_irq_handler,
+                                       IRQF_SHARED | IRQF_ONESHOT |
+                                       IRQF_NO_SUSPEND,
+                                       pdev->name, info);

use of IRQF_NO_SUSPEND is not recommended to be used together with IRQF_SHARED so I'll remove IRQF_SHARED from here if we decide to stick with IRQF_NO_SUSPEND. More on this below.

Quoted 38 lines
Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+       if (ret < 0) {
+               dev_err(dev, "failed to request handler for ID IRQ\n");
+               return ret;
+       }
+
+       info->edev = devm_extcon_dev_allocate(dev, usb_extcon_cable);
+       if (IS_ERR(info->edev)) {
+               dev_err(dev, "failed to allocate extcon device\n");

drivers/extcon/extcon-usb-gpio.c line 157

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+               return -ENOMEM;
+       }
+
+       ret = devm_extcon_dev_register(dev, info->edev);
+       if (ret < 0) {
+               dev_err(dev, "failed to register extcon device\n");
+               return ret;
+       }
+
+       platform_set_drvdata(pdev, info);

I prefer to execute the device_init_wakeup() function as following for suspend/resume function:

            device_init_wakeup(&pdev->dev, 1);

drivers/extcon/extcon-usb-gpio.c line 169

Quoted 12 lines
drivers/extcon/extcon-usb-gpio.c new file +12 -0
+
+       /* Perform initial detection */
+       usb_extcon_detect_cable(&info->wq_detcable.work);
+
+       return 0;
+}
+
+static int usb_extcon_remove(struct platform_device *pdev)
+{
+       struct usb_extcon_info *info = platform_get_drvdata(pdev);
+
+       cancel_delayed_work_sync(&info->wq_detcable);

Need to add blank line.

Quoted 15 lines

drivers/extcon/extcon-usb-gpio.c line 178

Quoted 9 lines
drivers/extcon/extcon-usb-gpio.c new file +9 -0
+       return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int usb_extcon_suspend(struct device *dev)
+{
+       struct usb_extcon_info *info = dev_get_drvdata(dev);
+
+       enable_irq_wake(info->id_irq);

I prefer to use device_may_wakeup() function for whether executing enable_irq_wake() or not. Also, The disable_irq() in the suspend function would prevent us from discarding interrupt before wakeup from suspend completely.

I need more clarification here.

If we are going to use enable_irq_wake() here then what is the point of IRQF_NO_SUSPEND?

Quoted 7 lines
Quoted 1 line

From Documentation/power/suspend-and-interrupts.txt I see that interrupts marked

as IRQF_NO_SUSPEND should not be configured for system wakeup using enable_irq_wake().

what is your preference?

Is it good enough to not use IRQF_NO_SUSPEND but use enable_irq_wake() instead to enable system wakeup for that IRQ.

Quoted 7 lines

I'm sorry for confusion about usage both IRQF_NO_SUSPEND and enable_irq_wake(). If suspend() function in device driver executes the enable_irq_wake(), IRQF_NO_SUSPEND flag is not necessary.

I think that we better use enable_irq_wake() instead of adding IRQF_NO_SUSPEND flag. I'll expect to remove IRQF_NO_SUSPEND flag when requesting gpio interrupt.

OK.

Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
            if (device_may_wakeup(dev))
                     enable_irq_wake(info->id_irq);
            disable_irq(info->id_irq);

why do we need to disable irq here? How will the system wakeup if IRQ is disabled?

The disable_irq() may make the interrupt as masking state. Although interrput is masking state(disable), interrup can happen. but, the interrupt may remain the pending state without discarding it.

Quoted 7 lines

And then,
When resume() function in extcon-usb-gpio.c executes enable_irq(info->id_irq), pending interrupt will happen and executes the interrupt handler(usb_irq_handler).

If we don't execute disable_irq() in suspend function, info->id->irq interrupt might happen before completing the resume sequence of extcon-gpio-usb driver.

How will that cause a problem? If an interrupt happens _before_ the system enters SUSPEND state then kernel should abort the suspend. This should be taken care by kernel PM core and not the device driver.

I still fail to understand that we need to call disable_irq() in .suspend() and enable_irq() in .resume()

can you point me to any other drivers doing so?

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#6 lore raw

Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

Hi Roger,

Quoted 183 lines · Roger Quadros

Chanwoo,

Quoted 152 lines · Chanwoo Choi

Hi Roger,

Quoted 141 lines · Roger Quadros

Hi Chanwoo,

All your comments are valid. Need some clarification on one comment.

Quoted 30 lines · Chanwoo Choi

Hi Roger,

This patch looks good to me. But I add some comment. If you modify some comment, I'll apply this patch on 3.21 queue.

Quoted 24 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-Host (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  20 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 214 +++++++++++++++++++++
 4 files changed, 242 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c

<snip>

Quoted 32 lines
Quoted 32 lines
drivers/extcon/extcon-usb-gpio.c new file +32 -0
+
+static int usb_extcon_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct device_node *np = dev->of_node;
+       struct usb_extcon_info *info;
+       int ret;
+
+       if (!np)
+               return -EINVAL;
+
+       info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
+       if (!info)
+               return -ENOMEM;
+
+       info->dev = dev;
+       info->id_gpiod = devm_gpiod_get(&pdev->dev, "id");
+       if (IS_ERR(info->id_gpiod)) {
+               dev_err(dev, "failed to get ID GPIO\n");
+               return PTR_ERR(info->id_gpiod);
+       }
+
+       ret = gpiod_set_debounce(info->id_gpiod,
+                                USB_GPIO_DEBOUNCE_MS * 1000);
+       if (ret < 0)
+               info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEBOUNCE_MS);
+
+       INIT_DELAYED_WORK(&info->wq_detcable, usb_extcon_detect_cable);
+
+       info->id_irq = gpiod_to_irq(info->id_gpiod);
+       if (info->id_irq < 0) {
+               dev_err(dev, "failed to get ID IRQ\n");
Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 139

Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+               return info->id_irq;
+       }
+
+       ret = devm_request_threaded_irq(dev, info->id_irq, NULL,
+                                       usb_irq_handler,
+                                       IRQF_SHARED | IRQF_ONESHOT |
+                                       IRQF_NO_SUSPEND,
+                                       pdev->name, info);

use of IRQF_NO_SUSPEND is not recommended to be used together with IRQF_SHARED so I'll remove IRQF_SHARED from here if we decide to stick with IRQF_NO_SUSPEND. More on this below.

Quoted 38 lines
Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+       if (ret < 0) {
+               dev_err(dev, "failed to request handler for ID IRQ\n");
+               return ret;
+       }
+
+       info->edev = devm_extcon_dev_allocate(dev, usb_extcon_cable);
+       if (IS_ERR(info->edev)) {
+               dev_err(dev, "failed to allocate extcon device\n");

drivers/extcon/extcon-usb-gpio.c line 157

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+               return -ENOMEM;
+       }
+
+       ret = devm_extcon_dev_register(dev, info->edev);
+       if (ret < 0) {
+               dev_err(dev, "failed to register extcon device\n");
+               return ret;
+       }
+
+       platform_set_drvdata(pdev, info);

I prefer to execute the device_init_wakeup() function as following for suspend/resume function:

            device_init_wakeup(&pdev->dev, 1);

drivers/extcon/extcon-usb-gpio.c line 169

Quoted 12 lines
drivers/extcon/extcon-usb-gpio.c new file +12 -0
+
+       /* Perform initial detection */
+       usb_extcon_detect_cable(&info->wq_detcable.work);
+
+       return 0;
+}
+
+static int usb_extcon_remove(struct platform_device *pdev)
+{
+       struct usb_extcon_info *info = platform_get_drvdata(pdev);
+
+       cancel_delayed_work_sync(&info->wq_detcable);

Need to add blank line.

Quoted 15 lines

drivers/extcon/extcon-usb-gpio.c line 178

Quoted 9 lines
drivers/extcon/extcon-usb-gpio.c new file +9 -0
+       return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int usb_extcon_suspend(struct device *dev)
+{
+       struct usb_extcon_info *info = dev_get_drvdata(dev);
+
+       enable_irq_wake(info->id_irq);

I prefer to use device_may_wakeup() function for whether executing enable_irq_wake() or not. Also, The disable_irq() in the suspend function would prevent us from discarding interrupt before wakeup from suspend completely.

I need more clarification here.

If we are going to use enable_irq_wake() here then what is the point of IRQF_NO_SUSPEND?

Quoted 7 lines
Quoted 1 line

From Documentation/power/suspend-and-interrupts.txt I see that interrupts marked

as IRQF_NO_SUSPEND should not be configured for system wakeup using enable_irq_wake().

what is your preference?

Is it good enough to not use IRQF_NO_SUSPEND but use enable_irq_wake() instead to enable system wakeup for that IRQ.

Quoted 7 lines

I'm sorry for confusion about usage both IRQF_NO_SUSPEND and enable_irq_wake(). If suspend() function in device driver executes the enable_irq_wake(), IRQF_NO_SUSPEND flag is not necessary.

I think that we better use enable_irq_wake() instead of adding IRQF_NO_SUSPEND flag. I'll expect to remove IRQF_NO_SUSPEND flag when requesting gpio interrupt.

OK.

Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
            if (device_may_wakeup(dev))
                     enable_irq_wake(info->id_irq);
            disable_irq(info->id_irq);

why do we need to disable irq here? How will the system wakeup if IRQ is disabled?

The disable_irq() may make the interrupt as masking state. Although interrput is masking state(disable), interrup can happen. but, the interrupt may remain the pending state without discarding it.

Quoted 7 lines

And then,
When resume() function in extcon-usb-gpio.c executes enable_irq(info->id_irq), pending interrupt will happen and executes the interrupt handler(usb_irq_handler).

If we don't execute disable_irq() in suspend function, info->id->irq interrupt might happen before completing the resume sequence of extcon-gpio-usb driver.

Quoted 8 lines

How will that cause a problem? If an interrupt happens _before_ the system enters SUSPEND state then kernel should abort the suspend. This should be taken care by kernel PM core and not the device driver.

I still fail to understand that we need to call disable_irq() in .suspend() and enable_irq() in .resume()

can you point me to any other drivers doing so?

You can refer the suspend function in drivers/mfd/max14577.c or drivers/mfd/max77693.c. The max14577_suspend() includes the detailed comment for why using disable_irq() in suspend function.

In max14577 case, max14577_suspend() use disable_irq() function because of i2c dependency. If max14577 device is wake-up from suspend state before completing the resume sequence of i2c, max14577 may fail to read/write i2c communication.

Thanks,
Chanwoo Choi

#7 lore raw

Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

Chanwoo,

Quoted 193 lines · Chanwoo Choi

Hi Roger,

Quoted 190 lines · Roger Quadros

Chanwoo,

Quoted 152 lines · Chanwoo Choi

Hi Roger,

Quoted 141 lines · Roger Quadros

Hi Chanwoo,

All your comments are valid. Need some clarification on one comment.

Quoted 30 lines · Chanwoo Choi

Hi Roger,

This patch looks good to me. But I add some comment. If you modify some comment, I'll apply this patch on 3.21 queue.

Quoted 24 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-Host (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  20 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 214 +++++++++++++++++++++
 4 files changed, 242 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c

<snip>

Quoted 32 lines
Quoted 32 lines
drivers/extcon/extcon-usb-gpio.c new file +32 -0
+
+static int usb_extcon_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct device_node *np = dev->of_node;
+       struct usb_extcon_info *info;
+       int ret;
+
+       if (!np)
+               return -EINVAL;
+
+       info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
+       if (!info)
+               return -ENOMEM;
+
+       info->dev = dev;
+       info->id_gpiod = devm_gpiod_get(&pdev->dev, "id");
+       if (IS_ERR(info->id_gpiod)) {
+               dev_err(dev, "failed to get ID GPIO\n");
+               return PTR_ERR(info->id_gpiod);
+       }
+
+       ret = gpiod_set_debounce(info->id_gpiod,
+                                USB_GPIO_DEBOUNCE_MS * 1000);
+       if (ret < 0)
+               info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEBOUNCE_MS);
+
+       INIT_DELAYED_WORK(&info->wq_detcable, usb_extcon_detect_cable);
+
+       info->id_irq = gpiod_to_irq(info->id_gpiod);
+       if (info->id_irq < 0) {
+               dev_err(dev, "failed to get ID IRQ\n");
Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 139

Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+               return info->id_irq;
+       }
+
+       ret = devm_request_threaded_irq(dev, info->id_irq, NULL,
+                                       usb_irq_handler,
+                                       IRQF_SHARED | IRQF_ONESHOT |
+                                       IRQF_NO_SUSPEND,
+                                       pdev->name, info);

use of IRQF_NO_SUSPEND is not recommended to be used together with IRQF_SHARED so I'll remove IRQF_SHARED from here if we decide to stick with IRQF_NO_SUSPEND. More on this below.

Quoted 38 lines
Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+       if (ret < 0) {
+               dev_err(dev, "failed to request handler for ID IRQ\n");
+               return ret;
+       }
+
+       info->edev = devm_extcon_dev_allocate(dev, usb_extcon_cable);
+       if (IS_ERR(info->edev)) {
+               dev_err(dev, "failed to allocate extcon device\n");

drivers/extcon/extcon-usb-gpio.c line 157

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+               return -ENOMEM;
+       }
+
+       ret = devm_extcon_dev_register(dev, info->edev);
+       if (ret < 0) {
+               dev_err(dev, "failed to register extcon device\n");
+               return ret;
+       }
+
+       platform_set_drvdata(pdev, info);

I prefer to execute the device_init_wakeup() function as following for suspend/resume function:

            device_init_wakeup(&pdev->dev, 1);

drivers/extcon/extcon-usb-gpio.c line 169

Quoted 12 lines
drivers/extcon/extcon-usb-gpio.c new file +12 -0
+
+       /* Perform initial detection */
+       usb_extcon_detect_cable(&info->wq_detcable.work);
+
+       return 0;
+}
+
+static int usb_extcon_remove(struct platform_device *pdev)
+{
+       struct usb_extcon_info *info = platform_get_drvdata(pdev);
+
+       cancel_delayed_work_sync(&info->wq_detcable);

Need to add blank line.

Quoted 15 lines

drivers/extcon/extcon-usb-gpio.c line 178

Quoted 9 lines
drivers/extcon/extcon-usb-gpio.c new file +9 -0
+       return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int usb_extcon_suspend(struct device *dev)
+{
+       struct usb_extcon_info *info = dev_get_drvdata(dev);
+
+       enable_irq_wake(info->id_irq);

I prefer to use device_may_wakeup() function for whether executing enable_irq_wake() or not. Also, The disable_irq() in the suspend function would prevent us from discarding interrupt before wakeup from suspend completely.

I need more clarification here.

If we are going to use enable_irq_wake() here then what is the point of IRQF_NO_SUSPEND?

Quoted 7 lines
Quoted 1 line

From Documentation/power/suspend-and-interrupts.txt I see that interrupts marked

as IRQF_NO_SUSPEND should not be configured for system wakeup using enable_irq_wake().

what is your preference?

Is it good enough to not use IRQF_NO_SUSPEND but use enable_irq_wake() instead to enable system wakeup for that IRQ.

Quoted 7 lines

I'm sorry for confusion about usage both IRQF_NO_SUSPEND and enable_irq_wake(). If suspend() function in device driver executes the enable_irq_wake(), IRQF_NO_SUSPEND flag is not necessary.

I think that we better use enable_irq_wake() instead of adding IRQF_NO_SUSPEND flag. I'll expect to remove IRQF_NO_SUSPEND flag when requesting gpio interrupt.

OK.

Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
            if (device_may_wakeup(dev))
                     enable_irq_wake(info->id_irq);
            disable_irq(info->id_irq);

why do we need to disable irq here? How will the system wakeup if IRQ is disabled?

The disable_irq() may make the interrupt as masking state. Although interrput is masking state(disable), interrup can happen. but, the interrupt may remain the pending state without discarding it.

Quoted 7 lines

And then,
When resume() function in extcon-usb-gpio.c executes enable_irq(info->id_irq), pending interrupt will happen and executes the interrupt handler(usb_irq_handler).

If we don't execute disable_irq() in suspend function, info->id->irq interrupt might happen before completing the resume sequence of extcon-gpio-usb driver.

How will that cause a problem? If an interrupt happens _before_ the system enters SUSPEND state then kernel should abort the suspend. This should be taken care by kernel PM core and not the device driver.

I still fail to understand that we need to call disable_irq() in .suspend() and enable_irq() in .resume()

Quoted 8 lines
Quoted 1 line

can you point me to any other drivers doing so?

You can refer the suspend function in drivers/mfd/max14577.c or drivers/mfd/max77693.c. The max14577_suspend() includes the detailed comment for why using disable_irq() in suspend function.

In max14577 case, max14577_suspend() use disable_irq() function because of i2c dependency. If max14577 device is wake-up from suspend state before completing the resume sequence of i2c, max14577 may fail to read/write i2c communication.

Thanks for this information. I will add disable/enable_irq() in suspend/resume().

cheers,
-roger

#12 lore raw

PATCH v3 1/7 extcon: usb-gpio: Introduce gpio usb extcon driver

In reply to Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-Host (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v3:
- removed IRQF_NO_SUSPEND flag. Added IRQF_TRIGGER_RISING and IRQF_TRIGGER_FALLING
- Added disable_irq() to suspend() and enable_irq() to resume()

 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  18 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 233 +++++++++++++++++++++
 4 files changed, 259 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +18 -0
new file mode 100644
index 0000000..85fe6b0
@@ -0,0 +1,18 @@
+USB GPIO Extcon device
+
+This is a virtual device used to generate USB cable states from the USB ID pin
+connected to a GPIO pin.
+
+Required properties:
+- compatible: Should be "linux,extcon-usb-gpio"
+- id-gpio: gpio for USB ID pin. See gpio binding.
+
+Example:
+	extcon_usb1 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+	}
+
+	&omap_dwc3_1 {
+		extcon = <&extcon_usb1>;
+	};
drivers/extcon/Kconfig +7 -0
index 6a1f7de..fd11536 100644
@@ -93,4 +93,11 @@ config EXTCON_SM5502
 	  Silicon Mitus SM5502. The SM5502 is a USB port accessory
 	  detector and switch.
 
+config EXTCON_USB_GPIO
+	tristate "USB GPIO extcon support"
+	select GPIOLIB
+	help
+	  Say Y here to enable GPIO based USB cable detection extcon support.
+	  Used typically if GPIO is used for USB ID pin detection.
+
 endif # MULTISTATE_SWITCH
drivers/extcon/Makefile +1 -0
index 0370b42..6a08a98 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_EXTCON_MAX8997)	+= extcon-max8997.o
 obj-$(CONFIG_EXTCON_PALMAS)	+= extcon-palmas.o
 obj-$(CONFIG_EXTCON_RT8973A)	+= extcon-rt8973a.o
 obj-$(CONFIG_EXTCON_SM5502)	+= extcon-sm5502.o
+obj-$(CONFIG_EXTCON_USB_GPIO)	+= extcon-usb-gpio.o
drivers/extcon/extcon-usb-gpio.c new file +233 -0

233 lines not on this page · raw message

Signature · 1 line
2.1.0
maintainer
#8 lore raw

Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

In reply to Roger Quadros
Quoted 7 lines · Roger Quadros
Quoted 6 lines · Chanwoo Choi
Quoted 5 lines

I still fail to understand that we need to call disable_irq() in .suspend() and enable_irq() in .resume()

can you point me to any other drivers doing so?

Quoted 8 lines
Quoted 6 lines

You can refer the suspend function in drivers/mfd/max14577.c or drivers/mfd/max77693.c. The max14577_suspend() includes the detailed comment for why using disable_irq() in suspend function.

In max14577 case, max14577_suspend() use disable_irq() function because of i2c dependency. If max14577 device is wake-up from suspend state before completing the resume sequence of i2c, max14577 may fail to read/write i2c communication.

Thanks for this information. I will add disable/enable_irq() in suspend/resume().

Are the .dts changes safe for me to apply already?

Regards,

Tony

maintainer
#13 lore raw

Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

In reply to Roger Quadros

Hi Roger,

We need to discuss one point about 'id_irqwake'.
I don't recommend to use 'id_irqwake' field.

And I catch build warning by using "select" keywork in Kconfig. It is my wrong guide of "select" keyword. So, I'll change it as 'depends on' keyword.

Looks good to me except for 'id_irqwake'.
I'll apply this patch on 3.21 queue after completing this discussion.

Quoted 58 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-Host (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v3:
- removed IRQF_NO_SUSPEND flag. Added IRQF_TRIGGER_RISING and IRQF_TRIGGER_FALLING
- Added disable_irq() to suspend() and enable_irq() to resume()

 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  18 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 233 +++++++++++++++++++++
 4 files changed, 259 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +18 -0
new file mode 100644
index 0000000..85fe6b0
@@ -0,0 +1,18 @@
+USB GPIO Extcon device
+
+This is a virtual device used to generate USB cable states from the USB ID pin
+connected to a GPIO pin.
+
+Required properties:
+- compatible: Should be "linux,extcon-usb-gpio"
+- id-gpio: gpio for USB ID pin. See gpio binding.
+
+Example:
+	extcon_usb1 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+	}
+
+	&omap_dwc3_1 {
+		extcon = <&extcon_usb1>;
+	};
drivers/extcon/Kconfig +0 -0
index 6a1f7de..fd11536 100644

drivers/extcon/Kconfig config EXTCON_SM5502 · line 98

Quoted 6 lines
drivers/extcon/Kconfig +3 -0
@@ -93,4 +93,11 @@ config EXTCON_SM5502
 	  Silicon Mitus SM5502. The SM5502 is a USB port accessory
 	  detector and switch.
 
+config EXTCON_USB_GPIO
+	tristate "USB GPIO extcon support"
+	select GPIOLIB

I catch the build warning if using 'select' instead of 'depends on' as following:
It is my wrong guide to you. So, I'll modify it by using "depends on" as your original patch.

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- zImage -j 8 scripts/kconfig/conf --silentoldconfig Kconfig drivers/gpio/Kconfig:34:error: recursive dependency detected!
drivers/gpio/Kconfig:34: symbol GPIOLIB is selected by EXTCON_USB_GPIO
drivers/extcon/Kconfig:96: symbol EXTCON_USB_GPIO depends on EXTCON
drivers/extcon/Kconfig:1: symbol EXTCON is selected by CHARGER_MANAGER
drivers/power/Kconfig:316: symbol CHARGER_MANAGER depends on POWER_SUPPLY
drivers/power/Kconfig:1: symbol POWER_SUPPLY is selected by HID_SONY
drivers/hid/Kconfig:670: symbol HID_SONY depends on NEW_LEDS
drivers/leds/Kconfig:8: symbol NEW_LEDS is selected by BCMA_DRIVER_GPIO
drivers/bcma/Kconfig:75: symbol BCMA_DRIVER_GPIO depends on GPIOLIB

Quoted 46 lines
drivers/extcon/Kconfig +4 -0
+	help
+	  Say Y here to enable GPIO based USB cable detection extcon support.
+	  Used typically if GPIO is used for USB ID pin detection.
+
 endif # MULTISTATE_SWITCH
drivers/extcon/Makefile +1 -0
index 0370b42..6a08a98 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_EXTCON_MAX8997)	+= extcon-max8997.o
 obj-$(CONFIG_EXTCON_PALMAS)	+= extcon-palmas.o
 obj-$(CONFIG_EXTCON_RT8973A)	+= extcon-rt8973a.o
 obj-$(CONFIG_EXTCON_SM5502)	+= extcon-sm5502.o
+obj-$(CONFIG_EXTCON_USB_GPIO)	+= extcon-usb-gpio.o
drivers/extcon/extcon-usb-gpio.c new file +26 -0
new file mode 100644
index 0000000..99a58b2
@@ -0,0 +1,233 @@
+/**
+ * drivers/extcon/extcon-usb-gpio.c - USB GPIO extcon driver
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Roger Quadros <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/extcon.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>

drivers/extcon/extcon-usb-gpio.c line 36

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+
+#define USB_GPIO_DEBOUNCE_MS	20	/* ms */
+
+struct usb_extcon_info {
+	struct device *dev;
+	struct extcon_dev *edev;
+
+	struct gpio_desc *id_gpiod;
+	int id_irq;
+	bool id_irqwake;		/* ID wakeup enabled flag */

Do you really think id_irqwake is necessary?
I think it is not necessary.

Quoted 19 lines
drivers/extcon/extcon-usb-gpio.c new file +19 -0
+
+	unsigned long debounce_jiffies;
+	struct delayed_work wq_detcable;
+};
+
+/* List of detectable cables */
+enum {
+	EXTCON_CABLE_USB = 0,
+	EXTCON_CABLE_USB_HOST,
+
+	EXTCON_CABLE_END,
+};
+
+static const char *usb_extcon_cable[] = {
+	[EXTCON_CABLE_USB] = "USB",
+	[EXTCON_CABLE_USB_HOST] = "USB-Host",
+	NULL,
+};
+

[snip]

Quoted 9 lines
drivers/extcon/extcon-usb-gpio.c new file +9 -0
+
+static int usb_extcon_remove(struct platform_device *pdev)
+{
+	struct usb_extcon_info *info = platform_get_drvdata(pdev);
+
+	cancel_delayed_work_sync(&info->wq_detcable);
+
+	return 0;
+}

drivers/extcon/extcon-usb-gpio.c line 184

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+
+#ifdef CONFIG_PM_SLEEP
+static int usb_extcon_suspend(struct device *dev)
+{
+	struct usb_extcon_info *info = dev_get_drvdata(dev);
+
+	if (device_may_wakeup(dev))
+		if (!enable_irq_wake(info->id_irq))
+			info->id_irqwake = true;
+

You can simplify this code as following without 'id_irqwake':

	if (device_may_wakeup(dev))
		enable_irq_wake(info->id_irq);
Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+	/*
+	 * We don't want to process any IRQs after this point
+	 * as GPIOs used behind I2C subsystem might not be
+	 * accessible until resume completes. So disable IRQ.
+	 */
+	disable_irq(info->id_irq);
+
+	return 0;

drivers/extcon/extcon-usb-gpio.c line 202

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+}
+
+static int usb_extcon_resume(struct device *dev)
+{
+	struct usb_extcon_info *info = dev_get_drvdata(dev);
+
+	if (info->id_irqwake) {
+		disable_irq_wake(info->id_irq);
+		info->id_irqwake = false;
+	}

ditto.

	if (device_may_wakeup(dev))
		disable_irq_wake(info->id_irq);
Quoted 22 lines
drivers/extcon/extcon-usb-gpio.c new file +21 -0
+
+	enable_irq(info->id_irq);
+
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(usb_extcon_pm_ops,
+			 usb_extcon_suspend, usb_extcon_resume);
+
+static struct of_device_id usb_extcon_dt_match[] = {
+	{ .compatible = "linux,extcon-usb-gpio", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, usb_extcon_dt_match);
+
+static struct platform_driver usb_extcon_driver = {
+	.probe		= usb_extcon_probe,
+	.remove		= usb_extcon_remove,
+	.driver		= {
+		.name	= "extcon-usb-gpio",

drivers/extcon/extcon-usb-gpio.c line 233

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+		.pm	= &usb_extcon_pm_ops,
+		.of_match_table = usb_extcon_dt_match,
+	},
+};
+
+module_platform_driver(usb_extcon_driver);
+
+MODULE_AUTHOR("Roger Quadros <[email protected]>");
+MODULE_DESCRIPTION("USB GPIO extcon driver");
+MODULE_LICENSE("GPL v2");

Thanks,
Chanwoo Choi

#14 lore raw

Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

Chanwoo,

Quoted 74 lines · Chanwoo Choi

Hi Roger,

We need to discuss one point about 'id_irqwake'.
I don't recommend to use 'id_irqwake' field.

And I catch build warning by using "select" keywork in Kconfig. It is my wrong guide of "select" keyword. So, I'll change it as 'depends on' keyword.

Looks good to me except for 'id_irqwake'.
I'll apply this patch on 3.21 queue after completing this discussion.

Quoted 61 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-Host (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v3:
- removed IRQF_NO_SUSPEND flag. Added IRQF_TRIGGER_RISING and IRQF_TRIGGER_FALLING
- Added disable_irq() to suspend() and enable_irq() to resume()

 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  18 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 233 +++++++++++++++++++++
 4 files changed, 259 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +18 -0
new file mode 100644
index 0000000..85fe6b0
@@ -0,0 +1,18 @@
+USB GPIO Extcon device
+
+This is a virtual device used to generate USB cable states from the USB ID pin
+connected to a GPIO pin.
+
+Required properties:
+- compatible: Should be "linux,extcon-usb-gpio"
+- id-gpio: gpio for USB ID pin. See gpio binding.
+
+Example:
+	extcon_usb1 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+	}
+
+	&omap_dwc3_1 {
+		extcon = <&extcon_usb1>;
+	};
drivers/extcon/Kconfig +0 -0
index 6a1f7de..fd11536 100644
@@ -93,4 +93,11 @@ config EXTCON_SM5502
 	  Silicon Mitus SM5502. The SM5502 is a USB port accessory
 	  detector and switch.
 
Quoted 6 lines

drivers/extcon/Kconfig config EXTCON_SM5502 · line 98

Quoted 3 lines
drivers/extcon/Kconfig +3 -0
+config EXTCON_USB_GPIO
+	tristate "USB GPIO extcon support"
+	select GPIOLIB

I catch the build warning if using 'select' instead of 'depends on' as following:
It is my wrong guide to you. So, I'll modify it by using "depends on" as your original patch.

OK. Thanks.

Quoted 64 lines

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- zImage -j 8 scripts/kconfig/conf --silentoldconfig Kconfig drivers/gpio/Kconfig:34:error: recursive dependency detected!
drivers/gpio/Kconfig:34: symbol GPIOLIB is selected by EXTCON_USB_GPIO
drivers/extcon/Kconfig:96: symbol EXTCON_USB_GPIO depends on EXTCON
drivers/extcon/Kconfig:1: symbol EXTCON is selected by CHARGER_MANAGER
drivers/power/Kconfig:316: symbol CHARGER_MANAGER depends on POWER_SUPPLY
drivers/power/Kconfig:1: symbol POWER_SUPPLY is selected by HID_SONY
drivers/hid/Kconfig:670: symbol HID_SONY depends on NEW_LEDS
drivers/leds/Kconfig:8: symbol NEW_LEDS is selected by BCMA_DRIVER_GPIO
drivers/bcma/Kconfig:75: symbol BCMA_DRIVER_GPIO depends on GPIOLIB

Quoted 51 lines
drivers/extcon/Kconfig +4 -0
+	help
+	  Say Y here to enable GPIO based USB cable detection extcon support.
+	  Used typically if GPIO is used for USB ID pin detection.
+
 endif # MULTISTATE_SWITCH
drivers/extcon/Makefile +1 -0
index 0370b42..6a08a98 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_EXTCON_MAX8997)	+= extcon-max8997.o
 obj-$(CONFIG_EXTCON_PALMAS)	+= extcon-palmas.o
 obj-$(CONFIG_EXTCON_RT8973A)	+= extcon-rt8973a.o
 obj-$(CONFIG_EXTCON_SM5502)	+= extcon-sm5502.o
+obj-$(CONFIG_EXTCON_USB_GPIO)	+= extcon-usb-gpio.o
drivers/extcon/extcon-usb-gpio.c new file +31 -0
new file mode 100644
index 0000000..99a58b2
@@ -0,0 +1,233 @@
+/**
+ * drivers/extcon/extcon-usb-gpio.c - USB GPIO extcon driver
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Roger Quadros <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/extcon.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+
+#define USB_GPIO_DEBOUNCE_MS	20	/* ms */
+
+struct usb_extcon_info {
+	struct device *dev;
Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 36

Quoted 5 lines
drivers/extcon/extcon-usb-gpio.c new file +5 -0
+	struct extcon_dev *edev;
+
+	struct gpio_desc *id_gpiod;
+	int id_irq;
+	bool id_irqwake;		/* ID wakeup enabled flag */

Do you really think id_irqwake is necessary?
I think it is not necessary.

I will explain below why it is necessary.

Quoted 45 lines
Quoted 20 lines
drivers/extcon/extcon-usb-gpio.c new file +19 -0
+
+	unsigned long debounce_jiffies;
+	struct delayed_work wq_detcable;
+};
+
+/* List of detectable cables */
+enum {
+	EXTCON_CABLE_USB = 0,
+	EXTCON_CABLE_USB_HOST,
+
+	EXTCON_CABLE_END,
+};
+
+static const char *usb_extcon_cable[] = {
+	[EXTCON_CABLE_USB] = "USB",
+	[EXTCON_CABLE_USB_HOST] = "USB-Host",
+	NULL,
+};
+

[snip]

Quoted 9 lines
drivers/extcon/extcon-usb-gpio.c new file +9 -0
+
+static int usb_extcon_remove(struct platform_device *pdev)
+{
+	struct usb_extcon_info *info = platform_get_drvdata(pdev);
+
+	cancel_delayed_work_sync(&info->wq_detcable);
+
+	return 0;
+}

drivers/extcon/extcon-usb-gpio.c line 184

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+
+#ifdef CONFIG_PM_SLEEP
+static int usb_extcon_suspend(struct device *dev)
+{
+	struct usb_extcon_info *info = dev_get_drvdata(dev);
+
+	if (device_may_wakeup(dev))
+		if (!enable_irq_wake(info->id_irq))
+			info->id_irqwake = true;
+

You can simplify this code as following without 'id_irqwake':

Quoted 2 lines
	if (device_may_wakeup(dev))
		enable_irq_wake(info->id_irq);

enable_irq_wake() can fail. And if it does we need to keep track of it to prevent unbalanced disable_irq_wake() call in resume(). That's the reason I've added the id_irqwake flag in struct usb_extcon_info.

Quoted 49 lines
Quoted 9 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+	/*
+	 * We don't want to process any IRQs after this point
+	 * as GPIOs used behind I2C subsystem might not be
+	 * accessible until resume completes. So disable IRQ.
+	 */
+	disable_irq(info->id_irq);
+
+	return 0;

drivers/extcon/extcon-usb-gpio.c line 202

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+}
+
+static int usb_extcon_resume(struct device *dev)
+{
+	struct usb_extcon_info *info = dev_get_drvdata(dev);
+
+	if (info->id_irqwake) {
+		disable_irq_wake(info->id_irq);
+		info->id_irqwake = false;
+	}

ditto.

	if (device_may_wakeup(dev))
		disable_irq_wake(info->id_irq);
Quoted 24 lines
drivers/extcon/extcon-usb-gpio.c new file +24 -0
+
+	enable_irq(info->id_irq);
+
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(usb_extcon_pm_ops,
+			 usb_extcon_suspend, usb_extcon_resume);
+
+static struct of_device_id usb_extcon_dt_match[] = {
+	{ .compatible = "linux,extcon-usb-gpio", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, usb_extcon_dt_match);
+
+static struct platform_driver usb_extcon_driver = {
+	.probe		= usb_extcon_probe,
+	.remove		= usb_extcon_remove,
+	.driver		= {
+		.name	= "extcon-usb-gpio",
+		.pm	= &usb_extcon_pm_ops,
+		.of_match_table = usb_extcon_dt_match,
+	},
Quoted 9 lines

drivers/extcon/extcon-usb-gpio.c line 233

Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +7 -0
+};
+
+module_platform_driver(usb_extcon_driver);
+
+MODULE_AUTHOR("Roger Quadros <[email protected]>");
+MODULE_DESCRIPTION("USB GPIO extcon driver");
+MODULE_LICENSE("GPL v2");

cheers,
-roger

#9 lore raw

Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

In reply to Tony Lindgren
Quoted 11 lines · Tony Lindgren
Quoted 10 lines · Roger Quadros
Quoted 9 lines · Chanwoo Choi
Quoted 5 lines

I still fail to understand that we need to call disable_irq() in .suspend() and enable_irq() in .resume()

can you point me to any other drivers doing so?

You can refer the suspend function in drivers/mfd/max14577.c or drivers/mfd/max77693.c. The max14577_suspend() includes the detailed comment for why using disable_irq() in suspend function.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

In max14577 case, max14577_suspend() use disable_irq() function because of i2c dependency. If max14577 device is wake-up from suspend state before completing the resume sequence of i2c, max14577 may fail to read/write i2c communication.

Thanks for this information. I will add disable/enable_irq() in suspend/resume().

Are the .dts changes safe for me to apply already?

Yes Tony, you can pick them. Thanks.

cheers,
-roger

maintainer
#10 lore raw

Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

Quoted 16 lines · Roger Quadros
Quoted 15 lines · Tony Lindgren
Quoted 14 lines · Roger Quadros
Quoted 12 lines · Chanwoo Choi
Quoted 5 lines

I still fail to understand that we need to call disable_irq() in .suspend() and enable_irq() in .resume()

can you point me to any other drivers doing so?

You can refer the suspend function in drivers/mfd/max14577.c or drivers/mfd/max77693.c. The max14577_suspend() includes the detailed comment for why using disable_irq() in suspend function.

In max14577 case, max14577_suspend() use disable_irq() function because of i2c dependency. If max14577 device is wake-up from suspend state before completing the resume sequence of i2c, max14577 may fail to read/write i2c communication.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Thanks for this information. I will add disable/enable_irq() in suspend/resume().

Are the .dts changes safe for me to apply already?

Yes Tony, you can pick them. Thanks.

OK will apply the dts changes into omap-for-v3.20/dt thanks. I have also the defconfig changes tagged, will apply those a bit later probably as a fix after the driver is merged.

Regards,

Tony

maintainer
#15 lore raw

Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

In reply to Roger Quadros

Hi Roger,

Quoted 206 lines · Roger Quadros

Chanwoo,

Quoted 74 lines · Chanwoo Choi

Hi Roger,

We need to discuss one point about 'id_irqwake'.
I don't recommend to use 'id_irqwake' field.

And I catch build warning by using "select" keywork in Kconfig. It is my wrong guide of "select" keyword. So, I'll change it as 'depends on' keyword.

Looks good to me except for 'id_irqwake'.
I'll apply this patch on 3.21 queue after completing this discussion.

Quoted 61 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-Host (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v3:
- removed IRQF_NO_SUSPEND flag. Added IRQF_TRIGGER_RISING and IRQF_TRIGGER_FALLING
- Added disable_irq() to suspend() and enable_irq() to resume()

 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  18 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 233 +++++++++++++++++++++
 4 files changed, 259 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +18 -0
new file mode 100644
index 0000000..85fe6b0
@@ -0,0 +1,18 @@
+USB GPIO Extcon device
+
+This is a virtual device used to generate USB cable states from the USB ID pin
+connected to a GPIO pin.
+
+Required properties:
+- compatible: Should be "linux,extcon-usb-gpio"
+- id-gpio: gpio for USB ID pin. See gpio binding.
+
+Example:
+	extcon_usb1 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+	}
+
+	&omap_dwc3_1 {
+		extcon = <&extcon_usb1>;
+	};
drivers/extcon/Kconfig +0 -0
index 6a1f7de..fd11536 100644
@@ -93,4 +93,11 @@ config EXTCON_SM5502
 	  Silicon Mitus SM5502. The SM5502 is a USB port accessory
 	  detector and switch.
 
Quoted 6 lines

drivers/extcon/Kconfig config EXTCON_SM5502 · line 98

Quoted 3 lines
drivers/extcon/Kconfig +3 -0
+config EXTCON_USB_GPIO
+	tristate "USB GPIO extcon support"
+	select GPIOLIB

I catch the build warning if using 'select' instead of 'depends on' as following:
It is my wrong guide to you. So, I'll modify it by using "depends on" as your original patch.

OK. Thanks.

Quoted 64 lines

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- zImage -j 8 scripts/kconfig/conf --silentoldconfig Kconfig drivers/gpio/Kconfig:34:error: recursive dependency detected!
drivers/gpio/Kconfig:34: symbol GPIOLIB is selected by EXTCON_USB_GPIO
drivers/extcon/Kconfig:96: symbol EXTCON_USB_GPIO depends on EXTCON
drivers/extcon/Kconfig:1: symbol EXTCON is selected by CHARGER_MANAGER
drivers/power/Kconfig:316: symbol CHARGER_MANAGER depends on POWER_SUPPLY
drivers/power/Kconfig:1: symbol POWER_SUPPLY is selected by HID_SONY
drivers/hid/Kconfig:670: symbol HID_SONY depends on NEW_LEDS
drivers/leds/Kconfig:8: symbol NEW_LEDS is selected by BCMA_DRIVER_GPIO
drivers/bcma/Kconfig:75: symbol BCMA_DRIVER_GPIO depends on GPIOLIB

Quoted 51 lines
drivers/extcon/Kconfig +4 -0
+	help
+	  Say Y here to enable GPIO based USB cable detection extcon support.
+	  Used typically if GPIO is used for USB ID pin detection.
+
 endif # MULTISTATE_SWITCH
drivers/extcon/Makefile +1 -0
index 0370b42..6a08a98 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_EXTCON_MAX8997)	+= extcon-max8997.o
 obj-$(CONFIG_EXTCON_PALMAS)	+= extcon-palmas.o
 obj-$(CONFIG_EXTCON_RT8973A)	+= extcon-rt8973a.o
 obj-$(CONFIG_EXTCON_SM5502)	+= extcon-sm5502.o
+obj-$(CONFIG_EXTCON_USB_GPIO)	+= extcon-usb-gpio.o
drivers/extcon/extcon-usb-gpio.c new file +31 -0
new file mode 100644
index 0000000..99a58b2
@@ -0,0 +1,233 @@
+/**
+ * drivers/extcon/extcon-usb-gpio.c - USB GPIO extcon driver
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Roger Quadros <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/extcon.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+
+#define USB_GPIO_DEBOUNCE_MS	20	/* ms */
+
+struct usb_extcon_info {
+	struct device *dev;
Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 36

Quoted 5 lines
drivers/extcon/extcon-usb-gpio.c new file +5 -0
+	struct extcon_dev *edev;
+
+	struct gpio_desc *id_gpiod;
+	int id_irq;
+	bool id_irqwake;		/* ID wakeup enabled flag */

Do you really think id_irqwake is necessary?
I think it is not necessary.

I will explain below why it is necessary.

Quoted 45 lines
Quoted 20 lines
drivers/extcon/extcon-usb-gpio.c new file +19 -0
+
+	unsigned long debounce_jiffies;
+	struct delayed_work wq_detcable;
+};
+
+/* List of detectable cables */
+enum {
+	EXTCON_CABLE_USB = 0,
+	EXTCON_CABLE_USB_HOST,
+
+	EXTCON_CABLE_END,
+};
+
+static const char *usb_extcon_cable[] = {
+	[EXTCON_CABLE_USB] = "USB",
+	[EXTCON_CABLE_USB_HOST] = "USB-Host",
+	NULL,
+};
+

[snip]

Quoted 9 lines
drivers/extcon/extcon-usb-gpio.c new file +9 -0
+
+static int usb_extcon_remove(struct platform_device *pdev)
+{
+	struct usb_extcon_info *info = platform_get_drvdata(pdev);
+
+	cancel_delayed_work_sync(&info->wq_detcable);
+
+	return 0;
+}

drivers/extcon/extcon-usb-gpio.c line 184

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+
+#ifdef CONFIG_PM_SLEEP
+static int usb_extcon_suspend(struct device *dev)
+{
+	struct usb_extcon_info *info = dev_get_drvdata(dev);
+
+	if (device_may_wakeup(dev))
+		if (!enable_irq_wake(info->id_irq))
+			info->id_irqwake = true;
+

You can simplify this code as following without 'id_irqwake':

Quoted 6 lines
Quoted 2 lines
	if (device_may_wakeup(dev))
		enable_irq_wake(info->id_irq);

enable_irq_wake() can fail. And if it does we need to keep track of it to prevent unbalanced disable_irq_wake() call in resume(). That's the reason I've added the id_irqwake flag in struct usb_extcon_info.

It is not proper solution using id_irqwake. If fail to execute enable_irq_wake(), usb_extcon_suspend() function have to return error immediately.

Quoted 49 lines
Quoted 49 lines
Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+	/*
+	 * We don't want to process any IRQs after this point
+	 * as GPIOs used behind I2C subsystem might not be
+	 * accessible until resume completes. So disable IRQ.
+	 */
+	disable_irq(info->id_irq);
+
+	return 0;

drivers/extcon/extcon-usb-gpio.c line 202

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+}
+
+static int usb_extcon_resume(struct device *dev)
+{
+	struct usb_extcon_info *info = dev_get_drvdata(dev);
+
+	if (info->id_irqwake) {
+		disable_irq_wake(info->id_irq);
+		info->id_irqwake = false;
+	}

ditto.

	if (device_may_wakeup(dev))
		disable_irq_wake(info->id_irq);
Quoted 23 lines
drivers/extcon/extcon-usb-gpio.c new file +23 -0
+
+	enable_irq(info->id_irq);
+
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(usb_extcon_pm_ops,
+			 usb_extcon_suspend, usb_extcon_resume);
+
+static struct of_device_id usb_extcon_dt_match[] = {
+	{ .compatible = "linux,extcon-usb-gpio", },
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, usb_extcon_dt_match);
+
+static struct platform_driver usb_extcon_driver = {
+	.probe		= usb_extcon_probe,
+	.remove		= usb_extcon_remove,
+	.driver		= {
+		.name	= "extcon-usb-gpio",
+		.pm	= &usb_extcon_pm_ops,
+		.of_match_table = usb_extcon_dt_match,
Quoted 8 lines
Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 233

Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+	},
+};
+
+module_platform_driver(usb_extcon_driver);
+
+MODULE_AUTHOR("Roger Quadros <[email protected]>");
+MODULE_DESCRIPTION("USB GPIO extcon driver");
+MODULE_LICENSE("GPL v2");

Thanks,
Chanwoo

maintainer
#18 lore raw

Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

In reply to Roger Quadros

Hi Roger,

Quoted 126 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-Host (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v3:
- removed IRQF_NO_SUSPEND flag. Added IRQF_TRIGGER_RISING and IRQF_TRIGGER_FALLING
- Added disable_irq() to suspend() and enable_irq() to resume()

 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  18 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 233 +++++++++++++++++++++
 4 files changed, 259 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +18 -0
new file mode 100644
index 0000000..85fe6b0
@@ -0,0 +1,18 @@
+USB GPIO Extcon device
+
+This is a virtual device used to generate USB cable states from the USB ID pin
+connected to a GPIO pin.
+
+Required properties:
+- compatible: Should be "linux,extcon-usb-gpio"
+- id-gpio: gpio for USB ID pin. See gpio binding.
+
+Example:
+	extcon_usb1 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+	}
+
+	&omap_dwc3_1 {
+		extcon = <&extcon_usb1>;
+	};
drivers/extcon/Kconfig +7 -0
index 6a1f7de..fd11536 100644
@@ -93,4 +93,11 @@ config EXTCON_SM5502
 	  Silicon Mitus SM5502. The SM5502 is a USB port accessory
 	  detector and switch.
 
+config EXTCON_USB_GPIO
+	tristate "USB GPIO extcon support"
+	select GPIOLIB
+	help
+	  Say Y here to enable GPIO based USB cable detection extcon support.
+	  Used typically if GPIO is used for USB ID pin detection.
+
 endif # MULTISTATE_SWITCH
drivers/extcon/Makefile +1 -0
index 0370b42..6a08a98 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_EXTCON_MAX8997)	+= extcon-max8997.o
 obj-$(CONFIG_EXTCON_PALMAS)	+= extcon-palmas.o
 obj-$(CONFIG_EXTCON_RT8973A)	+= extcon-rt8973a.o
 obj-$(CONFIG_EXTCON_SM5502)	+= extcon-sm5502.o
+obj-$(CONFIG_EXTCON_USB_GPIO)	+= extcon-usb-gpio.o
drivers/extcon/extcon-usb-gpio.c new file +42 -0
new file mode 100644
index 0000000..99a58b2
@@ -0,0 +1,233 @@
+/**
+ * drivers/extcon/extcon-usb-gpio.c - USB GPIO extcon driver
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Roger Quadros <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/extcon.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+
+#define USB_GPIO_DEBOUNCE_MS	20	/* ms */
+
+struct usb_extcon_info {
+	struct device *dev;
+	struct extcon_dev *edev;
+
+	struct gpio_desc *id_gpiod;
+	int id_irq;
+	bool id_irqwake;		/* ID wakeup enabled flag */
+
+	unsigned long debounce_jiffies;
+	struct delayed_work wq_detcable;
+};
+
+/* List of detectable cables */

drivers/extcon/extcon-usb-gpio.c line 52

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+enum {
+	EXTCON_CABLE_USB = 0,
+	EXTCON_CABLE_USB_HOST,
+
+	EXTCON_CABLE_END,
+};
+
+static const char *usb_extcon_cable[] = {
+	[EXTCON_CABLE_USB] = "USB",
+	[EXTCON_CABLE_USB_HOST] = "USB-Host",

I'll use the defined name for extcon cable name as soon because
it has potential isseu about the conflict of extcon cable name between subsystems. So, I recommend to use a captical letter as "USB-HOST" instead of "USB-Host". If other extcon driver don't use the captical letter, I'll fix it.

[snip]

Thanks,
Chanwoo Choi

#11 lore raw

Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

In reply to Tony Lindgren
Quoted 19 lines · Tony Lindgren
Quoted 18 lines · Roger Quadros
Quoted 17 lines · Tony Lindgren
Quoted 15 lines · Roger Quadros
Quoted 4 lines · Chanwoo Choi
Quoted 4 lines

I still fail to understand that we need to call disable_irq() in .suspend() and enable_irq() in .resume()

Quoted 8 lines
Quoted 1 line

can you point me to any other drivers doing so?

You can refer the suspend function in drivers/mfd/max14577.c or drivers/mfd/max77693.c. The max14577_suspend() includes the detailed comment for why using disable_irq() in suspend function.

In max14577 case, max14577_suspend() use disable_irq() function because of i2c dependency. If max14577 device is wake-up from suspend state before completing the resume sequence of i2c, max14577 may fail to read/write i2c communication.

Thanks for this information. I will add disable/enable_irq() in suspend/resume().

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Are the .dts changes safe for me to apply already?

Yes Tony, you can pick them. Thanks.

OK will apply the dts changes into omap-for-v3.20/dt thanks. I have also the defconfig changes tagged, will apply those a bit later probably as a fix after the driver is merged.

Sounds good to me. Thanks Tony.

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#30 lore raw

Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name

In reply to Roger Quadros

Felipe & Chanwoo,

Quoted 8 lines · Roger Quadros

The recommended name for USB-Host cable state is "USB-Host" and not "USB-HOST" as per drivers/extcon/extcon-class.c extcon_cable_name.

Change all instances of "USB-HOST" to "USB-Host".

This patch has no dependency to the rest so can be picked up as soon as possible.

Do you think it is better to go via the USB tree? If yes then Chanwoo, can you please Ack this one? Thanks.

This would mean that only the first patch needs to go through extcon tree as Tony will pick the rest.

cheers,
-roger

Quoted 140 lines
---
 drivers/extcon/extcon-palmas.c | 18 +++++++++---------
 drivers/usb/dwc3/dwc3-omap.c   |  6 +++---
 drivers/usb/phy/phy-omap-otg.c |  4 ++--
 drivers/usb/phy/phy-tahvo.c    |  8 ++++----
 4 files changed, 18 insertions(+), 18 deletions(-)
drivers/extcon/extcon-palmas.c +9 -9
index 11c6757..6d002c3 100644
@@ -31,7 +31,7 @@
 
 static const char *palmas_extcon_cable[] = {
 	[0] = "USB",
-	[1] = "USB-HOST",
+	[1] = "USB-Host",
 	NULL,
 };
 
@@ -93,26 +93,26 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)
 			PALMAS_USB_ID_INT_LATCH_CLR,
 			PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND);
 		palmas_usb->linkstat = PALMAS_USB_STATE_ID;
-		extcon_set_cable_state(palmas_usb->edev, "USB-HOST", true);
-		dev_info(palmas_usb->dev, "USB-HOST cable is attached\n");
+		extcon_set_cable_state(palmas_usb->edev, "USB-Host", true);
+		dev_info(palmas_usb->dev, "USB-Host cable is attached\n");
 	} else if ((set & PALMAS_USB_ID_INT_SRC_ID_FLOAT) &&
 				(id_src & PALMAS_USB_ID_INT_SRC_ID_FLOAT)) {
 		palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
 			PALMAS_USB_ID_INT_LATCH_CLR,
 			PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT);
 		palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
-		extcon_set_cable_state(palmas_usb->edev, "USB-HOST", false);
-		dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
+		extcon_set_cable_state(palmas_usb->edev, "USB-Host", false);
+		dev_info(palmas_usb->dev, "USB-Host cable is detached\n");
 	} else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) &&
 				(!(set & PALMAS_USB_ID_INT_SRC_ID_GND))) {
 		palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
-		extcon_set_cable_state(palmas_usb->edev, "USB-HOST", false);
-		dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
+		extcon_set_cable_state(palmas_usb->edev, "USB-Host", false);
+		dev_info(palmas_usb->dev, "USB-Host cable is detached\n");
 	} else if ((palmas_usb->linkstat == PALMAS_USB_STATE_DISCONNECT) &&
 				(id_src & PALMAS_USB_ID_INT_SRC_ID_GND)) {
 		palmas_usb->linkstat = PALMAS_USB_STATE_ID;
-		extcon_set_cable_state(palmas_usb->edev, "USB-HOST", true);
-		dev_info(palmas_usb->dev, " USB-HOST cable is attached\n");
+		extcon_set_cable_state(palmas_usb->edev, "USB-Host", true);
+		dev_info(palmas_usb->dev, " USB-Host cable is attached\n");
 	}
 
 	return IRQ_HANDLED;
drivers/usb/dwc3/dwc3-omap.c +3 -3
index 172d64e..6713ad9 100644
@@ -445,14 +445,14 @@ static int dwc3_omap_extcon_register(struct dwc3_omap *omap)
 
 		omap->id_nb.notifier_call = dwc3_omap_id_notifier;
 		ret = extcon_register_interest(&omap->extcon_id_dev,
-					       edev->name, "USB-HOST",
+					       edev->name, "USB-Host",
 					       &omap->id_nb);
 		if (ret < 0)
-			dev_vdbg(omap->dev, "failed to register notifier for USB-HOST\n");
+			dev_vdbg(omap->dev, "failed to register notifier for USB-Host\n");
 
 		if (extcon_get_cable_state(edev, "USB") == true)
 			dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
-		if (extcon_get_cable_state(edev, "USB-HOST") == true)
+		if (extcon_get_cable_state(edev, "USB-Host") == true)
 			dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
 	}
 
drivers/usb/phy/phy-omap-otg.c +2 -2
index 56ee760..53cba3f 100644
@@ -119,7 +119,7 @@ static int omap_otg_probe(struct platform_device *pdev)
 	otg_dev->vbus_nb.notifier_call = omap_otg_vbus_notifier;
 
 	ret = extcon_register_interest(&otg_dev->id_dev, config->extcon,
-				       "USB-HOST", &otg_dev->id_nb);
+				       "USB-Host", &otg_dev->id_nb);
 	if (ret)
 		return ret;
 
@@ -130,7 +130,7 @@ static int omap_otg_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	otg_dev->id = extcon_get_cable_state(extcon, "USB-HOST");
+	otg_dev->id = extcon_get_cable_state(extcon, "USB-Host");
 	otg_dev->vbus = extcon_get_cable_state(extcon, "USB");
 	omap_otg_set_mode(otg_dev);
 
drivers/usb/phy/phy-tahvo.c +4 -4
index 845f658..56d3704 100644
@@ -61,7 +61,7 @@ struct tahvo_usb {
 };
 
 static const char *tahvo_cable[] = {
-	"USB-HOST",
+	"USB-Host",
 	"USB",
 	NULL,
 };
@@ -129,7 +129,7 @@ static void tahvo_usb_become_host(struct tahvo_usb *tu)
 {
 	struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent);
 
-	extcon_set_cable_state(&tu->extcon, "USB-HOST", true);
+	extcon_set_cable_state(&tu->extcon, "USB-Host", true);
 
 	/* Power up the transceiver in USB host mode */
 	retu_write(rdev, TAHVO_REG_USBR, USBR_REGOUT | USBR_NSUSPEND |
@@ -148,7 +148,7 @@ static void tahvo_usb_become_peripheral(struct tahvo_usb *tu)
 {
 	struct retu_dev *rdev = dev_get_drvdata(tu->pt_dev->dev.parent);
 
-	extcon_set_cable_state(&tu->extcon, "USB-HOST", false);
+	extcon_set_cable_state(&tu->extcon, "USB-Host", false);
 
 	/* Power up transceiver and set it in USB peripheral mode */
 	retu_write(rdev, TAHVO_REG_USBR, USBR_SLAVE_CONTROL | USBR_REGOUT |
@@ -376,7 +376,7 @@ static int tahvo_usb_probe(struct platform_device *pdev)
 	}
 
 	/* Set the initial cable state. */
-	extcon_set_cable_state(&tu->extcon, "USB-HOST",
+	extcon_set_cable_state(&tu->extcon, "USB-Host",
 			       tu->tahvo_mode == TAHVO_MODE_HOST);
 	extcon_set_cable_state(&tu->extcon, "USB", tu->vbus_state);
 
#16 lore raw

Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

In reply to Chanwoo Choi

Chanwoo,

Quoted 212 lines · Chanwoo Choi

Hi Roger,

Quoted 209 lines · Roger Quadros

Chanwoo,

Quoted 74 lines · Chanwoo Choi

Hi Roger,

We need to discuss one point about 'id_irqwake'.
I don't recommend to use 'id_irqwake' field.

And I catch build warning by using "select" keywork in Kconfig. It is my wrong guide of "select" keyword. So, I'll change it as 'depends on' keyword.

Looks good to me except for 'id_irqwake'.
I'll apply this patch on 3.21 queue after completing this discussion.

Quoted 61 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-Host (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v3:
- removed IRQF_NO_SUSPEND flag. Added IRQF_TRIGGER_RISING and IRQF_TRIGGER_FALLING
- Added disable_irq() to suspend() and enable_irq() to resume()

 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  18 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 233 +++++++++++++++++++++
 4 files changed, 259 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +18 -0
new file mode 100644
index 0000000..85fe6b0
@@ -0,0 +1,18 @@
+USB GPIO Extcon device
+
+This is a virtual device used to generate USB cable states from the USB ID pin
+connected to a GPIO pin.
+
+Required properties:
+- compatible: Should be "linux,extcon-usb-gpio"
+- id-gpio: gpio for USB ID pin. See gpio binding.
+
+Example:
+	extcon_usb1 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+	}
+
+	&omap_dwc3_1 {
+		extcon = <&extcon_usb1>;
+	};
drivers/extcon/Kconfig +0 -0
index 6a1f7de..fd11536 100644
@@ -93,4 +93,11 @@ config EXTCON_SM5502
 	  Silicon Mitus SM5502. The SM5502 is a USB port accessory
 	  detector and switch.
 
Quoted 6 lines

drivers/extcon/Kconfig config EXTCON_SM5502 · line 98

Quoted 3 lines
drivers/extcon/Kconfig +3 -0
+config EXTCON_USB_GPIO
+	tristate "USB GPIO extcon support"
+	select GPIOLIB

I catch the build warning if using 'select' instead of 'depends on' as following:
It is my wrong guide to you. So, I'll modify it by using "depends on" as your original patch.

OK. Thanks.

Quoted 64 lines

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- zImage -j 8 scripts/kconfig/conf --silentoldconfig Kconfig drivers/gpio/Kconfig:34:error: recursive dependency detected!
drivers/gpio/Kconfig:34: symbol GPIOLIB is selected by EXTCON_USB_GPIO
drivers/extcon/Kconfig:96: symbol EXTCON_USB_GPIO depends on EXTCON
drivers/extcon/Kconfig:1: symbol EXTCON is selected by CHARGER_MANAGER
drivers/power/Kconfig:316: symbol CHARGER_MANAGER depends on POWER_SUPPLY
drivers/power/Kconfig:1: symbol POWER_SUPPLY is selected by HID_SONY
drivers/hid/Kconfig:670: symbol HID_SONY depends on NEW_LEDS
drivers/leds/Kconfig:8: symbol NEW_LEDS is selected by BCMA_DRIVER_GPIO
drivers/bcma/Kconfig:75: symbol BCMA_DRIVER_GPIO depends on GPIOLIB

Quoted 51 lines
drivers/extcon/Kconfig +4 -0
+	help
+	  Say Y here to enable GPIO based USB cable detection extcon support.
+	  Used typically if GPIO is used for USB ID pin detection.
+
 endif # MULTISTATE_SWITCH
drivers/extcon/Makefile +1 -0
index 0370b42..6a08a98 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_EXTCON_MAX8997)	+= extcon-max8997.o
 obj-$(CONFIG_EXTCON_PALMAS)	+= extcon-palmas.o
 obj-$(CONFIG_EXTCON_RT8973A)	+= extcon-rt8973a.o
 obj-$(CONFIG_EXTCON_SM5502)	+= extcon-sm5502.o
+obj-$(CONFIG_EXTCON_USB_GPIO)	+= extcon-usb-gpio.o
drivers/extcon/extcon-usb-gpio.c new file +31 -0
new file mode 100644
index 0000000..99a58b2
@@ -0,0 +1,233 @@
+/**
+ * drivers/extcon/extcon-usb-gpio.c - USB GPIO extcon driver
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Roger Quadros <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/extcon.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+
+#define USB_GPIO_DEBOUNCE_MS	20	/* ms */
+
+struct usb_extcon_info {
+	struct device *dev;
Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 36

Quoted 5 lines
drivers/extcon/extcon-usb-gpio.c new file +5 -0
+	struct extcon_dev *edev;
+
+	struct gpio_desc *id_gpiod;
+	int id_irq;
+	bool id_irqwake;		/* ID wakeup enabled flag */

Do you really think id_irqwake is necessary?
I think it is not necessary.

I will explain below why it is necessary.

Quoted 47 lines
Quoted 20 lines
drivers/extcon/extcon-usb-gpio.c new file +19 -0
+
+	unsigned long debounce_jiffies;
+	struct delayed_work wq_detcable;
+};
+
+/* List of detectable cables */
+enum {
+	EXTCON_CABLE_USB = 0,
+	EXTCON_CABLE_USB_HOST,
+
+	EXTCON_CABLE_END,
+};
+
+static const char *usb_extcon_cable[] = {
+	[EXTCON_CABLE_USB] = "USB",
+	[EXTCON_CABLE_USB_HOST] = "USB-Host",
+	NULL,
+};
+

[snip]

Quoted 9 lines
drivers/extcon/extcon-usb-gpio.c new file +9 -0
+
+static int usb_extcon_remove(struct platform_device *pdev)
+{
+	struct usb_extcon_info *info = platform_get_drvdata(pdev);
+
+	cancel_delayed_work_sync(&info->wq_detcable);
+
+	return 0;
+}

drivers/extcon/extcon-usb-gpio.c line 184

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+
+#ifdef CONFIG_PM_SLEEP
+static int usb_extcon_suspend(struct device *dev)
+{
+	struct usb_extcon_info *info = dev_get_drvdata(dev);
+
+	if (device_may_wakeup(dev))
+		if (!enable_irq_wake(info->id_irq))
+			info->id_irqwake = true;
+

You can simplify this code as following without 'id_irqwake':

	if (device_may_wakeup(dev))
		enable_irq_wake(info->id_irq);
Quoted 7 lines
Quoted 3 lines

enable_irq_wake() can fail. And if it does we need to keep track of it to prevent unbalanced disable_irq_wake() call in resume(). That's the reason I've added the id_irqwake flag in struct usb_extcon_info.

It is not proper solution using id_irqwake. If fail to execute enable_irq_wake(), usb_extcon_suspend() function have to return error immediately.

Your point is valid. I will now need to investigate why enable_irq_wake() is failing when used for GPIO of PCA857x on DRA7-evm.

cheers,
-roger

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#17 lore raw

Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

+Thomas (for irq/dummychip.c question)

Hi,

Quoted 219 lines · Roger Quadros

Chanwoo,

Quoted 216 lines · Chanwoo Choi

Hi Roger,

Quoted 212 lines · Roger Quadros

Chanwoo,

Quoted 74 lines · Chanwoo Choi

Hi Roger,

We need to discuss one point about 'id_irqwake'.
I don't recommend to use 'id_irqwake' field.

And I catch build warning by using "select" keywork in Kconfig. It is my wrong guide of "select" keyword. So, I'll change it as 'depends on' keyword.

Looks good to me except for 'id_irqwake'.
I'll apply this patch on 3.21 queue after completing this discussion.

Quoted 61 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-Host (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v3:
- removed IRQF_NO_SUSPEND flag. Added IRQF_TRIGGER_RISING and IRQF_TRIGGER_FALLING
- Added disable_irq() to suspend() and enable_irq() to resume()

 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  18 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 233 +++++++++++++++++++++
 4 files changed, 259 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +18 -0
new file mode 100644
index 0000000..85fe6b0
@@ -0,0 +1,18 @@
+USB GPIO Extcon device
+
+This is a virtual device used to generate USB cable states from the USB ID pin
+connected to a GPIO pin.
+
+Required properties:
+- compatible: Should be "linux,extcon-usb-gpio"
+- id-gpio: gpio for USB ID pin. See gpio binding.
+
+Example:
+	extcon_usb1 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+	}
+
+	&omap_dwc3_1 {
+		extcon = <&extcon_usb1>;
+	};
drivers/extcon/Kconfig +0 -0
index 6a1f7de..fd11536 100644
@@ -93,4 +93,11 @@ config EXTCON_SM5502
 	  Silicon Mitus SM5502. The SM5502 is a USB port accessory
 	  detector and switch.
 
Quoted 6 lines

drivers/extcon/Kconfig config EXTCON_SM5502 · line 98

Quoted 3 lines
drivers/extcon/Kconfig +3 -0
+config EXTCON_USB_GPIO
+	tristate "USB GPIO extcon support"
+	select GPIOLIB

I catch the build warning if using 'select' instead of 'depends on' as following:
It is my wrong guide to you. So, I'll modify it by using "depends on" as your original patch.

OK. Thanks.

Quoted 64 lines

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- zImage -j 8 scripts/kconfig/conf --silentoldconfig Kconfig drivers/gpio/Kconfig:34:error: recursive dependency detected!
drivers/gpio/Kconfig:34: symbol GPIOLIB is selected by EXTCON_USB_GPIO
drivers/extcon/Kconfig:96: symbol EXTCON_USB_GPIO depends on EXTCON
drivers/extcon/Kconfig:1: symbol EXTCON is selected by CHARGER_MANAGER
drivers/power/Kconfig:316: symbol CHARGER_MANAGER depends on POWER_SUPPLY
drivers/power/Kconfig:1: symbol POWER_SUPPLY is selected by HID_SONY
drivers/hid/Kconfig:670: symbol HID_SONY depends on NEW_LEDS
drivers/leds/Kconfig:8: symbol NEW_LEDS is selected by BCMA_DRIVER_GPIO
drivers/bcma/Kconfig:75: symbol BCMA_DRIVER_GPIO depends on GPIOLIB

Quoted 51 lines
drivers/extcon/Kconfig +4 -0
+	help
+	  Say Y here to enable GPIO based USB cable detection extcon support.
+	  Used typically if GPIO is used for USB ID pin detection.
+
 endif # MULTISTATE_SWITCH
drivers/extcon/Makefile +1 -0
index 0370b42..6a08a98 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_EXTCON_MAX8997)	+= extcon-max8997.o
 obj-$(CONFIG_EXTCON_PALMAS)	+= extcon-palmas.o
 obj-$(CONFIG_EXTCON_RT8973A)	+= extcon-rt8973a.o
 obj-$(CONFIG_EXTCON_SM5502)	+= extcon-sm5502.o
+obj-$(CONFIG_EXTCON_USB_GPIO)	+= extcon-usb-gpio.o
drivers/extcon/extcon-usb-gpio.c new file +31 -0
new file mode 100644
index 0000000..99a58b2
@@ -0,0 +1,233 @@
+/**
+ * drivers/extcon/extcon-usb-gpio.c - USB GPIO extcon driver
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Roger Quadros <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/extcon.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+
+#define USB_GPIO_DEBOUNCE_MS	20	/* ms */
+
+struct usb_extcon_info {
+	struct device *dev;
Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 36

Quoted 5 lines
drivers/extcon/extcon-usb-gpio.c new file +5 -0
+	struct extcon_dev *edev;
+
+	struct gpio_desc *id_gpiod;
+	int id_irq;
+	bool id_irqwake;		/* ID wakeup enabled flag */

Do you really think id_irqwake is necessary?
I think it is not necessary.

I will explain below why it is necessary.

Quoted 45 lines
Quoted 20 lines
drivers/extcon/extcon-usb-gpio.c new file +19 -0
+
+	unsigned long debounce_jiffies;
+	struct delayed_work wq_detcable;
+};
+
+/* List of detectable cables */
+enum {
+	EXTCON_CABLE_USB = 0,
+	EXTCON_CABLE_USB_HOST,
+
+	EXTCON_CABLE_END,
+};
+
+static const char *usb_extcon_cable[] = {
+	[EXTCON_CABLE_USB] = "USB",
+	[EXTCON_CABLE_USB_HOST] = "USB-Host",
+	NULL,
+};
+

[snip]

Quoted 9 lines
drivers/extcon/extcon-usb-gpio.c new file +9 -0
+
+static int usb_extcon_remove(struct platform_device *pdev)
+{
+	struct usb_extcon_info *info = platform_get_drvdata(pdev);
+
+	cancel_delayed_work_sync(&info->wq_detcable);
+
+	return 0;
+}

drivers/extcon/extcon-usb-gpio.c line 184

Quoted 10 lines
drivers/extcon/extcon-usb-gpio.c new file +10 -0
+
+#ifdef CONFIG_PM_SLEEP
+static int usb_extcon_suspend(struct device *dev)
+{
+	struct usb_extcon_info *info = dev_get_drvdata(dev);
+
+	if (device_may_wakeup(dev))
+		if (!enable_irq_wake(info->id_irq))
+			info->id_irqwake = true;
+

You can simplify this code as following without 'id_irqwake':

Quoted 2 lines
	if (device_may_wakeup(dev))
		enable_irq_wake(info->id_irq);

enable_irq_wake() can fail. And if it does we need to keep track of it to prevent unbalanced disable_irq_wake() call in resume(). That's the reason I've added the id_irqwake flag in struct usb_extcon_info.

Quoted 7 lines
Quoted 3 lines

It is not proper solution using id_irqwake. If fail to execute enable_irq_wake(), usb_extcon_suspend() function have to return error immediately.

Your point is valid. I will now need to investigate why enable_irq_wake() is failing when used for GPIO of PCA857x on DRA7-evm.

The reason of enable_irq_wake() failure with PCA857x is that it uses dummy_irq_chip which doesn't have irq_set_wake() or IRQCHIP_SKIP_SET_WAKE flag set.

I can send out another patch to add IRQCHIP_SKIP_SET_WAKE to dummy_irq_chip.

Thomas, is this a reasonable option?

The problem at hand is that enable_irq_wake() on a IRQ line based off PCA857x GPIO chip fails. PCA857x uses dummy_irq_chip to implement the IRQ feature.
http://lxr.free-electrons.com/source/drivers/gpio/gpio-pcf857x.c#L227

cheers,
-roger

#19 lore raw

Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

In reply to Chanwoo Choi
Quoted 136 lines · Chanwoo Choi

Hi Roger,

Quoted 133 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-Host (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v3:
- removed IRQF_NO_SUSPEND flag. Added IRQF_TRIGGER_RISING and IRQF_TRIGGER_FALLING
- Added disable_irq() to suspend() and enable_irq() to resume()

 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  18 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 233 +++++++++++++++++++++
 4 files changed, 259 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +18 -0
new file mode 100644
index 0000000..85fe6b0
@@ -0,0 +1,18 @@
+USB GPIO Extcon device
+
+This is a virtual device used to generate USB cable states from the USB ID pin
+connected to a GPIO pin.
+
+Required properties:
+- compatible: Should be "linux,extcon-usb-gpio"
+- id-gpio: gpio for USB ID pin. See gpio binding.
+
+Example:
+	extcon_usb1 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+	}
+
+	&omap_dwc3_1 {
+		extcon = <&extcon_usb1>;
+	};
drivers/extcon/Kconfig +7 -0
index 6a1f7de..fd11536 100644
@@ -93,4 +93,11 @@ config EXTCON_SM5502
 	  Silicon Mitus SM5502. The SM5502 is a USB port accessory
 	  detector and switch.
 
+config EXTCON_USB_GPIO
+	tristate "USB GPIO extcon support"
+	select GPIOLIB
+	help
+	  Say Y here to enable GPIO based USB cable detection extcon support.
+	  Used typically if GPIO is used for USB ID pin detection.
+
 endif # MULTISTATE_SWITCH
drivers/extcon/Makefile +1 -0
index 0370b42..6a08a98 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_EXTCON_MAX8997)	+= extcon-max8997.o
 obj-$(CONFIG_EXTCON_PALMAS)	+= extcon-palmas.o
 obj-$(CONFIG_EXTCON_RT8973A)	+= extcon-rt8973a.o
 obj-$(CONFIG_EXTCON_SM5502)	+= extcon-sm5502.o
+obj-$(CONFIG_EXTCON_USB_GPIO)	+= extcon-usb-gpio.o
drivers/extcon/extcon-usb-gpio.c new file +49 -0
new file mode 100644
index 0000000..99a58b2
@@ -0,0 +1,233 @@
+/**
+ * drivers/extcon/extcon-usb-gpio.c - USB GPIO extcon driver
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Roger Quadros <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/extcon.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+
+#define USB_GPIO_DEBOUNCE_MS	20	/* ms */
+
+struct usb_extcon_info {
+	struct device *dev;
+	struct extcon_dev *edev;
+
+	struct gpio_desc *id_gpiod;
+	int id_irq;
+	bool id_irqwake;		/* ID wakeup enabled flag */
+
+	unsigned long debounce_jiffies;
+	struct delayed_work wq_detcable;
+};
+
+/* List of detectable cables */
+enum {
+	EXTCON_CABLE_USB = 0,
+	EXTCON_CABLE_USB_HOST,
+
+	EXTCON_CABLE_END,
+};
+
Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 52

Quoted 3 lines
drivers/extcon/extcon-usb-gpio.c new file +3 -0
+static const char *usb_extcon_cable[] = {
+	[EXTCON_CABLE_USB] = "USB",
+	[EXTCON_CABLE_USB_HOST] = "USB-Host",

I'll use the defined name for extcon cable name as soon because
it has potential isseu about the conflict of extcon cable name between subsystems. So, I recommend to use a captical letter as "USB-HOST" instead of "USB-Host". If other extcon driver don't use the captical letter, I'll fix it.

Did you see patch 2 in this series?
In that I had fixed all instances to use "USB-Host" based on
http://lxr.free-electrons.com/source/drivers/extcon/extcon-class.c#L45

What do you suggest?
Skip patch 2 and convert all "USB-Host" to "USB-HOST"?

cheers,
-roger

#31 lore raw

Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name

In reply to Roger Quadros

Hi,

Quoted 12 lines · Roger Quadros

Felipe & Chanwoo,

Quoted 8 lines · Roger Quadros

The recommended name for USB-Host cable state is "USB-Host" and not "USB-HOST" as per drivers/extcon/extcon-class.c extcon_cable_name.

Change all instances of "USB-HOST" to "USB-Host".

Quoted 7 lines

This patch has no dependency to the rest so can be picked up as soon as possible.

Do you think it is better to go via the USB tree? If yes then Chanwoo, can you please Ack this one? Thanks.

This would mean that only the first patch needs to go through extcon tree as Tony will pick the rest.

Hold on. Let's first decide what we really want to go ahead with "USB-Host" or "USB-HOST".

cheers,
-roger

maintainer
#32 lore raw

Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name

Hi Roger,

Quoted 17 lines · Roger Quadros

Hi,

Quoted 14 lines · Roger Quadros

Felipe & Chanwoo,

Quoted 8 lines · Roger Quadros

The recommended name for USB-Host cable state is "USB-Host" and not "USB-HOST" as per drivers/extcon/extcon-class.c extcon_cable_name.

Change all instances of "USB-HOST" to "USB-Host".

This patch has no dependency to the rest so can be picked up as soon as possible.

Quoted 8 lines
Quoted 5 lines

Do you think it is better to go via the USB tree? If yes then Chanwoo, can you please Ack this one? Thanks.

This would mean that only the first patch needs to go through extcon tree as Tony will pick the rest.

Hold on. Let's first decide what we really want to go ahead with "USB-Host" or "USB-HOST".

Currently, extcon driver have used the specific cable name(USB-Host or USB-HOST) without any standard way. So, I have plan to define common cable name in extcon header file by using capital letter.

Thanks,
Chanwoo Choi

maintainer
#20 lore raw

Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver

In reply to Roger Quadros

Hi Roger,

Quoted 146 lines · Roger Quadros
Quoted 136 lines · Chanwoo Choi

Hi Roger,

Quoted 133 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-Host (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v3:
- removed IRQF_NO_SUSPEND flag. Added IRQF_TRIGGER_RISING and IRQF_TRIGGER_FALLING
- Added disable_irq() to suspend() and enable_irq() to resume()

 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  18 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 233 +++++++++++++++++++++
 4 files changed, 259 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +18 -0
new file mode 100644
index 0000000..85fe6b0
@@ -0,0 +1,18 @@
+USB GPIO Extcon device
+
+This is a virtual device used to generate USB cable states from the USB ID pin
+connected to a GPIO pin.
+
+Required properties:
+- compatible: Should be "linux,extcon-usb-gpio"
+- id-gpio: gpio for USB ID pin. See gpio binding.
+
+Example:
+	extcon_usb1 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+	}
+
+	&omap_dwc3_1 {
+		extcon = <&extcon_usb1>;
+	};
drivers/extcon/Kconfig +7 -0
index 6a1f7de..fd11536 100644
@@ -93,4 +93,11 @@ config EXTCON_SM5502
 	  Silicon Mitus SM5502. The SM5502 is a USB port accessory
 	  detector and switch.
 
+config EXTCON_USB_GPIO
+	tristate "USB GPIO extcon support"
+	select GPIOLIB
+	help
+	  Say Y here to enable GPIO based USB cable detection extcon support.
+	  Used typically if GPIO is used for USB ID pin detection.
+
 endif # MULTISTATE_SWITCH
drivers/extcon/Makefile +1 -0
index 0370b42..6a08a98 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_EXTCON_MAX8997)	+= extcon-max8997.o
 obj-$(CONFIG_EXTCON_PALMAS)	+= extcon-palmas.o
 obj-$(CONFIG_EXTCON_RT8973A)	+= extcon-rt8973a.o
 obj-$(CONFIG_EXTCON_SM5502)	+= extcon-sm5502.o
+obj-$(CONFIG_EXTCON_USB_GPIO)	+= extcon-usb-gpio.o
drivers/extcon/extcon-usb-gpio.c new file +49 -0
new file mode 100644
index 0000000..99a58b2
@@ -0,0 +1,233 @@
+/**
+ * drivers/extcon/extcon-usb-gpio.c - USB GPIO extcon driver
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Roger Quadros <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/extcon.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+
+#define USB_GPIO_DEBOUNCE_MS	20	/* ms */
+
+struct usb_extcon_info {
+	struct device *dev;
+	struct extcon_dev *edev;
+
+	struct gpio_desc *id_gpiod;
+	int id_irq;
+	bool id_irqwake;		/* ID wakeup enabled flag */
+
+	unsigned long debounce_jiffies;
+	struct delayed_work wq_detcable;
+};
+
+/* List of detectable cables */
+enum {
+	EXTCON_CABLE_USB = 0,
+	EXTCON_CABLE_USB_HOST,
+
+	EXTCON_CABLE_END,
+};
+
Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 52

Quoted 3 lines
drivers/extcon/extcon-usb-gpio.c new file +3 -0
+static const char *usb_extcon_cable[] = {
+	[EXTCON_CABLE_USB] = "USB",
+	[EXTCON_CABLE_USB_HOST] = "USB-Host",

I'll use the defined name for extcon cable name as soon because
it has potential isseu about the conflict of extcon cable name between subsystems. So, I recommend to use a captical letter as "USB-HOST" instead of "USB-Host". If other extcon driver don't use the captical letter, I'll fix it.

Quoted 6 lines

Did you see patch 2 in this series?
In that I had fixed all instances to use "USB-Host" based on
http://lxr.free-electrons.com/source/drivers/extcon/extcon-class.c#L45

What do you suggest?
Skip patch 2 and convert all "USB-Host" to "USB-HOST"?

I replied my opinion about this on following patch[1].
[1] Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name

Thanks,
Chanwoo Choi

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#33 lore raw

Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name

In reply to Chanwoo Choi

Chanwoo,

Quoted 26 lines · Chanwoo Choi

Hi Roger,

Quoted 23 lines · Roger Quadros

Hi,

Quoted 19 lines · Roger Quadros

Felipe & Chanwoo,

Quoted 8 lines · Roger Quadros

The recommended name for USB-Host cable state is "USB-Host" and not "USB-HOST" as per drivers/extcon/extcon-class.c extcon_cable_name.

Change all instances of "USB-HOST" to "USB-Host".

This patch has no dependency to the rest so can be picked up as soon as possible.

Do you think it is better to go via the USB tree? If yes then Chanwoo, can you please Ack this one? Thanks.

This would mean that only the first patch needs to go through extcon tree as Tony will pick the rest.

Quoted 6 lines
Quoted 2 lines

Hold on. Let's first decide what we really want to go ahead with "USB-Host" or "USB-HOST".

Currently, extcon driver have used the specific cable name(USB-Host or USB-HOST) without any standard way. So, I have plan to define common cable name in extcon header file by using capital letter.

OK. In that case, this patch is not required.
I will resend patch 1 with cable name corrected to "USB-HOST".

cheers,
-roger

maintainer
#34 lore raw

Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name

Hi Roger,

Quoted 32 lines · Roger Quadros

Chanwoo,

Quoted 29 lines · Chanwoo Choi

Hi Roger,

Quoted 25 lines · Roger Quadros

Hi,

Quoted 12 lines · Roger Quadros

Felipe & Chanwoo,

Quoted 8 lines · Roger Quadros

The recommended name for USB-Host cable state is "USB-Host" and not "USB-HOST" as per drivers/extcon/extcon-class.c extcon_cable_name.

Change all instances of "USB-HOST" to "USB-Host".

Quoted 7 lines

This patch has no dependency to the rest so can be picked up as soon as possible.

Do you think it is better to go via the USB tree? If yes then Chanwoo, can you please Ack this one? Thanks.

This would mean that only the first patch needs to go through extcon tree as Tony will pick the rest.

Hold on. Let's first decide what we really want to go ahead with "USB-Host" or "USB-HOST".

Quoted 6 lines
Quoted 3 lines

Currently, extcon driver have used the specific cable name(USB-Host or USB-HOST) without any standard way. So, I have plan to define common cable name in extcon header file by using capital letter.

OK. In that case, this patch is not required.
I will resend patch 1 with cable name corrected to "USB-HOST".

If you possbile, I want to use 'USB-HOST' cable name in drivers related to extcon. If we use different cable name, this cause the confusion to control cable.

Thanks,
Chanwoo

#35 lore raw

Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name

Quoted 39 lines · Chanwoo Choi

Hi Roger,

Quoted 36 lines · Roger Quadros

Chanwoo,

Quoted 32 lines · Chanwoo Choi

Hi Roger,

Quoted 17 lines · Roger Quadros

Hi,

Quoted 14 lines · Roger Quadros

Felipe & Chanwoo,

Quoted 8 lines · Roger Quadros

The recommended name for USB-Host cable state is "USB-Host" and not "USB-HOST" as per drivers/extcon/extcon-class.c extcon_cable_name.

Change all instances of "USB-HOST" to "USB-Host".

This patch has no dependency to the rest so can be picked up as soon as possible.

Quoted 8 lines
Quoted 5 lines

Do you think it is better to go via the USB tree? If yes then Chanwoo, can you please Ack this one? Thanks.

This would mean that only the first patch needs to go through extcon tree as Tony will pick the rest.

Hold on. Let's first decide what we really want to go ahead with "USB-Host" or "USB-HOST".

Currently, extcon driver have used the specific cable name(USB-Host or USB-HOST) without any standard way. So, I have plan to define common cable name in extcon header file by using capital letter.

Quoted 6 lines
Quoted 2 lines

OK. In that case, this patch is not required.
I will resend patch 1 with cable name corrected to "USB-HOST".

If you possbile, I want to use 'USB-HOST' cable name in drivers related to extcon. If we use different cable name, this cause the confusion to control cable.

Kernel tree shows following users of "USB-Host" that will have to be changed to "USB-HOST".

extcon-class.c: [EXTCON_USB_HOST] = "USB-Host",
extcon-max77693.c: [EXTCON_CABLE_USB_HOST] = "USB-Host",
extcon-max77693.c: extcon_set_cable_state(info->edev, "USB-Host", attached);
extcon-max8997.c: [EXTCON_CABLE_USB_HOST] = "USB-Host",
extcon-max8997.c: extcon_set_cable_state(info->edev, "USB-Host", attached);
extcon-rt8973a.c: [EXTCON_CABLE_USB_HOST] = "USB-Host",
extcon-sm5502.c: [EXTCON_CABLE_USB_HOST] = "USB-Host",

I'm not aware if any user space programs depend on this name. Do you know of any?

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#36 lore raw

Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name

Quoted 43 lines · Roger Quadros
Quoted 42 lines · Chanwoo Choi

Hi Roger,

Quoted 38 lines · Roger Quadros

Chanwoo,

Quoted 26 lines · Chanwoo Choi

Hi Roger,

Quoted 23 lines · Roger Quadros

Hi,

Quoted 19 lines · Roger Quadros

Felipe & Chanwoo,

Quoted 8 lines · Roger Quadros

The recommended name for USB-Host cable state is "USB-Host" and not "USB-HOST" as per drivers/extcon/extcon-class.c extcon_cable_name.

Change all instances of "USB-HOST" to "USB-Host".

This patch has no dependency to the rest so can be picked up as soon as possible.

Do you think it is better to go via the USB tree? If yes then Chanwoo, can you please Ack this one? Thanks.

This would mean that only the first patch needs to go through extcon tree as Tony will pick the rest.

Quoted 6 lines
Quoted 2 lines

Hold on. Let's first decide what we really want to go ahead with "USB-Host" or "USB-HOST".

Currently, extcon driver have used the specific cable name(USB-Host or USB-HOST) without any standard way. So, I have plan to define common cable name in extcon header file by using capital letter.

OK. In that case, this patch is not required.
I will resend patch 1 with cable name corrected to "USB-HOST".

Quoted 6 lines
Quoted 3 lines

If you possbile, I want to use 'USB-HOST' cable name in drivers related to extcon. If we use different cable name, this cause the confusion to control cable.

Kernel tree shows following users of "USB-Host" that will have to be changed to "USB-HOST".

You're right. I'll modify all cable name of 'USB-HOST'. Also, I have plan to use only capital letter for cable name.

Quoted 10 lines

extcon-class.c: [EXTCON_USB_HOST] = "USB-Host",
extcon-max77693.c: [EXTCON_CABLE_USB_HOST] = "USB-Host",
extcon-max77693.c: extcon_set_cable_state(info->edev, "USB-Host", attached);
extcon-max8997.c: [EXTCON_CABLE_USB_HOST] = "USB-Host",
extcon-max8997.c: extcon_set_cable_state(info->edev, "USB-Host", attached);
extcon-rt8973a.c: [EXTCON_CABLE_USB_HOST] = "USB-Host",
extcon-sm5502.c: [EXTCON_CABLE_USB_HOST] = "USB-Host",

I'm not aware if any user space programs depend on this name. Do you know of any?

As I knew, released samsung smart-phone used the cable name to detect the cable state becaues extcon send the uevent with both cable name and cable state.

Thanks,
Chanwoo Choi

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#21 lore raw

PATCH v4 1/1 extcon: usb-gpio: Introduce gpio usb extcon driver

In reply to Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-HOST (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v4:
- got rid of id_irqwake flag. Fail if enable/disable_irq_wake() fails
- changed host cable name to "USB-HOST"
- use 'depends on' instead of 'select' GPIOLIB

 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  18 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 237 +++++++++++++++++++++
 4 files changed, 263 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +18 -0
new file mode 100644
index 0000000..85fe6b0
@@ -0,0 +1,18 @@
+USB GPIO Extcon device
+
+This is a virtual device used to generate USB cable states from the USB ID pin
+connected to a GPIO pin.
+
+Required properties:
+- compatible: Should be "linux,extcon-usb-gpio"
+- id-gpio: gpio for USB ID pin. See gpio binding.
+
+Example:
+	extcon_usb1 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+	}
+
+	&omap_dwc3_1 {
+		extcon = <&extcon_usb1>;
+	};
drivers/extcon/Kconfig +7 -0
index 6a1f7de..e4c01ab 100644
@@ -93,4 +93,11 @@ config EXTCON_SM5502
 	  Silicon Mitus SM5502. The SM5502 is a USB port accessory
 	  detector and switch.
 
+config EXTCON_USB_GPIO
+	tristate "USB GPIO extcon support"
+	depends on GPIOLIB
+	help
+	  Say Y here to enable GPIO based USB cable detection extcon support.
+	  Used typically if GPIO is used for USB ID pin detection.
+
 endif # MULTISTATE_SWITCH
drivers/extcon/Makefile +1 -0
index 0370b42..6a08a98 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_EXTCON_MAX8997)	+= extcon-max8997.o
 obj-$(CONFIG_EXTCON_PALMAS)	+= extcon-palmas.o
 obj-$(CONFIG_EXTCON_RT8973A)	+= extcon-rt8973a.o
 obj-$(CONFIG_EXTCON_SM5502)	+= extcon-sm5502.o
+obj-$(CONFIG_EXTCON_USB_GPIO)	+= extcon-usb-gpio.o
drivers/extcon/extcon-usb-gpio.c new file +237 -0

237 lines not on this page · raw message

Signature · 1 line
2.1.0
maintainer
#22 lore raw

Re: [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver

Hi Roger,

Looks good to me. Applied it on v3.21 queue.

Thanks,
Chanwoo Choi

Quoted 35 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-HOST (attach/detach)

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v4:
- got rid of id_irqwake flag. Fail if enable/disable_irq_wake() fails
- changed host cable name to "USB-HOST"
- use 'depends on' instead of 'select' GPIOLIB

 .../devicetree/bindings/extcon/extcon-usb-gpio.txt |  18 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-usb-gpio.c                   | 237 +++++++++++++++++++++
 4 files changed, 263 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
 create mode 100644 drivers/extcon/extcon-usb-gpio.c
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +0 -0
new file mode 100644
index 0000000..85fe6b0

Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt line 10

Quoted 10 lines
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +10 -0
@@ -0,0 +1,18 @@
+USB GPIO Extcon device
+
+This is a virtual device used to generate USB cable states from the USB ID pin
+connected to a GPIO pin.
+
+Required properties:
+- compatible: Should be "linux,extcon-usb-gpio"
+- id-gpio: gpio for USB ID pin. See gpio binding.
+
+Example:

I add some description for example as following:

+Example: Examples of extcon-usb-gpio node in dra7-evm.dts as listed below:

Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt line 18

Quoted 8 lines
Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt new file +8 -0
+	extcon_usb1 {
+		compatible = "linux,extcon-usb-gpio";
+		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+	}
+
+	&omap_dwc3_1 {
+		extcon = <&extcon_usb1>;
+	};

[snip]

Thanks,
Chanwoo Choi

#23 lore raw

Re: [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver

In reply to Roger Quadros

Hi,

Quoted 11 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-HOST (attach/detach)

Quoted 8 lines

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v4:
- got rid of id_irqwake flag. Fail if enable/disable_irq_wake() fails
- changed host cable name to "USB-HOST"

I am sorry that I am getting a bit little late into this.

Isn't supposed that we have to use strings defined in const char extcon_cable_name[][]?

drivers/extcon/extcon-usb-gpio.c line 45

Quoted 6 lines
drivers/extcon/extcon-usb-gpio.c new file +6 -0
+
+/* List of detectable cables */
+enum {
+       EXTCON_CABLE_USB = 0,
+       EXTCON_CABLE_USB_HOST,
+

Same here: duplicated with enum extcon_cable_name

Quoted 9 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+       EXTCON_CABLE_END,
+};
+
+static const char *usb_extcon_cable[] = {
+       [EXTCON_CABLE_USB] = "USB",
+       [EXTCON_CABLE_USB_HOST] = "USB-HOST",
+       NULL,
+};

<snip>

Quoted 4 lines
drivers/extcon/extcon-usb-gpio.c new file +3 -0
+
+static int usb_extcon_probe(struct platform_device *pdev)
+{

<snip>

drivers/extcon/extcon-usb-gpio.c line 138

Quoted 5 lines
drivers/extcon/extcon-usb-gpio.c new file +5 -0
+
+       ret = devm_request_threaded_irq(dev, info->id_irq, NULL,
+                                       usb_irq_handler,
+                                       IRQF_TRIGGER_RISING |
+                                       IRQF_TRIGGER_FALLING | IRQF_ONESHOT,

Shouldn't triggers be defined in DTS files?

Regards,
Ivan

Quoted 1 line
#24 lore raw

Re: [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver

Hi Ivan,

Quoted 38 lines · Ivan T. Ivanov

Hi,

Quoted 11 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-HOST (attach/detach)

Quoted 8 lines

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v4:
- got rid of id_irqwake flag. Fail if enable/disable_irq_wake() fails
- changed host cable name to "USB-HOST"

I am sorry that I am getting a bit little late into this.

Isn't supposed that we have to use strings defined in const char extcon_cable_name[][]?

drivers/extcon/extcon-usb-gpio.c line 45

Quoted 6 lines
drivers/extcon/extcon-usb-gpio.c new file +6 -0
+
+/* List of detectable cables */
+enum {
+       EXTCON_CABLE_USB = 0,
+       EXTCON_CABLE_USB_HOST,
+

Same here: duplicated with enum extcon_cable_name

Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 53

Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+       EXTCON_CABLE_END,
+};
+
+static const char *usb_extcon_cable[] = {
+       [EXTCON_CABLE_USB] = "USB",
+       [EXTCON_CABLE_USB_HOST] = "USB-HOST",
+       NULL,
+};

I'm not exactly sure how else it is supposed to work if we support only a subset of cables from the global extcon_cable_name[][].

Quoted 11 lines
Quoted 1 line

<snip>

Quoted 4 lines
drivers/extcon/extcon-usb-gpio.c new file +3 -0
+
+static int usb_extcon_probe(struct platform_device *pdev)
+{

<snip>

Quoted 7 lines

drivers/extcon/extcon-usb-gpio.c line 138

Quoted 5 lines
drivers/extcon/extcon-usb-gpio.c new file +5 -0
+
+       ret = devm_request_threaded_irq(dev, info->id_irq, NULL,
+                                       usb_irq_handler,
+                                       IRQF_TRIGGER_RISING |
+                                       IRQF_TRIGGER_FALLING | IRQF_ONESHOT,

Shouldn't triggers be defined in DTS files?

Could be but we're sure that we always need the trigger for both rising/falling edges in this case. So the usage is more appropriately decided from application point of view rather than h/w point of view. h/w is generic GPIO.

cheers,
-roger

#25 lore raw

Re: [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver

Hi Roger,

Quoted 41 lines · Roger Quadros

Hi Ivan,

Quoted 38 lines · Ivan T. Ivanov

Hi,

Quoted 11 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-HOST (attach/detach)

Quoted 8 lines

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v4:
- got rid of id_irqwake flag. Fail if enable/disable_irq_wake() fails
- changed host cable name to "USB-HOST"

I am sorry that I am getting a bit little late into this.

Isn't supposed that we have to use strings defined in const char extcon_cable_name[][]?

drivers/extcon/extcon-usb-gpio.c line 45

Quoted 6 lines
drivers/extcon/extcon-usb-gpio.c new file +6 -0
+
+/* List of detectable cables */
+enum {
+       EXTCON_CABLE_USB = 0,
+       EXTCON_CABLE_USB_HOST,
+

Same here: duplicated with enum extcon_cable_name

Quoted 11 lines
Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 53

Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+       EXTCON_CABLE_END,
+};
+
+static const char *usb_extcon_cable[] = {
+       [EXTCON_CABLE_USB] = "USB",
+       [EXTCON_CABLE_USB_HOST] = "USB-HOST",
+       NULL,
+};

I'm not exactly sure how else it is supposed to work if we support only a subset of cables from the global extcon_cable_name[][].

I don't see issue that we use just 2 events. I think that we can reuse enum extcon_cable_name and strings already defined in extcon_cable_name[][] global variable. It is defined extern in extcon.h file exactly for this purpose, no?

Quoted 17 lines
Quoted 17 lines

<snip>

Quoted 4 lines
drivers/extcon/extcon-usb-gpio.c new file +3 -0
+
+static int usb_extcon_probe(struct platform_device *pdev)
+{

<snip>

Quoted 5 lines
drivers/extcon/extcon-usb-gpio.c new file +5 -0
+
+       ret = devm_request_threaded_irq(dev, info->id_irq, NULL,
+                                       usb_irq_handler,
+                                       IRQF_TRIGGER_RISING |
+                                       IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
Quoted 5 lines
Quoted 1 line

Shouldn't triggers be defined in DTS files?

Could be but we're sure that we always need the trigger for both rising/falling edges in this case. So the usage is more appropriately decided from application point of view rather than h/w point of view. h/w is generic GPIO.

No strong opinion on this. Could it be that GPIO did't support edge triggered interrupt, but just level triggered?

Regards,
Ivan

maintainer
#42 lore raw

Re: [PATCH v2 7/7] ARM: omap2plus_defconfig: Enable EXTCON_GPIO_USB

In reply to Roger Quadros
Quoted 4 lines · Roger Quadros

This driver is needed for USB cable type detection on dra7-evm, dra72-evm and am57xx-beagle-x15.

Applying this into omap-for-v4.1/defconfig. I think it's all queued up after this, please check and repost patches if it's still missing something as I've marked all the extcon related threads as read here now.

Regards,

Tony

Quoted 19 lines
---
 arch/arm/configs/omap2plus_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm/configs/omap2plus_defconfig +1 -0
index 667d9d5..7e10e58 100644
@@ -326,6 +326,7 @@ CONFIG_DMADEVICES=y
 CONFIG_TI_EDMA=y
 CONFIG_DMA_OMAP=y
 CONFIG_EXTCON=y
+CONFIG_EXTCON_USB_GPIO=m
 CONFIG_EXTCON_PALMAS=y
 CONFIG_PWM=y
 CONFIG_PWM_TIECAP=y
Signature · 1 line
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#26 lore raw

Re: [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver

In reply to Ivan T. Ivanov

Hi Ivan,

Quoted 57 lines · Ivan T. Ivanov

Hi Roger,

Quoted 41 lines · Roger Quadros

Hi Ivan,

Quoted 38 lines · Ivan T. Ivanov

Hi,

Quoted 11 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-HOST (attach/detach)

Quoted 8 lines

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v4:
- got rid of id_irqwake flag. Fail if enable/disable_irq_wake() fails
- changed host cable name to "USB-HOST"

I am sorry that I am getting a bit little late into this.

Isn't supposed that we have to use strings defined in const char extcon_cable_name[][]?

drivers/extcon/extcon-usb-gpio.c line 45

Quoted 6 lines
drivers/extcon/extcon-usb-gpio.c new file +6 -0
+
+/* List of detectable cables */
+enum {
+       EXTCON_CABLE_USB = 0,
+       EXTCON_CABLE_USB_HOST,
+

Same here: duplicated with enum extcon_cable_name

Quoted 11 lines
Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 53

Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+       EXTCON_CABLE_END,
+};
+
+static const char *usb_extcon_cable[] = {
+       [EXTCON_CABLE_USB] = "USB",
+       [EXTCON_CABLE_USB_HOST] = "USB-HOST",
+       NULL,
+};

I'm not exactly sure how else it is supposed to work if we support only a subset of cables from the global extcon_cable_name[][].

Quoted 4 lines

I don't see issue that we use just 2 events. I think that we can reuse enum extcon_cable_name and strings already defined in extcon_cable_name[][] global variable. It is defined extern in extcon.h file exactly for this purpose, no?

'extcon_cable_name' global variable is not used on extcon driver directly. It is just recommended cable name.

I have plan to use standard cable name for extcon driver instead of that each extcon driver define the cable name.

[snip]

Thanks,
Chanwoo Choi

#27 lore raw

Re: [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver

Hi,

Quoted 61 lines · Chanwoo Choi

Hi Ivan,

Quoted 58 lines · Ivan T. Ivanov

Hi Roger,

Quoted 41 lines · Roger Quadros

Hi Ivan,

Quoted 38 lines · Ivan T. Ivanov

Hi,

Quoted 11 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-HOST (attach/detach)

Quoted 8 lines

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v4:
- got rid of id_irqwake flag. Fail if enable/disable_irq_wake() fails
- changed host cable name to "USB-HOST"

I am sorry that I am getting a bit little late into this.

Isn't supposed that we have to use strings defined in const char extcon_cable_name[][]?

drivers/extcon/extcon-usb-gpio.c line 45

Quoted 6 lines
drivers/extcon/extcon-usb-gpio.c new file +6 -0
+
+/* List of detectable cables */
+enum {
+       EXTCON_CABLE_USB = 0,
+       EXTCON_CABLE_USB_HOST,
+

Same here: duplicated with enum extcon_cable_name

Quoted 11 lines
Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 53

Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+       EXTCON_CABLE_END,
+};
+
+static const char *usb_extcon_cable[] = {
+       [EXTCON_CABLE_USB] = "USB",
+       [EXTCON_CABLE_USB_HOST] = "USB-HOST",
+       NULL,
+};

I'm not exactly sure how else it is supposed to work if we support only a subset of cables from the global extcon_cable_name[][].

I don't see issue that we use just 2 events. I think that we can reuse enum extcon_cable_name

Now I see that extcon_dev_register() expect NULL terminated array of pointers, so it will not be possible to use enum extcon_cable_name as index in the above array, sorry.

Quoted 6 lines
Quoted 3 lines

and strings already defined in
extcon_cable_name[][] global variable. It is defined extern in extcon.h file exactly for this purpose, no?

'extcon_cable_name' global variable is not used on extcon driver directly. It is just recommended cable name.

Hm, this is what bothers me. How client drivers will know cable name if every provider start using its own naming scheme?

If I write client driver I will use:

extcon_register_interest(obj, name, extcon_cable_name[EXTCON_USB_HOST], nb);

and this will now work with this driver because it define string differently.

... Well, I see that string is changed because your recommendation :-), then lets fix extcon_cable_name strings and not let drivers define its own names.

Quoted 3 lines

I have plan to use standard cable name for extcon driver instead of that each extcon driver define the cable name.

Sound like a good plan :-)

Regards,
Ivan

#28 lore raw

Re: [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver

Fixed spelling error.

Quoted 76 lines · Ivan T. Ivanov

Hi,

Quoted 61 lines · Chanwoo Choi

Hi Ivan,

Quoted 58 lines · Ivan T. Ivanov

Hi Roger,

Quoted 41 lines · Roger Quadros

Hi Ivan,

Quoted 38 lines · Ivan T. Ivanov

Hi,

Quoted 11 lines · Roger Quadros

This driver observes the USB ID pin connected over a GPIO and updates the USB cable extcon states accordingly.

The existing GPIO extcon driver is not suitable for this purpose as it needs to be taught to understand USB cable states and it can't handle more than one cable per instance.

For the USB case we need to handle 2 cable states.
1) USB (attach/detach)
2) USB-HOST (attach/detach)

Quoted 8 lines

This driver can be easily updated in the future to handle VBUS events in case it happens to be available on GPIO for any platform.

---
v4:
- got rid of id_irqwake flag. Fail if enable/disable_irq_wake() fails
- changed host cable name to "USB-HOST"

I am sorry that I am getting a bit little late into this.

Isn't supposed that we have to use strings defined in const char extcon_cable_name[][]?

drivers/extcon/extcon-usb-gpio.c line 45

Quoted 6 lines
drivers/extcon/extcon-usb-gpio.c new file +6 -0
+
+/* List of detectable cables */
+enum {
+       EXTCON_CABLE_USB = 0,
+       EXTCON_CABLE_USB_HOST,
+

Same here: duplicated with enum extcon_cable_name

Quoted 11 lines
Quoted 8 lines

drivers/extcon/extcon-usb-gpio.c line 53

Quoted 8 lines
drivers/extcon/extcon-usb-gpio.c new file +8 -0
+       EXTCON_CABLE_END,
+};
+
+static const char *usb_extcon_cable[] = {
+       [EXTCON_CABLE_USB] = "USB",
+       [EXTCON_CABLE_USB_HOST] = "USB-HOST",
+       NULL,
+};

I'm not exactly sure how else it is supposed to work if we support only a subset of cables from the global extcon_cable_name[][].

I don't see issue that we use just 2 events. I think that we can reuse enum extcon_cable_name

Now I see that extcon_dev_register() expect NULL terminated array of pointers, so it will not be possible to use enum extcon_cable_name as index in the above array, sorry.

Quoted 6 lines
Quoted 3 lines

and strings already defined in
extcon_cable_name[][] global variable. It is defined extern in extcon.h file exactly for this purpose, no?

'extcon_cable_name' global variable is not used on extcon driver directly. It is just recommended cable name.

Quoted 8 lines

Hm, this is what bothers me. How client drivers will know cable name if every provider start using its own naming scheme?

If I write client driver I will use:

extcon_register_interest(obj, name, extcon_cable_name[EXTCON_USB_HOST], nb);

and this will now work with this driver because it define string differently.

                ^^^

s/now/not/

Quoted 6 lines

... Well, I see that string is changed because your recommendation :-), then lets fix extcon_cable_name strings and not let drivers define its own names.

Quoted 11 lines
Quoted 3 lines

I have plan to use standard cable name for extcon driver instead of that each extcon driver define the cable name.

Sound like a good plan :-)

Regards,
Ivan

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#43 lore raw

Re: [PATCH v2 7/7] ARM: omap2plus_defconfig: Enable EXTCON_GPIO_USB

In reply to Tony Lindgren
Quoted 10 lines · Tony Lindgren
Quoted 4 lines · Roger Quadros

This driver is needed for USB cable type detection on dra7-evm, dra72-evm and am57xx-beagle-x15.

Applying this into omap-for-v4.1/defconfig. I think it's all queued up after this, please check and repost patches if it's still missing something as I've marked all the extcon related threads as read here now.

Thanks Tony.

We just need to revert the following commit. addfcde7c485 ("ARM: dts: dra7x-evm: beagle-x15: Fix USB Host")

I'll send a patch on l-o for that.

cheers,
-roger

Quoted 9 lines

Regards,

Tony

Quoted 4 lines
---
 arch/arm/configs/omap2plus_defconfig | 1 +
 1 file changed, 1 insertion(+)
Quoted 15 lines
Quoted 15 lines
arch/arm/configs/omap2plus_defconfig +1 -0
index 667d9d5..7e10e58 100644
@@ -326,6 +326,7 @@ CONFIG_DMADEVICES=y
 CONFIG_TI_EDMA=y
 CONFIG_DMA_OMAP=y
 CONFIG_EXTCON=y
+CONFIG_EXTCON_USB_GPIO=m
 CONFIG_EXTCON_PALMAS=y
 CONFIG_PWM=y
 CONFIG_PWM_TIECAP=y
Signature · 1 line
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html