blob: 138e72f74377a2c5d034b22f9ebf32f9a83d7d34 [file] [log] [blame]
Linus Walleij2744e8a2011-05-02 20:50:54 +02001/*
2 * Core driver for the pin control subsystem
3 *
Linus Walleijbefe5bd2012-02-09 19:47:48 +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 Warrenb2b3e662012-02-19 23:45:43 -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) "pinctrl core: " fmt
15
16#include <linux/kernel.h>
Stephen Rothwella5a697c2011-09-30 14:39:04 +100017#include <linux/export.h>
Linus Walleij2744e8a2011-05-02 20:50:54 +020018#include <linux/init.h>
19#include <linux/device.h>
20#include <linux/slab.h>
Linus Walleij2744e8a2011-05-02 20:50:54 +020021#include <linux/err.h>
22#include <linux/list.h>
Linus Walleij2744e8a2011-05-02 20:50:54 +020023#include <linux/sysfs.h>
24#include <linux/debugfs.h>
25#include <linux/seq_file.h>
Stephen Warren6d4ca1f2012-04-16 10:51:00 -060026#include <linux/pinctrl/consumer.h>
Linus Walleij2744e8a2011-05-02 20:50:54 +020027#include <linux/pinctrl/pinctrl.h>
28#include <linux/pinctrl/machine.h>
29#include "core.h"
Stephen Warren57291ce2012-03-23 10:29:46 -060030#include "devicetree.h"
Linus Walleij2744e8a2011-05-02 20:50:54 +020031#include "pinmux.h"
Linus Walleijae6b4d82011-10-19 18:14:33 +020032#include "pinconf.h"
Linus Walleij2744e8a2011-05-02 20:50:54 +020033
Linus Walleijbefe5bd2012-02-09 19:47:48 +010034/**
Stephen Warrenb2b3e662012-02-19 23:45:43 -070035 * struct pinctrl_maps - a list item containing part of the mapping table
36 * @node: mapping table list node
37 * @maps: array of mapping table entries
38 * @num_maps: the number of entries in @maps
39 */
40struct pinctrl_maps {
41 struct list_head node;
42 struct pinctrl_map const *maps;
43 unsigned num_maps;
44};
45
Stephen Warren57b676f2012-03-02 13:05:44 -070046/* Mutex taken by all entry points */
47DEFINE_MUTEX(pinctrl_mutex);
48
49/* Global list of pin control devices (struct pinctrl_dev) */
Stephen Warren57291ce2012-03-23 10:29:46 -060050LIST_HEAD(pinctrldev_list);
Linus Walleij2744e8a2011-05-02 20:50:54 +020051
Stephen Warren57b676f2012-03-02 13:05:44 -070052/* List of pin controller handles (struct pinctrl) */
Linus Walleijbefe5bd2012-02-09 19:47:48 +010053static LIST_HEAD(pinctrl_list);
54
Stephen Warren57b676f2012-03-02 13:05:44 -070055/* List of pinctrl maps (struct pinctrl_maps) */
Stephen Warrenb2b3e662012-02-19 23:45:43 -070056static LIST_HEAD(pinctrl_maps);
57
58#define for_each_maps(_maps_node_, _i_, _map_) \
59 list_for_each_entry(_maps_node_, &pinctrl_maps, node) \
60 for (_i_ = 0, _map_ = &_maps_node_->maps[_i_]; \
61 _i_ < _maps_node_->num_maps; \
62 i++, _map_ = &_maps_node_->maps[_i_])
Linus Walleijbefe5bd2012-02-09 19:47:48 +010063
Linus Walleij2744e8a2011-05-02 20:50:54 +020064const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev)
65{
66 /* We're not allowed to register devices without name */
67 return pctldev->desc->name;
68}
69EXPORT_SYMBOL_GPL(pinctrl_dev_get_name);
70
71void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev)
72{
73 return pctldev->driver_data;
74}
75EXPORT_SYMBOL_GPL(pinctrl_dev_get_drvdata);
76
77/**
Linus Walleij9dfac4f2012-02-01 18:02:47 +010078 * get_pinctrl_dev_from_devname() - look up pin controller device
79 * @devname: the name of a device instance, as returned by dev_name()
Linus Walleij2744e8a2011-05-02 20:50:54 +020080 *
81 * Looks up a pin control device matching a certain device name or pure device
82 * pointer, the pure device pointer will take precedence.
83 */
Linus Walleij9dfac4f2012-02-01 18:02:47 +010084struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *devname)
Linus Walleij2744e8a2011-05-02 20:50:54 +020085{
86 struct pinctrl_dev *pctldev = NULL;
87 bool found = false;
88
Linus Walleij9dfac4f2012-02-01 18:02:47 +010089 if (!devname)
90 return NULL;
91
Linus Walleij2744e8a2011-05-02 20:50:54 +020092 list_for_each_entry(pctldev, &pinctrldev_list, node) {
Linus Walleij9dfac4f2012-02-01 18:02:47 +010093 if (!strcmp(dev_name(pctldev->dev), devname)) {
Linus Walleij2744e8a2011-05-02 20:50:54 +020094 /* Matched on device name */
95 found = true;
96 break;
97 }
98 }
Linus Walleij2744e8a2011-05-02 20:50:54 +020099
100 return found ? pctldev : NULL;
101}
102
Linus Walleij2744e8a2011-05-02 20:50:54 +0200103/**
Linus Walleijae6b4d82011-10-19 18:14:33 +0200104 * pin_get_from_name() - look up a pin number from a name
105 * @pctldev: the pin control device to lookup the pin on
106 * @name: the name of the pin to look up
107 */
108int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name)
109{
Chanho Park706e8522012-01-03 16:47:50 +0900110 unsigned i, pin;
Linus Walleijae6b4d82011-10-19 18:14:33 +0200111
Chanho Park706e8522012-01-03 16:47:50 +0900112 /* The pin number can be retrived from the pin controller descriptor */
113 for (i = 0; i < pctldev->desc->npins; i++) {
Linus Walleijae6b4d82011-10-19 18:14:33 +0200114 struct pin_desc *desc;
115
Chanho Park706e8522012-01-03 16:47:50 +0900116 pin = pctldev->desc->pins[i].number;
Linus Walleijae6b4d82011-10-19 18:14:33 +0200117 desc = pin_desc_get(pctldev, pin);
118 /* Pin space may be sparse */
119 if (desc == NULL)
120 continue;
121 if (desc->name && !strcmp(name, desc->name))
122 return pin;
123 }
124
125 return -EINVAL;
126}
127
128/**
Dong Aishengdcb5dbc2012-04-17 15:00:46 +0800129 * pin_get_name_from_id() - look up a pin name from a pin id
130 * @pctldev: the pin control device to lookup the pin on
131 * @name: the name of the pin to look up
132 */
133const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin)
134{
135 const struct pin_desc *desc;
136
137 desc = pin_desc_get(pctldev, pin);
138 if (desc == NULL) {
139 dev_err(pctldev->dev, "failed to get pin(%d) name\n",
140 pin);
141 return NULL;
142 }
143
144 return desc->name;
145}
146
147/**
Linus Walleij2744e8a2011-05-02 20:50:54 +0200148 * pin_is_valid() - check if pin exists on controller
149 * @pctldev: the pin control device to check the pin on
150 * @pin: pin to check, use the local pin controller index number
151 *
152 * This tells us whether a certain pin exist on a certain pin controller or
153 * not. Pin lists may be sparse, so some pins may not exist.
154 */
155bool pin_is_valid(struct pinctrl_dev *pctldev, int pin)
156{
157 struct pin_desc *pindesc;
158
159 if (pin < 0)
160 return false;
161
Stephen Warren57b676f2012-03-02 13:05:44 -0700162 mutex_lock(&pinctrl_mutex);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200163 pindesc = pin_desc_get(pctldev, pin);
Stephen Warren57b676f2012-03-02 13:05:44 -0700164 mutex_unlock(&pinctrl_mutex);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200165
Stephen Warren57b676f2012-03-02 13:05:44 -0700166 return pindesc != NULL;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200167}
168EXPORT_SYMBOL_GPL(pin_is_valid);
169
170/* Deletes a range of pin descriptors */
171static void pinctrl_free_pindescs(struct pinctrl_dev *pctldev,
172 const struct pinctrl_pin_desc *pins,
173 unsigned num_pins)
174{
175 int i;
176
Linus Walleij2744e8a2011-05-02 20:50:54 +0200177 for (i = 0; i < num_pins; i++) {
178 struct pin_desc *pindesc;
179
180 pindesc = radix_tree_lookup(&pctldev->pin_desc_tree,
181 pins[i].number);
182 if (pindesc != NULL) {
183 radix_tree_delete(&pctldev->pin_desc_tree,
184 pins[i].number);
Linus Walleijca53c5f2011-12-14 20:33:37 +0100185 if (pindesc->dynamic_name)
186 kfree(pindesc->name);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200187 }
188 kfree(pindesc);
189 }
Linus Walleij2744e8a2011-05-02 20:50:54 +0200190}
191
192static int pinctrl_register_one_pin(struct pinctrl_dev *pctldev,
193 unsigned number, const char *name)
194{
195 struct pin_desc *pindesc;
196
197 pindesc = pin_desc_get(pctldev, number);
198 if (pindesc != NULL) {
199 pr_err("pin %d already registered on %s\n", number,
200 pctldev->desc->name);
201 return -EINVAL;
202 }
203
204 pindesc = kzalloc(sizeof(*pindesc), GFP_KERNEL);
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700205 if (pindesc == NULL) {
206 dev_err(pctldev->dev, "failed to alloc struct pin_desc\n");
Linus Walleij2744e8a2011-05-02 20:50:54 +0200207 return -ENOMEM;
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700208 }
Linus Walleijae6b4d82011-10-19 18:14:33 +0200209
Linus Walleij2744e8a2011-05-02 20:50:54 +0200210 /* Set owner */
211 pindesc->pctldev = pctldev;
212
Stephen Warren9af1e442011-10-19 16:19:27 -0600213 /* Copy basic pin info */
Linus Walleij8dc6ae42012-02-01 18:11:40 +0100214 if (name) {
Linus Walleijca53c5f2011-12-14 20:33:37 +0100215 pindesc->name = name;
216 } else {
217 pindesc->name = kasprintf(GFP_KERNEL, "PIN%u", number);
218 if (pindesc->name == NULL)
219 return -ENOMEM;
220 pindesc->dynamic_name = true;
221 }
Linus Walleij2744e8a2011-05-02 20:50:54 +0200222
Linus Walleij2744e8a2011-05-02 20:50:54 +0200223 radix_tree_insert(&pctldev->pin_desc_tree, number, pindesc);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200224 pr_debug("registered pin %d (%s) on %s\n",
Linus Walleijca53c5f2011-12-14 20:33:37 +0100225 number, pindesc->name, pctldev->desc->name);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200226 return 0;
227}
228
229static int pinctrl_register_pins(struct pinctrl_dev *pctldev,
230 struct pinctrl_pin_desc const *pins,
231 unsigned num_descs)
232{
233 unsigned i;
234 int ret = 0;
235
236 for (i = 0; i < num_descs; i++) {
237 ret = pinctrl_register_one_pin(pctldev,
238 pins[i].number, pins[i].name);
239 if (ret)
240 return ret;
241 }
242
243 return 0;
244}
245
246/**
247 * pinctrl_match_gpio_range() - check if a certain GPIO pin is in range
248 * @pctldev: pin controller device to check
249 * @gpio: gpio pin to check taken from the global GPIO pin space
250 *
251 * Tries to match a GPIO pin number to the ranges handled by a certain pin
252 * controller, return the range or NULL
253 */
254static struct pinctrl_gpio_range *
255pinctrl_match_gpio_range(struct pinctrl_dev *pctldev, unsigned gpio)
256{
257 struct pinctrl_gpio_range *range = NULL;
258
259 /* Loop over the ranges */
Linus Walleij2744e8a2011-05-02 20:50:54 +0200260 list_for_each_entry(range, &pctldev->gpio_ranges, node) {
261 /* Check if we're in the valid range */
262 if (gpio >= range->base &&
263 gpio < range->base + range->npins) {
Linus Walleij2744e8a2011-05-02 20:50:54 +0200264 return range;
265 }
266 }
Linus Walleij2744e8a2011-05-02 20:50:54 +0200267
268 return NULL;
269}
270
271/**
272 * pinctrl_get_device_gpio_range() - find device for GPIO range
273 * @gpio: the pin to locate the pin controller for
274 * @outdev: the pin control device if found
275 * @outrange: the GPIO range if found
276 *
277 * Find the pin controller handling a certain GPIO pin from the pinspace of
278 * the GPIO subsystem, return the device and the matching GPIO range. Returns
279 * negative if the GPIO range could not be found in any device.
280 */
Stephen Warren4ecce45d2012-02-19 23:45:47 -0700281static int pinctrl_get_device_gpio_range(unsigned gpio,
282 struct pinctrl_dev **outdev,
283 struct pinctrl_gpio_range **outrange)
Linus Walleij2744e8a2011-05-02 20:50:54 +0200284{
285 struct pinctrl_dev *pctldev = NULL;
286
287 /* Loop over the pin controllers */
Linus Walleij2744e8a2011-05-02 20:50:54 +0200288 list_for_each_entry(pctldev, &pinctrldev_list, node) {
289 struct pinctrl_gpio_range *range;
290
291 range = pinctrl_match_gpio_range(pctldev, gpio);
292 if (range != NULL) {
293 *outdev = pctldev;
294 *outrange = range;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200295 return 0;
296 }
297 }
Linus Walleij2744e8a2011-05-02 20:50:54 +0200298
299 return -EINVAL;
300}
301
302/**
303 * pinctrl_add_gpio_range() - register a GPIO range for a controller
304 * @pctldev: pin controller device to add the range to
305 * @range: the GPIO range to add
306 *
307 * This adds a range of GPIOs to be handled by a certain pin controller. Call
308 * this to register handled ranges after registering your pin controller.
309 */
310void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,
311 struct pinctrl_gpio_range *range)
312{
Stephen Warren57b676f2012-03-02 13:05:44 -0700313 mutex_lock(&pinctrl_mutex);
Stephen Warren8b9c1392012-02-19 23:45:42 -0700314 list_add_tail(&range->node, &pctldev->gpio_ranges);
Stephen Warren57b676f2012-03-02 13:05:44 -0700315 mutex_unlock(&pinctrl_mutex);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200316}
Stephen Warren4ecce45d2012-02-19 23:45:47 -0700317EXPORT_SYMBOL_GPL(pinctrl_add_gpio_range);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200318
319/**
320 * pinctrl_remove_gpio_range() - remove a range of GPIOs fro a pin controller
321 * @pctldev: pin controller device to remove the range from
322 * @range: the GPIO range to remove
323 */
324void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev,
325 struct pinctrl_gpio_range *range)
326{
Stephen Warren57b676f2012-03-02 13:05:44 -0700327 mutex_lock(&pinctrl_mutex);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200328 list_del(&range->node);
Stephen Warren57b676f2012-03-02 13:05:44 -0700329 mutex_unlock(&pinctrl_mutex);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200330}
Stephen Warren4ecce45d2012-02-19 23:45:47 -0700331EXPORT_SYMBOL_GPL(pinctrl_remove_gpio_range);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200332
Linus Walleij7afde8b2011-10-19 17:07:16 +0200333/**
334 * pinctrl_get_group_selector() - returns the group selector for a group
335 * @pctldev: the pin controller handling the group
336 * @pin_group: the pin group to look up
337 */
338int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
339 const char *pin_group)
340{
341 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
Viresh Kumard1e90e92012-03-30 11:25:40 +0530342 unsigned ngroups = pctlops->get_groups_count(pctldev);
Linus Walleij7afde8b2011-10-19 17:07:16 +0200343 unsigned group_selector = 0;
344
Viresh Kumard1e90e92012-03-30 11:25:40 +0530345 while (group_selector < ngroups) {
Linus Walleij7afde8b2011-10-19 17:07:16 +0200346 const char *gname = pctlops->get_group_name(pctldev,
347 group_selector);
348 if (!strcmp(gname, pin_group)) {
Stephen Warren51cd24e2011-12-09 16:59:05 -0700349 dev_dbg(pctldev->dev,
Linus Walleij7afde8b2011-10-19 17:07:16 +0200350 "found group selector %u for %s\n",
351 group_selector,
352 pin_group);
353 return group_selector;
354 }
355
356 group_selector++;
357 }
358
Stephen Warren51cd24e2011-12-09 16:59:05 -0700359 dev_err(pctldev->dev, "does not have pin group %s\n",
Linus Walleij7afde8b2011-10-19 17:07:16 +0200360 pin_group);
361
362 return -EINVAL;
363}
364
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100365/**
366 * pinctrl_request_gpio() - request a single pin to be used in as GPIO
367 * @gpio: the GPIO pin number from the GPIO subsystem number space
368 *
369 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
370 * as part of their gpio_request() semantics, platforms and individual drivers
371 * shall *NOT* request GPIO pins to be muxed in.
372 */
373int pinctrl_request_gpio(unsigned gpio)
374{
375 struct pinctrl_dev *pctldev;
376 struct pinctrl_gpio_range *range;
377 int ret;
378 int pin;
379
Stephen Warren57b676f2012-03-02 13:05:44 -0700380 mutex_lock(&pinctrl_mutex);
381
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100382 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
Stephen Warren57b676f2012-03-02 13:05:44 -0700383 if (ret) {
384 mutex_unlock(&pinctrl_mutex);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100385 return -EINVAL;
Stephen Warren57b676f2012-03-02 13:05:44 -0700386 }
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100387
388 /* Convert to the pin controllers number space */
389 pin = gpio - range->base + range->pin_base;
390
Stephen Warren57b676f2012-03-02 13:05:44 -0700391 ret = pinmux_request_gpio(pctldev, range, pin, gpio);
392
393 mutex_unlock(&pinctrl_mutex);
394 return ret;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100395}
396EXPORT_SYMBOL_GPL(pinctrl_request_gpio);
397
398/**
399 * pinctrl_free_gpio() - free control on a single pin, currently used as GPIO
400 * @gpio: the GPIO pin number from the GPIO subsystem number space
401 *
402 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
403 * as part of their gpio_free() semantics, platforms and individual drivers
404 * shall *NOT* request GPIO pins to be muxed out.
405 */
406void pinctrl_free_gpio(unsigned gpio)
407{
408 struct pinctrl_dev *pctldev;
409 struct pinctrl_gpio_range *range;
410 int ret;
411 int pin;
412
Stephen Warren57b676f2012-03-02 13:05:44 -0700413 mutex_lock(&pinctrl_mutex);
414
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100415 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
Stephen Warren57b676f2012-03-02 13:05:44 -0700416 if (ret) {
417 mutex_unlock(&pinctrl_mutex);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100418 return;
Stephen Warren57b676f2012-03-02 13:05:44 -0700419 }
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100420
421 /* Convert to the pin controllers number space */
422 pin = gpio - range->base + range->pin_base;
423
Stephen Warren57b676f2012-03-02 13:05:44 -0700424 pinmux_free_gpio(pctldev, pin, range);
425
426 mutex_unlock(&pinctrl_mutex);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100427}
428EXPORT_SYMBOL_GPL(pinctrl_free_gpio);
429
430static int pinctrl_gpio_direction(unsigned gpio, bool input)
431{
432 struct pinctrl_dev *pctldev;
433 struct pinctrl_gpio_range *range;
434 int ret;
435 int pin;
436
437 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
438 if (ret)
439 return ret;
440
441 /* Convert to the pin controllers number space */
442 pin = gpio - range->base + range->pin_base;
443
444 return pinmux_gpio_direction(pctldev, range, pin, input);
445}
446
447/**
448 * pinctrl_gpio_direction_input() - request a GPIO pin to go into input mode
449 * @gpio: the GPIO pin number from the GPIO subsystem number space
450 *
451 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
452 * as part of their gpio_direction_input() semantics, platforms and individual
453 * drivers shall *NOT* touch pin control GPIO calls.
454 */
455int pinctrl_gpio_direction_input(unsigned gpio)
456{
Stephen Warren57b676f2012-03-02 13:05:44 -0700457 int ret;
458 mutex_lock(&pinctrl_mutex);
459 ret = pinctrl_gpio_direction(gpio, true);
460 mutex_unlock(&pinctrl_mutex);
461 return ret;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100462}
463EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input);
464
465/**
466 * pinctrl_gpio_direction_output() - request a GPIO pin to go into output mode
467 * @gpio: the GPIO pin number from the GPIO subsystem number space
468 *
469 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
470 * as part of their gpio_direction_output() semantics, platforms and individual
471 * drivers shall *NOT* touch pin control GPIO calls.
472 */
473int pinctrl_gpio_direction_output(unsigned gpio)
474{
Stephen Warren57b676f2012-03-02 13:05:44 -0700475 int ret;
476 mutex_lock(&pinctrl_mutex);
477 ret = pinctrl_gpio_direction(gpio, false);
478 mutex_unlock(&pinctrl_mutex);
479 return ret;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100480}
481EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);
482
Stephen Warren6e5e9592012-03-02 13:05:47 -0700483static struct pinctrl_state *find_state(struct pinctrl *p,
484 const char *name)
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100485{
Stephen Warren6e5e9592012-03-02 13:05:47 -0700486 struct pinctrl_state *state;
487
488 list_for_each_entry(state, &p->states, node)
489 if (!strcmp(state->name, name))
490 return state;
491
492 return NULL;
493}
494
495static struct pinctrl_state *create_state(struct pinctrl *p,
496 const char *name)
497{
498 struct pinctrl_state *state;
499
500 state = kzalloc(sizeof(*state), GFP_KERNEL);
501 if (state == NULL) {
502 dev_err(p->dev,
503 "failed to alloc struct pinctrl_state\n");
504 return ERR_PTR(-ENOMEM);
505 }
506
507 state->name = name;
508 INIT_LIST_HEAD(&state->settings);
509
510 list_add_tail(&state->node, &p->states);
511
512 return state;
513}
514
515static int add_setting(struct pinctrl *p, struct pinctrl_map const *map)
516{
517 struct pinctrl_state *state;
518 struct pinctrl_setting *setting;
Stephen Warren7ecdb162012-03-02 13:05:45 -0700519 int ret;
Stephen Warren6e5e9592012-03-02 13:05:47 -0700520
521 state = find_state(p, map->name);
522 if (!state)
523 state = create_state(p, map->name);
524 if (IS_ERR(state))
525 return PTR_ERR(state);
526
Stephen Warren1e2082b2012-03-02 13:05:48 -0700527 if (map->type == PIN_MAP_TYPE_DUMMY_STATE)
528 return 0;
529
Stephen Warren6e5e9592012-03-02 13:05:47 -0700530 setting = kzalloc(sizeof(*setting), GFP_KERNEL);
531 if (setting == NULL) {
532 dev_err(p->dev,
533 "failed to alloc struct pinctrl_setting\n");
534 return -ENOMEM;
535 }
536
Stephen Warren1e2082b2012-03-02 13:05:48 -0700537 setting->type = map->type;
538
Stephen Warren6e5e9592012-03-02 13:05:47 -0700539 setting->pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name);
540 if (setting->pctldev == NULL) {
Linus Walleijc05127c2012-04-10 10:00:38 +0200541 dev_info(p->dev, "unknown pinctrl device %s in map entry, deferring probe",
Stephen Warren6e5e9592012-03-02 13:05:47 -0700542 map->ctrl_dev_name);
543 kfree(setting);
Linus Walleijc05127c2012-04-10 10:00:38 +0200544 /*
545 * OK let us guess that the driver is not there yet, and
546 * let's defer obtaining this pinctrl handle to later...
547 */
548 return -EPROBE_DEFER;
Stephen Warren6e5e9592012-03-02 13:05:47 -0700549 }
550
Stephen Warren1e2082b2012-03-02 13:05:48 -0700551 switch (map->type) {
552 case PIN_MAP_TYPE_MUX_GROUP:
553 ret = pinmux_map_to_setting(map, setting);
554 break;
555 case PIN_MAP_TYPE_CONFIGS_PIN:
556 case PIN_MAP_TYPE_CONFIGS_GROUP:
557 ret = pinconf_map_to_setting(map, setting);
558 break;
559 default:
560 ret = -EINVAL;
561 break;
562 }
Stephen Warren6e5e9592012-03-02 13:05:47 -0700563 if (ret < 0) {
564 kfree(setting);
565 return ret;
566 }
567
568 list_add_tail(&setting->node, &state->settings);
569
570 return 0;
571}
572
573static struct pinctrl *find_pinctrl(struct device *dev)
574{
575 struct pinctrl *p;
576
Stephen Warren1e2082b2012-03-02 13:05:48 -0700577 list_for_each_entry(p, &pinctrl_list, node)
Stephen Warren6e5e9592012-03-02 13:05:47 -0700578 if (p->dev == dev)
579 return p;
580
581 return NULL;
582}
583
584static void pinctrl_put_locked(struct pinctrl *p, bool inlist);
585
586static struct pinctrl *create_pinctrl(struct device *dev)
587{
588 struct pinctrl *p;
589 const char *devname;
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700590 struct pinctrl_maps *maps_node;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100591 int i;
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700592 struct pinctrl_map const *map;
Stephen Warren6e5e9592012-03-02 13:05:47 -0700593 int ret;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100594
595 /*
596 * create the state cookie holder struct pinctrl for each
597 * mapping, this is what consumers will get when requesting
598 * a pin control handle with pinctrl_get()
599 */
Stephen Warren02f5b982012-02-22 14:26:00 -0700600 p = kzalloc(sizeof(*p), GFP_KERNEL);
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700601 if (p == NULL) {
602 dev_err(dev, "failed to alloc struct pinctrl\n");
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100603 return ERR_PTR(-ENOMEM);
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700604 }
Stephen Warren7ecdb162012-03-02 13:05:45 -0700605 p->dev = dev;
Stephen Warren6e5e9592012-03-02 13:05:47 -0700606 INIT_LIST_HEAD(&p->states);
Stephen Warren57291ce2012-03-23 10:29:46 -0600607 INIT_LIST_HEAD(&p->dt_maps);
608
609 ret = pinctrl_dt_to_map(p);
610 if (ret < 0) {
611 kfree(p);
612 return ERR_PTR(ret);
613 }
Stephen Warren6e5e9592012-03-02 13:05:47 -0700614
615 devname = dev_name(dev);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100616
617 /* Iterate over the pin control maps to locate the right ones */
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700618 for_each_maps(maps_node, i, map) {
Stephen Warren1681f5a2012-02-22 14:25:58 -0700619 /* Map must be for this device */
620 if (strcmp(map->dev_name, devname))
621 continue;
622
Stephen Warren6e5e9592012-03-02 13:05:47 -0700623 ret = add_setting(p, map);
624 if (ret < 0) {
625 pinctrl_put_locked(p, false);
626 return ERR_PTR(ret);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100627 }
628 }
629
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100630 /* Add the pinmux to the global list */
Stephen Warren8b9c1392012-02-19 23:45:42 -0700631 list_add_tail(&p->node, &pinctrl_list);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100632
633 return p;
Stephen Warren6e5e9592012-03-02 13:05:47 -0700634}
Stephen Warren7ecdb162012-03-02 13:05:45 -0700635
Stephen Warren6e5e9592012-03-02 13:05:47 -0700636static struct pinctrl *pinctrl_get_locked(struct device *dev)
637{
638 struct pinctrl *p;
Stephen Warren7ecdb162012-03-02 13:05:45 -0700639
Stephen Warren6e5e9592012-03-02 13:05:47 -0700640 if (WARN_ON(!dev))
641 return ERR_PTR(-EINVAL);
Stephen Warren7ecdb162012-03-02 13:05:45 -0700642
Stephen Warren6e5e9592012-03-02 13:05:47 -0700643 p = find_pinctrl(dev);
644 if (p != NULL)
645 return ERR_PTR(-EBUSY);
646
647 p = create_pinctrl(dev);
648 if (IS_ERR(p))
649 return p;
650
651 return p;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100652}
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700653
654/**
Stephen Warren6e5e9592012-03-02 13:05:47 -0700655 * pinctrl_get() - retrieves the pinctrl handle for a device
656 * @dev: the device to obtain the handle for
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700657 */
Stephen Warren6e5e9592012-03-02 13:05:47 -0700658struct pinctrl *pinctrl_get(struct device *dev)
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700659{
660 struct pinctrl *p;
661
Stephen Warren57b676f2012-03-02 13:05:44 -0700662 mutex_lock(&pinctrl_mutex);
Stephen Warren6e5e9592012-03-02 13:05:47 -0700663 p = pinctrl_get_locked(dev);
Stephen Warren57b676f2012-03-02 13:05:44 -0700664 mutex_unlock(&pinctrl_mutex);
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700665
666 return p;
667}
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100668EXPORT_SYMBOL_GPL(pinctrl_get);
669
Stephen Warren6e5e9592012-03-02 13:05:47 -0700670static void pinctrl_put_locked(struct pinctrl *p, bool inlist)
Stephen Warren57b676f2012-03-02 13:05:44 -0700671{
Stephen Warren6e5e9592012-03-02 13:05:47 -0700672 struct pinctrl_state *state, *n1;
673 struct pinctrl_setting *setting, *n2;
Stephen Warren7ecdb162012-03-02 13:05:45 -0700674
Stephen Warren6e5e9592012-03-02 13:05:47 -0700675 list_for_each_entry_safe(state, n1, &p->states, node) {
676 list_for_each_entry_safe(setting, n2, &state->settings, node) {
Stephen Warren1e2082b2012-03-02 13:05:48 -0700677 switch (setting->type) {
678 case PIN_MAP_TYPE_MUX_GROUP:
679 if (state == p->state)
680 pinmux_disable_setting(setting);
681 pinmux_free_setting(setting);
682 break;
683 case PIN_MAP_TYPE_CONFIGS_PIN:
684 case PIN_MAP_TYPE_CONFIGS_GROUP:
685 pinconf_free_setting(setting);
686 break;
687 default:
688 break;
689 }
Stephen Warren6e5e9592012-03-02 13:05:47 -0700690 list_del(&setting->node);
691 kfree(setting);
692 }
693 list_del(&state->node);
694 kfree(state);
Stephen Warren7ecdb162012-03-02 13:05:45 -0700695 }
Stephen Warren57b676f2012-03-02 13:05:44 -0700696
Stephen Warren57291ce2012-03-23 10:29:46 -0600697 pinctrl_dt_free_maps(p);
698
Stephen Warren6e5e9592012-03-02 13:05:47 -0700699 if (inlist)
700 list_del(&p->node);
Stephen Warren57b676f2012-03-02 13:05:44 -0700701 kfree(p);
702}
703
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100704/**
Stephen Warren6e5e9592012-03-02 13:05:47 -0700705 * pinctrl_put() - release a previously claimed pinctrl handle
706 * @p: the pinctrl handle to release
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100707 */
708void pinctrl_put(struct pinctrl *p)
709{
Stephen Warren57b676f2012-03-02 13:05:44 -0700710 mutex_lock(&pinctrl_mutex);
Stephen Warren6e5e9592012-03-02 13:05:47 -0700711 pinctrl_put_locked(p, true);
Stephen Warren57b676f2012-03-02 13:05:44 -0700712 mutex_unlock(&pinctrl_mutex);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100713}
714EXPORT_SYMBOL_GPL(pinctrl_put);
715
Stephen Warren6e5e9592012-03-02 13:05:47 -0700716static struct pinctrl_state *pinctrl_lookup_state_locked(struct pinctrl *p,
717 const char *name)
Stephen Warren57b676f2012-03-02 13:05:44 -0700718{
Stephen Warren6e5e9592012-03-02 13:05:47 -0700719 struct pinctrl_state *state;
720
721 state = find_state(p, name);
722 if (!state)
723 return ERR_PTR(-ENODEV);
724
725 return state;
726}
727
728/**
729 * pinctrl_lookup_state() - retrieves a state handle from a pinctrl handle
730 * @p: the pinctrl handle to retrieve the state from
731 * @name: the state name to retrieve
732 */
733struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p, const char *name)
734{
735 struct pinctrl_state *s;
736
737 mutex_lock(&pinctrl_mutex);
738 s = pinctrl_lookup_state_locked(p, name);
739 mutex_unlock(&pinctrl_mutex);
740
741 return s;
742}
743EXPORT_SYMBOL_GPL(pinctrl_lookup_state);
744
745static int pinctrl_select_state_locked(struct pinctrl *p,
746 struct pinctrl_state *state)
747{
748 struct pinctrl_setting *setting, *setting2;
Stephen Warren7ecdb162012-03-02 13:05:45 -0700749 int ret;
Stephen Warren57b676f2012-03-02 13:05:44 -0700750
Stephen Warren6e5e9592012-03-02 13:05:47 -0700751 if (p->state == state)
752 return 0;
Stephen Warren57b676f2012-03-02 13:05:44 -0700753
Stephen Warren6e5e9592012-03-02 13:05:47 -0700754 if (p->state) {
755 /*
756 * The set of groups with a mux configuration in the old state
757 * may not be identical to the set of groups with a mux setting
758 * in the new state. While this might be unusual, it's entirely
759 * possible for the "user"-supplied mapping table to be written
760 * that way. For each group that was configured in the old state
761 * but not in the new state, this code puts that group into a
762 * safe/disabled state.
763 */
764 list_for_each_entry(setting, &p->state->settings, node) {
765 bool found = false;
Stephen Warren1e2082b2012-03-02 13:05:48 -0700766 if (setting->type != PIN_MAP_TYPE_MUX_GROUP)
767 continue;
Stephen Warren6e5e9592012-03-02 13:05:47 -0700768 list_for_each_entry(setting2, &state->settings, node) {
Stephen Warren1e2082b2012-03-02 13:05:48 -0700769 if (setting2->type != PIN_MAP_TYPE_MUX_GROUP)
770 continue;
771 if (setting2->data.mux.group ==
772 setting->data.mux.group) {
Stephen Warren6e5e9592012-03-02 13:05:47 -0700773 found = true;
774 break;
775 }
Stephen Warren7ecdb162012-03-02 13:05:45 -0700776 }
Stephen Warren6e5e9592012-03-02 13:05:47 -0700777 if (!found)
778 pinmux_disable_setting(setting);
779 }
780 }
781
782 p->state = state;
783
784 /* Apply all the settings for the new state */
785 list_for_each_entry(setting, &state->settings, node) {
Stephen Warren1e2082b2012-03-02 13:05:48 -0700786 switch (setting->type) {
787 case PIN_MAP_TYPE_MUX_GROUP:
788 ret = pinmux_enable_setting(setting);
789 break;
790 case PIN_MAP_TYPE_CONFIGS_PIN:
791 case PIN_MAP_TYPE_CONFIGS_GROUP:
792 ret = pinconf_apply_setting(setting);
793 break;
794 default:
795 ret = -EINVAL;
796 break;
797 }
Stephen Warren6e5e9592012-03-02 13:05:47 -0700798 if (ret < 0) {
799 /* FIXME: Difficult to return to prev state */
800 return ret;
Stephen Warren7ecdb162012-03-02 13:05:45 -0700801 }
Stephen Warren57b676f2012-03-02 13:05:44 -0700802 }
803
Stephen Warren7ecdb162012-03-02 13:05:45 -0700804 return 0;
Stephen Warren57b676f2012-03-02 13:05:44 -0700805}
806
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100807/**
Stephen Warren6e5e9592012-03-02 13:05:47 -0700808 * pinctrl_select() - select/activate/program a pinctrl state to HW
809 * @p: the pinctrl handle for the device that requests configuratio
810 * @state: the state handle to select/activate/program
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100811 */
Stephen Warren6e5e9592012-03-02 13:05:47 -0700812int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100813{
Stephen Warren57b676f2012-03-02 13:05:44 -0700814 int ret;
Stephen Warren6e5e9592012-03-02 13:05:47 -0700815
Stephen Warren57b676f2012-03-02 13:05:44 -0700816 mutex_lock(&pinctrl_mutex);
Stephen Warren6e5e9592012-03-02 13:05:47 -0700817 ret = pinctrl_select_state_locked(p, state);
Stephen Warren57b676f2012-03-02 13:05:44 -0700818 mutex_unlock(&pinctrl_mutex);
Stephen Warren6e5e9592012-03-02 13:05:47 -0700819
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100820 return ret;
821}
Stephen Warren6e5e9592012-03-02 13:05:47 -0700822EXPORT_SYMBOL_GPL(pinctrl_select_state);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100823
Stephen Warren6d4ca1f2012-04-16 10:51:00 -0600824static void devm_pinctrl_release(struct device *dev, void *res)
825{
826 pinctrl_put(*(struct pinctrl **)res);
827}
828
829/**
830 * struct devm_pinctrl_get() - Resource managed pinctrl_get()
831 * @dev: the device to obtain the handle for
832 *
833 * If there is a need to explicitly destroy the returned struct pinctrl,
834 * devm_pinctrl_put() should be used, rather than plain pinctrl_put().
835 */
836struct pinctrl *devm_pinctrl_get(struct device *dev)
837{
838 struct pinctrl **ptr, *p;
839
840 ptr = devres_alloc(devm_pinctrl_release, sizeof(*ptr), GFP_KERNEL);
841 if (!ptr)
842 return ERR_PTR(-ENOMEM);
843
844 p = pinctrl_get(dev);
845 if (!IS_ERR(p)) {
846 *ptr = p;
847 devres_add(dev, ptr);
848 } else {
849 devres_free(ptr);
850 }
851
852 return p;
853}
854EXPORT_SYMBOL_GPL(devm_pinctrl_get);
855
856static int devm_pinctrl_match(struct device *dev, void *res, void *data)
857{
858 struct pinctrl **p = res;
859
860 return *p == data;
861}
862
863/**
864 * devm_pinctrl_put() - Resource managed pinctrl_put()
865 * @p: the pinctrl handle to release
866 *
867 * Deallocate a struct pinctrl obtained via devm_pinctrl_get(). Normally
868 * this function will not need to be called and the resource management
869 * code will ensure that the resource is freed.
870 */
871void devm_pinctrl_put(struct pinctrl *p)
872{
873 WARN_ON(devres_destroy(p->dev, devm_pinctrl_release,
874 devm_pinctrl_match, p));
875 pinctrl_put(p);
876}
877EXPORT_SYMBOL_GPL(devm_pinctrl_put);
878
Stephen Warren57291ce2012-03-23 10:29:46 -0600879int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps,
880 bool dup, bool locked)
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100881{
Stephen Warren1e2082b2012-03-02 13:05:48 -0700882 int i, ret;
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700883 struct pinctrl_maps *maps_node;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100884
885 pr_debug("add %d pinmux maps\n", num_maps);
886
887 /* First sanity check the new mapping */
888 for (i = 0; i < num_maps; i++) {
Stephen Warren1e2082b2012-03-02 13:05:48 -0700889 if (!maps[i].dev_name) {
890 pr_err("failed to register map %s (%d): no device given\n",
891 maps[i].name, i);
892 return -EINVAL;
893 }
894
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100895 if (!maps[i].name) {
896 pr_err("failed to register map %d: no map name given\n",
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700897 i);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100898 return -EINVAL;
899 }
900
Stephen Warren1e2082b2012-03-02 13:05:48 -0700901 if (maps[i].type != PIN_MAP_TYPE_DUMMY_STATE &&
902 !maps[i].ctrl_dev_name) {
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100903 pr_err("failed to register map %s (%d): no pin control device given\n",
904 maps[i].name, i);
905 return -EINVAL;
906 }
907
Stephen Warren1e2082b2012-03-02 13:05:48 -0700908 switch (maps[i].type) {
909 case PIN_MAP_TYPE_DUMMY_STATE:
910 break;
911 case PIN_MAP_TYPE_MUX_GROUP:
912 ret = pinmux_validate_map(&maps[i], i);
913 if (ret < 0)
Stephen Warrenfde04f42012-04-25 10:32:16 -0600914 return ret;
Stephen Warren1e2082b2012-03-02 13:05:48 -0700915 break;
916 case PIN_MAP_TYPE_CONFIGS_PIN:
917 case PIN_MAP_TYPE_CONFIGS_GROUP:
918 ret = pinconf_validate_map(&maps[i], i);
919 if (ret < 0)
Stephen Warrenfde04f42012-04-25 10:32:16 -0600920 return ret;
Stephen Warren1e2082b2012-03-02 13:05:48 -0700921 break;
922 default:
923 pr_err("failed to register map %s (%d): invalid type given\n",
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700924 maps[i].name, i);
Stephen Warren1681f5a2012-02-22 14:25:58 -0700925 return -EINVAL;
926 }
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100927 }
928
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700929 maps_node = kzalloc(sizeof(*maps_node), GFP_KERNEL);
930 if (!maps_node) {
931 pr_err("failed to alloc struct pinctrl_maps\n");
932 return -ENOMEM;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100933 }
934
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700935 maps_node->num_maps = num_maps;
Stephen Warren57291ce2012-03-23 10:29:46 -0600936 if (dup) {
937 maps_node->maps = kmemdup(maps, sizeof(*maps) * num_maps,
938 GFP_KERNEL);
939 if (!maps_node->maps) {
940 pr_err("failed to duplicate mapping table\n");
941 kfree(maps_node);
942 return -ENOMEM;
943 }
944 } else {
945 maps_node->maps = maps;
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700946 }
947
Stephen Warren57291ce2012-03-23 10:29:46 -0600948 if (!locked)
949 mutex_lock(&pinctrl_mutex);
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700950 list_add_tail(&maps_node->node, &pinctrl_maps);
Stephen Warren57291ce2012-03-23 10:29:46 -0600951 if (!locked)
952 mutex_unlock(&pinctrl_mutex);
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700953
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100954 return 0;
955}
956
Stephen Warren57291ce2012-03-23 10:29:46 -0600957/**
958 * pinctrl_register_mappings() - register a set of pin controller mappings
959 * @maps: the pincontrol mappings table to register. This should probably be
960 * marked with __initdata so it can be discarded after boot. This
961 * function will perform a shallow copy for the mapping entries.
962 * @num_maps: the number of maps in the mapping table
963 */
964int pinctrl_register_mappings(struct pinctrl_map const *maps,
965 unsigned num_maps)
966{
967 return pinctrl_register_map(maps, num_maps, true, false);
968}
969
970void pinctrl_unregister_map(struct pinctrl_map const *map)
971{
972 struct pinctrl_maps *maps_node;
973
974 list_for_each_entry(maps_node, &pinctrl_maps, node) {
975 if (maps_node->maps == map) {
976 list_del(&maps_node->node);
977 return;
978 }
979 }
980}
981
Linus Walleij2744e8a2011-05-02 20:50:54 +0200982#ifdef CONFIG_DEBUG_FS
983
984static int pinctrl_pins_show(struct seq_file *s, void *what)
985{
986 struct pinctrl_dev *pctldev = s->private;
987 const struct pinctrl_ops *ops = pctldev->desc->pctlops;
Chanho Park706e8522012-01-03 16:47:50 +0900988 unsigned i, pin;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200989
990 seq_printf(s, "registered pins: %d\n", pctldev->desc->npins);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200991
Stephen Warren57b676f2012-03-02 13:05:44 -0700992 mutex_lock(&pinctrl_mutex);
993
Chanho Park706e8522012-01-03 16:47:50 +0900994 /* The pin number can be retrived from the pin controller descriptor */
995 for (i = 0; i < pctldev->desc->npins; i++) {
Linus Walleij2744e8a2011-05-02 20:50:54 +0200996 struct pin_desc *desc;
997
Chanho Park706e8522012-01-03 16:47:50 +0900998 pin = pctldev->desc->pins[i].number;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200999 desc = pin_desc_get(pctldev, pin);
1000 /* Pin space may be sparse */
1001 if (desc == NULL)
1002 continue;
1003
1004 seq_printf(s, "pin %d (%s) ", pin,
1005 desc->name ? desc->name : "unnamed");
1006
1007 /* Driver-specific info per pin */
1008 if (ops->pin_dbg_show)
1009 ops->pin_dbg_show(pctldev, s, pin);
1010
1011 seq_puts(s, "\n");
1012 }
1013
Stephen Warren57b676f2012-03-02 13:05:44 -07001014 mutex_unlock(&pinctrl_mutex);
1015
Linus Walleij2744e8a2011-05-02 20:50:54 +02001016 return 0;
1017}
1018
1019static int pinctrl_groups_show(struct seq_file *s, void *what)
1020{
1021 struct pinctrl_dev *pctldev = s->private;
1022 const struct pinctrl_ops *ops = pctldev->desc->pctlops;
Viresh Kumard1e90e92012-03-30 11:25:40 +05301023 unsigned ngroups, selector = 0;
Linus Walleij2744e8a2011-05-02 20:50:54 +02001024
Viresh Kumard1e90e92012-03-30 11:25:40 +05301025 ngroups = ops->get_groups_count(pctldev);
Stephen Warren57b676f2012-03-02 13:05:44 -07001026 mutex_lock(&pinctrl_mutex);
1027
Linus Walleij2744e8a2011-05-02 20:50:54 +02001028 seq_puts(s, "registered pin groups:\n");
Viresh Kumard1e90e92012-03-30 11:25:40 +05301029 while (selector < ngroups) {
Stephen Warrena5818a82011-10-19 16:19:25 -06001030 const unsigned *pins;
Linus Walleij2744e8a2011-05-02 20:50:54 +02001031 unsigned num_pins;
1032 const char *gname = ops->get_group_name(pctldev, selector);
Dong Aishengdcb5dbc2012-04-17 15:00:46 +08001033 const char *pname;
Linus Walleij2744e8a2011-05-02 20:50:54 +02001034 int ret;
1035 int i;
1036
1037 ret = ops->get_group_pins(pctldev, selector,
1038 &pins, &num_pins);
1039 if (ret)
1040 seq_printf(s, "%s [ERROR GETTING PINS]\n",
1041 gname);
1042 else {
Dong Aishengdcb5dbc2012-04-17 15:00:46 +08001043 seq_printf(s, "group: %s\n", gname);
1044 for (i = 0; i < num_pins; i++) {
1045 pname = pin_get_name(pctldev, pins[i]);
1046 if (WARN_ON(!pname))
1047 return -EINVAL;
1048 seq_printf(s, "pin %d (%s)\n", pins[i], pname);
1049 }
1050 seq_puts(s, "\n");
Linus Walleij2744e8a2011-05-02 20:50:54 +02001051 }
1052 selector++;
1053 }
1054
Stephen Warren57b676f2012-03-02 13:05:44 -07001055 mutex_unlock(&pinctrl_mutex);
Linus Walleij2744e8a2011-05-02 20:50:54 +02001056
1057 return 0;
1058}
1059
1060static int pinctrl_gpioranges_show(struct seq_file *s, void *what)
1061{
1062 struct pinctrl_dev *pctldev = s->private;
1063 struct pinctrl_gpio_range *range = NULL;
1064
1065 seq_puts(s, "GPIO ranges handled:\n");
1066
Stephen Warren57b676f2012-03-02 13:05:44 -07001067 mutex_lock(&pinctrl_mutex);
1068
Linus Walleij2744e8a2011-05-02 20:50:54 +02001069 /* Loop over the ranges */
Linus Walleij2744e8a2011-05-02 20:50:54 +02001070 list_for_each_entry(range, &pctldev->gpio_ranges, node) {
Linus Walleij75d66422011-11-16 09:58:51 +01001071 seq_printf(s, "%u: %s GPIOS [%u - %u] PINS [%u - %u]\n",
1072 range->id, range->name,
1073 range->base, (range->base + range->npins - 1),
1074 range->pin_base,
1075 (range->pin_base + range->npins - 1));
Linus Walleij2744e8a2011-05-02 20:50:54 +02001076 }
Stephen Warren57b676f2012-03-02 13:05:44 -07001077
1078 mutex_unlock(&pinctrl_mutex);
Linus Walleij2744e8a2011-05-02 20:50:54 +02001079
1080 return 0;
1081}
1082
1083static int pinctrl_devices_show(struct seq_file *s, void *what)
1084{
1085 struct pinctrl_dev *pctldev;
1086
Linus Walleijae6b4d82011-10-19 18:14:33 +02001087 seq_puts(s, "name [pinmux] [pinconf]\n");
Stephen Warren57b676f2012-03-02 13:05:44 -07001088
1089 mutex_lock(&pinctrl_mutex);
1090
Linus Walleij2744e8a2011-05-02 20:50:54 +02001091 list_for_each_entry(pctldev, &pinctrldev_list, node) {
1092 seq_printf(s, "%s ", pctldev->desc->name);
1093 if (pctldev->desc->pmxops)
Linus Walleijae6b4d82011-10-19 18:14:33 +02001094 seq_puts(s, "yes ");
1095 else
1096 seq_puts(s, "no ");
1097 if (pctldev->desc->confops)
Linus Walleij2744e8a2011-05-02 20:50:54 +02001098 seq_puts(s, "yes");
1099 else
1100 seq_puts(s, "no");
1101 seq_puts(s, "\n");
1102 }
Stephen Warren57b676f2012-03-02 13:05:44 -07001103
1104 mutex_unlock(&pinctrl_mutex);
Linus Walleij2744e8a2011-05-02 20:50:54 +02001105
1106 return 0;
1107}
1108
Stephen Warren1e2082b2012-03-02 13:05:48 -07001109static inline const char *map_type(enum pinctrl_map_type type)
1110{
1111 static const char * const names[] = {
1112 "INVALID",
1113 "DUMMY_STATE",
1114 "MUX_GROUP",
1115 "CONFIGS_PIN",
1116 "CONFIGS_GROUP",
1117 };
1118
1119 if (type >= ARRAY_SIZE(names))
1120 return "UNKNOWN";
1121
1122 return names[type];
1123}
1124
Stephen Warren3eedb432012-02-23 17:04:40 -07001125static int pinctrl_maps_show(struct seq_file *s, void *what)
1126{
1127 struct pinctrl_maps *maps_node;
1128 int i;
1129 struct pinctrl_map const *map;
1130
1131 seq_puts(s, "Pinctrl maps:\n");
1132
Stephen Warren57b676f2012-03-02 13:05:44 -07001133 mutex_lock(&pinctrl_mutex);
1134
Stephen Warren3eedb432012-02-23 17:04:40 -07001135 for_each_maps(maps_node, i, map) {
Stephen Warren1e2082b2012-03-02 13:05:48 -07001136 seq_printf(s, "device %s\nstate %s\ntype %s (%d)\n",
1137 map->dev_name, map->name, map_type(map->type),
1138 map->type);
1139
1140 if (map->type != PIN_MAP_TYPE_DUMMY_STATE)
1141 seq_printf(s, "controlling device %s\n",
1142 map->ctrl_dev_name);
1143
1144 switch (map->type) {
1145 case PIN_MAP_TYPE_MUX_GROUP:
1146 pinmux_show_map(s, map);
1147 break;
1148 case PIN_MAP_TYPE_CONFIGS_PIN:
1149 case PIN_MAP_TYPE_CONFIGS_GROUP:
1150 pinconf_show_map(s, map);
1151 break;
1152 default:
1153 break;
1154 }
1155
1156 seq_printf(s, "\n");
Stephen Warren3eedb432012-02-23 17:04:40 -07001157 }
Stephen Warren57b676f2012-03-02 13:05:44 -07001158
1159 mutex_unlock(&pinctrl_mutex);
Stephen Warren3eedb432012-02-23 17:04:40 -07001160
1161 return 0;
1162}
1163
Linus Walleijbefe5bd2012-02-09 19:47:48 +01001164static int pinctrl_show(struct seq_file *s, void *what)
1165{
1166 struct pinctrl *p;
Stephen Warren6e5e9592012-03-02 13:05:47 -07001167 struct pinctrl_state *state;
Stephen Warren7ecdb162012-03-02 13:05:45 -07001168 struct pinctrl_setting *setting;
Linus Walleijbefe5bd2012-02-09 19:47:48 +01001169
1170 seq_puts(s, "Requested pin control handlers their pinmux maps:\n");
Stephen Warren57b676f2012-03-02 13:05:44 -07001171
1172 mutex_lock(&pinctrl_mutex);
1173
Linus Walleijbefe5bd2012-02-09 19:47:48 +01001174 list_for_each_entry(p, &pinctrl_list, node) {
Stephen Warren6e5e9592012-03-02 13:05:47 -07001175 seq_printf(s, "device: %s current state: %s\n",
1176 dev_name(p->dev),
1177 p->state ? p->state->name : "none");
Linus Walleijbefe5bd2012-02-09 19:47:48 +01001178
Stephen Warren6e5e9592012-03-02 13:05:47 -07001179 list_for_each_entry(state, &p->states, node) {
1180 seq_printf(s, " state: %s\n", state->name);
1181
1182 list_for_each_entry(setting, &state->settings, node) {
Stephen Warren1e2082b2012-03-02 13:05:48 -07001183 struct pinctrl_dev *pctldev = setting->pctldev;
1184
1185 seq_printf(s, " type: %s controller %s ",
1186 map_type(setting->type),
1187 pinctrl_dev_get_name(pctldev));
1188
1189 switch (setting->type) {
1190 case PIN_MAP_TYPE_MUX_GROUP:
1191 pinmux_show_setting(s, setting);
1192 break;
1193 case PIN_MAP_TYPE_CONFIGS_PIN:
1194 case PIN_MAP_TYPE_CONFIGS_GROUP:
1195 pinconf_show_setting(s, setting);
1196 break;
1197 default:
1198 break;
1199 }
Stephen Warren6e5e9592012-03-02 13:05:47 -07001200 }
Linus Walleijbefe5bd2012-02-09 19:47:48 +01001201 }
Linus Walleijbefe5bd2012-02-09 19:47:48 +01001202 }
1203
Stephen Warren57b676f2012-03-02 13:05:44 -07001204 mutex_unlock(&pinctrl_mutex);
1205
Linus Walleijbefe5bd2012-02-09 19:47:48 +01001206 return 0;
1207}
1208
Linus Walleij2744e8a2011-05-02 20:50:54 +02001209static int pinctrl_pins_open(struct inode *inode, struct file *file)
1210{
1211 return single_open(file, pinctrl_pins_show, inode->i_private);
1212}
1213
1214static int pinctrl_groups_open(struct inode *inode, struct file *file)
1215{
1216 return single_open(file, pinctrl_groups_show, inode->i_private);
1217}
1218
1219static int pinctrl_gpioranges_open(struct inode *inode, struct file *file)
1220{
1221 return single_open(file, pinctrl_gpioranges_show, inode->i_private);
1222}
1223
1224static int pinctrl_devices_open(struct inode *inode, struct file *file)
1225{
1226 return single_open(file, pinctrl_devices_show, NULL);
1227}
1228
Stephen Warren3eedb432012-02-23 17:04:40 -07001229static int pinctrl_maps_open(struct inode *inode, struct file *file)
1230{
1231 return single_open(file, pinctrl_maps_show, NULL);
1232}
1233
Linus Walleijbefe5bd2012-02-09 19:47:48 +01001234static int pinctrl_open(struct inode *inode, struct file *file)
1235{
1236 return single_open(file, pinctrl_show, NULL);
1237}
1238
Linus Walleij2744e8a2011-05-02 20:50:54 +02001239static const struct file_operations pinctrl_pins_ops = {
1240 .open = pinctrl_pins_open,
1241 .read = seq_read,
1242 .llseek = seq_lseek,
1243 .release = single_release,
1244};
1245
1246static const struct file_operations pinctrl_groups_ops = {
1247 .open = pinctrl_groups_open,
1248 .read = seq_read,
1249 .llseek = seq_lseek,
1250 .release = single_release,
1251};
1252
1253static const struct file_operations pinctrl_gpioranges_ops = {
1254 .open = pinctrl_gpioranges_open,
1255 .read = seq_read,
1256 .llseek = seq_lseek,
1257 .release = single_release,
1258};
1259
1260static const struct file_operations pinctrl_devices_ops = {
1261 .open = pinctrl_devices_open,
1262 .read = seq_read,
1263 .llseek = seq_lseek,
1264 .release = single_release,
1265};
1266
Stephen Warren3eedb432012-02-23 17:04:40 -07001267static const struct file_operations pinctrl_maps_ops = {
1268 .open = pinctrl_maps_open,
1269 .read = seq_read,
1270 .llseek = seq_lseek,
1271 .release = single_release,
1272};
1273
Linus Walleijbefe5bd2012-02-09 19:47:48 +01001274static const struct file_operations pinctrl_ops = {
1275 .open = pinctrl_open,
1276 .read = seq_read,
1277 .llseek = seq_lseek,
1278 .release = single_release,
1279};
1280
Linus Walleij2744e8a2011-05-02 20:50:54 +02001281static struct dentry *debugfs_root;
1282
1283static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)
1284{
Tony Lindgren02157162012-01-20 08:17:22 -08001285 struct dentry *device_root;
Linus Walleij2744e8a2011-05-02 20:50:54 +02001286
Stephen Warren51cd24e2011-12-09 16:59:05 -07001287 device_root = debugfs_create_dir(dev_name(pctldev->dev),
Linus Walleij2744e8a2011-05-02 20:50:54 +02001288 debugfs_root);
Tony Lindgren02157162012-01-20 08:17:22 -08001289 pctldev->device_root = device_root;
1290
Linus Walleij2744e8a2011-05-02 20:50:54 +02001291 if (IS_ERR(device_root) || !device_root) {
1292 pr_warn("failed to create debugfs directory for %s\n",
Stephen Warren51cd24e2011-12-09 16:59:05 -07001293 dev_name(pctldev->dev));
Linus Walleij2744e8a2011-05-02 20:50:54 +02001294 return;
1295 }
1296 debugfs_create_file("pins", S_IFREG | S_IRUGO,
1297 device_root, pctldev, &pinctrl_pins_ops);
1298 debugfs_create_file("pingroups", S_IFREG | S_IRUGO,
1299 device_root, pctldev, &pinctrl_groups_ops);
1300 debugfs_create_file("gpio-ranges", S_IFREG | S_IRUGO,
1301 device_root, pctldev, &pinctrl_gpioranges_ops);
1302 pinmux_init_device_debugfs(device_root, pctldev);
Linus Walleijae6b4d82011-10-19 18:14:33 +02001303 pinconf_init_device_debugfs(device_root, pctldev);
Linus Walleij2744e8a2011-05-02 20:50:54 +02001304}
1305
Tony Lindgren02157162012-01-20 08:17:22 -08001306static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev)
1307{
1308 debugfs_remove_recursive(pctldev->device_root);
1309}
1310
Linus Walleij2744e8a2011-05-02 20:50:54 +02001311static void pinctrl_init_debugfs(void)
1312{
1313 debugfs_root = debugfs_create_dir("pinctrl", NULL);
1314 if (IS_ERR(debugfs_root) || !debugfs_root) {
1315 pr_warn("failed to create debugfs directory\n");
1316 debugfs_root = NULL;
1317 return;
1318 }
1319
1320 debugfs_create_file("pinctrl-devices", S_IFREG | S_IRUGO,
1321 debugfs_root, NULL, &pinctrl_devices_ops);
Stephen Warren3eedb432012-02-23 17:04:40 -07001322 debugfs_create_file("pinctrl-maps", S_IFREG | S_IRUGO,
1323 debugfs_root, NULL, &pinctrl_maps_ops);
Linus Walleijbefe5bd2012-02-09 19:47:48 +01001324 debugfs_create_file("pinctrl-handles", S_IFREG | S_IRUGO,
1325 debugfs_root, NULL, &pinctrl_ops);
Linus Walleij2744e8a2011-05-02 20:50:54 +02001326}
1327
1328#else /* CONFIG_DEBUG_FS */
1329
1330static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)
1331{
1332}
1333
1334static void pinctrl_init_debugfs(void)
1335{
1336}
1337
Tony Lindgren02157162012-01-20 08:17:22 -08001338static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev)
1339{
1340}
1341
Linus Walleij2744e8a2011-05-02 20:50:54 +02001342#endif
1343
Stephen Warrend26bc492012-03-16 14:54:25 -06001344static int pinctrl_check_ops(struct pinctrl_dev *pctldev)
1345{
1346 const struct pinctrl_ops *ops = pctldev->desc->pctlops;
1347
1348 if (!ops ||
Viresh Kumard1e90e92012-03-30 11:25:40 +05301349 !ops->get_groups_count ||
Stephen Warrend26bc492012-03-16 14:54:25 -06001350 !ops->get_group_name ||
1351 !ops->get_group_pins)
1352 return -EINVAL;
1353
Stephen Warren57291ce2012-03-23 10:29:46 -06001354 if (ops->dt_node_to_map && !ops->dt_free_map)
1355 return -EINVAL;
1356
Stephen Warrend26bc492012-03-16 14:54:25 -06001357 return 0;
1358}
1359
Linus Walleij2744e8a2011-05-02 20:50:54 +02001360/**
1361 * pinctrl_register() - register a pin controller device
1362 * @pctldesc: descriptor for this pin controller
1363 * @dev: parent device for this pin controller
1364 * @driver_data: private pin controller data for this pin controller
1365 */
1366struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
1367 struct device *dev, void *driver_data)
1368{
Linus Walleij2744e8a2011-05-02 20:50:54 +02001369 struct pinctrl_dev *pctldev;
1370 int ret;
1371
1372 if (pctldesc == NULL)
1373 return NULL;
1374 if (pctldesc->name == NULL)
1375 return NULL;
1376
Stephen Warren02f5b982012-02-22 14:26:00 -07001377 pctldev = kzalloc(sizeof(*pctldev), GFP_KERNEL);
Stephen Warren95dcd4a2012-02-22 14:25:59 -07001378 if (pctldev == NULL) {
1379 dev_err(dev, "failed to alloc struct pinctrl_dev\n");
Linus Walleij2744e8a2011-05-02 20:50:54 +02001380 return NULL;
Stephen Warren95dcd4a2012-02-22 14:25:59 -07001381 }
Linus Walleij2744e8a2011-05-02 20:50:54 +02001382
1383 /* Initialize pin control device struct */
1384 pctldev->owner = pctldesc->owner;
1385 pctldev->desc = pctldesc;
1386 pctldev->driver_data = driver_data;
1387 INIT_RADIX_TREE(&pctldev->pin_desc_tree, GFP_KERNEL);
Linus Walleij2744e8a2011-05-02 20:50:54 +02001388 INIT_LIST_HEAD(&pctldev->gpio_ranges);
Stephen Warren51cd24e2011-12-09 16:59:05 -07001389 pctldev->dev = dev;
Linus Walleij2744e8a2011-05-02 20:50:54 +02001390
Stephen Warrend26bc492012-03-16 14:54:25 -06001391 /* check core ops for sanity */
1392 ret = pinctrl_check_ops(pctldev);
1393 if (ret) {
John Crispinad6e1102012-04-26 16:47:11 +02001394 dev_err(dev, "pinctrl ops lacks necessary functions\n");
Stephen Warrend26bc492012-03-16 14:54:25 -06001395 goto out_err;
1396 }
1397
Tony Lindgrenb9130b72012-01-24 16:28:08 -08001398 /* If we're implementing pinmuxing, check the ops for sanity */
1399 if (pctldesc->pmxops) {
1400 ret = pinmux_check_ops(pctldev);
John Crispinad6e1102012-04-26 16:47:11 +02001401 if (ret)
Tony Lindgrenb9130b72012-01-24 16:28:08 -08001402 goto out_err;
Tony Lindgrenb9130b72012-01-24 16:28:08 -08001403 }
1404
1405 /* If we're implementing pinconfig, check the ops for sanity */
1406 if (pctldesc->confops) {
1407 ret = pinconf_check_ops(pctldev);
John Crispinad6e1102012-04-26 16:47:11 +02001408 if (ret)
Tony Lindgrenb9130b72012-01-24 16:28:08 -08001409 goto out_err;
Tony Lindgrenb9130b72012-01-24 16:28:08 -08001410 }
1411
Linus Walleij2744e8a2011-05-02 20:50:54 +02001412 /* Register all the pins */
John Crispinad6e1102012-04-26 16:47:11 +02001413 dev_dbg(dev, "try to register %d pins ...\n", pctldesc->npins);
Linus Walleij2744e8a2011-05-02 20:50:54 +02001414 ret = pinctrl_register_pins(pctldev, pctldesc->pins, pctldesc->npins);
1415 if (ret) {
John Crispinad6e1102012-04-26 16:47:11 +02001416 dev_err(dev, "error during pin registration\n");
Linus Walleij2744e8a2011-05-02 20:50:54 +02001417 pinctrl_free_pindescs(pctldev, pctldesc->pins,
1418 pctldesc->npins);
Stephen Warren51cd24e2011-12-09 16:59:05 -07001419 goto out_err;
Linus Walleij2744e8a2011-05-02 20:50:54 +02001420 }
1421
Stephen Warren57b676f2012-03-02 13:05:44 -07001422 mutex_lock(&pinctrl_mutex);
1423
Stephen Warren8b9c1392012-02-19 23:45:42 -07001424 list_add_tail(&pctldev->node, &pinctrldev_list);
Stephen Warren57b676f2012-03-02 13:05:44 -07001425
Stephen Warren6e5e9592012-03-02 13:05:47 -07001426 pctldev->p = pinctrl_get_locked(pctldev->dev);
1427 if (!IS_ERR(pctldev->p)) {
1428 struct pinctrl_state *s =
1429 pinctrl_lookup_state_locked(pctldev->p,
1430 PINCTRL_STATE_DEFAULT);
John Crispinad6e1102012-04-26 16:47:11 +02001431 if (IS_ERR(s)) {
1432 dev_dbg(dev, "failed to lookup the default state\n");
1433 } else {
1434 ret = pinctrl_select_state_locked(pctldev->p, s);
1435 if (ret) {
1436 dev_err(dev,
1437 "failed to select default state\n");
1438 }
1439 }
Stephen Warren6e5e9592012-03-02 13:05:47 -07001440 }
Stephen Warren57b676f2012-03-02 13:05:44 -07001441
1442 mutex_unlock(&pinctrl_mutex);
1443
Stephen Warren2304b472012-02-22 14:26:01 -07001444 pinctrl_init_device_debugfs(pctldev);
1445
Linus Walleij2744e8a2011-05-02 20:50:54 +02001446 return pctldev;
1447
Stephen Warren51cd24e2011-12-09 16:59:05 -07001448out_err:
1449 kfree(pctldev);
Linus Walleij2744e8a2011-05-02 20:50:54 +02001450 return NULL;
1451}
1452EXPORT_SYMBOL_GPL(pinctrl_register);
1453
1454/**
1455 * pinctrl_unregister() - unregister pinmux
1456 * @pctldev: pin controller to unregister
1457 *
1458 * Called by pinmux drivers to unregister a pinmux.
1459 */
1460void pinctrl_unregister(struct pinctrl_dev *pctldev)
1461{
1462 if (pctldev == NULL)
1463 return;
1464
Tony Lindgren02157162012-01-20 08:17:22 -08001465 pinctrl_remove_device_debugfs(pctldev);
Stephen Warren57b676f2012-03-02 13:05:44 -07001466
1467 mutex_lock(&pinctrl_mutex);
1468
Stephen Warren6e5e9592012-03-02 13:05:47 -07001469 if (!IS_ERR(pctldev->p))
1470 pinctrl_put_locked(pctldev->p, true);
Stephen Warren57b676f2012-03-02 13:05:44 -07001471
Linus Walleij2744e8a2011-05-02 20:50:54 +02001472 /* TODO: check that no pinmuxes are still active? */
Linus Walleij2744e8a2011-05-02 20:50:54 +02001473 list_del(&pctldev->node);
Linus Walleij2744e8a2011-05-02 20:50:54 +02001474 /* Destroy descriptor tree */
1475 pinctrl_free_pindescs(pctldev, pctldev->desc->pins,
1476 pctldev->desc->npins);
Stephen Warren51cd24e2011-12-09 16:59:05 -07001477 kfree(pctldev);
Stephen Warren57b676f2012-03-02 13:05:44 -07001478
1479 mutex_unlock(&pinctrl_mutex);
Linus Walleij2744e8a2011-05-02 20:50:54 +02001480}
1481EXPORT_SYMBOL_GPL(pinctrl_unregister);
1482
1483static int __init pinctrl_init(void)
1484{
1485 pr_info("initialized pinctrl subsystem\n");
1486 pinctrl_init_debugfs();
1487 return 0;
1488}
1489
1490/* init early since many drivers really need to initialized pinmux early */
1491core_initcall(pinctrl_init);