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