070-gpio-add-flags-to-export-GPIOs-when-requesting.patch 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From fc3a1f04f5040255cbc086c419e4237f29f89f88 Mon Sep 17 00:00:00 2001
  2. From: Wolfram Sang <w.sang@pengutronix.de>
  3. Date: Tue, 13 Dec 2011 18:34:01 +0100
  4. Subject: [PATCH] gpio: add flags to export GPIOs when requesting
  5. commit fc3a1f04f5040255cbc086c419e4237f29f89f88 upstream.
  6. Introduce new flags to automatically export GPIOs when using the convenience
  7. functions gpio_request_one() or gpio_request_array(). This eases support for
  8. custom boards where lots of GPIOs need to be exported for customer
  9. applications.
  10. Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
  11. Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
  12. ---
  13. Documentation/gpio.txt | 3 +++
  14. drivers/gpio/gpiolib.c | 12 +++++++++++-
  15. include/linux/gpio.h | 5 +++++
  16. 3 files changed, 19 insertions(+), 1 deletion(-)
  17. --- a/Documentation/gpio.txt
  18. +++ b/Documentation/gpio.txt
  19. @@ -303,6 +303,9 @@ where 'flags' is currently defined to sp
  20. * GPIOF_INIT_LOW - as output, set initial level to LOW
  21. * GPIOF_INIT_HIGH - as output, set initial level to HIGH
  22. + * GPIOF_EXPORT_DIR_FIXED - export gpio to sysfs, keep direction
  23. + * GPIOF_EXPORT_DIR_CHANGEABLE - also export, allow changing direction
  24. +
  25. since GPIOF_INIT_* are only valid when configured as output, so group valid
  26. combinations as:
  27. --- a/drivers/gpio/gpiolib.c
  28. +++ b/drivers/gpio/gpiolib.c
  29. @@ -1289,8 +1289,18 @@ int gpio_request_one(unsigned gpio, unsi
  30. (flags & GPIOF_INIT_HIGH) ? 1 : 0);
  31. if (err)
  32. - gpio_free(gpio);
  33. + goto free_gpio;
  34. + if (flags & GPIOF_EXPORT) {
  35. + err = gpio_export(gpio, flags & GPIOF_EXPORT_CHANGEABLE);
  36. + if (err)
  37. + goto free_gpio;
  38. + }
  39. +
  40. + return 0;
  41. +
  42. + free_gpio:
  43. + gpio_free(gpio);
  44. return err;
  45. }
  46. EXPORT_SYMBOL_GPL(gpio_request_one);
  47. --- a/include/linux/gpio.h
  48. +++ b/include/linux/gpio.h
  49. @@ -14,6 +14,11 @@
  50. #define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
  51. #define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
  52. +#define GPIOF_EXPORT (1 << 2)
  53. +#define GPIOF_EXPORT_CHANGEABLE (1 << 3)
  54. +#define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
  55. +#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
  56. +
  57. /**
  58. * struct gpio - a structure describing a GPIO with configuration
  59. * @gpio: the GPIO number