186-USB-bcma-switch-to-GPIO-descriptor-for-power-control.patch 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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
  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. ---
  15. drivers/usb/host/bcma-hcd.c | 21 ++++++++++-----------
  16. 1 file changed, 10 insertions(+), 11 deletions(-)
  17. --- a/drivers/usb/host/bcma-hcd.c
  18. +++ b/drivers/usb/host/bcma-hcd.c
  19. @@ -21,6 +21,7 @@
  20. */
  21. #include <linux/bcma/bcma.h>
  22. #include <linux/delay.h>
  23. +#include <linux/gpio/consumer.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/module.h>
  26. #include <linux/slab.h>
  27. @@ -36,6 +37,7 @@ MODULE_LICENSE("GPL");
  28. struct bcma_hcd_device {
  29. struct platform_device *ehci_dev;
  30. struct platform_device *ohci_dev;
  31. + struct gpio_desc *gpio_desc;
  32. };
  33. /* Wait for bitmask in a register to get set or cleared.
  34. @@ -228,19 +230,12 @@ static void bcma_hcd_init_chip_arm(struc
  35. static void bcma_hci_platform_power_gpio(struct bcma_device *dev, bool val)
  36. {
  37. - int gpio;
  38. + struct bcma_hcd_device *usb_dev = bcma_get_drvdata(dev);
  39. - gpio = of_get_named_gpio(dev->dev.of_node, "vcc-gpio", 0);
  40. - if (!gpio_is_valid(gpio))
  41. + if (IS_ERR_OR_NULL(usb_dev->gpio_desc))
  42. return;
  43. - if (val) {
  44. - gpio_request(gpio, "bcma-hcd-gpio");
  45. - gpio_set_value(gpio, 1);
  46. - } else {
  47. - gpio_set_value(gpio, 0);
  48. - gpio_free(gpio);
  49. - }
  50. + gpiod_set_value(usb_dev->gpio_desc, val);
  51. }
  52. static const struct usb_ehci_pdata ehci_pdata = {
  53. @@ -314,7 +309,11 @@ static int bcma_hcd_probe(struct bcma_de
  54. if (!usb_dev)
  55. return -ENOMEM;
  56. - bcma_hci_platform_power_gpio(dev, true);
  57. + if (dev->dev.of_node)
  58. + usb_dev->gpio_desc = devm_get_gpiod_from_child(&dev->dev, "vcc",
  59. + &dev->dev.of_node->fwnode);
  60. + if (!IS_ERR_OR_NULL(usb_dev->gpio_desc))
  61. + gpiod_direction_output(usb_dev->gpio_desc, 1);
  62. switch (dev->id.id) {
  63. case BCMA_CORE_NS_USB20: