diff options
| -rw-r--r-- | Documentation/pinctrl.txt | 11 | ||||
| -rw-r--r-- | drivers/pinctrl/pinconf.c | 174 | ||||
| -rw-r--r-- | include/linux/pinctrl/consumer.h | 43 |
3 files changed, 2 insertions, 226 deletions
diff --git a/Documentation/pinctrl.txt b/Documentation/pinctrl.txt index 3ee24759be0f..c5948c7d662a 100644 --- a/Documentation/pinctrl.txt +++ b/Documentation/pinctrl.txt | |||
| @@ -203,15 +203,8 @@ using a certain resistor value - pull up and pull down - so that the pin has a | |||
| 203 | stable value when nothing is driving the rail it is connected to, or when it's | 203 | stable value when nothing is driving the rail it is connected to, or when it's |
| 204 | unconnected. | 204 | unconnected. |
| 205 | 205 | ||
| 206 | Pin configuration can be programmed either using the explicit APIs described | 206 | Pin configuration can be programmed by adding configuration entries into the |
| 207 | immediately below, or by adding configuration entries into the mapping table; | 207 | mapping table; see section "Board/machine configuration" below. |
| 208 | see section "Board/machine configuration" below. | ||
| 209 | |||
| 210 | For example, a platform may do the following to pull up a pin to VDD: | ||
| 211 | |||
| 212 | #include <linux/pinctrl/consumer.h> | ||
| 213 | |||
| 214 | ret = pin_config_set("foo-dev", "FOO_GPIO_PIN", PLATFORM_X_PULL_UP); | ||
| 215 | 208 | ||
| 216 | The format and meaning of the configuration parameter, PLATFORM_X_PULL_UP | 209 | The format and meaning of the configuration parameter, PLATFORM_X_PULL_UP |
| 217 | above, is entirely defined by the pin controller driver. | 210 | above, is entirely defined by the pin controller driver. |
diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c index 694c3ace4520..e875f21a5908 100644 --- a/drivers/pinctrl/pinconf.c +++ b/drivers/pinctrl/pinconf.c | |||
| @@ -75,98 +75,6 @@ int pin_config_get_for_pin(struct pinctrl_dev *pctldev, unsigned pin, | |||
| 75 | return ops->pin_config_get(pctldev, pin, config); | 75 | return ops->pin_config_get(pctldev, pin, config); |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | /** | ||
| 79 | * pin_config_get() - get the configuration of a single pin parameter | ||
| 80 | * @dev_name: name of the pin controller device for this pin | ||
| 81 | * @name: name of the pin to get the config for | ||
| 82 | * @config: the config pointed to by this argument will be filled in with the | ||
| 83 | * current pin state, it can be used directly by drivers as a numeral, or | ||
| 84 | * it can be dereferenced to any struct. | ||
| 85 | */ | ||
| 86 | int pin_config_get(const char *dev_name, const char *name, | ||
| 87 | unsigned long *config) | ||
| 88 | { | ||
| 89 | struct pinctrl_dev *pctldev; | ||
| 90 | int pin; | ||
| 91 | |||
| 92 | pctldev = get_pinctrl_dev_from_devname(dev_name); | ||
| 93 | if (!pctldev) { | ||
| 94 | pin = -EINVAL; | ||
| 95 | return pin; | ||
| 96 | } | ||
| 97 | |||
| 98 | mutex_lock(&pctldev->mutex); | ||
| 99 | |||
| 100 | pin = pin_get_from_name(pctldev, name); | ||
| 101 | if (pin < 0) | ||
| 102 | goto unlock; | ||
| 103 | |||
| 104 | pin = pin_config_get_for_pin(pctldev, pin, config); | ||
| 105 | |||
| 106 | unlock: | ||
| 107 | mutex_unlock(&pctldev->mutex); | ||
| 108 | return pin; | ||
| 109 | } | ||
| 110 | EXPORT_SYMBOL(pin_config_get); | ||
| 111 | |||
| 112 | static int pin_config_set_for_pin(struct pinctrl_dev *pctldev, unsigned pin, | ||
| 113 | unsigned long config) | ||
| 114 | { | ||
| 115 | const struct pinconf_ops *ops = pctldev->desc->confops; | ||
| 116 | int ret; | ||
| 117 | |||
| 118 | if (!ops || !ops->pin_config_set) { | ||
| 119 | dev_err(pctldev->dev, "cannot configure pin, missing " | ||
| 120 | "config function in driver\n"); | ||
| 121 | return -EINVAL; | ||
| 122 | } | ||
| 123 | |||
| 124 | ret = ops->pin_config_set(pctldev, pin, config); | ||
| 125 | if (ret) { | ||
| 126 | dev_err(pctldev->dev, | ||
| 127 | "unable to set pin configuration on pin %d\n", pin); | ||
| 128 | return ret; | ||
| 129 | } | ||
| 130 | |||
| 131 | return 0; | ||
| 132 | } | ||
| 133 | |||
| 134 | /** | ||
| 135 | * pin_config_set() - set the configuration of a single pin parameter | ||
| 136 | * @dev_name: name of pin controller device for this pin | ||
| 137 | * @name: name of the pin to set the config for | ||
| 138 | * @config: the config in this argument will contain the desired pin state, it | ||
| 139 | * can be used directly by drivers as a numeral, or it can be dereferenced | ||
| 140 | * to any struct. | ||
| 141 | */ | ||
| 142 | int pin_config_set(const char *dev_name, const char *name, | ||
| 143 | unsigned long config) | ||
| 144 | { | ||
| 145 | struct pinctrl_dev *pctldev; | ||
| 146 | int pin, ret; | ||
| 147 | |||
| 148 | pctldev = get_pinctrl_dev_from_devname(dev_name); | ||
| 149 | if (!pctldev) { | ||
| 150 | ret = -EINVAL; | ||
| 151 | return ret; | ||
| 152 | } | ||
| 153 | |||
| 154 | mutex_lock(&pctldev->mutex); | ||
| 155 | |||
| 156 | pin = pin_get_from_name(pctldev, name); | ||
| 157 | if (pin < 0) { | ||
| 158 | ret = pin; | ||
| 159 | goto unlock; | ||
| 160 | } | ||
| 161 | |||
| 162 | ret = pin_config_set_for_pin(pctldev, pin, config); | ||
| 163 | |||
| 164 | unlock: | ||
| 165 | mutex_unlock(&pctldev->mutex); | ||
| 166 | return ret; | ||
| 167 | } | ||
| 168 | EXPORT_SYMBOL(pin_config_set); | ||
| 169 | |||
| 170 | int pin_config_group_get(const char *dev_name, const char *pin_group, | 78 | int pin_config_group_get(const char *dev_name, const char *pin_group, |
| 171 | unsigned long *config) | 79 | unsigned long *config) |
| 172 | { | 80 | { |
| @@ -204,88 +112,6 @@ unlock: | |||
| 204 | mutex_unlock(&pctldev->mutex); | 112 | mutex_unlock(&pctldev->mutex); |
| 205 | return ret; | 113 | return ret; |
| 206 | } | 114 | } |
| 207 | EXPORT_SYMBOL(pin_config_group_get); | ||
| 208 | |||
| 209 | int pin_config_group_set(const char *dev_name, const char *pin_group, | ||
| 210 | unsigned long config) | ||
| 211 | { | ||
| 212 | struct pinctrl_dev *pctldev; | ||
| 213 | const struct pinconf_ops *ops; | ||
| 214 | const struct pinctrl_ops *pctlops; | ||
| 215 | int selector; | ||
| 216 | const unsigned *pins; | ||
| 217 | unsigned num_pins; | ||
| 218 | int ret; | ||
| 219 | int i; | ||
| 220 | |||
| 221 | pctldev = get_pinctrl_dev_from_devname(dev_name); | ||
| 222 | if (!pctldev) { | ||
| 223 | ret = -EINVAL; | ||
| 224 | return ret; | ||
| 225 | } | ||
| 226 | |||
| 227 | mutex_lock(&pctldev->mutex); | ||
| 228 | |||
| 229 | ops = pctldev->desc->confops; | ||
| 230 | pctlops = pctldev->desc->pctlops; | ||
| 231 | |||
| 232 | if (!ops || (!ops->pin_config_group_set && !ops->pin_config_set)) { | ||
| 233 | dev_err(pctldev->dev, "cannot configure pin group, missing " | ||
| 234 | "config function in driver\n"); | ||
| 235 | ret = -EINVAL; | ||
| 236 | goto unlock; | ||
| 237 | } | ||
| 238 | |||
| 239 | selector = pinctrl_get_group_selector(pctldev, pin_group); | ||
| 240 | if (selector < 0) { | ||
| 241 | ret = selector; | ||
| 242 | goto unlock; | ||
| 243 | } | ||
| 244 | |||
| 245 | ret = pctlops->get_group_pins(pctldev, selector, &pins, &num_pins); | ||
| 246 | if (ret) { | ||
| 247 | dev_err(pctldev->dev, "cannot configure pin group, error " | ||
| 248 | "getting pins\n"); | ||
| 249 | goto unlock; | ||
| 250 | } | ||
| 251 | |||
| 252 | /* | ||
| 253 | * If the pin controller supports handling entire groups we use that | ||
| 254 | * capability. | ||
| 255 | */ | ||
| 256 | if (ops->pin_config_group_set) { | ||
| 257 | ret = ops->pin_config_group_set(pctldev, selector, config); | ||
| 258 | /* | ||
| 259 | * If the pin controller prefer that a certain group be handled | ||
| 260 | * pin-by-pin as well, it returns -EAGAIN. | ||
| 261 | */ | ||
| 262 | if (ret != -EAGAIN) | ||
| 263 | goto unlock; | ||
| 264 | } | ||
| 265 | |||
| 266 | /* | ||
| 267 | * If the controller cannot handle entire groups, we configure each pin | ||
| 268 | * individually. | ||
| 269 | */ | ||
| 270 | if (!ops->pin_config_set) { | ||
| 271 | ret = 0; | ||
| 272 | goto unlock; | ||
| 273 | } | ||
| 274 | |||
| 275 | for (i = 0; i < num_pins; i++) { | ||
| 276 | ret = ops->pin_config_set(pctldev, pins[i], config); | ||
| 277 | if (ret < 0) | ||
| 278 | goto unlock; | ||
| 279 | } | ||
| 280 | |||
| 281 | ret = 0; | ||
| 282 | |||
| 283 | unlock: | ||
| 284 | mutex_unlock(&pctldev->mutex); | ||
| 285 | |||
| 286 | return ret; | ||
| 287 | } | ||
| 288 | EXPORT_SYMBOL(pin_config_group_set); | ||
| 289 | 115 | ||
| 290 | int pinconf_map_to_setting(struct pinctrl_map const *map, | 116 | int pinconf_map_to_setting(struct pinctrl_map const *map, |
| 291 | struct pinctrl_setting *setting) | 117 | struct pinctrl_setting *setting) |
diff --git a/include/linux/pinctrl/consumer.h b/include/linux/pinctrl/consumer.h index d071d850d1de..18eccefea06e 100644 --- a/include/linux/pinctrl/consumer.h +++ b/include/linux/pinctrl/consumer.h | |||
| @@ -192,47 +192,4 @@ static inline struct pinctrl * __must_check devm_pinctrl_get_select_default( | |||
| 192 | return devm_pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT); | 192 | return devm_pinctrl_get_select(dev, PINCTRL_STATE_DEFAULT); |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | #ifdef CONFIG_PINCONF | ||
| 196 | |||
| 197 | extern int pin_config_get(const char *dev_name, const char *name, | ||
| 198 | unsigned long *config); | ||
| 199 | extern int pin_config_set(const char *dev_name, const char *name, | ||
| 200 | unsigned long config); | ||
| 201 | extern int pin_config_group_get(const char *dev_name, | ||
| 202 | const char *pin_group, | ||
| 203 | unsigned long *config); | ||
| 204 | extern int pin_config_group_set(const char *dev_name, | ||
| 205 | const char *pin_group, | ||
| 206 | unsigned long config); | ||
| 207 | |||
| 208 | #else | ||
| 209 | |||
| 210 | static inline int pin_config_get(const char *dev_name, const char *name, | ||
| 211 | unsigned long *config) | ||
| 212 | { | ||
| 213 | return 0; | ||
| 214 | } | ||
| 215 | |||
| 216 | static inline int pin_config_set(const char *dev_name, const char *name, | ||
| 217 | unsigned long config) | ||
| 218 | { | ||
| 219 | return 0; | ||
| 220 | } | ||
| 221 | |||
| 222 | static inline int pin_config_group_get(const char *dev_name, | ||
| 223 | const char *pin_group, | ||
| 224 | unsigned long *config) | ||
| 225 | { | ||
| 226 | return 0; | ||
| 227 | } | ||
| 228 | |||
| 229 | static inline int pin_config_group_set(const char *dev_name, | ||
| 230 | const char *pin_group, | ||
| 231 | unsigned long config) | ||
| 232 | { | ||
| 233 | return 0; | ||
| 234 | } | ||
| 235 | |||
| 236 | #endif | ||
| 237 | |||
| 238 | #endif /* __LINUX_PINCTRL_CONSUMER_H */ | 195 | #endif /* __LINUX_PINCTRL_CONSUMER_H */ |
