442-leds-gpio-allow-to-use-OPEN_-DRAIN-SOURCE-flags-with.patch 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. From 183148e0789bee1cd5c46ba49afcb211f636f8a2 Mon Sep 17 00:00:00 2001
  2. From: Gabor Juhos <juhosg@freemail.hu>
  3. Date: Mon, 15 Jan 2018 15:01:14 +0100
  4. Subject: [PATCH] leds: gpio: allow to use OPEN_{DRAIN,SOURCE} flags with
  5. legacy GPIOs
  6. LEDs which are connected to open-source or open-drain type of GPIO lines
  7. can be used only, if those are defined via devicetree.
  8. Add two new fields to 'struct gpio_led' in order to make it possible to
  9. specify this type of GPIO lines to the leds-gpio driver via platform data.
  10. Also update the create_gpio_led() function to set the GPIOF_OPEN_DRAIN and
  11. GPIOF_OPEN_SOURCE flags for the given GPIO line.
  12. Signed-off-by: Gabor Juhos <juhosg@freemail.hu>
  13. ---
  14. drivers/leds/leds-gpio.c | 6 ++++++
  15. include/linux/leds.h | 2 ++
  16. 2 files changed, 8 insertions(+)
  17. --- a/drivers/leds/leds-gpio.c
  18. +++ b/drivers/leds/leds-gpio.c
  19. @@ -100,6 +100,12 @@ static int create_gpio_led(const struct
  20. if (template->active_low)
  21. flags |= GPIOF_ACTIVE_LOW;
  22. + if (template->open_drain)
  23. + flags |= GPIOF_OPEN_DRAIN;
  24. +
  25. + if (template->open_source)
  26. + flags |= GPIOF_OPEN_SOURCE;
  27. +
  28. ret = devm_gpio_request_one(parent, template->gpio, flags,
  29. template->name);
  30. if (ret < 0)
  31. --- a/include/linux/leds.h
  32. +++ b/include/linux/leds.h
  33. @@ -395,6 +395,8 @@ struct gpio_led {
  34. unsigned default_state : 2;
  35. unsigned retain_state_shutdown : 1;
  36. /* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */
  37. + unsigned open_drain : 1;
  38. + unsigned open_source : 1;
  39. struct gpio_desc *gpiod;
  40. };
  41. #define LEDS_GPIO_DEFSTATE_OFF 0