blob: 18eccefea06e40a0ea10f77e857105c6feaf4ff9 [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>
David Howellsa1ce3922012-10-02 18:01:25 +010018#include <linux/pinctrl/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 Walleij14005ee2013-06-05 15:30:33 +020043#ifdef CONFIG_PM
44extern int pinctrl_pm_select_default_state(struct device *dev);
45extern int pinctrl_pm_select_sleep_state(struct device *dev);
46extern int pinctrl_pm_select_idle_state(struct device *dev);
47#else
48static inline int pinctrl_pm_select_default_state(struct device *dev)
49{
50 return 0;
51}
52static inline int pinctrl_pm_select_sleep_state(struct device *dev)
53{
54 return 0;
55}
56static inline int pinctrl_pm_select_idle_state(struct device *dev)
57{
58 return 0;
59}
60#endif
61
Linus Walleijbefe5bd2012-02-09 19:47:48 +010062#else /* !CONFIG_PINCTRL */
Linus Walleij28a8d142012-02-09 01:52:22 +010063
Linus Walleije93bcee2012-02-09 07:23:28 +010064static inline int pinctrl_request_gpio(unsigned gpio)
Linus Walleij28a8d142012-02-09 01:52:22 +010065{
66 return 0;
67}
68
Linus Walleije93bcee2012-02-09 07:23:28 +010069static inline void pinctrl_free_gpio(unsigned gpio)
Linus Walleij28a8d142012-02-09 01:52:22 +010070{
71}
72
Linus Walleije93bcee2012-02-09 07:23:28 +010073static inline int pinctrl_gpio_direction_input(unsigned gpio)
Linus Walleij28a8d142012-02-09 01:52:22 +010074{
75 return 0;
76}
77
Linus Walleije93bcee2012-02-09 07:23:28 +010078static inline int pinctrl_gpio_direction_output(unsigned gpio)
Linus Walleij28a8d142012-02-09 01:52:22 +010079{
80 return 0;
81}
82
Stephen Warren6e5e9592012-03-02 13:05:47 -070083static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
Linus Walleij28a8d142012-02-09 01:52:22 +010084{
Linus Walleij40eeb112015-03-05 10:08:14 +010085 return NULL;
Linus Walleij28a8d142012-02-09 01:52:22 +010086}
87
Linus Walleije93bcee2012-02-09 07:23:28 +010088static inline void pinctrl_put(struct pinctrl *p)
Linus Walleij28a8d142012-02-09 01:52:22 +010089{
90}
91
Stephen Warren6e5e9592012-03-02 13:05:47 -070092static inline struct pinctrl_state * __must_check pinctrl_lookup_state(
93 struct pinctrl *p,
94 const char *name)
95{
Linus Walleij40eeb112015-03-05 10:08:14 +010096 return NULL;
Stephen Warren6e5e9592012-03-02 13:05:47 -070097}
98
99static inline int pinctrl_select_state(struct pinctrl *p,
100 struct pinctrl_state *s)
Linus Walleij28a8d142012-02-09 01:52:22 +0100101{
102 return 0;
103}
104
Stephen Warren6d4ca1f2012-04-16 10:51:00 -0600105static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev)
106{
Linus Walleij40eeb112015-03-05 10:08:14 +0100107 return NULL;
Stephen Warren6d4ca1f2012-04-16 10:51:00 -0600108}
109
110static inline void devm_pinctrl_put(struct pinctrl *p)
111{
112}
113
Linus Walleijff73cee2013-06-13 22:27:59 +0200114static inline int pinctrl_pm_select_default_state(struct device *dev)
115{
116 return 0;
117}
118
119static inline int pinctrl_pm_select_sleep_state(struct device *dev)
120{
121 return 0;
122}
123
124static inline int pinctrl_pm_select_idle_state(struct device *dev)
125{
126 return 0;
127}
128
Stephen Warren6e5e9592012-03-02 13:05:47 -0700129#endif /* CONFIG_PINCTRL */
130
131static inline struct pinctrl * __must_check pinctrl_get_select(
132 struct device *dev, const char *name)
Linus Walleij28a8d142012-02-09 01:52:22 +0100133{
Stephen Warren6e5e9592012-03-02 13:05:47 -0700134 struct pinctrl *p;
135 struct pinctrl_state *s;
136 int ret;
137
138 p = pinctrl_get(dev);
139 if (IS_ERR(p))
140 return p;
141
142 s = pinctrl_lookup_state(p, name);
143 if (IS_ERR(s)) {
144 pinctrl_put(p);
145 return ERR_PTR(PTR_ERR(s));
146 }
147
148 ret = pinctrl_select_state(p, s);
149 if (ret < 0) {
150 pinctrl_put(p);
151 return ERR_PTR(ret);
152 }
153
154 return p;
Linus Walleij28a8d142012-02-09 01:52:22 +0100155}
156
Stephen Warren6e5e9592012-03-02 13:05:47 -0700157static inline struct pinctrl * __must_check pinctrl_get_select_default(
158 struct device *dev)
159{
160 return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
161}
Linus Walleij28a8d142012-02-09 01:52:22 +0100162
Stephen Warren6d4ca1f2012-04-16 10:51:00 -0600163static inline struct pinctrl * __must_check devm_pinctrl_get_select(
164 struct device *dev, const char *name)
165{
166 struct pinctrl *p;
167 struct pinctrl_state *s;
168 int ret;
169
170 p = devm_pinctrl_get(dev);
171 if (IS_ERR(p))
172 return p;
173
174 s = pinctrl_lookup_state(p, name);
175 if (IS_ERR(s)) {
176 devm_pinctrl_put(p);
Uwe Kleine-Könige60bc2d2012-07-30 18:38:33 +0200177 return ERR_CAST(s);
Stephen Warren6d4ca1f2012-04-16 10:51:00 -0600178 }
179
180 ret = pinctrl_select_state(p, s);
181 if (ret < 0) {
182 devm_pinctrl_put(p);
183 return ERR_PTR(ret);
184 }
185
186 return p;
187}
188
189static inline struct pinctrl * __must_check devm_pinctrl_get_select_default(
190 struct device *dev)
191{
192 return devm_pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
193}
194
Linus Walleij28a8d142012-02-09 01:52:22 +0100195#endif /* __LINUX_PINCTRL_CONSUMER_H */