Skip to content

Commit 054d4b7

Browse files
wenyouyagregkh
authored andcommitted
usb: ohci-at91: Use descriptor-based gpio APIs
Use the descriptor-based interface to manipulate GPIOs, instead of the legacy integer-based interface. Signed-off-by: Wenyou Yang <wenyou.yang@atmel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 629dd21 commit 054d4b7

File tree

1 file changed

+31
-90
lines changed

1 file changed

+31
-90
lines changed

drivers/usb/host/ohci-at91.c

Lines changed: 31 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
#include <linux/clk.h>
1616
#include <linux/dma-mapping.h>
17+
#include <linux/gpio/consumer.h>
1718
#include <linux/of_platform.h>
18-
#include <linux/of_gpio.h>
1919
#include <linux/platform_device.h>
2020
#include <linux/platform_data/atmel.h>
2121
#include <linux/io.h>
@@ -39,8 +39,8 @@
3939

4040
#define AT91_MAX_USBH_PORTS 3
4141
struct at91_usbh_data {
42-
int vbus_pin[AT91_MAX_USBH_PORTS]; /* port power-control pin */
43-
int overcurrent_pin[AT91_MAX_USBH_PORTS];
42+
struct gpio_desc *vbus_pin[AT91_MAX_USBH_PORTS];
43+
struct gpio_desc *overcurrent_pin[AT91_MAX_USBH_PORTS];
4444
u8 ports; /* number of ports on root hub */
4545
u8 overcurrent_supported;
4646
u8 vbus_pin_active_low[AT91_MAX_USBH_PORTS];
@@ -262,23 +262,17 @@ static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int
262262
if (!valid_port(port))
263263
return;
264264

265-
if (!gpio_is_valid(pdata->vbus_pin[port]))
266-
return;
267-
268-
gpio_set_value(pdata->vbus_pin[port],
269-
pdata->vbus_pin_active_low[port] ^ enable);
265+
gpiod_set_value(pdata->vbus_pin[port],
266+
pdata->vbus_pin_active_low[port] ^ enable);
270267
}
271268

272269
static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
273270
{
274271
if (!valid_port(port))
275272
return -EINVAL;
276273

277-
if (!gpio_is_valid(pdata->vbus_pin[port]))
278-
return -EINVAL;
279-
280-
return gpio_get_value(pdata->vbus_pin[port]) ^
281-
pdata->vbus_pin_active_low[port];
274+
return gpiod_get_value(pdata->vbus_pin[port]) ^
275+
pdata->vbus_pin_active_low[port];
282276
}
283277

284278
/*
@@ -468,24 +462,21 @@ static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
468462
{
469463
struct platform_device *pdev = data;
470464
struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev);
471-
int val, gpio, port;
465+
int val, port;
472466

473467
/* From the GPIO notifying the over-current situation, find
474468
* out the corresponding port */
475469
at91_for_each_port(port) {
476-
if (gpio_is_valid(pdata->overcurrent_pin[port]) &&
477-
gpio_to_irq(pdata->overcurrent_pin[port]) == irq) {
478-
gpio = pdata->overcurrent_pin[port];
470+
if (gpiod_to_irq(pdata->overcurrent_pin[port]) == irq)
479471
break;
480-
}
481472
}
482473

483474
if (port == AT91_MAX_USBH_PORTS) {
484475
dev_err(& pdev->dev, "overcurrent interrupt from unknown GPIO\n");
485476
return IRQ_HANDLED;
486477
}
487478

488-
val = gpio_get_value(gpio);
479+
val = gpiod_get_value(pdata->overcurrent_pin[port]);
489480

490481
/* When notified of an over-current situation, disable power
491482
on the corresponding port, and mark this port in
@@ -516,9 +507,8 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
516507
struct device_node *np = pdev->dev.of_node;
517508
struct at91_usbh_data *pdata;
518509
int i;
519-
int gpio;
520510
int ret;
521-
enum of_gpio_flags flags;
511+
int err;
522512
u32 ports;
523513

524514
/* Right now device-tree probed devices don't get dma_mask set.
@@ -539,38 +529,16 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
539529
pdata->ports = ports;
540530

541531
at91_for_each_port(i) {
542-
/*
543-
* do not configure PIO if not in relation with
544-
* real USB port on board
545-
*/
546-
if (i >= pdata->ports) {
547-
pdata->vbus_pin[i] = -EINVAL;
548-
pdata->overcurrent_pin[i] = -EINVAL;
532+
pdata->vbus_pin[i] = devm_gpiod_get_optional(&pdev->dev,
533+
"atmel,vbus-gpio",
534+
GPIOD_IN);
535+
if (IS_ERR(pdata->vbus_pin[i])) {
536+
err = PTR_ERR(pdata->vbus_pin[i]);
537+
dev_err(&pdev->dev, "unable to claim gpio \"vbus\": %d\n", err);
549538
continue;
550539
}
551540

552-
gpio = of_get_named_gpio_flags(np, "atmel,vbus-gpio", i,
553-
&flags);
554-
pdata->vbus_pin[i] = gpio;
555-
if (!gpio_is_valid(gpio))
556-
continue;
557-
pdata->vbus_pin_active_low[i] = flags & OF_GPIO_ACTIVE_LOW;
558-
559-
ret = gpio_request(gpio, "ohci_vbus");
560-
if (ret) {
561-
dev_err(&pdev->dev,
562-
"can't request vbus gpio %d\n", gpio);
563-
continue;
564-
}
565-
ret = gpio_direction_output(gpio,
566-
!pdata->vbus_pin_active_low[i]);
567-
if (ret) {
568-
dev_err(&pdev->dev,
569-
"can't put vbus gpio %d as output %d\n",
570-
gpio, !pdata->vbus_pin_active_low[i]);
571-
gpio_free(gpio);
572-
continue;
573-
}
541+
pdata->vbus_pin_active_low[i] = gpiod_get_value(pdata->vbus_pin[i]);
574542

575543
ohci_at91_usb_set_power(pdata, i, 1);
576544
}
@@ -580,37 +548,21 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
580548
break;
581549

582550
pdata->overcurrent_pin[i] =
583-
of_get_named_gpio_flags(np, "atmel,oc-gpio", i, &flags);
584-
585-
if (!gpio_is_valid(pdata->overcurrent_pin[i]))
586-
continue;
587-
gpio = pdata->overcurrent_pin[i];
588-
589-
ret = gpio_request(gpio, "ohci_overcurrent");
590-
if (ret) {
591-
dev_err(&pdev->dev,
592-
"can't request overcurrent gpio %d\n",
593-
gpio);
551+
devm_gpiod_get_optional(&pdev->dev,
552+
"atmel,oc-gpio", GPIOD_IN);
553+
if (IS_ERR(pdata->overcurrent_pin[i])) {
554+
err = PTR_ERR(pdata->overcurrent_pin[i]);
555+
dev_err(&pdev->dev, "unable to claim gpio \"overcurrent\": %d\n", err);
594556
continue;
595557
}
596558

597-
ret = gpio_direction_input(gpio);
598-
if (ret) {
599-
dev_err(&pdev->dev,
600-
"can't configure overcurrent gpio %d as input\n",
601-
gpio);
602-
gpio_free(gpio);
603-
continue;
604-
}
605-
606-
ret = request_irq(gpio_to_irq(gpio),
607-
ohci_hcd_at91_overcurrent_irq,
608-
IRQF_SHARED, "ohci_overcurrent", pdev);
609-
if (ret) {
610-
gpio_free(gpio);
611-
dev_err(&pdev->dev,
612-
"can't get gpio IRQ for overcurrent\n");
613-
}
559+
ret = devm_request_irq(&pdev->dev,
560+
gpiod_to_irq(pdata->overcurrent_pin[i]),
561+
ohci_hcd_at91_overcurrent_irq,
562+
IRQF_SHARED,
563+
"ohci_overcurrent", pdev);
564+
if (ret)
565+
dev_info(&pdev->dev, "failed to request gpio \"overcurrent\" IRQ\n");
614566
}
615567

616568
device_init_wakeup(&pdev->dev, 1);
@@ -623,19 +575,8 @@ static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
623575
int i;
624576

625577
if (pdata) {
626-
at91_for_each_port(i) {
627-
if (!gpio_is_valid(pdata->vbus_pin[i]))
628-
continue;
578+
at91_for_each_port(i)
629579
ohci_at91_usb_set_power(pdata, i, 0);
630-
gpio_free(pdata->vbus_pin[i]);
631-
}
632-
633-
at91_for_each_port(i) {
634-
if (!gpio_is_valid(pdata->overcurrent_pin[i]))
635-
continue;
636-
free_irq(gpio_to_irq(pdata->overcurrent_pin[i]), pdev);
637-
gpio_free(pdata->overcurrent_pin[i]);
638-
}
639580
}
640581

641582
device_init_wakeup(&pdev->dev, 0);

0 commit comments

Comments
 (0)