| 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> | 
| Linus Walleij | 9a01be1 | 2012-03-06 21:15:51 +0100 | [diff] [blame] | 18 | #include "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 | 62e998a | 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 | 4be45fa | 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 | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 43 | #else /* !CONFIG_PINCTRL */ | 
| Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 44 |  | 
| Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 45 | static inline int pinctrl_request_gpio(unsigned gpio) | 
| Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 46 | { | 
 | 47 | 	return 0; | 
 | 48 | } | 
 | 49 |  | 
| Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 50 | static inline void pinctrl_free_gpio(unsigned gpio) | 
| Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 51 | { | 
 | 52 | } | 
 | 53 |  | 
| Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 54 | static inline int pinctrl_gpio_direction_input(unsigned gpio) | 
| Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 55 | { | 
 | 56 | 	return 0; | 
 | 57 | } | 
 | 58 |  | 
| Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 59 | static inline int pinctrl_gpio_direction_output(unsigned gpio) | 
| Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 60 | { | 
 | 61 | 	return 0; | 
 | 62 | } | 
 | 63 |  | 
| Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 64 | static inline struct pinctrl * __must_check pinctrl_get(struct device *dev) | 
| Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 65 | { | 
 | 66 | 	return NULL; | 
 | 67 | } | 
 | 68 |  | 
| Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 69 | static inline void pinctrl_put(struct pinctrl *p) | 
| Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 70 | { | 
 | 71 | } | 
 | 72 |  | 
| Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 73 | static inline struct pinctrl_state * __must_check pinctrl_lookup_state( | 
 | 74 | 							struct pinctrl *p, | 
 | 75 | 							const char *name) | 
 | 76 | { | 
 | 77 | 	return NULL; | 
 | 78 | } | 
 | 79 |  | 
 | 80 | static inline int pinctrl_select_state(struct pinctrl *p, | 
 | 81 | 				       struct pinctrl_state *s) | 
| Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 82 | { | 
 | 83 | 	return 0; | 
 | 84 | } | 
 | 85 |  | 
| Stephen Warren | 4be45fa | 2012-04-16 10:51:00 -0600 | [diff] [blame] | 86 | static inline struct pinctrl * __must_check devm_pinctrl_get(struct device *dev) | 
 | 87 | { | 
 | 88 | 	return NULL; | 
 | 89 | } | 
 | 90 |  | 
 | 91 | static inline void devm_pinctrl_put(struct pinctrl *p) | 
 | 92 | { | 
 | 93 | } | 
 | 94 |  | 
| Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 95 | #endif /* CONFIG_PINCTRL */ | 
 | 96 |  | 
 | 97 | static inline struct pinctrl * __must_check pinctrl_get_select( | 
 | 98 | 					struct device *dev, const char *name) | 
| Linus Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 99 | { | 
| Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 100 | 	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 Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 121 | } | 
 | 122 |  | 
| Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 123 | static 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 Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 128 |  | 
| Stephen Warren | 4be45fa | 2012-04-16 10:51:00 -0600 | [diff] [blame] | 129 | static 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); | 
| Uwe Kleine-König | 5e4b330 | 2012-07-30 18:38:33 +0200 | [diff] [blame] | 143 | 		return ERR_CAST(s); | 
| Stephen Warren | 4be45fa | 2012-04-16 10:51:00 -0600 | [diff] [blame] | 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 |  | 
 | 155 | static 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 Walleij | 28a8d14 | 2012-02-09 01:52:22 +0100 | [diff] [blame] | 161 | #ifdef CONFIG_PINCONF | 
 | 162 |  | 
 | 163 | extern int pin_config_get(const char *dev_name, const char *name, | 
 | 164 | 			  unsigned long *config); | 
 | 165 | extern int pin_config_set(const char *dev_name, const char *name, | 
 | 166 | 			  unsigned long config); | 
 | 167 | extern int pin_config_group_get(const char *dev_name, | 
 | 168 | 				const char *pin_group, | 
 | 169 | 				unsigned long *config); | 
 | 170 | extern int pin_config_group_set(const char *dev_name, | 
 | 171 | 				const char *pin_group, | 
 | 172 | 				unsigned long config); | 
 | 173 |  | 
 | 174 | #else | 
 | 175 |  | 
 | 176 | static inline int pin_config_get(const char *dev_name, const char *name, | 
 | 177 | 				 unsigned long *config) | 
 | 178 | { | 
 | 179 | 	return 0; | 
 | 180 | } | 
 | 181 |  | 
 | 182 | static inline int pin_config_set(const char *dev_name, const char *name, | 
 | 183 | 				 unsigned long config) | 
 | 184 | { | 
 | 185 | 	return 0; | 
 | 186 | } | 
 | 187 |  | 
 | 188 | static 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 |  | 
 | 195 | static 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 */ |