All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/7] extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 & AM57xx USB.
@ 2015-01-26 12:15 ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 12:15 UTC (permalink / raw)
  To: balbi, tony, myungjoo.ham, cw00.choi
  Cc: george.cherian, nsekhar, devicetree, linux-usb, linux-omap,
	linux-kernel, Roger Quadros

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

-- 
2.1.0


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

* [PATCH v2 0/7] extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 & AM57xx USB.
@ 2015-01-26 12:15 ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 12:15 UTC (permalink / raw)
  To: balbi, tony, myungjoo.ham, cw00.choi
  Cc: george.cherian, nsekhar, devicetree, linux-usb, linux-omap,
	linux-kernel, Roger Quadros

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

-- 
2.1.0

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

* [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-26 12:15   ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 12:15 UTC (permalink / raw)
  To: balbi, tony, myungjoo.ham, cw00.choi
  Cc: george.cherian, nsekhar, devicetree, linux-usb, linux-omap,
	linux-kernel, 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.

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 .../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

diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
new file mode 100644
index 0000000..ab52a85
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
@@ -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>;
+		...
+	};
diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
index 6a1f7de..e4c01ab 100644
--- a/drivers/extcon/Kconfig
+++ b/drivers/extcon/Kconfig
@@ -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
diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
index 0370b42..6a08a98 100644
--- a/drivers/extcon/Makefile
+++ b/drivers/extcon/Makefile
@@ -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
diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
new file mode 100644
index 0000000..a20aa39
--- /dev/null
+++ b/drivers/extcon/extcon-usb-gpio.c
@@ -0,0 +1,214 @@
+/**
+ * drivers/extcon/extcon_usb_gpio.c - USB GPIO extcon driver
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Roger Quadros <rogerq@ti.com>
+ *
+ * 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",
+	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);
+
+	/* 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],
+				       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);
+	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");
+		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);
+
+	/* 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);
+	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);
+	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);
+	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 */ }
+};
+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,
+	},
+};
+
+module_platform_driver(usb_extcon_driver);
+
+MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
+MODULE_DESCRIPTION("USB GPIO extcon driver");
+MODULE_LICENSE("GPL v2");
-- 
2.1.0


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

* [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-26 12:15   ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 12:15 UTC (permalink / raw)
  To: balbi-l0cyMroinI0, tony-4v6yS6AI5VpBDgjK7y7TUQ,
	myungjoo.ham-Sze3O3UU22JBDgjK7y7TUQ,
	cw00.choi-Sze3O3UU22JBDgjK7y7TUQ
  Cc: george.cherian-l0cyMroinI0, nsekhar-l0cyMroinI0,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, 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.

Signed-off-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
---
 .../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

diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
new file mode 100644
index 0000000..ab52a85
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
@@ -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>;
+		...
+	};
diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
index 6a1f7de..e4c01ab 100644
--- a/drivers/extcon/Kconfig
+++ b/drivers/extcon/Kconfig
@@ -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
diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
index 0370b42..6a08a98 100644
--- a/drivers/extcon/Makefile
+++ b/drivers/extcon/Makefile
@@ -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
diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
new file mode 100644
index 0000000..a20aa39
--- /dev/null
+++ b/drivers/extcon/extcon-usb-gpio.c
@@ -0,0 +1,214 @@
+/**
+ * drivers/extcon/extcon_usb_gpio.c - USB GPIO extcon driver
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
+ *
+ * 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",
+	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);
+
+	/* 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],
+				       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);
+	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");
+		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);
+
+	/* 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);
+	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);
+	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);
+	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 */ }
+};
+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,
+	},
+};
+
+module_platform_driver(usb_extcon_driver);
+
+MODULE_AUTHOR("Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>");
+MODULE_DESCRIPTION("USB GPIO extcon driver");
+MODULE_LICENSE("GPL v2");
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name
@ 2015-01-26 12:15   ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 12:15 UTC (permalink / raw)
  To: balbi, tony, myungjoo.ham, cw00.choi
  Cc: george.cherian, nsekhar, devicetree, linux-usb, linux-omap,
	linux-kernel, 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".

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Felipe Balbi <balbi@ti.com>
Acked-by: Felipe Balbi <balbi@ti.com>
---
 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(-)

diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
index 11c6757..6d002c3 100644
--- a/drivers/extcon/extcon-palmas.c
+++ b/drivers/extcon/extcon-palmas.c
@@ -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;
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index 172d64e..6713ad9 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -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);
 	}
 
diff --git a/drivers/usb/phy/phy-omap-otg.c b/drivers/usb/phy/phy-omap-otg.c
index 56ee760..53cba3f 100644
--- a/drivers/usb/phy/phy-omap-otg.c
+++ b/drivers/usb/phy/phy-omap-otg.c
@@ -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);
 
diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c
index 845f658..56d3704 100644
--- a/drivers/usb/phy/phy-tahvo.c
+++ b/drivers/usb/phy/phy-tahvo.c
@@ -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);
 
-- 
2.1.0


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

* [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name
@ 2015-01-26 12:15   ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 12:15 UTC (permalink / raw)
  To: balbi-l0cyMroinI0, tony-4v6yS6AI5VpBDgjK7y7TUQ,
	myungjoo.ham-Sze3O3UU22JBDgjK7y7TUQ,
	cw00.choi-Sze3O3UU22JBDgjK7y7TUQ
  Cc: george.cherian-l0cyMroinI0, nsekhar-l0cyMroinI0,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, 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".

Signed-off-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
Reviewed-by: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
Acked-by: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
---
 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(-)

diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
index 11c6757..6d002c3 100644
--- a/drivers/extcon/extcon-palmas.c
+++ b/drivers/extcon/extcon-palmas.c
@@ -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;
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index 172d64e..6713ad9 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -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);
 	}
 
diff --git a/drivers/usb/phy/phy-omap-otg.c b/drivers/usb/phy/phy-omap-otg.c
index 56ee760..53cba3f 100644
--- a/drivers/usb/phy/phy-omap-otg.c
+++ b/drivers/usb/phy/phy-omap-otg.c
@@ -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);
 
diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c
index 845f658..56d3704 100644
--- a/drivers/usb/phy/phy-tahvo.c
+++ b/drivers/usb/phy/phy-tahvo.c
@@ -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);
 
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v2 3/7] ARM: dts: dra7-evm: Add extcon nodes for USB
  2015-01-26 12:15 ` Roger Quadros
@ 2015-01-26 12:15   ` Roger Quadros
  -1 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 12:15 UTC (permalink / raw)
  To: balbi, tony, myungjoo.ham, cw00.choi
  Cc: george.cherian, nsekhar, devicetree, linux-usb, linux-omap,
	linux-kernel, 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.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Felipe Balbi <balbi@ti.com>
Acked-by: Felipe Balbi <balbi@ti.com>
---
 arch/arm/boot/dts/dra7-evm.dts | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/arch/arm/boot/dts/dra7-evm.dts b/arch/arm/boot/dts/dra7-evm.dts
index ad4118f..746cddb 100644
--- a/arch/arm/boot/dts/dra7-evm.dts
+++ b/arch/arm/boot/dts/dra7-evm.dts
@@ -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";
-- 
2.1.0


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

* [PATCH v2 3/7] ARM: dts: dra7-evm: Add extcon nodes for USB
@ 2015-01-26 12:15   ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 12:15 UTC (permalink / raw)
  To: balbi, tony, myungjoo.ham, cw00.choi
  Cc: george.cherian, nsekhar, devicetree, linux-usb, linux-omap,
	linux-kernel, 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.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Felipe Balbi <balbi@ti.com>
Acked-by: Felipe Balbi <balbi@ti.com>
---
 arch/arm/boot/dts/dra7-evm.dts | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/arch/arm/boot/dts/dra7-evm.dts b/arch/arm/boot/dts/dra7-evm.dts
index ad4118f..746cddb 100644
--- a/arch/arm/boot/dts/dra7-evm.dts
+++ b/arch/arm/boot/dts/dra7-evm.dts
@@ -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";
-- 
2.1.0

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

* [PATCH v2 4/7] ARM: dts: dra72-evm: Add extcon nodes for USB
  2015-01-26 12:15 ` Roger Quadros
@ 2015-01-26 12:15   ` Roger Quadros
  -1 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 12:15 UTC (permalink / raw)
  To: balbi, tony, myungjoo.ham, cw00.choi
  Cc: george.cherian, nsekhar, devicetree, linux-usb, linux-omap,
	linux-kernel, 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.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Felipe Balbi <balbi@ti.com>
Acked-by: Felipe Balbi <balbi@ti.com>
---
 arch/arm/boot/dts/dra72-evm.dts | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/arch/arm/boot/dts/dra72-evm.dts b/arch/arm/boot/dts/dra72-evm.dts
index 89085d0..ce8e243 100644
--- a/arch/arm/boot/dts/dra72-evm.dts
+++ b/arch/arm/boot/dts/dra72-evm.dts
@@ -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";
-- 
2.1.0


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

* [PATCH v2 4/7] ARM: dts: dra72-evm: Add extcon nodes for USB
@ 2015-01-26 12:15   ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 12:15 UTC (permalink / raw)
  To: balbi, tony, myungjoo.ham, cw00.choi
  Cc: george.cherian, nsekhar, devicetree, linux-usb, linux-omap,
	linux-kernel, 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.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Felipe Balbi <balbi@ti.com>
Acked-by: Felipe Balbi <balbi@ti.com>
---
 arch/arm/boot/dts/dra72-evm.dts | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/arch/arm/boot/dts/dra72-evm.dts b/arch/arm/boot/dts/dra72-evm.dts
index 89085d0..ce8e243 100644
--- a/arch/arm/boot/dts/dra72-evm.dts
+++ b/arch/arm/boot/dts/dra72-evm.dts
@@ -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";
-- 
2.1.0

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

* [PATCH v2 5/7] ARM: dts: am57xx-beagle-x15: Add extcon nodes for USB
  2015-01-26 12:15 ` Roger Quadros
@ 2015-01-26 12:15   ` Roger Quadros
  -1 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 12:15 UTC (permalink / raw)
  To: balbi, tony, myungjoo.ham, cw00.choi
  Cc: george.cherian, nsekhar, devicetree, linux-usb, linux-omap,
	linux-kernel, 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.

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 arch/arm/boot/dts/am57xx-beagle-x15.dts | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/arch/arm/boot/dts/am57xx-beagle-x15.dts b/arch/arm/boot/dts/am57xx-beagle-x15.dts
index 49edbda..ad1833b 100644
--- a/arch/arm/boot/dts/am57xx-beagle-x15.dts
+++ b/arch/arm/boot/dts/am57xx-beagle-x15.dts
@@ -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>;
+};
-- 
2.1.0


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

* [PATCH v2 5/7] ARM: dts: am57xx-beagle-x15: Add extcon nodes for USB
@ 2015-01-26 12:15   ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 12:15 UTC (permalink / raw)
  To: balbi, tony, myungjoo.ham, cw00.choi
  Cc: george.cherian, nsekhar, devicetree, linux-usb, linux-omap,
	linux-kernel, 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.

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 arch/arm/boot/dts/am57xx-beagle-x15.dts | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/arch/arm/boot/dts/am57xx-beagle-x15.dts b/arch/arm/boot/dts/am57xx-beagle-x15.dts
index 49edbda..ad1833b 100644
--- a/arch/arm/boot/dts/am57xx-beagle-x15.dts
+++ b/arch/arm/boot/dts/am57xx-beagle-x15.dts
@@ -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>;
+};
-- 
2.1.0


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

* [PATCH v2 6/7] ARM: dts: am57xx-beagle-x15: Fix USB2 mode
  2015-01-26 12:15 ` Roger Quadros
@ 2015-01-26 12:15   ` Roger Quadros
  -1 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 12:15 UTC (permalink / raw)
  To: balbi, tony, myungjoo.ham, cw00.choi
  Cc: george.cherian, nsekhar, devicetree, linux-usb, linux-omap,
	linux-kernel, Roger Quadros

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

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 arch/arm/boot/dts/am57xx-beagle-x15.dts | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/boot/dts/am57xx-beagle-x15.dts b/arch/arm/boot/dts/am57xx-beagle-x15.dts
index ad1833b..2115dda 100644
--- a/arch/arm/boot/dts/am57xx-beagle-x15.dts
+++ b/arch/arm/boot/dts/am57xx-beagle-x15.dts
@@ -436,3 +436,7 @@
 &omap_dwc3_2 {
 	extcon = <&extcon_usb2>;
 };
+
+&usb2 {
+	dr_mode = "peripheral";
+};
-- 
2.1.0


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

* [PATCH v2 6/7] ARM: dts: am57xx-beagle-x15: Fix USB2 mode
@ 2015-01-26 12:15   ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 12:15 UTC (permalink / raw)
  To: balbi, tony, myungjoo.ham, cw00.choi
  Cc: george.cherian, nsekhar, devicetree, linux-usb, linux-omap,
	linux-kernel, Roger Quadros

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

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 arch/arm/boot/dts/am57xx-beagle-x15.dts | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/boot/dts/am57xx-beagle-x15.dts b/arch/arm/boot/dts/am57xx-beagle-x15.dts
index ad1833b..2115dda 100644
--- a/arch/arm/boot/dts/am57xx-beagle-x15.dts
+++ b/arch/arm/boot/dts/am57xx-beagle-x15.dts
@@ -436,3 +436,7 @@
 &omap_dwc3_2 {
 	extcon = <&extcon_usb2>;
 };
+
+&usb2 {
+	dr_mode = "peripheral";
+};
-- 
2.1.0

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

* [PATCH v2 7/7] ARM: omap2plus_defconfig: Enable EXTCON_GPIO_USB
  2015-01-26 12:15 ` Roger Quadros
@ 2015-01-26 12:15   ` Roger Quadros
  -1 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 12:15 UTC (permalink / raw)
  To: balbi, tony, myungjoo.ham, cw00.choi
  Cc: george.cherian, nsekhar, devicetree, linux-usb, linux-omap,
	linux-kernel, Roger Quadros

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

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 arch/arm/configs/omap2plus_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
index 667d9d5..7e10e58 100644
--- a/arch/arm/configs/omap2plus_defconfig
+++ b/arch/arm/configs/omap2plus_defconfig
@@ -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
-- 
2.1.0


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

* [PATCH v2 7/7] ARM: omap2plus_defconfig: Enable EXTCON_GPIO_USB
@ 2015-01-26 12:15   ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 12:15 UTC (permalink / raw)
  To: balbi, tony, myungjoo.ham, cw00.choi
  Cc: george.cherian, nsekhar, devicetree, linux-usb, linux-omap,
	linux-kernel, Roger Quadros

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

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
 arch/arm/configs/omap2plus_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
index 667d9d5..7e10e58 100644
--- a/arch/arm/configs/omap2plus_defconfig
+++ b/arch/arm/configs/omap2plus_defconfig
@@ -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
-- 
2.1.0

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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-26 13:56     ` Chanwoo Choi
  0 siblings, 0 replies; 75+ messages in thread
From: Chanwoo Choi @ 2015-01-26 13:56 UTC (permalink / raw)
  To: Roger Quadros
  Cc: Felipe Balbi, tony, myungjoo.ham, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

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.

On Mon, Jan 26, 2015 at 9:15 PM, Roger Quadros <rogerq@ti.com> wrote:
> 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.
>
> Signed-off-by: Roger Quadros <rogerq@ti.com>
> ---
>  .../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
>
> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
> new file mode 100644
> index 0000000..ab52a85
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
> @@ -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>;
> +               ...

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>;
            };

> +       };
> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
> index 6a1f7de..e4c01ab 100644
> --- a/drivers/extcon/Kconfig
> +++ b/drivers/extcon/Kconfig
> @@ -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

> +       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
> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
> index 0370b42..6a08a98 100644
> --- a/drivers/extcon/Makefile
> +++ b/drivers/extcon/Makefile
> @@ -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
> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
> new file mode 100644
> index 0000000..a20aa39
> --- /dev/null
> +++ b/drivers/extcon/extcon-usb-gpio.c
> @@ -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

> + *
> + * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
> + * Author: Roger Quadros <rogerq@ti.com>
> + *
> + * 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",
> +       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);

> +
> +       /* 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],
> +                                      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.

> +       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");
> +               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);

> +
> +       /* 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.

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


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

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

> +};
> +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,
> +       },
> +};
> +
> +module_platform_driver(usb_extcon_driver);
> +
> +MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
> +MODULE_DESCRIPTION("USB GPIO extcon driver");
> +MODULE_LICENSE("GPL v2");

Thanks,
Chanwoo Choi

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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-26 13:56     ` Chanwoo Choi
  0 siblings, 0 replies; 75+ messages in thread
From: Chanwoo Choi @ 2015-01-26 13:56 UTC (permalink / raw)
  To: Roger Quadros
  Cc: Felipe Balbi, tony-4v6yS6AI5VpBDgjK7y7TUQ,
	myungjoo.ham-Sze3O3UU22JBDgjK7y7TUQ, george.cherian-l0cyMroinI0,
	nsekhar-l0cyMroinI0, devicetree,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA, linux-kernel

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.

On Mon, Jan 26, 2015 at 9:15 PM, Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org> wrote:
> 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.
>
> Signed-off-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
> ---
>  .../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
>
> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
> new file mode 100644
> index 0000000..ab52a85
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
> @@ -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>;
> +               ...

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>;
            };

> +       };
> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
> index 6a1f7de..e4c01ab 100644
> --- a/drivers/extcon/Kconfig
> +++ b/drivers/extcon/Kconfig
> @@ -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

> +       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
> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
> index 0370b42..6a08a98 100644
> --- a/drivers/extcon/Makefile
> +++ b/drivers/extcon/Makefile
> @@ -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
> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
> new file mode 100644
> index 0000000..a20aa39
> --- /dev/null
> +++ b/drivers/extcon/extcon-usb-gpio.c
> @@ -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

> + *
> + * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
> + * Author: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
> + *
> + * 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",
> +       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);

> +
> +       /* 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],
> +                                      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.

> +       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");
> +               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);

> +
> +       /* 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.

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


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

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

> +};
> +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,
> +       },
> +};
> +
> +module_platform_driver(usb_extcon_driver);
> +
> +MODULE_AUTHOR("Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>");
> +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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-01-26 13:56     ` Chanwoo Choi
@ 2015-01-26 16:27       ` Roger Quadros
  -1 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 16:27 UTC (permalink / raw)
  To: cw00.choi
  Cc: Felipe Balbi, tony, myungjoo.ham, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

Hi Chanwoo,

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

On 26/01/15 15:56, Chanwoo Choi wrote:
> 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.
> 
> On Mon, Jan 26, 2015 at 9:15 PM, Roger Quadros <rogerq@ti.com> wrote:
>> 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.
>>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> ---
>>  .../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>

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

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.

>> +       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");
>> +               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);
> 
>> +
>> +       /* 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.
> 
>> +       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?

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

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

> 
> 
>> +       return 0;
>> +}
>> +

<snip>

cheers,
-roger


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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-26 16:27       ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-26 16:27 UTC (permalink / raw)
  To: cw00.choi
  Cc: Felipe Balbi, tony, myungjoo.ham, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

Hi Chanwoo,

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

On 26/01/15 15:56, Chanwoo Choi wrote:
> 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.
> 
> On Mon, Jan 26, 2015 at 9:15 PM, Roger Quadros <rogerq@ti.com> wrote:
>> 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.
>>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> ---
>>  .../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>

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

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.

>> +       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");
>> +               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);
> 
>> +
>> +       /* 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.
> 
>> +       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?

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

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

> 
> 
>> +       return 0;
>> +}
>> +

<snip>

cheers,
-roger

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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-27  1:54         ` Chanwoo Choi
  0 siblings, 0 replies; 75+ messages in thread
From: Chanwoo Choi @ 2015-01-27  1:54 UTC (permalink / raw)
  To: Roger Quadros
  Cc: Felipe Balbi, tony, myungjoo.ham, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

Hi Roger,

On 01/27/2015 01:27 AM, Roger Quadros wrote:
> Hi Chanwoo,
> 
> All your comments are valid. Need some clarification on one comment.
> 
> On 26/01/15 15:56, Chanwoo Choi wrote:
>> 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.
>>
>> On Mon, Jan 26, 2015 at 9:15 PM, Roger Quadros <rogerq@ti.com> wrote:
>>> 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.
>>>
>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>> ---
>>>  .../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>
> 
>>> +
>>> +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);
> 
> 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.
> 
>>> +       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");
>>> +               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);
>>
>>> +
>>> +       /* 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.
>>
>>> +       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?
> 
>>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.

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

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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-27  1:54         ` Chanwoo Choi
  0 siblings, 0 replies; 75+ messages in thread
From: Chanwoo Choi @ 2015-01-27  1:54 UTC (permalink / raw)
  To: Roger Quadros
  Cc: Felipe Balbi, tony-4v6yS6AI5VpBDgjK7y7TUQ,
	myungjoo.ham-Sze3O3UU22JBDgjK7y7TUQ, george.cherian-l0cyMroinI0,
	nsekhar-l0cyMroinI0, devicetree,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA, linux-kernel

Hi Roger,

On 01/27/2015 01:27 AM, Roger Quadros wrote:
> Hi Chanwoo,
> 
> All your comments are valid. Need some clarification on one comment.
> 
> On 26/01/15 15:56, Chanwoo Choi wrote:
>> 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.
>>
>> On Mon, Jan 26, 2015 at 9:15 PM, Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org> wrote:
>>> 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.
>>>
>>> Signed-off-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
>>> ---
>>>  .../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>
> 
>>> +
>>> +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);
> 
> 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.
> 
>>> +       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");
>>> +               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);
>>
>>> +
>>> +       /* 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.
>>
>>> +       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?
> 
>>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.

> 
>>             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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-27 15:38           ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-27 15:38 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: Felipe Balbi, tony, myungjoo.ham, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

Chanwoo,

On 27/01/15 03:54, Chanwoo Choi wrote:
> Hi Roger,
> 
> On 01/27/2015 01:27 AM, Roger Quadros wrote:
>> Hi Chanwoo,
>>
>> All your comments are valid. Need some clarification on one comment.
>>
>> On 26/01/15 15:56, Chanwoo Choi wrote:
>>> 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.
>>>
>>> On Mon, Jan 26, 2015 at 9:15 PM, Roger Quadros <rogerq@ti.com> wrote:
>>>> 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.
>>>>
>>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>>> ---
>>>>  .../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>
>>
>>>> +
>>>> +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);
>>
>> 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.
>>
>>>> +       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");
>>>> +               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);
>>>
>>>> +
>>>> +       /* 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.
>>>
>>>> +       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?
>>
>> >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.
> 
OK.

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

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

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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-27 15:38           ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-27 15:38 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: Felipe Balbi, tony-4v6yS6AI5VpBDgjK7y7TUQ,
	myungjoo.ham-Sze3O3UU22JBDgjK7y7TUQ, george.cherian-l0cyMroinI0,
	nsekhar-l0cyMroinI0, devicetree,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA, linux-kernel

Chanwoo,

On 27/01/15 03:54, Chanwoo Choi wrote:
> Hi Roger,
> 
> On 01/27/2015 01:27 AM, Roger Quadros wrote:
>> Hi Chanwoo,
>>
>> All your comments are valid. Need some clarification on one comment.
>>
>> On 26/01/15 15:56, Chanwoo Choi wrote:
>>> 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.
>>>
>>> On Mon, Jan 26, 2015 at 9:15 PM, Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org> wrote:
>>>> 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.
>>>>
>>>> Signed-off-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
>>>> ---
>>>>  .../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>
>>
>>>> +
>>>> +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);
>>
>> 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.
>>
>>>> +       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");
>>>> +               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);
>>>
>>>> +
>>>> +       /* 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.
>>>
>>>> +       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?
>>
>> >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.
> 
OK.

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

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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-01-27 15:38           ` Roger Quadros
  (?)
@ 2015-01-28  2:19           ` Chanwoo Choi
  2015-01-28 12:12               ` Roger Quadros
  -1 siblings, 1 reply; 75+ messages in thread
From: Chanwoo Choi @ 2015-01-28  2:19 UTC (permalink / raw)
  To: Roger Quadros
  Cc: Felipe Balbi, tony, myungjoo.ham, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

Hi Roger,

On 01/28/2015 12:38 AM, Roger Quadros wrote:
> Chanwoo,
> 
> On 27/01/15 03:54, Chanwoo Choi wrote:
>> Hi Roger,
>>
>> On 01/27/2015 01:27 AM, Roger Quadros wrote:
>>> Hi Chanwoo,
>>>
>>> All your comments are valid. Need some clarification on one comment.
>>>
>>> On 26/01/15 15:56, Chanwoo Choi wrote:
>>>> 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.
>>>>
>>>> On Mon, Jan 26, 2015 at 9:15 PM, Roger Quadros <rogerq@ti.com> wrote:
>>>>> 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.
>>>>>
>>>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>>>> ---
>>>>>  .../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>
>>>
>>>>> +
>>>>> +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);
>>>
>>> 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.
>>>
>>>>> +       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");
>>>>> +               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);
>>>>
>>>>> +
>>>>> +       /* 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.
>>>>
>>>>> +       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?
>>>
>>> >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.
>>
> OK.
> 
>>>
>>>>             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.
> 
> 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


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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-01-28  2:19           ` Chanwoo Choi
@ 2015-01-28 12:12               ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-28 12:12 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: Felipe Balbi, tony, myungjoo.ham, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

Chanwoo,

On 28/01/15 04:19, Chanwoo Choi wrote:
> Hi Roger,
> 
> On 01/28/2015 12:38 AM, Roger Quadros wrote:
>> Chanwoo,
>>
>> On 27/01/15 03:54, Chanwoo Choi wrote:
>>> Hi Roger,
>>>
>>> On 01/27/2015 01:27 AM, Roger Quadros wrote:
>>>> Hi Chanwoo,
>>>>
>>>> All your comments are valid. Need some clarification on one comment.
>>>>
>>>> On 26/01/15 15:56, Chanwoo Choi wrote:
>>>>> 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.
>>>>>
>>>>> On Mon, Jan 26, 2015 at 9:15 PM, Roger Quadros <rogerq@ti.com> wrote:
>>>>>> 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.
>>>>>>
>>>>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>>>>> ---
>>>>>>  .../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>
>>>>
>>>>>> +
>>>>>> +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);
>>>>
>>>> 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.
>>>>
>>>>>> +       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");
>>>>>> +               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);
>>>>>
>>>>>> +
>>>>>> +       /* 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.
>>>>>
>>>>>> +       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?
>>>>
>>>> >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.
>>>
>> OK.
>>
>>>>
>>>>>             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.
>>
>> 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 for this information. I will add disable/enable_irq() in suspend/resume().

cheers,
-roger


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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-28 12:12               ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-28 12:12 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: Felipe Balbi, tony, myungjoo.ham, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

Chanwoo,

On 28/01/15 04:19, Chanwoo Choi wrote:
> Hi Roger,
> 
> On 01/28/2015 12:38 AM, Roger Quadros wrote:
>> Chanwoo,
>>
>> On 27/01/15 03:54, Chanwoo Choi wrote:
>>> Hi Roger,
>>>
>>> On 01/27/2015 01:27 AM, Roger Quadros wrote:
>>>> Hi Chanwoo,
>>>>
>>>> All your comments are valid. Need some clarification on one comment.
>>>>
>>>> On 26/01/15 15:56, Chanwoo Choi wrote:
>>>>> 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.
>>>>>
>>>>> On Mon, Jan 26, 2015 at 9:15 PM, Roger Quadros <rogerq@ti.com> wrote:
>>>>>> 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.
>>>>>>
>>>>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>>>>> ---
>>>>>>  .../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>
>>>>
>>>>>> +
>>>>>> +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);
>>>>
>>>> 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.
>>>>
>>>>>> +       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");
>>>>>> +               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);
>>>>>
>>>>>> +
>>>>>> +       /* 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.
>>>>>
>>>>>> +       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?
>>>>
>>>> >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.
>>>
>> OK.
>>
>>>>
>>>>>             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.
>>
>> 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 for this information. I will add disable/enable_irq() in suspend/resume().

cheers,
-roger

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

* [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-01-26 12:15   ` Roger Quadros
@ 2015-01-28 12:15     ` Roger Quadros
  -1 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-28 12:15 UTC (permalink / raw)
  To: myungjoo.ham, cw00.choi
  Cc: balbi, tony, george.cherian, nsekhar, devicetree, linux-usb,
	linux-omap, linux-kernel, 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.

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
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

diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
new file mode 100644
index 0000000..85fe6b0
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
@@ -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>;
+	};
diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
index 6a1f7de..fd11536 100644
--- a/drivers/extcon/Kconfig
+++ b/drivers/extcon/Kconfig
@@ -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
diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
index 0370b42..6a08a98 100644
--- a/drivers/extcon/Makefile
+++ b/drivers/extcon/Makefile
@@ -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
diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
new file mode 100644
index 0000000..99a58b2
--- /dev/null
+++ b/drivers/extcon/extcon-usb-gpio.c
@@ -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 <rogerq@ti.com>
+ *
+ * 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,
+};
+
+static const char *usb_extcon_cable[] = {
+	[EXTCON_CABLE_USB] = "USB",
+	[EXTCON_CABLE_USB_HOST] = "USB-Host",
+	NULL,
+};
+
+static void usb_extcon_detect_cable(struct work_struct *work)
+{
+	int id;
+	struct usb_extcon_info *info = container_of(to_delayed_work(work),
+						    struct usb_extcon_info,
+						    wq_detcable);
+
+	/* 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],
+				       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);
+
+	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_TRIGGER_RISING |
+					IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+					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");
+		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);
+	device_init_wakeup(dev, 1);
+
+	/* 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);
+
+	return 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;
+
+	/*
+	 * 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;
+}
+
+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;
+	}
+
+	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,
+	},
+};
+
+module_platform_driver(usb_extcon_driver);
+
+MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
+MODULE_DESCRIPTION("USB GPIO extcon driver");
+MODULE_LICENSE("GPL v2");
-- 
2.1.0



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

* [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-28 12:15     ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-28 12:15 UTC (permalink / raw)
  To: myungjoo.ham, cw00.choi
  Cc: balbi, tony, george.cherian, nsekhar, devicetree, linux-usb,
	linux-omap, linux-kernel, 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.

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
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

diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
new file mode 100644
index 0000000..85fe6b0
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
@@ -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>;
+	};
diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
index 6a1f7de..fd11536 100644
--- a/drivers/extcon/Kconfig
+++ b/drivers/extcon/Kconfig
@@ -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
diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
index 0370b42..6a08a98 100644
--- a/drivers/extcon/Makefile
+++ b/drivers/extcon/Makefile
@@ -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
diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
new file mode 100644
index 0000000..99a58b2
--- /dev/null
+++ b/drivers/extcon/extcon-usb-gpio.c
@@ -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 <rogerq@ti.com>
+ *
+ * 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,
+};
+
+static const char *usb_extcon_cable[] = {
+	[EXTCON_CABLE_USB] = "USB",
+	[EXTCON_CABLE_USB_HOST] = "USB-Host",
+	NULL,
+};
+
+static void usb_extcon_detect_cable(struct work_struct *work)
+{
+	int id;
+	struct usb_extcon_info *info = container_of(to_delayed_work(work),
+						    struct usb_extcon_info,
+						    wq_detcable);
+
+	/* 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],
+				       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);
+
+	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_TRIGGER_RISING |
+					IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+					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");
+		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);
+	device_init_wakeup(dev, 1);
+
+	/* 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);
+
+	return 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;
+
+	/*
+	 * 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;
+}
+
+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;
+	}
+
+	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,
+	},
+};
+
+module_platform_driver(usb_extcon_driver);
+
+MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
+MODULE_DESCRIPTION("USB GPIO extcon driver");
+MODULE_LICENSE("GPL v2");
-- 
2.1.0

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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-01-28 12:12               ` Roger Quadros
  (?)
@ 2015-01-28 17:09               ` Tony Lindgren
  2015-01-29 11:31                   ` Roger Quadros
  -1 siblings, 1 reply; 75+ messages in thread
From: Tony Lindgren @ 2015-01-28 17:09 UTC (permalink / raw)
  To: Roger Quadros
  Cc: Chanwoo Choi, Felipe Balbi, myungjoo.ham, george.cherian,
	nsekhar, devicetree, linux-usb, linux-omap, linux-kernel

* Roger Quadros <rogerq@ti.com> [150128 04:15]:
> On 28/01/15 04:19, Chanwoo Choi wrote:
> >>
> >> 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 for this information. I will add disable/enable_irq() in suspend/resume().

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

Regards,

Tony

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

* Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-01-28 12:15     ` Roger Quadros
  (?)
@ 2015-01-29  1:49     ` Chanwoo Choi
  2015-01-29 11:26         ` Roger Quadros
  -1 siblings, 1 reply; 75+ messages in thread
From: Chanwoo Choi @ 2015-01-29  1:49 UTC (permalink / raw)
  To: Roger Quadros
  Cc: myungjoo.ham, balbi, tony, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

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.

On 01/28/2015 09:15 PM, Roger Quadros wrote:
> 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.
> 
> Signed-off-by: Roger Quadros <rogerq@ti.com>
> ---
> 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
> 
> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
> new file mode 100644
> index 0000000..85fe6b0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
> @@ -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>;
> +	};
> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
> index 6a1f7de..fd11536 100644
> --- a/drivers/extcon/Kconfig
> +++ b/drivers/extcon/Kconfig
> @@ -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

> +	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
> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
> index 0370b42..6a08a98 100644
> --- a/drivers/extcon/Makefile
> +++ b/drivers/extcon/Makefile
> @@ -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
> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
> new file mode 100644
> index 0000000..99a58b2
> --- /dev/null
> +++ b/drivers/extcon/extcon-usb-gpio.c
> @@ -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 <rogerq@ti.com>
> + *
> + * 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 */

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

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

> +
> +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;
> +}
> +
> +#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);

> +	/*
> +	 * 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;
> +}
> +
> +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);

> +
> +	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,
> +	},
> +};
> +
> +module_platform_driver(usb_extcon_driver);
> +
> +MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
> +MODULE_DESCRIPTION("USB GPIO extcon driver");
> +MODULE_LICENSE("GPL v2");
> 

Thanks,
Chanwoo Choi


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

* Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-01-29  1:49     ` Chanwoo Choi
@ 2015-01-29 11:26         ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-29 11:26 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: myungjoo.ham, balbi, tony, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Chanwoo,

On 29/01/15 03:49, Chanwoo Choi wrote:
> 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.
> 
> On 01/28/2015 09:15 PM, Roger Quadros wrote:
>> 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.
>>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> ---
>> 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
>>
>> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>> new file mode 100644
>> index 0000000..85fe6b0
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>> @@ -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>;
>> +	};
>> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
>> index 6a1f7de..fd11536 100644
>> --- a/drivers/extcon/Kconfig
>> +++ b/drivers/extcon/Kconfig
>> @@ -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.

OK. Thanks.

> 
> 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
> 
>> +	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
>> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
>> index 0370b42..6a08a98 100644
>> --- a/drivers/extcon/Makefile
>> +++ b/drivers/extcon/Makefile
>> @@ -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
>> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
>> new file mode 100644
>> index 0000000..99a58b2
>> --- /dev/null
>> +++ b/drivers/extcon/extcon-usb-gpio.c
>> @@ -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 <rogerq@ti.com>
>> + *
>> + * 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 */
> 
> Do you really think id_irqwake is necessary?
> I think it is not necessary.

I will explain below why it is necessary.

> 
>> +
>> +	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]
> 
>> +
>> +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;
>> +}
>> +
>> +#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);

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.

> 
>> +	/*
>> +	 * 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;
>> +}
>> +
>> +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);
> 
>> +
>> +	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,
>> +	},
>> +};
>> +
>> +module_platform_driver(usb_extcon_driver);
>> +
>> +MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
>> +MODULE_DESCRIPTION("USB GPIO extcon driver");
>> +MODULE_LICENSE("GPL v2");
>>
> 
cheers,
-roger

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

* Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-29 11:26         ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-29 11:26 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: myungjoo.ham, balbi, tony, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Chanwoo,

On 29/01/15 03:49, Chanwoo Choi wrote:
> 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.
> 
> On 01/28/2015 09:15 PM, Roger Quadros wrote:
>> 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.
>>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> ---
>> 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
>>
>> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>> new file mode 100644
>> index 0000000..85fe6b0
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>> @@ -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>;
>> +	};
>> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
>> index 6a1f7de..fd11536 100644
>> --- a/drivers/extcon/Kconfig
>> +++ b/drivers/extcon/Kconfig
>> @@ -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.

OK. Thanks.

> 
> 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
> 
>> +	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
>> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
>> index 0370b42..6a08a98 100644
>> --- a/drivers/extcon/Makefile
>> +++ b/drivers/extcon/Makefile
>> @@ -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
>> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
>> new file mode 100644
>> index 0000000..99a58b2
>> --- /dev/null
>> +++ b/drivers/extcon/extcon-usb-gpio.c
>> @@ -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 <rogerq@ti.com>
>> + *
>> + * 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 */
> 
> Do you really think id_irqwake is necessary?
> I think it is not necessary.

I will explain below why it is necessary.

> 
>> +
>> +	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]
> 
>> +
>> +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;
>> +}
>> +
>> +#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);

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.

> 
>> +	/*
>> +	 * 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;
>> +}
>> +
>> +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);
> 
>> +
>> +	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,
>> +	},
>> +};
>> +
>> +module_platform_driver(usb_extcon_driver);
>> +
>> +MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
>> +MODULE_DESCRIPTION("USB GPIO extcon driver");
>> +MODULE_LICENSE("GPL v2");
>>
> 
cheers,
-roger

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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-01-28 17:09               ` Tony Lindgren
@ 2015-01-29 11:31                   ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-29 11:31 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: Chanwoo Choi, Felipe Balbi, myungjoo.ham, george.cherian,
	nsekhar, devicetree, linux-usb, linux-omap, linux-kernel

On 28/01/15 19:09, Tony Lindgren wrote:
> * Roger Quadros <rogerq@ti.com> [150128 04:15]:
>> On 28/01/15 04:19, Chanwoo Choi wrote:
>>>>
>>>> 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 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


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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-29 11:31                   ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-29 11:31 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: Chanwoo Choi, Felipe Balbi, myungjoo.ham, george.cherian,
	nsekhar, devicetree, linux-usb, linux-omap, linux-kernel

On 28/01/15 19:09, Tony Lindgren wrote:
> * Roger Quadros <rogerq@ti.com> [150128 04:15]:
>> On 28/01/15 04:19, Chanwoo Choi wrote:
>>>>
>>>> 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 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

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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-01-29 11:31                   ` Roger Quadros
  (?)
@ 2015-01-29 16:56                   ` Tony Lindgren
  2015-01-30 10:58                       ` Roger Quadros
  -1 siblings, 1 reply; 75+ messages in thread
From: Tony Lindgren @ 2015-01-29 16:56 UTC (permalink / raw)
  To: Roger Quadros
  Cc: Chanwoo Choi, Felipe Balbi, myungjoo.ham, george.cherian,
	nsekhar, devicetree, linux-usb, linux-omap, linux-kernel

* Roger Quadros <rogerq@ti.com> [150129 03:34]:
> On 28/01/15 19:09, Tony Lindgren wrote:
> > * Roger Quadros <rogerq@ti.com> [150128 04:15]:
> >> On 28/01/15 04:19, Chanwoo Choi wrote:
> >>>>
> >>>> 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 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

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

* Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-01-29 11:26         ` Roger Quadros
  (?)
@ 2015-01-30  0:06         ` Chanwoo Choi
  2015-01-30 11:09             ` Roger Quadros
  -1 siblings, 1 reply; 75+ messages in thread
From: Chanwoo Choi @ 2015-01-30  0:06 UTC (permalink / raw)
  To: Roger Quadros
  Cc: myungjoo.ham, balbi, tony, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Hi Roger,

On 01/29/2015 08:26 PM, Roger Quadros wrote:
> Chanwoo,
> 
> On 29/01/15 03:49, Chanwoo Choi wrote:
>> 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.
>>
>> On 01/28/2015 09:15 PM, Roger Quadros wrote:
>>> 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.
>>>
>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>> ---
>>> 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
>>>
>>> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>>> new file mode 100644
>>> index 0000000..85fe6b0
>>> --- /dev/null
>>> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>>> @@ -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>;
>>> +	};
>>> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
>>> index 6a1f7de..fd11536 100644
>>> --- a/drivers/extcon/Kconfig
>>> +++ b/drivers/extcon/Kconfig
>>> @@ -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.
> 
> OK. Thanks.
> 
>>
>> 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
>>
>>> +	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
>>> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
>>> index 0370b42..6a08a98 100644
>>> --- a/drivers/extcon/Makefile
>>> +++ b/drivers/extcon/Makefile
>>> @@ -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
>>> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
>>> new file mode 100644
>>> index 0000000..99a58b2
>>> --- /dev/null
>>> +++ b/drivers/extcon/extcon-usb-gpio.c
>>> @@ -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 <rogerq@ti.com>
>>> + *
>>> + * 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 */
>>
>> Do you really think id_irqwake is necessary?
>> I think it is not necessary.
> 
> I will explain below why it is necessary.
> 
>>
>>> +
>>> +	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]
>>
>>> +
>>> +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;
>>> +}
>>> +
>>> +#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);
> 
> 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.

> 
>>
>>> +	/*
>>> +	 * 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;
>>> +}
>>> +
>>> +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);
>>
>>> +
>>> +	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,
>>> +	},
>>> +};
>>> +
>>> +module_platform_driver(usb_extcon_driver);
>>> +
>>> +MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
>>> +MODULE_DESCRIPTION("USB GPIO extcon driver");
>>> +MODULE_LICENSE("GPL v2");

Thanks,
Chanwoo


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

* Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-01-28 12:15     ` Roger Quadros
  (?)
  (?)
@ 2015-01-30  0:11     ` Chanwoo Choi
  2015-01-30 14:03         ` Roger Quadros
  -1 siblings, 1 reply; 75+ messages in thread
From: Chanwoo Choi @ 2015-01-30  0:11 UTC (permalink / raw)
  To: Roger Quadros
  Cc: myungjoo.ham, balbi, tony, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Hi Roger,

On 01/28/2015 09:15 PM, Roger Quadros wrote:
> 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.
> 
> Signed-off-by: Roger Quadros <rogerq@ti.com>
> ---
> 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
> 
> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
> new file mode 100644
> index 0000000..85fe6b0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
> @@ -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>;
> +	};
> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
> index 6a1f7de..fd11536 100644
> --- a/drivers/extcon/Kconfig
> +++ b/drivers/extcon/Kconfig
> @@ -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
> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
> index 0370b42..6a08a98 100644
> --- a/drivers/extcon/Makefile
> +++ b/drivers/extcon/Makefile
> @@ -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
> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
> new file mode 100644
> index 0000000..99a58b2
> --- /dev/null
> +++ b/drivers/extcon/extcon-usb-gpio.c
> @@ -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 <rogerq@ti.com>
> + *
> + * 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,
> +};
> +
> +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

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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-30 10:58                       ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-30 10:58 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: Chanwoo Choi, Felipe Balbi, myungjoo.ham, george.cherian,
	nsekhar, devicetree, linux-usb, linux-omap, linux-kernel

On 29/01/15 18:56, Tony Lindgren wrote:
> * Roger Quadros <rogerq@ti.com> [150129 03:34]:
>> On 28/01/15 19:09, Tony Lindgren wrote:
>>> * Roger Quadros <rogerq@ti.com> [150128 04:15]:
>>>> On 28/01/15 04:19, Chanwoo Choi wrote:
>>>>>>
>>>>>> 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 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.

Sounds good to me. Thanks Tony.

cheers,
-roger

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

* Re: [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-30 10:58                       ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-30 10:58 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: Chanwoo Choi, Felipe Balbi, myungjoo.ham-Sze3O3UU22JBDgjK7y7TUQ,
	george.cherian-l0cyMroinI0, nsekhar-l0cyMroinI0, devicetree,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA, linux-kernel

On 29/01/15 18:56, Tony Lindgren wrote:
> * Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org> [150129 03:34]:
>> On 28/01/15 19:09, Tony Lindgren wrote:
>>> * Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org> [150128 04:15]:
>>>> On 28/01/15 04:19, Chanwoo Choi wrote:
>>>>>>
>>>>>> 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 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.

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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name
  2015-01-26 12:15   ` Roger Quadros
@ 2015-01-30 11:04     ` Roger Quadros
  -1 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-30 11:04 UTC (permalink / raw)
  To: balbi, cw00.choi
  Cc: tony, myungjoo.ham, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Felipe & Chanwoo,

On 26/01/15 14:15, Roger Quadros wrote:
> 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".
> 
> Signed-off-by: Roger Quadros <rogerq@ti.com>
> Reviewed-by: Felipe Balbi <balbi@ti.com>
> Acked-by: Felipe Balbi <balbi@ti.com>

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

> ---
>  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(-)
> 
> diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
> index 11c6757..6d002c3 100644
> --- a/drivers/extcon/extcon-palmas.c
> +++ b/drivers/extcon/extcon-palmas.c
> @@ -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;
> diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
> index 172d64e..6713ad9 100644
> --- a/drivers/usb/dwc3/dwc3-omap.c
> +++ b/drivers/usb/dwc3/dwc3-omap.c
> @@ -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);
>  	}
>  
> diff --git a/drivers/usb/phy/phy-omap-otg.c b/drivers/usb/phy/phy-omap-otg.c
> index 56ee760..53cba3f 100644
> --- a/drivers/usb/phy/phy-omap-otg.c
> +++ b/drivers/usb/phy/phy-omap-otg.c
> @@ -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);
>  
> diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c
> index 845f658..56d3704 100644
> --- a/drivers/usb/phy/phy-tahvo.c
> +++ b/drivers/usb/phy/phy-tahvo.c
> @@ -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);
>  
> 


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

* Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name
@ 2015-01-30 11:04     ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-30 11:04 UTC (permalink / raw)
  To: balbi, cw00.choi
  Cc: tony, myungjoo.ham, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Felipe & Chanwoo,

On 26/01/15 14:15, Roger Quadros wrote:
> 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".
> 
> Signed-off-by: Roger Quadros <rogerq@ti.com>
> Reviewed-by: Felipe Balbi <balbi@ti.com>
> Acked-by: Felipe Balbi <balbi@ti.com>

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

> ---
>  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(-)
> 
> diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
> index 11c6757..6d002c3 100644
> --- a/drivers/extcon/extcon-palmas.c
> +++ b/drivers/extcon/extcon-palmas.c
> @@ -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;
> diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
> index 172d64e..6713ad9 100644
> --- a/drivers/usb/dwc3/dwc3-omap.c
> +++ b/drivers/usb/dwc3/dwc3-omap.c
> @@ -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);
>  	}
>  
> diff --git a/drivers/usb/phy/phy-omap-otg.c b/drivers/usb/phy/phy-omap-otg.c
> index 56ee760..53cba3f 100644
> --- a/drivers/usb/phy/phy-omap-otg.c
> +++ b/drivers/usb/phy/phy-omap-otg.c
> @@ -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);
>  
> diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c
> index 845f658..56d3704 100644
> --- a/drivers/usb/phy/phy-tahvo.c
> +++ b/drivers/usb/phy/phy-tahvo.c
> @@ -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);
>  
> 

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

* Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-30 11:09             ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-30 11:09 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: myungjoo.ham, balbi, tony, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Chanwoo,

On 30/01/15 02:06, Chanwoo Choi wrote:
> Hi Roger,
> 
> On 01/29/2015 08:26 PM, Roger Quadros wrote:
>> Chanwoo,
>>
>> On 29/01/15 03:49, Chanwoo Choi wrote:
>>> 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.
>>>
>>> On 01/28/2015 09:15 PM, Roger Quadros wrote:
>>>> 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.
>>>>
>>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>>> ---
>>>> 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
>>>>
>>>> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>>>> new file mode 100644
>>>> index 0000000..85fe6b0
>>>> --- /dev/null
>>>> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>>>> @@ -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>;
>>>> +	};
>>>> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
>>>> index 6a1f7de..fd11536 100644
>>>> --- a/drivers/extcon/Kconfig
>>>> +++ b/drivers/extcon/Kconfig
>>>> @@ -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.
>>
>> OK. Thanks.
>>
>>>
>>> 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
>>>
>>>> +	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
>>>> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
>>>> index 0370b42..6a08a98 100644
>>>> --- a/drivers/extcon/Makefile
>>>> +++ b/drivers/extcon/Makefile
>>>> @@ -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
>>>> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
>>>> new file mode 100644
>>>> index 0000000..99a58b2
>>>> --- /dev/null
>>>> +++ b/drivers/extcon/extcon-usb-gpio.c
>>>> @@ -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 <rogerq@ti.com>
>>>> + *
>>>> + * 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 */
>>>
>>> Do you really think id_irqwake is necessary?
>>> I think it is not necessary.
>>
>> I will explain below why it is necessary.
>>
>>>
>>>> +
>>>> +	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]
>>>
>>>> +
>>>> +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;
>>>> +}
>>>> +
>>>> +#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);
>>
>> 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


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

* Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-30 11:09             ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-30 11:09 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: myungjoo.ham-Sze3O3UU22JBDgjK7y7TUQ, balbi-l0cyMroinI0,
	tony-4v6yS6AI5VpBDgjK7y7TUQ, george.cherian-l0cyMroinI0,
	nsekhar-l0cyMroinI0, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

Chanwoo,

On 30/01/15 02:06, Chanwoo Choi wrote:
> Hi Roger,
> 
> On 01/29/2015 08:26 PM, Roger Quadros wrote:
>> Chanwoo,
>>
>> On 29/01/15 03:49, Chanwoo Choi wrote:
>>> 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.
>>>
>>> On 01/28/2015 09:15 PM, Roger Quadros wrote:
>>>> 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.
>>>>
>>>> Signed-off-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
>>>> ---
>>>> 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
>>>>
>>>> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>>>> new file mode 100644
>>>> index 0000000..85fe6b0
>>>> --- /dev/null
>>>> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>>>> @@ -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>;
>>>> +	};
>>>> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
>>>> index 6a1f7de..fd11536 100644
>>>> --- a/drivers/extcon/Kconfig
>>>> +++ b/drivers/extcon/Kconfig
>>>> @@ -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.
>>
>> OK. Thanks.
>>
>>>
>>> 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
>>>
>>>> +	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
>>>> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
>>>> index 0370b42..6a08a98 100644
>>>> --- a/drivers/extcon/Makefile
>>>> +++ b/drivers/extcon/Makefile
>>>> @@ -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
>>>> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
>>>> new file mode 100644
>>>> index 0000000..99a58b2
>>>> --- /dev/null
>>>> +++ b/drivers/extcon/extcon-usb-gpio.c
>>>> @@ -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 <rogerq-l0cyMroinI0@public.gmane.org>
>>>> + *
>>>> + * 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 */
>>>
>>> Do you really think id_irqwake is necessary?
>>> I think it is not necessary.
>>
>> I will explain below why it is necessary.
>>
>>>
>>>> +
>>>> +	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]
>>>
>>>> +
>>>> +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;
>>>> +}
>>>> +
>>>> +#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);
>>
>> 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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-01-30 11:09             ` Roger Quadros
@ 2015-01-30 13:57               ` Roger Quadros
  -1 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-30 13:57 UTC (permalink / raw)
  To: Chanwoo Choi, Thomas Gleixner
  Cc: myungjoo.ham, balbi, tony, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

+Thomas (for irq/dummychip.c question)

Hi,

On 30/01/15 13:09, Roger Quadros wrote:
> Chanwoo,
> 
> On 30/01/15 02:06, Chanwoo Choi wrote:
>> Hi Roger,
>>
>> On 01/29/2015 08:26 PM, Roger Quadros wrote:
>>> Chanwoo,
>>>
>>> On 29/01/15 03:49, Chanwoo Choi wrote:
>>>> 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.
>>>>
>>>> On 01/28/2015 09:15 PM, Roger Quadros wrote:
>>>>> 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.
>>>>>
>>>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>>>> ---
>>>>> 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
>>>>>
>>>>> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>>>>> new file mode 100644
>>>>> index 0000000..85fe6b0
>>>>> --- /dev/null
>>>>> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>>>>> @@ -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>;
>>>>> +	};
>>>>> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
>>>>> index 6a1f7de..fd11536 100644
>>>>> --- a/drivers/extcon/Kconfig
>>>>> +++ b/drivers/extcon/Kconfig
>>>>> @@ -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.
>>>
>>> OK. Thanks.
>>>
>>>>
>>>> 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
>>>>
>>>>> +	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
>>>>> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
>>>>> index 0370b42..6a08a98 100644
>>>>> --- a/drivers/extcon/Makefile
>>>>> +++ b/drivers/extcon/Makefile
>>>>> @@ -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
>>>>> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
>>>>> new file mode 100644
>>>>> index 0000000..99a58b2
>>>>> --- /dev/null
>>>>> +++ b/drivers/extcon/extcon-usb-gpio.c
>>>>> @@ -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 <rogerq@ti.com>
>>>>> + *
>>>>> + * 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 */
>>>>
>>>> Do you really think id_irqwake is necessary?
>>>> I think it is not necessary.
>>>
>>> I will explain below why it is necessary.
>>>
>>>>
>>>>> +
>>>>> +	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]
>>>>
>>>>> +
>>>>> +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;
>>>>> +}
>>>>> +
>>>>> +#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);
>>>
>>> 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.
> 

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

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

* Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-30 13:57               ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-30 13:57 UTC (permalink / raw)
  To: Chanwoo Choi, Thomas Gleixner
  Cc: myungjoo.ham, balbi, tony, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

+Thomas (for irq/dummychip.c question)

Hi,

On 30/01/15 13:09, Roger Quadros wrote:
> Chanwoo,
> 
> On 30/01/15 02:06, Chanwoo Choi wrote:
>> Hi Roger,
>>
>> On 01/29/2015 08:26 PM, Roger Quadros wrote:
>>> Chanwoo,
>>>
>>> On 29/01/15 03:49, Chanwoo Choi wrote:
>>>> 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.
>>>>
>>>> On 01/28/2015 09:15 PM, Roger Quadros wrote:
>>>>> 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.
>>>>>
>>>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>>>> ---
>>>>> 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
>>>>>
>>>>> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>>>>> new file mode 100644
>>>>> index 0000000..85fe6b0
>>>>> --- /dev/null
>>>>> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>>>>> @@ -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>;
>>>>> +	};
>>>>> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
>>>>> index 6a1f7de..fd11536 100644
>>>>> --- a/drivers/extcon/Kconfig
>>>>> +++ b/drivers/extcon/Kconfig
>>>>> @@ -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.
>>>
>>> OK. Thanks.
>>>
>>>>
>>>> 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
>>>>
>>>>> +	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
>>>>> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
>>>>> index 0370b42..6a08a98 100644
>>>>> --- a/drivers/extcon/Makefile
>>>>> +++ b/drivers/extcon/Makefile
>>>>> @@ -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
>>>>> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
>>>>> new file mode 100644
>>>>> index 0000000..99a58b2
>>>>> --- /dev/null
>>>>> +++ b/drivers/extcon/extcon-usb-gpio.c
>>>>> @@ -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 <rogerq@ti.com>
>>>>> + *
>>>>> + * 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 */
>>>>
>>>> Do you really think id_irqwake is necessary?
>>>> I think it is not necessary.
>>>
>>> I will explain below why it is necessary.
>>>
>>>>
>>>>> +
>>>>> +	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]
>>>>
>>>>> +
>>>>> +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;
>>>>> +}
>>>>> +
>>>>> +#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);
>>>
>>> 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.
> 

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

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

* Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-01-30  0:11     ` Chanwoo Choi
@ 2015-01-30 14:03         ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-30 14:03 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: myungjoo.ham, balbi, tony, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

On 30/01/15 02:11, Chanwoo Choi wrote:
> Hi Roger,
> 
> On 01/28/2015 09:15 PM, Roger Quadros wrote:
>> 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.
>>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> ---
>> 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
>>
>> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>> new file mode 100644
>> index 0000000..85fe6b0
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>> @@ -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>;
>> +	};
>> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
>> index 6a1f7de..fd11536 100644
>> --- a/drivers/extcon/Kconfig
>> +++ b/drivers/extcon/Kconfig
>> @@ -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
>> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
>> index 0370b42..6a08a98 100644
>> --- a/drivers/extcon/Makefile
>> +++ b/drivers/extcon/Makefile
>> @@ -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
>> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
>> new file mode 100644
>> index 0000000..99a58b2
>> --- /dev/null
>> +++ b/drivers/extcon/extcon-usb-gpio.c
>> @@ -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 <rogerq@ti.com>
>> + *
>> + * 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,
>> +};
>> +
>> +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

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

* Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-01-30 14:03         ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-30 14:03 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: myungjoo.ham, balbi, tony, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

On 30/01/15 02:11, Chanwoo Choi wrote:
> Hi Roger,
> 
> On 01/28/2015 09:15 PM, Roger Quadros wrote:
>> 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.
>>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> ---
>> 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
>>
>> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>> new file mode 100644
>> index 0000000..85fe6b0
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>> @@ -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>;
>> +	};
>> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
>> index 6a1f7de..fd11536 100644
>> --- a/drivers/extcon/Kconfig
>> +++ b/drivers/extcon/Kconfig
>> @@ -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
>> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
>> index 0370b42..6a08a98 100644
>> --- a/drivers/extcon/Makefile
>> +++ b/drivers/extcon/Makefile
>> @@ -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
>> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
>> new file mode 100644
>> index 0000000..99a58b2
>> --- /dev/null
>> +++ b/drivers/extcon/extcon-usb-gpio.c
>> @@ -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 <rogerq@ti.com>
>> + *
>> + * 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,
>> +};
>> +
>> +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

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

* Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name
  2015-01-30 11:04     ` Roger Quadros
@ 2015-01-30 14:05       ` Roger Quadros
  -1 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-30 14:05 UTC (permalink / raw)
  To: balbi, cw00.choi
  Cc: tony, myungjoo.ham, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Hi,

On 30/01/15 13:04, Roger Quadros wrote:
> Felipe & Chanwoo,
> 
> On 26/01/15 14:15, Roger Quadros wrote:
>> 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".
>>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> Reviewed-by: Felipe Balbi <balbi@ti.com>
>> Acked-by: Felipe Balbi <balbi@ti.com>
> 
> 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

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

* Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name
@ 2015-01-30 14:05       ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-01-30 14:05 UTC (permalink / raw)
  To: balbi, cw00.choi
  Cc: tony, myungjoo.ham, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Hi,

On 30/01/15 13:04, Roger Quadros wrote:
> Felipe & Chanwoo,
> 
> On 26/01/15 14:15, Roger Quadros wrote:
>> 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".
>>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> Reviewed-by: Felipe Balbi <balbi@ti.com>
>> Acked-by: Felipe Balbi <balbi@ti.com>
> 
> 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

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

* Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name
  2015-01-30 14:05       ` Roger Quadros
  (?)
@ 2015-02-02  5:04       ` Chanwoo Choi
  2015-02-02  9:09           ` Roger Quadros
  -1 siblings, 1 reply; 75+ messages in thread
From: Chanwoo Choi @ 2015-02-02  5:04 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi, tony, myungjoo.ham, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Hi Roger,

On 01/30/2015 11:05 PM, Roger Quadros wrote:
> Hi,
> 
> On 30/01/15 13:04, Roger Quadros wrote:
>> Felipe & Chanwoo,
>>
>> On 26/01/15 14:15, Roger Quadros wrote:
>>> 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".
>>>
>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>> Reviewed-by: Felipe Balbi <balbi@ti.com>
>>> Acked-by: Felipe Balbi <balbi@ti.com>
>>
>> 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".

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


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

* Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-02-02  5:06           ` Chanwoo Choi
  0 siblings, 0 replies; 75+ messages in thread
From: Chanwoo Choi @ 2015-02-02  5:06 UTC (permalink / raw)
  To: Roger Quadros
  Cc: myungjoo.ham, balbi, tony, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Hi Roger,

On 01/30/2015 11:03 PM, Roger Quadros wrote:
> On 30/01/15 02:11, Chanwoo Choi wrote:
>> Hi Roger,
>>
>> On 01/28/2015 09:15 PM, Roger Quadros wrote:
>>> 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.
>>>
>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>> ---
>>> 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
>>>
>>> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>>> new file mode 100644
>>> index 0000000..85fe6b0
>>> --- /dev/null
>>> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>>> @@ -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>;
>>> +	};
>>> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
>>> index 6a1f7de..fd11536 100644
>>> --- a/drivers/extcon/Kconfig
>>> +++ b/drivers/extcon/Kconfig
>>> @@ -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
>>> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
>>> index 0370b42..6a08a98 100644
>>> --- a/drivers/extcon/Makefile
>>> +++ b/drivers/extcon/Makefile
>>> @@ -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
>>> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
>>> new file mode 100644
>>> index 0000000..99a58b2
>>> --- /dev/null
>>> +++ b/drivers/extcon/extcon-usb-gpio.c
>>> @@ -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 <rogerq@ti.com>
>>> + *
>>> + * 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,
>>> +};
>>> +
>>> +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"?

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


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

* Re: [PATCH v3 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-02-02  5:06           ` Chanwoo Choi
  0 siblings, 0 replies; 75+ messages in thread
From: Chanwoo Choi @ 2015-02-02  5:06 UTC (permalink / raw)
  To: Roger Quadros
  Cc: myungjoo.ham-Sze3O3UU22JBDgjK7y7TUQ, balbi-l0cyMroinI0,
	tony-4v6yS6AI5VpBDgjK7y7TUQ, george.cherian-l0cyMroinI0,
	nsekhar-l0cyMroinI0, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

Hi Roger,

On 01/30/2015 11:03 PM, Roger Quadros wrote:
> On 30/01/15 02:11, Chanwoo Choi wrote:
>> Hi Roger,
>>
>> On 01/28/2015 09:15 PM, Roger Quadros wrote:
>>> 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.
>>>
>>> Signed-off-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
>>> ---
>>> 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
>>>
>>> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>>> new file mode 100644
>>> index 0000000..85fe6b0
>>> --- /dev/null
>>> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
>>> @@ -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>;
>>> +	};
>>> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
>>> index 6a1f7de..fd11536 100644
>>> --- a/drivers/extcon/Kconfig
>>> +++ b/drivers/extcon/Kconfig
>>> @@ -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
>>> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
>>> index 0370b42..6a08a98 100644
>>> --- a/drivers/extcon/Makefile
>>> +++ b/drivers/extcon/Makefile
>>> @@ -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
>>> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
>>> new file mode 100644
>>> index 0000000..99a58b2
>>> --- /dev/null
>>> +++ b/drivers/extcon/extcon-usb-gpio.c
>>> @@ -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 <rogerq-l0cyMroinI0@public.gmane.org>
>>> + *
>>> + * 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,
>>> +};
>>> +
>>> +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"?

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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name
  2015-02-02  5:04       ` Chanwoo Choi
@ 2015-02-02  9:09           ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-02-02  9:09 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: balbi, tony, myungjoo.ham, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Chanwoo,

On 02/02/15 07:04, Chanwoo Choi wrote:
> Hi Roger,
> 
> On 01/30/2015 11:05 PM, Roger Quadros wrote:
>> Hi,
>>
>> On 30/01/15 13:04, Roger Quadros wrote:
>>> Felipe & Chanwoo,
>>>
>>> On 26/01/15 14:15, Roger Quadros wrote:
>>>> 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".
>>>>
>>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>>> Reviewed-by: Felipe Balbi <balbi@ti.com>
>>>> Acked-by: Felipe Balbi <balbi@ti.com>
>>>
>>> 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".
> 
> 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

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

* Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name
@ 2015-02-02  9:09           ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-02-02  9:09 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: balbi, tony, myungjoo.ham, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Chanwoo,

On 02/02/15 07:04, Chanwoo Choi wrote:
> Hi Roger,
> 
> On 01/30/2015 11:05 PM, Roger Quadros wrote:
>> Hi,
>>
>> On 30/01/15 13:04, Roger Quadros wrote:
>>> Felipe & Chanwoo,
>>>
>>> On 26/01/15 14:15, Roger Quadros wrote:
>>>> 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".
>>>>
>>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>>> Reviewed-by: Felipe Balbi <balbi@ti.com>
>>>> Acked-by: Felipe Balbi <balbi@ti.com>
>>>
>>> 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".
> 
> 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

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

* Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name
  2015-02-02  9:09           ` Roger Quadros
  (?)
@ 2015-02-02  9:55           ` Chanwoo Choi
  2015-02-02 10:01               ` Roger Quadros
  -1 siblings, 1 reply; 75+ messages in thread
From: Chanwoo Choi @ 2015-02-02  9:55 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi, tony, myungjoo.ham, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Hi Roger,

On 02/02/2015 06:09 PM, Roger Quadros wrote:
> Chanwoo,
> 
> On 02/02/15 07:04, Chanwoo Choi wrote:
>> Hi Roger,
>>
>> On 01/30/2015 11:05 PM, Roger Quadros wrote:
>>> Hi,
>>>
>>> On 30/01/15 13:04, Roger Quadros wrote:
>>>> Felipe & Chanwoo,
>>>>
>>>> On 26/01/15 14:15, Roger Quadros wrote:
>>>>> 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".
>>>>>
>>>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>>>> Reviewed-by: Felipe Balbi <balbi@ti.com>
>>>>> Acked-by: Felipe Balbi <balbi@ti.com>
>>>>
>>>> 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".
>>
>> 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



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

* Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name
@ 2015-02-02 10:01               ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-02-02 10:01 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: balbi, tony, myungjoo.ham, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

On 02/02/15 11:55, Chanwoo Choi wrote:
> Hi Roger,
> 
> On 02/02/2015 06:09 PM, Roger Quadros wrote:
>> Chanwoo,
>>
>> On 02/02/15 07:04, Chanwoo Choi wrote:
>>> Hi Roger,
>>>
>>> On 01/30/2015 11:05 PM, Roger Quadros wrote:
>>>> Hi,
>>>>
>>>> On 30/01/15 13:04, Roger Quadros wrote:
>>>>> Felipe & Chanwoo,
>>>>>
>>>>> On 26/01/15 14:15, Roger Quadros wrote:
>>>>>> 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".
>>>>>>
>>>>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>>>>> Reviewed-by: Felipe Balbi <balbi@ti.com>
>>>>>> Acked-by: Felipe Balbi <balbi@ti.com>
>>>>>
>>>>> 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".
>>>
>>> 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.
> 

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

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

* Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name
@ 2015-02-02 10:01               ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-02-02 10:01 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: balbi-l0cyMroinI0, tony-4v6yS6AI5VpBDgjK7y7TUQ,
	myungjoo.ham-Sze3O3UU22JBDgjK7y7TUQ, george.cherian-l0cyMroinI0,
	nsekhar-l0cyMroinI0, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On 02/02/15 11:55, Chanwoo Choi wrote:
> Hi Roger,
> 
> On 02/02/2015 06:09 PM, Roger Quadros wrote:
>> Chanwoo,
>>
>> On 02/02/15 07:04, Chanwoo Choi wrote:
>>> Hi Roger,
>>>
>>> On 01/30/2015 11:05 PM, Roger Quadros wrote:
>>>> Hi,
>>>>
>>>> On 30/01/15 13:04, Roger Quadros wrote:
>>>>> Felipe & Chanwoo,
>>>>>
>>>>> On 26/01/15 14:15, Roger Quadros wrote:
>>>>>> 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".
>>>>>>
>>>>>> Signed-off-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
>>>>>> Reviewed-by: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
>>>>>> Acked-by: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
>>>>>
>>>>> 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".
>>>
>>> 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.
> 

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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name
@ 2015-02-02 10:06                 ` Chanwoo Choi
  0 siblings, 0 replies; 75+ messages in thread
From: Chanwoo Choi @ 2015-02-02 10:06 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi, tony, myungjoo.ham, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

On 02/02/2015 07:01 PM, Roger Quadros wrote:
> On 02/02/15 11:55, Chanwoo Choi wrote:
>> Hi Roger,
>>
>> On 02/02/2015 06:09 PM, Roger Quadros wrote:
>>> Chanwoo,
>>>
>>> On 02/02/15 07:04, Chanwoo Choi wrote:
>>>> Hi Roger,
>>>>
>>>> On 01/30/2015 11:05 PM, Roger Quadros wrote:
>>>>> Hi,
>>>>>
>>>>> On 30/01/15 13:04, Roger Quadros wrote:
>>>>>> Felipe & Chanwoo,
>>>>>>
>>>>>> On 26/01/15 14:15, Roger Quadros wrote:
>>>>>>> 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".
>>>>>>>
>>>>>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>>>>>> Reviewed-by: Felipe Balbi <balbi@ti.com>
>>>>>>> Acked-by: Felipe Balbi <balbi@ti.com>
>>>>>>
>>>>>> 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".
>>>>
>>>> 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.
>>
> 
> 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.

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


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

* Re: [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name
@ 2015-02-02 10:06                 ` Chanwoo Choi
  0 siblings, 0 replies; 75+ messages in thread
From: Chanwoo Choi @ 2015-02-02 10:06 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi-l0cyMroinI0, tony-4v6yS6AI5VpBDgjK7y7TUQ,
	myungjoo.ham-Sze3O3UU22JBDgjK7y7TUQ, george.cherian-l0cyMroinI0,
	nsekhar-l0cyMroinI0, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On 02/02/2015 07:01 PM, Roger Quadros wrote:
> On 02/02/15 11:55, Chanwoo Choi wrote:
>> Hi Roger,
>>
>> On 02/02/2015 06:09 PM, Roger Quadros wrote:
>>> Chanwoo,
>>>
>>> On 02/02/15 07:04, Chanwoo Choi wrote:
>>>> Hi Roger,
>>>>
>>>> On 01/30/2015 11:05 PM, Roger Quadros wrote:
>>>>> Hi,
>>>>>
>>>>> On 30/01/15 13:04, Roger Quadros wrote:
>>>>>> Felipe & Chanwoo,
>>>>>>
>>>>>> On 26/01/15 14:15, Roger Quadros wrote:
>>>>>>> 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".
>>>>>>>
>>>>>>> Signed-off-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
>>>>>>> Reviewed-by: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
>>>>>>> Acked-by: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
>>>>>>
>>>>>> 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".
>>>>
>>>> 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.
>>
> 
> 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.

> 
> 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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-01-28 12:15     ` Roger Quadros
@ 2015-02-02 10:21       ` Roger Quadros
  -1 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-02-02 10:21 UTC (permalink / raw)
  To: cw00.choi
  Cc: myungjoo.ham, balbi, tony, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel, 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.

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
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

diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
new file mode 100644
index 0000000..85fe6b0
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
@@ -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>;
+	};
diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
index 6a1f7de..e4c01ab 100644
--- a/drivers/extcon/Kconfig
+++ b/drivers/extcon/Kconfig
@@ -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
diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
index 0370b42..6a08a98 100644
--- a/drivers/extcon/Makefile
+++ b/drivers/extcon/Makefile
@@ -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
diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
new file mode 100644
index 0000000..3f0bad3
--- /dev/null
+++ b/drivers/extcon/extcon-usb-gpio.c
@@ -0,0 +1,237 @@
+/**
+ * drivers/extcon/extcon-usb-gpio.c - USB GPIO extcon driver
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Roger Quadros <rogerq@ti.com>
+ *
+ * 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",
+	NULL,
+};
+
+static void usb_extcon_detect_cable(struct work_struct *work)
+{
+	int id;
+	struct usb_extcon_info *info = container_of(to_delayed_work(work),
+						    struct usb_extcon_info,
+						    wq_detcable);
+
+	/* 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],
+				       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);
+
+	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_TRIGGER_RISING |
+					IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+					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");
+		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);
+	device_init_wakeup(dev, 1);
+
+	/* 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);
+
+	return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int usb_extcon_suspend(struct device *dev)
+{
+	struct usb_extcon_info *info = dev_get_drvdata(dev);
+	int ret = 0;
+
+	if (device_may_wakeup(dev)) {
+		ret = enable_irq_wake(info->id_irq);
+		if (ret)
+			return ret;
+	}
+
+	/*
+	 * 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 ret;
+}
+
+static int usb_extcon_resume(struct device *dev)
+{
+	struct usb_extcon_info *info = dev_get_drvdata(dev);
+	int ret = 0;
+
+	if (device_may_wakeup(dev)) {
+		ret = disable_irq_wake(info->id_irq);
+		if (ret)
+			return ret;
+	}
+
+	enable_irq(info->id_irq);
+
+	return ret;
+}
+#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,
+	},
+};
+
+module_platform_driver(usb_extcon_driver);
+
+MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
+MODULE_DESCRIPTION("USB GPIO extcon driver");
+MODULE_LICENSE("GPL v2");
-- 
2.1.0



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

* [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-02-02 10:21       ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-02-02 10:21 UTC (permalink / raw)
  To: cw00.choi
  Cc: myungjoo.ham, balbi, tony, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel, 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.

Signed-off-by: Roger Quadros <rogerq@ti.com>
---
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

diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
new file mode 100644
index 0000000..85fe6b0
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
@@ -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>;
+	};
diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
index 6a1f7de..e4c01ab 100644
--- a/drivers/extcon/Kconfig
+++ b/drivers/extcon/Kconfig
@@ -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
diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
index 0370b42..6a08a98 100644
--- a/drivers/extcon/Makefile
+++ b/drivers/extcon/Makefile
@@ -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
diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
new file mode 100644
index 0000000..3f0bad3
--- /dev/null
+++ b/drivers/extcon/extcon-usb-gpio.c
@@ -0,0 +1,237 @@
+/**
+ * drivers/extcon/extcon-usb-gpio.c - USB GPIO extcon driver
+ *
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
+ * Author: Roger Quadros <rogerq@ti.com>
+ *
+ * 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",
+	NULL,
+};
+
+static void usb_extcon_detect_cable(struct work_struct *work)
+{
+	int id;
+	struct usb_extcon_info *info = container_of(to_delayed_work(work),
+						    struct usb_extcon_info,
+						    wq_detcable);
+
+	/* 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],
+				       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);
+
+	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_TRIGGER_RISING |
+					IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+					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");
+		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);
+	device_init_wakeup(dev, 1);
+
+	/* 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);
+
+	return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int usb_extcon_suspend(struct device *dev)
+{
+	struct usb_extcon_info *info = dev_get_drvdata(dev);
+	int ret = 0;
+
+	if (device_may_wakeup(dev)) {
+		ret = enable_irq_wake(info->id_irq);
+		if (ret)
+			return ret;
+	}
+
+	/*
+	 * 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 ret;
+}
+
+static int usb_extcon_resume(struct device *dev)
+{
+	struct usb_extcon_info *info = dev_get_drvdata(dev);
+	int ret = 0;
+
+	if (device_may_wakeup(dev)) {
+		ret = disable_irq_wake(info->id_irq);
+		if (ret)
+			return ret;
+	}
+
+	enable_irq(info->id_irq);
+
+	return ret;
+}
+#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,
+	},
+};
+
+module_platform_driver(usb_extcon_driver);
+
+MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
+MODULE_DESCRIPTION("USB GPIO extcon driver");
+MODULE_LICENSE("GPL v2");
-- 
2.1.0

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

* Re: [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-02-02 10:21       ` Roger Quadros
  (?)
@ 2015-02-03  1:13       ` Chanwoo Choi
  -1 siblings, 0 replies; 75+ messages in thread
From: Chanwoo Choi @ 2015-02-03  1:13 UTC (permalink / raw)
  To: Roger Quadros
  Cc: myungjoo.ham, balbi, tony, george.cherian, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Hi Roger,

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

Thanks,
Chanwoo Choi

On 02/02/2015 07:21 PM, Roger Quadros wrote:
> 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.
> 
> Signed-off-by: Roger Quadros <rogerq@ti.com>
> ---
> 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
> 
> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
> new file mode 100644
> index 0000000..85fe6b0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb-gpio.txt
> @@ -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:

> +	extcon_usb1 {
> +		compatible = "linux,extcon-usb-gpio";
> +		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
> +	}
> +
> +	&omap_dwc3_1 {
> +		extcon = <&extcon_usb1>;
> +	};

[snip]

Thanks,
Chanwoo Choi


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

* Re: [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-02-02 10:21       ` Roger Quadros
  (?)
  (?)
@ 2015-03-16 12:32       ` Ivan T. Ivanov
  2015-03-16 13:11           ` Roger Quadros
  -1 siblings, 1 reply; 75+ messages in thread
From: Ivan T. Ivanov @ 2015-03-16 12:32 UTC (permalink / raw)
  To: Roger Quadros
  Cc: cw00.choi, myungjoo.ham, balbi, tony, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

Hi, 

On Mon, 2015-02-02 at 12:21 +0200, Roger Quadros wrote:
> 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.
> 
> Signed-off-by: Roger Quadros <rogerq@ti.com>
> ---
> 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[][]?


> +
> +/* List of detectable cables */
> +enum {
> +       EXTCON_CABLE_USB = 0,
> +       EXTCON_CABLE_USB_HOST,
> +

Same here: duplicated with enum extcon_cable_name

> +       EXTCON_CABLE_END,
> +};
> +
> +static const char *usb_extcon_cable[] = {
> +       [EXTCON_CABLE_USB] = "USB",
> +       [EXTCON_CABLE_USB_HOST] = "USB-HOST",
> +       NULL,
> +};
> 

<snip>

> +
> +static int usb_extcon_probe(struct platform_device *pdev)
> +{
> 

<snip>

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

> 

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

* Re: [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-03-16 12:32       ` Ivan T. Ivanov
@ 2015-03-16 13:11           ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-03-16 13:11 UTC (permalink / raw)
  To: Ivan T. Ivanov
  Cc: cw00.choi, myungjoo.ham, balbi, tony, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Hi Ivan,

On 16/03/15 14:32, Ivan T. Ivanov wrote:
> Hi, 
> 
> On Mon, 2015-02-02 at 12:21 +0200, Roger Quadros wrote:
>> 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.
>>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> ---
>> 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[][]?
> 
> 
>> +
>> +/* List of detectable cables */
>> +enum {
>> +       EXTCON_CABLE_USB = 0,
>> +       EXTCON_CABLE_USB_HOST,
>> +
> 
> Same here: duplicated with enum extcon_cable_name
> 
>> +       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[][].

>>
> 
> <snip>
> 
>> +
>> +static int usb_extcon_probe(struct platform_device *pdev)
>> +{
>>
> 
> <snip>
> 
>> +
>> +       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

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

* Re: [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-03-16 13:11           ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-03-16 13:11 UTC (permalink / raw)
  To: Ivan T. Ivanov
  Cc: cw00.choi, myungjoo.ham, balbi, tony, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Hi Ivan,

On 16/03/15 14:32, Ivan T. Ivanov wrote:
> Hi, 
> 
> On Mon, 2015-02-02 at 12:21 +0200, Roger Quadros wrote:
>> 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.
>>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>> ---
>> 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[][]?
> 
> 
>> +
>> +/* List of detectable cables */
>> +enum {
>> +       EXTCON_CABLE_USB = 0,
>> +       EXTCON_CABLE_USB_HOST,
>> +
> 
> Same here: duplicated with enum extcon_cable_name
> 
>> +       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[][].

>>
> 
> <snip>
> 
>> +
>> +static int usb_extcon_probe(struct platform_device *pdev)
>> +{
>>
> 
> <snip>
> 
>> +
>> +       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

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

* Re: [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-03-16 13:11           ` Roger Quadros
  (?)
@ 2015-03-16 14:23           ` Ivan T. Ivanov
  2015-03-17  2:01             ` Chanwoo Choi
  -1 siblings, 1 reply; 75+ messages in thread
From: Ivan T. Ivanov @ 2015-03-16 14:23 UTC (permalink / raw)
  To: Roger Quadros
  Cc: cw00.choi, myungjoo.ham, balbi, tony, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel


Hi Roger, 

On Mon, 2015-03-16 at 15:11 +0200, Roger Quadros wrote:
> Hi Ivan,
> 
> On 16/03/15 14:32, Ivan T. Ivanov wrote:
> > Hi,
> > 
> > On Mon, 2015-02-02 at 12:21 +0200, Roger Quadros wrote:
> > > 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.
> > > 
> > > Signed-off-by: Roger Quadros <rogerq@ti.com>
> > > ---
> > > 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[][]?
> > 
> > 
> > > +
> > > +/* List of detectable cables */
> > > +enum {
> > > +       EXTCON_CABLE_USB = 0,
> > > +       EXTCON_CABLE_USB_HOST,
> > > +
> > 
> > Same here: duplicated with enum extcon_cable_name
> > 
> > > +       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?

> 
> > 
> > <snip>
> > 
> > > +
> > > +static int usb_extcon_probe(struct platform_device *pdev)
> > > +{
> > > 
> > 
> > <snip>
> > 
> > > +
> > > +       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.

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

Regards,
Ivan


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

* Re: [PATCH v2 7/7] ARM: omap2plus_defconfig: Enable EXTCON_GPIO_USB
@ 2015-03-16 17:53     ` Tony Lindgren
  0 siblings, 0 replies; 75+ messages in thread
From: Tony Lindgren @ 2015-03-16 17:53 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

* Roger Quadros <rogerq@ti.com> [150126 04:19]:
> This driver is needed for USB cable type detection on dra7-evm,
> dra72-evm and am57xx-beagle-x15.
> 
> Signed-off-by: Roger Quadros <rogerq@ti.com>

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

> ---
>  arch/arm/configs/omap2plus_defconfig | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
> index 667d9d5..7e10e58 100644
> --- a/arch/arm/configs/omap2plus_defconfig
> +++ b/arch/arm/configs/omap2plus_defconfig
> @@ -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
> -- 
> 2.1.0
> 

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

* Re: [PATCH v2 7/7] ARM: omap2plus_defconfig: Enable EXTCON_GPIO_USB
@ 2015-03-16 17:53     ` Tony Lindgren
  0 siblings, 0 replies; 75+ messages in thread
From: Tony Lindgren @ 2015-03-16 17:53 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi-l0cyMroinI0, myungjoo.ham-Sze3O3UU22JBDgjK7y7TUQ,
	cw00.choi-Sze3O3UU22JBDgjK7y7TUQ, george.cherian-l0cyMroinI0,
	nsekhar-l0cyMroinI0, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

* Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org> [150126 04:19]:
> This driver is needed for USB cable type detection on dra7-evm,
> dra72-evm and am57xx-beagle-x15.
> 
> Signed-off-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>

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

> ---
>  arch/arm/configs/omap2plus_defconfig | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
> index 667d9d5..7e10e58 100644
> --- a/arch/arm/configs/omap2plus_defconfig
> +++ b/arch/arm/configs/omap2plus_defconfig
> @@ -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
> -- 
> 2.1.0
> 
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-03-16 14:23           ` Ivan T. Ivanov
@ 2015-03-17  2:01             ` Chanwoo Choi
  2015-03-17  7:52               ` Ivan T. Ivanov
  0 siblings, 1 reply; 75+ messages in thread
From: Chanwoo Choi @ 2015-03-17  2:01 UTC (permalink / raw)
  To: Ivan T. Ivanov
  Cc: Roger Quadros, myungjoo.ham, balbi, tony, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Hi Ivan,

On 03/16/2015 11:23 PM, Ivan T. Ivanov wrote:
> 
> Hi Roger, 
> 
> On Mon, 2015-03-16 at 15:11 +0200, Roger Quadros wrote:
>> Hi Ivan,
>>
>> On 16/03/15 14:32, Ivan T. Ivanov wrote:
>>> Hi,
>>>
>>> On Mon, 2015-02-02 at 12:21 +0200, Roger Quadros wrote:
>>>> 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.
>>>>
>>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>>> ---
>>>> 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[][]?
>>>
>>>
>>>> +
>>>> +/* List of detectable cables */
>>>> +enum {
>>>> +       EXTCON_CABLE_USB = 0,
>>>> +       EXTCON_CABLE_USB_HOST,
>>>> +
>>>
>>> Same here: duplicated with enum extcon_cable_name
>>>
>>>> +       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?

'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

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

* Re: [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver
  2015-03-17  2:01             ` Chanwoo Choi
@ 2015-03-17  7:52               ` Ivan T. Ivanov
  2015-03-17  8:00                   ` Ivan T. Ivanov
  0 siblings, 1 reply; 75+ messages in thread
From: Ivan T. Ivanov @ 2015-03-17  7:52 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: Roger Quadros, myungjoo.ham, balbi, tony, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel

Hi,

On Tue, 2015-03-17 at 11:01 +0900, Chanwoo Choi wrote:
> Hi Ivan,
> 
> On 03/16/2015 11:23 PM, Ivan T. Ivanov wrote:
> > Hi Roger,
> > 
> > On Mon, 2015-03-16 at 15:11 +0200, Roger Quadros wrote:
> > > Hi Ivan,
> > > 
> > > On 16/03/15 14:32, Ivan T. Ivanov wrote:
> > > > Hi,
> > > > 
> > > > On Mon, 2015-02-02 at 12:21 +0200, Roger Quadros wrote:
> > > > > 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.
> > > > > 
> > > > > Signed-off-by: Roger Quadros <rogerq@ti.com>
> > > > > ---
> > > > > 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[][]?
> > > > 
> > > > 
> > > > > +
> > > > > +/* List of detectable cables */
> > > > > +enum {
> > > > > +       EXTCON_CABLE_USB = 0,
> > > > > +       EXTCON_CABLE_USB_HOST,
> > > > > +
> > > > 
> > > > Same here: duplicated with enum extcon_cable_name
> > > > 
> > > > > +       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.

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


> 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




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

* Re: [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-03-17  8:00                   ` Ivan T. Ivanov
  0 siblings, 0 replies; 75+ messages in thread
From: Ivan T. Ivanov @ 2015-03-17  8:00 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: Roger Quadros, myungjoo.ham, balbi, tony, nsekhar, devicetree,
	linux-usb, linux-omap, linux-kernel


Fixed spelling error.

On Tue, 2015-03-17 at 09:52 +0200, Ivan T. Ivanov wrote:
> Hi,
> 
> On Tue, 2015-03-17 at 11:01 +0900, Chanwoo Choi wrote:
> > Hi Ivan,
> > 
> > On 03/16/2015 11:23 PM, Ivan T. Ivanov wrote:
> > > Hi Roger,
> > > 
> > > On Mon, 2015-03-16 at 15:11 +0200, Roger Quadros wrote:
> > > > Hi Ivan,
> > > > 
> > > > On 16/03/15 14:32, Ivan T. Ivanov wrote:
> > > > > Hi,
> > > > > 
> > > > > On Mon, 2015-02-02 at 12:21 +0200, Roger Quadros wrote:
> > > > > > 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.
> > > > > > 
> > > > > > Signed-off-by: Roger Quadros <rogerq@ti.com>
> > > > > > ---
> > > > > > 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[][]?
> > > > > 
> > > > > 
> > > > > > +
> > > > > > +/* List of detectable cables */
> > > > > > +enum {
> > > > > > +       EXTCON_CABLE_USB = 0,
> > > > > > +       EXTCON_CABLE_USB_HOST,
> > > > > > +
> > > > > 
> > > > > Same here: duplicated with enum extcon_cable_name
> > > > > 
> > > > > > +       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.
> 
> > >  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.
                ^^^
s/now/not/

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

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

* Re: [PATCH v4 1/1] extcon: usb-gpio: Introduce gpio usb extcon driver
@ 2015-03-17  8:00                   ` Ivan T. Ivanov
  0 siblings, 0 replies; 75+ messages in thread
From: Ivan T. Ivanov @ 2015-03-17  8:00 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: Roger Quadros, myungjoo.ham-Sze3O3UU22JBDgjK7y7TUQ,
	balbi-l0cyMroinI0, tony-4v6yS6AI5VpBDgjK7y7TUQ,
	nsekhar-l0cyMroinI0, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA


Fixed spelling error.

On Tue, 2015-03-17 at 09:52 +0200, Ivan T. Ivanov wrote:
> Hi,
> 
> On Tue, 2015-03-17 at 11:01 +0900, Chanwoo Choi wrote:
> > Hi Ivan,
> > 
> > On 03/16/2015 11:23 PM, Ivan T. Ivanov wrote:
> > > Hi Roger,
> > > 
> > > On Mon, 2015-03-16 at 15:11 +0200, Roger Quadros wrote:
> > > > Hi Ivan,
> > > > 
> > > > On 16/03/15 14:32, Ivan T. Ivanov wrote:
> > > > > Hi,
> > > > > 
> > > > > On Mon, 2015-02-02 at 12:21 +0200, Roger Quadros wrote:
> > > > > > 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.
> > > > > > 
> > > > > > Signed-off-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
> > > > > > ---
> > > > > > 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[][]?
> > > > > 
> > > > > 
> > > > > > +
> > > > > > +/* List of detectable cables */
> > > > > > +enum {
> > > > > > +       EXTCON_CABLE_USB = 0,
> > > > > > +       EXTCON_CABLE_USB_HOST,
> > > > > > +
> > > > > 
> > > > > Same here: duplicated with enum extcon_cable_name
> > > > > 
> > > > > > +       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.
> 
> > >  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.
                ^^^
s/now/not/

> 
> ... 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.
> 
> 
> > 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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v2 7/7] ARM: omap2plus_defconfig: Enable EXTCON_GPIO_USB
@ 2015-03-17  9:29       ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-03-17  9:29 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: balbi, myungjoo.ham, cw00.choi, nsekhar, devicetree, linux-usb,
	linux-omap, linux-kernel

On 16/03/15 19:53, Tony Lindgren wrote:
> * Roger Quadros <rogerq@ti.com> [150126 04:19]:
>> This driver is needed for USB cable type detection on dra7-evm,
>> dra72-evm and am57xx-beagle-x15.
>>
>> Signed-off-by: Roger Quadros <rogerq@ti.com>
> 
> 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


> 
> Regards,
> 
> Tony
> 
>> ---
>>  arch/arm/configs/omap2plus_defconfig | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
>> index 667d9d5..7e10e58 100644
>> --- a/arch/arm/configs/omap2plus_defconfig
>> +++ b/arch/arm/configs/omap2plus_defconfig
>> @@ -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
>> -- 
>> 2.1.0
>>


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

* Re: [PATCH v2 7/7] ARM: omap2plus_defconfig: Enable EXTCON_GPIO_USB
@ 2015-03-17  9:29       ` Roger Quadros
  0 siblings, 0 replies; 75+ messages in thread
From: Roger Quadros @ 2015-03-17  9:29 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: balbi-l0cyMroinI0, myungjoo.ham-Sze3O3UU22JBDgjK7y7TUQ,
	cw00.choi-Sze3O3UU22JBDgjK7y7TUQ, nsekhar-l0cyMroinI0,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On 16/03/15 19:53, Tony Lindgren wrote:
> * Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org> [150126 04:19]:
>> This driver is needed for USB cable type detection on dra7-evm,
>> dra72-evm and am57xx-beagle-x15.
>>
>> Signed-off-by: Roger Quadros <rogerq-l0cyMroinI0@public.gmane.org>
> 
> 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


> 
> Regards,
> 
> Tony
> 
>> ---
>>  arch/arm/configs/omap2plus_defconfig | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
>> index 667d9d5..7e10e58 100644
>> --- a/arch/arm/configs/omap2plus_defconfig
>> +++ b/arch/arm/configs/omap2plus_defconfig
>> @@ -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
>> -- 
>> 2.1.0
>>

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2015-03-17  9:30 UTC | newest]

Thread overview: 75+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-26 12:15 [PATCH v2 0/7] extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 & AM57xx USB Roger Quadros
2015-01-26 12:15 ` Roger Quadros
2015-01-26 12:15 ` [PATCH v2 1/7] extcon: usb-gpio: Introduce gpio usb extcon driver Roger Quadros
2015-01-26 12:15   ` Roger Quadros
2015-01-26 13:56   ` Chanwoo Choi
2015-01-26 13:56     ` Chanwoo Choi
2015-01-26 16:27     ` Roger Quadros
2015-01-26 16:27       ` Roger Quadros
2015-01-27  1:54       ` Chanwoo Choi
2015-01-27  1:54         ` Chanwoo Choi
2015-01-27 15:38         ` Roger Quadros
2015-01-27 15:38           ` Roger Quadros
2015-01-28  2:19           ` Chanwoo Choi
2015-01-28 12:12             ` Roger Quadros
2015-01-28 12:12               ` Roger Quadros
2015-01-28 17:09               ` Tony Lindgren
2015-01-29 11:31                 ` Roger Quadros
2015-01-29 11:31                   ` Roger Quadros
2015-01-29 16:56                   ` Tony Lindgren
2015-01-30 10:58                     ` Roger Quadros
2015-01-30 10:58                       ` Roger Quadros
2015-01-28 12:15   ` [PATCH v3 " Roger Quadros
2015-01-28 12:15     ` Roger Quadros
2015-01-29  1:49     ` Chanwoo Choi
2015-01-29 11:26       ` Roger Quadros
2015-01-29 11:26         ` Roger Quadros
2015-01-30  0:06         ` Chanwoo Choi
2015-01-30 11:09           ` Roger Quadros
2015-01-30 11:09             ` Roger Quadros
2015-01-30 13:57             ` Roger Quadros
2015-01-30 13:57               ` Roger Quadros
2015-01-30  0:11     ` Chanwoo Choi
2015-01-30 14:03       ` Roger Quadros
2015-01-30 14:03         ` Roger Quadros
2015-02-02  5:06         ` Chanwoo Choi
2015-02-02  5:06           ` Chanwoo Choi
2015-02-02 10:21     ` [PATCH v4 1/1] " Roger Quadros
2015-02-02 10:21       ` Roger Quadros
2015-02-03  1:13       ` Chanwoo Choi
2015-03-16 12:32       ` Ivan T. Ivanov
2015-03-16 13:11         ` Roger Quadros
2015-03-16 13:11           ` Roger Quadros
2015-03-16 14:23           ` Ivan T. Ivanov
2015-03-17  2:01             ` Chanwoo Choi
2015-03-17  7:52               ` Ivan T. Ivanov
2015-03-17  8:00                 ` Ivan T. Ivanov
2015-03-17  8:00                   ` Ivan T. Ivanov
2015-01-26 12:15 ` [PATCH v2 2/7] usb: extcon: Fix USB-Host cable name Roger Quadros
2015-01-26 12:15   ` Roger Quadros
2015-01-30 11:04   ` Roger Quadros
2015-01-30 11:04     ` Roger Quadros
2015-01-30 14:05     ` Roger Quadros
2015-01-30 14:05       ` Roger Quadros
2015-02-02  5:04       ` Chanwoo Choi
2015-02-02  9:09         ` Roger Quadros
2015-02-02  9:09           ` Roger Quadros
2015-02-02  9:55           ` Chanwoo Choi
2015-02-02 10:01             ` Roger Quadros
2015-02-02 10:01               ` Roger Quadros
2015-02-02 10:06               ` Chanwoo Choi
2015-02-02 10:06                 ` Chanwoo Choi
2015-01-26 12:15 ` [PATCH v2 3/7] ARM: dts: dra7-evm: Add extcon nodes for USB Roger Quadros
2015-01-26 12:15   ` Roger Quadros
2015-01-26 12:15 ` [PATCH v2 4/7] ARM: dts: dra72-evm: " Roger Quadros
2015-01-26 12:15   ` Roger Quadros
2015-01-26 12:15 ` [PATCH v2 5/7] ARM: dts: am57xx-beagle-x15: " Roger Quadros
2015-01-26 12:15   ` Roger Quadros
2015-01-26 12:15 ` [PATCH v2 6/7] ARM: dts: am57xx-beagle-x15: Fix USB2 mode Roger Quadros
2015-01-26 12:15   ` Roger Quadros
2015-01-26 12:15 ` [PATCH v2 7/7] ARM: omap2plus_defconfig: Enable EXTCON_GPIO_USB Roger Quadros
2015-01-26 12:15   ` Roger Quadros
2015-03-16 17:53   ` Tony Lindgren
2015-03-16 17:53     ` Tony Lindgren
2015-03-17  9:29     ` Roger Quadros
2015-03-17  9:29       ` Roger Quadros

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.