aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWenyou Yang <wenyou.yang@atmel.com>2016-09-29 05:59:02 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-10-24 09:17:51 -0400
commit054d4b7b577de6f5d25a0d443f0d59410bf156ad (patch)
tree2d4b1d96b826154153f5d3722db5721434898eeb
parent629dd219881a6d9643806acf4f0166501f4c3374 (diff)
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>
-rw-r--r--drivers/usb/host/ohci-at91.c121
1 files changed, 31 insertions, 90 deletions
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 5b5880c0ae19..2ebea306151d 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -14,8 +14,8 @@
14 14
15#include <linux/clk.h> 15#include <linux/clk.h>
16#include <linux/dma-mapping.h> 16#include <linux/dma-mapping.h>
17#include <linux/gpio/consumer.h>
17#include <linux/of_platform.h> 18#include <linux/of_platform.h>
18#include <linux/of_gpio.h>
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/platform_data/atmel.h> 20#include <linux/platform_data/atmel.h>
21#include <linux/io.h> 21#include <linux/io.h>
@@ -39,8 +39,8 @@
39 39
40#define AT91_MAX_USBH_PORTS 3 40#define AT91_MAX_USBH_PORTS 3
41struct at91_usbh_data { 41struct at91_usbh_data {
42 int vbus_pin[AT91_MAX_USBH_PORTS]; /* port power-control pin */ 42 struct gpio_desc *vbus_pin[AT91_MAX_USBH_PORTS];
43 int overcurrent_pin[AT91_MAX_USBH_PORTS]; 43 struct gpio_desc *overcurrent_pin[AT91_MAX_USBH_PORTS];
44 u8 ports; /* number of ports on root hub */ 44 u8 ports; /* number of ports on root hub */
45 u8 overcurrent_supported; 45 u8 overcurrent_supported;
46 u8 vbus_pin_active_low[AT91_MAX_USBH_PORTS]; 46 u8 vbus_pin_active_low[AT91_MAX_USBH_PORTS];
@@ -262,11 +262,8 @@ static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int
262 if (!valid_port(port)) 262 if (!valid_port(port))
263 return; 263 return;
264 264
265 if (!gpio_is_valid(pdata->vbus_pin[port])) 265 gpiod_set_value(pdata->vbus_pin[port],
266 return; 266 pdata->vbus_pin_active_low[port] ^ enable);
267
268 gpio_set_value(pdata->vbus_pin[port],
269 pdata->vbus_pin_active_low[port] ^ enable);
270} 267}
271 268
272static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port) 269static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
@@ -274,11 +271,8 @@ static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
274 if (!valid_port(port)) 271 if (!valid_port(port))
275 return -EINVAL; 272 return -EINVAL;
276 273
277 if (!gpio_is_valid(pdata->vbus_pin[port])) 274 return gpiod_get_value(pdata->vbus_pin[port]) ^
278 return -EINVAL; 275 pdata->vbus_pin_active_low[port];
279
280 return gpio_get_value(pdata->vbus_pin[port]) ^
281 pdata->vbus_pin_active_low[port];
282} 276}
283 277
284/* 278/*
@@ -468,16 +462,13 @@ static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
468{ 462{
469 struct platform_device *pdev = data; 463 struct platform_device *pdev = data;
470 struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev); 464 struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev);
471 int val, gpio, port; 465 int val, port;
472 466
473 /* From the GPIO notifying the over-current situation, find 467 /* From the GPIO notifying the over-current situation, find
474 * out the corresponding port */ 468 * out the corresponding port */
475 at91_for_each_port(port) { 469 at91_for_each_port(port) {
476 if (gpio_is_valid(pdata->overcurrent_pin[port]) && 470 if (gpiod_to_irq(pdata->overcurrent_pin[port]) == irq)
477 gpio_to_irq(pdata->overcurrent_pin[port]) == irq) {
478 gpio = pdata->overcurrent_pin[port];
479 break; 471 break;
480 }
481 } 472 }
482 473
483 if (port == AT91_MAX_USBH_PORTS) { 474 if (port == AT91_MAX_USBH_PORTS) {
@@ -485,7 +476,7 @@ static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
485 return IRQ_HANDLED; 476 return IRQ_HANDLED;
486 } 477 }
487 478
488 val = gpio_get_value(gpio); 479 val = gpiod_get_value(pdata->overcurrent_pin[port]);
489 480
490 /* When notified of an over-current situation, disable power 481 /* When notified of an over-current situation, disable power
491 on the corresponding port, and mark this port in 482 on the corresponding port, and mark this port in
@@ -516,9 +507,8 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
516 struct device_node *np = pdev->dev.of_node; 507 struct device_node *np = pdev->dev.of_node;
517 struct at91_usbh_data *pdata; 508 struct at91_usbh_data *pdata;
518 int i; 509 int i;
519 int gpio;
520 int ret; 510 int ret;
521 enum of_gpio_flags flags; 511 int err;
522 u32 ports; 512 u32 ports;
523 513
524 /* Right now device-tree probed devices don't get dma_mask set. 514 /* 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)
539 pdata->ports = ports; 529 pdata->ports = ports;
540 530
541 at91_for_each_port(i) { 531 at91_for_each_port(i) {
542 /* 532 pdata->vbus_pin[i] = devm_gpiod_get_optional(&pdev->dev,
543 * do not configure PIO if not in relation with 533 "atmel,vbus-gpio",
544 * real USB port on board 534 GPIOD_IN);
545 */ 535 if (IS_ERR(pdata->vbus_pin[i])) {
546 if (i >= pdata->ports) { 536 err = PTR_ERR(pdata->vbus_pin[i]);
547 pdata->vbus_pin[i] = -EINVAL; 537 dev_err(&pdev->dev, "unable to claim gpio \"vbus\": %d\n", err);
548 pdata->overcurrent_pin[i] = -EINVAL;
549 continue; 538 continue;
550 } 539 }
551 540
552 gpio = of_get_named_gpio_flags(np, "atmel,vbus-gpio", i, 541 pdata->vbus_pin_active_low[i] = gpiod_get_value(pdata->vbus_pin[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 }
574 542
575 ohci_at91_usb_set_power(pdata, i, 1); 543 ohci_at91_usb_set_power(pdata, i, 1);
576 } 544 }
@@ -580,37 +548,21 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
580 break; 548 break;
581 549
582 pdata->overcurrent_pin[i] = 550 pdata->overcurrent_pin[i] =
583 of_get_named_gpio_flags(np, "atmel,oc-gpio", i, &flags); 551 devm_gpiod_get_optional(&pdev->dev,
584 552 "atmel,oc-gpio", GPIOD_IN);
585 if (!gpio_is_valid(pdata->overcurrent_pin[i])) 553 if (IS_ERR(pdata->overcurrent_pin[i])) {
586 continue; 554 err = PTR_ERR(pdata->overcurrent_pin[i]);
587 gpio = pdata->overcurrent_pin[i]; 555 dev_err(&pdev->dev, "unable to claim gpio \"overcurrent\": %d\n", err);
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);
594 continue; 556 continue;
595 } 557 }
596 558
597 ret = gpio_direction_input(gpio); 559 ret = devm_request_irq(&pdev->dev,
598 if (ret) { 560 gpiod_to_irq(pdata->overcurrent_pin[i]),
599 dev_err(&pdev->dev, 561 ohci_hcd_at91_overcurrent_irq,
600 "can't configure overcurrent gpio %d as input\n", 562 IRQF_SHARED,
601 gpio); 563 "ohci_overcurrent", pdev);
602 gpio_free(gpio); 564 if (ret)
603 continue; 565 dev_info(&pdev->dev, "failed to request gpio \"overcurrent\" IRQ\n");
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 }
614 } 566 }
615 567
616 device_init_wakeup(&pdev->dev, 1); 568 device_init_wakeup(&pdev->dev, 1);
@@ -623,19 +575,8 @@ static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
623 int i; 575 int i;
624 576
625 if (pdata) { 577 if (pdata) {
626 at91_for_each_port(i) { 578 at91_for_each_port(i)
627 if (!gpio_is_valid(pdata->vbus_pin[i]))
628 continue;
629 ohci_at91_usb_set_power(pdata, i, 0); 579 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 }
639 } 580 }
640 581
641 device_init_wakeup(&pdev->dev, 0); 582 device_init_wakeup(&pdev->dev, 0);