Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Core driver for the pin control subsystem |
| 3 | * |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 4 | * Copyright (C) 2011-2012 ST-Ericsson SA |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 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 | * |
Stephen Warren | b2b3e66 | 2012-02-19 23:45:43 -0700 | [diff] [blame] | 10 | * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved. |
| 11 | * |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 12 | * License terms: GNU General Public License (GPL) version 2 |
| 13 | */ |
| 14 | #define pr_fmt(fmt) "pinctrl core: " fmt |
| 15 | |
| 16 | #include <linux/kernel.h> |
Linus Walleij | ab78029 | 2013-01-22 10:56:14 -0700 | [diff] [blame] | 17 | #include <linux/kref.h> |
Stephen Rothwell | a5a697c | 2011-09-30 14:39:04 +1000 | [diff] [blame] | 18 | #include <linux/export.h> |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 19 | #include <linux/init.h> |
| 20 | #include <linux/device.h> |
| 21 | #include <linux/slab.h> |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 22 | #include <linux/err.h> |
| 23 | #include <linux/list.h> |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 24 | #include <linux/sysfs.h> |
| 25 | #include <linux/debugfs.h> |
| 26 | #include <linux/seq_file.h> |
Stephen Warren | 6d4ca1f | 2012-04-16 10:51:00 -0600 | [diff] [blame] | 27 | #include <linux/pinctrl/consumer.h> |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 28 | #include <linux/pinctrl/pinctrl.h> |
| 29 | #include <linux/pinctrl/machine.h> |
Haojian Zhuang | 2afe822 | 2013-03-28 07:34:19 +0800 | [diff] [blame^] | 30 | |
| 31 | #ifdef CONFIG_GPIOLIB |
Haojian Zhuang | 51e13c2 | 2013-02-17 19:42:50 +0800 | [diff] [blame] | 32 | #include <asm-generic/gpio.h> |
Haojian Zhuang | 2afe822 | 2013-03-28 07:34:19 +0800 | [diff] [blame^] | 33 | #endif |
| 34 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 35 | #include "core.h" |
Stephen Warren | 57291ce | 2012-03-23 10:29:46 -0600 | [diff] [blame] | 36 | #include "devicetree.h" |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 37 | #include "pinmux.h" |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 38 | #include "pinconf.h" |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 39 | |
Stephen Warren | b2b3e66 | 2012-02-19 23:45:43 -0700 | [diff] [blame] | 40 | |
Dong Aisheng | 5b3aa5f | 2012-04-26 16:15:50 +0800 | [diff] [blame] | 41 | static bool pinctrl_dummy_state; |
| 42 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 43 | /* Mutex taken by all entry points */ |
| 44 | DEFINE_MUTEX(pinctrl_mutex); |
| 45 | |
| 46 | /* Global list of pin control devices (struct pinctrl_dev) */ |
Stephen Warren | 57291ce | 2012-03-23 10:29:46 -0600 | [diff] [blame] | 47 | LIST_HEAD(pinctrldev_list); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 48 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 49 | /* List of pin controller handles (struct pinctrl) */ |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 50 | static LIST_HEAD(pinctrl_list); |
| 51 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 52 | /* List of pinctrl maps (struct pinctrl_maps) */ |
Laurent Meunier | 6f9e41f | 2013-02-06 09:09:44 +0100 | [diff] [blame] | 53 | LIST_HEAD(pinctrl_maps); |
Stephen Warren | b2b3e66 | 2012-02-19 23:45:43 -0700 | [diff] [blame] | 54 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 55 | |
Dong Aisheng | 5b3aa5f | 2012-04-26 16:15:50 +0800 | [diff] [blame] | 56 | /** |
| 57 | * pinctrl_provide_dummies() - indicate if pinctrl provides dummy state support |
| 58 | * |
| 59 | * Usually this function is called by platforms without pinctrl driver support |
| 60 | * but run with some shared drivers using pinctrl APIs. |
| 61 | * After calling this function, the pinctrl core will return successfully |
| 62 | * with creating a dummy state for the driver to keep going smoothly. |
| 63 | */ |
| 64 | void pinctrl_provide_dummies(void) |
| 65 | { |
| 66 | pinctrl_dummy_state = true; |
| 67 | } |
| 68 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 69 | const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev) |
| 70 | { |
| 71 | /* We're not allowed to register devices without name */ |
| 72 | return pctldev->desc->name; |
| 73 | } |
| 74 | EXPORT_SYMBOL_GPL(pinctrl_dev_get_name); |
| 75 | |
Haojian Zhuang | d6e99ab | 2013-01-18 15:31:06 +0800 | [diff] [blame] | 76 | const char *pinctrl_dev_get_devname(struct pinctrl_dev *pctldev) |
| 77 | { |
| 78 | return dev_name(pctldev->dev); |
| 79 | } |
| 80 | EXPORT_SYMBOL_GPL(pinctrl_dev_get_devname); |
| 81 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 82 | void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev) |
| 83 | { |
| 84 | return pctldev->driver_data; |
| 85 | } |
| 86 | EXPORT_SYMBOL_GPL(pinctrl_dev_get_drvdata); |
| 87 | |
| 88 | /** |
Linus Walleij | 9dfac4f | 2012-02-01 18:02:47 +0100 | [diff] [blame] | 89 | * get_pinctrl_dev_from_devname() - look up pin controller device |
| 90 | * @devname: the name of a device instance, as returned by dev_name() |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 91 | * |
| 92 | * Looks up a pin control device matching a certain device name or pure device |
| 93 | * pointer, the pure device pointer will take precedence. |
| 94 | */ |
Linus Walleij | 9dfac4f | 2012-02-01 18:02:47 +0100 | [diff] [blame] | 95 | struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *devname) |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 96 | { |
| 97 | struct pinctrl_dev *pctldev = NULL; |
| 98 | bool found = false; |
| 99 | |
Linus Walleij | 9dfac4f | 2012-02-01 18:02:47 +0100 | [diff] [blame] | 100 | if (!devname) |
| 101 | return NULL; |
| 102 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 103 | list_for_each_entry(pctldev, &pinctrldev_list, node) { |
Linus Walleij | 9dfac4f | 2012-02-01 18:02:47 +0100 | [diff] [blame] | 104 | if (!strcmp(dev_name(pctldev->dev), devname)) { |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 105 | /* Matched on device name */ |
| 106 | found = true; |
| 107 | break; |
| 108 | } |
| 109 | } |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 110 | |
| 111 | return found ? pctldev : NULL; |
| 112 | } |
| 113 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 114 | /** |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 115 | * pin_get_from_name() - look up a pin number from a name |
| 116 | * @pctldev: the pin control device to lookup the pin on |
| 117 | * @name: the name of the pin to look up |
| 118 | */ |
| 119 | int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name) |
| 120 | { |
Chanho Park | 706e852 | 2012-01-03 16:47:50 +0900 | [diff] [blame] | 121 | unsigned i, pin; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 122 | |
Chanho Park | 706e852 | 2012-01-03 16:47:50 +0900 | [diff] [blame] | 123 | /* The pin number can be retrived from the pin controller descriptor */ |
| 124 | for (i = 0; i < pctldev->desc->npins; i++) { |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 125 | struct pin_desc *desc; |
| 126 | |
Chanho Park | 706e852 | 2012-01-03 16:47:50 +0900 | [diff] [blame] | 127 | pin = pctldev->desc->pins[i].number; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 128 | desc = pin_desc_get(pctldev, pin); |
| 129 | /* Pin space may be sparse */ |
| 130 | if (desc == NULL) |
| 131 | continue; |
| 132 | if (desc->name && !strcmp(name, desc->name)) |
| 133 | return pin; |
| 134 | } |
| 135 | |
| 136 | return -EINVAL; |
| 137 | } |
| 138 | |
| 139 | /** |
Dong Aisheng | dcb5dbc | 2012-04-17 15:00:46 +0800 | [diff] [blame] | 140 | * pin_get_name_from_id() - look up a pin name from a pin id |
| 141 | * @pctldev: the pin control device to lookup the pin on |
| 142 | * @name: the name of the pin to look up |
| 143 | */ |
| 144 | const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin) |
| 145 | { |
| 146 | const struct pin_desc *desc; |
| 147 | |
| 148 | desc = pin_desc_get(pctldev, pin); |
| 149 | if (desc == NULL) { |
| 150 | dev_err(pctldev->dev, "failed to get pin(%d) name\n", |
| 151 | pin); |
| 152 | return NULL; |
| 153 | } |
| 154 | |
| 155 | return desc->name; |
| 156 | } |
| 157 | |
| 158 | /** |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 159 | * pin_is_valid() - check if pin exists on controller |
| 160 | * @pctldev: the pin control device to check the pin on |
| 161 | * @pin: pin to check, use the local pin controller index number |
| 162 | * |
| 163 | * This tells us whether a certain pin exist on a certain pin controller or |
| 164 | * not. Pin lists may be sparse, so some pins may not exist. |
| 165 | */ |
| 166 | bool pin_is_valid(struct pinctrl_dev *pctldev, int pin) |
| 167 | { |
| 168 | struct pin_desc *pindesc; |
| 169 | |
| 170 | if (pin < 0) |
| 171 | return false; |
| 172 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 173 | mutex_lock(&pinctrl_mutex); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 174 | pindesc = pin_desc_get(pctldev, pin); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 175 | mutex_unlock(&pinctrl_mutex); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 176 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 177 | return pindesc != NULL; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 178 | } |
| 179 | EXPORT_SYMBOL_GPL(pin_is_valid); |
| 180 | |
| 181 | /* Deletes a range of pin descriptors */ |
| 182 | static void pinctrl_free_pindescs(struct pinctrl_dev *pctldev, |
| 183 | const struct pinctrl_pin_desc *pins, |
| 184 | unsigned num_pins) |
| 185 | { |
| 186 | int i; |
| 187 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 188 | for (i = 0; i < num_pins; i++) { |
| 189 | struct pin_desc *pindesc; |
| 190 | |
| 191 | pindesc = radix_tree_lookup(&pctldev->pin_desc_tree, |
| 192 | pins[i].number); |
| 193 | if (pindesc != NULL) { |
| 194 | radix_tree_delete(&pctldev->pin_desc_tree, |
| 195 | pins[i].number); |
Linus Walleij | ca53c5f | 2011-12-14 20:33:37 +0100 | [diff] [blame] | 196 | if (pindesc->dynamic_name) |
| 197 | kfree(pindesc->name); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 198 | } |
| 199 | kfree(pindesc); |
| 200 | } |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | static int pinctrl_register_one_pin(struct pinctrl_dev *pctldev, |
| 204 | unsigned number, const char *name) |
| 205 | { |
| 206 | struct pin_desc *pindesc; |
| 207 | |
| 208 | pindesc = pin_desc_get(pctldev, number); |
| 209 | if (pindesc != NULL) { |
| 210 | pr_err("pin %d already registered on %s\n", number, |
| 211 | pctldev->desc->name); |
| 212 | return -EINVAL; |
| 213 | } |
| 214 | |
| 215 | pindesc = kzalloc(sizeof(*pindesc), GFP_KERNEL); |
Stephen Warren | 95dcd4a | 2012-02-22 14:25:59 -0700 | [diff] [blame] | 216 | if (pindesc == NULL) { |
| 217 | dev_err(pctldev->dev, "failed to alloc struct pin_desc\n"); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 218 | return -ENOMEM; |
Stephen Warren | 95dcd4a | 2012-02-22 14:25:59 -0700 | [diff] [blame] | 219 | } |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 220 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 221 | /* Set owner */ |
| 222 | pindesc->pctldev = pctldev; |
| 223 | |
Stephen Warren | 9af1e44 | 2011-10-19 16:19:27 -0600 | [diff] [blame] | 224 | /* Copy basic pin info */ |
Linus Walleij | 8dc6ae4 | 2012-02-01 18:11:40 +0100 | [diff] [blame] | 225 | if (name) { |
Linus Walleij | ca53c5f | 2011-12-14 20:33:37 +0100 | [diff] [blame] | 226 | pindesc->name = name; |
| 227 | } else { |
| 228 | pindesc->name = kasprintf(GFP_KERNEL, "PIN%u", number); |
Sachin Kamat | eb26cc9 | 2012-09-25 12:41:40 +0530 | [diff] [blame] | 229 | if (pindesc->name == NULL) { |
| 230 | kfree(pindesc); |
Linus Walleij | ca53c5f | 2011-12-14 20:33:37 +0100 | [diff] [blame] | 231 | return -ENOMEM; |
Sachin Kamat | eb26cc9 | 2012-09-25 12:41:40 +0530 | [diff] [blame] | 232 | } |
Linus Walleij | ca53c5f | 2011-12-14 20:33:37 +0100 | [diff] [blame] | 233 | pindesc->dynamic_name = true; |
| 234 | } |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 235 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 236 | radix_tree_insert(&pctldev->pin_desc_tree, number, pindesc); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 237 | pr_debug("registered pin %d (%s) on %s\n", |
Linus Walleij | ca53c5f | 2011-12-14 20:33:37 +0100 | [diff] [blame] | 238 | number, pindesc->name, pctldev->desc->name); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | static int pinctrl_register_pins(struct pinctrl_dev *pctldev, |
| 243 | struct pinctrl_pin_desc const *pins, |
| 244 | unsigned num_descs) |
| 245 | { |
| 246 | unsigned i; |
| 247 | int ret = 0; |
| 248 | |
| 249 | for (i = 0; i < num_descs; i++) { |
| 250 | ret = pinctrl_register_one_pin(pctldev, |
| 251 | pins[i].number, pins[i].name); |
| 252 | if (ret) |
| 253 | return ret; |
| 254 | } |
| 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * pinctrl_match_gpio_range() - check if a certain GPIO pin is in range |
| 261 | * @pctldev: pin controller device to check |
| 262 | * @gpio: gpio pin to check taken from the global GPIO pin space |
| 263 | * |
| 264 | * Tries to match a GPIO pin number to the ranges handled by a certain pin |
| 265 | * controller, return the range or NULL |
| 266 | */ |
| 267 | static struct pinctrl_gpio_range * |
| 268 | pinctrl_match_gpio_range(struct pinctrl_dev *pctldev, unsigned gpio) |
| 269 | { |
| 270 | struct pinctrl_gpio_range *range = NULL; |
| 271 | |
| 272 | /* Loop over the ranges */ |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 273 | list_for_each_entry(range, &pctldev->gpio_ranges, node) { |
| 274 | /* Check if we're in the valid range */ |
| 275 | if (gpio >= range->base && |
| 276 | gpio < range->base + range->npins) { |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 277 | return range; |
| 278 | } |
| 279 | } |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 280 | |
| 281 | return NULL; |
| 282 | } |
| 283 | |
| 284 | /** |
Haojian Zhuang | 51e13c2 | 2013-02-17 19:42:50 +0800 | [diff] [blame] | 285 | * pinctrl_ready_for_gpio_range() - check if other GPIO pins of |
| 286 | * the same GPIO chip are in range |
| 287 | * @gpio: gpio pin to check taken from the global GPIO pin space |
| 288 | * |
| 289 | * This function is complement of pinctrl_match_gpio_range(). If the return |
| 290 | * value of pinctrl_match_gpio_range() is NULL, this function could be used |
| 291 | * to check whether pinctrl device is ready or not. Maybe some GPIO pins |
| 292 | * of the same GPIO chip don't have back-end pinctrl interface. |
| 293 | * If the return value is true, it means that pinctrl device is ready & the |
| 294 | * certain GPIO pin doesn't have back-end pinctrl device. If the return value |
| 295 | * is false, it means that pinctrl device may not be ready. |
| 296 | */ |
Haojian Zhuang | 2afe822 | 2013-03-28 07:34:19 +0800 | [diff] [blame^] | 297 | #ifdef CONFIG_GPIOLIB |
Haojian Zhuang | 51e13c2 | 2013-02-17 19:42:50 +0800 | [diff] [blame] | 298 | static bool pinctrl_ready_for_gpio_range(unsigned gpio) |
| 299 | { |
| 300 | struct pinctrl_dev *pctldev; |
| 301 | struct pinctrl_gpio_range *range = NULL; |
| 302 | struct gpio_chip *chip = gpio_to_chip(gpio); |
| 303 | |
| 304 | /* Loop over the pin controllers */ |
| 305 | list_for_each_entry(pctldev, &pinctrldev_list, node) { |
| 306 | /* Loop over the ranges */ |
| 307 | list_for_each_entry(range, &pctldev->gpio_ranges, node) { |
| 308 | /* Check if any gpio range overlapped with gpio chip */ |
| 309 | if (range->base + range->npins - 1 < chip->base || |
| 310 | range->base > chip->base + chip->ngpio - 1) |
| 311 | continue; |
| 312 | return true; |
| 313 | } |
| 314 | } |
| 315 | return false; |
| 316 | } |
Haojian Zhuang | 2afe822 | 2013-03-28 07:34:19 +0800 | [diff] [blame^] | 317 | #else |
| 318 | static bool pinctrl_ready_for_gpio_range(unsigned gpio) { return true; } |
| 319 | #endif |
Haojian Zhuang | 51e13c2 | 2013-02-17 19:42:50 +0800 | [diff] [blame] | 320 | |
| 321 | /** |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 322 | * pinctrl_get_device_gpio_range() - find device for GPIO range |
| 323 | * @gpio: the pin to locate the pin controller for |
| 324 | * @outdev: the pin control device if found |
| 325 | * @outrange: the GPIO range if found |
| 326 | * |
| 327 | * Find the pin controller handling a certain GPIO pin from the pinspace of |
| 328 | * the GPIO subsystem, return the device and the matching GPIO range. Returns |
Dong Aisheng | 4650b7c | 2012-04-25 19:38:13 +0800 | [diff] [blame] | 329 | * -EPROBE_DEFER if the GPIO range could not be found in any device since it |
| 330 | * may still have not been registered. |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 331 | */ |
Stephen Warren | 4ecce45d | 2012-02-19 23:45:47 -0700 | [diff] [blame] | 332 | static int pinctrl_get_device_gpio_range(unsigned gpio, |
| 333 | struct pinctrl_dev **outdev, |
| 334 | struct pinctrl_gpio_range **outrange) |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 335 | { |
| 336 | struct pinctrl_dev *pctldev = NULL; |
| 337 | |
| 338 | /* Loop over the pin controllers */ |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 339 | list_for_each_entry(pctldev, &pinctrldev_list, node) { |
| 340 | struct pinctrl_gpio_range *range; |
| 341 | |
| 342 | range = pinctrl_match_gpio_range(pctldev, gpio); |
| 343 | if (range != NULL) { |
| 344 | *outdev = pctldev; |
| 345 | *outrange = range; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 346 | return 0; |
| 347 | } |
| 348 | } |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 349 | |
Dong Aisheng | 4650b7c | 2012-04-25 19:38:13 +0800 | [diff] [blame] | 350 | return -EPROBE_DEFER; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /** |
| 354 | * pinctrl_add_gpio_range() - register a GPIO range for a controller |
| 355 | * @pctldev: pin controller device to add the range to |
| 356 | * @range: the GPIO range to add |
| 357 | * |
| 358 | * This adds a range of GPIOs to be handled by a certain pin controller. Call |
| 359 | * this to register handled ranges after registering your pin controller. |
| 360 | */ |
| 361 | void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev, |
| 362 | struct pinctrl_gpio_range *range) |
| 363 | { |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 364 | mutex_lock(&pinctrl_mutex); |
Stephen Warren | 8b9c139 | 2012-02-19 23:45:42 -0700 | [diff] [blame] | 365 | list_add_tail(&range->node, &pctldev->gpio_ranges); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 366 | mutex_unlock(&pinctrl_mutex); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 367 | } |
Stephen Warren | 4ecce45d | 2012-02-19 23:45:47 -0700 | [diff] [blame] | 368 | EXPORT_SYMBOL_GPL(pinctrl_add_gpio_range); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 369 | |
Dong Aisheng | 3e5e00b | 2012-05-23 21:22:41 +0800 | [diff] [blame] | 370 | void pinctrl_add_gpio_ranges(struct pinctrl_dev *pctldev, |
| 371 | struct pinctrl_gpio_range *ranges, |
| 372 | unsigned nranges) |
| 373 | { |
| 374 | int i; |
| 375 | |
| 376 | for (i = 0; i < nranges; i++) |
| 377 | pinctrl_add_gpio_range(pctldev, &ranges[i]); |
| 378 | } |
| 379 | EXPORT_SYMBOL_GPL(pinctrl_add_gpio_ranges); |
| 380 | |
Linus Walleij | 192c369 | 2012-11-20 14:03:37 +0100 | [diff] [blame] | 381 | struct pinctrl_dev *pinctrl_find_and_add_gpio_range(const char *devname, |
Shiraz Hashim | f23f151 | 2012-10-27 15:21:36 +0530 | [diff] [blame] | 382 | struct pinctrl_gpio_range *range) |
| 383 | { |
| 384 | struct pinctrl_dev *pctldev = get_pinctrl_dev_from_devname(devname); |
| 385 | |
Linus Walleij | dfa9751 | 2012-11-20 14:54:18 +0100 | [diff] [blame] | 386 | /* |
| 387 | * If we can't find this device, let's assume that is because |
| 388 | * it has not probed yet, so the driver trying to register this |
| 389 | * range need to defer probing. |
| 390 | */ |
Shiraz Hashim | f23f151 | 2012-10-27 15:21:36 +0530 | [diff] [blame] | 391 | if (!pctldev) |
Linus Walleij | dfa9751 | 2012-11-20 14:54:18 +0100 | [diff] [blame] | 392 | return ERR_PTR(-EPROBE_DEFER); |
Shiraz Hashim | f23f151 | 2012-10-27 15:21:36 +0530 | [diff] [blame] | 393 | |
| 394 | pinctrl_add_gpio_range(pctldev, range); |
| 395 | return pctldev; |
| 396 | } |
Linus Walleij | 192c369 | 2012-11-20 14:03:37 +0100 | [diff] [blame] | 397 | EXPORT_SYMBOL_GPL(pinctrl_find_and_add_gpio_range); |
Shiraz Hashim | f23f151 | 2012-10-27 15:21:36 +0530 | [diff] [blame] | 398 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 399 | /** |
Linus Walleij | 9afbefb | 2012-11-20 14:25:07 +0100 | [diff] [blame] | 400 | * pinctrl_find_gpio_range_from_pin() - locate the GPIO range for a pin |
| 401 | * @pctldev: the pin controller device to look in |
| 402 | * @pin: a controller-local number to find the range for |
| 403 | */ |
| 404 | struct pinctrl_gpio_range * |
| 405 | pinctrl_find_gpio_range_from_pin(struct pinctrl_dev *pctldev, |
| 406 | unsigned int pin) |
| 407 | { |
| 408 | struct pinctrl_gpio_range *range = NULL; |
| 409 | |
| 410 | /* Loop over the ranges */ |
| 411 | list_for_each_entry(range, &pctldev->gpio_ranges, node) { |
| 412 | /* Check if we're in the valid range */ |
| 413 | if (pin >= range->pin_base && |
| 414 | pin < range->pin_base + range->npins) { |
| 415 | return range; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | return NULL; |
| 420 | } |
| 421 | EXPORT_SYMBOL_GPL(pinctrl_find_gpio_range_from_pin); |
| 422 | |
| 423 | /** |
Viresh Kumar | 7e10ee6 | 2012-10-27 15:21:35 +0530 | [diff] [blame] | 424 | * pinctrl_remove_gpio_range() - remove a range of GPIOs fro a pin controller |
| 425 | * @pctldev: pin controller device to remove the range from |
| 426 | * @range: the GPIO range to remove |
| 427 | */ |
| 428 | void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev, |
| 429 | struct pinctrl_gpio_range *range) |
| 430 | { |
| 431 | mutex_lock(&pinctrl_mutex); |
| 432 | list_del(&range->node); |
| 433 | mutex_unlock(&pinctrl_mutex); |
| 434 | } |
| 435 | EXPORT_SYMBOL_GPL(pinctrl_remove_gpio_range); |
| 436 | |
| 437 | /** |
Linus Walleij | 7afde8b | 2011-10-19 17:07:16 +0200 | [diff] [blame] | 438 | * pinctrl_get_group_selector() - returns the group selector for a group |
| 439 | * @pctldev: the pin controller handling the group |
| 440 | * @pin_group: the pin group to look up |
| 441 | */ |
| 442 | int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, |
| 443 | const char *pin_group) |
| 444 | { |
| 445 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; |
Viresh Kumar | d1e90e9 | 2012-03-30 11:25:40 +0530 | [diff] [blame] | 446 | unsigned ngroups = pctlops->get_groups_count(pctldev); |
Linus Walleij | 7afde8b | 2011-10-19 17:07:16 +0200 | [diff] [blame] | 447 | unsigned group_selector = 0; |
| 448 | |
Viresh Kumar | d1e90e9 | 2012-03-30 11:25:40 +0530 | [diff] [blame] | 449 | while (group_selector < ngroups) { |
Linus Walleij | 7afde8b | 2011-10-19 17:07:16 +0200 | [diff] [blame] | 450 | const char *gname = pctlops->get_group_name(pctldev, |
| 451 | group_selector); |
| 452 | if (!strcmp(gname, pin_group)) { |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 453 | dev_dbg(pctldev->dev, |
Linus Walleij | 7afde8b | 2011-10-19 17:07:16 +0200 | [diff] [blame] | 454 | "found group selector %u for %s\n", |
| 455 | group_selector, |
| 456 | pin_group); |
| 457 | return group_selector; |
| 458 | } |
| 459 | |
| 460 | group_selector++; |
| 461 | } |
| 462 | |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 463 | dev_err(pctldev->dev, "does not have pin group %s\n", |
Linus Walleij | 7afde8b | 2011-10-19 17:07:16 +0200 | [diff] [blame] | 464 | pin_group); |
| 465 | |
| 466 | return -EINVAL; |
| 467 | } |
| 468 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 469 | /** |
| 470 | * pinctrl_request_gpio() - request a single pin to be used in as GPIO |
| 471 | * @gpio: the GPIO pin number from the GPIO subsystem number space |
| 472 | * |
| 473 | * This function should *ONLY* be used from gpiolib-based GPIO drivers, |
| 474 | * as part of their gpio_request() semantics, platforms and individual drivers |
| 475 | * shall *NOT* request GPIO pins to be muxed in. |
| 476 | */ |
| 477 | int pinctrl_request_gpio(unsigned gpio) |
| 478 | { |
| 479 | struct pinctrl_dev *pctldev; |
| 480 | struct pinctrl_gpio_range *range; |
| 481 | int ret; |
| 482 | int pin; |
| 483 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 484 | mutex_lock(&pinctrl_mutex); |
| 485 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 486 | ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 487 | if (ret) { |
Haojian Zhuang | 51e13c2 | 2013-02-17 19:42:50 +0800 | [diff] [blame] | 488 | if (pinctrl_ready_for_gpio_range(gpio)) |
| 489 | ret = 0; |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 490 | mutex_unlock(&pinctrl_mutex); |
Dong Aisheng | 4650b7c | 2012-04-25 19:38:13 +0800 | [diff] [blame] | 491 | return ret; |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 492 | } |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 493 | |
| 494 | /* Convert to the pin controllers number space */ |
| 495 | pin = gpio - range->base + range->pin_base; |
| 496 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 497 | ret = pinmux_request_gpio(pctldev, range, pin, gpio); |
| 498 | |
| 499 | mutex_unlock(&pinctrl_mutex); |
| 500 | return ret; |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 501 | } |
| 502 | EXPORT_SYMBOL_GPL(pinctrl_request_gpio); |
| 503 | |
| 504 | /** |
| 505 | * pinctrl_free_gpio() - free control on a single pin, currently used as GPIO |
| 506 | * @gpio: the GPIO pin number from the GPIO subsystem number space |
| 507 | * |
| 508 | * This function should *ONLY* be used from gpiolib-based GPIO drivers, |
| 509 | * as part of their gpio_free() semantics, platforms and individual drivers |
| 510 | * shall *NOT* request GPIO pins to be muxed out. |
| 511 | */ |
| 512 | void pinctrl_free_gpio(unsigned gpio) |
| 513 | { |
| 514 | struct pinctrl_dev *pctldev; |
| 515 | struct pinctrl_gpio_range *range; |
| 516 | int ret; |
| 517 | int pin; |
| 518 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 519 | mutex_lock(&pinctrl_mutex); |
| 520 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 521 | ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 522 | if (ret) { |
| 523 | mutex_unlock(&pinctrl_mutex); |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 524 | return; |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 525 | } |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 526 | |
| 527 | /* Convert to the pin controllers number space */ |
| 528 | pin = gpio - range->base + range->pin_base; |
| 529 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 530 | pinmux_free_gpio(pctldev, pin, range); |
| 531 | |
| 532 | mutex_unlock(&pinctrl_mutex); |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 533 | } |
| 534 | EXPORT_SYMBOL_GPL(pinctrl_free_gpio); |
| 535 | |
| 536 | static int pinctrl_gpio_direction(unsigned gpio, bool input) |
| 537 | { |
| 538 | struct pinctrl_dev *pctldev; |
| 539 | struct pinctrl_gpio_range *range; |
| 540 | int ret; |
| 541 | int pin; |
| 542 | |
| 543 | ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range); |
| 544 | if (ret) |
| 545 | return ret; |
| 546 | |
| 547 | /* Convert to the pin controllers number space */ |
| 548 | pin = gpio - range->base + range->pin_base; |
| 549 | |
| 550 | return pinmux_gpio_direction(pctldev, range, pin, input); |
| 551 | } |
| 552 | |
| 553 | /** |
| 554 | * pinctrl_gpio_direction_input() - request a GPIO pin to go into input mode |
| 555 | * @gpio: the GPIO pin number from the GPIO subsystem number space |
| 556 | * |
| 557 | * This function should *ONLY* be used from gpiolib-based GPIO drivers, |
| 558 | * as part of their gpio_direction_input() semantics, platforms and individual |
| 559 | * drivers shall *NOT* touch pin control GPIO calls. |
| 560 | */ |
| 561 | int pinctrl_gpio_direction_input(unsigned gpio) |
| 562 | { |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 563 | int ret; |
| 564 | mutex_lock(&pinctrl_mutex); |
| 565 | ret = pinctrl_gpio_direction(gpio, true); |
| 566 | mutex_unlock(&pinctrl_mutex); |
| 567 | return ret; |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 568 | } |
| 569 | EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input); |
| 570 | |
| 571 | /** |
| 572 | * pinctrl_gpio_direction_output() - request a GPIO pin to go into output mode |
| 573 | * @gpio: the GPIO pin number from the GPIO subsystem number space |
| 574 | * |
| 575 | * This function should *ONLY* be used from gpiolib-based GPIO drivers, |
| 576 | * as part of their gpio_direction_output() semantics, platforms and individual |
| 577 | * drivers shall *NOT* touch pin control GPIO calls. |
| 578 | */ |
| 579 | int pinctrl_gpio_direction_output(unsigned gpio) |
| 580 | { |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 581 | int ret; |
| 582 | mutex_lock(&pinctrl_mutex); |
| 583 | ret = pinctrl_gpio_direction(gpio, false); |
| 584 | mutex_unlock(&pinctrl_mutex); |
| 585 | return ret; |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 586 | } |
| 587 | EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output); |
| 588 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 589 | static struct pinctrl_state *find_state(struct pinctrl *p, |
| 590 | const char *name) |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 591 | { |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 592 | struct pinctrl_state *state; |
| 593 | |
| 594 | list_for_each_entry(state, &p->states, node) |
| 595 | if (!strcmp(state->name, name)) |
| 596 | return state; |
| 597 | |
| 598 | return NULL; |
| 599 | } |
| 600 | |
| 601 | static struct pinctrl_state *create_state(struct pinctrl *p, |
| 602 | const char *name) |
| 603 | { |
| 604 | struct pinctrl_state *state; |
| 605 | |
| 606 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
| 607 | if (state == NULL) { |
| 608 | dev_err(p->dev, |
| 609 | "failed to alloc struct pinctrl_state\n"); |
| 610 | return ERR_PTR(-ENOMEM); |
| 611 | } |
| 612 | |
| 613 | state->name = name; |
| 614 | INIT_LIST_HEAD(&state->settings); |
| 615 | |
| 616 | list_add_tail(&state->node, &p->states); |
| 617 | |
| 618 | return state; |
| 619 | } |
| 620 | |
| 621 | static int add_setting(struct pinctrl *p, struct pinctrl_map const *map) |
| 622 | { |
| 623 | struct pinctrl_state *state; |
| 624 | struct pinctrl_setting *setting; |
Stephen Warren | 7ecdb16 | 2012-03-02 13:05:45 -0700 | [diff] [blame] | 625 | int ret; |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 626 | |
| 627 | state = find_state(p, map->name); |
| 628 | if (!state) |
| 629 | state = create_state(p, map->name); |
| 630 | if (IS_ERR(state)) |
| 631 | return PTR_ERR(state); |
| 632 | |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 633 | if (map->type == PIN_MAP_TYPE_DUMMY_STATE) |
| 634 | return 0; |
| 635 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 636 | setting = kzalloc(sizeof(*setting), GFP_KERNEL); |
| 637 | if (setting == NULL) { |
| 638 | dev_err(p->dev, |
| 639 | "failed to alloc struct pinctrl_setting\n"); |
| 640 | return -ENOMEM; |
| 641 | } |
| 642 | |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 643 | setting->type = map->type; |
| 644 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 645 | setting->pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name); |
| 646 | if (setting->pctldev == NULL) { |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 647 | kfree(setting); |
Linus Walleij | 8921649 | 2012-12-11 14:14:32 +0100 | [diff] [blame] | 648 | /* Do not defer probing of hogs (circular loop) */ |
| 649 | if (!strcmp(map->ctrl_dev_name, map->dev_name)) |
| 650 | return -ENODEV; |
Linus Walleij | c05127c | 2012-04-10 10:00:38 +0200 | [diff] [blame] | 651 | /* |
| 652 | * OK let us guess that the driver is not there yet, and |
| 653 | * let's defer obtaining this pinctrl handle to later... |
| 654 | */ |
Linus Walleij | 8921649 | 2012-12-11 14:14:32 +0100 | [diff] [blame] | 655 | dev_info(p->dev, "unknown pinctrl device %s in map entry, deferring probe", |
| 656 | map->ctrl_dev_name); |
Linus Walleij | c05127c | 2012-04-10 10:00:38 +0200 | [diff] [blame] | 657 | return -EPROBE_DEFER; |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Linus Walleij | 1a78958 | 2012-10-17 20:51:54 +0200 | [diff] [blame] | 660 | setting->dev_name = map->dev_name; |
| 661 | |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 662 | switch (map->type) { |
| 663 | case PIN_MAP_TYPE_MUX_GROUP: |
| 664 | ret = pinmux_map_to_setting(map, setting); |
| 665 | break; |
| 666 | case PIN_MAP_TYPE_CONFIGS_PIN: |
| 667 | case PIN_MAP_TYPE_CONFIGS_GROUP: |
| 668 | ret = pinconf_map_to_setting(map, setting); |
| 669 | break; |
| 670 | default: |
| 671 | ret = -EINVAL; |
| 672 | break; |
| 673 | } |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 674 | if (ret < 0) { |
| 675 | kfree(setting); |
| 676 | return ret; |
| 677 | } |
| 678 | |
| 679 | list_add_tail(&setting->node, &state->settings); |
| 680 | |
| 681 | return 0; |
| 682 | } |
| 683 | |
| 684 | static struct pinctrl *find_pinctrl(struct device *dev) |
| 685 | { |
| 686 | struct pinctrl *p; |
| 687 | |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 688 | list_for_each_entry(p, &pinctrl_list, node) |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 689 | if (p->dev == dev) |
| 690 | return p; |
| 691 | |
| 692 | return NULL; |
| 693 | } |
| 694 | |
| 695 | static void pinctrl_put_locked(struct pinctrl *p, bool inlist); |
| 696 | |
| 697 | static struct pinctrl *create_pinctrl(struct device *dev) |
| 698 | { |
| 699 | struct pinctrl *p; |
| 700 | const char *devname; |
Stephen Warren | b2b3e66 | 2012-02-19 23:45:43 -0700 | [diff] [blame] | 701 | struct pinctrl_maps *maps_node; |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 702 | int i; |
Stephen Warren | b2b3e66 | 2012-02-19 23:45:43 -0700 | [diff] [blame] | 703 | struct pinctrl_map const *map; |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 704 | int ret; |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 705 | |
| 706 | /* |
| 707 | * create the state cookie holder struct pinctrl for each |
| 708 | * mapping, this is what consumers will get when requesting |
| 709 | * a pin control handle with pinctrl_get() |
| 710 | */ |
Stephen Warren | 02f5b98 | 2012-02-22 14:26:00 -0700 | [diff] [blame] | 711 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
Stephen Warren | 95dcd4a | 2012-02-22 14:25:59 -0700 | [diff] [blame] | 712 | if (p == NULL) { |
| 713 | dev_err(dev, "failed to alloc struct pinctrl\n"); |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 714 | return ERR_PTR(-ENOMEM); |
Stephen Warren | 95dcd4a | 2012-02-22 14:25:59 -0700 | [diff] [blame] | 715 | } |
Stephen Warren | 7ecdb16 | 2012-03-02 13:05:45 -0700 | [diff] [blame] | 716 | p->dev = dev; |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 717 | INIT_LIST_HEAD(&p->states); |
Stephen Warren | 57291ce | 2012-03-23 10:29:46 -0600 | [diff] [blame] | 718 | INIT_LIST_HEAD(&p->dt_maps); |
| 719 | |
| 720 | ret = pinctrl_dt_to_map(p); |
| 721 | if (ret < 0) { |
| 722 | kfree(p); |
| 723 | return ERR_PTR(ret); |
| 724 | } |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 725 | |
| 726 | devname = dev_name(dev); |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 727 | |
| 728 | /* Iterate over the pin control maps to locate the right ones */ |
Stephen Warren | b2b3e66 | 2012-02-19 23:45:43 -0700 | [diff] [blame] | 729 | for_each_maps(maps_node, i, map) { |
Stephen Warren | 1681f5a | 2012-02-22 14:25:58 -0700 | [diff] [blame] | 730 | /* Map must be for this device */ |
| 731 | if (strcmp(map->dev_name, devname)) |
| 732 | continue; |
| 733 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 734 | ret = add_setting(p, map); |
Linus Walleij | 8921649 | 2012-12-11 14:14:32 +0100 | [diff] [blame] | 735 | /* |
| 736 | * At this point the adding of a setting may: |
| 737 | * |
| 738 | * - Defer, if the pinctrl device is not yet available |
| 739 | * - Fail, if the pinctrl device is not yet available, |
| 740 | * AND the setting is a hog. We cannot defer that, since |
| 741 | * the hog will kick in immediately after the device |
| 742 | * is registered. |
| 743 | * |
| 744 | * If the error returned was not -EPROBE_DEFER then we |
| 745 | * accumulate the errors to see if we end up with |
| 746 | * an -EPROBE_DEFER later, as that is the worst case. |
| 747 | */ |
| 748 | if (ret == -EPROBE_DEFER) { |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 749 | pinctrl_put_locked(p, false); |
| 750 | return ERR_PTR(ret); |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 751 | } |
| 752 | } |
Linus Walleij | 8921649 | 2012-12-11 14:14:32 +0100 | [diff] [blame] | 753 | if (ret < 0) { |
| 754 | /* If some other error than deferral occured, return here */ |
| 755 | pinctrl_put_locked(p, false); |
| 756 | return ERR_PTR(ret); |
| 757 | } |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 758 | |
Linus Walleij | ab78029 | 2013-01-22 10:56:14 -0700 | [diff] [blame] | 759 | kref_init(&p->users); |
| 760 | |
Linus Walleij | b0666ba | 2012-12-11 13:12:35 +0100 | [diff] [blame] | 761 | /* Add the pinctrl handle to the global list */ |
Stephen Warren | 8b9c139 | 2012-02-19 23:45:42 -0700 | [diff] [blame] | 762 | list_add_tail(&p->node, &pinctrl_list); |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 763 | |
| 764 | return p; |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 765 | } |
Stephen Warren | 7ecdb16 | 2012-03-02 13:05:45 -0700 | [diff] [blame] | 766 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 767 | static struct pinctrl *pinctrl_get_locked(struct device *dev) |
| 768 | { |
| 769 | struct pinctrl *p; |
Stephen Warren | 7ecdb16 | 2012-03-02 13:05:45 -0700 | [diff] [blame] | 770 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 771 | if (WARN_ON(!dev)) |
| 772 | return ERR_PTR(-EINVAL); |
Stephen Warren | 7ecdb16 | 2012-03-02 13:05:45 -0700 | [diff] [blame] | 773 | |
Linus Walleij | ab78029 | 2013-01-22 10:56:14 -0700 | [diff] [blame] | 774 | /* |
| 775 | * See if somebody else (such as the device core) has already |
| 776 | * obtained a handle to the pinctrl for this device. In that case, |
| 777 | * return another pointer to it. |
| 778 | */ |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 779 | p = find_pinctrl(dev); |
Linus Walleij | ab78029 | 2013-01-22 10:56:14 -0700 | [diff] [blame] | 780 | if (p != NULL) { |
| 781 | dev_dbg(dev, "obtain a copy of previously claimed pinctrl\n"); |
| 782 | kref_get(&p->users); |
| 783 | return p; |
| 784 | } |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 785 | |
Richard Genoud | d599bfb | 2012-08-10 16:53:49 +0200 | [diff] [blame] | 786 | return create_pinctrl(dev); |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 787 | } |
Stephen Warren | b2b3e66 | 2012-02-19 23:45:43 -0700 | [diff] [blame] | 788 | |
| 789 | /** |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 790 | * pinctrl_get() - retrieves the pinctrl handle for a device |
| 791 | * @dev: the device to obtain the handle for |
Stephen Warren | b2b3e66 | 2012-02-19 23:45:43 -0700 | [diff] [blame] | 792 | */ |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 793 | struct pinctrl *pinctrl_get(struct device *dev) |
Stephen Warren | b2b3e66 | 2012-02-19 23:45:43 -0700 | [diff] [blame] | 794 | { |
| 795 | struct pinctrl *p; |
| 796 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 797 | mutex_lock(&pinctrl_mutex); |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 798 | p = pinctrl_get_locked(dev); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 799 | mutex_unlock(&pinctrl_mutex); |
Stephen Warren | b2b3e66 | 2012-02-19 23:45:43 -0700 | [diff] [blame] | 800 | |
| 801 | return p; |
| 802 | } |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 803 | EXPORT_SYMBOL_GPL(pinctrl_get); |
| 804 | |
Richard Genoud | d3cee830 | 2013-03-25 15:47:21 +0100 | [diff] [blame] | 805 | static void pinctrl_free_setting(bool disable_setting, |
| 806 | struct pinctrl_setting *setting) |
| 807 | { |
| 808 | switch (setting->type) { |
| 809 | case PIN_MAP_TYPE_MUX_GROUP: |
| 810 | if (disable_setting) |
| 811 | pinmux_disable_setting(setting); |
| 812 | pinmux_free_setting(setting); |
| 813 | break; |
| 814 | case PIN_MAP_TYPE_CONFIGS_PIN: |
| 815 | case PIN_MAP_TYPE_CONFIGS_GROUP: |
| 816 | pinconf_free_setting(setting); |
| 817 | break; |
| 818 | default: |
| 819 | break; |
| 820 | } |
| 821 | } |
| 822 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 823 | static void pinctrl_put_locked(struct pinctrl *p, bool inlist) |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 824 | { |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 825 | struct pinctrl_state *state, *n1; |
| 826 | struct pinctrl_setting *setting, *n2; |
Stephen Warren | 7ecdb16 | 2012-03-02 13:05:45 -0700 | [diff] [blame] | 827 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 828 | list_for_each_entry_safe(state, n1, &p->states, node) { |
| 829 | list_for_each_entry_safe(setting, n2, &state->settings, node) { |
Richard Genoud | d3cee830 | 2013-03-25 15:47:21 +0100 | [diff] [blame] | 830 | pinctrl_free_setting(state == p->state, setting); |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 831 | list_del(&setting->node); |
| 832 | kfree(setting); |
| 833 | } |
| 834 | list_del(&state->node); |
| 835 | kfree(state); |
Stephen Warren | 7ecdb16 | 2012-03-02 13:05:45 -0700 | [diff] [blame] | 836 | } |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 837 | |
Stephen Warren | 57291ce | 2012-03-23 10:29:46 -0600 | [diff] [blame] | 838 | pinctrl_dt_free_maps(p); |
| 839 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 840 | if (inlist) |
| 841 | list_del(&p->node); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 842 | kfree(p); |
| 843 | } |
| 844 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 845 | /** |
Linus Walleij | ab78029 | 2013-01-22 10:56:14 -0700 | [diff] [blame] | 846 | * pinctrl_release() - release the pinctrl handle |
| 847 | * @kref: the kref in the pinctrl being released |
| 848 | */ |
Sachin Kamat | 2917e83 | 2013-01-24 15:01:00 +0530 | [diff] [blame] | 849 | static void pinctrl_release(struct kref *kref) |
Linus Walleij | ab78029 | 2013-01-22 10:56:14 -0700 | [diff] [blame] | 850 | { |
| 851 | struct pinctrl *p = container_of(kref, struct pinctrl, users); |
| 852 | |
| 853 | pinctrl_put_locked(p, true); |
| 854 | } |
| 855 | |
| 856 | /** |
| 857 | * pinctrl_put() - decrease use count on a previously claimed pinctrl handle |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 858 | * @p: the pinctrl handle to release |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 859 | */ |
| 860 | void pinctrl_put(struct pinctrl *p) |
| 861 | { |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 862 | mutex_lock(&pinctrl_mutex); |
Linus Walleij | ab78029 | 2013-01-22 10:56:14 -0700 | [diff] [blame] | 863 | kref_put(&p->users, pinctrl_release); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 864 | mutex_unlock(&pinctrl_mutex); |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 865 | } |
| 866 | EXPORT_SYMBOL_GPL(pinctrl_put); |
| 867 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 868 | static struct pinctrl_state *pinctrl_lookup_state_locked(struct pinctrl *p, |
| 869 | const char *name) |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 870 | { |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 871 | struct pinctrl_state *state; |
| 872 | |
| 873 | state = find_state(p, name); |
Dong Aisheng | 5b3aa5f | 2012-04-26 16:15:50 +0800 | [diff] [blame] | 874 | if (!state) { |
| 875 | if (pinctrl_dummy_state) { |
| 876 | /* create dummy state */ |
| 877 | dev_dbg(p->dev, "using pinctrl dummy state (%s)\n", |
| 878 | name); |
| 879 | state = create_state(p, name); |
Richard Genoud | d599bfb | 2012-08-10 16:53:49 +0200 | [diff] [blame] | 880 | } else |
| 881 | state = ERR_PTR(-ENODEV); |
Dong Aisheng | 5b3aa5f | 2012-04-26 16:15:50 +0800 | [diff] [blame] | 882 | } |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 883 | |
| 884 | return state; |
| 885 | } |
| 886 | |
| 887 | /** |
| 888 | * pinctrl_lookup_state() - retrieves a state handle from a pinctrl handle |
| 889 | * @p: the pinctrl handle to retrieve the state from |
| 890 | * @name: the state name to retrieve |
| 891 | */ |
| 892 | struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p, const char *name) |
| 893 | { |
| 894 | struct pinctrl_state *s; |
| 895 | |
| 896 | mutex_lock(&pinctrl_mutex); |
| 897 | s = pinctrl_lookup_state_locked(p, name); |
| 898 | mutex_unlock(&pinctrl_mutex); |
| 899 | |
| 900 | return s; |
| 901 | } |
| 902 | EXPORT_SYMBOL_GPL(pinctrl_lookup_state); |
| 903 | |
| 904 | static int pinctrl_select_state_locked(struct pinctrl *p, |
| 905 | struct pinctrl_state *state) |
| 906 | { |
| 907 | struct pinctrl_setting *setting, *setting2; |
Richard Genoud | 50cf7c8 | 2013-03-25 15:47:23 +0100 | [diff] [blame] | 908 | struct pinctrl_state *old_state = p->state; |
Stephen Warren | 7ecdb16 | 2012-03-02 13:05:45 -0700 | [diff] [blame] | 909 | int ret; |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 910 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 911 | if (p->state == state) |
| 912 | return 0; |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 913 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 914 | if (p->state) { |
| 915 | /* |
| 916 | * The set of groups with a mux configuration in the old state |
| 917 | * may not be identical to the set of groups with a mux setting |
| 918 | * in the new state. While this might be unusual, it's entirely |
| 919 | * possible for the "user"-supplied mapping table to be written |
| 920 | * that way. For each group that was configured in the old state |
| 921 | * but not in the new state, this code puts that group into a |
| 922 | * safe/disabled state. |
| 923 | */ |
| 924 | list_for_each_entry(setting, &p->state->settings, node) { |
| 925 | bool found = false; |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 926 | if (setting->type != PIN_MAP_TYPE_MUX_GROUP) |
| 927 | continue; |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 928 | list_for_each_entry(setting2, &state->settings, node) { |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 929 | if (setting2->type != PIN_MAP_TYPE_MUX_GROUP) |
| 930 | continue; |
| 931 | if (setting2->data.mux.group == |
| 932 | setting->data.mux.group) { |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 933 | found = true; |
| 934 | break; |
| 935 | } |
Stephen Warren | 7ecdb16 | 2012-03-02 13:05:45 -0700 | [diff] [blame] | 936 | } |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 937 | if (!found) |
| 938 | pinmux_disable_setting(setting); |
| 939 | } |
| 940 | } |
| 941 | |
Richard Genoud | 3102a76 | 2013-03-25 15:47:22 +0100 | [diff] [blame] | 942 | p->state = NULL; |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 943 | |
| 944 | /* Apply all the settings for the new state */ |
| 945 | list_for_each_entry(setting, &state->settings, node) { |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 946 | switch (setting->type) { |
| 947 | case PIN_MAP_TYPE_MUX_GROUP: |
| 948 | ret = pinmux_enable_setting(setting); |
| 949 | break; |
| 950 | case PIN_MAP_TYPE_CONFIGS_PIN: |
| 951 | case PIN_MAP_TYPE_CONFIGS_GROUP: |
| 952 | ret = pinconf_apply_setting(setting); |
| 953 | break; |
| 954 | default: |
| 955 | ret = -EINVAL; |
| 956 | break; |
| 957 | } |
Richard Genoud | 3102a76 | 2013-03-25 15:47:22 +0100 | [diff] [blame] | 958 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 959 | if (ret < 0) { |
Richard Genoud | 3102a76 | 2013-03-25 15:47:22 +0100 | [diff] [blame] | 960 | goto unapply_new_state; |
Stephen Warren | 7ecdb16 | 2012-03-02 13:05:45 -0700 | [diff] [blame] | 961 | } |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 962 | } |
| 963 | |
Richard Genoud | 3102a76 | 2013-03-25 15:47:22 +0100 | [diff] [blame] | 964 | p->state = state; |
| 965 | |
Stephen Warren | 7ecdb16 | 2012-03-02 13:05:45 -0700 | [diff] [blame] | 966 | return 0; |
Richard Genoud | 3102a76 | 2013-03-25 15:47:22 +0100 | [diff] [blame] | 967 | |
| 968 | unapply_new_state: |
| 969 | pr_info("Error applying setting, reverse things back\n"); |
| 970 | |
| 971 | /* |
| 972 | * If the loop stopped on the 1st entry, nothing has been enabled, |
| 973 | * so jump directly to the 2nd phase |
| 974 | */ |
| 975 | if (list_entry(&setting->node, typeof(*setting), node) == |
| 976 | list_first_entry(&state->settings, typeof(*setting), node)) |
| 977 | goto reapply_old_state; |
| 978 | |
| 979 | list_for_each_entry(setting2, &state->settings, node) { |
| 980 | if (&setting2->node == &setting->node) |
| 981 | break; |
| 982 | pinctrl_free_setting(true, setting2); |
| 983 | } |
| 984 | reapply_old_state: |
Richard Genoud | 50cf7c8 | 2013-03-25 15:47:23 +0100 | [diff] [blame] | 985 | if (old_state) { |
| 986 | list_for_each_entry(setting, &old_state->settings, node) { |
| 987 | bool found = false; |
| 988 | if (setting->type != PIN_MAP_TYPE_MUX_GROUP) |
| 989 | continue; |
| 990 | list_for_each_entry(setting2, &state->settings, node) { |
| 991 | if (setting2->type != PIN_MAP_TYPE_MUX_GROUP) |
| 992 | continue; |
| 993 | if (setting2->data.mux.group == |
| 994 | setting->data.mux.group) { |
| 995 | found = true; |
| 996 | break; |
| 997 | } |
| 998 | } |
| 999 | if (!found) |
| 1000 | pinmux_enable_setting(setting); |
| 1001 | } |
| 1002 | } |
Richard Genoud | 3102a76 | 2013-03-25 15:47:22 +0100 | [diff] [blame] | 1003 | return ret; |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1006 | /** |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 1007 | * pinctrl_select() - select/activate/program a pinctrl state to HW |
| 1008 | * @p: the pinctrl handle for the device that requests configuratio |
| 1009 | * @state: the state handle to select/activate/program |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1010 | */ |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 1011 | int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state) |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1012 | { |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1013 | int ret; |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 1014 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1015 | mutex_lock(&pinctrl_mutex); |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 1016 | ret = pinctrl_select_state_locked(p, state); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1017 | mutex_unlock(&pinctrl_mutex); |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 1018 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1019 | return ret; |
| 1020 | } |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 1021 | EXPORT_SYMBOL_GPL(pinctrl_select_state); |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1022 | |
Stephen Warren | 6d4ca1f | 2012-04-16 10:51:00 -0600 | [diff] [blame] | 1023 | static void devm_pinctrl_release(struct device *dev, void *res) |
| 1024 | { |
| 1025 | pinctrl_put(*(struct pinctrl **)res); |
| 1026 | } |
| 1027 | |
| 1028 | /** |
| 1029 | * struct devm_pinctrl_get() - Resource managed pinctrl_get() |
| 1030 | * @dev: the device to obtain the handle for |
| 1031 | * |
| 1032 | * If there is a need to explicitly destroy the returned struct pinctrl, |
| 1033 | * devm_pinctrl_put() should be used, rather than plain pinctrl_put(). |
| 1034 | */ |
| 1035 | struct pinctrl *devm_pinctrl_get(struct device *dev) |
| 1036 | { |
| 1037 | struct pinctrl **ptr, *p; |
| 1038 | |
| 1039 | ptr = devres_alloc(devm_pinctrl_release, sizeof(*ptr), GFP_KERNEL); |
| 1040 | if (!ptr) |
| 1041 | return ERR_PTR(-ENOMEM); |
| 1042 | |
| 1043 | p = pinctrl_get(dev); |
| 1044 | if (!IS_ERR(p)) { |
| 1045 | *ptr = p; |
| 1046 | devres_add(dev, ptr); |
| 1047 | } else { |
| 1048 | devres_free(ptr); |
| 1049 | } |
| 1050 | |
| 1051 | return p; |
| 1052 | } |
| 1053 | EXPORT_SYMBOL_GPL(devm_pinctrl_get); |
| 1054 | |
| 1055 | static int devm_pinctrl_match(struct device *dev, void *res, void *data) |
| 1056 | { |
| 1057 | struct pinctrl **p = res; |
| 1058 | |
| 1059 | return *p == data; |
| 1060 | } |
| 1061 | |
| 1062 | /** |
| 1063 | * devm_pinctrl_put() - Resource managed pinctrl_put() |
| 1064 | * @p: the pinctrl handle to release |
| 1065 | * |
| 1066 | * Deallocate a struct pinctrl obtained via devm_pinctrl_get(). Normally |
| 1067 | * this function will not need to be called and the resource management |
| 1068 | * code will ensure that the resource is freed. |
| 1069 | */ |
| 1070 | void devm_pinctrl_put(struct pinctrl *p) |
| 1071 | { |
Jingoo Han | a72149e | 2013-02-26 11:34:07 +0900 | [diff] [blame] | 1072 | WARN_ON(devres_release(p->dev, devm_pinctrl_release, |
Stephen Warren | 6d4ca1f | 2012-04-16 10:51:00 -0600 | [diff] [blame] | 1073 | devm_pinctrl_match, p)); |
Stephen Warren | 6d4ca1f | 2012-04-16 10:51:00 -0600 | [diff] [blame] | 1074 | } |
| 1075 | EXPORT_SYMBOL_GPL(devm_pinctrl_put); |
| 1076 | |
Stephen Warren | 57291ce | 2012-03-23 10:29:46 -0600 | [diff] [blame] | 1077 | int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps, |
| 1078 | bool dup, bool locked) |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1079 | { |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 1080 | int i, ret; |
Stephen Warren | b2b3e66 | 2012-02-19 23:45:43 -0700 | [diff] [blame] | 1081 | struct pinctrl_maps *maps_node; |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1082 | |
| 1083 | pr_debug("add %d pinmux maps\n", num_maps); |
| 1084 | |
| 1085 | /* First sanity check the new mapping */ |
| 1086 | for (i = 0; i < num_maps; i++) { |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 1087 | if (!maps[i].dev_name) { |
| 1088 | pr_err("failed to register map %s (%d): no device given\n", |
| 1089 | maps[i].name, i); |
| 1090 | return -EINVAL; |
| 1091 | } |
| 1092 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1093 | if (!maps[i].name) { |
| 1094 | pr_err("failed to register map %d: no map name given\n", |
Stephen Warren | 95dcd4a | 2012-02-22 14:25:59 -0700 | [diff] [blame] | 1095 | i); |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1096 | return -EINVAL; |
| 1097 | } |
| 1098 | |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 1099 | if (maps[i].type != PIN_MAP_TYPE_DUMMY_STATE && |
| 1100 | !maps[i].ctrl_dev_name) { |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1101 | pr_err("failed to register map %s (%d): no pin control device given\n", |
| 1102 | maps[i].name, i); |
| 1103 | return -EINVAL; |
| 1104 | } |
| 1105 | |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 1106 | switch (maps[i].type) { |
| 1107 | case PIN_MAP_TYPE_DUMMY_STATE: |
| 1108 | break; |
| 1109 | case PIN_MAP_TYPE_MUX_GROUP: |
| 1110 | ret = pinmux_validate_map(&maps[i], i); |
| 1111 | if (ret < 0) |
Stephen Warren | fde04f4 | 2012-04-25 10:32:16 -0600 | [diff] [blame] | 1112 | return ret; |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 1113 | break; |
| 1114 | case PIN_MAP_TYPE_CONFIGS_PIN: |
| 1115 | case PIN_MAP_TYPE_CONFIGS_GROUP: |
| 1116 | ret = pinconf_validate_map(&maps[i], i); |
| 1117 | if (ret < 0) |
Stephen Warren | fde04f4 | 2012-04-25 10:32:16 -0600 | [diff] [blame] | 1118 | return ret; |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 1119 | break; |
| 1120 | default: |
| 1121 | pr_err("failed to register map %s (%d): invalid type given\n", |
Stephen Warren | 95dcd4a | 2012-02-22 14:25:59 -0700 | [diff] [blame] | 1122 | maps[i].name, i); |
Stephen Warren | 1681f5a | 2012-02-22 14:25:58 -0700 | [diff] [blame] | 1123 | return -EINVAL; |
| 1124 | } |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1125 | } |
| 1126 | |
Stephen Warren | b2b3e66 | 2012-02-19 23:45:43 -0700 | [diff] [blame] | 1127 | maps_node = kzalloc(sizeof(*maps_node), GFP_KERNEL); |
| 1128 | if (!maps_node) { |
| 1129 | pr_err("failed to alloc struct pinctrl_maps\n"); |
| 1130 | return -ENOMEM; |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1131 | } |
| 1132 | |
Stephen Warren | b2b3e66 | 2012-02-19 23:45:43 -0700 | [diff] [blame] | 1133 | maps_node->num_maps = num_maps; |
Stephen Warren | 57291ce | 2012-03-23 10:29:46 -0600 | [diff] [blame] | 1134 | if (dup) { |
| 1135 | maps_node->maps = kmemdup(maps, sizeof(*maps) * num_maps, |
| 1136 | GFP_KERNEL); |
| 1137 | if (!maps_node->maps) { |
| 1138 | pr_err("failed to duplicate mapping table\n"); |
| 1139 | kfree(maps_node); |
| 1140 | return -ENOMEM; |
| 1141 | } |
| 1142 | } else { |
| 1143 | maps_node->maps = maps; |
Stephen Warren | b2b3e66 | 2012-02-19 23:45:43 -0700 | [diff] [blame] | 1144 | } |
| 1145 | |
Stephen Warren | 57291ce | 2012-03-23 10:29:46 -0600 | [diff] [blame] | 1146 | if (!locked) |
| 1147 | mutex_lock(&pinctrl_mutex); |
Stephen Warren | b2b3e66 | 2012-02-19 23:45:43 -0700 | [diff] [blame] | 1148 | list_add_tail(&maps_node->node, &pinctrl_maps); |
Stephen Warren | 57291ce | 2012-03-23 10:29:46 -0600 | [diff] [blame] | 1149 | if (!locked) |
| 1150 | mutex_unlock(&pinctrl_mutex); |
Stephen Warren | b2b3e66 | 2012-02-19 23:45:43 -0700 | [diff] [blame] | 1151 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1152 | return 0; |
| 1153 | } |
| 1154 | |
Stephen Warren | 57291ce | 2012-03-23 10:29:46 -0600 | [diff] [blame] | 1155 | /** |
| 1156 | * pinctrl_register_mappings() - register a set of pin controller mappings |
| 1157 | * @maps: the pincontrol mappings table to register. This should probably be |
| 1158 | * marked with __initdata so it can be discarded after boot. This |
| 1159 | * function will perform a shallow copy for the mapping entries. |
| 1160 | * @num_maps: the number of maps in the mapping table |
| 1161 | */ |
| 1162 | int pinctrl_register_mappings(struct pinctrl_map const *maps, |
| 1163 | unsigned num_maps) |
| 1164 | { |
| 1165 | return pinctrl_register_map(maps, num_maps, true, false); |
| 1166 | } |
| 1167 | |
| 1168 | void pinctrl_unregister_map(struct pinctrl_map const *map) |
| 1169 | { |
| 1170 | struct pinctrl_maps *maps_node; |
| 1171 | |
| 1172 | list_for_each_entry(maps_node, &pinctrl_maps, node) { |
| 1173 | if (maps_node->maps == map) { |
| 1174 | list_del(&maps_node->node); |
| 1175 | return; |
| 1176 | } |
| 1177 | } |
| 1178 | } |
| 1179 | |
Julien Delacou | 840a47b | 2012-12-10 14:47:33 +0100 | [diff] [blame] | 1180 | /** |
| 1181 | * pinctrl_force_sleep() - turn a given controller device into sleep state |
| 1182 | * @pctldev: pin controller device |
| 1183 | */ |
| 1184 | int pinctrl_force_sleep(struct pinctrl_dev *pctldev) |
| 1185 | { |
| 1186 | if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_sleep)) |
| 1187 | return pinctrl_select_state(pctldev->p, pctldev->hog_sleep); |
| 1188 | return 0; |
| 1189 | } |
| 1190 | EXPORT_SYMBOL_GPL(pinctrl_force_sleep); |
| 1191 | |
| 1192 | /** |
| 1193 | * pinctrl_force_default() - turn a given controller device into default state |
| 1194 | * @pctldev: pin controller device |
| 1195 | */ |
| 1196 | int pinctrl_force_default(struct pinctrl_dev *pctldev) |
| 1197 | { |
| 1198 | if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_default)) |
| 1199 | return pinctrl_select_state(pctldev->p, pctldev->hog_default); |
| 1200 | return 0; |
| 1201 | } |
| 1202 | EXPORT_SYMBOL_GPL(pinctrl_force_default); |
| 1203 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1204 | #ifdef CONFIG_DEBUG_FS |
| 1205 | |
| 1206 | static int pinctrl_pins_show(struct seq_file *s, void *what) |
| 1207 | { |
| 1208 | struct pinctrl_dev *pctldev = s->private; |
| 1209 | const struct pinctrl_ops *ops = pctldev->desc->pctlops; |
Chanho Park | 706e852 | 2012-01-03 16:47:50 +0900 | [diff] [blame] | 1210 | unsigned i, pin; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1211 | |
| 1212 | seq_printf(s, "registered pins: %d\n", pctldev->desc->npins); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1213 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1214 | mutex_lock(&pinctrl_mutex); |
| 1215 | |
Chanho Park | 706e852 | 2012-01-03 16:47:50 +0900 | [diff] [blame] | 1216 | /* The pin number can be retrived from the pin controller descriptor */ |
| 1217 | for (i = 0; i < pctldev->desc->npins; i++) { |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1218 | struct pin_desc *desc; |
| 1219 | |
Chanho Park | 706e852 | 2012-01-03 16:47:50 +0900 | [diff] [blame] | 1220 | pin = pctldev->desc->pins[i].number; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1221 | desc = pin_desc_get(pctldev, pin); |
| 1222 | /* Pin space may be sparse */ |
| 1223 | if (desc == NULL) |
| 1224 | continue; |
| 1225 | |
| 1226 | seq_printf(s, "pin %d (%s) ", pin, |
| 1227 | desc->name ? desc->name : "unnamed"); |
| 1228 | |
| 1229 | /* Driver-specific info per pin */ |
| 1230 | if (ops->pin_dbg_show) |
| 1231 | ops->pin_dbg_show(pctldev, s, pin); |
| 1232 | |
| 1233 | seq_puts(s, "\n"); |
| 1234 | } |
| 1235 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1236 | mutex_unlock(&pinctrl_mutex); |
| 1237 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1238 | return 0; |
| 1239 | } |
| 1240 | |
| 1241 | static int pinctrl_groups_show(struct seq_file *s, void *what) |
| 1242 | { |
| 1243 | struct pinctrl_dev *pctldev = s->private; |
| 1244 | const struct pinctrl_ops *ops = pctldev->desc->pctlops; |
Viresh Kumar | d1e90e9 | 2012-03-30 11:25:40 +0530 | [diff] [blame] | 1245 | unsigned ngroups, selector = 0; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1246 | |
Viresh Kumar | d1e90e9 | 2012-03-30 11:25:40 +0530 | [diff] [blame] | 1247 | ngroups = ops->get_groups_count(pctldev); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1248 | mutex_lock(&pinctrl_mutex); |
| 1249 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1250 | seq_puts(s, "registered pin groups:\n"); |
Viresh Kumar | d1e90e9 | 2012-03-30 11:25:40 +0530 | [diff] [blame] | 1251 | while (selector < ngroups) { |
Stephen Warren | a5818a8 | 2011-10-19 16:19:25 -0600 | [diff] [blame] | 1252 | const unsigned *pins; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1253 | unsigned num_pins; |
| 1254 | const char *gname = ops->get_group_name(pctldev, selector); |
Dong Aisheng | dcb5dbc | 2012-04-17 15:00:46 +0800 | [diff] [blame] | 1255 | const char *pname; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1256 | int ret; |
| 1257 | int i; |
| 1258 | |
| 1259 | ret = ops->get_group_pins(pctldev, selector, |
| 1260 | &pins, &num_pins); |
| 1261 | if (ret) |
| 1262 | seq_printf(s, "%s [ERROR GETTING PINS]\n", |
| 1263 | gname); |
| 1264 | else { |
Dong Aisheng | dcb5dbc | 2012-04-17 15:00:46 +0800 | [diff] [blame] | 1265 | seq_printf(s, "group: %s\n", gname); |
| 1266 | for (i = 0; i < num_pins; i++) { |
| 1267 | pname = pin_get_name(pctldev, pins[i]); |
Wei Yongjun | b4dd784 | 2012-10-22 12:58:09 +0800 | [diff] [blame] | 1268 | if (WARN_ON(!pname)) { |
| 1269 | mutex_unlock(&pinctrl_mutex); |
Dong Aisheng | dcb5dbc | 2012-04-17 15:00:46 +0800 | [diff] [blame] | 1270 | return -EINVAL; |
Wei Yongjun | b4dd784 | 2012-10-22 12:58:09 +0800 | [diff] [blame] | 1271 | } |
Dong Aisheng | dcb5dbc | 2012-04-17 15:00:46 +0800 | [diff] [blame] | 1272 | seq_printf(s, "pin %d (%s)\n", pins[i], pname); |
| 1273 | } |
| 1274 | seq_puts(s, "\n"); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1275 | } |
| 1276 | selector++; |
| 1277 | } |
| 1278 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1279 | mutex_unlock(&pinctrl_mutex); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1280 | |
| 1281 | return 0; |
| 1282 | } |
| 1283 | |
| 1284 | static int pinctrl_gpioranges_show(struct seq_file *s, void *what) |
| 1285 | { |
| 1286 | struct pinctrl_dev *pctldev = s->private; |
| 1287 | struct pinctrl_gpio_range *range = NULL; |
| 1288 | |
| 1289 | seq_puts(s, "GPIO ranges handled:\n"); |
| 1290 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1291 | mutex_lock(&pinctrl_mutex); |
| 1292 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1293 | /* Loop over the ranges */ |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1294 | list_for_each_entry(range, &pctldev->gpio_ranges, node) { |
Linus Walleij | 75d6642 | 2011-11-16 09:58:51 +0100 | [diff] [blame] | 1295 | seq_printf(s, "%u: %s GPIOS [%u - %u] PINS [%u - %u]\n", |
| 1296 | range->id, range->name, |
| 1297 | range->base, (range->base + range->npins - 1), |
| 1298 | range->pin_base, |
| 1299 | (range->pin_base + range->npins - 1)); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1300 | } |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1301 | |
| 1302 | mutex_unlock(&pinctrl_mutex); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1303 | |
| 1304 | return 0; |
| 1305 | } |
| 1306 | |
| 1307 | static int pinctrl_devices_show(struct seq_file *s, void *what) |
| 1308 | { |
| 1309 | struct pinctrl_dev *pctldev; |
| 1310 | |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 1311 | seq_puts(s, "name [pinmux] [pinconf]\n"); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1312 | |
| 1313 | mutex_lock(&pinctrl_mutex); |
| 1314 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1315 | list_for_each_entry(pctldev, &pinctrldev_list, node) { |
| 1316 | seq_printf(s, "%s ", pctldev->desc->name); |
| 1317 | if (pctldev->desc->pmxops) |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 1318 | seq_puts(s, "yes "); |
| 1319 | else |
| 1320 | seq_puts(s, "no "); |
| 1321 | if (pctldev->desc->confops) |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1322 | seq_puts(s, "yes"); |
| 1323 | else |
| 1324 | seq_puts(s, "no"); |
| 1325 | seq_puts(s, "\n"); |
| 1326 | } |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1327 | |
| 1328 | mutex_unlock(&pinctrl_mutex); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1329 | |
| 1330 | return 0; |
| 1331 | } |
| 1332 | |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 1333 | static inline const char *map_type(enum pinctrl_map_type type) |
| 1334 | { |
| 1335 | static const char * const names[] = { |
| 1336 | "INVALID", |
| 1337 | "DUMMY_STATE", |
| 1338 | "MUX_GROUP", |
| 1339 | "CONFIGS_PIN", |
| 1340 | "CONFIGS_GROUP", |
| 1341 | }; |
| 1342 | |
| 1343 | if (type >= ARRAY_SIZE(names)) |
| 1344 | return "UNKNOWN"; |
| 1345 | |
| 1346 | return names[type]; |
| 1347 | } |
| 1348 | |
Stephen Warren | 3eedb43 | 2012-02-23 17:04:40 -0700 | [diff] [blame] | 1349 | static int pinctrl_maps_show(struct seq_file *s, void *what) |
| 1350 | { |
| 1351 | struct pinctrl_maps *maps_node; |
| 1352 | int i; |
| 1353 | struct pinctrl_map const *map; |
| 1354 | |
| 1355 | seq_puts(s, "Pinctrl maps:\n"); |
| 1356 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1357 | mutex_lock(&pinctrl_mutex); |
| 1358 | |
Stephen Warren | 3eedb43 | 2012-02-23 17:04:40 -0700 | [diff] [blame] | 1359 | for_each_maps(maps_node, i, map) { |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 1360 | seq_printf(s, "device %s\nstate %s\ntype %s (%d)\n", |
| 1361 | map->dev_name, map->name, map_type(map->type), |
| 1362 | map->type); |
| 1363 | |
| 1364 | if (map->type != PIN_MAP_TYPE_DUMMY_STATE) |
| 1365 | seq_printf(s, "controlling device %s\n", |
| 1366 | map->ctrl_dev_name); |
| 1367 | |
| 1368 | switch (map->type) { |
| 1369 | case PIN_MAP_TYPE_MUX_GROUP: |
| 1370 | pinmux_show_map(s, map); |
| 1371 | break; |
| 1372 | case PIN_MAP_TYPE_CONFIGS_PIN: |
| 1373 | case PIN_MAP_TYPE_CONFIGS_GROUP: |
| 1374 | pinconf_show_map(s, map); |
| 1375 | break; |
| 1376 | default: |
| 1377 | break; |
| 1378 | } |
| 1379 | |
| 1380 | seq_printf(s, "\n"); |
Stephen Warren | 3eedb43 | 2012-02-23 17:04:40 -0700 | [diff] [blame] | 1381 | } |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1382 | |
| 1383 | mutex_unlock(&pinctrl_mutex); |
Stephen Warren | 3eedb43 | 2012-02-23 17:04:40 -0700 | [diff] [blame] | 1384 | |
| 1385 | return 0; |
| 1386 | } |
| 1387 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1388 | static int pinctrl_show(struct seq_file *s, void *what) |
| 1389 | { |
| 1390 | struct pinctrl *p; |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 1391 | struct pinctrl_state *state; |
Stephen Warren | 7ecdb16 | 2012-03-02 13:05:45 -0700 | [diff] [blame] | 1392 | struct pinctrl_setting *setting; |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1393 | |
| 1394 | seq_puts(s, "Requested pin control handlers their pinmux maps:\n"); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1395 | |
| 1396 | mutex_lock(&pinctrl_mutex); |
| 1397 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1398 | list_for_each_entry(p, &pinctrl_list, node) { |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 1399 | seq_printf(s, "device: %s current state: %s\n", |
| 1400 | dev_name(p->dev), |
| 1401 | p->state ? p->state->name : "none"); |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1402 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 1403 | list_for_each_entry(state, &p->states, node) { |
| 1404 | seq_printf(s, " state: %s\n", state->name); |
| 1405 | |
| 1406 | list_for_each_entry(setting, &state->settings, node) { |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 1407 | struct pinctrl_dev *pctldev = setting->pctldev; |
| 1408 | |
| 1409 | seq_printf(s, " type: %s controller %s ", |
| 1410 | map_type(setting->type), |
| 1411 | pinctrl_dev_get_name(pctldev)); |
| 1412 | |
| 1413 | switch (setting->type) { |
| 1414 | case PIN_MAP_TYPE_MUX_GROUP: |
| 1415 | pinmux_show_setting(s, setting); |
| 1416 | break; |
| 1417 | case PIN_MAP_TYPE_CONFIGS_PIN: |
| 1418 | case PIN_MAP_TYPE_CONFIGS_GROUP: |
| 1419 | pinconf_show_setting(s, setting); |
| 1420 | break; |
| 1421 | default: |
| 1422 | break; |
| 1423 | } |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 1424 | } |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1425 | } |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1426 | } |
| 1427 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1428 | mutex_unlock(&pinctrl_mutex); |
| 1429 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1430 | return 0; |
| 1431 | } |
| 1432 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1433 | static int pinctrl_pins_open(struct inode *inode, struct file *file) |
| 1434 | { |
| 1435 | return single_open(file, pinctrl_pins_show, inode->i_private); |
| 1436 | } |
| 1437 | |
| 1438 | static int pinctrl_groups_open(struct inode *inode, struct file *file) |
| 1439 | { |
| 1440 | return single_open(file, pinctrl_groups_show, inode->i_private); |
| 1441 | } |
| 1442 | |
| 1443 | static int pinctrl_gpioranges_open(struct inode *inode, struct file *file) |
| 1444 | { |
| 1445 | return single_open(file, pinctrl_gpioranges_show, inode->i_private); |
| 1446 | } |
| 1447 | |
| 1448 | static int pinctrl_devices_open(struct inode *inode, struct file *file) |
| 1449 | { |
| 1450 | return single_open(file, pinctrl_devices_show, NULL); |
| 1451 | } |
| 1452 | |
Stephen Warren | 3eedb43 | 2012-02-23 17:04:40 -0700 | [diff] [blame] | 1453 | static int pinctrl_maps_open(struct inode *inode, struct file *file) |
| 1454 | { |
| 1455 | return single_open(file, pinctrl_maps_show, NULL); |
| 1456 | } |
| 1457 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1458 | static int pinctrl_open(struct inode *inode, struct file *file) |
| 1459 | { |
| 1460 | return single_open(file, pinctrl_show, NULL); |
| 1461 | } |
| 1462 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1463 | static const struct file_operations pinctrl_pins_ops = { |
| 1464 | .open = pinctrl_pins_open, |
| 1465 | .read = seq_read, |
| 1466 | .llseek = seq_lseek, |
| 1467 | .release = single_release, |
| 1468 | }; |
| 1469 | |
| 1470 | static const struct file_operations pinctrl_groups_ops = { |
| 1471 | .open = pinctrl_groups_open, |
| 1472 | .read = seq_read, |
| 1473 | .llseek = seq_lseek, |
| 1474 | .release = single_release, |
| 1475 | }; |
| 1476 | |
| 1477 | static const struct file_operations pinctrl_gpioranges_ops = { |
| 1478 | .open = pinctrl_gpioranges_open, |
| 1479 | .read = seq_read, |
| 1480 | .llseek = seq_lseek, |
| 1481 | .release = single_release, |
| 1482 | }; |
| 1483 | |
| 1484 | static const struct file_operations pinctrl_devices_ops = { |
| 1485 | .open = pinctrl_devices_open, |
| 1486 | .read = seq_read, |
| 1487 | .llseek = seq_lseek, |
| 1488 | .release = single_release, |
| 1489 | }; |
| 1490 | |
Stephen Warren | 3eedb43 | 2012-02-23 17:04:40 -0700 | [diff] [blame] | 1491 | static const struct file_operations pinctrl_maps_ops = { |
| 1492 | .open = pinctrl_maps_open, |
| 1493 | .read = seq_read, |
| 1494 | .llseek = seq_lseek, |
| 1495 | .release = single_release, |
| 1496 | }; |
| 1497 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1498 | static const struct file_operations pinctrl_ops = { |
| 1499 | .open = pinctrl_open, |
| 1500 | .read = seq_read, |
| 1501 | .llseek = seq_lseek, |
| 1502 | .release = single_release, |
| 1503 | }; |
| 1504 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1505 | static struct dentry *debugfs_root; |
| 1506 | |
| 1507 | static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev) |
| 1508 | { |
Tony Lindgren | 0215716 | 2012-01-20 08:17:22 -0800 | [diff] [blame] | 1509 | struct dentry *device_root; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1510 | |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 1511 | device_root = debugfs_create_dir(dev_name(pctldev->dev), |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1512 | debugfs_root); |
Tony Lindgren | 0215716 | 2012-01-20 08:17:22 -0800 | [diff] [blame] | 1513 | pctldev->device_root = device_root; |
| 1514 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1515 | if (IS_ERR(device_root) || !device_root) { |
| 1516 | pr_warn("failed to create debugfs directory for %s\n", |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 1517 | dev_name(pctldev->dev)); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1518 | return; |
| 1519 | } |
| 1520 | debugfs_create_file("pins", S_IFREG | S_IRUGO, |
| 1521 | device_root, pctldev, &pinctrl_pins_ops); |
| 1522 | debugfs_create_file("pingroups", S_IFREG | S_IRUGO, |
| 1523 | device_root, pctldev, &pinctrl_groups_ops); |
| 1524 | debugfs_create_file("gpio-ranges", S_IFREG | S_IRUGO, |
| 1525 | device_root, pctldev, &pinctrl_gpioranges_ops); |
| 1526 | pinmux_init_device_debugfs(device_root, pctldev); |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 1527 | pinconf_init_device_debugfs(device_root, pctldev); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1528 | } |
| 1529 | |
Tony Lindgren | 0215716 | 2012-01-20 08:17:22 -0800 | [diff] [blame] | 1530 | static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev) |
| 1531 | { |
| 1532 | debugfs_remove_recursive(pctldev->device_root); |
| 1533 | } |
| 1534 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1535 | static void pinctrl_init_debugfs(void) |
| 1536 | { |
| 1537 | debugfs_root = debugfs_create_dir("pinctrl", NULL); |
| 1538 | if (IS_ERR(debugfs_root) || !debugfs_root) { |
| 1539 | pr_warn("failed to create debugfs directory\n"); |
| 1540 | debugfs_root = NULL; |
| 1541 | return; |
| 1542 | } |
| 1543 | |
| 1544 | debugfs_create_file("pinctrl-devices", S_IFREG | S_IRUGO, |
| 1545 | debugfs_root, NULL, &pinctrl_devices_ops); |
Stephen Warren | 3eedb43 | 2012-02-23 17:04:40 -0700 | [diff] [blame] | 1546 | debugfs_create_file("pinctrl-maps", S_IFREG | S_IRUGO, |
| 1547 | debugfs_root, NULL, &pinctrl_maps_ops); |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 1548 | debugfs_create_file("pinctrl-handles", S_IFREG | S_IRUGO, |
| 1549 | debugfs_root, NULL, &pinctrl_ops); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | #else /* CONFIG_DEBUG_FS */ |
| 1553 | |
| 1554 | static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev) |
| 1555 | { |
| 1556 | } |
| 1557 | |
| 1558 | static void pinctrl_init_debugfs(void) |
| 1559 | { |
| 1560 | } |
| 1561 | |
Tony Lindgren | 0215716 | 2012-01-20 08:17:22 -0800 | [diff] [blame] | 1562 | static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev) |
| 1563 | { |
| 1564 | } |
| 1565 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1566 | #endif |
| 1567 | |
Stephen Warren | d26bc49 | 2012-03-16 14:54:25 -0600 | [diff] [blame] | 1568 | static int pinctrl_check_ops(struct pinctrl_dev *pctldev) |
| 1569 | { |
| 1570 | const struct pinctrl_ops *ops = pctldev->desc->pctlops; |
| 1571 | |
| 1572 | if (!ops || |
Viresh Kumar | d1e90e9 | 2012-03-30 11:25:40 +0530 | [diff] [blame] | 1573 | !ops->get_groups_count || |
Stephen Warren | d26bc49 | 2012-03-16 14:54:25 -0600 | [diff] [blame] | 1574 | !ops->get_group_name || |
| 1575 | !ops->get_group_pins) |
| 1576 | return -EINVAL; |
| 1577 | |
Stephen Warren | 57291ce | 2012-03-23 10:29:46 -0600 | [diff] [blame] | 1578 | if (ops->dt_node_to_map && !ops->dt_free_map) |
| 1579 | return -EINVAL; |
| 1580 | |
Stephen Warren | d26bc49 | 2012-03-16 14:54:25 -0600 | [diff] [blame] | 1581 | return 0; |
| 1582 | } |
| 1583 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1584 | /** |
| 1585 | * pinctrl_register() - register a pin controller device |
| 1586 | * @pctldesc: descriptor for this pin controller |
| 1587 | * @dev: parent device for this pin controller |
| 1588 | * @driver_data: private pin controller data for this pin controller |
| 1589 | */ |
| 1590 | struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, |
| 1591 | struct device *dev, void *driver_data) |
| 1592 | { |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1593 | struct pinctrl_dev *pctldev; |
| 1594 | int ret; |
| 1595 | |
Devendra Naga | da9aecb | 2012-06-16 23:43:16 +0530 | [diff] [blame] | 1596 | if (!pctldesc) |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1597 | return NULL; |
Devendra Naga | da9aecb | 2012-06-16 23:43:16 +0530 | [diff] [blame] | 1598 | if (!pctldesc->name) |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1599 | return NULL; |
| 1600 | |
Stephen Warren | 02f5b98 | 2012-02-22 14:26:00 -0700 | [diff] [blame] | 1601 | pctldev = kzalloc(sizeof(*pctldev), GFP_KERNEL); |
Stephen Warren | 95dcd4a | 2012-02-22 14:25:59 -0700 | [diff] [blame] | 1602 | if (pctldev == NULL) { |
| 1603 | dev_err(dev, "failed to alloc struct pinctrl_dev\n"); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1604 | return NULL; |
Stephen Warren | 95dcd4a | 2012-02-22 14:25:59 -0700 | [diff] [blame] | 1605 | } |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1606 | |
| 1607 | /* Initialize pin control device struct */ |
| 1608 | pctldev->owner = pctldesc->owner; |
| 1609 | pctldev->desc = pctldesc; |
| 1610 | pctldev->driver_data = driver_data; |
| 1611 | INIT_RADIX_TREE(&pctldev->pin_desc_tree, GFP_KERNEL); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1612 | INIT_LIST_HEAD(&pctldev->gpio_ranges); |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 1613 | pctldev->dev = dev; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1614 | |
Stephen Warren | d26bc49 | 2012-03-16 14:54:25 -0600 | [diff] [blame] | 1615 | /* check core ops for sanity */ |
Devendra Naga | da9aecb | 2012-06-16 23:43:16 +0530 | [diff] [blame] | 1616 | if (pinctrl_check_ops(pctldev)) { |
John Crispin | ad6e110 | 2012-04-26 16:47:11 +0200 | [diff] [blame] | 1617 | dev_err(dev, "pinctrl ops lacks necessary functions\n"); |
Stephen Warren | d26bc49 | 2012-03-16 14:54:25 -0600 | [diff] [blame] | 1618 | goto out_err; |
| 1619 | } |
| 1620 | |
Tony Lindgren | b9130b7 | 2012-01-24 16:28:08 -0800 | [diff] [blame] | 1621 | /* If we're implementing pinmuxing, check the ops for sanity */ |
| 1622 | if (pctldesc->pmxops) { |
Devendra Naga | da9aecb | 2012-06-16 23:43:16 +0530 | [diff] [blame] | 1623 | if (pinmux_check_ops(pctldev)) |
Tony Lindgren | b9130b7 | 2012-01-24 16:28:08 -0800 | [diff] [blame] | 1624 | goto out_err; |
Tony Lindgren | b9130b7 | 2012-01-24 16:28:08 -0800 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | /* If we're implementing pinconfig, check the ops for sanity */ |
| 1628 | if (pctldesc->confops) { |
Devendra Naga | da9aecb | 2012-06-16 23:43:16 +0530 | [diff] [blame] | 1629 | if (pinconf_check_ops(pctldev)) |
Tony Lindgren | b9130b7 | 2012-01-24 16:28:08 -0800 | [diff] [blame] | 1630 | goto out_err; |
Tony Lindgren | b9130b7 | 2012-01-24 16:28:08 -0800 | [diff] [blame] | 1631 | } |
| 1632 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1633 | /* Register all the pins */ |
John Crispin | ad6e110 | 2012-04-26 16:47:11 +0200 | [diff] [blame] | 1634 | dev_dbg(dev, "try to register %d pins ...\n", pctldesc->npins); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1635 | ret = pinctrl_register_pins(pctldev, pctldesc->pins, pctldesc->npins); |
| 1636 | if (ret) { |
John Crispin | ad6e110 | 2012-04-26 16:47:11 +0200 | [diff] [blame] | 1637 | dev_err(dev, "error during pin registration\n"); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1638 | pinctrl_free_pindescs(pctldev, pctldesc->pins, |
| 1639 | pctldesc->npins); |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 1640 | goto out_err; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1641 | } |
| 1642 | |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1643 | mutex_lock(&pinctrl_mutex); |
| 1644 | |
Stephen Warren | 8b9c139 | 2012-02-19 23:45:42 -0700 | [diff] [blame] | 1645 | list_add_tail(&pctldev->node, &pinctrldev_list); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1646 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 1647 | pctldev->p = pinctrl_get_locked(pctldev->dev); |
| 1648 | if (!IS_ERR(pctldev->p)) { |
Julien Delacou | 840a47b | 2012-12-10 14:47:33 +0100 | [diff] [blame] | 1649 | pctldev->hog_default = |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 1650 | pinctrl_lookup_state_locked(pctldev->p, |
| 1651 | PINCTRL_STATE_DEFAULT); |
Julien Delacou | 840a47b | 2012-12-10 14:47:33 +0100 | [diff] [blame] | 1652 | if (IS_ERR(pctldev->hog_default)) { |
John Crispin | ad6e110 | 2012-04-26 16:47:11 +0200 | [diff] [blame] | 1653 | dev_dbg(dev, "failed to lookup the default state\n"); |
| 1654 | } else { |
Julien Delacou | 840a47b | 2012-12-10 14:47:33 +0100 | [diff] [blame] | 1655 | if (pinctrl_select_state_locked(pctldev->p, |
| 1656 | pctldev->hog_default)) |
John Crispin | ad6e110 | 2012-04-26 16:47:11 +0200 | [diff] [blame] | 1657 | dev_err(dev, |
| 1658 | "failed to select default state\n"); |
John Crispin | ad6e110 | 2012-04-26 16:47:11 +0200 | [diff] [blame] | 1659 | } |
Julien Delacou | 840a47b | 2012-12-10 14:47:33 +0100 | [diff] [blame] | 1660 | |
| 1661 | pctldev->hog_sleep = |
| 1662 | pinctrl_lookup_state_locked(pctldev->p, |
| 1663 | PINCTRL_STATE_SLEEP); |
| 1664 | if (IS_ERR(pctldev->hog_sleep)) |
| 1665 | dev_dbg(dev, "failed to lookup the sleep state\n"); |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 1666 | } |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1667 | |
| 1668 | mutex_unlock(&pinctrl_mutex); |
| 1669 | |
Stephen Warren | 2304b47 | 2012-02-22 14:26:01 -0700 | [diff] [blame] | 1670 | pinctrl_init_device_debugfs(pctldev); |
| 1671 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1672 | return pctldev; |
| 1673 | |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 1674 | out_err: |
| 1675 | kfree(pctldev); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1676 | return NULL; |
| 1677 | } |
| 1678 | EXPORT_SYMBOL_GPL(pinctrl_register); |
| 1679 | |
| 1680 | /** |
| 1681 | * pinctrl_unregister() - unregister pinmux |
| 1682 | * @pctldev: pin controller to unregister |
| 1683 | * |
| 1684 | * Called by pinmux drivers to unregister a pinmux. |
| 1685 | */ |
| 1686 | void pinctrl_unregister(struct pinctrl_dev *pctldev) |
| 1687 | { |
Dong Aisheng | 5d589b0 | 2012-05-23 21:22:40 +0800 | [diff] [blame] | 1688 | struct pinctrl_gpio_range *range, *n; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1689 | if (pctldev == NULL) |
| 1690 | return; |
| 1691 | |
Tony Lindgren | 0215716 | 2012-01-20 08:17:22 -0800 | [diff] [blame] | 1692 | pinctrl_remove_device_debugfs(pctldev); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1693 | |
| 1694 | mutex_lock(&pinctrl_mutex); |
| 1695 | |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 1696 | if (!IS_ERR(pctldev->p)) |
| 1697 | pinctrl_put_locked(pctldev->p, true); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1698 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1699 | /* TODO: check that no pinmuxes are still active? */ |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1700 | list_del(&pctldev->node); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1701 | /* Destroy descriptor tree */ |
| 1702 | pinctrl_free_pindescs(pctldev, pctldev->desc->pins, |
| 1703 | pctldev->desc->npins); |
Dong Aisheng | 5d589b0 | 2012-05-23 21:22:40 +0800 | [diff] [blame] | 1704 | /* remove gpio ranges map */ |
| 1705 | list_for_each_entry_safe(range, n, &pctldev->gpio_ranges, node) |
| 1706 | list_del(&range->node); |
| 1707 | |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 1708 | kfree(pctldev); |
Stephen Warren | 57b676f | 2012-03-02 13:05:44 -0700 | [diff] [blame] | 1709 | |
| 1710 | mutex_unlock(&pinctrl_mutex); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1711 | } |
| 1712 | EXPORT_SYMBOL_GPL(pinctrl_unregister); |
| 1713 | |
| 1714 | static int __init pinctrl_init(void) |
| 1715 | { |
| 1716 | pr_info("initialized pinctrl subsystem\n"); |
| 1717 | pinctrl_init_debugfs(); |
| 1718 | return 0; |
| 1719 | } |
| 1720 | |
| 1721 | /* init early since many drivers really need to initialized pinmux early */ |
| 1722 | core_initcall(pinctrl_init); |