]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/pinctrl/consumer.h
Merge tag 'uapi-prep-20121002' of git://git.infradead.org/users/dhowells/linux-headers
[mirror_ubuntu-bionic-kernel.git] / include / linux / pinctrl / consumer.h
CommitLineData
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 21struct pinctrl;
6e5e959d 22struct pinctrl_state;
ac5aa7f9 23struct device;
28a8d14c 24
befe5bdf 25#ifdef CONFIG_PINCTRL
28a8d14c 26
befe5bdf 27/* External interface to pin control */
e93bcee0
LW
28extern int pinctrl_request_gpio(unsigned gpio);
29extern void pinctrl_free_gpio(unsigned gpio);
30extern int pinctrl_gpio_direction_input(unsigned gpio);
31extern int pinctrl_gpio_direction_output(unsigned gpio);
6e5e959d
SW
32
33extern struct pinctrl * __must_check pinctrl_get(struct device *dev);
e93bcee0 34extern void pinctrl_put(struct pinctrl *p);
6e5e959d
SW
35extern struct pinctrl_state * __must_check pinctrl_lookup_state(
36 struct pinctrl *p,
37 const char *name);
38extern int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *s);
28a8d14c 39
6d4ca1fb
SW
40extern struct pinctrl * __must_check devm_pinctrl_get(struct device *dev);
41extern void devm_pinctrl_put(struct pinctrl *p);
42
befe5bdf 43#else /* !CONFIG_PINCTRL */
28a8d14c 44
e93bcee0 45static inline int pinctrl_request_gpio(unsigned gpio)
28a8d14c
LW
46{
47 return 0;
48}
49
e93bcee0 50static inline void pinctrl_free_gpio(unsigned gpio)
28a8d14c
LW
51{
52}
53
e93bcee0 54static inline int pinctrl_gpio_direction_input(unsigned gpio)
28a8d14c
LW
55{
56 return 0;
57}
58
e93bcee0 59static inline int pinctrl_gpio_direction_output(unsigned gpio)
28a8d14c
LW
60{
61 return 0;
62}
63
6e5e959d 64static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
28a8d14c
LW
65{
66 return NULL;
67}
68
e93bcee0 69static inline void pinctrl_put(struct pinctrl *p)
28a8d14c
LW
70{
71}
72
6e5e959d
SW
73static inline struct pinctrl_state * __must_check pinctrl_lookup_state(
74 struct pinctrl *p,
75 const char *name)
28a8d14c 76{
6e5e959d 77 return NULL;
28a8d14c
LW
78}
79
6e5e959d
SW
80static inline int pinctrl_select_state(struct pinctrl *p,
81 struct pinctrl_state *s)
28a8d14c 82{
6e5e959d 83 return 0;
28a8d14c
LW
84}
85
6d4ca1fb
SW
86static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev)
87{
88 return NULL;
89}
90
91static inline void devm_pinctrl_put(struct pinctrl *p)
92{
93}
94
befe5bdf 95#endif /* CONFIG_PINCTRL */
28a8d14c 96
6e5e959d
SW
97static 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
123static inline struct pinctrl * __must_check pinctrl_get_select_default(
124 struct device *dev)
125{
126 return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
6d4ca1fb
SW
127}
128
129static 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);
e60bc2df 143 return ERR_CAST(s);
6d4ca1fb
SW
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
155static 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);
6e5e959d
SW
159}
160
28a8d14c
LW
161#ifdef CONFIG_PINCONF
162
163extern int pin_config_get(const char *dev_name, const char *name,
164 unsigned long *config);
165extern int pin_config_set(const char *dev_name, const char *name,
166 unsigned long config);
167extern int pin_config_group_get(const char *dev_name,
168 const char *pin_group,
169 unsigned long *config);
170extern int pin_config_group_set(const char *dev_name,
171 const char *pin_group,
172 unsigned long config);
173
174#else
175
176static inline int pin_config_get(const char *dev_name, const char *name,
177 unsigned long *config)
178{
179 return 0;
180}
181
182static inline int pin_config_set(const char *dev_name, const char *name,
183 unsigned long config)
184{
185 return 0;
186}
187
188static 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
195static 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 */