Commit 3df03408 authored by Ludovic Desroches's avatar Ludovic Desroches Committed by Felipe Balbi

usb: gadget: udc: atmel: convert to use GPIO descriptors

Use GPIO descriptors instead of relying on the old method.
Include irq.h header since it is needed and was indirectly
included through of_gpio.h.
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarLudovic Desroches <ludovic.desroches@microchip.com>
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
parent 7c55984e
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
#include <linux/usb/atmel_usba_udc.h> #include <linux/usb/atmel_usba_udc.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_gpio.h> #include <linux/irq.h>
#include <linux/gpio/consumer.h>
#include "atmel_usba_udc.h" #include "atmel_usba_udc.h"
#define USBA_VBUS_IRQFLAGS (IRQF_ONESHOT \ #define USBA_VBUS_IRQFLAGS (IRQF_ONESHOT \
...@@ -415,8 +416,8 @@ static inline void usba_int_enb_set(struct usba_udc *udc, u32 val) ...@@ -415,8 +416,8 @@ static inline void usba_int_enb_set(struct usba_udc *udc, u32 val)
static int vbus_is_present(struct usba_udc *udc) static int vbus_is_present(struct usba_udc *udc)
{ {
if (gpio_is_valid(udc->vbus_pin)) if (udc->vbus_pin)
return gpio_get_value(udc->vbus_pin) ^ udc->vbus_pin_inverted; return gpiod_get_value(udc->vbus_pin) ^ udc->vbus_pin_inverted;
/* No Vbus detection: Assume always present */ /* No Vbus detection: Assume always present */
return 1; return 1;
...@@ -1975,8 +1976,8 @@ static int atmel_usba_start(struct usb_gadget *gadget, ...@@ -1975,8 +1976,8 @@ static int atmel_usba_start(struct usb_gadget *gadget,
mutex_lock(&udc->vbus_mutex); mutex_lock(&udc->vbus_mutex);
if (gpio_is_valid(udc->vbus_pin)) if (udc->vbus_pin)
enable_irq(gpio_to_irq(udc->vbus_pin)); enable_irq(gpiod_to_irq(udc->vbus_pin));
/* If Vbus is present, enable the controller and wait for reset */ /* If Vbus is present, enable the controller and wait for reset */
udc->vbus_prev = vbus_is_present(udc); udc->vbus_prev = vbus_is_present(udc);
...@@ -1990,8 +1991,8 @@ static int atmel_usba_start(struct usb_gadget *gadget, ...@@ -1990,8 +1991,8 @@ static int atmel_usba_start(struct usb_gadget *gadget,
return 0; return 0;
err: err:
if (gpio_is_valid(udc->vbus_pin)) if (udc->vbus_pin)
disable_irq(gpio_to_irq(udc->vbus_pin)); disable_irq(gpiod_to_irq(udc->vbus_pin));
mutex_unlock(&udc->vbus_mutex); mutex_unlock(&udc->vbus_mutex);
...@@ -2006,8 +2007,8 @@ static int atmel_usba_stop(struct usb_gadget *gadget) ...@@ -2006,8 +2007,8 @@ static int atmel_usba_stop(struct usb_gadget *gadget)
{ {
struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget); struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget);
if (gpio_is_valid(udc->vbus_pin)) if (udc->vbus_pin)
disable_irq(gpio_to_irq(udc->vbus_pin)); disable_irq(gpiod_to_irq(udc->vbus_pin));
if (fifo_mode == 0) if (fifo_mode == 0)
udc->configured_ep = 1; udc->configured_ep = 1;
...@@ -2054,7 +2055,6 @@ static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev, ...@@ -2054,7 +2055,6 @@ static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev,
{ {
u32 val; u32 val;
const char *name; const char *name;
enum of_gpio_flags flags;
struct device_node *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
const struct of_device_id *match; const struct of_device_id *match;
struct device_node *pp; struct device_node *pp;
...@@ -2074,9 +2074,9 @@ static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev, ...@@ -2074,9 +2074,9 @@ static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev,
udc->num_ep = 0; udc->num_ep = 0;
udc->vbus_pin = of_get_named_gpio_flags(np, "atmel,vbus-gpio", 0, udc->vbus_pin = devm_gpiod_get_optional(&pdev->dev, "atmel,vbus",
&flags); GPIOD_IN);
udc->vbus_pin_inverted = (flags & OF_GPIO_ACTIVE_LOW) ? 1 : 0; udc->vbus_pin_inverted = gpiod_is_active_low(udc->vbus_pin);
if (fifo_mode == 0) { if (fifo_mode == 0) {
pp = NULL; pp = NULL;
...@@ -2247,7 +2247,6 @@ static int usba_udc_probe(struct platform_device *pdev) ...@@ -2247,7 +2247,6 @@ static int usba_udc_probe(struct platform_device *pdev)
udc->pdev = pdev; udc->pdev = pdev;
udc->pclk = pclk; udc->pclk = pclk;
udc->hclk = hclk; udc->hclk = hclk;
udc->vbus_pin = -ENODEV;
platform_set_drvdata(pdev, udc); platform_set_drvdata(pdev, udc);
...@@ -2277,24 +2276,18 @@ static int usba_udc_probe(struct platform_device *pdev) ...@@ -2277,24 +2276,18 @@ static int usba_udc_probe(struct platform_device *pdev)
} }
udc->irq = irq; udc->irq = irq;
if (gpio_is_valid(udc->vbus_pin)) { if (udc->vbus_pin) {
if (!devm_gpio_request(&pdev->dev, udc->vbus_pin, "atmel_usba_udc")) { irq_set_status_flags(gpiod_to_irq(udc->vbus_pin), IRQ_NOAUTOEN);
irq_set_status_flags(gpio_to_irq(udc->vbus_pin), ret = devm_request_threaded_irq(&pdev->dev,
IRQ_NOAUTOEN); gpiod_to_irq(udc->vbus_pin), NULL,
ret = devm_request_threaded_irq(&pdev->dev,
gpio_to_irq(udc->vbus_pin), NULL,
usba_vbus_irq_thread, USBA_VBUS_IRQFLAGS, usba_vbus_irq_thread, USBA_VBUS_IRQFLAGS,
"atmel_usba_udc", udc); "atmel_usba_udc", udc);
if (ret) { if (ret) {
udc->vbus_pin = -ENODEV; udc->vbus_pin = NULL;
dev_warn(&udc->pdev->dev, dev_warn(&udc->pdev->dev,
"failed to request vbus irq; " "failed to request vbus irq; "
"assuming always on\n"); "assuming always on\n");
} }
} else {
/* gpio_request fail so use -EINVAL for gpio_is_valid */
udc->vbus_pin = -EINVAL;
}
} }
ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
...@@ -2346,9 +2339,9 @@ static int usba_udc_suspend(struct device *dev) ...@@ -2346,9 +2339,9 @@ static int usba_udc_suspend(struct device *dev)
* Device may wake up. We stay clocked if we failed * Device may wake up. We stay clocked if we failed
* to request vbus irq, assuming always on. * to request vbus irq, assuming always on.
*/ */
if (gpio_is_valid(udc->vbus_pin)) { if (udc->vbus_pin) {
usba_stop(udc); usba_stop(udc);
enable_irq_wake(gpio_to_irq(udc->vbus_pin)); enable_irq_wake(gpiod_to_irq(udc->vbus_pin));
} }
out: out:
...@@ -2364,8 +2357,8 @@ static int usba_udc_resume(struct device *dev) ...@@ -2364,8 +2357,8 @@ static int usba_udc_resume(struct device *dev)
if (!udc->driver) if (!udc->driver)
return 0; return 0;
if (device_may_wakeup(dev) && gpio_is_valid(udc->vbus_pin)) if (device_may_wakeup(dev) && udc->vbus_pin)
disable_irq_wake(gpio_to_irq(udc->vbus_pin)); disable_irq_wake(gpiod_to_irq(udc->vbus_pin));
/* If Vbus is present, enable the controller and wait for reset */ /* If Vbus is present, enable the controller and wait for reset */
mutex_lock(&udc->vbus_mutex); mutex_lock(&udc->vbus_mutex);
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#ifndef __LINUX_USB_GADGET_USBA_UDC_H__ #ifndef __LINUX_USB_GADGET_USBA_UDC_H__
#define __LINUX_USB_GADGET_USBA_UDC_H__ #define __LINUX_USB_GADGET_USBA_UDC_H__
#include <linux/gpio/consumer.h>
/* USB register offsets */ /* USB register offsets */
#define USBA_CTRL 0x0000 #define USBA_CTRL 0x0000
#define USBA_FNUM 0x0004 #define USBA_FNUM 0x0004
...@@ -323,7 +325,7 @@ struct usba_udc { ...@@ -323,7 +325,7 @@ struct usba_udc {
struct platform_device *pdev; struct platform_device *pdev;
const struct usba_udc_errata *errata; const struct usba_udc_errata *errata;
int irq; int irq;
int vbus_pin; struct gpio_desc *vbus_pin;
int vbus_pin_inverted; int vbus_pin_inverted;
int num_ep; int num_ep;
int configured_ep; int configured_ep;
......
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