blob: e9b7f4350844435daf050bd539de04d44fe4b6fa [file] [log] [blame]
Linus Walleij28a8d142012-02-09 01:52:22 +01001/*
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
Stephen Warren6e5e9592012-03-02 13:05:47 -070015#include <linux/err.h>
Linus Walleij28a8d142012-02-09 01:52:22 +010016#include <linux/list.h>
17#include <linux/seq_file.h>
Linus Walleij9a01be12012-03-06 21:15:51 +010018#include "pinctrl-state.h"
Linus Walleij28a8d142012-02-09 01:52:22 +010019
20/* This struct is private to the core and should be regarded as a cookie */
Linus Walleije93bcee2012-02-09 07:23:28 +010021struct pinctrl;
Stephen Warren6e5e9592012-03-02 13:05:47 -070022struct pinctrl_state;
Richard Genoudac5aa7f2012-08-10 16:52:58 +020023struct device;
Linus Walleij28a8d142012-02-09 01:52:22 +010024
Linus Walleijbefe5bd2012-02-09 19:47:48 +010025#ifdef CONFIG_PINCTRL
Linus Walleij28a8d142012-02-09 01:52:22 +010026
Linus Walleijbefe5bd2012-02-09 19:47:48 +010027/* External interface to pin control */
Linus Walleije93bcee2012-02-09 07:23:28 +010028extern 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);
Stephen Warren6e5e9592012-03-02 13:05:47 -070032
33extern struct pinctrl * __must_check pinctrl_get(struct device *dev);
Linus Walleije93bcee2012-02-09 07:23:28 +010034extern void pinctrl_put(struct pinctrl *p);
Stephen Warren6e5e9592012-03-02 13:05:47 -070035extern 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);
Linus Walleij28a8d142012-02-09 01:52:22 +010039
Stephen Warren6d4ca1f2012-04-16 10:51:00 -060040extern struct pinctrl * __must_check devm_pinctrl_get(struct device *dev);
41extern void devm_pinctrl_put(struct pinctrl *p);
42
Linus Walleijbefe5bd2012-02-09 19:47:48 +010043#else /* !CONFIG_PINCTRL */
Linus Walleij28a8d142012-02-09 01:52:22 +010044
Linus Walleije93bcee2012-02-09 07:23:28 +010045static inline int pinctrl_request_gpio(unsigned gpio)
Linus Walleij28a8d142012-02-09 01:52:22 +010046{
47 return 0;
48}
49
Linus Walleije93bcee2012-02-09 07:23:28 +010050static inline void pinctrl_free_gpio(unsigned gpio)
Linus Walleij28a8d142012-02-09 01:52:22 +010051{
52}
53
Linus Walleije93bcee2012-02-09 07:23:28 +010054static inline int pinctrl_gpio_direction_input(unsigned gpio)
Linus Walleij28a8d142012-02-09 01:52:22 +010055{
56 return 0;
57}
58
Linus Walleije93bcee2012-02-09 07:23:28 +010059static inline int pinctrl_gpio_direction_output(unsigned gpio)
Linus Walleij28a8d142012-02-09 01:52:22 +010060{
61 return 0;
62}
63
Stephen Warren6e5e9592012-03-02 13:05:47 -070064static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
Linus Walleij28a8d142012-02-09 01:52:22 +010065{
66 return NULL;
67}
68
Linus Walleije93bcee2012-02-09 07:23:28 +010069static inline void pinctrl_put(struct pinctrl *p)
Linus Walleij28a8d142012-02-09 01:52:22 +010070{
71}
72
Stephen Warren6e5e9592012-03-02 13:05:47 -070073static inline struct pinctrl_state * __must_check pinctrl_lookup_state(
74 struct pinctrl *p,
75 const char *name)
76{
77 return NULL;
78}
79
80static inline int pinctrl_select_state(struct pinctrl *p,
81 struct pinctrl_state *s)
Linus Walleij28a8d142012-02-09 01:52:22 +010082{
83 return 0;
84}
85
Stephen Warren6d4ca1f2012-04-16 10:51:00 -060086static 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
Stephen Warren6e5e9592012-03-02 13:05:47 -070095#endif /* CONFIG_PINCTRL */
96
97static inline struct pinctrl * __must_check pinctrl_get_select(
98 struct device *dev, const char *name)
Linus Walleij28a8d142012-02-09 01:52:22 +010099{
Stephen Warren6e5e9592012-03-02 13:05:47 -0700100 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;
Linus Walleij28a8d142012-02-09 01:52:22 +0100121}
122
Stephen Warren6e5e9592012-03-02 13:05:47 -0700123static inline struct pinctrl * __must_check pinctrl_get_select_default(
124 struct device *dev)
125{
126 return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
127}
Linus Walleij28a8d142012-02-09 01:52:22 +0100128
Stephen Warren6d4ca1f2012-04-16 10:51:00 -0600129static 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_PTR(PTR_ERR(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
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);
159}
160
Linus Walleij28a8d142012-02-09 01:52:22 +0100161#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 */