1
2
3
4
5
6
7
8
9
10
11#ifndef __LINUX_PINCTRL_CONSUMER_H
12#define __LINUX_PINCTRL_CONSUMER_H
13
14#include <linux/err.h>
15#include <linux/list.h>
16#include <linux/seq_file.h>
17#include <linux/pinctrl/pinctrl-state.h>
18
19
20struct pinctrl;
21struct pinctrl_state;
22struct device;
23
24#ifdef CONFIG_PINCTRL
25
26
27extern bool pinctrl_gpio_can_use_line(unsigned gpio);
28extern int pinctrl_gpio_request(unsigned gpio);
29extern void pinctrl_gpio_free(unsigned gpio);
30extern int pinctrl_gpio_direction_input(unsigned gpio);
31extern int pinctrl_gpio_direction_output(unsigned gpio);
32extern int pinctrl_gpio_set_config(unsigned gpio, unsigned long config);
33
34extern struct pinctrl * __must_check pinctrl_get(struct device *dev);
35extern void pinctrl_put(struct pinctrl *p);
36extern struct pinctrl_state * __must_check pinctrl_lookup_state(
37 struct pinctrl *p,
38 const char *name);
39extern int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *s);
40
41extern struct pinctrl * __must_check devm_pinctrl_get(struct device *dev);
42extern void devm_pinctrl_put(struct pinctrl *p);
43
44#ifdef CONFIG_PM
45extern int pinctrl_pm_select_default_state(struct device *dev);
46extern int pinctrl_pm_select_sleep_state(struct device *dev);
47extern int pinctrl_pm_select_idle_state(struct device *dev);
48#else
49static inline int pinctrl_pm_select_default_state(struct device *dev)
50{
51 return 0;
52}
53static inline int pinctrl_pm_select_sleep_state(struct device *dev)
54{
55 return 0;
56}
57static inline int pinctrl_pm_select_idle_state(struct device *dev)
58{
59 return 0;
60}
61#endif
62
63#else
64
65static inline bool pinctrl_gpio_can_use_line(unsigned gpio)
66{
67 return true;
68}
69
70static inline int pinctrl_gpio_request(unsigned gpio)
71{
72 return 0;
73}
74
75static inline void pinctrl_gpio_free(unsigned gpio)
76{
77}
78
79static inline int pinctrl_gpio_direction_input(unsigned gpio)
80{
81 return 0;
82}
83
84static inline int pinctrl_gpio_direction_output(unsigned gpio)
85{
86 return 0;
87}
88
89static inline int pinctrl_gpio_set_config(unsigned gpio, unsigned long config)
90{
91 return 0;
92}
93
94static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
95{
96 return NULL;
97}
98
99static inline void pinctrl_put(struct pinctrl *p)
100{
101}
102
103static inline struct pinctrl_state * __must_check pinctrl_lookup_state(
104 struct pinctrl *p,
105 const char *name)
106{
107 return NULL;
108}
109
110static inline int pinctrl_select_state(struct pinctrl *p,
111 struct pinctrl_state *s)
112{
113 return 0;
114}
115
116static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev)
117{
118 return NULL;
119}
120
121static inline void devm_pinctrl_put(struct pinctrl *p)
122{
123}
124
125static inline int pinctrl_pm_select_default_state(struct device *dev)
126{
127 return 0;
128}
129
130static inline int pinctrl_pm_select_sleep_state(struct device *dev)
131{
132 return 0;
133}
134
135static inline int pinctrl_pm_select_idle_state(struct device *dev)
136{
137 return 0;
138}
139
140#endif
141
142static inline struct pinctrl * __must_check pinctrl_get_select(
143 struct device *dev, const char *name)
144{
145 struct pinctrl *p;
146 struct pinctrl_state *s;
147 int ret;
148
149 p = pinctrl_get(dev);
150 if (IS_ERR(p))
151 return p;
152
153 s = pinctrl_lookup_state(p, name);
154 if (IS_ERR(s)) {
155 pinctrl_put(p);
156 return ERR_CAST(s);
157 }
158
159 ret = pinctrl_select_state(p, s);
160 if (ret < 0) {
161 pinctrl_put(p);
162 return ERR_PTR(ret);
163 }
164
165 return p;
166}
167
168static inline struct pinctrl * __must_check pinctrl_get_select_default(
169 struct device *dev)
170{
171 return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
172}
173
174static inline struct pinctrl * __must_check devm_pinctrl_get_select(
175 struct device *dev, const char *name)
176{
177 struct pinctrl *p;
178 struct pinctrl_state *s;
179 int ret;
180
181 p = devm_pinctrl_get(dev);
182 if (IS_ERR(p))
183 return p;
184
185 s = pinctrl_lookup_state(p, name);
186 if (IS_ERR(s)) {
187 devm_pinctrl_put(p);
188 return ERR_CAST(s);
189 }
190
191 ret = pinctrl_select_state(p, s);
192 if (ret < 0) {
193 devm_pinctrl_put(p);
194 return ERR_PTR(ret);
195 }
196
197 return p;
198}
199
200static inline struct pinctrl * __must_check devm_pinctrl_get_select_default(
201 struct device *dev)
202{
203 return devm_pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
204}
205
206#endif
207