Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Core driver for the pin muxing portions of the pin control subsystem |
| 3 | * |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +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 | * |
| 10 | * License terms: GNU General Public License (GPL) version 2 |
| 11 | */ |
| 12 | #define pr_fmt(fmt) "pinmux core: " fmt |
| 13 | |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/device.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/radix-tree.h> |
| 20 | #include <linux/err.h> |
| 21 | #include <linux/list.h> |
| 22 | #include <linux/mutex.h> |
| 23 | #include <linux/spinlock.h> |
Linus Walleij | 97607d1 | 2011-11-29 12:52:39 +0100 | [diff] [blame] | 24 | #include <linux/string.h> |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 25 | #include <linux/sysfs.h> |
| 26 | #include <linux/debugfs.h> |
| 27 | #include <linux/seq_file.h> |
| 28 | #include <linux/pinctrl/machine.h> |
| 29 | #include <linux/pinctrl/pinmux.h> |
| 30 | #include "core.h" |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 31 | #include "pinmux.h" |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * struct pinmux_group - group list item for pinmux groups |
| 35 | * @node: pinmux group list node |
Stephen Warren | d4e3198 | 2012-03-01 18:48:31 -0700 | [diff] [blame^] | 36 | * @func_selector: the function selector for the pinmux device handling |
| 37 | * this pinmux |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 38 | * @group_selector: the group selector for this group |
| 39 | */ |
| 40 | struct pinmux_group { |
| 41 | struct list_head node; |
Stephen Warren | d4e3198 | 2012-03-01 18:48:31 -0700 | [diff] [blame^] | 42 | unsigned func_selector; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 43 | unsigned group_selector; |
| 44 | }; |
| 45 | |
Stephen Warren | 03665e0 | 2012-02-19 23:45:45 -0700 | [diff] [blame] | 46 | int pinmux_check_ops(struct pinctrl_dev *pctldev) |
| 47 | { |
| 48 | const struct pinmux_ops *ops = pctldev->desc->pmxops; |
| 49 | unsigned selector = 0; |
| 50 | |
| 51 | /* Check that we implement required operations */ |
| 52 | if (!ops->list_functions || |
| 53 | !ops->get_function_name || |
| 54 | !ops->get_function_groups || |
| 55 | !ops->enable || |
| 56 | !ops->disable) |
| 57 | return -EINVAL; |
| 58 | |
| 59 | /* Check that all functions registered have names */ |
| 60 | while (ops->list_functions(pctldev, selector) >= 0) { |
| 61 | const char *fname = ops->get_function_name(pctldev, |
| 62 | selector); |
| 63 | if (!fname) { |
| 64 | pr_err("pinmux ops has no name for function%u\n", |
| 65 | selector); |
| 66 | return -EINVAL; |
| 67 | } |
| 68 | selector++; |
| 69 | } |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 74 | /** |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 75 | * pin_request() - request a single pin to be muxed in, typically for GPIO |
| 76 | * @pin: the pin number in the global pin space |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 77 | * @owner: a representation of the owner of this pin; typically the device |
| 78 | * name that controls its mux function, or the requested GPIO name |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 79 | * @gpio_range: the range matching the GPIO pin if this is a request for a |
| 80 | * single GPIO pin |
| 81 | */ |
| 82 | static int pin_request(struct pinctrl_dev *pctldev, |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 83 | int pin, const char *owner, |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 84 | struct pinctrl_gpio_range *gpio_range) |
| 85 | { |
| 86 | struct pin_desc *desc; |
| 87 | const struct pinmux_ops *ops = pctldev->desc->pmxops; |
| 88 | int status = -EINVAL; |
| 89 | |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 90 | dev_dbg(pctldev->dev, "request pin %d for %s\n", pin, owner); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 91 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 92 | desc = pin_desc_get(pctldev, pin); |
| 93 | if (desc == NULL) { |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 94 | dev_err(pctldev->dev, |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 95 | "pin is not registered so it cannot be requested\n"); |
| 96 | goto out; |
| 97 | } |
| 98 | |
| 99 | spin_lock(&desc->lock); |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 100 | if (desc->owner && strcmp(desc->owner, owner)) { |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 101 | spin_unlock(&desc->lock); |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 102 | dev_err(pctldev->dev, |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 103 | "pin already requested\n"); |
| 104 | goto out; |
| 105 | } |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 106 | desc->owner = owner; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 107 | spin_unlock(&desc->lock); |
| 108 | |
| 109 | /* Let each pin increase references to this module */ |
| 110 | if (!try_module_get(pctldev->owner)) { |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 111 | dev_err(pctldev->dev, |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 112 | "could not increase module refcount for pin %d\n", |
| 113 | pin); |
| 114 | status = -EINVAL; |
| 115 | goto out_free_pin; |
| 116 | } |
| 117 | |
| 118 | /* |
| 119 | * If there is no kind of request function for the pin we just assume |
| 120 | * we got it by default and proceed. |
| 121 | */ |
Stephen Warren | 3712a3c | 2011-10-21 12:25:53 -0600 | [diff] [blame] | 122 | if (gpio_range && ops->gpio_request_enable) |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 123 | /* This requests and enables a single GPIO pin */ |
| 124 | status = ops->gpio_request_enable(pctldev, gpio_range, pin); |
| 125 | else if (ops->request) |
| 126 | status = ops->request(pctldev, pin); |
| 127 | else |
| 128 | status = 0; |
| 129 | |
| 130 | if (status) |
Uwe Kleine-König | f9d41d7 | 2012-01-19 22:42:48 +0100 | [diff] [blame] | 131 | dev_err(pctldev->dev, "->request on device %s failed for pin %d\n", |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 132 | pctldev->desc->name, pin); |
| 133 | out_free_pin: |
| 134 | if (status) { |
| 135 | spin_lock(&desc->lock); |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 136 | desc->owner = NULL; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 137 | spin_unlock(&desc->lock); |
| 138 | } |
| 139 | out: |
| 140 | if (status) |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 141 | dev_err(pctldev->dev, "pin-%d (%s) status %d\n", |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 142 | pin, owner, status); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 143 | |
| 144 | return status; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * pin_free() - release a single muxed in pin so something else can be muxed |
| 149 | * @pctldev: pin controller device handling this pin |
| 150 | * @pin: the pin to free |
Stephen Warren | 3712a3c | 2011-10-21 12:25:53 -0600 | [diff] [blame] | 151 | * @gpio_range: the range matching the GPIO pin if this is a request for a |
| 152 | * single GPIO pin |
Linus Walleij | 336cdba0 | 2011-11-10 09:27:41 +0100 | [diff] [blame] | 153 | * |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 154 | * This function returns a pointer to the previous owner. This is used |
| 155 | * for callers that dynamically allocate an owner name so it can be freed |
Linus Walleij | 336cdba0 | 2011-11-10 09:27:41 +0100 | [diff] [blame] | 156 | * once the pin is free. This is done for GPIO request functions. |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 157 | */ |
Stephen Warren | 3712a3c | 2011-10-21 12:25:53 -0600 | [diff] [blame] | 158 | static const char *pin_free(struct pinctrl_dev *pctldev, int pin, |
| 159 | struct pinctrl_gpio_range *gpio_range) |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 160 | { |
| 161 | const struct pinmux_ops *ops = pctldev->desc->pmxops; |
| 162 | struct pin_desc *desc; |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 163 | const char *owner; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 164 | |
| 165 | desc = pin_desc_get(pctldev, pin); |
| 166 | if (desc == NULL) { |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 167 | dev_err(pctldev->dev, |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 168 | "pin is not registered so it cannot be freed\n"); |
Stephen Warren | 3712a3c | 2011-10-21 12:25:53 -0600 | [diff] [blame] | 169 | return NULL; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 170 | } |
| 171 | |
Stephen Warren | 3712a3c | 2011-10-21 12:25:53 -0600 | [diff] [blame] | 172 | /* |
| 173 | * If there is no kind of request function for the pin we just assume |
| 174 | * we got it by default and proceed. |
| 175 | */ |
| 176 | if (gpio_range && ops->gpio_disable_free) |
| 177 | ops->gpio_disable_free(pctldev, gpio_range, pin); |
| 178 | else if (ops->free) |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 179 | ops->free(pctldev, pin); |
| 180 | |
| 181 | spin_lock(&desc->lock); |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 182 | owner = desc->owner; |
| 183 | desc->owner = NULL; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 184 | spin_unlock(&desc->lock); |
| 185 | module_put(pctldev->owner); |
Stephen Warren | 3712a3c | 2011-10-21 12:25:53 -0600 | [diff] [blame] | 186 | |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 187 | return owner; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /** |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 191 | * pinmux_request_gpio() - request pinmuxing for a GPIO pin |
| 192 | * @pctldev: pin controller device affected |
| 193 | * @pin: the pin to mux in for GPIO |
| 194 | * @range: the applicable GPIO range |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 195 | */ |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 196 | int pinmux_request_gpio(struct pinctrl_dev *pctldev, |
| 197 | struct pinctrl_gpio_range *range, |
| 198 | unsigned pin, unsigned gpio) |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 199 | { |
| 200 | char gpiostr[16]; |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 201 | const char *owner; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 202 | int ret; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 203 | |
| 204 | /* Conjure some name stating what chip and pin this is taken by */ |
| 205 | snprintf(gpiostr, 15, "%s:%d", range->name, gpio); |
| 206 | |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 207 | owner = kstrdup(gpiostr, GFP_KERNEL); |
| 208 | if (!owner) |
Stephen Warren | 5d2eaf8 | 2011-10-19 16:19:28 -0600 | [diff] [blame] | 209 | return -EINVAL; |
| 210 | |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 211 | ret = pin_request(pctldev, pin, owner, range); |
Stephen Warren | 5d2eaf8 | 2011-10-19 16:19:28 -0600 | [diff] [blame] | 212 | if (ret < 0) |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 213 | kfree(owner); |
Stephen Warren | 5d2eaf8 | 2011-10-19 16:19:28 -0600 | [diff] [blame] | 214 | |
| 215 | return ret; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 216 | } |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 217 | |
| 218 | /** |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 219 | * pinmux_free_gpio() - release a pin from GPIO muxing |
| 220 | * @pctldev: the pin controller device for the pin |
| 221 | * @pin: the affected currently GPIO-muxed in pin |
| 222 | * @range: applicable GPIO range |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 223 | */ |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 224 | void pinmux_free_gpio(struct pinctrl_dev *pctldev, unsigned pin, |
| 225 | struct pinctrl_gpio_range *range) |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 226 | { |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 227 | const char *owner; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 228 | |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 229 | owner = pin_free(pctldev, pin, range); |
| 230 | kfree(owner); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 231 | } |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 232 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 233 | /** |
| 234 | * pinmux_gpio_direction() - set the direction of a single muxed-in GPIO pin |
| 235 | * @pctldev: the pin controller handling this pin |
| 236 | * @range: applicable GPIO range |
| 237 | * @pin: the affected GPIO pin in this controller |
| 238 | * @input: true if we set the pin as input, false for output |
| 239 | */ |
| 240 | int pinmux_gpio_direction(struct pinctrl_dev *pctldev, |
| 241 | struct pinctrl_gpio_range *range, |
| 242 | unsigned pin, bool input) |
Linus Walleij | 542e704 | 2011-11-14 10:06:22 +0100 | [diff] [blame] | 243 | { |
Linus Walleij | 542e704 | 2011-11-14 10:06:22 +0100 | [diff] [blame] | 244 | const struct pinmux_ops *ops; |
| 245 | int ret; |
Linus Walleij | 542e704 | 2011-11-14 10:06:22 +0100 | [diff] [blame] | 246 | |
| 247 | ops = pctldev->desc->pmxops; |
| 248 | |
Linus Walleij | 542e704 | 2011-11-14 10:06:22 +0100 | [diff] [blame] | 249 | if (ops->gpio_set_direction) |
| 250 | ret = ops->gpio_set_direction(pctldev, range, pin, input); |
| 251 | else |
| 252 | ret = 0; |
| 253 | |
| 254 | return ret; |
| 255 | } |
| 256 | |
| 257 | /** |
Tony Lindgren | de849ee | 2012-01-20 08:17:33 -0800 | [diff] [blame] | 258 | * acquire_pins() - acquire all the pins for a certain function on a pinmux |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 259 | * @pctldev: the device to take the pins on |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 260 | * @owner: a representation of the owner of this pin; typically the device |
| 261 | * name that controls its mux function |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 262 | * @group_selector: the group selector containing the pins to acquire |
| 263 | */ |
| 264 | static int acquire_pins(struct pinctrl_dev *pctldev, |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 265 | const char *owner, |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 266 | unsigned group_selector) |
| 267 | { |
| 268 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; |
Stephen Warren | a5818a8 | 2011-10-19 16:19:25 -0600 | [diff] [blame] | 269 | const unsigned *pins; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 270 | unsigned num_pins; |
| 271 | int ret; |
| 272 | int i; |
| 273 | |
| 274 | ret = pctlops->get_group_pins(pctldev, group_selector, |
| 275 | &pins, &num_pins); |
| 276 | if (ret) |
| 277 | return ret; |
| 278 | |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 279 | dev_dbg(pctldev->dev, "requesting the %u pins from group %u\n", |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 280 | num_pins, group_selector); |
| 281 | |
| 282 | /* Try to allocate all pins in this group, one by one */ |
| 283 | for (i = 0; i < num_pins; i++) { |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 284 | ret = pin_request(pctldev, pins[i], owner, NULL); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 285 | if (ret) { |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 286 | dev_err(pctldev->dev, |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 287 | "could not get request pin %d on device %s - conflicting mux mappings?\n", |
| 288 | pins[i], |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 289 | pinctrl_dev_get_name(pctldev)); |
| 290 | /* On error release all taken pins */ |
| 291 | i--; /* this pin just failed */ |
| 292 | for (; i >= 0; i--) |
Stephen Warren | 3712a3c | 2011-10-21 12:25:53 -0600 | [diff] [blame] | 293 | pin_free(pctldev, pins[i], NULL); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 294 | return -ENODEV; |
| 295 | } |
| 296 | } |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * release_pins() - release pins taken by earlier acquirement |
Tony Lindgren | de849ee | 2012-01-20 08:17:33 -0800 | [diff] [blame] | 302 | * @pctldev: the device to free the pins on |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 303 | * @group_selector: the group selector containing the pins to free |
| 304 | */ |
| 305 | static void release_pins(struct pinctrl_dev *pctldev, |
| 306 | unsigned group_selector) |
| 307 | { |
| 308 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; |
Stephen Warren | a5818a8 | 2011-10-19 16:19:25 -0600 | [diff] [blame] | 309 | const unsigned *pins; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 310 | unsigned num_pins; |
| 311 | int ret; |
| 312 | int i; |
| 313 | |
| 314 | ret = pctlops->get_group_pins(pctldev, group_selector, |
| 315 | &pins, &num_pins); |
| 316 | if (ret) { |
Uwe Kleine-König | f9d41d7 | 2012-01-19 22:42:48 +0100 | [diff] [blame] | 317 | dev_err(pctldev->dev, "could not get pins to release for group selector %d\n", |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 318 | group_selector); |
| 319 | return; |
| 320 | } |
| 321 | for (i = 0; i < num_pins; i++) |
Stephen Warren | 3712a3c | 2011-10-21 12:25:53 -0600 | [diff] [blame] | 322 | pin_free(pctldev, pins[i], NULL); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /** |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 326 | * pinmux_check_pin_group() - check function and pin group combo |
| 327 | * @pctldev: device to check the pin group vs function for |
| 328 | * @func_selector: the function selector to check the pin group for, we have |
| 329 | * already looked this up in the calling function |
| 330 | * @pin_group: the pin group to match to the function |
| 331 | * |
| 332 | * This function will check that the pinmux driver can supply the |
| 333 | * selected pin group for a certain function, returns the group selector if |
| 334 | * the group and function selector will work fine together, else returns |
| 335 | * negative |
| 336 | */ |
| 337 | static int pinmux_check_pin_group(struct pinctrl_dev *pctldev, |
| 338 | unsigned func_selector, |
| 339 | const char *pin_group) |
| 340 | { |
| 341 | const struct pinmux_ops *pmxops = pctldev->desc->pmxops; |
| 342 | const struct pinctrl_ops *pctlops = pctldev->desc->pctlops; |
| 343 | int ret; |
| 344 | |
| 345 | /* |
| 346 | * If the driver does not support different pin groups for the |
| 347 | * functions, we only support group 0, and assume this exists. |
| 348 | */ |
| 349 | if (!pctlops || !pctlops->list_groups) |
| 350 | return 0; |
| 351 | |
| 352 | /* |
| 353 | * Passing NULL (no specific group) will select the first and |
| 354 | * hopefully only group of pins available for this function. |
| 355 | */ |
| 356 | if (!pin_group) { |
| 357 | char const * const *groups; |
| 358 | unsigned num_groups; |
| 359 | |
| 360 | ret = pmxops->get_function_groups(pctldev, func_selector, |
| 361 | &groups, &num_groups); |
| 362 | if (ret) |
| 363 | return ret; |
| 364 | if (num_groups < 1) |
| 365 | return -EINVAL; |
Linus Walleij | 7afde8b | 2011-10-19 17:07:16 +0200 | [diff] [blame] | 366 | ret = pinctrl_get_group_selector(pctldev, groups[0]); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 367 | if (ret < 0) { |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 368 | dev_err(pctldev->dev, |
Uwe Kleine-König | f9d41d7 | 2012-01-19 22:42:48 +0100 | [diff] [blame] | 369 | "function %s wants group %s but the pin controller does not seem to have that group\n", |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 370 | pmxops->get_function_name(pctldev, func_selector), |
| 371 | groups[0]); |
| 372 | return ret; |
| 373 | } |
| 374 | |
| 375 | if (num_groups > 1) |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 376 | dev_dbg(pctldev->dev, |
Uwe Kleine-König | f9d41d7 | 2012-01-19 22:42:48 +0100 | [diff] [blame] | 377 | "function %s support more than one group, default-selecting first group %s (%d)\n", |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 378 | pmxops->get_function_name(pctldev, func_selector), |
| 379 | groups[0], |
| 380 | ret); |
| 381 | |
| 382 | return ret; |
| 383 | } |
| 384 | |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 385 | dev_dbg(pctldev->dev, |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 386 | "check if we have pin group %s on controller %s\n", |
| 387 | pin_group, pinctrl_dev_get_name(pctldev)); |
| 388 | |
Linus Walleij | 7afde8b | 2011-10-19 17:07:16 +0200 | [diff] [blame] | 389 | ret = pinctrl_get_group_selector(pctldev, pin_group); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 390 | if (ret < 0) { |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 391 | dev_dbg(pctldev->dev, |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 392 | "%s does not support pin group %s with function %s\n", |
| 393 | pinctrl_dev_get_name(pctldev), |
| 394 | pin_group, |
| 395 | pmxops->get_function_name(pctldev, func_selector)); |
| 396 | } |
| 397 | return ret; |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * pinmux_search_function() - check pin control driver for a certain function |
| 402 | * @pctldev: device to check for function and position |
| 403 | * @map: function map containing the function and position to look for |
| 404 | * @func_selector: returns the applicable function selector if found |
| 405 | * @group_selector: returns the applicable group selector if found |
| 406 | * |
| 407 | * This will search the pinmux driver for an applicable |
| 408 | * function with a specific pin group, returns 0 if these can be mapped |
| 409 | * negative otherwise |
| 410 | */ |
| 411 | static int pinmux_search_function(struct pinctrl_dev *pctldev, |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 412 | struct pinctrl_map const *map, |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 413 | unsigned *func_selector, |
| 414 | unsigned *group_selector) |
| 415 | { |
| 416 | const struct pinmux_ops *ops = pctldev->desc->pmxops; |
| 417 | unsigned selector = 0; |
| 418 | |
| 419 | /* See if this pctldev has this function */ |
| 420 | while (ops->list_functions(pctldev, selector) >= 0) { |
| 421 | const char *fname = ops->get_function_name(pctldev, |
| 422 | selector); |
| 423 | int ret; |
| 424 | |
| 425 | if (!strcmp(map->function, fname)) { |
| 426 | /* Found the function, check pin group */ |
| 427 | ret = pinmux_check_pin_group(pctldev, selector, |
| 428 | map->group); |
| 429 | if (ret < 0) |
| 430 | return ret; |
| 431 | |
| 432 | /* This function and group selector can be used */ |
| 433 | *func_selector = selector; |
| 434 | *group_selector = ret; |
| 435 | return 0; |
| 436 | |
| 437 | } |
| 438 | selector++; |
| 439 | } |
| 440 | |
| 441 | pr_err("%s does not support function %s\n", |
| 442 | pinctrl_dev_get_name(pctldev), map->function); |
| 443 | return -EINVAL; |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * pinmux_enable_muxmap() - enable a map entry for a certain pinmux |
| 448 | */ |
| 449 | static int pinmux_enable_muxmap(struct pinctrl_dev *pctldev, |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 450 | struct pinctrl *p, |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 451 | struct device *dev, |
| 452 | const char *devname, |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 453 | struct pinctrl_map const *map) |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 454 | { |
| 455 | unsigned func_selector; |
| 456 | unsigned group_selector; |
| 457 | struct pinmux_group *grp; |
| 458 | int ret; |
| 459 | |
| 460 | /* |
| 461 | * Note that we're not locking the pinmux mutex here, because |
| 462 | * this is only called at pinmux initialization time when it |
| 463 | * has not been added to any list and thus is not reachable |
| 464 | * by anyone else. |
| 465 | */ |
| 466 | |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 467 | if (p->pctldev && p->pctldev != pctldev) { |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 468 | dev_err(pctldev->dev, |
Uwe Kleine-König | f9d41d7 | 2012-01-19 22:42:48 +0100 | [diff] [blame] | 469 | "different pin control devices given for device %s, function %s\n", |
| 470 | devname, map->function); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 471 | return -EINVAL; |
| 472 | } |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 473 | p->dev = dev; |
| 474 | p->pctldev = pctldev; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 475 | |
| 476 | /* Now go into the driver and try to match a function and group */ |
| 477 | ret = pinmux_search_function(pctldev, map, &func_selector, |
| 478 | &group_selector); |
| 479 | if (ret < 0) |
| 480 | return ret; |
| 481 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 482 | /* Now add this group selector, we may have many of them */ |
Stephen Warren | 02f5b98 | 2012-02-22 14:26:00 -0700 | [diff] [blame] | 483 | grp = kmalloc(sizeof(*grp), GFP_KERNEL); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 484 | if (!grp) |
| 485 | return -ENOMEM; |
Stephen Warren | d4e3198 | 2012-03-01 18:48:31 -0700 | [diff] [blame^] | 486 | grp->func_selector = func_selector; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 487 | grp->group_selector = group_selector; |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 488 | ret = acquire_pins(pctldev, devname, group_selector); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 489 | if (ret) { |
| 490 | kfree(grp); |
| 491 | return ret; |
| 492 | } |
Stephen Warren | 8b9c139 | 2012-02-19 23:45:42 -0700 | [diff] [blame] | 493 | list_add_tail(&grp->node, &p->groups); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 494 | |
| 495 | return 0; |
| 496 | } |
| 497 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 498 | /** |
| 499 | * pinmux_apply_muxmap() - apply a certain mux mapping entry |
| 500 | */ |
| 501 | int pinmux_apply_muxmap(struct pinctrl_dev *pctldev, |
| 502 | struct pinctrl *p, |
| 503 | struct device *dev, |
| 504 | const char *devname, |
| 505 | struct pinctrl_map const *map) |
| 506 | { |
| 507 | int ret; |
| 508 | |
| 509 | ret = pinmux_enable_muxmap(pctldev, p, dev, |
| 510 | devname, map); |
| 511 | if (ret) { |
| 512 | pinmux_put(p); |
| 513 | return ret; |
| 514 | } |
| 515 | |
| 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | /** |
| 520 | * pinmux_put() - free up the pinmux portions of a pin controller handle |
| 521 | */ |
| 522 | void pinmux_put(struct pinctrl *p) |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 523 | { |
| 524 | struct list_head *node, *tmp; |
| 525 | |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 526 | list_for_each_safe(node, tmp, &p->groups) { |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 527 | struct pinmux_group *grp = |
| 528 | list_entry(node, struct pinmux_group, node); |
| 529 | /* Release all pins taken by this group */ |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 530 | release_pins(p->pctldev, grp->group_selector); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 531 | list_del(node); |
| 532 | kfree(grp); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | /** |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 537 | * pinmux_enable() - enable the pinmux portion of a pin control handle |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 538 | */ |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 539 | int pinmux_enable(struct pinctrl *p) |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 540 | { |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 541 | struct pinctrl_dev *pctldev = p->pctldev; |
| 542 | const struct pinmux_ops *ops = pctldev->desc->pmxops; |
| 543 | struct pinmux_group *grp; |
| 544 | int ret; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 545 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 546 | list_for_each_entry(grp, &p->groups, node) { |
Stephen Warren | d4e3198 | 2012-03-01 18:48:31 -0700 | [diff] [blame^] | 547 | ret = ops->enable(pctldev, grp->func_selector, |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 548 | grp->group_selector); |
| 549 | if (ret) |
| 550 | /* |
| 551 | * TODO: call disable() on all groups we called |
| 552 | * enable() on to this point? |
| 553 | */ |
| 554 | return ret; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 555 | } |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 556 | return 0; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 557 | } |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 558 | |
| 559 | /** |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 560 | * pinmux_disable() - disable the pinmux portions of a pin control handle |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 561 | */ |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 562 | void pinmux_disable(struct pinctrl *p) |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 563 | { |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 564 | struct pinctrl_dev *pctldev = p->pctldev; |
| 565 | const struct pinmux_ops *ops = pctldev->desc->pmxops; |
| 566 | struct pinmux_group *grp; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 567 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 568 | list_for_each_entry(grp, &p->groups, node) { |
Stephen Warren | d4e3198 | 2012-03-01 18:48:31 -0700 | [diff] [blame^] | 569 | ops->disable(pctldev, grp->func_selector, |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 570 | grp->group_selector); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 571 | } |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 572 | } |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 573 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 574 | #ifdef CONFIG_DEBUG_FS |
| 575 | |
| 576 | /* Called from pincontrol core */ |
| 577 | static int pinmux_functions_show(struct seq_file *s, void *what) |
| 578 | { |
| 579 | struct pinctrl_dev *pctldev = s->private; |
| 580 | const struct pinmux_ops *pmxops = pctldev->desc->pmxops; |
| 581 | unsigned func_selector = 0; |
| 582 | |
| 583 | while (pmxops->list_functions(pctldev, func_selector) >= 0) { |
| 584 | const char *func = pmxops->get_function_name(pctldev, |
| 585 | func_selector); |
| 586 | const char * const *groups; |
| 587 | unsigned num_groups; |
| 588 | int ret; |
| 589 | int i; |
| 590 | |
| 591 | ret = pmxops->get_function_groups(pctldev, func_selector, |
| 592 | &groups, &num_groups); |
| 593 | if (ret) |
| 594 | seq_printf(s, "function %s: COULD NOT GET GROUPS\n", |
| 595 | func); |
| 596 | |
| 597 | seq_printf(s, "function: %s, groups = [ ", func); |
| 598 | for (i = 0; i < num_groups; i++) |
| 599 | seq_printf(s, "%s ", groups[i]); |
| 600 | seq_puts(s, "]\n"); |
| 601 | |
| 602 | func_selector++; |
| 603 | |
| 604 | } |
| 605 | |
| 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | static int pinmux_pins_show(struct seq_file *s, void *what) |
| 610 | { |
| 611 | struct pinctrl_dev *pctldev = s->private; |
Chanho Park | 706e852 | 2012-01-03 16:47:50 +0900 | [diff] [blame] | 612 | unsigned i, pin; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 613 | |
| 614 | seq_puts(s, "Pinmux settings per pin\n"); |
Stephen Warren | 3cc70ed | 2012-02-19 23:45:44 -0700 | [diff] [blame] | 615 | seq_puts(s, "Format: pin (name): owner\n"); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 616 | |
Chanho Park | 706e852 | 2012-01-03 16:47:50 +0900 | [diff] [blame] | 617 | /* The pin number can be retrived from the pin controller descriptor */ |
| 618 | for (i = 0; i < pctldev->desc->npins; i++) { |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 619 | struct pin_desc *desc; |
Linus Walleij | 1cf94c4 | 2012-02-24 06:53:04 +0100 | [diff] [blame] | 620 | bool is_hog = false; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 621 | |
Chanho Park | 706e852 | 2012-01-03 16:47:50 +0900 | [diff] [blame] | 622 | pin = pctldev->desc->pins[i].number; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 623 | desc = pin_desc_get(pctldev, pin); |
Chanho Park | 706e852 | 2012-01-03 16:47:50 +0900 | [diff] [blame] | 624 | /* Skip if we cannot search the pin */ |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 625 | if (desc == NULL) |
| 626 | continue; |
| 627 | |
Linus Walleij | 1cf94c4 | 2012-02-24 06:53:04 +0100 | [diff] [blame] | 628 | if (desc->owner && |
| 629 | !strcmp(desc->owner, pinctrl_dev_get_name(pctldev))) |
| 630 | is_hog = true; |
| 631 | |
| 632 | seq_printf(s, "pin %d (%s): %s%s\n", pin, |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 633 | desc->name ? desc->name : "unnamed", |
Linus Walleij | 1cf94c4 | 2012-02-24 06:53:04 +0100 | [diff] [blame] | 634 | desc->owner ? desc->owner : "UNCLAIMED", |
| 635 | is_hog ? " (HOG)" : ""); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | return 0; |
| 639 | } |
| 640 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 641 | void pinmux_dbg_show(struct seq_file *s, struct pinctrl *p) |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 642 | { |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 643 | struct pinctrl_dev *pctldev = p->pctldev; |
| 644 | const struct pinmux_ops *pmxops; |
| 645 | const struct pinctrl_ops *pctlops; |
| 646 | struct pinmux_group *grp; |
Stephen Warren | d4e3198 | 2012-03-01 18:48:31 -0700 | [diff] [blame^] | 647 | const char *sep = ""; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 648 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 649 | pmxops = pctldev->desc->pmxops; |
| 650 | pctlops = pctldev->desc->pctlops; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 651 | |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 652 | seq_printf(s, " groups: ["); |
| 653 | list_for_each_entry(grp, &p->groups, node) { |
Stephen Warren | d4e3198 | 2012-03-01 18:48:31 -0700 | [diff] [blame^] | 654 | seq_printf(s, "%s%s (%u)=%s (%u)", |
| 655 | sep, |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 656 | pctlops->get_group_name(pctldev, |
| 657 | grp->group_selector), |
Stephen Warren | d4e3198 | 2012-03-01 18:48:31 -0700 | [diff] [blame^] | 658 | grp->group_selector, |
| 659 | pmxops->get_function_name(pctldev, |
| 660 | grp->func_selector), |
| 661 | grp->func_selector); |
| 662 | sep = ", "; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 663 | } |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame] | 664 | seq_printf(s, " ]"); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | static int pinmux_functions_open(struct inode *inode, struct file *file) |
| 668 | { |
| 669 | return single_open(file, pinmux_functions_show, inode->i_private); |
| 670 | } |
| 671 | |
| 672 | static int pinmux_pins_open(struct inode *inode, struct file *file) |
| 673 | { |
| 674 | return single_open(file, pinmux_pins_show, inode->i_private); |
| 675 | } |
| 676 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 677 | static const struct file_operations pinmux_functions_ops = { |
| 678 | .open = pinmux_functions_open, |
| 679 | .read = seq_read, |
| 680 | .llseek = seq_lseek, |
| 681 | .release = single_release, |
| 682 | }; |
| 683 | |
| 684 | static const struct file_operations pinmux_pins_ops = { |
| 685 | .open = pinmux_pins_open, |
| 686 | .read = seq_read, |
| 687 | .llseek = seq_lseek, |
| 688 | .release = single_release, |
| 689 | }; |
| 690 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 691 | void pinmux_init_device_debugfs(struct dentry *devroot, |
| 692 | struct pinctrl_dev *pctldev) |
| 693 | { |
| 694 | debugfs_create_file("pinmux-functions", S_IFREG | S_IRUGO, |
| 695 | devroot, pctldev, &pinmux_functions_ops); |
| 696 | debugfs_create_file("pinmux-pins", S_IFREG | S_IRUGO, |
| 697 | devroot, pctldev, &pinmux_pins_ops); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | #endif /* CONFIG_DEBUG_FS */ |