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