Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / include / linux / pinctrl / consumer.h
blob0412cc9833e99d0291fea4029f0b72bd1b9d9148
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_gpio_request(unsigned gpio);
29 extern void pinctrl_gpio_free(unsigned gpio);
30 extern int pinctrl_gpio_direction_input(unsigned gpio);
31 extern int pinctrl_gpio_direction_output(unsigned gpio);
32 extern int pinctrl_gpio_set_config(unsigned gpio, unsigned long config);
34 extern struct pinctrl * __must_check pinctrl_get(struct device *dev);
35 extern void pinctrl_put(struct pinctrl *p);
36 extern struct pinctrl_state * __must_check pinctrl_lookup_state(
37 struct pinctrl *p,
38 const char *name);
39 extern int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *s);
41 extern struct pinctrl * __must_check devm_pinctrl_get(struct device *dev);
42 extern void devm_pinctrl_put(struct pinctrl *p);
44 #ifdef CONFIG_PM
45 extern int pinctrl_pm_select_default_state(struct device *dev);
46 extern int pinctrl_pm_select_sleep_state(struct device *dev);
47 extern int pinctrl_pm_select_idle_state(struct device *dev);
48 #else
49 static inline int pinctrl_pm_select_default_state(struct device *dev)
51 return 0;
53 static inline int pinctrl_pm_select_sleep_state(struct device *dev)
55 return 0;
57 static inline int pinctrl_pm_select_idle_state(struct device *dev)
59 return 0;
61 #endif
63 #else /* !CONFIG_PINCTRL */
65 static inline int pinctrl_gpio_request(unsigned gpio)
67 return 0;
70 static inline void pinctrl_gpio_free(unsigned gpio)
74 static inline int pinctrl_gpio_direction_input(unsigned gpio)
76 return 0;
79 static inline int pinctrl_gpio_direction_output(unsigned gpio)
81 return 0;
84 static inline int pinctrl_gpio_set_config(unsigned gpio, unsigned long config)
86 return 0;
89 static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
91 return NULL;
94 static inline void pinctrl_put(struct pinctrl *p)
98 static inline struct pinctrl_state * __must_check pinctrl_lookup_state(
99 struct pinctrl *p,
100 const char *name)
102 return NULL;
105 static inline int pinctrl_select_state(struct pinctrl *p,
106 struct pinctrl_state *s)
108 return 0;
111 static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev)
113 return NULL;
116 static inline void devm_pinctrl_put(struct pinctrl *p)
120 static inline int pinctrl_pm_select_default_state(struct device *dev)
122 return 0;
125 static inline int pinctrl_pm_select_sleep_state(struct device *dev)
127 return 0;
130 static inline int pinctrl_pm_select_idle_state(struct device *dev)
132 return 0;
135 #endif /* CONFIG_PINCTRL */
137 static inline struct pinctrl * __must_check pinctrl_get_select(
138 struct device *dev, const char *name)
140 struct pinctrl *p;
141 struct pinctrl_state *s;
142 int ret;
144 p = pinctrl_get(dev);
145 if (IS_ERR(p))
146 return p;
148 s = pinctrl_lookup_state(p, name);
149 if (IS_ERR(s)) {
150 pinctrl_put(p);
151 return ERR_CAST(s);
154 ret = pinctrl_select_state(p, s);
155 if (ret < 0) {
156 pinctrl_put(p);
157 return ERR_PTR(ret);
160 return p;
163 static inline struct pinctrl * __must_check pinctrl_get_select_default(
164 struct device *dev)
166 return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
169 static inline struct pinctrl * __must_check devm_pinctrl_get_select(
170 struct device *dev, const char *name)
172 struct pinctrl *p;
173 struct pinctrl_state *s;
174 int ret;
176 p = devm_pinctrl_get(dev);
177 if (IS_ERR(p))
178 return p;
180 s = pinctrl_lookup_state(p, name);
181 if (IS_ERR(s)) {
182 devm_pinctrl_put(p);
183 return ERR_CAST(s);
186 ret = pinctrl_select_state(p, s);
187 if (ret < 0) {
188 devm_pinctrl_put(p);
189 return ERR_PTR(ret);
192 return p;
195 static inline struct pinctrl * __must_check devm_pinctrl_get_select_default(
196 struct device *dev)
198 return devm_pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
201 #endif /* __LINUX_PINCTRL_CONSUMER_H */