Linux 4.6-rc6
[cris-mirror.git] / include / linux / pinctrl / consumer.h
blobd7e5d608faa7db52543fbb4c7cc221171dca2744
1 /*
2 * Consumer interface the pin control subsystem
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
8 * Author: Linus Walleij <linus.walleij@linaro.org>
10 * License terms: GNU General Public License (GPL) version 2
12 #ifndef __LINUX_PINCTRL_CONSUMER_H
13 #define __LINUX_PINCTRL_CONSUMER_H
15 #include <linux/err.h>
16 #include <linux/list.h>
17 #include <linux/seq_file.h>
18 #include <linux/pinctrl/pinctrl-state.h>
20 /* This struct is private to the core and should be regarded as a cookie */
21 struct pinctrl;
22 struct pinctrl_state;
23 struct device;
25 #ifdef CONFIG_PINCTRL
27 /* External interface to pin control */
28 extern int pinctrl_request_gpio(unsigned gpio);
29 extern void pinctrl_free_gpio(unsigned gpio);
30 extern int pinctrl_gpio_direction_input(unsigned gpio);
31 extern int pinctrl_gpio_direction_output(unsigned gpio);
33 extern struct pinctrl * __must_check pinctrl_get(struct device *dev);
34 extern void pinctrl_put(struct pinctrl *p);
35 extern struct pinctrl_state * __must_check pinctrl_lookup_state(
36 struct pinctrl *p,
37 const char *name);
38 extern int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *s);
40 extern struct pinctrl * __must_check devm_pinctrl_get(struct device *dev);
41 extern void devm_pinctrl_put(struct pinctrl *p);
43 #ifdef CONFIG_PM
44 extern int pinctrl_pm_select_default_state(struct device *dev);
45 extern int pinctrl_pm_select_sleep_state(struct device *dev);
46 extern int pinctrl_pm_select_idle_state(struct device *dev);
47 #else
48 static inline int pinctrl_pm_select_default_state(struct device *dev)
50 return 0;
52 static inline int pinctrl_pm_select_sleep_state(struct device *dev)
54 return 0;
56 static inline int pinctrl_pm_select_idle_state(struct device *dev)
58 return 0;
60 #endif
62 #else /* !CONFIG_PINCTRL */
64 static inline int pinctrl_request_gpio(unsigned gpio)
66 return 0;
69 static inline void pinctrl_free_gpio(unsigned gpio)
73 static inline int pinctrl_gpio_direction_input(unsigned gpio)
75 return 0;
78 static inline int pinctrl_gpio_direction_output(unsigned gpio)
80 return 0;
83 static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
85 return NULL;
88 static inline void pinctrl_put(struct pinctrl *p)
92 static inline struct pinctrl_state * __must_check pinctrl_lookup_state(
93 struct pinctrl *p,
94 const char *name)
96 return NULL;
99 static inline int pinctrl_select_state(struct pinctrl *p,
100 struct pinctrl_state *s)
102 return 0;
105 static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev)
107 return NULL;
110 static inline void devm_pinctrl_put(struct pinctrl *p)
114 static inline int pinctrl_pm_select_default_state(struct device *dev)
116 return 0;
119 static inline int pinctrl_pm_select_sleep_state(struct device *dev)
121 return 0;
124 static inline int pinctrl_pm_select_idle_state(struct device *dev)
126 return 0;
129 #endif /* CONFIG_PINCTRL */
131 static inline struct pinctrl * __must_check pinctrl_get_select(
132 struct device *dev, const char *name)
134 struct pinctrl *p;
135 struct pinctrl_state *s;
136 int ret;
138 p = pinctrl_get(dev);
139 if (IS_ERR(p))
140 return p;
142 s = pinctrl_lookup_state(p, name);
143 if (IS_ERR(s)) {
144 pinctrl_put(p);
145 return ERR_CAST(s);
148 ret = pinctrl_select_state(p, s);
149 if (ret < 0) {
150 pinctrl_put(p);
151 return ERR_PTR(ret);
154 return p;
157 static inline struct pinctrl * __must_check pinctrl_get_select_default(
158 struct device *dev)
160 return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
163 static inline struct pinctrl * __must_check devm_pinctrl_get_select(
164 struct device *dev, const char *name)
166 struct pinctrl *p;
167 struct pinctrl_state *s;
168 int ret;
170 p = devm_pinctrl_get(dev);
171 if (IS_ERR(p))
172 return p;
174 s = pinctrl_lookup_state(p, name);
175 if (IS_ERR(s)) {
176 devm_pinctrl_put(p);
177 return ERR_CAST(s);
180 ret = pinctrl_select_state(p, s);
181 if (ret < 0) {
182 devm_pinctrl_put(p);
183 return ERR_PTR(ret);
186 return p;
189 static inline struct pinctrl * __must_check devm_pinctrl_get_select_default(
190 struct device *dev)
192 return devm_pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
195 #endif /* __LINUX_PINCTRL_CONSUMER_H */