Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 304001
b: refs/heads/master
c: f06b9f3
h: refs/heads/master
i:
  303999: fb42631
v: v3
  • Loading branch information
Greg Kroah-Hartman committed May 18, 2012
1 parent 2de1dd4 commit 6d58d5a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 14 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e1f12eb6ba6f1e74007eb01ed26fad7c5239d62b
refs/heads/master: f06b9f3ced17dfb559af2c0c5db2d68e939f06e6
58 changes: 47 additions & 11 deletions trunk/drivers/usb/otg/gpio_vbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct gpio_vbus_data {
unsigned mA;
struct delayed_work work;
int vbus;
int irq;
};


Expand All @@ -52,8 +53,7 @@ struct gpio_vbus_data {
* edges might be workable.
*/
#define VBUS_IRQ_FLAGS \
( IRQF_SAMPLE_RANDOM | IRQF_SHARED \
| IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING )
(IRQF_SHARED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)


/* interface to regulator framework */
Expand Down Expand Up @@ -173,12 +173,11 @@ static int gpio_vbus_set_peripheral(struct usb_otg *otg,
struct gpio_vbus_data *gpio_vbus;
struct gpio_vbus_mach_info *pdata;
struct platform_device *pdev;
int gpio, irq;
int gpio;

gpio_vbus = container_of(otg->phy, struct gpio_vbus_data, phy);
pdev = to_platform_device(gpio_vbus->dev);
pdata = gpio_vbus->dev->platform_data;
irq = gpio_to_irq(pdata->gpio_vbus);
gpio = pdata->gpio_pullup;

if (!gadget) {
Expand All @@ -203,7 +202,7 @@ static int gpio_vbus_set_peripheral(struct usb_otg *otg,

/* initialize connection state */
gpio_vbus->vbus = 0; /* start with disconnected */
gpio_vbus_irq(irq, pdev);
gpio_vbus_irq(gpio_vbus->irq, pdev);
return 0;
}

Expand Down Expand Up @@ -243,6 +242,7 @@ static int __init gpio_vbus_probe(struct platform_device *pdev)
struct gpio_vbus_data *gpio_vbus;
struct resource *res;
int err, gpio, irq;
unsigned long irqflags;

if (!pdata || !gpio_is_valid(pdata->gpio_vbus))
return -EINVAL;
Expand Down Expand Up @@ -279,10 +279,13 @@ static int __init gpio_vbus_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (res) {
irq = res->start;
res->flags &= IRQF_TRIGGER_MASK;
res->flags |= IRQF_SAMPLE_RANDOM | IRQF_SHARED;
} else
irqflags = (res->flags & IRQF_TRIGGER_MASK) | IRQF_SHARED;
} else {
irq = gpio_to_irq(gpio);
irqflags = VBUS_IRQ_FLAGS;
}

gpio_vbus->irq = irq;

/* if data line pullup is in use, initialize it to "not pulling up" */
gpio = pdata->gpio_pullup;
Expand All @@ -298,8 +301,7 @@ static int __init gpio_vbus_probe(struct platform_device *pdev)
gpio_direction_output(gpio, pdata->gpio_pullup_inverted);
}

err = request_irq(irq, gpio_vbus_irq, VBUS_IRQ_FLAGS,
"vbus_detect", pdev);
err = request_irq(irq, gpio_vbus_irq, irqflags, "vbus_detect", pdev);
if (err) {
dev_err(&pdev->dev, "can't request irq %i, err: %d\n",
irq, err);
Expand All @@ -325,6 +327,8 @@ static int __init gpio_vbus_probe(struct platform_device *pdev)
goto err_otg;
}

device_init_wakeup(&pdev->dev, pdata->wakeup);

return 0;
err_otg:
regulator_put(gpio_vbus->vbus_draw);
Expand All @@ -346,11 +350,13 @@ static int __exit gpio_vbus_remove(struct platform_device *pdev)
struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data;
int gpio = pdata->gpio_vbus;

device_init_wakeup(&pdev->dev, 0);
cancel_delayed_work_sync(&gpio_vbus->work);
regulator_put(gpio_vbus->vbus_draw);

usb_set_transceiver(NULL);

free_irq(gpio_to_irq(gpio), pdev);
free_irq(gpio_vbus->irq, pdev);
if (gpio_is_valid(pdata->gpio_pullup))
gpio_free(pdata->gpio_pullup);
gpio_free(gpio);
Expand All @@ -361,6 +367,33 @@ static int __exit gpio_vbus_remove(struct platform_device *pdev)
return 0;
}

#ifdef CONFIG_PM
static int gpio_vbus_pm_suspend(struct device *dev)
{
struct gpio_vbus_data *gpio_vbus = dev_get_drvdata(dev);

if (device_may_wakeup(dev))
enable_irq_wake(gpio_vbus->irq);

return 0;
}

static int gpio_vbus_pm_resume(struct device *dev)
{
struct gpio_vbus_data *gpio_vbus = dev_get_drvdata(dev);

if (device_may_wakeup(dev))
disable_irq_wake(gpio_vbus->irq);

return 0;
}

static const struct dev_pm_ops gpio_vbus_dev_pm_ops = {
.suspend = gpio_vbus_pm_suspend,
.resume = gpio_vbus_pm_resume,
};
#endif

/* NOTE: the gpio-vbus device may *NOT* be hotplugged */

MODULE_ALIAS("platform:gpio-vbus");
Expand All @@ -369,6 +402,9 @@ static struct platform_driver gpio_vbus_driver = {
.driver = {
.name = "gpio-vbus",
.owner = THIS_MODULE,
#ifdef CONFIG_PM
.pm = &gpio_vbus_dev_pm_ops,
#endif
},
.remove = __exit_p(gpio_vbus_remove),
};
Expand Down
4 changes: 2 additions & 2 deletions trunk/drivers/usb/otg/twl6030-usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)

twl->irq_enabled = true;
status = request_threaded_irq(twl->irq1, NULL, twl6030_usbotg_irq,
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT,
"twl6030_usb", twl);
if (status < 0) {
dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
Expand All @@ -467,7 +467,7 @@ static int __devinit twl6030_usb_probe(struct platform_device *pdev)
}

status = request_threaded_irq(twl->irq2, NULL, twl6030_usb_irq,
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT,
"twl6030_usb", twl);
if (status < 0) {
dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
Expand Down
2 changes: 2 additions & 0 deletions trunk/include/linux/usb/gpio_vbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @gpio_pullup: optional D+ or D- pullup GPIO (else negative/invalid)
* @gpio_vbus_inverted: true if gpio_vbus is active low
* @gpio_pullup_inverted: true if gpio_pullup is active low
* @wakeup: configure gpio_vbus as a wake-up source
*
* The VBUS sensing GPIO should have a pulldown, which will normally be
* part of a resistor ladder turning a 4.0V-5.25V level on VBUS into a
Expand All @@ -27,4 +28,5 @@ struct gpio_vbus_mach_info {
int gpio_pullup;
bool gpio_vbus_inverted;
bool gpio_pullup_inverted;
bool wakeup;
};

0 comments on commit 6d58d5a

Please sign in to comment.