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