blob: 191e7268848170ad2a8889ba4c0a559860c75fa0 [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
Linus Walleijbefe5bd2012-02-09 19:47:48 +010039#else /* !CONFIG_PINCTRL */
Linus Walleij28a8d142012-02-09 01:52:22 +010040
Linus Walleije93bcee2012-02-09 07:23:28 +010041static inline int pinctrl_request_gpio(unsigned gpio)
Linus Walleij28a8d142012-02-09 01:52:22 +010042{
43 return 0;
44}
45
Linus Walleije93bcee2012-02-09 07:23:28 +010046static inline void pinctrl_free_gpio(unsigned gpio)
Linus Walleij28a8d142012-02-09 01:52:22 +010047{
48}
49
Linus Walleije93bcee2012-02-09 07:23:28 +010050static inline int pinctrl_gpio_direction_input(unsigned gpio)
Linus Walleij28a8d142012-02-09 01:52:22 +010051{
52 return 0;
53}
54
Linus Walleije93bcee2012-02-09 07:23:28 +010055static inline int pinctrl_gpio_direction_output(unsigned gpio)
Linus Walleij28a8d142012-02-09 01:52:22 +010056{
57 return 0;
58}
59
Stephen Warren6e5e9592012-03-02 13:05:47 -070060static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
Linus Walleij28a8d142012-02-09 01:52:22 +010061{
62 return NULL;
63}
64
Linus Walleije93bcee2012-02-09 07:23:28 +010065static inline void pinctrl_put(struct pinctrl *p)
Linus Walleij28a8d142012-02-09 01:52:22 +010066{
67}
68
Stephen Warren6e5e9592012-03-02 13:05:47 -070069static inline struct pinctrl_state * __must_check pinctrl_lookup_state(
70 struct pinctrl *p,
71 const char *name)
72{
73 return NULL;
74}
75
76static inline int pinctrl_select_state(struct pinctrl *p,
77 struct pinctrl_state *s)
Linus Walleij28a8d142012-02-09 01:52:22 +010078{
79 return 0;
80}
81
Stephen Warren6e5e9592012-03-02 13:05:47 -070082#endif /* CONFIG_PINCTRL */
83
84static inline struct pinctrl * __must_check pinctrl_get_select(
85 struct device *dev, const char *name)
Linus Walleij28a8d142012-02-09 01:52:22 +010086{
Stephen Warren6e5e9592012-03-02 13:05:47 -070087 struct pinctrl *p;
88 struct pinctrl_state *s;
89 int ret;
90
91 p = pinctrl_get(dev);
92 if (IS_ERR(p))
93 return p;
94
95 s = pinctrl_lookup_state(p, name);
96 if (IS_ERR(s)) {
97 pinctrl_put(p);
98 return ERR_PTR(PTR_ERR(s));
99 }
100
101 ret = pinctrl_select_state(p, s);
102 if (ret < 0) {
103 pinctrl_put(p);
104 return ERR_PTR(ret);
105 }
106
107 return p;
Linus Walleij28a8d142012-02-09 01:52:22 +0100108}
109
Stephen Warren6e5e9592012-03-02 13:05:47 -0700110static inline struct pinctrl * __must_check pinctrl_get_select_default(
111 struct device *dev)
112{
113 return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT);
114}
Linus Walleij28a8d142012-02-09 01:52:22 +0100115
116#ifdef CONFIG_PINCONF
117
118extern int pin_config_get(const char *dev_name, const char *name,
119 unsigned long *config);
120extern int pin_config_set(const char *dev_name, const char *name,
121 unsigned long config);
122extern int pin_config_group_get(const char *dev_name,
123 const char *pin_group,
124 unsigned long *config);
125extern int pin_config_group_set(const char *dev_name,
126 const char *pin_group,
127 unsigned long config);
128
129#else
130
131static inline int pin_config_get(const char *dev_name, const char *name,
132 unsigned long *config)
133{
134 return 0;
135}
136
137static inline int pin_config_set(const char *dev_name, const char *name,
138 unsigned long config)
139{
140 return 0;
141}
142
143static inline int pin_config_group_get(const char *dev_name,
144 const char *pin_group,
145 unsigned long *config)
146{
147 return 0;
148}
149
150static inline int pin_config_group_set(const char *dev_name,
151 const char *pin_group,
152 unsigned long config)
153{
154 return 0;
155}
156
157#endif
158
159#endif /* __LINUX_PINCTRL_CONSUMER_H */