blob: 6dd96fb45482b00b0ede76c92f83fc6bd76f0f2f [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;
Linus Walleij28a8d142012-02-09 01:52:22 +010023
Linus Walleijbefe5bd2012-02-09 19:47:48 +010024#ifdef CONFIG_PINCTRL
Linus Walleij28a8d142012-02-09 01:52:22 +010025
Linus Walleijbefe5bd2012-02-09 19:47:48 +010026/* External interface to pin control */
Linus Walleije93bcee2012-02-09 07:23:28 +010027extern int pinctrl_request_gpio(unsigned gpio);
28extern void pinctrl_free_gpio(unsigned gpio);
29extern int pinctrl_gpio_direction_input(unsigned gpio);
30extern int pinctrl_gpio_direction_output(unsigned gpio);
Stephen Warren6e5e9592012-03-02 13:05:47 -070031
32extern struct pinctrl * __must_check pinctrl_get(struct device *dev);
Linus Walleije93bcee2012-02-09 07:23:28 +010033extern void pinctrl_put(struct pinctrl *p);
Stephen Warren6e5e9592012-03-02 13:05:47 -070034extern struct pinctrl_state * __must_check pinctrl_lookup_state(
35 struct pinctrl *p,
36 const char *name);
37extern int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *s);
Linus Walleij28a8d142012-02-09 01:52:22 +010038
Stephen Warren6d4ca1f2012-04-16 10:51:00 -060039extern struct pinctrl * __must_check devm_pinctrl_get(struct device *dev);
40extern void devm_pinctrl_put(struct pinctrl *p);
41
Linus Walleijbefe5bd2012-02-09 19:47:48 +010042#else /* !CONFIG_PINCTRL */
Linus Walleij28a8d142012-02-09 01:52:22 +010043
Linus Walleije93bcee2012-02-09 07:23:28 +010044static inline int pinctrl_request_gpio(unsigned gpio)
Linus Walleij28a8d142012-02-09 01:52:22 +010045{
46 return 0;
47}
48
Linus Walleije93bcee2012-02-09 07:23:28 +010049static inline void pinctrl_free_gpio(unsigned gpio)
Linus Walleij28a8d142012-02-09 01:52:22 +010050{
51}
52
Linus Walleije93bcee2012-02-09 07:23:28 +010053static inline int pinctrl_gpio_direction_input(unsigned gpio)
Linus Walleij28a8d142012-02-09 01:52:22 +010054{
55 return 0;
56}
57
Linus Walleije93bcee2012-02-09 07:23:28 +010058static inline int pinctrl_gpio_direction_output(unsigned gpio)
Linus Walleij28a8d142012-02-09 01:52:22 +010059{
60 return 0;
61}
62
Stephen Warren6e5e9592012-03-02 13:05:47 -070063static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
Linus Walleij28a8d142012-02-09 01:52:22 +010064{
65 return NULL;
66}
67
Linus Walleije93bcee2012-02-09 07:23:28 +010068static inline void pinctrl_put(struct pinctrl *p)
Linus Walleij28a8d142012-02-09 01:52:22 +010069{
70}
71
Stephen Warren6e5e9592012-03-02 13:05:47 -070072static inline struct pinctrl_state * __must_check pinctrl_lookup_state(
73 struct pinctrl *p,
74 const char *name)
75{
76 return NULL;
77}
78
79static inline int pinctrl_select_state(struct pinctrl *p,
80 struct pinctrl_state *s)
Linus Walleij28a8d142012-02-09 01:52:22 +010081{
82 return 0;
83}
84
Stephen Warren6d4ca1f2012-04-16 10:51:00 -060085static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev)
86{
87 return NULL;
88}
89
90static inline void devm_pinctrl_put(struct pinctrl *p)
91{
92}
93
Stephen Warren6e5e9592012-03-02 13:05:47 -070094#endif /* CONFIG_PINCTRL */
95
96static inline struct pinctrl * __must_check pinctrl_get_select(
97 struct device *dev, const char *name)
Linus Walleij28a8d142012-02-09 01:52:22 +010098{
Stephen Warren6e5e9592012-03-02 13:05:47 -070099 struct pinctrl *p;
100 struct pinctrl_state *s;
101 int ret;
102
103 p = pinctrl_get(dev);
104 if (IS_ERR(p))
105 return p;
106
107 s = pinctrl_lookup_state(p, name);
108 if (IS_ERR(s)) {
109 pinctrl_put(p);
110 return ERR_PTR(PTR_ERR(s));
111 }
112
113 ret = pinctrl_select_state(p, s);
114 if (ret < 0) {
115 pinctrl_put(p);
116 return ERR_PTR(ret);
117 }
118
119 return p;
Linus Walleij28a8d142012-02-09 01:52:22 +0100120}
121
Stephen Warren6e5e9592012-03-02 13:05:47 -0700122static inline struct pinctrl * __must_check pinctrl_get_select_default(
123 struct device *dev)
124{
125 return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
126}
Linus Walleij28a8d142012-02-09 01:52:22 +0100127
Stephen Warren6d4ca1f2012-04-16 10:51:00 -0600128static inline struct pinctrl * __must_check devm_pinctrl_get_select(
129 struct device *dev, const char *name)
130{
131 struct pinctrl *p;
132 struct pinctrl_state *s;
133 int ret;
134
135 p = devm_pinctrl_get(dev);
136 if (IS_ERR(p))
137 return p;
138
139 s = pinctrl_lookup_state(p, name);
140 if (IS_ERR(s)) {
141 devm_pinctrl_put(p);
142 return ERR_PTR(PTR_ERR(s));
143 }
144
145 ret = pinctrl_select_state(p, s);
146 if (ret < 0) {
147 devm_pinctrl_put(p);
148 return ERR_PTR(ret);
149 }
150
151 return p;
152}
153
154static inline struct pinctrl * __must_check devm_pinctrl_get_select_default(
155 struct device *dev)
156{
157 return devm_pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
158}
159
Linus Walleij28a8d142012-02-09 01:52:22 +0100160#ifdef CONFIG_PINCONF
161
162extern int pin_config_get(const char *dev_name, const char *name,
163 unsigned long *config);
164extern int pin_config_set(const char *dev_name, const char *name,
165 unsigned long config);
166extern int pin_config_group_get(const char *dev_name,
167 const char *pin_group,
168 unsigned long *config);
169extern int pin_config_group_set(const char *dev_name,
170 const char *pin_group,
171 unsigned long config);
172
173#else
174
175static inline int pin_config_get(const char *dev_name, const char *name,
176 unsigned long *config)
177{
178 return 0;
179}
180
181static inline int pin_config_set(const char *dev_name, const char *name,
182 unsigned long config)
183{
184 return 0;
185}
186
187static inline int pin_config_group_get(const char *dev_name,
188 const char *pin_group,
189 unsigned long *config)
190{
191 return 0;
192}
193
194static inline int pin_config_group_set(const char *dev_name,
195 const char *pin_group,
196 unsigned long config)
197{
198 return 0;
199}
200
201#endif
202
203#endif /* __LINUX_PINCTRL_CONSUMER_H */