Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Core driver for the pin config portions of the pin control subsystem |
| 3 | * |
| 4 | * Copyright (C) 2011 ST-Ericsson SA |
| 5 | * Written on behalf of Linaro for ST-Ericsson |
| 6 | * |
| 7 | * Author: Linus Walleij <linus.walleij@linaro.org> |
| 8 | * |
| 9 | * License terms: GNU General Public License (GPL) version 2 |
| 10 | */ |
| 11 | #define pr_fmt(fmt) "pinconfig core: " fmt |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/device.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/debugfs.h> |
| 19 | #include <linux/seq_file.h> |
| 20 | #include <linux/pinctrl/machine.h> |
| 21 | #include <linux/pinctrl/pinctrl.h> |
| 22 | #include <linux/pinctrl/pinconf.h> |
| 23 | #include "core.h" |
| 24 | #include "pinconf.h" |
| 25 | |
Stephen Warren | 2b69425 | 2012-02-19 23:45:46 -0700 | [diff] [blame] | 26 | int pinconf_check_ops(struct pinctrl_dev *pctldev) |
| 27 | { |
| 28 | const struct pinconf_ops *ops = pctldev->desc->confops; |
| 29 | |
| 30 | /* We must be able to read out pin status */ |
| 31 | if (!ops->pin_config_get && !ops->pin_config_group_get) |
| 32 | return -EINVAL; |
| 33 | /* We have to be able to config the pins in SOME way */ |
| 34 | if (!ops->pin_config_set && !ops->pin_config_group_set) |
| 35 | return -EINVAL; |
| 36 | return 0; |
| 37 | } |
| 38 | |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 39 | int pinconf_validate_map(struct pinctrl_map const *map, int i) |
| 40 | { |
| 41 | if (!map->data.configs.group_or_pin) { |
| 42 | pr_err("failed to register map %s (%d): no group/pin given\n", |
| 43 | map->name, i); |
| 44 | return -EINVAL; |
| 45 | } |
| 46 | |
| 47 | if (map->data.configs.num_configs && |
| 48 | !map->data.configs.configs) { |
| 49 | pr_err("failed to register map %s (%d): no configs ptr given\n", |
| 50 | map->name, i); |
| 51 | return -EINVAL; |
| 52 | } |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 57 | int pin_config_get_for_pin(struct pinctrl_dev *pctldev, unsigned pin, |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 58 | unsigned long *config) |
| 59 | { |
| 60 | const struct pinconf_ops *ops = pctldev->desc->confops; |
| 61 | |
| 62 | if (!ops || !ops->pin_config_get) { |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 63 | dev_err(pctldev->dev, "cannot get pin configuration, missing " |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 64 | "pin_config_get() function in driver\n"); |
| 65 | return -EINVAL; |
| 66 | } |
| 67 | |
| 68 | return ops->pin_config_get(pctldev, pin, config); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * pin_config_get() - get the configuration of a single pin parameter |
Stephen Warren | 43699de | 2011-12-15 16:57:17 -0700 | [diff] [blame] | 73 | * @dev_name: name of the pin controller device for this pin |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 74 | * @name: name of the pin to get the config for |
| 75 | * @config: the config pointed to by this argument will be filled in with the |
| 76 | * current pin state, it can be used directly by drivers as a numeral, or |
| 77 | * it can be dereferenced to any struct. |
| 78 | */ |
Stephen Warren | 43699de | 2011-12-15 16:57:17 -0700 | [diff] [blame] | 79 | int pin_config_get(const char *dev_name, const char *name, |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 80 | unsigned long *config) |
| 81 | { |
Stephen Warren | 43699de | 2011-12-15 16:57:17 -0700 | [diff] [blame] | 82 | struct pinctrl_dev *pctldev; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 83 | int pin; |
| 84 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 85 | mutex_lock(&pinctrl_mutex); |
| 86 | |
Linus Walleij | 9dfac4f | 2012-02-01 18:02:47 +0100 | [diff] [blame] | 87 | pctldev = get_pinctrl_dev_from_devname(dev_name); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 88 | if (!pctldev) { |
| 89 | pin = -EINVAL; |
| 90 | goto unlock; |
| 91 | } |
Stephen Warren | 43699de | 2011-12-15 16:57:17 -0700 | [diff] [blame] | 92 | |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 93 | pin = pin_get_from_name(pctldev, name); |
| 94 | if (pin < 0) |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 95 | goto unlock; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 96 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 97 | pin = pin_config_get_for_pin(pctldev, pin, config); |
| 98 | |
| 99 | unlock: |
| 100 | mutex_unlock(&pinctrl_mutex); |
| 101 | return pin; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 102 | } |
| 103 | EXPORT_SYMBOL(pin_config_get); |
| 104 | |
Stephen Warren | 2b69425 | 2012-02-19 23:45:46 -0700 | [diff] [blame] | 105 | static int pin_config_set_for_pin(struct pinctrl_dev *pctldev, unsigned pin, |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 106 | unsigned long config) |
| 107 | { |
| 108 | const struct pinconf_ops *ops = pctldev->desc->confops; |
| 109 | int ret; |
| 110 | |
| 111 | if (!ops || !ops->pin_config_set) { |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 112 | dev_err(pctldev->dev, "cannot configure pin, missing " |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 113 | "config function in driver\n"); |
| 114 | return -EINVAL; |
| 115 | } |
| 116 | |
| 117 | ret = ops->pin_config_set(pctldev, pin, config); |
| 118 | if (ret) { |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 119 | dev_err(pctldev->dev, |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 120 | "unable to set pin configuration on pin %d\n", pin); |
| 121 | return ret; |
| 122 | } |
| 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * pin_config_set() - set the configuration of a single pin parameter |
Stephen Warren | 43699de | 2011-12-15 16:57:17 -0700 | [diff] [blame] | 129 | * @dev_name: name of pin controller device for this pin |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 130 | * @name: name of the pin to set the config for |
| 131 | * @config: the config in this argument will contain the desired pin state, it |
| 132 | * can be used directly by drivers as a numeral, or it can be dereferenced |
| 133 | * to any struct. |
| 134 | */ |
Stephen Warren | 43699de | 2011-12-15 16:57:17 -0700 | [diff] [blame] | 135 | int pin_config_set(const char *dev_name, const char *name, |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 136 | unsigned long config) |
| 137 | { |
Stephen Warren | 43699de | 2011-12-15 16:57:17 -0700 | [diff] [blame] | 138 | struct pinctrl_dev *pctldev; |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 139 | int pin, ret; |
| 140 | |
| 141 | mutex_lock(&pinctrl_mutex); |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 142 | |
Linus Walleij | 9dfac4f | 2012-02-01 18:02:47 +0100 | [diff] [blame] | 143 | pctldev = get_pinctrl_dev_from_devname(dev_name); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 144 | if (!pctldev) { |
| 145 | ret = -EINVAL; |
| 146 | goto unlock; |
| 147 | } |
Stephen Warren | 43699de | 2011-12-15 16:57:17 -0700 | [diff] [blame] | 148 | |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 149 | pin = pin_get_from_name(pctldev, name); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 150 | if (pin < 0) { |
| 151 | ret = pin; |
| 152 | goto unlock; |
| 153 | } |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 154 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 155 | ret = pin_config_set_for_pin(pctldev, pin, config); |
| 156 | |
| 157 | unlock: |
| 158 | mutex_unlock(&pinctrl_mutex); |
| 159 | return ret; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 160 | } |
| 161 | EXPORT_SYMBOL(pin_config_set); |
| 162 | |
Stephen Warren | 43699de | 2011-12-15 16:57:17 -0700 | [diff] [blame] | 163 | int pin_config_group_get(const char *dev_name, const char *pin_group, |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 164 | unsigned long *config) |
| 165 | { |
Stephen Warren | 43699de | 2011-12-15 16:57:17 -0700 | [diff] [blame] | 166 | struct pinctrl_dev *pctldev; |
| 167 | const struct pinconf_ops *ops; |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 168 | int selector, ret; |
| 169 | |
| 170 | mutex_lock(&pinctrl_mutex); |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 171 | |
Linus Walleij | 9dfac4f | 2012-02-01 18:02:47 +0100 | [diff] [blame] | 172 | pctldev = get_pinctrl_dev_from_devname(dev_name); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 173 | if (!pctldev) { |
| 174 | ret = -EINVAL; |
| 175 | goto unlock; |
| 176 | } |
Stephen Warren | 43699de | 2011-12-15 16:57:17 -0700 | [diff] [blame] | 177 | ops = pctldev->desc->confops; |
| 178 | |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 179 | if (!ops || !ops->pin_config_group_get) { |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 180 | dev_err(pctldev->dev, "cannot get configuration for pin " |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 181 | "group, missing group config get function in " |
| 182 | "driver\n"); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 183 | ret = -EINVAL; |
| 184 | goto unlock; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | selector = pinctrl_get_group_selector(pctldev, pin_group); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 188 | if (selector < 0) { |
| 189 | ret = selector; |
| 190 | goto unlock; |
| 191 | } |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 192 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 193 | ret = ops->pin_config_group_get(pctldev, selector, config); |
| 194 | |
| 195 | unlock: |
| 196 | mutex_unlock(&pinctrl_mutex); |
| 197 | return ret; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 198 | } |
| 199 | EXPORT_SYMBOL(pin_config_group_get); |
| 200 | |
Stephen Warren | 43699de | 2011-12-15 16:57:17 -0700 | [diff] [blame] | 201 | int pin_config_group_set(const char *dev_name, const char *pin_group, |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 202 | unsigned long config) |
| 203 | { |
Stephen Warren | 43699de | 2011-12-15 16:57:17 -0700 | [diff] [blame] | 204 | struct pinctrl_dev *pctldev; |
| 205 | const struct pinconf_ops *ops; |
| 206 | const struct pinctrl_ops *pctlops; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 207 | int selector; |
| 208 | const unsigned *pins; |
| 209 | unsigned num_pins; |
| 210 | int ret; |
| 211 | int i; |
| 212 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 213 | mutex_lock(&pinctrl_mutex); |
| 214 | |
Linus Walleij | 9dfac4f | 2012-02-01 18:02:47 +0100 | [diff] [blame] | 215 | pctldev = get_pinctrl_dev_from_devname(dev_name); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 216 | if (!pctldev) { |
| 217 | ret = -EINVAL; |
| 218 | goto unlock; |
| 219 | } |
Stephen Warren | 43699de | 2011-12-15 16:57:17 -0700 | [diff] [blame] | 220 | ops = pctldev->desc->confops; |
| 221 | pctlops = pctldev->desc->pctlops; |
| 222 | |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 223 | if (!ops || (!ops->pin_config_group_set && !ops->pin_config_set)) { |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 224 | dev_err(pctldev->dev, "cannot configure pin group, missing " |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 225 | "config function in driver\n"); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 226 | ret = -EINVAL; |
| 227 | goto unlock; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | selector = pinctrl_get_group_selector(pctldev, pin_group); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 231 | if (selector < 0) { |
| 232 | ret = selector; |
| 233 | goto unlock; |
| 234 | } |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 235 | |
| 236 | ret = pctlops->get_group_pins(pctldev, selector, &pins, &num_pins); |
| 237 | if (ret) { |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 238 | dev_err(pctldev->dev, "cannot configure pin group, error " |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 239 | "getting pins\n"); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 240 | goto unlock; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /* |
| 244 | * If the pin controller supports handling entire groups we use that |
| 245 | * capability. |
| 246 | */ |
| 247 | if (ops->pin_config_group_set) { |
| 248 | ret = ops->pin_config_group_set(pctldev, selector, config); |
| 249 | /* |
| 250 | * If the pin controller prefer that a certain group be handled |
| 251 | * pin-by-pin as well, it returns -EAGAIN. |
| 252 | */ |
| 253 | if (ret != -EAGAIN) |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 254 | goto unlock; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | /* |
| 258 | * If the controller cannot handle entire groups, we configure each pin |
| 259 | * individually. |
| 260 | */ |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 261 | if (!ops->pin_config_set) { |
| 262 | ret = 0; |
| 263 | goto unlock; |
| 264 | } |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 265 | |
| 266 | for (i = 0; i < num_pins; i++) { |
| 267 | ret = ops->pin_config_set(pctldev, pins[i], config); |
| 268 | if (ret < 0) |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 269 | goto unlock; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 270 | } |
| 271 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 272 | ret = 0; |
| 273 | |
| 274 | unlock: |
| 275 | mutex_unlock(&pinctrl_mutex); |
| 276 | |
| 277 | return ret; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 278 | } |
| 279 | EXPORT_SYMBOL(pin_config_group_set); |
| 280 | |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 281 | int pinconf_map_to_setting(struct pinctrl_map const *map, |
| 282 | struct pinctrl_setting *setting) |
| 283 | { |
| 284 | struct pinctrl_dev *pctldev = setting->pctldev; |
Linus Walleij | 70b3637 | 2012-03-12 21:38:29 +0100 | [diff] [blame] | 285 | int pin; |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 286 | |
| 287 | switch (setting->type) { |
| 288 | case PIN_MAP_TYPE_CONFIGS_PIN: |
Linus Walleij | 70b3637 | 2012-03-12 21:38:29 +0100 | [diff] [blame] | 289 | pin = pin_get_from_name(pctldev, |
| 290 | map->data.configs.group_or_pin); |
| 291 | if (pin < 0) { |
| 292 | dev_err(pctldev->dev, "could not map pin config for \"%s\"", |
| 293 | map->data.configs.group_or_pin); |
| 294 | return pin; |
| 295 | } |
| 296 | setting->data.configs.group_or_pin = pin; |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 297 | break; |
| 298 | case PIN_MAP_TYPE_CONFIGS_GROUP: |
Linus Walleij | 70b3637 | 2012-03-12 21:38:29 +0100 | [diff] [blame] | 299 | pin = pinctrl_get_group_selector(pctldev, |
| 300 | map->data.configs.group_or_pin); |
| 301 | if (pin < 0) { |
| 302 | dev_err(pctldev->dev, "could not map group config for \"%s\"", |
| 303 | map->data.configs.group_or_pin); |
| 304 | return pin; |
| 305 | } |
| 306 | setting->data.configs.group_or_pin = pin; |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 307 | break; |
| 308 | default: |
| 309 | return -EINVAL; |
| 310 | } |
| 311 | |
| 312 | setting->data.configs.num_configs = map->data.configs.num_configs; |
| 313 | setting->data.configs.configs = map->data.configs.configs; |
| 314 | |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | void pinconf_free_setting(struct pinctrl_setting const *setting) |
| 319 | { |
| 320 | } |
| 321 | |
| 322 | int pinconf_apply_setting(struct pinctrl_setting const *setting) |
| 323 | { |
| 324 | struct pinctrl_dev *pctldev = setting->pctldev; |
| 325 | const struct pinconf_ops *ops = pctldev->desc->confops; |
| 326 | int i, ret; |
| 327 | |
| 328 | if (!ops) { |
| 329 | dev_err(pctldev->dev, "missing confops\n"); |
| 330 | return -EINVAL; |
| 331 | } |
| 332 | |
| 333 | switch (setting->type) { |
| 334 | case PIN_MAP_TYPE_CONFIGS_PIN: |
| 335 | if (!ops->pin_config_set) { |
| 336 | dev_err(pctldev->dev, "missing pin_config_set op\n"); |
| 337 | return -EINVAL; |
| 338 | } |
| 339 | for (i = 0; i < setting->data.configs.num_configs; i++) { |
| 340 | ret = ops->pin_config_set(pctldev, |
| 341 | setting->data.configs.group_or_pin, |
| 342 | setting->data.configs.configs[i]); |
| 343 | if (ret < 0) { |
| 344 | dev_err(pctldev->dev, |
| 345 | "pin_config_set op failed for pin %d config %08lx\n", |
| 346 | setting->data.configs.group_or_pin, |
| 347 | setting->data.configs.configs[i]); |
| 348 | return ret; |
| 349 | } |
| 350 | } |
| 351 | break; |
| 352 | case PIN_MAP_TYPE_CONFIGS_GROUP: |
| 353 | if (!ops->pin_config_group_set) { |
| 354 | dev_err(pctldev->dev, |
| 355 | "missing pin_config_group_set op\n"); |
| 356 | return -EINVAL; |
| 357 | } |
| 358 | for (i = 0; i < setting->data.configs.num_configs; i++) { |
| 359 | ret = ops->pin_config_group_set(pctldev, |
| 360 | setting->data.configs.group_or_pin, |
| 361 | setting->data.configs.configs[i]); |
| 362 | if (ret < 0) { |
| 363 | dev_err(pctldev->dev, |
| 364 | "pin_config_group_set op failed for group %d config %08lx\n", |
| 365 | setting->data.configs.group_or_pin, |
| 366 | setting->data.configs.configs[i]); |
| 367 | return ret; |
| 368 | } |
| 369 | } |
| 370 | break; |
| 371 | default: |
| 372 | return -EINVAL; |
| 373 | } |
| 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 378 | #ifdef CONFIG_DEBUG_FS |
| 379 | |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 380 | void pinconf_show_map(struct seq_file *s, struct pinctrl_map const *map) |
| 381 | { |
| 382 | int i; |
| 383 | |
| 384 | switch (map->type) { |
| 385 | case PIN_MAP_TYPE_CONFIGS_PIN: |
| 386 | seq_printf(s, "pin "); |
| 387 | break; |
| 388 | case PIN_MAP_TYPE_CONFIGS_GROUP: |
| 389 | seq_printf(s, "group "); |
| 390 | break; |
| 391 | default: |
| 392 | break; |
| 393 | } |
| 394 | |
| 395 | seq_printf(s, "%s\n", map->data.configs.group_or_pin); |
| 396 | |
| 397 | for (i = 0; i < map->data.configs.num_configs; i++) |
| 398 | seq_printf(s, "config %08lx\n", map->data.configs.configs[i]); |
| 399 | } |
| 400 | |
| 401 | void pinconf_show_setting(struct seq_file *s, |
| 402 | struct pinctrl_setting const *setting) |
| 403 | { |
| 404 | struct pinctrl_dev *pctldev = setting->pctldev; |
| 405 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; |
| 406 | struct pin_desc *desc; |
| 407 | int i; |
| 408 | |
| 409 | switch (setting->type) { |
| 410 | case PIN_MAP_TYPE_CONFIGS_PIN: |
| 411 | desc = pin_desc_get(setting->pctldev, |
| 412 | setting->data.configs.group_or_pin); |
| 413 | seq_printf(s, "pin %s (%d)", |
| 414 | desc->name ? desc->name : "unnamed", |
| 415 | setting->data.configs.group_or_pin); |
| 416 | break; |
| 417 | case PIN_MAP_TYPE_CONFIGS_GROUP: |
| 418 | seq_printf(s, "group %s (%d)", |
| 419 | pctlops->get_group_name(pctldev, |
| 420 | setting->data.configs.group_or_pin), |
| 421 | setting->data.configs.group_or_pin); |
| 422 | break; |
| 423 | default: |
| 424 | break; |
| 425 | } |
| 426 | |
| 427 | /* |
| 428 | * FIXME: We should really get the pin controler to dump the config |
| 429 | * values, so they can be decoded to something meaningful. |
| 430 | */ |
| 431 | for (i = 0; i < setting->data.configs.num_configs; i++) |
| 432 | seq_printf(s, " %08lx", setting->data.configs.configs[i]); |
| 433 | |
| 434 | seq_printf(s, "\n"); |
| 435 | } |
| 436 | |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 437 | static void pinconf_dump_pin(struct pinctrl_dev *pctldev, |
| 438 | struct seq_file *s, int pin) |
| 439 | { |
| 440 | const struct pinconf_ops *ops = pctldev->desc->confops; |
| 441 | |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 442 | /* no-op when not using generic pin config */ |
| 443 | pinconf_generic_dump_pin(pctldev, s, pin); |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 444 | if (ops && ops->pin_config_dbg_show) |
| 445 | ops->pin_config_dbg_show(pctldev, s, pin); |
| 446 | } |
| 447 | |
| 448 | static int pinconf_pins_show(struct seq_file *s, void *what) |
| 449 | { |
| 450 | struct pinctrl_dev *pctldev = s->private; |
Chanho Park | 706e852 | 2012-01-03 16:47:50 +0900 | [diff] [blame] | 451 | unsigned i, pin; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 452 | |
| 453 | seq_puts(s, "Pin config settings per pin\n"); |
| 454 | seq_puts(s, "Format: pin (name): pinmux setting array\n"); |
| 455 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 456 | mutex_lock(&pinctrl_mutex); |
| 457 | |
Chanho Park | 706e852 | 2012-01-03 16:47:50 +0900 | [diff] [blame] | 458 | /* The pin number can be retrived from the pin controller descriptor */ |
Stephen Warren | 546edd8 | 2012-01-06 13:38:31 -0700 | [diff] [blame] | 459 | for (i = 0; i < pctldev->desc->npins; i++) { |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 460 | struct pin_desc *desc; |
| 461 | |
Chanho Park | 706e852 | 2012-01-03 16:47:50 +0900 | [diff] [blame] | 462 | pin = pctldev->desc->pins[i].number; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 463 | desc = pin_desc_get(pctldev, pin); |
Chanho Park | 706e852 | 2012-01-03 16:47:50 +0900 | [diff] [blame] | 464 | /* Skip if we cannot search the pin */ |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 465 | if (desc == NULL) |
| 466 | continue; |
| 467 | |
| 468 | seq_printf(s, "pin %d (%s):", pin, |
| 469 | desc->name ? desc->name : "unnamed"); |
| 470 | |
| 471 | pinconf_dump_pin(pctldev, s, pin); |
| 472 | |
| 473 | seq_printf(s, "\n"); |
| 474 | } |
| 475 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 476 | mutex_unlock(&pinctrl_mutex); |
| 477 | |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 478 | return 0; |
| 479 | } |
| 480 | |
| 481 | static void pinconf_dump_group(struct pinctrl_dev *pctldev, |
| 482 | struct seq_file *s, unsigned selector, |
| 483 | const char *gname) |
| 484 | { |
| 485 | const struct pinconf_ops *ops = pctldev->desc->confops; |
| 486 | |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 487 | /* no-op when not using generic pin config */ |
| 488 | pinconf_generic_dump_group(pctldev, s, gname); |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 489 | if (ops && ops->pin_config_group_dbg_show) |
| 490 | ops->pin_config_group_dbg_show(pctldev, s, selector); |
| 491 | } |
| 492 | |
| 493 | static int pinconf_groups_show(struct seq_file *s, void *what) |
| 494 | { |
| 495 | struct pinctrl_dev *pctldev = s->private; |
| 496 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; |
| 497 | const struct pinconf_ops *ops = pctldev->desc->confops; |
| 498 | unsigned selector = 0; |
| 499 | |
| 500 | if (!ops || !ops->pin_config_group_get) |
| 501 | return 0; |
| 502 | |
| 503 | seq_puts(s, "Pin config settings per pin group\n"); |
| 504 | seq_puts(s, "Format: group (name): pinmux setting array\n"); |
| 505 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 506 | mutex_lock(&pinctrl_mutex); |
| 507 | |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 508 | while (pctlops->list_groups(pctldev, selector) >= 0) { |
| 509 | const char *gname = pctlops->get_group_name(pctldev, selector); |
| 510 | |
| 511 | seq_printf(s, "%u (%s):", selector, gname); |
| 512 | pinconf_dump_group(pctldev, s, selector, gname); |
Stephen Warren | f7b9006 | 2012-02-19 23:45:58 -0700 | [diff] [blame] | 513 | seq_printf(s, "\n"); |
| 514 | |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 515 | selector++; |
| 516 | } |
| 517 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 518 | mutex_unlock(&pinctrl_mutex); |
| 519 | |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | static int pinconf_pins_open(struct inode *inode, struct file *file) |
| 524 | { |
| 525 | return single_open(file, pinconf_pins_show, inode->i_private); |
| 526 | } |
| 527 | |
| 528 | static int pinconf_groups_open(struct inode *inode, struct file *file) |
| 529 | { |
| 530 | return single_open(file, pinconf_groups_show, inode->i_private); |
| 531 | } |
| 532 | |
| 533 | static const struct file_operations pinconf_pins_ops = { |
| 534 | .open = pinconf_pins_open, |
| 535 | .read = seq_read, |
| 536 | .llseek = seq_lseek, |
| 537 | .release = single_release, |
| 538 | }; |
| 539 | |
| 540 | static const struct file_operations pinconf_groups_ops = { |
| 541 | .open = pinconf_groups_open, |
| 542 | .read = seq_read, |
| 543 | .llseek = seq_lseek, |
| 544 | .release = single_release, |
| 545 | }; |
| 546 | |
| 547 | void pinconf_init_device_debugfs(struct dentry *devroot, |
| 548 | struct pinctrl_dev *pctldev) |
| 549 | { |
| 550 | debugfs_create_file("pinconf-pins", S_IFREG | S_IRUGO, |
| 551 | devroot, pctldev, &pinconf_pins_ops); |
| 552 | debugfs_create_file("pinconf-groups", S_IFREG | S_IRUGO, |
| 553 | devroot, pctldev, &pinconf_groups_ops); |
| 554 | } |
| 555 | |
| 556 | #endif |