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

Hi,

On DRA7 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 and DRA72-evm.

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

Roger Quadros (5):
  extcon: gpio-usb: 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: omap2plus_defconfig: Enable PCF857X and EXTCON_GPIO_USB

 .../devicetree/bindings/extcon/extcon-usb.txt      |  20 ++
 arch/arm/boot/dts/dra7-evm.dts                     |  31 +++
 arch/arm/boot/dts/dra72-evm.dts                    |  31 +++
 arch/arm/configs/omap2plus_defconfig               |   2 +
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-gpio-usb.c                   | 225 +++++++++++++++++++++
 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 +-
 11 files changed, 335 insertions(+), 18 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb.txt
 create mode 100644 drivers/extcon/extcon-gpio-usb.c

-- 
2.1.0


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

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

Hi,

On DRA7 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 and DRA72-evm.

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

Roger Quadros (5):
  extcon: gpio-usb: 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: omap2plus_defconfig: Enable PCF857X and EXTCON_GPIO_USB

 .../devicetree/bindings/extcon/extcon-usb.txt      |  20 ++
 arch/arm/boot/dts/dra7-evm.dts                     |  31 +++
 arch/arm/boot/dts/dra72-evm.dts                    |  31 +++
 arch/arm/configs/omap2plus_defconfig               |   2 +
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-gpio-usb.c                   | 225 +++++++++++++++++++++
 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 +-
 11 files changed, 335 insertions(+), 18 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb.txt
 create mode 100644 drivers/extcon/extcon-gpio-usb.c

-- 
2.1.0

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

* [PATCH 1/5] extcon: gpio-usb: Introduce gpio usb extcon driver
@ 2015-01-19 17:52   ` Roger Quadros
  0 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-19 17:52 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.txt      |  20 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-gpio-usb.c                   | 225 +++++++++++++++++++++
 4 files changed, 253 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb.txt
 create mode 100644 drivers/extcon/extcon-gpio-usb.c

diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb.txt b/Documentation/devicetree/bindings/extcon/extcon-usb.txt
new file mode 100644
index 0000000..171c5a4
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-usb.txt
@@ -0,0 +1,20 @@
+USB 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"
+- id-gpio: gpio for USB ID pin. See gpio binding.
+
+Example:
+	extcon_usb1 {
+		compatible = "linux,extcon-usb";
+		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+	}
+
+	usb@1 {
+		...
+		extcon = <&extcon_usb1>;
+		...
+	};
diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
index 6a1f7de..8106a83 100644
--- a/drivers/extcon/Kconfig
+++ b/drivers/extcon/Kconfig
@@ -35,6 +35,13 @@ config EXTCON_GPIO
 	  Say Y here to enable GPIO based extcon support. Note that GPIO
 	  extcon supports single state per extcon instance.
 
+config EXTCON_GPIO_USB
+	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.
+
 config EXTCON_MAX14577
 	tristate "MAX14577/77836 EXTCON Support"
 	depends on MFD_MAX14577
diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
index 0370b42..bae594b 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_GPIO_USB)	+= extcon-gpio-usb.o
diff --git a/drivers/extcon/extcon-gpio-usb.c b/drivers/extcon/extcon-gpio-usb.c
new file mode 100644
index 0000000..aeb2298
--- /dev/null
+++ b/drivers/extcon/extcon-gpio-usb.c
@@ -0,0 +1,225 @@
+/**
+ * drivers/extcon/extcon_gpio_usb.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/extcon/extcon-gpio.h>
+#include <linux/gpio.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;
+	const char **cable_names;
+
+	info  = container_of(to_delayed_work(work), struct usb_extcon_info,
+			     wq_detcable);
+	cable_names = info->edev->supported_cable;
+
+	/* 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,
+				       cable_names[EXTCON_CABLE_USB_HOST],
+				       false);
+		extcon_set_cable_state(info->edev,
+				       cable_names[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,
+				       cable_names[EXTCON_CABLE_USB], false);
+		extcon_set_cable_state(info->edev,
+				       cable_names[EXTCON_CABLE_USB_HOST],
+				       true);
+	}
+}
+
+static irqreturn_t usb_irq_handler(int irq, void *dev_id)
+{
+	struct usb_extcon_info *info = dev_id;
+
+	/* debounce the GPIO via delayed work */
+	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(struct usb_extcon_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,
+					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 allocate 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;
+
+	info = dev_get_drvdata(dev);
+
+	if (!IS_ERR(info->id_gpiod))
+		enable_irq_wake(info->id_irq);
+
+	return 0;
+}
+
+static int usb_extcon_resume(struct device *dev)
+{
+	struct usb_extcon_info *info;
+
+	info = dev_get_drvdata(dev);
+
+	if (!IS_ERR(info->id_gpiod))
+		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", },
+	{ /* end */ }
+};
+
+static struct platform_driver usb_extcon_driver = {
+	.probe		= usb_extcon_probe,
+	.remove		= usb_extcon_remove,
+	.driver		= {
+		.name	= "extcon-usb",
+		.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] 40+ messages in thread

* [PATCH 1/5] extcon: gpio-usb: Introduce gpio usb extcon driver
@ 2015-01-19 17:52   ` Roger Quadros
  0 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-19 17:52 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.txt      |  20 ++
 drivers/extcon/Kconfig                             |   7 +
 drivers/extcon/Makefile                            |   1 +
 drivers/extcon/extcon-gpio-usb.c                   | 225 +++++++++++++++++++++
 4 files changed, 253 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb.txt
 create mode 100644 drivers/extcon/extcon-gpio-usb.c

diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb.txt b/Documentation/devicetree/bindings/extcon/extcon-usb.txt
new file mode 100644
index 0000000..171c5a4
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-usb.txt
@@ -0,0 +1,20 @@
+USB 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"
+- id-gpio: gpio for USB ID pin. See gpio binding.
+
+Example:
+	extcon_usb1 {
+		compatible = "linux,extcon-usb";
+		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+	}
+
+	usb@1 {
+		...
+		extcon = <&extcon_usb1>;
+		...
+	};
diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
index 6a1f7de..8106a83 100644
--- a/drivers/extcon/Kconfig
+++ b/drivers/extcon/Kconfig
@@ -35,6 +35,13 @@ config EXTCON_GPIO
 	  Say Y here to enable GPIO based extcon support. Note that GPIO
 	  extcon supports single state per extcon instance.
 
+config EXTCON_GPIO_USB
+	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.
+
 config EXTCON_MAX14577
 	tristate "MAX14577/77836 EXTCON Support"
 	depends on MFD_MAX14577
diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
index 0370b42..bae594b 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_GPIO_USB)	+= extcon-gpio-usb.o
diff --git a/drivers/extcon/extcon-gpio-usb.c b/drivers/extcon/extcon-gpio-usb.c
new file mode 100644
index 0000000..aeb2298
--- /dev/null
+++ b/drivers/extcon/extcon-gpio-usb.c
@@ -0,0 +1,225 @@
+/**
+ * drivers/extcon/extcon_gpio_usb.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/extcon/extcon-gpio.h>
+#include <linux/gpio.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;
+	const char **cable_names;
+
+	info  = container_of(to_delayed_work(work), struct usb_extcon_info,
+			     wq_detcable);
+	cable_names = info->edev->supported_cable;
+
+	/* 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,
+				       cable_names[EXTCON_CABLE_USB_HOST],
+				       false);
+		extcon_set_cable_state(info->edev,
+				       cable_names[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,
+				       cable_names[EXTCON_CABLE_USB], false);
+		extcon_set_cable_state(info->edev,
+				       cable_names[EXTCON_CABLE_USB_HOST],
+				       true);
+	}
+}
+
+static irqreturn_t usb_irq_handler(int irq, void *dev_id)
+{
+	struct usb_extcon_info *info = dev_id;
+
+	/* debounce the GPIO via delayed work */
+	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(struct usb_extcon_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,
+					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 allocate 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;
+
+	info = dev_get_drvdata(dev);
+
+	if (!IS_ERR(info->id_gpiod))
+		enable_irq_wake(info->id_irq);
+
+	return 0;
+}
+
+static int usb_extcon_resume(struct device *dev)
+{
+	struct usb_extcon_info *info;
+
+	info = dev_get_drvdata(dev);
+
+	if (!IS_ERR(info->id_gpiod))
+		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", },
+	{ /* end */ }
+};
+
+static struct platform_driver usb_extcon_driver = {
+	.probe		= usb_extcon_probe,
+	.remove		= usb_extcon_remove,
+	.driver		= {
+		.name	= "extcon-usb",
+		.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 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] 40+ messages in thread

* [PATCH 2/5] usb: extcon: Fix USB-Host cable name
  2015-01-19 17:52 ` Roger Quadros
@ 2015-01-19 17:52   ` Roger Quadros
  -1 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-19 17:52 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>
---
 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] 40+ messages in thread

* [PATCH 2/5] usb: extcon: Fix USB-Host cable name
@ 2015-01-19 17:52   ` Roger Quadros
  0 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-19 17:52 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>
---
 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] 40+ messages in thread

* [PATCH 3/5] ARM: dts: dra7-evm: Add extcon nodes for USB
  2015-01-19 17:52 ` Roger Quadros
@ 2015-01-19 17:52   ` Roger Quadros
  -1 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-19 17:52 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>
---
 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 10b725c..47d9a06 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";
+		id-gpio = <&pcf_gpio_21 1 GPIO_ACTIVE_HIGH>;
+	};
+
+	extcon_usb2: extcon_usb2 {
+		compatible = "linux,extcon-usb";
+		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] 40+ messages in thread

* [PATCH 3/5] ARM: dts: dra7-evm: Add extcon nodes for USB
@ 2015-01-19 17:52   ` Roger Quadros
  0 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-19 17:52 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>
---
 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 10b725c..47d9a06 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";
+		id-gpio = <&pcf_gpio_21 1 GPIO_ACTIVE_HIGH>;
+	};
+
+	extcon_usb2: extcon_usb2 {
+		compatible = "linux,extcon-usb";
+		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] 40+ messages in thread

* [PATCH 4/5] ARM: dts: dra72-evm: Add extcon nodes for USB
  2015-01-19 17:52 ` Roger Quadros
@ 2015-01-19 17:52   ` Roger Quadros
  -1 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-19 17:52 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>
---
 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..d93a98f 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";
+		id-gpio = <&pcf_gpio_21 1 GPIO_ACTIVE_HIGH>;
+	};
+
+	extcon_usb2: extcon_usb2 {
+		compatible = "linux,extcon-usb";
+		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] 40+ messages in thread

* [PATCH 4/5] ARM: dts: dra72-evm: Add extcon nodes for USB
@ 2015-01-19 17:52   ` Roger Quadros
  0 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-19 17:52 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>
---
 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..d93a98f 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";
+		id-gpio = <&pcf_gpio_21 1 GPIO_ACTIVE_HIGH>;
+	};
+
+	extcon_usb2: extcon_usb2 {
+		compatible = "linux,extcon-usb";
+		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] 40+ messages in thread

* [PATCH 5/5] ARM: omap2plus_defconfig: Enable PCF857X and EXTCON_GPIO_USB
  2015-01-19 17:52 ` Roger Quadros
@ 2015-01-19 17:52   ` Roger Quadros
  -1 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-19 17:52 UTC (permalink / raw)
  To: balbi, tony, myungjoo.ham, cw00.choi
  Cc: george.cherian, nsekhar, devicetree, linux-usb, linux-omap,
	linux-kernel, Roger Quadros

Both are needed for USB cable type detection on dra7-evm.

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

diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
index c2c3a85..bc23b90 100644
--- a/arch/arm/configs/omap2plus_defconfig
+++ b/arch/arm/configs/omap2plus_defconfig
@@ -203,6 +203,7 @@ CONFIG_SPI_OMAP24XX=y
 CONFIG_PINCTRL_SINGLE=y
 CONFIG_DEBUG_GPIO=y
 CONFIG_GPIO_SYSFS=y
+CONFIG_GPIO_PCF857X=y
 CONFIG_GPIO_TWL4030=y
 CONFIG_W1=y
 CONFIG_BATTERY_BQ27x00=m
@@ -326,6 +327,7 @@ CONFIG_DMADEVICES=y
 CONFIG_TI_EDMA=y
 CONFIG_DMA_OMAP=y
 CONFIG_EXTCON=y
+CONFIG_EXTCON_GPIO_USB=y
 CONFIG_EXTCON_PALMAS=y
 CONFIG_PWM=y
 CONFIG_PWM_TIECAP=y
-- 
2.1.0


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

* [PATCH 5/5] ARM: omap2plus_defconfig: Enable PCF857X and EXTCON_GPIO_USB
@ 2015-01-19 17:52   ` Roger Quadros
  0 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-19 17:52 UTC (permalink / raw)
  To: balbi, tony, myungjoo.ham, cw00.choi
  Cc: george.cherian, nsekhar, devicetree, linux-usb, linux-omap,
	linux-kernel, Roger Quadros

Both are needed for USB cable type detection on dra7-evm.

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

diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
index c2c3a85..bc23b90 100644
--- a/arch/arm/configs/omap2plus_defconfig
+++ b/arch/arm/configs/omap2plus_defconfig
@@ -203,6 +203,7 @@ CONFIG_SPI_OMAP24XX=y
 CONFIG_PINCTRL_SINGLE=y
 CONFIG_DEBUG_GPIO=y
 CONFIG_GPIO_SYSFS=y
+CONFIG_GPIO_PCF857X=y
 CONFIG_GPIO_TWL4030=y
 CONFIG_W1=y
 CONFIG_BATTERY_BQ27x00=m
@@ -326,6 +327,7 @@ CONFIG_DMADEVICES=y
 CONFIG_TI_EDMA=y
 CONFIG_DMA_OMAP=y
 CONFIG_EXTCON=y
+CONFIG_EXTCON_GPIO_USB=y
 CONFIG_EXTCON_PALMAS=y
 CONFIG_PWM=y
 CONFIG_PWM_TIECAP=y
-- 
2.1.0

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

* Re: [PATCH 5/5] ARM: omap2plus_defconfig: Enable PCF857X and EXTCON_GPIO_USB
  2015-01-19 17:52   ` Roger Quadros
  (?)
@ 2015-01-19 18:45   ` Tony Lindgren
  2015-01-19 19:38     ` Tony Lindgren
  -1 siblings, 1 reply; 40+ messages in thread
From: Tony Lindgren @ 2015-01-19 18:45 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> [150119 09:55]:
> Both are needed for USB cable type detection on dra7-evm.
> 
> Signed-off-by: Roger Quadros <rogerq@ti.com>
> ---
>  arch/arm/configs/omap2plus_defconfig | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
> index c2c3a85..bc23b90 100644
> --- a/arch/arm/configs/omap2plus_defconfig
> +++ b/arch/arm/configs/omap2plus_defconfig
> @@ -203,6 +203,7 @@ CONFIG_SPI_OMAP24XX=y
>  CONFIG_PINCTRL_SINGLE=y
>  CONFIG_DEBUG_GPIO=y
>  CONFIG_GPIO_SYSFS=y
> +CONFIG_GPIO_PCF857X=y
>  CONFIG_GPIO_TWL4030=y
>  CONFIG_W1=y
>  CONFIG_BATTERY_BQ27x00=m

Looks like I have this too but as a loadable module :) So I'll keep
that one.

> @@ -326,6 +327,7 @@ CONFIG_DMADEVICES=y
>  CONFIG_TI_EDMA=y
>  CONFIG_DMA_OMAP=y
>  CONFIG_EXTCON=y
> +CONFIG_EXTCON_GPIO_USB=y
>  CONFIG_EXTCON_PALMAS=y
>  CONFIG_PWM=y
>  CONFIG_PWM_TIECAP=y

I'll apply this part into omap-for-v3.20/defconfig but make it into =m
instead of =y.

Regards,

Tony

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

* Re: [PATCH 5/5] ARM: omap2plus_defconfig: Enable PCF857X and EXTCON_GPIO_USB
  2015-01-19 18:45   ` Tony Lindgren
@ 2015-01-19 19:38     ` Tony Lindgren
  2015-01-20  9:26         ` Roger Quadros
  0 siblings, 1 reply; 40+ messages in thread
From: Tony Lindgren @ 2015-01-19 19:38 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

* Tony Lindgren <tony@atomide.com> [150119 10:52]:
> * Roger Quadros <rogerq@ti.com> [150119 09:55]:
> > Both are needed for USB cable type detection on dra7-evm.
> > 
> > Signed-off-by: Roger Quadros <rogerq@ti.com>
> > ---
> >  arch/arm/configs/omap2plus_defconfig | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
> > index c2c3a85..bc23b90 100644
> > --- a/arch/arm/configs/omap2plus_defconfig
> > +++ b/arch/arm/configs/omap2plus_defconfig
> > @@ -203,6 +203,7 @@ CONFIG_SPI_OMAP24XX=y
> >  CONFIG_PINCTRL_SINGLE=y
> >  CONFIG_DEBUG_GPIO=y
> >  CONFIG_GPIO_SYSFS=y
> > +CONFIG_GPIO_PCF857X=y
> >  CONFIG_GPIO_TWL4030=y
> >  CONFIG_W1=y
> >  CONFIG_BATTERY_BQ27x00=m
> 
> Looks like I have this too but as a loadable module :) So I'll keep
> that one.
> 
> > @@ -326,6 +327,7 @@ CONFIG_DMADEVICES=y
> >  CONFIG_TI_EDMA=y
> >  CONFIG_DMA_OMAP=y
> >  CONFIG_EXTCON=y
> > +CONFIG_EXTCON_GPIO_USB=y
> >  CONFIG_EXTCON_PALMAS=y
> >  CONFIG_PWM=y
> >  CONFIG_PWM_TIECAP=y
> 
> I'll apply this part into omap-for-v3.20/defconfig but make it into =m
> instead of =y.

Oh but this depends on the driver being added, so not applying.
Can you please repost a patch adding CONFIG_EXTCON_GPIO_USB=m
once the driver is merged?

Regards,

Tony

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

* Re: [PATCH 5/5] ARM: omap2plus_defconfig: Enable PCF857X and EXTCON_GPIO_USB
  2015-01-19 19:38     ` Tony Lindgren
@ 2015-01-20  9:26         ` Roger Quadros
  0 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-20  9:26 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: balbi, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

On 19/01/15 21:38, Tony Lindgren wrote:
> * Tony Lindgren <tony@atomide.com> [150119 10:52]:
>> * Roger Quadros <rogerq@ti.com> [150119 09:55]:
>>> Both are needed for USB cable type detection on dra7-evm.
>>>
>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>> ---
>>>  arch/arm/configs/omap2plus_defconfig | 2 ++
>>>  1 file changed, 2 insertions(+)
>>>
>>> diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
>>> index c2c3a85..bc23b90 100644
>>> --- a/arch/arm/configs/omap2plus_defconfig
>>> +++ b/arch/arm/configs/omap2plus_defconfig
>>> @@ -203,6 +203,7 @@ CONFIG_SPI_OMAP24XX=y
>>>  CONFIG_PINCTRL_SINGLE=y
>>>  CONFIG_DEBUG_GPIO=y
>>>  CONFIG_GPIO_SYSFS=y
>>> +CONFIG_GPIO_PCF857X=y
>>>  CONFIG_GPIO_TWL4030=y
>>>  CONFIG_W1=y
>>>  CONFIG_BATTERY_BQ27x00=m
>>
>> Looks like I have this too but as a loadable module :) So I'll keep
>> that one.
>>
>>> @@ -326,6 +327,7 @@ CONFIG_DMADEVICES=y
>>>  CONFIG_TI_EDMA=y
>>>  CONFIG_DMA_OMAP=y
>>>  CONFIG_EXTCON=y
>>> +CONFIG_EXTCON_GPIO_USB=y
>>>  CONFIG_EXTCON_PALMAS=y
>>>  CONFIG_PWM=y
>>>  CONFIG_PWM_TIECAP=y
>>
>> I'll apply this part into omap-for-v3.20/defconfig but make it into =m
>> instead of =y.
> 
> Oh but this depends on the driver being added, so not applying.
> Can you please repost a patch adding CONFIG_EXTCON_GPIO_USB=m
> once the driver is merged?
> 
Yes, I'll do that.

cheers,
-roger

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

* Re: [PATCH 5/5] ARM: omap2plus_defconfig: Enable PCF857X and EXTCON_GPIO_USB
@ 2015-01-20  9:26         ` Roger Quadros
  0 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-20  9:26 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: balbi, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

On 19/01/15 21:38, Tony Lindgren wrote:
> * Tony Lindgren <tony@atomide.com> [150119 10:52]:
>> * Roger Quadros <rogerq@ti.com> [150119 09:55]:
>>> Both are needed for USB cable type detection on dra7-evm.
>>>
>>> Signed-off-by: Roger Quadros <rogerq@ti.com>
>>> ---
>>>  arch/arm/configs/omap2plus_defconfig | 2 ++
>>>  1 file changed, 2 insertions(+)
>>>
>>> diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
>>> index c2c3a85..bc23b90 100644
>>> --- a/arch/arm/configs/omap2plus_defconfig
>>> +++ b/arch/arm/configs/omap2plus_defconfig
>>> @@ -203,6 +203,7 @@ CONFIG_SPI_OMAP24XX=y
>>>  CONFIG_PINCTRL_SINGLE=y
>>>  CONFIG_DEBUG_GPIO=y
>>>  CONFIG_GPIO_SYSFS=y
>>> +CONFIG_GPIO_PCF857X=y
>>>  CONFIG_GPIO_TWL4030=y
>>>  CONFIG_W1=y
>>>  CONFIG_BATTERY_BQ27x00=m
>>
>> Looks like I have this too but as a loadable module :) So I'll keep
>> that one.
>>
>>> @@ -326,6 +327,7 @@ CONFIG_DMADEVICES=y
>>>  CONFIG_TI_EDMA=y
>>>  CONFIG_DMA_OMAP=y
>>>  CONFIG_EXTCON=y
>>> +CONFIG_EXTCON_GPIO_USB=y
>>>  CONFIG_EXTCON_PALMAS=y
>>>  CONFIG_PWM=y
>>>  CONFIG_PWM_TIECAP=y
>>
>> I'll apply this part into omap-for-v3.20/defconfig but make it into =m
>> instead of =y.
> 
> Oh but this depends on the driver being added, so not applying.
> Can you please repost a patch adding CONFIG_EXTCON_GPIO_USB=m
> once the driver is merged?
> 
Yes, I'll do that.

cheers,
-roger

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

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

[-- Attachment #1: Type: text/plain, Size: 9748 bytes --]

On Mon, Jan 19, 2015 at 07:52:18PM +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>

Reviewed-by: Felipe Balbi <balbi@ti.com>
Acked-by: Felipe Balbi <balbi@ti.com>

> ---
>  .../devicetree/bindings/extcon/extcon-usb.txt      |  20 ++
>  drivers/extcon/Kconfig                             |   7 +
>  drivers/extcon/Makefile                            |   1 +
>  drivers/extcon/extcon-gpio-usb.c                   | 225 +++++++++++++++++++++
>  4 files changed, 253 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb.txt
>  create mode 100644 drivers/extcon/extcon-gpio-usb.c
> 
> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb.txt b/Documentation/devicetree/bindings/extcon/extcon-usb.txt
> new file mode 100644
> index 0000000..171c5a4
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb.txt
> @@ -0,0 +1,20 @@
> +USB 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"
> +- id-gpio: gpio for USB ID pin. See gpio binding.
> +
> +Example:
> +	extcon_usb1 {
> +		compatible = "linux,extcon-usb";
> +		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
> +	}
> +
> +	usb@1 {
> +		...
> +		extcon = <&extcon_usb1>;
> +		...
> +	};
> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
> index 6a1f7de..8106a83 100644
> --- a/drivers/extcon/Kconfig
> +++ b/drivers/extcon/Kconfig
> @@ -35,6 +35,13 @@ config EXTCON_GPIO
>  	  Say Y here to enable GPIO based extcon support. Note that GPIO
>  	  extcon supports single state per extcon instance.
>  
> +config EXTCON_GPIO_USB
> +	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.
> +
>  config EXTCON_MAX14577
>  	tristate "MAX14577/77836 EXTCON Support"
>  	depends on MFD_MAX14577
> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
> index 0370b42..bae594b 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_GPIO_USB)	+= extcon-gpio-usb.o
> diff --git a/drivers/extcon/extcon-gpio-usb.c b/drivers/extcon/extcon-gpio-usb.c
> new file mode 100644
> index 0000000..aeb2298
> --- /dev/null
> +++ b/drivers/extcon/extcon-gpio-usb.c
> @@ -0,0 +1,225 @@
> +/**
> + * drivers/extcon/extcon_gpio_usb.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/extcon/extcon-gpio.h>
> +#include <linux/gpio.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;
> +	const char **cable_names;
> +
> +	info  = container_of(to_delayed_work(work), struct usb_extcon_info,
> +			     wq_detcable);
> +	cable_names = info->edev->supported_cable;
> +
> +	/* 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,
> +				       cable_names[EXTCON_CABLE_USB_HOST],
> +				       false);
> +		extcon_set_cable_state(info->edev,
> +				       cable_names[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,
> +				       cable_names[EXTCON_CABLE_USB], false);
> +		extcon_set_cable_state(info->edev,
> +				       cable_names[EXTCON_CABLE_USB_HOST],
> +				       true);
> +	}
> +}
> +
> +static irqreturn_t usb_irq_handler(int irq, void *dev_id)
> +{
> +	struct usb_extcon_info *info = dev_id;
> +
> +	/* debounce the GPIO via delayed work */
> +	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(struct usb_extcon_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,
> +					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 allocate 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;
> +
> +	info = dev_get_drvdata(dev);
> +
> +	if (!IS_ERR(info->id_gpiod))
> +		enable_irq_wake(info->id_irq);
> +
> +	return 0;
> +}
> +
> +static int usb_extcon_resume(struct device *dev)
> +{
> +	struct usb_extcon_info *info;
> +
> +	info = dev_get_drvdata(dev);
> +
> +	if (!IS_ERR(info->id_gpiod))
> +		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", },
> +	{ /* end */ }
> +};
> +
> +static struct platform_driver usb_extcon_driver = {
> +	.probe		= usb_extcon_probe,
> +	.remove		= usb_extcon_remove,
> +	.driver		= {
> +		.name	= "extcon-usb",
> +		.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
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 1/5] extcon: gpio-usb: Introduce gpio usb extcon driver
@ 2015-01-20 19:00     ` Felipe Balbi
  0 siblings, 0 replies; 40+ messages in thread
From: Felipe Balbi @ 2015-01-20 19:00 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi-l0cyMroinI0, tony-4v6yS6AI5VpBDgjK7y7TUQ,
	myungjoo.ham-Sze3O3UU22JBDgjK7y7TUQ,
	cw00.choi-Sze3O3UU22JBDgjK7y7TUQ, george.cherian-l0cyMroinI0,
	nsekhar-l0cyMroinI0, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 9858 bytes --]

On Mon, Jan 19, 2015 at 07:52:18PM +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>

Reviewed-by: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>
Acked-by: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>

> ---
>  .../devicetree/bindings/extcon/extcon-usb.txt      |  20 ++
>  drivers/extcon/Kconfig                             |   7 +
>  drivers/extcon/Makefile                            |   1 +
>  drivers/extcon/extcon-gpio-usb.c                   | 225 +++++++++++++++++++++
>  4 files changed, 253 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb.txt
>  create mode 100644 drivers/extcon/extcon-gpio-usb.c
> 
> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb.txt b/Documentation/devicetree/bindings/extcon/extcon-usb.txt
> new file mode 100644
> index 0000000..171c5a4
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb.txt
> @@ -0,0 +1,20 @@
> +USB 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"
> +- id-gpio: gpio for USB ID pin. See gpio binding.
> +
> +Example:
> +	extcon_usb1 {
> +		compatible = "linux,extcon-usb";
> +		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
> +	}
> +
> +	usb@1 {
> +		...
> +		extcon = <&extcon_usb1>;
> +		...
> +	};
> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
> index 6a1f7de..8106a83 100644
> --- a/drivers/extcon/Kconfig
> +++ b/drivers/extcon/Kconfig
> @@ -35,6 +35,13 @@ config EXTCON_GPIO
>  	  Say Y here to enable GPIO based extcon support. Note that GPIO
>  	  extcon supports single state per extcon instance.
>  
> +config EXTCON_GPIO_USB
> +	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.
> +
>  config EXTCON_MAX14577
>  	tristate "MAX14577/77836 EXTCON Support"
>  	depends on MFD_MAX14577
> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
> index 0370b42..bae594b 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_GPIO_USB)	+= extcon-gpio-usb.o
> diff --git a/drivers/extcon/extcon-gpio-usb.c b/drivers/extcon/extcon-gpio-usb.c
> new file mode 100644
> index 0000000..aeb2298
> --- /dev/null
> +++ b/drivers/extcon/extcon-gpio-usb.c
> @@ -0,0 +1,225 @@
> +/**
> + * drivers/extcon/extcon_gpio_usb.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/extcon/extcon-gpio.h>
> +#include <linux/gpio.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;
> +	const char **cable_names;
> +
> +	info  = container_of(to_delayed_work(work), struct usb_extcon_info,
> +			     wq_detcable);
> +	cable_names = info->edev->supported_cable;
> +
> +	/* 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,
> +				       cable_names[EXTCON_CABLE_USB_HOST],
> +				       false);
> +		extcon_set_cable_state(info->edev,
> +				       cable_names[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,
> +				       cable_names[EXTCON_CABLE_USB], false);
> +		extcon_set_cable_state(info->edev,
> +				       cable_names[EXTCON_CABLE_USB_HOST],
> +				       true);
> +	}
> +}
> +
> +static irqreturn_t usb_irq_handler(int irq, void *dev_id)
> +{
> +	struct usb_extcon_info *info = dev_id;
> +
> +	/* debounce the GPIO via delayed work */
> +	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(struct usb_extcon_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,
> +					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 allocate 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;
> +
> +	info = dev_get_drvdata(dev);
> +
> +	if (!IS_ERR(info->id_gpiod))
> +		enable_irq_wake(info->id_irq);
> +
> +	return 0;
> +}
> +
> +static int usb_extcon_resume(struct device *dev)
> +{
> +	struct usb_extcon_info *info;
> +
> +	info = dev_get_drvdata(dev);
> +
> +	if (!IS_ERR(info->id_gpiod))
> +		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", },
> +	{ /* end */ }
> +};
> +
> +static struct platform_driver usb_extcon_driver = {
> +	.probe		= usb_extcon_probe,
> +	.remove		= usb_extcon_remove,
> +	.driver		= {
> +		.name	= "extcon-usb",
> +		.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
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 2/5] usb: extcon: Fix USB-Host cable name
  2015-01-19 17:52   ` Roger Quadros
@ 2015-01-20 19:01     ` Felipe Balbi
  -1 siblings, 0 replies; 40+ messages in thread
From: Felipe Balbi @ 2015-01-20 19:01 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi, tony, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 6510 bytes --]

On Mon, Jan 19, 2015 at 07:52:19PM +0200, 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>

I checked that these are not documented and there are no DTS using
USB-HOST, so it's fine to change

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
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

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

[-- Attachment #1: Type: text/plain, Size: 6510 bytes --]

On Mon, Jan 19, 2015 at 07:52:19PM +0200, 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>

I checked that these are not documented and there are no DTS using
USB-HOST, so it's fine to change

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
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 3/5] ARM: dts: dra7-evm: Add extcon nodes for USB
  2015-01-19 17:52   ` Roger Quadros
@ 2015-01-20 19:02     ` Felipe Balbi
  -1 siblings, 0 replies; 40+ messages in thread
From: Felipe Balbi @ 2015-01-20 19:02 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi, tony, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2017 bytes --]

On Mon, Jan 19, 2015 at 07:52:20PM +0200, Roger Quadros wrote:
> 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 10b725c..47d9a06 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";
> +		id-gpio = <&pcf_gpio_21 1 GPIO_ACTIVE_HIGH>;
> +	};
> +
> +	extcon_usb2: extcon_usb2 {
> +		compatible = "linux,extcon-usb";
> +		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
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 3/5] ARM: dts: dra7-evm: Add extcon nodes for USB
@ 2015-01-20 19:02     ` Felipe Balbi
  0 siblings, 0 replies; 40+ messages in thread
From: Felipe Balbi @ 2015-01-20 19:02 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi, tony, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2017 bytes --]

On Mon, Jan 19, 2015 at 07:52:20PM +0200, Roger Quadros wrote:
> 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 10b725c..47d9a06 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";
> +		id-gpio = <&pcf_gpio_21 1 GPIO_ACTIVE_HIGH>;
> +	};
> +
> +	extcon_usb2: extcon_usb2 {
> +		compatible = "linux,extcon-usb";
> +		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
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 4/5] ARM: dts: dra72-evm: Add extcon nodes for USB
  2015-01-19 17:52   ` Roger Quadros
@ 2015-01-20 19:02     ` Felipe Balbi
  -1 siblings, 0 replies; 40+ messages in thread
From: Felipe Balbi @ 2015-01-20 19:02 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi, tony, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2177 bytes --]

On Mon, Jan 19, 2015 at 07:52:21PM +0200, Roger Quadros wrote:
> 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..d93a98f 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";
> +		id-gpio = <&pcf_gpio_21 1 GPIO_ACTIVE_HIGH>;
> +	};
> +
> +	extcon_usb2: extcon_usb2 {
> +		compatible = "linux,extcon-usb";
> +		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
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 4/5] ARM: dts: dra72-evm: Add extcon nodes for USB
@ 2015-01-20 19:02     ` Felipe Balbi
  0 siblings, 0 replies; 40+ messages in thread
From: Felipe Balbi @ 2015-01-20 19:02 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi, tony, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2177 bytes --]

On Mon, Jan 19, 2015 at 07:52:21PM +0200, Roger Quadros wrote:
> 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..d93a98f 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";
> +		id-gpio = <&pcf_gpio_21 1 GPIO_ACTIVE_HIGH>;
> +	};
> +
> +	extcon_usb2: extcon_usb2 {
> +		compatible = "linux,extcon-usb";
> +		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
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 0/5] extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 USB.
  2015-01-19 17:52 ` Roger Quadros
@ 2015-01-20 19:02   ` Felipe Balbi
  -1 siblings, 0 replies; 40+ messages in thread
From: Felipe Balbi @ 2015-01-20 19:02 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi, tony, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1737 bytes --]

On Mon, Jan 19, 2015 at 07:52:17PM +0200, Roger Quadros wrote:
> Hi,
> 
> On DRA7 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 and DRA72-evm.

while at that, you might want to patch X15 too.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 0/5] extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 USB.
@ 2015-01-20 19:02   ` Felipe Balbi
  0 siblings, 0 replies; 40+ messages in thread
From: Felipe Balbi @ 2015-01-20 19:02 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi, tony, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1737 bytes --]

On Mon, Jan 19, 2015 at 07:52:17PM +0200, Roger Quadros wrote:
> Hi,
> 
> On DRA7 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 and DRA72-evm.

while at that, you might want to patch X15 too.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 1/5] extcon: gpio-usb: Introduce gpio usb extcon driver
@ 2015-01-21  5:28     ` Chanwoo Choi
  0 siblings, 0 replies; 40+ messages in thread
From: Chanwoo Choi @ 2015-01-21  5:28 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/20/2015 02:52 AM, 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>
> ---
>  .../devicetree/bindings/extcon/extcon-usb.txt      |  20 ++
>  drivers/extcon/Kconfig                             |   7 +
>  drivers/extcon/Makefile                            |   1 +
>  drivers/extcon/extcon-gpio-usb.c                   | 225 +++++++++++++++++++++
>  4 files changed, 253 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb.txt
>  create mode 100644 drivers/extcon/extcon-gpio-usb.c
> 
> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb.txt b/Documentation/devicetree/bindings/extcon/extcon-usb.txt
> new file mode 100644
> index 0000000..171c5a4
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb.txt

Need to rename from extcon-usb.txt to extcon-gpio-usb.txt.

> @@ -0,0 +1,20 @@
> +USB 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"

I think you better use "linux,extcon-gpio-usb"
because the point of this driver use the gpio for usb cable.

> +- id-gpio: gpio for USB ID pin. See gpio binding.
> +
> +Example:
> +	extcon_usb1 {
> +		compatible = "linux,extcon-usb";

ditto.

> +		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
> +	}
> +
> +	usb@1 {
> +		...
> +		extcon = <&extcon_usb1>;
> +		...
> +	};
> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
> index 6a1f7de..8106a83 100644
> --- a/drivers/extcon/Kconfig
> +++ b/drivers/extcon/Kconfig
> @@ -35,6 +35,13 @@ config EXTCON_GPIO
>  	  Say Y here to enable GPIO based extcon support. Note that GPIO
>  	  extcon supports single state per extcon instance.
>  
> +config EXTCON_GPIO_USB
> +	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.
> +
>  config EXTCON_MAX14577
>  	tristate "MAX14577/77836 EXTCON Support"
>  	depends on MFD_MAX14577
> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
> index 0370b42..bae594b 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_GPIO_USB)	+= extcon-gpio-usb.o

Need to re-order it alphabetically.

> diff --git a/drivers/extcon/extcon-gpio-usb.c b/drivers/extcon/extcon-gpio-usb.c
> new file mode 100644
> index 0000000..aeb2298
> --- /dev/null
> +++ b/drivers/extcon/extcon-gpio-usb.c
> @@ -0,0 +1,225 @@
> +/**
> + * drivers/extcon/extcon_gpio_usb.c - USB GPIO extcon driver
> + *
> + * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
> + *

Remove un-necessary blank line.

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

Is it necessary? I think it is your mistake?

> +#include <linux/gpio.h>

Don't need it because 'of_gpio.h' includes already 'gpio.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;
> +	const char **cable_names;
> +
> +	info  = container_of(to_delayed_work(work), struct usb_extcon_info,
> +			     wq_detcable);
> +	cable_names = info->edev->supported_cable;

I think you can use 'usb_extcon_cable' instead of 'cable_names'.
So, you will remove 'cable_names' variable.

> +
> +	/* 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,
> +				       cable_names[EXTCON_CABLE_USB_HOST],
> +				       false);
> +		extcon_set_cable_state(info->edev,
> +				       cable_names[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,
> +				       cable_names[EXTCON_CABLE_USB], false);
> +		extcon_set_cable_state(info->edev,
> +				       cable_names[EXTCON_CABLE_USB_HOST],
> +				       true);
> +	}
> +}
> +
> +static irqreturn_t usb_irq_handler(int irq, void *dev_id)
> +{
> +	struct usb_extcon_info *info = dev_id;
> +
> +	/* debounce the GPIO via delayed work */

I think this comment is not necessary.

> +	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(struct usb_extcon_info),

sizeof(struct usb_extcon_info) -> 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,

I prefer to add IRQF_NO_SUSPEND flag because IRQF_NO_SUSPEND flag is necessary
for wake-up from freeze pm state.

> +					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 allocate extcon device\n");

Wrong error information, you have to change verb (allocate -> register)

> +		return ret;
> +	}
> +
> +	platform_set_drvdata(pdev, info);

Need blank line.

> +	/* 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;
> +
> +	info = dev_get_drvdata(dev);

Simplify this code as following:
	struct usb_extcon_info *info = dev_get_drvdata(dev);

> +
> +	if (!IS_ERR(info->id_gpiod))

I think that it is sufficient cheking without IS_ERR macro as following:
	if (info->id_gpiod)

> +		enable_irq_wake(info->id_irq);
> +
> +	return 0;
> +}
> +
> +static int usb_extcon_resume(struct device *dev)
> +{
> +	struct usb_extcon_info *info;
> +
> +	info = dev_get_drvdata(dev);

ditto.

> +
> +	if (!IS_ERR(info->id_gpiod))

ditto.

> +		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", },

Change compatible name from "linux,extcon-usb", to "linux,extcon-gpio-usb".

> +	{ /* end */ }
> +};
> +
> +static struct platform_driver usb_extcon_driver = {
> +	.probe		= usb_extcon_probe,
> +	.remove		= usb_extcon_remove,
> +	.driver		= {
> +		.name	= "extcon-usb",
> +		.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 Cho


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

* Re: [PATCH 1/5] extcon: gpio-usb: Introduce gpio usb extcon driver
@ 2015-01-21  5:28     ` Chanwoo Choi
  0 siblings, 0 replies; 40+ messages in thread
From: Chanwoo Choi @ 2015-01-21  5:28 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

Hi Roger,

On 01/20/2015 02:52 AM, 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>
> ---
>  .../devicetree/bindings/extcon/extcon-usb.txt      |  20 ++
>  drivers/extcon/Kconfig                             |   7 +
>  drivers/extcon/Makefile                            |   1 +
>  drivers/extcon/extcon-gpio-usb.c                   | 225 +++++++++++++++++++++
>  4 files changed, 253 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb.txt
>  create mode 100644 drivers/extcon/extcon-gpio-usb.c
> 
> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb.txt b/Documentation/devicetree/bindings/extcon/extcon-usb.txt
> new file mode 100644
> index 0000000..171c5a4
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb.txt

Need to rename from extcon-usb.txt to extcon-gpio-usb.txt.

> @@ -0,0 +1,20 @@
> +USB 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"

I think you better use "linux,extcon-gpio-usb"
because the point of this driver use the gpio for usb cable.

> +- id-gpio: gpio for USB ID pin. See gpio binding.
> +
> +Example:
> +	extcon_usb1 {
> +		compatible = "linux,extcon-usb";

ditto.

> +		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
> +	}
> +
> +	usb@1 {
> +		...
> +		extcon = <&extcon_usb1>;
> +		...
> +	};
> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
> index 6a1f7de..8106a83 100644
> --- a/drivers/extcon/Kconfig
> +++ b/drivers/extcon/Kconfig
> @@ -35,6 +35,13 @@ config EXTCON_GPIO
>  	  Say Y here to enable GPIO based extcon support. Note that GPIO
>  	  extcon supports single state per extcon instance.
>  
> +config EXTCON_GPIO_USB
> +	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.
> +
>  config EXTCON_MAX14577
>  	tristate "MAX14577/77836 EXTCON Support"
>  	depends on MFD_MAX14577
> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
> index 0370b42..bae594b 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_GPIO_USB)	+= extcon-gpio-usb.o

Need to re-order it alphabetically.

> diff --git a/drivers/extcon/extcon-gpio-usb.c b/drivers/extcon/extcon-gpio-usb.c
> new file mode 100644
> index 0000000..aeb2298
> --- /dev/null
> +++ b/drivers/extcon/extcon-gpio-usb.c
> @@ -0,0 +1,225 @@
> +/**
> + * drivers/extcon/extcon_gpio_usb.c - USB GPIO extcon driver
> + *
> + * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
> + *

Remove un-necessary blank line.

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

Is it necessary? I think it is your mistake?

> +#include <linux/gpio.h>

Don't need it because 'of_gpio.h' includes already 'gpio.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;
> +	const char **cable_names;
> +
> +	info  = container_of(to_delayed_work(work), struct usb_extcon_info,
> +			     wq_detcable);
> +	cable_names = info->edev->supported_cable;

I think you can use 'usb_extcon_cable' instead of 'cable_names'.
So, you will remove 'cable_names' variable.

> +
> +	/* 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,
> +				       cable_names[EXTCON_CABLE_USB_HOST],
> +				       false);
> +		extcon_set_cable_state(info->edev,
> +				       cable_names[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,
> +				       cable_names[EXTCON_CABLE_USB], false);
> +		extcon_set_cable_state(info->edev,
> +				       cable_names[EXTCON_CABLE_USB_HOST],
> +				       true);
> +	}
> +}
> +
> +static irqreturn_t usb_irq_handler(int irq, void *dev_id)
> +{
> +	struct usb_extcon_info *info = dev_id;
> +
> +	/* debounce the GPIO via delayed work */

I think this comment is not necessary.

> +	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(struct usb_extcon_info),

sizeof(struct usb_extcon_info) -> 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,

I prefer to add IRQF_NO_SUSPEND flag because IRQF_NO_SUSPEND flag is necessary
for wake-up from freeze pm state.

> +					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 allocate extcon device\n");

Wrong error information, you have to change verb (allocate -> register)

> +		return ret;
> +	}
> +
> +	platform_set_drvdata(pdev, info);

Need blank line.

> +	/* 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;
> +
> +	info = dev_get_drvdata(dev);

Simplify this code as following:
	struct usb_extcon_info *info = dev_get_drvdata(dev);

> +
> +	if (!IS_ERR(info->id_gpiod))

I think that it is sufficient cheking without IS_ERR macro as following:
	if (info->id_gpiod)

> +		enable_irq_wake(info->id_irq);
> +
> +	return 0;
> +}
> +
> +static int usb_extcon_resume(struct device *dev)
> +{
> +	struct usb_extcon_info *info;
> +
> +	info = dev_get_drvdata(dev);

ditto.

> +
> +	if (!IS_ERR(info->id_gpiod))

ditto.

> +		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", },

Change compatible name from "linux,extcon-usb", to "linux,extcon-gpio-usb".

> +	{ /* end */ }
> +};
> +
> +static struct platform_driver usb_extcon_driver = {
> +	.probe		= usb_extcon_probe,
> +	.remove		= usb_extcon_remove,
> +	.driver		= {
> +		.name	= "extcon-usb",
> +		.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 Cho

--
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] 40+ messages in thread

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

Hi Chanwoo,

On 21/01/15 07:28, Chanwoo Choi wrote:
> Hi Roger,
> 
> On 01/20/2015 02:52 AM, 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>
>> ---
>>  .../devicetree/bindings/extcon/extcon-usb.txt      |  20 ++
>>  drivers/extcon/Kconfig                             |   7 +
>>  drivers/extcon/Makefile                            |   1 +
>>  drivers/extcon/extcon-gpio-usb.c                   | 225 +++++++++++++++++++++
>>  4 files changed, 253 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb.txt
>>  create mode 100644 drivers/extcon/extcon-gpio-usb.c
>>
>> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb.txt b/Documentation/devicetree/bindings/extcon/extcon-usb.txt
>> new file mode 100644
>> index 0000000..171c5a4
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb.txt
> 
> Need to rename from extcon-usb.txt to extcon-gpio-usb.txt.
> 
>> @@ -0,0 +1,20 @@
>> +USB 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"
> 
> I think you better use "linux,extcon-gpio-usb"
> because the point of this driver use the gpio for usb cable.

I will change all instances of "extcon-usb" to "extcon-usb-gpio".

> 
>> +- id-gpio: gpio for USB ID pin. See gpio binding.
>> +
>> +Example:
>> +	extcon_usb1 {
>> +		compatible = "linux,extcon-usb";
> 
> ditto.
> 
>> +		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
>> +	}
>> +
>> +	usb@1 {
>> +		...
>> +		extcon = <&extcon_usb1>;
>> +		...
>> +	};
>> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
>> index 6a1f7de..8106a83 100644
>> --- a/drivers/extcon/Kconfig
>> +++ b/drivers/extcon/Kconfig
>> @@ -35,6 +35,13 @@ config EXTCON_GPIO
>>  	  Say Y here to enable GPIO based extcon support. Note that GPIO
>>  	  extcon supports single state per extcon instance.
>>  
>> +config EXTCON_GPIO_USB
>> +	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.
>> +
>>  config EXTCON_MAX14577
>>  	tristate "MAX14577/77836 EXTCON Support"
>>  	depends on MFD_MAX14577
>> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
>> index 0370b42..bae594b 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_GPIO_USB)	+= extcon-gpio-usb.o
> 
> Need to re-order it alphabetically.

OK. I will change this to extcon-usb-gpio so it will remain last.
> 
>> diff --git a/drivers/extcon/extcon-gpio-usb.c b/drivers/extcon/extcon-gpio-usb.c
>> new file mode 100644
>> index 0000000..aeb2298
>> --- /dev/null
>> +++ b/drivers/extcon/extcon-gpio-usb.c
>> @@ -0,0 +1,225 @@
>> +/**
>> + * drivers/extcon/extcon_gpio_usb.c - USB GPIO extcon driver
>> + *
>> + * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
>> + *
> 
> Remove un-necessary blank line.

OK.
> 
>> + * 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/extcon/extcon-gpio.h>
> 
> Is it necessary? I think it is your mistake?

right. my bad.
> 
>> +#include <linux/gpio.h>
> 
> Don't need it because 'of_gpio.h' includes already 'gpio.h'.

agreed.

> 
>> +#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;
>> +	const char **cable_names;
>> +
>> +	info  = container_of(to_delayed_work(work), struct usb_extcon_info,
>> +			     wq_detcable);
>> +	cable_names = info->edev->supported_cable;
> 
> I think you can use 'usb_extcon_cable' instead of 'cable_names'.
> So, you will remove 'cable_names' variable.
> 
OK.

>> +
>> +	/* 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,
>> +				       cable_names[EXTCON_CABLE_USB_HOST],
>> +				       false);
>> +		extcon_set_cable_state(info->edev,
>> +				       cable_names[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,
>> +				       cable_names[EXTCON_CABLE_USB], false);
>> +		extcon_set_cable_state(info->edev,
>> +				       cable_names[EXTCON_CABLE_USB_HOST],
>> +				       true);
>> +	}
>> +}
>> +
>> +static irqreturn_t usb_irq_handler(int irq, void *dev_id)
>> +{
>> +	struct usb_extcon_info *info = dev_id;
>> +
>> +	/* debounce the GPIO via delayed work */
> 
> I think this comment is not necessary.

OK.
> 
>> +	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(struct usb_extcon_info),
> 
> sizeof(struct usb_extcon_info) -> sizeof(*info)
>
right.
 
>> +			    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,
> 
> I prefer to add IRQF_NO_SUSPEND flag because IRQF_NO_SUSPEND flag is necessary
> for wake-up from freeze pm state.

Agreed.
> 
>> +					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 allocate extcon device\n");
> 
> Wrong error information, you have to change verb (allocate -> register)

will fix.
> 
>> +		return ret;
>> +	}
>> +
>> +	platform_set_drvdata(pdev, info);
> 
> Need blank line.

OK.
> 
>> +	/* 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;
>> +
>> +	info = dev_get_drvdata(dev);
> 
> Simplify this code as following:
> 	struct usb_extcon_info *info = dev_get_drvdata(dev);

OK.
> 
>> +
>> +	if (!IS_ERR(info->id_gpiod))
> 
> I think that it is sufficient cheking without IS_ERR macro as following:
> 	if (info->id_gpiod)

I will remove this if check as we're failing probe if id_gpiod is not valid.

> 
>> +		enable_irq_wake(info->id_irq);
>> +
>> +	return 0;
>> +}
>> +
>> +static int usb_extcon_resume(struct device *dev)
>> +{
>> +	struct usb_extcon_info *info;
>> +
>> +	info = dev_get_drvdata(dev);
> 
> ditto.
> 
>> +
>> +	if (!IS_ERR(info->id_gpiod))
> 
> ditto.
> 
>> +		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", },
> 
> Change compatible name from "linux,extcon-usb", to "linux,extcon-gpio-usb".
> 

will use "linux,extcon-usb-gpio"

>> +	{ /* end */ }
>> +};
>> +
>> +static struct platform_driver usb_extcon_driver = {
>> +	.probe		= usb_extcon_probe,
>> +	.remove		= usb_extcon_remove,
>> +	.driver		= {
>> +		.name	= "extcon-usb",
>> +		.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] 40+ messages in thread

* Re: [PATCH 1/5] extcon: gpio-usb: Introduce gpio usb extcon driver
@ 2015-01-22 13:27       ` Roger Quadros
  0 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-22 13:27 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

Hi Chanwoo,

On 21/01/15 07:28, Chanwoo Choi wrote:
> Hi Roger,
> 
> On 01/20/2015 02:52 AM, 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>
>> ---
>>  .../devicetree/bindings/extcon/extcon-usb.txt      |  20 ++
>>  drivers/extcon/Kconfig                             |   7 +
>>  drivers/extcon/Makefile                            |   1 +
>>  drivers/extcon/extcon-gpio-usb.c                   | 225 +++++++++++++++++++++
>>  4 files changed, 253 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/extcon/extcon-usb.txt
>>  create mode 100644 drivers/extcon/extcon-gpio-usb.c
>>
>> diff --git a/Documentation/devicetree/bindings/extcon/extcon-usb.txt b/Documentation/devicetree/bindings/extcon/extcon-usb.txt
>> new file mode 100644
>> index 0000000..171c5a4
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/extcon/extcon-usb.txt
> 
> Need to rename from extcon-usb.txt to extcon-gpio-usb.txt.
> 
>> @@ -0,0 +1,20 @@
>> +USB 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"
> 
> I think you better use "linux,extcon-gpio-usb"
> because the point of this driver use the gpio for usb cable.

I will change all instances of "extcon-usb" to "extcon-usb-gpio".

> 
>> +- id-gpio: gpio for USB ID pin. See gpio binding.
>> +
>> +Example:
>> +	extcon_usb1 {
>> +		compatible = "linux,extcon-usb";
> 
> ditto.
> 
>> +		id-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
>> +	}
>> +
>> +	usb@1 {
>> +		...
>> +		extcon = <&extcon_usb1>;
>> +		...
>> +	};
>> diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
>> index 6a1f7de..8106a83 100644
>> --- a/drivers/extcon/Kconfig
>> +++ b/drivers/extcon/Kconfig
>> @@ -35,6 +35,13 @@ config EXTCON_GPIO
>>  	  Say Y here to enable GPIO based extcon support. Note that GPIO
>>  	  extcon supports single state per extcon instance.
>>  
>> +config EXTCON_GPIO_USB
>> +	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.
>> +
>>  config EXTCON_MAX14577
>>  	tristate "MAX14577/77836 EXTCON Support"
>>  	depends on MFD_MAX14577
>> diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
>> index 0370b42..bae594b 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_GPIO_USB)	+= extcon-gpio-usb.o
> 
> Need to re-order it alphabetically.

OK. I will change this to extcon-usb-gpio so it will remain last.
> 
>> diff --git a/drivers/extcon/extcon-gpio-usb.c b/drivers/extcon/extcon-gpio-usb.c
>> new file mode 100644
>> index 0000000..aeb2298
>> --- /dev/null
>> +++ b/drivers/extcon/extcon-gpio-usb.c
>> @@ -0,0 +1,225 @@
>> +/**
>> + * drivers/extcon/extcon_gpio_usb.c - USB GPIO extcon driver
>> + *
>> + * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
>> + *
> 
> Remove un-necessary blank line.

OK.
> 
>> + * 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/extcon/extcon-gpio.h>
> 
> Is it necessary? I think it is your mistake?

right. my bad.
> 
>> +#include <linux/gpio.h>
> 
> Don't need it because 'of_gpio.h' includes already 'gpio.h'.

agreed.

> 
>> +#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;
>> +	const char **cable_names;
>> +
>> +	info  = container_of(to_delayed_work(work), struct usb_extcon_info,
>> +			     wq_detcable);
>> +	cable_names = info->edev->supported_cable;
> 
> I think you can use 'usb_extcon_cable' instead of 'cable_names'.
> So, you will remove 'cable_names' variable.
> 
OK.

>> +
>> +	/* 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,
>> +				       cable_names[EXTCON_CABLE_USB_HOST],
>> +				       false);
>> +		extcon_set_cable_state(info->edev,
>> +				       cable_names[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,
>> +				       cable_names[EXTCON_CABLE_USB], false);
>> +		extcon_set_cable_state(info->edev,
>> +				       cable_names[EXTCON_CABLE_USB_HOST],
>> +				       true);
>> +	}
>> +}
>> +
>> +static irqreturn_t usb_irq_handler(int irq, void *dev_id)
>> +{
>> +	struct usb_extcon_info *info = dev_id;
>> +
>> +	/* debounce the GPIO via delayed work */
> 
> I think this comment is not necessary.

OK.
> 
>> +	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(struct usb_extcon_info),
> 
> sizeof(struct usb_extcon_info) -> sizeof(*info)
>
right.
 
>> +			    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,
> 
> I prefer to add IRQF_NO_SUSPEND flag because IRQF_NO_SUSPEND flag is necessary
> for wake-up from freeze pm state.

Agreed.
> 
>> +					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 allocate extcon device\n");
> 
> Wrong error information, you have to change verb (allocate -> register)

will fix.
> 
>> +		return ret;
>> +	}
>> +
>> +	platform_set_drvdata(pdev, info);
> 
> Need blank line.

OK.
> 
>> +	/* 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;
>> +
>> +	info = dev_get_drvdata(dev);
> 
> Simplify this code as following:
> 	struct usb_extcon_info *info = dev_get_drvdata(dev);

OK.
> 
>> +
>> +	if (!IS_ERR(info->id_gpiod))
> 
> I think that it is sufficient cheking without IS_ERR macro as following:
> 	if (info->id_gpiod)

I will remove this if check as we're failing probe if id_gpiod is not valid.

> 
>> +		enable_irq_wake(info->id_irq);
>> +
>> +	return 0;
>> +}
>> +
>> +static int usb_extcon_resume(struct device *dev)
>> +{
>> +	struct usb_extcon_info *info;
>> +
>> +	info = dev_get_drvdata(dev);
> 
> ditto.
> 
>> +
>> +	if (!IS_ERR(info->id_gpiod))
> 
> ditto.
> 
>> +		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", },
> 
> Change compatible name from "linux,extcon-usb", to "linux,extcon-gpio-usb".
> 

will use "linux,extcon-usb-gpio"

>> +	{ /* end */ }
>> +};
>> +
>> +static struct platform_driver usb_extcon_driver = {
>> +	.probe		= usb_extcon_probe,
>> +	.remove		= usb_extcon_remove,
>> +	.driver		= {
>> +		.name	= "extcon-usb",
>> +		.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");
>>

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] 40+ messages in thread

* Re: [PATCH 0/5] extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 USB.
  2015-01-20 19:02   ` Felipe Balbi
@ 2015-01-22 13:32     ` Roger Quadros
  -1 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-22 13:32 UTC (permalink / raw)
  To: balbi
  Cc: tony, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

Felipe,

On 20/01/15 21:02, Felipe Balbi wrote:
> On Mon, Jan 19, 2015 at 07:52:17PM +0200, Roger Quadros wrote:
>> Hi,
>>
>> On DRA7 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 and DRA72-evm.
> 
> while at that, you might want to patch X15 too.
> 
USB2 port is meant for peripheral use only. ID pin from USB port is not connected to GPIO.

cheers,
-roger

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

* Re: [PATCH 0/5] extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 USB.
@ 2015-01-22 13:32     ` Roger Quadros
  0 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-22 13:32 UTC (permalink / raw)
  To: balbi
  Cc: tony, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

Felipe,

On 20/01/15 21:02, Felipe Balbi wrote:
> On Mon, Jan 19, 2015 at 07:52:17PM +0200, Roger Quadros wrote:
>> Hi,
>>
>> On DRA7 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 and DRA72-evm.
> 
> while at that, you might want to patch X15 too.
> 
USB2 port is meant for peripheral use only. ID pin from USB port is not connected to GPIO.

cheers,
-roger

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

* Re: [PATCH 0/5] extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 USB.
  2015-01-22 13:32     ` Roger Quadros
@ 2015-01-22 14:57       ` Roger Quadros
  -1 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-22 14:57 UTC (permalink / raw)
  To: balbi
  Cc: tony, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel


On 22/01/15 15:32, Roger Quadros wrote:
> Felipe,
> 
> On 20/01/15 21:02, Felipe Balbi wrote:
>> On Mon, Jan 19, 2015 at 07:52:17PM +0200, Roger Quadros wrote:
>>> Hi,
>>>
>>> On DRA7 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 and DRA72-evm.
>>
>> while at that, you might want to patch X15 too.
>>
> USB2 port is meant for peripheral use only. ID pin from USB port is not connected to GPIO.
> 

OK answering myself here :).
Peripheral mode doesn't work on x15-bb as the USB driver (dwc3-omap)
doesn't set the mailbox correctly even when dwc3 node is set as otg = "peripheral".

Looks like we need to implement usb-gpio-extcon for x15 even though ID is hard coded.

cheers,
-roger

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

* Re: [PATCH 0/5] extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 USB.
@ 2015-01-22 14:57       ` Roger Quadros
  0 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-22 14:57 UTC (permalink / raw)
  To: balbi
  Cc: tony, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel


On 22/01/15 15:32, Roger Quadros wrote:
> Felipe,
> 
> On 20/01/15 21:02, Felipe Balbi wrote:
>> On Mon, Jan 19, 2015 at 07:52:17PM +0200, Roger Quadros wrote:
>>> Hi,
>>>
>>> On DRA7 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 and DRA72-evm.
>>
>> while at that, you might want to patch X15 too.
>>
> USB2 port is meant for peripheral use only. ID pin from USB port is not connected to GPIO.
> 

OK answering myself here :).
Peripheral mode doesn't work on x15-bb as the USB driver (dwc3-omap)
doesn't set the mailbox correctly even when dwc3 node is set as otg = "peripheral".

Looks like we need to implement usb-gpio-extcon for x15 even though ID is hard coded.

cheers,
-roger

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

* Re: [PATCH 0/5] extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 USB.
  2015-01-22 14:57       ` Roger Quadros
@ 2015-01-22 20:29         ` Felipe Balbi
  -1 siblings, 0 replies; 40+ messages in thread
From: Felipe Balbi @ 2015-01-22 20:29 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi, tony, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2585 bytes --]

On Thu, Jan 22, 2015 at 04:57:56PM +0200, Roger Quadros wrote:
> 
> On 22/01/15 15:32, Roger Quadros wrote:
> > Felipe,
> > 
> > On 20/01/15 21:02, Felipe Balbi wrote:
> >> On Mon, Jan 19, 2015 at 07:52:17PM +0200, Roger Quadros wrote:
> >>> Hi,
> >>>
> >>> On DRA7 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 and DRA72-evm.
> >>
> >> while at that, you might want to patch X15 too.
> >>
> > USB2 port is meant for peripheral use only. ID pin from USB port is not connected to GPIO.
> > 
> 
> OK answering myself here :).
> Peripheral mode doesn't work on x15-bb as the USB driver (dwc3-omap)
> doesn't set the mailbox correctly even when dwc3 node is set as otg = "peripheral".
> 
> Looks like we need to implement usb-gpio-extcon for x15 even though ID is hard coded.

right, another option is to have dwc3-omap read the child's DTS to check
dr_mode and hardcode things based on that.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 0/5] extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 USB.
@ 2015-01-22 20:29         ` Felipe Balbi
  0 siblings, 0 replies; 40+ messages in thread
From: Felipe Balbi @ 2015-01-22 20:29 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi, tony, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2585 bytes --]

On Thu, Jan 22, 2015 at 04:57:56PM +0200, Roger Quadros wrote:
> 
> On 22/01/15 15:32, Roger Quadros wrote:
> > Felipe,
> > 
> > On 20/01/15 21:02, Felipe Balbi wrote:
> >> On Mon, Jan 19, 2015 at 07:52:17PM +0200, Roger Quadros wrote:
> >>> Hi,
> >>>
> >>> On DRA7 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 and DRA72-evm.
> >>
> >> while at that, you might want to patch X15 too.
> >>
> > USB2 port is meant for peripheral use only. ID pin from USB port is not connected to GPIO.
> > 
> 
> OK answering myself here :).
> Peripheral mode doesn't work on x15-bb as the USB driver (dwc3-omap)
> doesn't set the mailbox correctly even when dwc3 node is set as otg = "peripheral".
> 
> Looks like we need to implement usb-gpio-extcon for x15 even though ID is hard coded.

right, another option is to have dwc3-omap read the child's DTS to check
dr_mode and hardcode things based on that.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

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

Felipe,

On 22/01/15 22:29, Felipe Balbi wrote:
> On Thu, Jan 22, 2015 at 04:57:56PM +0200, Roger Quadros wrote:
>>
>> On 22/01/15 15:32, Roger Quadros wrote:
>>> Felipe,
>>>
>>> On 20/01/15 21:02, Felipe Balbi wrote:
>>>> On Mon, Jan 19, 2015 at 07:52:17PM +0200, Roger Quadros wrote:
>>>>> Hi,
>>>>>
>>>>> On DRA7 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 and DRA72-evm.
>>>>
>>>> while at that, you might want to patch X15 too.
>>>>
>>> USB2 port is meant for peripheral use only. ID pin from USB port is not connected to GPIO.
>>>
>>
>> OK answering myself here :).
>> Peripheral mode doesn't work on x15-bb as the USB driver (dwc3-omap)
>> doesn't set the mailbox correctly even when dwc3 node is set as otg = "peripheral".
>>
>> Looks like we need to implement usb-gpio-extcon for x15 even though ID is hard coded.
> 
> right, another option is to have dwc3-omap read the child's DTS to check
> dr_mode and hardcode things based on that.
> 
I think that option is better as it doesn't require a GPIO line to be reserved
for ID when USB is not meant for dual-role use.

cheers,
-roger

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

* Re: [PATCH 0/5] extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 USB.
@ 2015-01-23  7:26           ` Roger Quadros
  0 siblings, 0 replies; 40+ messages in thread
From: Roger Quadros @ 2015-01-23  7:26 UTC (permalink / raw)
  To: balbi-l0cyMroinI0
  Cc: tony-4v6yS6AI5VpBDgjK7y7TUQ, myungjoo.ham-Sze3O3UU22JBDgjK7y7TUQ,
	cw00.choi-Sze3O3UU22JBDgjK7y7TUQ, george.cherian-l0cyMroinI0,
	nsekhar-l0cyMroinI0, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA,
	linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

Felipe,

On 22/01/15 22:29, Felipe Balbi wrote:
> On Thu, Jan 22, 2015 at 04:57:56PM +0200, Roger Quadros wrote:
>>
>> On 22/01/15 15:32, Roger Quadros wrote:
>>> Felipe,
>>>
>>> On 20/01/15 21:02, Felipe Balbi wrote:
>>>> On Mon, Jan 19, 2015 at 07:52:17PM +0200, Roger Quadros wrote:
>>>>> Hi,
>>>>>
>>>>> On DRA7 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 and DRA72-evm.
>>>>
>>>> while at that, you might want to patch X15 too.
>>>>
>>> USB2 port is meant for peripheral use only. ID pin from USB port is not connected to GPIO.
>>>
>>
>> OK answering myself here :).
>> Peripheral mode doesn't work on x15-bb as the USB driver (dwc3-omap)
>> doesn't set the mailbox correctly even when dwc3 node is set as otg = "peripheral".
>>
>> Looks like we need to implement usb-gpio-extcon for x15 even though ID is hard coded.
> 
> right, another option is to have dwc3-omap read the child's DTS to check
> dr_mode and hardcode things based on that.
> 
I think that option is better as it doesn't require a GPIO line to be reserved
for ID when USB is not meant for dual-role use.

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] 40+ messages in thread

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

[-- Attachment #1: Type: text/plain, Size: 3014 bytes --]

On Fri, Jan 23, 2015 at 09:26:56AM +0200, Roger Quadros wrote:
> Felipe,
> 
> On 22/01/15 22:29, Felipe Balbi wrote:
> > On Thu, Jan 22, 2015 at 04:57:56PM +0200, Roger Quadros wrote:
> >>
> >> On 22/01/15 15:32, Roger Quadros wrote:
> >>> Felipe,
> >>>
> >>> On 20/01/15 21:02, Felipe Balbi wrote:
> >>>> On Mon, Jan 19, 2015 at 07:52:17PM +0200, Roger Quadros wrote:
> >>>>> Hi,
> >>>>>
> >>>>> On DRA7 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 and DRA72-evm.
> >>>>
> >>>> while at that, you might want to patch X15 too.
> >>>>
> >>> USB2 port is meant for peripheral use only. ID pin from USB port is not connected to GPIO.
> >>>
> >>
> >> OK answering myself here :).
> >> Peripheral mode doesn't work on x15-bb as the USB driver (dwc3-omap)
> >> doesn't set the mailbox correctly even when dwc3 node is set as otg = "peripheral".
> >>
> >> Looks like we need to implement usb-gpio-extcon for x15 even though ID is hard coded.
> > 
> > right, another option is to have dwc3-omap read the child's DTS to check
> > dr_mode and hardcode things based on that.
> > 
> I think that option is better as it doesn't require a GPIO line to be
> reserved for ID when USB is not meant for dual-role use.

yeah, let's implement that for 3.21.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 0/5] extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 USB.
@ 2015-01-23 16:19             ` Felipe Balbi
  0 siblings, 0 replies; 40+ messages in thread
From: Felipe Balbi @ 2015-01-23 16:19 UTC (permalink / raw)
  To: Roger Quadros
  Cc: balbi, tony, myungjoo.ham, cw00.choi, george.cherian, nsekhar,
	devicetree, linux-usb, linux-omap, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3014 bytes --]

On Fri, Jan 23, 2015 at 09:26:56AM +0200, Roger Quadros wrote:
> Felipe,
> 
> On 22/01/15 22:29, Felipe Balbi wrote:
> > On Thu, Jan 22, 2015 at 04:57:56PM +0200, Roger Quadros wrote:
> >>
> >> On 22/01/15 15:32, Roger Quadros wrote:
> >>> Felipe,
> >>>
> >>> On 20/01/15 21:02, Felipe Balbi wrote:
> >>>> On Mon, Jan 19, 2015 at 07:52:17PM +0200, Roger Quadros wrote:
> >>>>> Hi,
> >>>>>
> >>>>> On DRA7 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 and DRA72-evm.
> >>>>
> >>>> while at that, you might want to patch X15 too.
> >>>>
> >>> USB2 port is meant for peripheral use only. ID pin from USB port is not connected to GPIO.
> >>>
> >>
> >> OK answering myself here :).
> >> Peripheral mode doesn't work on x15-bb as the USB driver (dwc3-omap)
> >> doesn't set the mailbox correctly even when dwc3 node is set as otg = "peripheral".
> >>
> >> Looks like we need to implement usb-gpio-extcon for x15 even though ID is hard coded.
> > 
> > right, another option is to have dwc3-omap read the child's DTS to check
> > dr_mode and hardcode things based on that.
> > 
> I think that option is better as it doesn't require a GPIO line to be
> reserved for ID when USB is not meant for dual-role use.

yeah, let's implement that for 3.21.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2015-01-23 16:19 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-19 17:52 [PATCH 0/5] extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 USB Roger Quadros
2015-01-19 17:52 ` Roger Quadros
2015-01-19 17:52 ` [PATCH 1/5] extcon: gpio-usb: Introduce gpio usb extcon driver Roger Quadros
2015-01-19 17:52   ` Roger Quadros
2015-01-20 19:00   ` Felipe Balbi
2015-01-20 19:00     ` Felipe Balbi
2015-01-21  5:28   ` Chanwoo Choi
2015-01-21  5:28     ` Chanwoo Choi
2015-01-22 13:27     ` Roger Quadros
2015-01-22 13:27       ` Roger Quadros
2015-01-19 17:52 ` [PATCH 2/5] usb: extcon: Fix USB-Host cable name Roger Quadros
2015-01-19 17:52   ` Roger Quadros
2015-01-20 19:01   ` Felipe Balbi
2015-01-20 19:01     ` Felipe Balbi
2015-01-19 17:52 ` [PATCH 3/5] ARM: dts: dra7-evm: Add extcon nodes for USB Roger Quadros
2015-01-19 17:52   ` Roger Quadros
2015-01-20 19:02   ` Felipe Balbi
2015-01-20 19:02     ` Felipe Balbi
2015-01-19 17:52 ` [PATCH 4/5] ARM: dts: dra72-evm: " Roger Quadros
2015-01-19 17:52   ` Roger Quadros
2015-01-20 19:02   ` Felipe Balbi
2015-01-20 19:02     ` Felipe Balbi
2015-01-19 17:52 ` [PATCH 5/5] ARM: omap2plus_defconfig: Enable PCF857X and EXTCON_GPIO_USB Roger Quadros
2015-01-19 17:52   ` Roger Quadros
2015-01-19 18:45   ` Tony Lindgren
2015-01-19 19:38     ` Tony Lindgren
2015-01-20  9:26       ` Roger Quadros
2015-01-20  9:26         ` Roger Quadros
2015-01-20 19:02 ` [PATCH 0/5] extcon: usb: Introduce USB GPIO extcon driver. Fix DRA7 USB Felipe Balbi
2015-01-20 19:02   ` Felipe Balbi
2015-01-22 13:32   ` Roger Quadros
2015-01-22 13:32     ` Roger Quadros
2015-01-22 14:57     ` Roger Quadros
2015-01-22 14:57       ` Roger Quadros
2015-01-22 20:29       ` Felipe Balbi
2015-01-22 20:29         ` Felipe Balbi
2015-01-23  7:26         ` Roger Quadros
2015-01-23  7:26           ` Roger Quadros
2015-01-23 16:19           ` Felipe Balbi
2015-01-23 16:19             ` Felipe Balbi

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.