consumer.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 "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. #else /* !CONFIG_PINCTRL */
  37. static inline int pinctrl_request_gpio(unsigned gpio)
  38. {
  39. return 0;
  40. }
  41. static inline void pinctrl_free_gpio(unsigned gpio)
  42. {
  43. }
  44. static inline int pinctrl_gpio_direction_input(unsigned gpio)
  45. {
  46. return 0;
  47. }
  48. static inline int pinctrl_gpio_direction_output(unsigned gpio)
  49. {
  50. return 0;
  51. }
  52. static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
  53. {
  54. return NULL;
  55. }
  56. static inline void pinctrl_put(struct pinctrl *p)
  57. {
  58. }
  59. static inline struct pinctrl_state * __must_check pinctrl_lookup_state(
  60. struct pinctrl *p,
  61. const char *name)
  62. {
  63. return NULL;
  64. }
  65. static inline int pinctrl_select_state(struct pinctrl *p,
  66. struct pinctrl_state *s)
  67. {
  68. return 0;
  69. }
  70. static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev)
  71. {
  72. return NULL;
  73. }
  74. static inline void devm_pinctrl_put(struct pinctrl *p)
  75. {
  76. }
  77. #endif /* CONFIG_PINCTRL */
  78. static inline struct pinctrl * __must_check pinctrl_get_select(
  79. struct device *dev, const char *name)
  80. {
  81. struct pinctrl *p;
  82. struct pinctrl_state *s;
  83. int ret;
  84. p = pinctrl_get(dev);
  85. if (IS_ERR(p))
  86. return p;
  87. s = pinctrl_lookup_state(p, name);
  88. if (IS_ERR(s)) {
  89. pinctrl_put(p);
  90. return ERR_PTR(PTR_ERR(s));
  91. }
  92. ret = pinctrl_select_state(p, s);
  93. if (ret < 0) {
  94. pinctrl_put(p);
  95. return ERR_PTR(ret);
  96. }
  97. return p;
  98. }
  99. static inline struct pinctrl * __must_check pinctrl_get_select_default(
  100. struct device *dev)
  101. {
  102. return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
  103. }
  104. static inline struct pinctrl * __must_check devm_pinctrl_get_select(
  105. struct device *dev, const char *name)
  106. {
  107. struct pinctrl *p;
  108. struct pinctrl_state *s;
  109. int ret;
  110. p = devm_pinctrl_get(dev);
  111. if (IS_ERR(p))
  112. return p;
  113. s = pinctrl_lookup_state(p, name);
  114. if (IS_ERR(s)) {
  115. devm_pinctrl_put(p);
  116. return ERR_CAST(s);
  117. }
  118. ret = pinctrl_select_state(p, s);
  119. if (ret < 0) {
  120. devm_pinctrl_put(p);
  121. return ERR_PTR(ret);
  122. }
  123. return p;
  124. }
  125. static inline struct pinctrl * __must_check devm_pinctrl_get_select_default(
  126. struct device *dev)
  127. {
  128. return devm_pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
  129. }
  130. #ifdef CONFIG_PINCONF
  131. extern int pin_config_get(const char *dev_name, const char *name,
  132. unsigned long *config);
  133. extern int pin_config_set(const char *dev_name, const char *name,
  134. unsigned long config);
  135. extern int pin_config_group_get(const char *dev_name,
  136. const char *pin_group,
  137. unsigned long *config);
  138. extern int pin_config_group_set(const char *dev_name,
  139. const char *pin_group,
  140. unsigned long config);
  141. #else
  142. static inline int pin_config_get(const char *dev_name, const char *name,
  143. unsigned long *config)
  144. {
  145. return 0;
  146. }
  147. static inline int pin_config_set(const char *dev_name, const char *name,
  148. unsigned long config)
  149. {
  150. return 0;
  151. }
  152. static inline int pin_config_group_get(const char *dev_name,
  153. const char *pin_group,
  154. unsigned long *config)
  155. {
  156. return 0;
  157. }
  158. static inline int pin_config_group_set(const char *dev_name,
  159. const char *pin_group,
  160. unsigned long config)
  161. {
  162. return 0;
  163. }
  164. #endif
  165. #endif /* __LINUX_PINCTRL_CONSUMER_H */