Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 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 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 15 | #include <linux/err.h> |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 16 | #include <linux/list.h> |
| 17 | #include <linux/seq_file.h> |
David Howells | a1ce392 | 2012-10-02 18:01:25 +0100 | [diff] [blame] | 18 | #include <linux/pinctrl/pinctrl-state.h> |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 19 | |
| 20 | /* This struct is private to the core and should be regarded as a cookie */ |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 21 | struct pinctrl; |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 22 | struct pinctrl_state; |
Richard Genoud | ac5aa7f | 2012-08-10 16:52:58 +0200 | [diff] [blame] | 23 | struct device; |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 24 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 25 | #ifdef CONFIG_PINCTRL |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 26 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 27 | /* External interface to pin control */ |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 28 | extern int pinctrl_request_gpio(unsigned gpio); |
| 29 | extern void pinctrl_free_gpio(unsigned gpio); |
| 30 | extern int pinctrl_gpio_direction_input(unsigned gpio); |
| 31 | extern int pinctrl_gpio_direction_output(unsigned gpio); |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 32 | |
| 33 | extern struct pinctrl * __must_check pinctrl_get(struct device *dev); |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 34 | extern void pinctrl_put(struct pinctrl *p); |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 35 | extern struct pinctrl_state * __must_check pinctrl_lookup_state( |
| 36 | struct pinctrl *p, |
| 37 | const char *name); |
| 38 | extern int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *s); |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 39 | |
Stephen Warren | 6d4ca1f | 2012-04-16 10:51:00 -0600 | [diff] [blame] | 40 | extern struct pinctrl * __must_check devm_pinctrl_get(struct device *dev); |
| 41 | extern void devm_pinctrl_put(struct pinctrl *p); |
| 42 | |
Linus Walleij | 14005ee | 2013-06-05 15:30:33 +0200 | [diff] [blame^] | 43 | #ifdef CONFIG_PM |
| 44 | extern int pinctrl_pm_select_default_state(struct device *dev); |
| 45 | extern int pinctrl_pm_select_sleep_state(struct device *dev); |
| 46 | extern int pinctrl_pm_select_idle_state(struct device *dev); |
| 47 | #else |
| 48 | static inline int pinctrl_pm_select_default_state(struct device *dev) |
| 49 | { |
| 50 | return 0; |
| 51 | } |
| 52 | static inline int pinctrl_pm_select_sleep_state(struct device *dev) |
| 53 | { |
| 54 | return 0; |
| 55 | } |
| 56 | static inline int pinctrl_pm_select_idle_state(struct device *dev) |
| 57 | { |
| 58 | return 0; |
| 59 | } |
| 60 | #endif |
| 61 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 62 | #else /* !CONFIG_PINCTRL */ |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 63 | |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 64 | static inline int pinctrl_request_gpio(unsigned gpio) |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 65 | { |
| 66 | return 0; |
| 67 | } |
| 68 | |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 69 | static inline void pinctrl_free_gpio(unsigned gpio) |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 70 | { |
| 71 | } |
| 72 | |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 73 | static inline int pinctrl_gpio_direction_input(unsigned gpio) |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 74 | { |
| 75 | return 0; |
| 76 | } |
| 77 | |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 78 | static inline int pinctrl_gpio_direction_output(unsigned gpio) |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 79 | { |
| 80 | return 0; |
| 81 | } |
| 82 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 83 | static inline struct pinctrl * __must_check pinctrl_get(struct device *dev) |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 84 | { |
| 85 | return NULL; |
| 86 | } |
| 87 | |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 88 | static inline void pinctrl_put(struct pinctrl *p) |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 89 | { |
| 90 | } |
| 91 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 92 | static inline struct pinctrl_state * __must_check pinctrl_lookup_state( |
| 93 | struct pinctrl *p, |
| 94 | const char *name) |
| 95 | { |
| 96 | return NULL; |
| 97 | } |
| 98 | |
| 99 | static inline int pinctrl_select_state(struct pinctrl *p, |
| 100 | struct pinctrl_state *s) |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 101 | { |
| 102 | return 0; |
| 103 | } |
| 104 | |
Stephen Warren | 6d4ca1f | 2012-04-16 10:51:00 -0600 | [diff] [blame] | 105 | static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev) |
| 106 | { |
| 107 | return NULL; |
| 108 | } |
| 109 | |
| 110 | static inline void devm_pinctrl_put(struct pinctrl *p) |
| 111 | { |
| 112 | } |
| 113 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 114 | #endif /* CONFIG_PINCTRL */ |
| 115 | |
| 116 | static inline struct pinctrl * __must_check pinctrl_get_select( |
| 117 | struct device *dev, const char *name) |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 118 | { |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 119 | struct pinctrl *p; |
| 120 | struct pinctrl_state *s; |
| 121 | int ret; |
| 122 | |
| 123 | p = pinctrl_get(dev); |
| 124 | if (IS_ERR(p)) |
| 125 | return p; |
| 126 | |
| 127 | s = pinctrl_lookup_state(p, name); |
| 128 | if (IS_ERR(s)) { |
| 129 | pinctrl_put(p); |
| 130 | return ERR_PTR(PTR_ERR(s)); |
| 131 | } |
| 132 | |
| 133 | ret = pinctrl_select_state(p, s); |
| 134 | if (ret < 0) { |
| 135 | pinctrl_put(p); |
| 136 | return ERR_PTR(ret); |
| 137 | } |
| 138 | |
| 139 | return p; |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 140 | } |
| 141 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 142 | static inline struct pinctrl * __must_check pinctrl_get_select_default( |
| 143 | struct device *dev) |
| 144 | { |
| 145 | return pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT); |
| 146 | } |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 147 | |
Stephen Warren | 6d4ca1f | 2012-04-16 10:51:00 -0600 | [diff] [blame] | 148 | static inline struct pinctrl * __must_check devm_pinctrl_get_select( |
| 149 | struct device *dev, const char *name) |
| 150 | { |
| 151 | struct pinctrl *p; |
| 152 | struct pinctrl_state *s; |
| 153 | int ret; |
| 154 | |
| 155 | p = devm_pinctrl_get(dev); |
| 156 | if (IS_ERR(p)) |
| 157 | return p; |
| 158 | |
| 159 | s = pinctrl_lookup_state(p, name); |
| 160 | if (IS_ERR(s)) { |
| 161 | devm_pinctrl_put(p); |
Uwe Kleine-König | e60bc2d | 2012-07-30 18:38:33 +0200 | [diff] [blame] | 162 | return ERR_CAST(s); |
Stephen Warren | 6d4ca1f | 2012-04-16 10:51:00 -0600 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | ret = pinctrl_select_state(p, s); |
| 166 | if (ret < 0) { |
| 167 | devm_pinctrl_put(p); |
| 168 | return ERR_PTR(ret); |
| 169 | } |
| 170 | |
| 171 | return p; |
| 172 | } |
| 173 | |
| 174 | static inline struct pinctrl * __must_check devm_pinctrl_get_select_default( |
| 175 | struct device *dev) |
| 176 | { |
| 177 | return devm_pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT); |
| 178 | } |
| 179 | |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 180 | #ifdef CONFIG_PINCONF |
| 181 | |
| 182 | extern int pin_config_get(const char *dev_name, const char *name, |
| 183 | unsigned long *config); |
| 184 | extern int pin_config_set(const char *dev_name, const char *name, |
| 185 | unsigned long config); |
| 186 | extern int pin_config_group_get(const char *dev_name, |
| 187 | const char *pin_group, |
| 188 | unsigned long *config); |
| 189 | extern int pin_config_group_set(const char *dev_name, |
| 190 | const char *pin_group, |
| 191 | unsigned long config); |
| 192 | |
| 193 | #else |
| 194 | |
| 195 | static inline int pin_config_get(const char *dev_name, const char *name, |
| 196 | unsigned long *config) |
| 197 | { |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | static inline int pin_config_set(const char *dev_name, const char *name, |
| 202 | unsigned long config) |
| 203 | { |
| 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | static inline int pin_config_group_get(const char *dev_name, |
| 208 | const char *pin_group, |
| 209 | unsigned long *config) |
| 210 | { |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | static inline int pin_config_group_set(const char *dev_name, |
| 215 | const char *pin_group, |
| 216 | unsigned long config) |
| 217 | { |
| 218 | return 0; |
| 219 | } |
| 220 | |
Linus Walleij | 14005ee | 2013-06-05 15:30:33 +0200 | [diff] [blame^] | 221 | static inline int pinctrl_pm_select_default_state(struct device *dev) |
| 222 | { |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | static inline int pinctrl_pm_select_sleep_state(struct device *dev) |
| 227 | { |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | static inline int pinctrl_pm_select_idle_state(struct device *dev) |
| 232 | { |
| 233 | return 0; |
| 234 | } |
| 235 | |
Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 236 | #endif |
| 237 | |
| 238 | #endif /* __LINUX_PINCTRL_CONSUMER_H */ |