of_gpio.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * OF helpers for the GPIO API
  3. *
  4. * Copyright (c) 2007-2008 MontaVista Software, Inc.
  5. *
  6. * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #ifndef __LINUX_OF_GPIO_H
  14. #define __LINUX_OF_GPIO_H
  15. #include <linux/compiler.h>
  16. #include <linux/kernel.h>
  17. #include <linux/errno.h>
  18. #include <linux/gpio.h>
  19. struct device_node;
  20. /*
  21. * This is Linux-specific flags. By default controllers' and Linux' mapping
  22. * match, but GPIO controllers are free to translate their own flags to
  23. * Linux-specific in their .xlate callback. Though, 1:1 mapping is recommended.
  24. */
  25. enum of_gpio_flags {
  26. OF_GPIO_ACTIVE_LOW = 0x1,
  27. };
  28. #ifdef CONFIG_OF_GPIO
  29. /*
  30. * OF GPIO chip for memory mapped banks
  31. */
  32. struct of_mm_gpio_chip {
  33. struct gpio_chip gc;
  34. void (*save_regs)(struct of_mm_gpio_chip *mm_gc);
  35. void __iomem *regs;
  36. };
  37. static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
  38. {
  39. return container_of(gc, struct of_mm_gpio_chip, gc);
  40. }
  41. extern int of_get_named_gpio_flags(struct device_node *np,
  42. const char *list_name, int index, enum of_gpio_flags *flags);
  43. extern unsigned int of_gpio_count(struct device_node *np);
  44. extern int of_mm_gpiochip_add(struct device_node *np,
  45. struct of_mm_gpio_chip *mm_gc);
  46. extern void of_gpiochip_add(struct gpio_chip *gc);
  47. extern void of_gpiochip_remove(struct gpio_chip *gc);
  48. extern struct gpio_chip *of_node_to_gpiochip(struct device_node *np);
  49. extern int of_gpio_simple_xlate(struct gpio_chip *gc, struct device_node *np,
  50. const void *gpio_spec, u32 *flags);
  51. #else /* CONFIG_OF_GPIO */
  52. /* Drivers may not strictly depend on the GPIO support, so let them link. */
  53. static inline int of_get_named_gpio_flags(struct device_node *np,
  54. const char *list_name, int index, enum of_gpio_flags *flags)
  55. {
  56. return -ENOSYS;
  57. }
  58. static inline unsigned int of_gpio_count(struct device_node *np)
  59. {
  60. return 0;
  61. }
  62. static inline int of_gpio_simple_xlate(struct gpio_chip *gc,
  63. struct device_node *np,
  64. const void *gpio_spec, u32 *flags)
  65. {
  66. return -ENOSYS;
  67. }
  68. static inline void of_gpiochip_add(struct gpio_chip *gc) { }
  69. static inline void of_gpiochip_remove(struct gpio_chip *gc) { }
  70. #endif /* CONFIG_OF_GPIO */
  71. /**
  72. * of_get_gpio_flags() - Get a GPIO number and flags to use with GPIO API
  73. * @np: device node to get GPIO from
  74. * @index: index of the GPIO
  75. * @flags: a flags pointer to fill in
  76. *
  77. * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
  78. * value on the error condition. If @flags is not NULL the function also fills
  79. * in flags for the GPIO.
  80. */
  81. static inline int of_get_gpio_flags(struct device_node *np, int index,
  82. enum of_gpio_flags *flags)
  83. {
  84. return of_get_named_gpio_flags(np, "gpios", index, flags);
  85. }
  86. /**
  87. * of_get_named_gpio() - Get a GPIO number to use with GPIO API
  88. * @np: device node to get GPIO from
  89. * @propname: Name of property containing gpio specifier(s)
  90. * @index: index of the GPIO
  91. *
  92. * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
  93. * value on the error condition.
  94. */
  95. static inline int of_get_named_gpio(struct device_node *np,
  96. const char *propname, int index)
  97. {
  98. return of_get_named_gpio_flags(np, propname, index, NULL);
  99. }
  100. /**
  101. * of_get_gpio() - Get a GPIO number to use with GPIO API
  102. * @np: device node to get GPIO from
  103. * @index: index of the GPIO
  104. *
  105. * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
  106. * value on the error condition.
  107. */
  108. static inline int of_get_gpio(struct device_node *np, int index)
  109. {
  110. return of_get_gpio_flags(np, index, NULL);
  111. }
  112. #endif /* __LINUX_OF_GPIO_H */