Skip to content

Commit 9faae5a

Browse files
rmileckigregkh
authored andcommitted
USB: bcma: switch to GPIO descriptor for power control
So far we were using simple (legacy) GPIO functions & some poor logic to control power. It got many drawbacks: we were ignoring OF flags (GPIO_ACTIVE_LOW), we were not setting direction to output and we were assuming gpio_request success all the time. Fix it by switching to gpiod functions and adding appropriate checks. Signed-off-by: Rafał Miłecki <[email protected]> Acked-by: Hauke Mehrtens <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6fb8ac8 commit 9faae5a

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

drivers/usb/host/bcma-hcd.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
#include <linux/bcma/bcma.h>
2323
#include <linux/delay.h>
24+
#include <linux/gpio/consumer.h>
2425
#include <linux/platform_device.h>
2526
#include <linux/module.h>
2627
#include <linux/slab.h>
@@ -36,6 +37,7 @@ MODULE_LICENSE("GPL");
3637
struct bcma_hcd_device {
3738
struct platform_device *ehci_dev;
3839
struct platform_device *ohci_dev;
40+
struct gpio_desc *gpio_desc;
3941
};
4042

4143
/* Wait for bitmask in a register to get set or cleared.
@@ -228,19 +230,12 @@ static void bcma_hcd_init_chip_arm(struct bcma_device *dev)
228230

229231
static void bcma_hci_platform_power_gpio(struct bcma_device *dev, bool val)
230232
{
231-
int gpio;
233+
struct bcma_hcd_device *usb_dev = bcma_get_drvdata(dev);
232234

233-
gpio = of_get_named_gpio(dev->dev.of_node, "vcc-gpio", 0);
234-
if (!gpio_is_valid(gpio))
235+
if (IS_ERR_OR_NULL(usb_dev->gpio_desc))
235236
return;
236237

237-
if (val) {
238-
gpio_request(gpio, "bcma-hcd-gpio");
239-
gpio_set_value(gpio, 1);
240-
} else {
241-
gpio_set_value(gpio, 0);
242-
gpio_free(gpio);
243-
}
238+
gpiod_set_value(usb_dev->gpio_desc, val);
244239
}
245240

246241
static const struct usb_ehci_pdata ehci_pdata = {
@@ -314,7 +309,11 @@ static int bcma_hcd_probe(struct bcma_device *dev)
314309
if (!usb_dev)
315310
return -ENOMEM;
316311

317-
bcma_hci_platform_power_gpio(dev, true);
312+
if (dev->dev.of_node)
313+
usb_dev->gpio_desc = devm_get_gpiod_from_child(&dev->dev, "vcc",
314+
&dev->dev.of_node->fwnode);
315+
if (!IS_ERR_OR_NULL(usb_dev->gpio_desc))
316+
gpiod_direction_output(usb_dev->gpio_desc, 1);
318317

319318
switch (dev->id.id) {
320319
case BCMA_CORE_NS_USB20:

0 commit comments

Comments
 (0)