Commit 75e9ebec authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

Merge tag 'extcon-next-for-4.10' of...

Merge tag 'extcon-next-for-4.10' of git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon into usb-nextx

Chanwoo writes:

Update extcon for 4.10

Detailed description for this pull request:
- The extcon-usb-gpio driver supports the VBUS detection with USB ID and VBUS pin.
parents cdefb95b 541332a1
...@@ -5,7 +5,10 @@ connected to a GPIO pin. ...@@ -5,7 +5,10 @@ connected to a GPIO pin.
Required properties: Required properties:
- compatible: Should be "linux,extcon-usb-gpio" - compatible: Should be "linux,extcon-usb-gpio"
Either one of id-gpio or vbus-gpio must be present. Both can be present as well.
- id-gpio: gpio for USB ID pin. See gpio binding. - id-gpio: gpio for USB ID pin. See gpio binding.
- vbus-gpio: gpio for USB VBUS pin.
Example: Examples of extcon-usb-gpio node in dra7-evm.dts as listed below: Example: Examples of extcon-usb-gpio node in dra7-evm.dts as listed below:
extcon_usb1 { extcon_usb1 {
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_gpio.h> #include <linux/of_gpio.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/pm_wakeirq.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/acpi.h> #include <linux/acpi.h>
...@@ -36,7 +35,9 @@ struct usb_extcon_info { ...@@ -36,7 +35,9 @@ struct usb_extcon_info {
struct extcon_dev *edev; struct extcon_dev *edev;
struct gpio_desc *id_gpiod; struct gpio_desc *id_gpiod;
struct gpio_desc *vbus_gpiod;
int id_irq; int id_irq;
int vbus_irq;
unsigned long debounce_jiffies; unsigned long debounce_jiffies;
struct delayed_work wq_detcable; struct delayed_work wq_detcable;
...@@ -48,31 +49,47 @@ static const unsigned int usb_extcon_cable[] = { ...@@ -48,31 +49,47 @@ static const unsigned int usb_extcon_cable[] = {
EXTCON_NONE, EXTCON_NONE,
}; };
/*
* "USB" = VBUS and "USB-HOST" = !ID, so we have:
* Both "USB" and "USB-HOST" can't be set as active at the
* same time so if "USB-HOST" is active (i.e. ID is 0) we keep "USB" inactive
* even if VBUS is on.
*
* State | ID | VBUS
* ----------------------------------------
* [1] USB | H | H
* [2] none | H | L
* [3] USB-HOST | L | H
* [4] USB-HOST | L | L
*
* In case we have only one of these signals:
* - VBUS only - we want to distinguish between [1] and [2], so ID is always 1.
* - ID only - we want to distinguish between [1] and [4], so VBUS = ID.
*/
static void usb_extcon_detect_cable(struct work_struct *work) static void usb_extcon_detect_cable(struct work_struct *work)
{ {
int id; int id, vbus;
struct usb_extcon_info *info = container_of(to_delayed_work(work), struct usb_extcon_info *info = container_of(to_delayed_work(work),
struct usb_extcon_info, struct usb_extcon_info,
wq_detcable); wq_detcable);
/* check ID and update cable state */ /* check ID and VBUS and update cable state */
id = gpiod_get_value_cansleep(info->id_gpiod); id = info->id_gpiod ?
if (id) { gpiod_get_value_cansleep(info->id_gpiod) : 1;
/* vbus = info->vbus_gpiod ?
* ID = 1 means USB HOST cable detached. gpiod_get_value_cansleep(info->vbus_gpiod) : id;
* As we don't have event for USB peripheral cable attached,
* we simulate USB peripheral attach here. /* at first we clean states which are no longer active */
*/ if (id)
extcon_set_state_sync(info->edev, EXTCON_USB_HOST, false); extcon_set_state_sync(info->edev, EXTCON_USB_HOST, false);
extcon_set_state_sync(info->edev, EXTCON_USB, true); if (!vbus)
} 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_state_sync(info->edev, EXTCON_USB, false); extcon_set_state_sync(info->edev, EXTCON_USB, false);
if (!id) {
extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true); extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true);
} else {
if (vbus)
extcon_set_state_sync(info->edev, EXTCON_USB, true);
} }
} }
...@@ -101,12 +118,21 @@ static int usb_extcon_probe(struct platform_device *pdev) ...@@ -101,12 +118,21 @@ static int usb_extcon_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
info->dev = dev; info->dev = dev;
info->id_gpiod = devm_gpiod_get(&pdev->dev, "id", GPIOD_IN); info->id_gpiod = devm_gpiod_get_optional(&pdev->dev, "id", GPIOD_IN);
if (IS_ERR(info->id_gpiod)) { info->vbus_gpiod = devm_gpiod_get_optional(&pdev->dev, "vbus",
dev_err(dev, "failed to get ID GPIO\n"); GPIOD_IN);
return PTR_ERR(info->id_gpiod);
if (!info->id_gpiod && !info->vbus_gpiod) {
dev_err(dev, "failed to get gpios\n");
return -ENODEV;
} }
if (IS_ERR(info->id_gpiod))
return PTR_ERR(info->id_gpiod);
if (IS_ERR(info->vbus_gpiod))
return PTR_ERR(info->vbus_gpiod);
info->edev = devm_extcon_dev_allocate(dev, usb_extcon_cable); info->edev = devm_extcon_dev_allocate(dev, usb_extcon_cable);
if (IS_ERR(info->edev)) { if (IS_ERR(info->edev)) {
dev_err(dev, "failed to allocate extcon device\n"); dev_err(dev, "failed to allocate extcon device\n");
...@@ -119,13 +145,19 @@ static int usb_extcon_probe(struct platform_device *pdev) ...@@ -119,13 +145,19 @@ static int usb_extcon_probe(struct platform_device *pdev)
return ret; return ret;
} }
if (info->id_gpiod)
ret = gpiod_set_debounce(info->id_gpiod, ret = gpiod_set_debounce(info->id_gpiod,
USB_GPIO_DEBOUNCE_MS * 1000); USB_GPIO_DEBOUNCE_MS * 1000);
if (!ret && info->vbus_gpiod)
ret = gpiod_set_debounce(info->vbus_gpiod,
USB_GPIO_DEBOUNCE_MS * 1000);
if (ret < 0) if (ret < 0)
info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEBOUNCE_MS); info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEBOUNCE_MS);
INIT_DELAYED_WORK(&info->wq_detcable, usb_extcon_detect_cable); INIT_DELAYED_WORK(&info->wq_detcable, usb_extcon_detect_cable);
if (info->id_gpiod) {
info->id_irq = gpiod_to_irq(info->id_gpiod); info->id_irq = gpiod_to_irq(info->id_gpiod);
if (info->id_irq < 0) { if (info->id_irq < 0) {
dev_err(dev, "failed to get ID IRQ\n"); dev_err(dev, "failed to get ID IRQ\n");
...@@ -141,10 +173,28 @@ static int usb_extcon_probe(struct platform_device *pdev) ...@@ -141,10 +173,28 @@ static int usb_extcon_probe(struct platform_device *pdev)
dev_err(dev, "failed to request handler for ID IRQ\n"); dev_err(dev, "failed to request handler for ID IRQ\n");
return ret; return ret;
} }
}
if (info->vbus_gpiod) {
info->vbus_irq = gpiod_to_irq(info->vbus_gpiod);
if (info->vbus_irq < 0) {
dev_err(dev, "failed to get VBUS IRQ\n");
return info->vbus_irq;
}
ret = devm_request_threaded_irq(dev, info->vbus_irq, NULL,
usb_irq_handler,
IRQF_TRIGGER_RISING |
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
pdev->name, info);
if (ret < 0) {
dev_err(dev, "failed to request handler for VBUS IRQ\n");
return ret;
}
}
platform_set_drvdata(pdev, info); platform_set_drvdata(pdev, info);
device_init_wakeup(dev, true); device_init_wakeup(dev, true);
dev_pm_set_wake_irq(dev, info->id_irq);
/* Perform initial detection */ /* Perform initial detection */
usb_extcon_detect_cable(&info->wq_detcable.work); usb_extcon_detect_cable(&info->wq_detcable.work);
...@@ -157,8 +207,6 @@ static int usb_extcon_remove(struct platform_device *pdev) ...@@ -157,8 +207,6 @@ static int usb_extcon_remove(struct platform_device *pdev)
struct usb_extcon_info *info = platform_get_drvdata(pdev); struct usb_extcon_info *info = platform_get_drvdata(pdev);
cancel_delayed_work_sync(&info->wq_detcable); cancel_delayed_work_sync(&info->wq_detcable);
dev_pm_clear_wake_irq(&pdev->dev);
device_init_wakeup(&pdev->dev, false); device_init_wakeup(&pdev->dev, false);
return 0; return 0;
...@@ -170,12 +218,32 @@ static int usb_extcon_suspend(struct device *dev) ...@@ -170,12 +218,32 @@ static int usb_extcon_suspend(struct device *dev)
struct usb_extcon_info *info = dev_get_drvdata(dev); struct usb_extcon_info *info = dev_get_drvdata(dev);
int ret = 0; int ret = 0;
if (device_may_wakeup(dev)) {
if (info->id_gpiod) {
ret = enable_irq_wake(info->id_irq);
if (ret)
return ret;
}
if (info->vbus_gpiod) {
ret = enable_irq_wake(info->vbus_irq);
if (ret) {
if (info->id_gpiod)
disable_irq_wake(info->id_irq);
return ret;
}
}
}
/* /*
* We don't want to process any IRQs after this point * We don't want to process any IRQs after this point
* as GPIOs used behind I2C subsystem might not be * as GPIOs used behind I2C subsystem might not be
* accessible until resume completes. So disable IRQ. * accessible until resume completes. So disable IRQ.
*/ */
if (info->id_gpiod)
disable_irq(info->id_irq); disable_irq(info->id_irq);
if (info->vbus_gpiod)
disable_irq(info->vbus_irq);
return ret; return ret;
} }
...@@ -185,7 +253,28 @@ static int usb_extcon_resume(struct device *dev) ...@@ -185,7 +253,28 @@ static int usb_extcon_resume(struct device *dev)
struct usb_extcon_info *info = dev_get_drvdata(dev); struct usb_extcon_info *info = dev_get_drvdata(dev);
int ret = 0; int ret = 0;
if (device_may_wakeup(dev)) {
if (info->id_gpiod) {
ret = disable_irq_wake(info->id_irq);
if (ret)
return ret;
}
if (info->vbus_gpiod) {
ret = disable_irq_wake(info->vbus_irq);
if (ret) {
if (info->id_gpiod)
enable_irq_wake(info->id_irq);
return ret;
}
}
}
if (info->id_gpiod)
enable_irq(info->id_irq); enable_irq(info->id_irq);
if (info->vbus_gpiod)
enable_irq(info->vbus_irq);
if (!device_may_wakeup(dev)) if (!device_may_wakeup(dev))
queue_delayed_work(system_power_efficient_wq, queue_delayed_work(system_power_efficient_wq,
&info->wq_detcable, 0); &info->wq_detcable, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment