diff options
Diffstat (limited to 'drivers/usb/phy/phy-gpio-vbus-usb.c')
-rw-r--r-- | drivers/usb/phy/phy-gpio-vbus-usb.c | 96 |
1 files changed, 43 insertions, 53 deletions
diff --git a/drivers/usb/phy/phy-gpio-vbus-usb.c b/drivers/usb/phy/phy-gpio-vbus-usb.c index 553e2573c74f..f13f5530746c 100644 --- a/drivers/usb/phy/phy-gpio-vbus-usb.c +++ b/drivers/usb/phy/phy-gpio-vbus-usb.c @@ -7,7 +7,7 @@ #include <linux/kernel.h> #include <linux/platform_device.h> -#include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/interrupt.h> @@ -17,7 +17,6 @@ #include <linux/regulator/consumer.h> #include <linux/usb/gadget.h> -#include <linux/usb/gpio_vbus.h> #include <linux/usb/otg.h> @@ -29,6 +28,8 @@ * Needs to be loaded before the UDC driver that will use it. */ struct gpio_vbus_data { + struct gpio_desc *vbus_gpiod; + struct gpio_desc *pullup_gpiod; struct usb_phy phy; struct device *dev; struct regulator *vbus_draw; @@ -83,38 +84,30 @@ static void set_vbus_draw(struct gpio_vbus_data *gpio_vbus, unsigned mA) gpio_vbus->mA = mA; } -static int is_vbus_powered(struct gpio_vbus_mach_info *pdata) +static int is_vbus_powered(struct gpio_vbus_data *gpio_vbus) { - int vbus; - - vbus = gpio_get_value(pdata->gpio_vbus); - if (pdata->gpio_vbus_inverted) - vbus = !vbus; - - return vbus; + return gpiod_get_value(gpio_vbus->vbus_gpiod); } static void gpio_vbus_work(struct work_struct *work) { struct gpio_vbus_data *gpio_vbus = container_of(work, struct gpio_vbus_data, work.work); - struct gpio_vbus_mach_info *pdata = dev_get_platdata(gpio_vbus->dev); - int gpio, status, vbus; + int status, vbus; if (!gpio_vbus->phy.otg->gadget) return; - vbus = is_vbus_powered(pdata); + vbus = is_vbus_powered(gpio_vbus); if ((vbus ^ gpio_vbus->vbus) == 0) return; gpio_vbus->vbus = vbus; /* Peripheral controllers which manage the pullup themselves won't have - * gpio_pullup configured here. If it's configured here, we'll do what - * isp1301_omap::b_peripheral() does and enable the pullup here... although - * that may complicate usb_gadget_{,dis}connect() support. + * a pullup GPIO configured here. If it's configured here, we'll do + * what isp1301_omap::b_peripheral() does and enable the pullup here... + * although that may complicate usb_gadget_{,dis}connect() support. */ - gpio = pdata->gpio_pullup; if (vbus) { status = USB_EVENT_VBUS; @@ -126,16 +119,16 @@ static void gpio_vbus_work(struct work_struct *work) set_vbus_draw(gpio_vbus, 100); /* optionally enable D+ pullup */ - if (gpio_is_valid(gpio)) - gpio_set_value(gpio, !pdata->gpio_pullup_inverted); + if (gpio_vbus->pullup_gpiod) + gpiod_set_value(gpio_vbus->pullup_gpiod, 1); atomic_notifier_call_chain(&gpio_vbus->phy.notifier, status, gpio_vbus->phy.otg->gadget); usb_phy_set_event(&gpio_vbus->phy, USB_EVENT_ENUMERATED); } else { /* optionally disable D+ pullup */ - if (gpio_is_valid(gpio)) - gpio_set_value(gpio, pdata->gpio_pullup_inverted); + if (gpio_vbus->pullup_gpiod) + gpiod_set_value(gpio_vbus->pullup_gpiod, 0); set_vbus_draw(gpio_vbus, 0); @@ -154,12 +147,11 @@ static void gpio_vbus_work(struct work_struct *work) static irqreturn_t gpio_vbus_irq(int irq, void *data) { struct platform_device *pdev = data; - struct gpio_vbus_mach_info *pdata = dev_get_platdata(&pdev->dev); struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev); struct usb_otg *otg = gpio_vbus->phy.otg; dev_dbg(&pdev->dev, "VBUS %s (gadget: %s)\n", - is_vbus_powered(pdata) ? "supplied" : "inactive", + is_vbus_powered(gpio_vbus) ? "supplied" : "inactive", otg->gadget ? otg->gadget->name : "none"); if (otg->gadget) @@ -175,22 +167,18 @@ static int gpio_vbus_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) { struct gpio_vbus_data *gpio_vbus; - struct gpio_vbus_mach_info *pdata; struct platform_device *pdev; - int gpio; gpio_vbus = container_of(otg->usb_phy, struct gpio_vbus_data, phy); pdev = to_platform_device(gpio_vbus->dev); - pdata = dev_get_platdata(gpio_vbus->dev); - gpio = pdata->gpio_pullup; if (!gadget) { dev_dbg(&pdev->dev, "unregistering gadget '%s'\n", otg->gadget->name); /* optionally disable D+ pullup */ - if (gpio_is_valid(gpio)) - gpio_set_value(gpio, pdata->gpio_pullup_inverted); + if (gpio_vbus->pullup_gpiod) + gpiod_set_value(gpio_vbus->pullup_gpiod, 0); set_vbus_draw(gpio_vbus, 0); @@ -242,16 +230,12 @@ static int gpio_vbus_set_suspend(struct usb_phy *phy, int suspend) static int gpio_vbus_probe(struct platform_device *pdev) { - struct gpio_vbus_mach_info *pdata = dev_get_platdata(&pdev->dev); struct gpio_vbus_data *gpio_vbus; struct resource *res; - int err, gpio, irq; + struct device *dev = &pdev->dev; + int err, irq; unsigned long irqflags; - if (!pdata || !gpio_is_valid(pdata->gpio_vbus)) - return -EINVAL; - gpio = pdata->gpio_vbus; - gpio_vbus = devm_kzalloc(&pdev->dev, sizeof(struct gpio_vbus_data), GFP_KERNEL); if (!gpio_vbus) @@ -273,37 +257,43 @@ static int gpio_vbus_probe(struct platform_device *pdev) gpio_vbus->phy.otg->usb_phy = &gpio_vbus->phy; gpio_vbus->phy.otg->set_peripheral = gpio_vbus_set_peripheral; - err = devm_gpio_request(&pdev->dev, gpio, "vbus_detect"); - if (err) { - dev_err(&pdev->dev, "can't request vbus gpio %d, err: %d\n", - gpio, err); + /* Look up the VBUS sensing GPIO */ + gpio_vbus->vbus_gpiod = devm_gpiod_get(dev, "vbus", GPIOD_IN); + if (IS_ERR(gpio_vbus->vbus_gpiod)) { + err = PTR_ERR(gpio_vbus->vbus_gpiod); + dev_err(&pdev->dev, "can't request vbus gpio, err: %d\n", err); return err; } - gpio_direction_input(gpio); + gpiod_set_consumer_name(gpio_vbus->vbus_gpiod, "vbus_detect"); res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (res) { irq = res->start; irqflags = (res->flags & IRQF_TRIGGER_MASK) | IRQF_SHARED; } else { - irq = gpio_to_irq(gpio); + irq = gpiod_to_irq(gpio_vbus->vbus_gpiod); 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; - if (gpio_is_valid(gpio)) { - err = devm_gpio_request(&pdev->dev, gpio, "udc_pullup"); - if (err) { - dev_err(&pdev->dev, - "can't request pullup gpio %d, err: %d\n", - gpio, err); - return err; - } - gpio_direction_output(gpio, pdata->gpio_pullup_inverted); + /* + * 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 + * value the GPIO detects as active. Some systems will use comparators. + * Get the optional D+ or D- pullup GPIO. If the data line pullup is + * in use, initialize it to "not pulling up" + */ + gpio_vbus->pullup_gpiod = devm_gpiod_get_optional(dev, "pullup", + GPIOD_OUT_LOW); + if (IS_ERR(gpio_vbus->pullup_gpiod)) { + err = PTR_ERR(gpio_vbus->pullup_gpiod); + dev_err(&pdev->dev, "can't request pullup gpio, err: %d\n", + err); + return err; } + if (gpio_vbus->pullup_gpiod) + gpiod_set_consumer_name(gpio_vbus->pullup_gpiod, "udc_pullup"); err = devm_request_irq(&pdev->dev, irq, gpio_vbus_irq, irqflags, "vbus_detect", pdev); @@ -330,7 +320,7 @@ static int gpio_vbus_probe(struct platform_device *pdev) return err; } - device_init_wakeup(&pdev->dev, pdata->wakeup); + /* TODO: wakeup could be enabled here with device_init_wakeup(dev, 1) */ return 0; } |