1 From 0cb136f9882e4649ad6160bb7b48955ff728888c Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Sun, 1 Nov 2015 08:17:21 +0100
4 Subject: [PATCH V2] USB: bcma: switch to GPIO descriptor for power control
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 So far we were using simple (legacy) GPIO functions & some poor logic to
10 control power. It got many drawbacks: we were ignoring OF flags
11 (GPIO_ACTIVE_LOW), we were not setting direction to output and we were
12 assuming gpio_request success all the time.
13 Fix it by switching to gpiod functions and adding appropriate checks.
15 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
17 drivers/usb/host/bcma-hcd.c | 21 ++++++++++-----------
18 1 file changed, 10 insertions(+), 11 deletions(-)
20 diff --git a/drivers/usb/host/bcma-hcd.c b/drivers/usb/host/bcma-hcd.c
21 index 5398e3d..291aaa2 100644
22 --- a/drivers/usb/host/bcma-hcd.c
23 +++ b/drivers/usb/host/bcma-hcd.c
26 #include <linux/bcma/bcma.h>
27 #include <linux/delay.h>
28 +#include <linux/gpio/consumer.h>
29 #include <linux/platform_device.h>
30 #include <linux/module.h>
31 #include <linux/slab.h>
32 @@ -36,6 +37,7 @@ MODULE_LICENSE("GPL");
33 struct bcma_hcd_device {
34 struct platform_device *ehci_dev;
35 struct platform_device *ohci_dev;
36 + struct gpio_desc *gpio_desc;
39 /* Wait for bitmask in a register to get set or cleared.
40 @@ -228,19 +230,12 @@ static void bcma_hcd_init_chip_arm(struct bcma_device *dev)
42 static void bcma_hci_platform_power_gpio(struct bcma_device *dev, bool val)
45 + struct bcma_hcd_device *usb_dev = bcma_get_drvdata(dev);
47 - gpio = of_get_named_gpio(dev->dev.of_node, "vcc-gpio", 0);
48 - if (!gpio_is_valid(gpio))
49 + if (IS_ERR_OR_NULL(usb_dev->gpio_desc))
53 - gpio_request(gpio, "bcma-hcd-gpio");
54 - gpio_set_value(gpio, 1);
56 - gpio_set_value(gpio, 0);
59 + gpiod_set_value(usb_dev->gpio_desc, val);
62 static const struct usb_ehci_pdata ehci_pdata = {
63 @@ -314,7 +309,11 @@ static int bcma_hcd_probe(struct bcma_device *dev)
67 - bcma_hci_platform_power_gpio(dev, true);
68 + if (dev->dev.of_node)
69 + usb_dev->gpio_desc = devm_get_gpiod_from_child(&dev->dev, "vcc",
70 + &dev->dev.of_node->fwnode);
71 + if (!IS_ERR_OR_NULL(usb_dev->gpio_desc))
72 + gpiod_direction_output(usb_dev->gpio_desc, 1);
75 case BCMA_CORE_NS_USB20: