consumer.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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.h"
  18. /* This struct is private to the core and should be regarded as a cookie */
  19. struct pinctrl;
  20. struct pinctrl_state;
  21. #ifdef CONFIG_PINCTRL
  22. /* External interface to pin control */
  23. extern int pinctrl_request_gpio(unsigned gpio);
  24. extern void pinctrl_free_gpio(unsigned gpio);
  25. extern int pinctrl_gpio_direction_input(unsigned gpio);
  26. extern int pinctrl_gpio_direction_output(unsigned gpio);
  27. extern struct pinctrl * __must_check pinctrl_get(struct device *dev);
  28. extern void pinctrl_put(struct pinctrl *p);
  29. extern struct pinctrl_state * __must_check pinctrl_lookup_state(
  30. struct pinctrl *p,
  31. const char *name);
  32. extern int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *s);
  33. #else /* !CONFIG_PINCTRL */
  34. static inline int pinctrl_request_gpio(unsigned gpio)
  35. {
  36. return 0;
  37. }
  38. static inline void pinctrl_free_gpio(unsigned gpio)
  39. {
  40. }
  41. static inline int pinctrl_gpio_direction_input(unsigned gpio)
  42. {
  43. return 0;
  44. }
  45. static inline int pinctrl_gpio_direction_output(unsigned gpio)
  46. {
  47. return 0;
  48. }
  49. static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
  50. {
  51. return NULL;
  52. }
  53. static inline void pinctrl_put(struct pinctrl *p)
  54. {
  55. }
  56. static inline struct pinctrl_state * __must_check pinctrl_lookup_state(
  57. struct pinctrl *p,
  58. const char *name)
  59. {
  60. return NULL;
  61. }
  62. static inline int pinctrl_select_state(struct pinctrl *p,
  63. struct pinctrl_state *s)
  64. {
  65. return 0;
  66. }
  67. #endif /* CONFIG_PINCTRL */
  68. static inline struct pinctrl * __must_check pinctrl_get_select(
  69. struct device *dev, const char *name)
  70. {
  71. struct pinctrl *p;
  72. struct pinctrl_state *s;
  73. int ret;
  74. p = pinctrl_get(dev);
  75. if (IS_ERR(p))
  76. return p;
  77. s = pinctrl_lookup_state(p, name);
  78. if (IS_ERR(s)) {
  79. pinctrl_put(p);
  80. return ERR_PTR(PTR_ERR(s));
  81. }
  82. ret = pinctrl_select_state(p, s);
  83. if (ret < 0) {
  84. pinctrl_put(p);
  85. return ERR_PTR(ret);
  86. }
  87. return p;
  88. }
  89. static inline struct pinctrl * __must_check pinctrl_get_select_default(
  90. struct device *dev)
  91. {
  92. return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
  93. }
  94. #ifdef CONFIG_PINCONF
  95. extern int pin_config_get(const char *dev_name, const char *name,
  96. unsigned long *config);
  97. extern int pin_config_set(const char *dev_name, const char *name,
  98. unsigned long config);
  99. extern int pin_config_group_get(const char *dev_name,
  100. const char *pin_group,
  101. unsigned long *config);
  102. extern int pin_config_group_set(const char *dev_name,
  103. const char *pin_group,
  104. unsigned long config);
  105. #else
  106. static inline int pin_config_get(const char *dev_name, const char *name,
  107. unsigned long *config)
  108. {
  109. return 0;
  110. }
  111. static inline int pin_config_set(const char *dev_name, const char *name,
  112. unsigned long config)
  113. {
  114. return 0;
  115. }
  116. static inline int pin_config_group_get(const char *dev_name,
  117. const char *pin_group,
  118. unsigned long *config)
  119. {
  120. return 0;
  121. }
  122. static inline int pin_config_group_set(const char *dev_name,
  123. const char *pin_group,
  124. unsigned long config)
  125. {
  126. return 0;
  127. }
  128. #endif
  129. #endif /* __LINUX_PINCTRL_CONSUMER_H */