consumer.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Consumer interface the pin control subsystem
  3. *
  4. * Copyright (C) 2012 ST-Ericsson SA
  5. * Written on behalf of Linaro for ST-Ericsson
  6. * Based on bits of regulator core, gpio core and clk core
  7. *
  8. * Author: Linus Walleij <linus.walleij@linaro.org>
  9. *
  10. * License terms: GNU General Public License (GPL) version 2
  11. */
  12. #ifndef __LINUX_PINCTRL_CONSUMER_H
  13. #define __LINUX_PINCTRL_CONSUMER_H
  14. #include <linux/err.h>
  15. #include <linux/list.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/pinctrl/pinctrl-state.h>
  18. /* This struct is private to the core and should be regarded as a cookie */
  19. struct pinctrl;
  20. struct pinctrl_state;
  21. struct device;
  22. #ifdef CONFIG_PINCTRL
  23. /* External interface to pin control */
  24. extern int pinctrl_request_gpio(unsigned gpio);
  25. extern void pinctrl_free_gpio(unsigned gpio);
  26. extern int pinctrl_gpio_direction_input(unsigned gpio);
  27. extern int pinctrl_gpio_direction_output(unsigned gpio);
  28. extern struct pinctrl * __must_check pinctrl_get(struct device *dev);
  29. extern void pinctrl_put(struct pinctrl *p);
  30. extern struct pinctrl_state * __must_check pinctrl_lookup_state(
  31. struct pinctrl *p,
  32. const char *name);
  33. extern int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *s);
  34. extern struct pinctrl * __must_check devm_pinctrl_get(struct device *dev);
  35. extern void devm_pinctrl_put(struct pinctrl *p);
  36. #ifdef CONFIG_PM
  37. extern int pinctrl_pm_select_default_state(struct device *dev);
  38. extern int pinctrl_pm_select_sleep_state(struct device *dev);
  39. extern int pinctrl_pm_select_idle_state(struct device *dev);
  40. #else
  41. static inline int pinctrl_pm_select_default_state(struct device *dev)
  42. {
  43. return 0;
  44. }
  45. static inline int pinctrl_pm_select_sleep_state(struct device *dev)
  46. {
  47. return 0;
  48. }
  49. static inline int pinctrl_pm_select_idle_state(struct device *dev)
  50. {
  51. return 0;
  52. }
  53. #endif
  54. #else /* !CONFIG_PINCTRL */
  55. static inline int pinctrl_request_gpio(unsigned gpio)
  56. {
  57. return 0;
  58. }
  59. static inline void pinctrl_free_gpio(unsigned gpio)
  60. {
  61. }
  62. static inline int pinctrl_gpio_direction_input(unsigned gpio)
  63. {
  64. return 0;
  65. }
  66. static inline int pinctrl_gpio_direction_output(unsigned gpio)
  67. {
  68. return 0;
  69. }
  70. static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
  71. {
  72. return NULL;
  73. }
  74. static inline void pinctrl_put(struct pinctrl *p)
  75. {
  76. }
  77. static inline struct pinctrl_state * __must_check pinctrl_lookup_state(
  78. struct pinctrl *p,
  79. const char *name)
  80. {
  81. return NULL;
  82. }
  83. static inline int pinctrl_select_state(struct pinctrl *p,
  84. struct pinctrl_state *s)
  85. {
  86. return 0;
  87. }
  88. static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev)
  89. {
  90. return NULL;
  91. }
  92. static inline void devm_pinctrl_put(struct pinctrl *p)
  93. {
  94. }
  95. static inline int pinctrl_pm_select_default_state(struct device *dev)
  96. {
  97. return 0;
  98. }
  99. static inline int pinctrl_pm_select_sleep_state(struct device *dev)
  100. {
  101. return 0;
  102. }
  103. static inline int pinctrl_pm_select_idle_state(struct device *dev)
  104. {
  105. return 0;
  106. }
  107. #endif /* CONFIG_PINCTRL */
  108. static inline struct pinctrl * __must_check pinctrl_get_select(
  109. struct device *dev, const char *name)
  110. {
  111. struct pinctrl *p;
  112. struct pinctrl_state *s;
  113. int ret;
  114. p = pinctrl_get(dev);
  115. if (IS_ERR(p))
  116. return p;
  117. s = pinctrl_lookup_state(p, name);
  118. if (IS_ERR(s)) {
  119. pinctrl_put(p);
  120. return ERR_CAST(s);
  121. }
  122. ret = pinctrl_select_state(p, s);
  123. if (ret < 0) {
  124. pinctrl_put(p);
  125. return ERR_PTR(ret);
  126. }
  127. return p;
  128. }
  129. static inline struct pinctrl * __must_check pinctrl_get_select_default(
  130. struct device *dev)
  131. {
  132. return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
  133. }
  134. static inline struct pinctrl * __must_check devm_pinctrl_get_select(
  135. struct device *dev, const char *name)
  136. {
  137. struct pinctrl *p;
  138. struct pinctrl_state *s;
  139. int ret;
  140. p = devm_pinctrl_get(dev);
  141. if (IS_ERR(p))
  142. return p;
  143. s = pinctrl_lookup_state(p, name);
  144. if (IS_ERR(s)) {
  145. devm_pinctrl_put(p);
  146. return ERR_CAST(s);
  147. }
  148. ret = pinctrl_select_state(p, s);
  149. if (ret < 0) {
  150. devm_pinctrl_put(p);
  151. return ERR_PTR(ret);
  152. }
  153. return p;
  154. }
  155. static inline struct pinctrl * __must_check devm_pinctrl_get_select_default(
  156. struct device *dev)
  157. {
  158. return devm_pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
  159. }
  160. #endif /* __LINUX_PINCTRL_CONSUMER_H */