blob: 56ca42e6a6ec770e177b8564c46d445bbbf15b17 [file] [log] [blame]
Linus Walleij2744e8a2011-05-02 20:50:54 +02001/*
2 * Core driver for the pin muxing portions of the pin control subsystem
3 *
Linus Walleije93bcee2012-02-09 07:23:28 +01004 * Copyright (C) 2011-2012 ST-Ericsson SA
Linus Walleij2744e8a2011-05-02 20:50:54 +02005 * 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 Warren7ecdb162012-03-02 13:05:45 -070010 * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
11 *
Linus Walleij2744e8a2011-05-02 20:50:54 +020012 * License terms: GNU General Public License (GPL) version 2
13 */
14#define pr_fmt(fmt) "pinmux core: " fmt
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/device.h>
20#include <linux/slab.h>
21#include <linux/radix-tree.h>
22#include <linux/err.h>
23#include <linux/list.h>
Linus Walleij97607d12011-11-29 12:52:39 +010024#include <linux/string.h>
Linus Walleij2744e8a2011-05-02 20:50:54 +020025#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 Walleijbefe5bd2012-02-09 19:47:48 +010031#include "pinmux.h"
Linus Walleij2744e8a2011-05-02 20:50:54 +020032
Stephen Warren03665e02012-02-19 23:45:45 -070033int pinmux_check_ops(struct pinctrl_dev *pctldev)
34{
35 const struct pinmux_ops *ops = pctldev->desc->pmxops;
36 unsigned selector = 0;
37
38 /* Check that we implement required operations */
39 if (!ops->list_functions ||
40 !ops->get_function_name ||
41 !ops->get_function_groups ||
42 !ops->enable ||
43 !ops->disable)
44 return -EINVAL;
45
46 /* Check that all functions registered have names */
47 while (ops->list_functions(pctldev, selector) >= 0) {
48 const char *fname = ops->get_function_name(pctldev,
49 selector);
50 if (!fname) {
51 pr_err("pinmux ops has no name for function%u\n",
52 selector);
53 return -EINVAL;
54 }
55 selector++;
56 }
57
58 return 0;
59}
60
Linus Walleij2744e8a2011-05-02 20:50:54 +020061/**
Linus Walleij2744e8a2011-05-02 20:50:54 +020062 * pin_request() - request a single pin to be muxed in, typically for GPIO
63 * @pin: the pin number in the global pin space
Stephen Warren3cc70ed2012-02-19 23:45:44 -070064 * @owner: a representation of the owner of this pin; typically the device
65 * name that controls its mux function, or the requested GPIO name
Linus Walleij2744e8a2011-05-02 20:50:54 +020066 * @gpio_range: the range matching the GPIO pin if this is a request for a
67 * single GPIO pin
68 */
69static int pin_request(struct pinctrl_dev *pctldev,
Stephen Warren3cc70ed2012-02-19 23:45:44 -070070 int pin, const char *owner,
Linus Walleij2744e8a2011-05-02 20:50:54 +020071 struct pinctrl_gpio_range *gpio_range)
72{
73 struct pin_desc *desc;
74 const struct pinmux_ops *ops = pctldev->desc->pmxops;
75 int status = -EINVAL;
76
Stephen Warren3cc70ed2012-02-19 23:45:44 -070077 dev_dbg(pctldev->dev, "request pin %d for %s\n", pin, owner);
Linus Walleij2744e8a2011-05-02 20:50:54 +020078
Linus Walleij2744e8a2011-05-02 20:50:54 +020079 desc = pin_desc_get(pctldev, pin);
80 if (desc == NULL) {
Stephen Warren51cd24e2011-12-09 16:59:05 -070081 dev_err(pctldev->dev,
Linus Walleij2744e8a2011-05-02 20:50:54 +020082 "pin is not registered so it cannot be requested\n");
83 goto out;
84 }
85
Stephen Warren0e3db1732012-03-02 13:05:46 -070086 if (desc->usecount && strcmp(desc->owner, owner)) {
Stephen Warren51cd24e2011-12-09 16:59:05 -070087 dev_err(pctldev->dev,
Linus Walleij2744e8a2011-05-02 20:50:54 +020088 "pin already requested\n");
89 goto out;
90 }
Stephen Warren0e3db1732012-03-02 13:05:46 -070091
92 desc->usecount++;
93 if (desc->usecount > 1)
94 return 0;
95
Stephen Warren3cc70ed2012-02-19 23:45:44 -070096 desc->owner = owner;
Linus Walleij2744e8a2011-05-02 20:50:54 +020097
98 /* Let each pin increase references to this module */
99 if (!try_module_get(pctldev->owner)) {
Stephen Warren51cd24e2011-12-09 16:59:05 -0700100 dev_err(pctldev->dev,
Linus Walleij2744e8a2011-05-02 20:50:54 +0200101 "could not increase module refcount for pin %d\n",
102 pin);
103 status = -EINVAL;
104 goto out_free_pin;
105 }
106
107 /*
108 * If there is no kind of request function for the pin we just assume
109 * we got it by default and proceed.
110 */
Stephen Warren3712a3c2011-10-21 12:25:53 -0600111 if (gpio_range && ops->gpio_request_enable)
Linus Walleij2744e8a2011-05-02 20:50:54 +0200112 /* This requests and enables a single GPIO pin */
113 status = ops->gpio_request_enable(pctldev, gpio_range, pin);
114 else if (ops->request)
115 status = ops->request(pctldev, pin);
116 else
117 status = 0;
118
Stephen Warren0e3db1732012-03-02 13:05:46 -0700119 if (status) {
Uwe Kleine-Königf9d41d72012-01-19 22:42:48 +0100120 dev_err(pctldev->dev, "->request on device %s failed for pin %d\n",
Linus Walleij2744e8a2011-05-02 20:50:54 +0200121 pctldev->desc->name, pin);
Stephen Warren0e3db1732012-03-02 13:05:46 -0700122 module_put(pctldev->owner);
123 }
124
Linus Walleij2744e8a2011-05-02 20:50:54 +0200125out_free_pin:
Stephen Warren0e3db1732012-03-02 13:05:46 -0700126 if (status) {
127 desc->usecount--;
128 if (!desc->usecount)
129 desc->owner = NULL;
130 }
Linus Walleij2744e8a2011-05-02 20:50:54 +0200131out:
132 if (status)
Stephen Warren51cd24e2011-12-09 16:59:05 -0700133 dev_err(pctldev->dev, "pin-%d (%s) status %d\n",
Stephen Warren3cc70ed2012-02-19 23:45:44 -0700134 pin, owner, status);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200135
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 Warren3712a3c2011-10-21 12:25:53 -0600143 * @gpio_range: the range matching the GPIO pin if this is a request for a
144 * single GPIO pin
Linus Walleij336cdba02011-11-10 09:27:41 +0100145 *
Stephen Warren3cc70ed2012-02-19 23:45:44 -0700146 * 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 Walleij336cdba02011-11-10 09:27:41 +0100148 * once the pin is free. This is done for GPIO request functions.
Linus Walleij2744e8a2011-05-02 20:50:54 +0200149 */
Stephen Warren3712a3c2011-10-21 12:25:53 -0600150static const char *pin_free(struct pinctrl_dev *pctldev, int pin,
151 struct pinctrl_gpio_range *gpio_range)
Linus Walleij2744e8a2011-05-02 20:50:54 +0200152{
153 const struct pinmux_ops *ops = pctldev->desc->pmxops;
154 struct pin_desc *desc;
Stephen Warren3cc70ed2012-02-19 23:45:44 -0700155 const char *owner;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200156
157 desc = pin_desc_get(pctldev, pin);
158 if (desc == NULL) {
Stephen Warren51cd24e2011-12-09 16:59:05 -0700159 dev_err(pctldev->dev,
Linus Walleij2744e8a2011-05-02 20:50:54 +0200160 "pin is not registered so it cannot be freed\n");
Stephen Warren3712a3c2011-10-21 12:25:53 -0600161 return NULL;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200162 }
163
Stephen Warren0e3db1732012-03-02 13:05:46 -0700164 desc->usecount--;
165 if (desc->usecount)
166 return NULL;
167
Stephen Warren3712a3c2011-10-21 12:25:53 -0600168 /*
169 * If there is no kind of request function for the pin we just assume
170 * we got it by default and proceed.
171 */
172 if (gpio_range && ops->gpio_disable_free)
173 ops->gpio_disable_free(pctldev, gpio_range, pin);
174 else if (ops->free)
Linus Walleij2744e8a2011-05-02 20:50:54 +0200175 ops->free(pctldev, pin);
176
Stephen Warren3cc70ed2012-02-19 23:45:44 -0700177 owner = desc->owner;
178 desc->owner = NULL;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200179 module_put(pctldev->owner);
Stephen Warren3712a3c2011-10-21 12:25:53 -0600180
Stephen Warren3cc70ed2012-02-19 23:45:44 -0700181 return owner;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200182}
183
184/**
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100185 * pinmux_request_gpio() - request pinmuxing for a GPIO pin
186 * @pctldev: pin controller device affected
187 * @pin: the pin to mux in for GPIO
188 * @range: the applicable GPIO range
Linus Walleij2744e8a2011-05-02 20:50:54 +0200189 */
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100190int pinmux_request_gpio(struct pinctrl_dev *pctldev,
191 struct pinctrl_gpio_range *range,
192 unsigned pin, unsigned gpio)
Linus Walleij2744e8a2011-05-02 20:50:54 +0200193{
194 char gpiostr[16];
Stephen Warren3cc70ed2012-02-19 23:45:44 -0700195 const char *owner;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200196 int ret;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200197
198 /* Conjure some name stating what chip and pin this is taken by */
199 snprintf(gpiostr, 15, "%s:%d", range->name, gpio);
200
Stephen Warren3cc70ed2012-02-19 23:45:44 -0700201 owner = kstrdup(gpiostr, GFP_KERNEL);
202 if (!owner)
Stephen Warren5d2eaf82011-10-19 16:19:28 -0600203 return -EINVAL;
204
Stephen Warren3cc70ed2012-02-19 23:45:44 -0700205 ret = pin_request(pctldev, pin, owner, range);
Stephen Warren5d2eaf82011-10-19 16:19:28 -0600206 if (ret < 0)
Stephen Warren3cc70ed2012-02-19 23:45:44 -0700207 kfree(owner);
Stephen Warren5d2eaf82011-10-19 16:19:28 -0600208
209 return ret;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200210}
Linus Walleij2744e8a2011-05-02 20:50:54 +0200211
212/**
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100213 * pinmux_free_gpio() - release a pin from GPIO muxing
214 * @pctldev: the pin controller device for the pin
215 * @pin: the affected currently GPIO-muxed in pin
216 * @range: applicable GPIO range
Linus Walleij2744e8a2011-05-02 20:50:54 +0200217 */
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100218void pinmux_free_gpio(struct pinctrl_dev *pctldev, unsigned pin,
219 struct pinctrl_gpio_range *range)
Linus Walleij2744e8a2011-05-02 20:50:54 +0200220{
Stephen Warren3cc70ed2012-02-19 23:45:44 -0700221 const char *owner;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200222
Stephen Warren3cc70ed2012-02-19 23:45:44 -0700223 owner = pin_free(pctldev, pin, range);
224 kfree(owner);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200225}
Linus Walleij2744e8a2011-05-02 20:50:54 +0200226
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100227/**
228 * pinmux_gpio_direction() - set the direction of a single muxed-in GPIO pin
229 * @pctldev: the pin controller handling this pin
230 * @range: applicable GPIO range
231 * @pin: the affected GPIO pin in this controller
232 * @input: true if we set the pin as input, false for output
233 */
234int pinmux_gpio_direction(struct pinctrl_dev *pctldev,
235 struct pinctrl_gpio_range *range,
236 unsigned pin, bool input)
Linus Walleij542e7042011-11-14 10:06:22 +0100237{
Linus Walleij542e7042011-11-14 10:06:22 +0100238 const struct pinmux_ops *ops;
239 int ret;
Linus Walleij542e7042011-11-14 10:06:22 +0100240
241 ops = pctldev->desc->pmxops;
242
Linus Walleij542e7042011-11-14 10:06:22 +0100243 if (ops->gpio_set_direction)
244 ret = ops->gpio_set_direction(pctldev, range, pin, input);
245 else
246 ret = 0;
247
248 return ret;
249}
250
Stephen Warren7ecdb162012-03-02 13:05:45 -0700251static int pinmux_func_name_to_selector(struct pinctrl_dev *pctldev,
252 const char *function)
Linus Walleij2744e8a2011-05-02 20:50:54 +0200253{
254 const struct pinmux_ops *ops = pctldev->desc->pmxops;
255 unsigned selector = 0;
256
257 /* See if this pctldev has this function */
258 while (ops->list_functions(pctldev, selector) >= 0) {
259 const char *fname = ops->get_function_name(pctldev,
260 selector);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200261
Stephen Warren7ecdb162012-03-02 13:05:45 -0700262 if (!strcmp(function, fname))
263 return selector;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200264
Linus Walleij2744e8a2011-05-02 20:50:54 +0200265 selector++;
266 }
267
268 pr_err("%s does not support function %s\n",
Stephen Warren7ecdb162012-03-02 13:05:45 -0700269 pinctrl_dev_get_name(pctldev), function);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200270 return -EINVAL;
271}
272
Stephen Warren7ecdb162012-03-02 13:05:45 -0700273int pinmux_map_to_setting(struct pinctrl_map const *map,
274 struct pinctrl_setting *setting)
Linus Walleij2744e8a2011-05-02 20:50:54 +0200275{
Stephen Warren7ecdb162012-03-02 13:05:45 -0700276 struct pinctrl_dev *pctldev = setting->pctldev;
277 const struct pinmux_ops *pmxops = pctldev->desc->pmxops;
278 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
279 char const * const *groups;
280 unsigned num_groups;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200281 int ret;
Stephen Warren7ecdb162012-03-02 13:05:45 -0700282 const char *group;
283 int i;
284 const unsigned *pins;
285 unsigned num_pins;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200286
Stephen Warren7ecdb162012-03-02 13:05:45 -0700287 setting->func_selector =
288 pinmux_func_name_to_selector(pctldev, map->function);
289 if (setting->func_selector < 0)
290 return setting->func_selector;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200291
Stephen Warren7ecdb162012-03-02 13:05:45 -0700292 ret = pmxops->get_function_groups(pctldev, setting->func_selector,
293 &groups, &num_groups);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200294 if (ret < 0)
295 return ret;
Stephen Warren7ecdb162012-03-02 13:05:45 -0700296 if (!num_groups)
297 return -EINVAL;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200298
Stephen Warren7ecdb162012-03-02 13:05:45 -0700299 if (map->group) {
300 bool found = false;
301 group = map->group;
302 for (i = 0; i < num_groups; i++) {
303 if (!strcmp(group, groups[i])) {
304 found = true;
305 break;
306 }
307 }
308 if (!found)
309 return -EINVAL;
310 } else {
311 group = groups[0];
312 }
313
314 setting->group_selector =
315 pinctrl_get_group_selector(pctldev, group);
316 if (setting->group_selector < 0)
317 return setting->group_selector;
318
319 ret = pctlops->get_group_pins(pctldev, setting->group_selector,
320 &pins, &num_pins);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200321 if (ret) {
Stephen Warren7ecdb162012-03-02 13:05:45 -0700322 dev_err(pctldev->dev,
323 "could not get pins for device %s group selector %d\n",
324 pinctrl_dev_get_name(pctldev), setting->group_selector);
325 return -ENODEV;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200326 }
Stephen Warren7ecdb162012-03-02 13:05:45 -0700327
328 /* Try to allocate all pins in this group, one by one */
329 for (i = 0; i < num_pins; i++) {
330 ret = pin_request(pctldev, pins[i], map->dev_name, NULL);
331 if (ret) {
332 dev_err(pctldev->dev,
333 "could not get request pin %d on device %s\n",
334 pins[i], pinctrl_dev_get_name(pctldev));
335 /* On error release all taken pins */
336 i--; /* this pin just failed */
337 for (; i >= 0; i--)
338 pin_free(pctldev, pins[i], NULL);
339 return -ENODEV;
340 }
341 }
Linus Walleij2744e8a2011-05-02 20:50:54 +0200342
343 return 0;
344}
345
Stephen Warren7ecdb162012-03-02 13:05:45 -0700346void pinmux_free_setting(struct pinctrl_setting const *setting)
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100347{
Stephen Warren7ecdb162012-03-02 13:05:45 -0700348 struct pinctrl_dev *pctldev = setting->pctldev;
349 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
350 const unsigned *pins;
351 unsigned num_pins;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100352 int ret;
Stephen Warren7ecdb162012-03-02 13:05:45 -0700353 int i;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100354
Stephen Warren7ecdb162012-03-02 13:05:45 -0700355 ret = pctlops->get_group_pins(pctldev, setting->group_selector,
356 &pins, &num_pins);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100357 if (ret) {
Stephen Warren7ecdb162012-03-02 13:05:45 -0700358 dev_err(pctldev->dev,
359 "could not get pins for device %s group selector %d\n",
360 pinctrl_dev_get_name(pctldev), setting->group_selector);
361 return;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100362 }
363
Stephen Warren7ecdb162012-03-02 13:05:45 -0700364 for (i = 0; i < num_pins; i++)
365 pin_free(pctldev, pins[i], NULL);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100366}
367
Stephen Warren7ecdb162012-03-02 13:05:45 -0700368int pinmux_enable_setting(struct pinctrl_setting const *setting)
Linus Walleij2744e8a2011-05-02 20:50:54 +0200369{
Stephen Warren7ecdb162012-03-02 13:05:45 -0700370 struct pinctrl_dev *pctldev = setting->pctldev;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100371 const struct pinmux_ops *ops = pctldev->desc->pmxops;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200372
Stephen Warren7ecdb162012-03-02 13:05:45 -0700373 return ops->enable(pctldev, setting->func_selector,
374 setting->group_selector);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200375}
Linus Walleij2744e8a2011-05-02 20:50:54 +0200376
Stephen Warren7ecdb162012-03-02 13:05:45 -0700377void pinmux_disable_setting(struct pinctrl_setting const *setting)
Linus Walleij2744e8a2011-05-02 20:50:54 +0200378{
Stephen Warren7ecdb162012-03-02 13:05:45 -0700379 struct pinctrl_dev *pctldev = setting->pctldev;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100380 const struct pinmux_ops *ops = pctldev->desc->pmxops;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200381
Stephen Warren7ecdb162012-03-02 13:05:45 -0700382 ops->disable(pctldev, setting->func_selector, setting->group_selector);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200383}
Linus Walleij2744e8a2011-05-02 20:50:54 +0200384
Linus Walleij2744e8a2011-05-02 20:50:54 +0200385#ifdef CONFIG_DEBUG_FS
386
387/* Called from pincontrol core */
388static int pinmux_functions_show(struct seq_file *s, void *what)
389{
390 struct pinctrl_dev *pctldev = s->private;
391 const struct pinmux_ops *pmxops = pctldev->desc->pmxops;
392 unsigned func_selector = 0;
393
Stephen Warren57b676f2012-03-02 13:05:44 -0700394 mutex_lock(&pinctrl_mutex);
395
Linus Walleij2744e8a2011-05-02 20:50:54 +0200396 while (pmxops->list_functions(pctldev, func_selector) >= 0) {
397 const char *func = pmxops->get_function_name(pctldev,
398 func_selector);
399 const char * const *groups;
400 unsigned num_groups;
401 int ret;
402 int i;
403
404 ret = pmxops->get_function_groups(pctldev, func_selector,
405 &groups, &num_groups);
406 if (ret)
407 seq_printf(s, "function %s: COULD NOT GET GROUPS\n",
408 func);
409
410 seq_printf(s, "function: %s, groups = [ ", func);
411 for (i = 0; i < num_groups; i++)
412 seq_printf(s, "%s ", groups[i]);
413 seq_puts(s, "]\n");
414
415 func_selector++;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200416 }
417
Stephen Warren57b676f2012-03-02 13:05:44 -0700418 mutex_unlock(&pinctrl_mutex);
419
Linus Walleij2744e8a2011-05-02 20:50:54 +0200420 return 0;
421}
422
423static int pinmux_pins_show(struct seq_file *s, void *what)
424{
425 struct pinctrl_dev *pctldev = s->private;
Chanho Park706e8522012-01-03 16:47:50 +0900426 unsigned i, pin;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200427
428 seq_puts(s, "Pinmux settings per pin\n");
Stephen Warren3cc70ed2012-02-19 23:45:44 -0700429 seq_puts(s, "Format: pin (name): owner\n");
Linus Walleij2744e8a2011-05-02 20:50:54 +0200430
Stephen Warren57b676f2012-03-02 13:05:44 -0700431 mutex_lock(&pinctrl_mutex);
432
Chanho Park706e8522012-01-03 16:47:50 +0900433 /* The pin number can be retrived from the pin controller descriptor */
434 for (i = 0; i < pctldev->desc->npins; i++) {
Linus Walleij2744e8a2011-05-02 20:50:54 +0200435 struct pin_desc *desc;
Linus Walleij1cf94c42012-02-24 06:53:04 +0100436 bool is_hog = false;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200437
Chanho Park706e8522012-01-03 16:47:50 +0900438 pin = pctldev->desc->pins[i].number;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200439 desc = pin_desc_get(pctldev, pin);
Chanho Park706e8522012-01-03 16:47:50 +0900440 /* Skip if we cannot search the pin */
Linus Walleij2744e8a2011-05-02 20:50:54 +0200441 if (desc == NULL)
442 continue;
443
Linus Walleij1cf94c42012-02-24 06:53:04 +0100444 if (desc->owner &&
445 !strcmp(desc->owner, pinctrl_dev_get_name(pctldev)))
446 is_hog = true;
447
448 seq_printf(s, "pin %d (%s): %s%s\n", pin,
Linus Walleij2744e8a2011-05-02 20:50:54 +0200449 desc->name ? desc->name : "unnamed",
Linus Walleij1cf94c42012-02-24 06:53:04 +0100450 desc->owner ? desc->owner : "UNCLAIMED",
451 is_hog ? " (HOG)" : "");
Linus Walleij2744e8a2011-05-02 20:50:54 +0200452 }
453
Stephen Warren57b676f2012-03-02 13:05:44 -0700454 mutex_unlock(&pinctrl_mutex);
455
Linus Walleij2744e8a2011-05-02 20:50:54 +0200456 return 0;
457}
458
Stephen Warren7ecdb162012-03-02 13:05:45 -0700459void pinmux_dbg_show(struct seq_file *s, struct pinctrl_setting const *setting)
Linus Walleij2744e8a2011-05-02 20:50:54 +0200460{
Stephen Warren7ecdb162012-03-02 13:05:45 -0700461 struct pinctrl_dev *pctldev = setting->pctldev;
462 const struct pinmux_ops *pmxops = pctldev->desc->pmxops;
463 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200464
Stephen Warren7ecdb162012-03-02 13:05:45 -0700465 seq_printf(s, "controller: %s group: %s (%u) function: %s (%u)\n",
466 pinctrl_dev_get_name(pctldev),
467 pctlops->get_group_name(pctldev, setting->group_selector),
468 setting->group_selector,
469 pmxops->get_function_name(pctldev, setting->func_selector),
470 setting->func_selector);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200471}
472
473static int pinmux_functions_open(struct inode *inode, struct file *file)
474{
475 return single_open(file, pinmux_functions_show, inode->i_private);
476}
477
478static int pinmux_pins_open(struct inode *inode, struct file *file)
479{
480 return single_open(file, pinmux_pins_show, inode->i_private);
481}
482
Linus Walleij2744e8a2011-05-02 20:50:54 +0200483static const struct file_operations pinmux_functions_ops = {
484 .open = pinmux_functions_open,
485 .read = seq_read,
486 .llseek = seq_lseek,
487 .release = single_release,
488};
489
490static const struct file_operations pinmux_pins_ops = {
491 .open = pinmux_pins_open,
492 .read = seq_read,
493 .llseek = seq_lseek,
494 .release = single_release,
495};
496
Linus Walleij2744e8a2011-05-02 20:50:54 +0200497void pinmux_init_device_debugfs(struct dentry *devroot,
498 struct pinctrl_dev *pctldev)
499{
500 debugfs_create_file("pinmux-functions", S_IFREG | S_IRUGO,
501 devroot, pctldev, &pinmux_functions_ops);
502 debugfs_create_file("pinmux-pins", S_IFREG | S_IRUGO,
503 devroot, pctldev, &pinmux_pins_ops);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200504}
505
506#endif /* CONFIG_DEBUG_FS */