080-USB-bcma-switch-to-GPIO-descriptor-for-power-control.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. From 9faae5a37b266afca6914163316856c5ed4ec366 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 10:04:41 +0100
  4. Subject: [PATCH] USB: bcma: switch to GPIO descriptor for power control
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. So far we were using simple (legacy) GPIO functions & some poor logic to
  9. control power. It got many drawbacks: we were ignoring OF flags
  10. (GPIO_ACTIVE_LOW), we were not setting direction to output and we were
  11. assuming gpio_request success all the time.
  12. Fix it by switching to gpiod functions and adding appropriate checks.
  13. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  14. Acked-by: Hauke Mehrtens <hauke@hauke-m.de>
  15. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  16. ---
  17. drivers/usb/host/bcma-hcd.c | 21 ++++++++++-----------
  18. 1 file changed, 10 insertions(+), 11 deletions(-)
  19. --- a/drivers/usb/host/bcma-hcd.c
  20. +++ b/drivers/usb/host/bcma-hcd.c
  21. @@ -21,6 +21,7 @@
  22. */
  23. #include <linux/bcma/bcma.h>
  24. #include <linux/delay.h>
  25. +#include <linux/gpio/consumer.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/module.h>
  28. #include <linux/slab.h>
  29. @@ -36,6 +37,7 @@ MODULE_LICENSE("GPL");
  30. struct bcma_hcd_device {
  31. struct platform_device *ehci_dev;
  32. struct platform_device *ohci_dev;
  33. + struct gpio_desc *gpio_desc;
  34. };
  35. /* Wait for bitmask in a register to get set or cleared.
  36. @@ -228,19 +230,12 @@ static void bcma_hcd_init_chip_arm(struc
  37. static void bcma_hci_platform_power_gpio(struct bcma_device *dev, bool val)
  38. {
  39. - int gpio;
  40. + struct bcma_hcd_device *usb_dev = bcma_get_drvdata(dev);
  41. - gpio = of_get_named_gpio(dev->dev.of_node, "vcc-gpio", 0);
  42. - if (!gpio_is_valid(gpio))
  43. + if (IS_ERR_OR_NULL(usb_dev->gpio_desc))
  44. return;
  45. - if (val) {
  46. - gpio_request(gpio, "bcma-hcd-gpio");
  47. - gpio_set_value(gpio, 1);
  48. - } else {
  49. - gpio_set_value(gpio, 0);
  50. - gpio_free(gpio);
  51. - }
  52. + gpiod_set_value(usb_dev->gpio_desc, val);
  53. }
  54. static const struct usb_ehci_pdata ehci_pdata = {
  55. @@ -314,7 +309,11 @@ static int bcma_hcd_probe(struct bcma_de
  56. if (!usb_dev)
  57. return -ENOMEM;
  58. - bcma_hci_platform_power_gpio(dev, true);
  59. + if (dev->dev.of_node)
  60. + usb_dev->gpio_desc = devm_get_gpiod_from_child(&dev->dev, "vcc",
  61. + &dev->dev.of_node->fwnode);
  62. + if (!IS_ERR_OR_NULL(usb_dev->gpio_desc))
  63. + gpiod_direction_output(usb_dev->gpio_desc, 1);
  64. switch (dev->id.id) {
  65. case BCMA_CORE_NS_USB20: