]>
Commit | Line | Data |
---|---|---|
28a8d14c LW |
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 | ||
6e5e959d | 15 | #include <linux/err.h> |
28a8d14c LW |
16 | #include <linux/list.h> |
17 | #include <linux/seq_file.h> | |
a1ce3928 | 18 | #include <linux/pinctrl/pinctrl-state.h> |
28a8d14c LW |
19 | |
20 | /* This struct is private to the core and should be regarded as a cookie */ | |
e93bcee0 | 21 | struct pinctrl; |
6e5e959d | 22 | struct pinctrl_state; |
ac5aa7f9 | 23 | struct device; |
28a8d14c | 24 | |
befe5bdf | 25 | #ifdef CONFIG_PINCTRL |
28a8d14c | 26 | |
befe5bdf | 27 | /* External interface to pin control */ |
e93bcee0 LW |
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); | |
6e5e959d SW |
32 | |
33 | extern struct pinctrl * __must_check pinctrl_get(struct device *dev); | |
e93bcee0 | 34 | extern void pinctrl_put(struct pinctrl *p); |
6e5e959d SW |
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); | |
28a8d14c | 39 | |
6d4ca1fb SW |
40 | extern struct pinctrl * __must_check devm_pinctrl_get(struct device *dev); |
41 | extern void devm_pinctrl_put(struct pinctrl *p); | |
42 | ||
14005ee2 LW |
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) | |
49 | { | |
50 | return 0; | |
51 | } | |
52 | static inline int pinctrl_pm_select_sleep_state(struct device *dev) | |
53 | { | |
54 | return 0; | |
55 | } | |
56 | static inline int pinctrl_pm_select_idle_state(struct device *dev) | |
57 | { | |
58 | return 0; | |
59 | } | |
60 | #endif | |
61 | ||
befe5bdf | 62 | #else /* !CONFIG_PINCTRL */ |
28a8d14c | 63 | |
e93bcee0 | 64 | static inline int pinctrl_request_gpio(unsigned gpio) |
28a8d14c LW |
65 | { |
66 | return 0; | |
67 | } | |
68 | ||
e93bcee0 | 69 | static inline void pinctrl_free_gpio(unsigned gpio) |
28a8d14c LW |
70 | { |
71 | } | |
72 | ||
e93bcee0 | 73 | static inline int pinctrl_gpio_direction_input(unsigned gpio) |
28a8d14c LW |
74 | { |
75 | return 0; | |
76 | } | |
77 | ||
e93bcee0 | 78 | static inline int pinctrl_gpio_direction_output(unsigned gpio) |
28a8d14c LW |
79 | { |
80 | return 0; | |
81 | } | |
82 | ||
6e5e959d | 83 | static inline struct pinctrl * __must_check pinctrl_get(struct device *dev) |
28a8d14c LW |
84 | { |
85 | return NULL; | |
86 | } | |
87 | ||
e93bcee0 | 88 | static inline void pinctrl_put(struct pinctrl *p) |
28a8d14c LW |
89 | { |
90 | } | |
91 | ||
6e5e959d SW |
92 | static inline struct pinctrl_state * __must_check pinctrl_lookup_state( |
93 | struct pinctrl *p, | |
94 | const char *name) | |
28a8d14c | 95 | { |
6e5e959d | 96 | return NULL; |
28a8d14c LW |
97 | } |
98 | ||
6e5e959d SW |
99 | static inline int pinctrl_select_state(struct pinctrl *p, |
100 | struct pinctrl_state *s) | |
28a8d14c | 101 | { |
6e5e959d | 102 | return 0; |
28a8d14c LW |
103 | } |
104 | ||
6d4ca1fb SW |
105 | static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev) |
106 | { | |
107 | return NULL; | |
108 | } | |
109 | ||
110 | static inline void devm_pinctrl_put(struct pinctrl *p) | |
111 | { | |
112 | } | |
113 | ||
ff73ceed LW |
114 | static inline int pinctrl_pm_select_default_state(struct device *dev) |
115 | { | |
116 | return 0; | |
117 | } | |
118 | ||
119 | static inline int pinctrl_pm_select_sleep_state(struct device *dev) | |
120 | { | |
121 | return 0; | |
122 | } | |
123 | ||
124 | static inline int pinctrl_pm_select_idle_state(struct device *dev) | |
125 | { | |
126 | return 0; | |
127 | } | |
128 | ||
befe5bdf | 129 | #endif /* CONFIG_PINCTRL */ |
28a8d14c | 130 | |
6e5e959d SW |
131 | static inline struct pinctrl * __must_check pinctrl_get_select( |
132 | struct device *dev, const char *name) | |
133 | { | |
134 | struct pinctrl *p; | |
135 | struct pinctrl_state *s; | |
136 | int ret; | |
137 | ||
138 | p = pinctrl_get(dev); | |
139 | if (IS_ERR(p)) | |
140 | return p; | |
141 | ||
142 | s = pinctrl_lookup_state(p, name); | |
143 | if (IS_ERR(s)) { | |
144 | pinctrl_put(p); | |
145 | return ERR_PTR(PTR_ERR(s)); | |
146 | } | |
147 | ||
148 | ret = pinctrl_select_state(p, s); | |
149 | if (ret < 0) { | |
150 | pinctrl_put(p); | |
151 | return ERR_PTR(ret); | |
152 | } | |
153 | ||
154 | return p; | |
155 | } | |
156 | ||
157 | static inline struct pinctrl * __must_check pinctrl_get_select_default( | |
158 | struct device *dev) | |
159 | { | |
160 | return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT); | |
6d4ca1fb SW |
161 | } |
162 | ||
163 | static inline struct pinctrl * __must_check devm_pinctrl_get_select( | |
164 | struct device *dev, const char *name) | |
165 | { | |
166 | struct pinctrl *p; | |
167 | struct pinctrl_state *s; | |
168 | int ret; | |
169 | ||
170 | p = devm_pinctrl_get(dev); | |
171 | if (IS_ERR(p)) | |
172 | return p; | |
173 | ||
174 | s = pinctrl_lookup_state(p, name); | |
175 | if (IS_ERR(s)) { | |
176 | devm_pinctrl_put(p); | |
e60bc2df | 177 | return ERR_CAST(s); |
6d4ca1fb SW |
178 | } |
179 | ||
180 | ret = pinctrl_select_state(p, s); | |
181 | if (ret < 0) { | |
182 | devm_pinctrl_put(p); | |
183 | return ERR_PTR(ret); | |
184 | } | |
185 | ||
186 | return p; | |
187 | } | |
188 | ||
189 | static inline struct pinctrl * __must_check devm_pinctrl_get_select_default( | |
190 | struct device *dev) | |
191 | { | |
192 | return devm_pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT); | |
6e5e959d SW |
193 | } |
194 | ||
28a8d14c LW |
195 | #ifdef CONFIG_PINCONF |
196 | ||
197 | extern int pin_config_get(const char *dev_name, const char *name, | |
198 | unsigned long *config); | |
199 | extern int pin_config_set(const char *dev_name, const char *name, | |
200 | unsigned long config); | |
201 | extern int pin_config_group_get(const char *dev_name, | |
202 | const char *pin_group, | |
203 | unsigned long *config); | |
204 | extern int pin_config_group_set(const char *dev_name, | |
205 | const char *pin_group, | |
206 | unsigned long config); | |
207 | ||
208 | #else | |
209 | ||
210 | static inline int pin_config_get(const char *dev_name, const char *name, | |
211 | unsigned long *config) | |
212 | { | |
213 | return 0; | |
214 | } | |
215 | ||
216 | static inline int pin_config_set(const char *dev_name, const char *name, | |
217 | unsigned long config) | |
218 | { | |
219 | return 0; | |
220 | } | |
221 | ||
222 | static inline int pin_config_group_get(const char *dev_name, | |
223 | const char *pin_group, | |
224 | unsigned long *config) | |
225 | { | |
226 | return 0; | |
227 | } | |
228 | ||
229 | static inline int pin_config_group_set(const char *dev_name, | |
230 | const char *pin_group, | |
231 | unsigned long config) | |
232 | { | |
233 | return 0; | |
234 | } | |
235 | ||
236 | #endif | |
237 | ||
238 | #endif /* __LINUX_PINCTRL_CONSUMER_H */ |