Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
consumer.h
Go to the documentation of this file.
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 <[email protected]>
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 
15 #include <linux/err.h>
16 #include <linux/list.h>
17 #include <linux/seq_file.h>
19 
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;
24 
25 #ifdef CONFIG_PINCTRL
26 
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);
32 
33 extern struct pinctrl * __must_check pinctrl_get(struct device *dev);
34 extern void pinctrl_put(struct pinctrl *p);
36  struct pinctrl *p,
37  const char *name);
38 extern int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *s);
39 
40 extern struct pinctrl * __must_check devm_pinctrl_get(struct device *dev);
41 extern void devm_pinctrl_put(struct pinctrl *p);
42 
43 #else /* !CONFIG_PINCTRL */
44 
45 static inline int pinctrl_request_gpio(unsigned gpio)
46 {
47  return 0;
48 }
49 
50 static inline void pinctrl_free_gpio(unsigned gpio)
51 {
52 }
53 
54 static inline int pinctrl_gpio_direction_input(unsigned gpio)
55 {
56  return 0;
57 }
58 
59 static inline int pinctrl_gpio_direction_output(unsigned gpio)
60 {
61  return 0;
62 }
63 
64 static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
65 {
66  return NULL;
67 }
68 
69 static inline void pinctrl_put(struct pinctrl *p)
70 {
71 }
72 
73 static inline struct pinctrl_state * __must_check pinctrl_lookup_state(
74  struct pinctrl *p,
75  const char *name)
76 {
77  return NULL;
78 }
79 
80 static inline int pinctrl_select_state(struct pinctrl *p,
81  struct pinctrl_state *s)
82 {
83  return 0;
84 }
85 
86 static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev)
87 {
88  return NULL;
89 }
90 
91 static inline void devm_pinctrl_put(struct pinctrl *p)
92 {
93 }
94 
95 #endif /* CONFIG_PINCTRL */
96 
97 static inline struct pinctrl * __must_check pinctrl_get_select(
98  struct device *dev, const char *name)
99 {
100  struct pinctrl *p;
101  struct pinctrl_state *s;
102  int ret;
103 
104  p = pinctrl_get(dev);
105  if (IS_ERR(p))
106  return p;
107 
108  s = pinctrl_lookup_state(p, name);
109  if (IS_ERR(s)) {
110  pinctrl_put(p);
111  return ERR_PTR(PTR_ERR(s));
112  }
113 
114  ret = pinctrl_select_state(p, s);
115  if (ret < 0) {
116  pinctrl_put(p);
117  return ERR_PTR(ret);
118  }
119 
120  return p;
121 }
122 
123 static inline struct pinctrl * __must_check pinctrl_get_select_default(
124  struct device *dev)
125 {
126  return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
127 }
128 
129 static inline struct pinctrl * __must_check devm_pinctrl_get_select(
130  struct device *dev, const char *name)
131 {
132  struct pinctrl *p;
133  struct pinctrl_state *s;
134  int ret;
135 
136  p = devm_pinctrl_get(dev);
137  if (IS_ERR(p))
138  return p;
139 
140  s = pinctrl_lookup_state(p, name);
141  if (IS_ERR(s)) {
142  devm_pinctrl_put(p);
143  return ERR_CAST(s);
144  }
145 
146  ret = pinctrl_select_state(p, s);
147  if (ret < 0) {
148  devm_pinctrl_put(p);
149  return ERR_PTR(ret);
150  }
151 
152  return p;
153 }
154 
155 static inline struct pinctrl * __must_check devm_pinctrl_get_select_default(
156  struct device *dev)
157 {
158  return devm_pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
159 }
160 
161 #ifdef CONFIG_PINCONF
162 
163 extern int pin_config_get(const char *dev_name, const char *name,
164  unsigned long *config);
165 extern int pin_config_set(const char *dev_name, const char *name,
166  unsigned long config);
167 extern int pin_config_group_get(const char *dev_name,
168  const char *pin_group,
169  unsigned long *config);
170 extern int pin_config_group_set(const char *dev_name,
171  const char *pin_group,
172  unsigned long config);
173 
174 #else
175 
176 static inline int pin_config_get(const char *dev_name, const char *name,
177  unsigned long *config)
178 {
179  return 0;
180 }
181 
182 static inline int pin_config_set(const char *dev_name, const char *name,
183  unsigned long config)
184 {
185  return 0;
186 }
187 
188 static inline int pin_config_group_get(const char *dev_name,
189  const char *pin_group,
190  unsigned long *config)
191 {
192  return 0;
193 }
194 
195 static inline int pin_config_group_set(const char *dev_name,
196  const char *pin_group,
197  unsigned long config)
198 {
199  return 0;
200 }
201 
202 #endif
203 
204 #endif /* __LINUX_PINCTRL_CONSUMER_H */