blob: f25307b0e00a70a76788ca02997e2ad0aac1ef34 [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>
21#include <linux/radix-tree.h>
22#include <linux/err.h>
23#include <linux/list.h>
24#include <linux/mutex.h>
25#include <linux/spinlock.h>
26#include <linux/sysfs.h>
27#include <linux/debugfs.h>
28#include <linux/seq_file.h>
29#include <linux/pinctrl/pinctrl.h>
30#include <linux/pinctrl/machine.h>
31#include "core.h"
32#include "pinmux.h"
Linus Walleijae6b4d82011-10-19 18:14:33 +020033#include "pinconf.h"
Linus Walleij2744e8a2011-05-02 20:50:54 +020034
Linus Walleijbefe5bd2012-02-09 19:47:48 +010035/**
Stephen Warrenb2b3e662012-02-19 23:45:43 -070036 * struct pinctrl_maps - a list item containing part of the mapping table
37 * @node: mapping table list node
38 * @maps: array of mapping table entries
39 * @num_maps: the number of entries in @maps
40 */
41struct pinctrl_maps {
42 struct list_head node;
43 struct pinctrl_map const *maps;
44 unsigned num_maps;
45};
46
Linus Walleij2744e8a2011-05-02 20:50:54 +020047/* Global list of pin control devices */
48static DEFINE_MUTEX(pinctrldev_list_mutex);
49static LIST_HEAD(pinctrldev_list);
50
Linus Walleijbefe5bd2012-02-09 19:47:48 +010051/* List of pin controller handles */
52static DEFINE_MUTEX(pinctrl_list_mutex);
53static LIST_HEAD(pinctrl_list);
54
55/* Global pinctrl maps */
Stephen Warrenb2b3e662012-02-19 23:45:43 -070056static DEFINE_MUTEX(pinctrl_maps_mutex);
57static LIST_HEAD(pinctrl_maps);
58
59#define for_each_maps(_maps_node_, _i_, _map_) \
60 list_for_each_entry(_maps_node_, &pinctrl_maps, node) \
61 for (_i_ = 0, _map_ = &_maps_node_->maps[_i_]; \
62 _i_ < _maps_node_->num_maps; \
63 i++, _map_ = &_maps_node_->maps[_i_])
Linus Walleijbefe5bd2012-02-09 19:47:48 +010064
Linus Walleij2744e8a2011-05-02 20:50:54 +020065const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev)
66{
67 /* We're not allowed to register devices without name */
68 return pctldev->desc->name;
69}
70EXPORT_SYMBOL_GPL(pinctrl_dev_get_name);
71
72void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev)
73{
74 return pctldev->driver_data;
75}
76EXPORT_SYMBOL_GPL(pinctrl_dev_get_drvdata);
77
78/**
Linus Walleij9dfac4f2012-02-01 18:02:47 +010079 * get_pinctrl_dev_from_devname() - look up pin controller device
80 * @devname: the name of a device instance, as returned by dev_name()
Linus Walleij2744e8a2011-05-02 20:50:54 +020081 *
82 * Looks up a pin control device matching a certain device name or pure device
83 * pointer, the pure device pointer will take precedence.
84 */
Linus Walleij9dfac4f2012-02-01 18:02:47 +010085struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *devname)
Linus Walleij2744e8a2011-05-02 20:50:54 +020086{
87 struct pinctrl_dev *pctldev = NULL;
88 bool found = false;
89
Linus Walleij9dfac4f2012-02-01 18:02:47 +010090 if (!devname)
91 return NULL;
92
Linus Walleij2744e8a2011-05-02 20:50:54 +020093 mutex_lock(&pinctrldev_list_mutex);
94 list_for_each_entry(pctldev, &pinctrldev_list, node) {
Linus Walleij9dfac4f2012-02-01 18:02:47 +010095 if (!strcmp(dev_name(pctldev->dev), devname)) {
Linus Walleij2744e8a2011-05-02 20:50:54 +020096 /* Matched on device name */
97 found = true;
98 break;
99 }
100 }
101 mutex_unlock(&pinctrldev_list_mutex);
102
103 return found ? pctldev : NULL;
104}
105
Linus Walleij2744e8a2011-05-02 20:50:54 +0200106/**
Linus Walleijae6b4d82011-10-19 18:14:33 +0200107 * pin_get_from_name() - look up a pin number from a name
108 * @pctldev: the pin control device to lookup the pin on
109 * @name: the name of the pin to look up
110 */
111int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name)
112{
Chanho Park706e8522012-01-03 16:47:50 +0900113 unsigned i, pin;
Linus Walleijae6b4d82011-10-19 18:14:33 +0200114
Chanho Park706e8522012-01-03 16:47:50 +0900115 /* The pin number can be retrived from the pin controller descriptor */
116 for (i = 0; i < pctldev->desc->npins; i++) {
Linus Walleijae6b4d82011-10-19 18:14:33 +0200117 struct pin_desc *desc;
118
Chanho Park706e8522012-01-03 16:47:50 +0900119 pin = pctldev->desc->pins[i].number;
Linus Walleijae6b4d82011-10-19 18:14:33 +0200120 desc = pin_desc_get(pctldev, pin);
121 /* Pin space may be sparse */
122 if (desc == NULL)
123 continue;
124 if (desc->name && !strcmp(name, desc->name))
125 return pin;
126 }
127
128 return -EINVAL;
129}
130
131/**
Linus Walleij2744e8a2011-05-02 20:50:54 +0200132 * pin_is_valid() - check if pin exists on controller
133 * @pctldev: the pin control device to check the pin on
134 * @pin: pin to check, use the local pin controller index number
135 *
136 * This tells us whether a certain pin exist on a certain pin controller or
137 * not. Pin lists may be sparse, so some pins may not exist.
138 */
139bool pin_is_valid(struct pinctrl_dev *pctldev, int pin)
140{
141 struct pin_desc *pindesc;
142
143 if (pin < 0)
144 return false;
145
146 pindesc = pin_desc_get(pctldev, pin);
147 if (pindesc == NULL)
148 return false;
149
150 return true;
151}
152EXPORT_SYMBOL_GPL(pin_is_valid);
153
154/* Deletes a range of pin descriptors */
155static void pinctrl_free_pindescs(struct pinctrl_dev *pctldev,
156 const struct pinctrl_pin_desc *pins,
157 unsigned num_pins)
158{
159 int i;
160
Linus Walleij2744e8a2011-05-02 20:50:54 +0200161 for (i = 0; i < num_pins; i++) {
162 struct pin_desc *pindesc;
163
164 pindesc = radix_tree_lookup(&pctldev->pin_desc_tree,
165 pins[i].number);
166 if (pindesc != NULL) {
167 radix_tree_delete(&pctldev->pin_desc_tree,
168 pins[i].number);
Linus Walleijca53c5f2011-12-14 20:33:37 +0100169 if (pindesc->dynamic_name)
170 kfree(pindesc->name);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200171 }
172 kfree(pindesc);
173 }
Linus Walleij2744e8a2011-05-02 20:50:54 +0200174}
175
176static int pinctrl_register_one_pin(struct pinctrl_dev *pctldev,
177 unsigned number, const char *name)
178{
179 struct pin_desc *pindesc;
180
181 pindesc = pin_desc_get(pctldev, number);
182 if (pindesc != NULL) {
183 pr_err("pin %d already registered on %s\n", number,
184 pctldev->desc->name);
185 return -EINVAL;
186 }
187
188 pindesc = kzalloc(sizeof(*pindesc), GFP_KERNEL);
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700189 if (pindesc == NULL) {
190 dev_err(pctldev->dev, "failed to alloc struct pin_desc\n");
Linus Walleij2744e8a2011-05-02 20:50:54 +0200191 return -ENOMEM;
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700192 }
Linus Walleijae6b4d82011-10-19 18:14:33 +0200193
Linus Walleij2744e8a2011-05-02 20:50:54 +0200194 spin_lock_init(&pindesc->lock);
195
196 /* Set owner */
197 pindesc->pctldev = pctldev;
198
Stephen Warren9af1e442011-10-19 16:19:27 -0600199 /* Copy basic pin info */
Linus Walleij8dc6ae42012-02-01 18:11:40 +0100200 if (name) {
Linus Walleijca53c5f2011-12-14 20:33:37 +0100201 pindesc->name = name;
202 } else {
203 pindesc->name = kasprintf(GFP_KERNEL, "PIN%u", number);
204 if (pindesc->name == NULL)
205 return -ENOMEM;
206 pindesc->dynamic_name = true;
207 }
Linus Walleij2744e8a2011-05-02 20:50:54 +0200208
Linus Walleij2744e8a2011-05-02 20:50:54 +0200209 radix_tree_insert(&pctldev->pin_desc_tree, number, pindesc);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200210 pr_debug("registered pin %d (%s) on %s\n",
Linus Walleijca53c5f2011-12-14 20:33:37 +0100211 number, pindesc->name, pctldev->desc->name);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200212 return 0;
213}
214
215static int pinctrl_register_pins(struct pinctrl_dev *pctldev,
216 struct pinctrl_pin_desc const *pins,
217 unsigned num_descs)
218{
219 unsigned i;
220 int ret = 0;
221
222 for (i = 0; i < num_descs; i++) {
223 ret = pinctrl_register_one_pin(pctldev,
224 pins[i].number, pins[i].name);
225 if (ret)
226 return ret;
227 }
228
229 return 0;
230}
231
232/**
233 * pinctrl_match_gpio_range() - check if a certain GPIO pin is in range
234 * @pctldev: pin controller device to check
235 * @gpio: gpio pin to check taken from the global GPIO pin space
236 *
237 * Tries to match a GPIO pin number to the ranges handled by a certain pin
238 * controller, return the range or NULL
239 */
240static struct pinctrl_gpio_range *
241pinctrl_match_gpio_range(struct pinctrl_dev *pctldev, unsigned gpio)
242{
243 struct pinctrl_gpio_range *range = NULL;
244
245 /* Loop over the ranges */
246 mutex_lock(&pctldev->gpio_ranges_lock);
247 list_for_each_entry(range, &pctldev->gpio_ranges, node) {
248 /* Check if we're in the valid range */
249 if (gpio >= range->base &&
250 gpio < range->base + range->npins) {
251 mutex_unlock(&pctldev->gpio_ranges_lock);
252 return range;
253 }
254 }
255 mutex_unlock(&pctldev->gpio_ranges_lock);
256
257 return NULL;
258}
259
260/**
261 * pinctrl_get_device_gpio_range() - find device for GPIO range
262 * @gpio: the pin to locate the pin controller for
263 * @outdev: the pin control device if found
264 * @outrange: the GPIO range if found
265 *
266 * Find the pin controller handling a certain GPIO pin from the pinspace of
267 * the GPIO subsystem, return the device and the matching GPIO range. Returns
268 * negative if the GPIO range could not be found in any device.
269 */
Stephen Warren4ecce45d2012-02-19 23:45:47 -0700270static int pinctrl_get_device_gpio_range(unsigned gpio,
271 struct pinctrl_dev **outdev,
272 struct pinctrl_gpio_range **outrange)
Linus Walleij2744e8a2011-05-02 20:50:54 +0200273{
274 struct pinctrl_dev *pctldev = NULL;
275
276 /* Loop over the pin controllers */
277 mutex_lock(&pinctrldev_list_mutex);
278 list_for_each_entry(pctldev, &pinctrldev_list, node) {
279 struct pinctrl_gpio_range *range;
280
281 range = pinctrl_match_gpio_range(pctldev, gpio);
282 if (range != NULL) {
283 *outdev = pctldev;
284 *outrange = range;
285 mutex_unlock(&pinctrldev_list_mutex);
286 return 0;
287 }
288 }
289 mutex_unlock(&pinctrldev_list_mutex);
290
291 return -EINVAL;
292}
293
294/**
295 * pinctrl_add_gpio_range() - register a GPIO range for a controller
296 * @pctldev: pin controller device to add the range to
297 * @range: the GPIO range to add
298 *
299 * This adds a range of GPIOs to be handled by a certain pin controller. Call
300 * this to register handled ranges after registering your pin controller.
301 */
302void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,
303 struct pinctrl_gpio_range *range)
304{
305 mutex_lock(&pctldev->gpio_ranges_lock);
Stephen Warren8b9c1392012-02-19 23:45:42 -0700306 list_add_tail(&range->node, &pctldev->gpio_ranges);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200307 mutex_unlock(&pctldev->gpio_ranges_lock);
308}
Stephen Warren4ecce45d2012-02-19 23:45:47 -0700309EXPORT_SYMBOL_GPL(pinctrl_add_gpio_range);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200310
311/**
312 * pinctrl_remove_gpio_range() - remove a range of GPIOs fro a pin controller
313 * @pctldev: pin controller device to remove the range from
314 * @range: the GPIO range to remove
315 */
316void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev,
317 struct pinctrl_gpio_range *range)
318{
319 mutex_lock(&pctldev->gpio_ranges_lock);
320 list_del(&range->node);
321 mutex_unlock(&pctldev->gpio_ranges_lock);
322}
Stephen Warren4ecce45d2012-02-19 23:45:47 -0700323EXPORT_SYMBOL_GPL(pinctrl_remove_gpio_range);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200324
Linus Walleij7afde8b2011-10-19 17:07:16 +0200325/**
326 * pinctrl_get_group_selector() - returns the group selector for a group
327 * @pctldev: the pin controller handling the group
328 * @pin_group: the pin group to look up
329 */
330int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
331 const char *pin_group)
332{
333 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
334 unsigned group_selector = 0;
335
336 while (pctlops->list_groups(pctldev, group_selector) >= 0) {
337 const char *gname = pctlops->get_group_name(pctldev,
338 group_selector);
339 if (!strcmp(gname, pin_group)) {
Stephen Warren51cd24e2011-12-09 16:59:05 -0700340 dev_dbg(pctldev->dev,
Linus Walleij7afde8b2011-10-19 17:07:16 +0200341 "found group selector %u for %s\n",
342 group_selector,
343 pin_group);
344 return group_selector;
345 }
346
347 group_selector++;
348 }
349
Stephen Warren51cd24e2011-12-09 16:59:05 -0700350 dev_err(pctldev->dev, "does not have pin group %s\n",
Linus Walleij7afde8b2011-10-19 17:07:16 +0200351 pin_group);
352
353 return -EINVAL;
354}
355
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100356/**
357 * pinctrl_request_gpio() - request a single pin to be used in as GPIO
358 * @gpio: the GPIO pin number from the GPIO subsystem number space
359 *
360 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
361 * as part of their gpio_request() semantics, platforms and individual drivers
362 * shall *NOT* request GPIO pins to be muxed in.
363 */
364int pinctrl_request_gpio(unsigned gpio)
365{
366 struct pinctrl_dev *pctldev;
367 struct pinctrl_gpio_range *range;
368 int ret;
369 int pin;
370
371 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
372 if (ret)
373 return -EINVAL;
374
375 /* Convert to the pin controllers number space */
376 pin = gpio - range->base + range->pin_base;
377
378 return pinmux_request_gpio(pctldev, range, pin, gpio);
379}
380EXPORT_SYMBOL_GPL(pinctrl_request_gpio);
381
382/**
383 * pinctrl_free_gpio() - free control on a single pin, currently used as GPIO
384 * @gpio: the GPIO pin number from the GPIO subsystem number space
385 *
386 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
387 * as part of their gpio_free() semantics, platforms and individual drivers
388 * shall *NOT* request GPIO pins to be muxed out.
389 */
390void pinctrl_free_gpio(unsigned gpio)
391{
392 struct pinctrl_dev *pctldev;
393 struct pinctrl_gpio_range *range;
394 int ret;
395 int pin;
396
397 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
398 if (ret)
399 return;
400
401 /* Convert to the pin controllers number space */
402 pin = gpio - range->base + range->pin_base;
403
404 return pinmux_free_gpio(pctldev, pin, range);
405}
406EXPORT_SYMBOL_GPL(pinctrl_free_gpio);
407
408static int pinctrl_gpio_direction(unsigned gpio, bool input)
409{
410 struct pinctrl_dev *pctldev;
411 struct pinctrl_gpio_range *range;
412 int ret;
413 int pin;
414
415 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
416 if (ret)
417 return ret;
418
419 /* Convert to the pin controllers number space */
420 pin = gpio - range->base + range->pin_base;
421
422 return pinmux_gpio_direction(pctldev, range, pin, input);
423}
424
425/**
426 * pinctrl_gpio_direction_input() - request a GPIO pin to go into input mode
427 * @gpio: the GPIO pin number from the GPIO subsystem number space
428 *
429 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
430 * as part of their gpio_direction_input() semantics, platforms and individual
431 * drivers shall *NOT* touch pin control GPIO calls.
432 */
433int pinctrl_gpio_direction_input(unsigned gpio)
434{
435 return pinctrl_gpio_direction(gpio, true);
436}
437EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input);
438
439/**
440 * pinctrl_gpio_direction_output() - request a GPIO pin to go into output mode
441 * @gpio: the GPIO pin number from the GPIO subsystem number space
442 *
443 * This function should *ONLY* be used from gpiolib-based GPIO drivers,
444 * as part of their gpio_direction_output() semantics, platforms and individual
445 * drivers shall *NOT* touch pin control GPIO calls.
446 */
447int pinctrl_gpio_direction_output(unsigned gpio)
448{
449 return pinctrl_gpio_direction(gpio, false);
450}
451EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);
452
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700453static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100454{
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100455 struct pinctrl_dev *pctldev = NULL;
Stephen Warren1681f5a2012-02-22 14:25:58 -0700456 const char *devname;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100457 struct pinctrl *p;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100458 unsigned num_maps = 0;
459 int ret = -ENODEV;
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700460 struct pinctrl_maps *maps_node;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100461 int i;
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700462 struct pinctrl_map const *map;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100463
Stephen Warren1681f5a2012-02-22 14:25:58 -0700464 /* We must have a dev name */
465 if (WARN_ON(!dev))
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100466 return ERR_PTR(-EINVAL);
467
Stephen Warren1681f5a2012-02-22 14:25:58 -0700468 devname = dev_name(dev);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100469
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700470 dev_dbg(dev, "pinctrl_get() for device %s state %s\n", devname, name);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100471
472 /*
473 * create the state cookie holder struct pinctrl for each
474 * mapping, this is what consumers will get when requesting
475 * a pin control handle with pinctrl_get()
476 */
Stephen Warren02f5b982012-02-22 14:26:00 -0700477 p = kzalloc(sizeof(*p), GFP_KERNEL);
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700478 if (p == NULL) {
479 dev_err(dev, "failed to alloc struct pinctrl\n");
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100480 return ERR_PTR(-ENOMEM);
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700481 }
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100482 mutex_init(&p->mutex);
483 pinmux_init_pinctrl_handle(p);
484
485 /* Iterate over the pin control maps to locate the right ones */
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700486 for_each_maps(maps_node, i, map) {
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100487 /*
488 * First, try to find the pctldev given in the map
489 */
490 pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name);
491 if (!pctldev) {
Stephen Warrenb1eed4e2012-02-19 23:45:53 -0700492 dev_err(dev, "unknown pinctrl device %s in map entry",
493 map->ctrl_dev_name);
494 pinmux_put(p);
495 kfree(p);
496 /* Eventually, this should trigger deferred probe */
497 return ERR_PTR(-ENODEV);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100498 }
499
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700500 dev_dbg(dev, "in map, found pctldev %s to handle function %s",
501 dev_name(pctldev->dev), map->function);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100502
Stephen Warren1681f5a2012-02-22 14:25:58 -0700503 /* Map must be for this device */
504 if (strcmp(map->dev_name, devname))
505 continue;
506
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100507 /*
508 * If we're looking for a specific named map, this must match,
509 * else we loop and look for the next.
510 */
511 if (name != NULL) {
512 if (map->name == NULL)
513 continue;
514 if (strcmp(map->name, name))
515 continue;
516 }
517
Stephen Warren1681f5a2012-02-22 14:25:58 -0700518 ret = pinmux_apply_muxmap(pctldev, p, dev, devname, map);
519 if (ret) {
520 kfree(p);
521 return ERR_PTR(ret);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100522 }
Stephen Warren1681f5a2012-02-22 14:25:58 -0700523 num_maps++;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100524 }
525
Stephen Warrenf026fe32012-02-19 23:45:51 -0700526 /*
527 * This may be perfectly legitimate. An IP block may get re-used
528 * across SoCs. Not all of those SoCs may need pinmux settings for the
529 * IP block, e.g. if one SoC dedicates pins to that function but
530 * another doesn't. The driver won't know this, and will always
531 * attempt to set up the pinmux. The mapping table defines whether any
532 * HW programming is actually needed.
533 */
534 if (!num_maps)
535 dev_info(dev, "zero maps found for mapping %s\n", name);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100536
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700537 dev_dbg(dev, "found %u maps for device %s state %s\n",
538 num_maps, devname, name ? name : "(undefined)");
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100539
540 /* Add the pinmux to the global list */
541 mutex_lock(&pinctrl_list_mutex);
Stephen Warren8b9c1392012-02-19 23:45:42 -0700542 list_add_tail(&p->node, &pinctrl_list);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100543 mutex_unlock(&pinctrl_list_mutex);
544
545 return p;
546}
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700547
548/**
549 * pinctrl_get() - retrieves the pin controller handle for a certain device
550 * @dev: the device to get the pin controller handle for
551 * @name: an optional specific control mapping name or NULL, the name is only
552 * needed if you want to have more than one mapping per device, or if you
553 * need an anonymous pin control (not tied to any specific device)
554 */
555struct pinctrl *pinctrl_get(struct device *dev, const char *name)
556{
557 struct pinctrl *p;
558
559 mutex_lock(&pinctrl_maps_mutex);
560 p = pinctrl_get_locked(dev, name);
561 mutex_unlock(&pinctrl_maps_mutex);
562
563 return p;
564}
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100565EXPORT_SYMBOL_GPL(pinctrl_get);
566
567/**
568 * pinctrl_put() - release a previously claimed pin control handle
569 * @p: a pin control handle previously claimed by pinctrl_get()
570 */
571void pinctrl_put(struct pinctrl *p)
572{
573 if (p == NULL)
574 return;
575
576 mutex_lock(&p->mutex);
577 if (p->usecount)
578 pr_warn("releasing pin control handle with active users!\n");
579 /* Free the groups and all acquired pins */
580 pinmux_put(p);
581 mutex_unlock(&p->mutex);
582
583 /* Remove from list */
584 mutex_lock(&pinctrl_list_mutex);
585 list_del(&p->node);
586 mutex_unlock(&pinctrl_list_mutex);
587
588 kfree(p);
589}
590EXPORT_SYMBOL_GPL(pinctrl_put);
591
592/**
593 * pinctrl_enable() - enable a certain pin controller setting
594 * @p: the pin control handle to enable, previously claimed by pinctrl_get()
595 */
596int pinctrl_enable(struct pinctrl *p)
597{
598 int ret = 0;
599
600 if (p == NULL)
601 return -EINVAL;
602 mutex_lock(&p->mutex);
603 if (p->usecount++ == 0) {
604 ret = pinmux_enable(p);
605 if (ret)
606 p->usecount--;
607 }
608 mutex_unlock(&p->mutex);
609 return ret;
610}
611EXPORT_SYMBOL_GPL(pinctrl_enable);
612
613/**
614 * pinctrl_disable() - disable a certain pin control setting
615 * @p: the pin control handle to disable, previously claimed by pinctrl_get()
616 */
617void pinctrl_disable(struct pinctrl *p)
618{
619 if (p == NULL)
620 return;
621
622 mutex_lock(&p->mutex);
623 if (--p->usecount == 0) {
624 pinmux_disable(p);
625 }
626 mutex_unlock(&p->mutex);
627}
628EXPORT_SYMBOL_GPL(pinctrl_disable);
629
630/**
631 * pinctrl_register_mappings() - register a set of pin controller mappings
Stephen Warren13398a42012-02-19 23:45:41 -0700632 * @maps: the pincontrol mappings table to register. This should probably be
633 * marked with __initdata so it can be discarded after boot. This
634 * function will perform a shallow copy for the mapping entries.
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100635 * @num_maps: the number of maps in the mapping table
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100636 */
Stephen Warren13398a42012-02-19 23:45:41 -0700637int pinctrl_register_mappings(struct pinctrl_map const *maps,
638 unsigned num_maps)
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100639{
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100640 int i;
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700641 struct pinctrl_maps *maps_node;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100642
643 pr_debug("add %d pinmux maps\n", num_maps);
644
645 /* First sanity check the new mapping */
646 for (i = 0; i < num_maps; i++) {
647 if (!maps[i].name) {
648 pr_err("failed to register map %d: no map name given\n",
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700649 i);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100650 return -EINVAL;
651 }
652
653 if (!maps[i].ctrl_dev_name) {
654 pr_err("failed to register map %s (%d): no pin control device given\n",
655 maps[i].name, i);
656 return -EINVAL;
657 }
658
659 if (!maps[i].function) {
660 pr_err("failed to register map %s (%d): no function ID given\n",
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700661 maps[i].name, i);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100662 return -EINVAL;
663 }
664
Stephen Warren1681f5a2012-02-22 14:25:58 -0700665 if (!maps[i].dev_name) {
666 pr_err("failed to register map %s (%d): no device given\n",
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700667 maps[i].name, i);
Stephen Warren1681f5a2012-02-22 14:25:58 -0700668 return -EINVAL;
669 }
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100670 }
671
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700672 maps_node = kzalloc(sizeof(*maps_node), GFP_KERNEL);
673 if (!maps_node) {
674 pr_err("failed to alloc struct pinctrl_maps\n");
675 return -ENOMEM;
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100676 }
677
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700678 maps_node->num_maps = num_maps;
679 maps_node->maps = kmemdup(maps, sizeof(*maps) * num_maps, GFP_KERNEL);
680 if (!maps_node->maps) {
Stephen Warren95dcd4a2012-02-22 14:25:59 -0700681 pr_err("failed to duplicate mapping table\n");
Stephen Warrenb2b3e662012-02-19 23:45:43 -0700682 kfree(maps_node);
683 return -ENOMEM;
684 }
685
686 mutex_lock(&pinctrl_maps_mutex);
687 list_add_tail(&maps_node->node, &pinctrl_maps);
688 mutex_unlock(&pinctrl_maps_mutex);
689
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100690 return 0;
691}
692
Linus Walleij2744e8a2011-05-02 20:50:54 +0200693#ifdef CONFIG_DEBUG_FS
694
695static int pinctrl_pins_show(struct seq_file *s, void *what)
696{
697 struct pinctrl_dev *pctldev = s->private;
698 const struct pinctrl_ops *ops = pctldev->desc->pctlops;
Chanho Park706e8522012-01-03 16:47:50 +0900699 unsigned i, pin;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200700
701 seq_printf(s, "registered pins: %d\n", pctldev->desc->npins);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200702
Chanho Park706e8522012-01-03 16:47:50 +0900703 /* The pin number can be retrived from the pin controller descriptor */
704 for (i = 0; i < pctldev->desc->npins; i++) {
Linus Walleij2744e8a2011-05-02 20:50:54 +0200705 struct pin_desc *desc;
706
Chanho Park706e8522012-01-03 16:47:50 +0900707 pin = pctldev->desc->pins[i].number;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200708 desc = pin_desc_get(pctldev, pin);
709 /* Pin space may be sparse */
710 if (desc == NULL)
711 continue;
712
713 seq_printf(s, "pin %d (%s) ", pin,
714 desc->name ? desc->name : "unnamed");
715
716 /* Driver-specific info per pin */
717 if (ops->pin_dbg_show)
718 ops->pin_dbg_show(pctldev, s, pin);
719
720 seq_puts(s, "\n");
721 }
722
723 return 0;
724}
725
726static int pinctrl_groups_show(struct seq_file *s, void *what)
727{
728 struct pinctrl_dev *pctldev = s->private;
729 const struct pinctrl_ops *ops = pctldev->desc->pctlops;
730 unsigned selector = 0;
731
732 /* No grouping */
733 if (!ops)
734 return 0;
735
736 seq_puts(s, "registered pin groups:\n");
737 while (ops->list_groups(pctldev, selector) >= 0) {
Stephen Warrena5818a82011-10-19 16:19:25 -0600738 const unsigned *pins;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200739 unsigned num_pins;
740 const char *gname = ops->get_group_name(pctldev, selector);
741 int ret;
742 int i;
743
744 ret = ops->get_group_pins(pctldev, selector,
745 &pins, &num_pins);
746 if (ret)
747 seq_printf(s, "%s [ERROR GETTING PINS]\n",
748 gname);
749 else {
750 seq_printf(s, "group: %s, pins = [ ", gname);
751 for (i = 0; i < num_pins; i++)
752 seq_printf(s, "%d ", pins[i]);
753 seq_puts(s, "]\n");
754 }
755 selector++;
756 }
757
758
759 return 0;
760}
761
762static int pinctrl_gpioranges_show(struct seq_file *s, void *what)
763{
764 struct pinctrl_dev *pctldev = s->private;
765 struct pinctrl_gpio_range *range = NULL;
766
767 seq_puts(s, "GPIO ranges handled:\n");
768
769 /* Loop over the ranges */
770 mutex_lock(&pctldev->gpio_ranges_lock);
771 list_for_each_entry(range, &pctldev->gpio_ranges, node) {
Linus Walleij75d66422011-11-16 09:58:51 +0100772 seq_printf(s, "%u: %s GPIOS [%u - %u] PINS [%u - %u]\n",
773 range->id, range->name,
774 range->base, (range->base + range->npins - 1),
775 range->pin_base,
776 (range->pin_base + range->npins - 1));
Linus Walleij2744e8a2011-05-02 20:50:54 +0200777 }
778 mutex_unlock(&pctldev->gpio_ranges_lock);
779
780 return 0;
781}
782
783static int pinctrl_devices_show(struct seq_file *s, void *what)
784{
785 struct pinctrl_dev *pctldev;
786
Linus Walleijae6b4d82011-10-19 18:14:33 +0200787 seq_puts(s, "name [pinmux] [pinconf]\n");
Linus Walleij2744e8a2011-05-02 20:50:54 +0200788 mutex_lock(&pinctrldev_list_mutex);
789 list_for_each_entry(pctldev, &pinctrldev_list, node) {
790 seq_printf(s, "%s ", pctldev->desc->name);
791 if (pctldev->desc->pmxops)
Linus Walleijae6b4d82011-10-19 18:14:33 +0200792 seq_puts(s, "yes ");
793 else
794 seq_puts(s, "no ");
795 if (pctldev->desc->confops)
Linus Walleij2744e8a2011-05-02 20:50:54 +0200796 seq_puts(s, "yes");
797 else
798 seq_puts(s, "no");
799 seq_puts(s, "\n");
800 }
801 mutex_unlock(&pinctrldev_list_mutex);
802
803 return 0;
804}
805
Stephen Warren3eedb432012-02-23 17:04:40 -0700806static int pinctrl_maps_show(struct seq_file *s, void *what)
807{
808 struct pinctrl_maps *maps_node;
809 int i;
810 struct pinctrl_map const *map;
811
812 seq_puts(s, "Pinctrl maps:\n");
813
814 mutex_lock(&pinctrl_maps_mutex);
815 for_each_maps(maps_node, i, map) {
816 seq_printf(s, "%s:\n", map->name);
817 seq_printf(s, " device: %s\n", map->dev_name);
818 seq_printf(s, " controlling device %s\n", map->ctrl_dev_name);
819 seq_printf(s, " function: %s\n", map->function);
820 seq_printf(s, " group: %s\n", map->group ? map->group :
821 "(default)");
822 }
823 mutex_unlock(&pinctrl_maps_mutex);
824
825 return 0;
826}
827
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100828static int pinctrl_show(struct seq_file *s, void *what)
829{
830 struct pinctrl *p;
831
832 seq_puts(s, "Requested pin control handlers their pinmux maps:\n");
833 list_for_each_entry(p, &pinctrl_list, node) {
834 struct pinctrl_dev *pctldev = p->pctldev;
835
836 if (!pctldev) {
837 seq_puts(s, "NO PIN CONTROLLER DEVICE\n");
838 continue;
839 }
840
841 seq_printf(s, "device: %s",
842 pinctrl_dev_get_name(p->pctldev));
843
844 pinmux_dbg_show(s, p);
845
846 seq_printf(s, " users: %u map-> %s\n",
847 p->usecount,
848 p->dev ? dev_name(p->dev) : "(system)");
849 }
850
851 return 0;
852}
853
Linus Walleij2744e8a2011-05-02 20:50:54 +0200854static int pinctrl_pins_open(struct inode *inode, struct file *file)
855{
856 return single_open(file, pinctrl_pins_show, inode->i_private);
857}
858
859static int pinctrl_groups_open(struct inode *inode, struct file *file)
860{
861 return single_open(file, pinctrl_groups_show, inode->i_private);
862}
863
864static int pinctrl_gpioranges_open(struct inode *inode, struct file *file)
865{
866 return single_open(file, pinctrl_gpioranges_show, inode->i_private);
867}
868
869static int pinctrl_devices_open(struct inode *inode, struct file *file)
870{
871 return single_open(file, pinctrl_devices_show, NULL);
872}
873
Stephen Warren3eedb432012-02-23 17:04:40 -0700874static int pinctrl_maps_open(struct inode *inode, struct file *file)
875{
876 return single_open(file, pinctrl_maps_show, NULL);
877}
878
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100879static int pinctrl_open(struct inode *inode, struct file *file)
880{
881 return single_open(file, pinctrl_show, NULL);
882}
883
Linus Walleij2744e8a2011-05-02 20:50:54 +0200884static const struct file_operations pinctrl_pins_ops = {
885 .open = pinctrl_pins_open,
886 .read = seq_read,
887 .llseek = seq_lseek,
888 .release = single_release,
889};
890
891static const struct file_operations pinctrl_groups_ops = {
892 .open = pinctrl_groups_open,
893 .read = seq_read,
894 .llseek = seq_lseek,
895 .release = single_release,
896};
897
898static const struct file_operations pinctrl_gpioranges_ops = {
899 .open = pinctrl_gpioranges_open,
900 .read = seq_read,
901 .llseek = seq_lseek,
902 .release = single_release,
903};
904
905static const struct file_operations pinctrl_devices_ops = {
906 .open = pinctrl_devices_open,
907 .read = seq_read,
908 .llseek = seq_lseek,
909 .release = single_release,
910};
911
Stephen Warren3eedb432012-02-23 17:04:40 -0700912static const struct file_operations pinctrl_maps_ops = {
913 .open = pinctrl_maps_open,
914 .read = seq_read,
915 .llseek = seq_lseek,
916 .release = single_release,
917};
918
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100919static const struct file_operations pinctrl_ops = {
920 .open = pinctrl_open,
921 .read = seq_read,
922 .llseek = seq_lseek,
923 .release = single_release,
924};
925
Linus Walleij2744e8a2011-05-02 20:50:54 +0200926static struct dentry *debugfs_root;
927
928static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)
929{
Tony Lindgren02157162012-01-20 08:17:22 -0800930 struct dentry *device_root;
Linus Walleij2744e8a2011-05-02 20:50:54 +0200931
Stephen Warren51cd24e2011-12-09 16:59:05 -0700932 device_root = debugfs_create_dir(dev_name(pctldev->dev),
Linus Walleij2744e8a2011-05-02 20:50:54 +0200933 debugfs_root);
Tony Lindgren02157162012-01-20 08:17:22 -0800934 pctldev->device_root = device_root;
935
Linus Walleij2744e8a2011-05-02 20:50:54 +0200936 if (IS_ERR(device_root) || !device_root) {
937 pr_warn("failed to create debugfs directory for %s\n",
Stephen Warren51cd24e2011-12-09 16:59:05 -0700938 dev_name(pctldev->dev));
Linus Walleij2744e8a2011-05-02 20:50:54 +0200939 return;
940 }
941 debugfs_create_file("pins", S_IFREG | S_IRUGO,
942 device_root, pctldev, &pinctrl_pins_ops);
943 debugfs_create_file("pingroups", S_IFREG | S_IRUGO,
944 device_root, pctldev, &pinctrl_groups_ops);
945 debugfs_create_file("gpio-ranges", S_IFREG | S_IRUGO,
946 device_root, pctldev, &pinctrl_gpioranges_ops);
947 pinmux_init_device_debugfs(device_root, pctldev);
Linus Walleijae6b4d82011-10-19 18:14:33 +0200948 pinconf_init_device_debugfs(device_root, pctldev);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200949}
950
Tony Lindgren02157162012-01-20 08:17:22 -0800951static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev)
952{
953 debugfs_remove_recursive(pctldev->device_root);
954}
955
Linus Walleij2744e8a2011-05-02 20:50:54 +0200956static void pinctrl_init_debugfs(void)
957{
958 debugfs_root = debugfs_create_dir("pinctrl", NULL);
959 if (IS_ERR(debugfs_root) || !debugfs_root) {
960 pr_warn("failed to create debugfs directory\n");
961 debugfs_root = NULL;
962 return;
963 }
964
965 debugfs_create_file("pinctrl-devices", S_IFREG | S_IRUGO,
966 debugfs_root, NULL, &pinctrl_devices_ops);
Stephen Warren3eedb432012-02-23 17:04:40 -0700967 debugfs_create_file("pinctrl-maps", S_IFREG | S_IRUGO,
968 debugfs_root, NULL, &pinctrl_maps_ops);
Linus Walleijbefe5bd2012-02-09 19:47:48 +0100969 debugfs_create_file("pinctrl-handles", S_IFREG | S_IRUGO,
970 debugfs_root, NULL, &pinctrl_ops);
Linus Walleij2744e8a2011-05-02 20:50:54 +0200971}
972
973#else /* CONFIG_DEBUG_FS */
974
975static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)
976{
977}
978
979static void pinctrl_init_debugfs(void)
980{
981}
982
Tony Lindgren02157162012-01-20 08:17:22 -0800983static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev)
984{
985}
986
Linus Walleij2744e8a2011-05-02 20:50:54 +0200987#endif
988
989/**
990 * pinctrl_register() - register a pin controller device
991 * @pctldesc: descriptor for this pin controller
992 * @dev: parent device for this pin controller
993 * @driver_data: private pin controller data for this pin controller
994 */
995struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
996 struct device *dev, void *driver_data)
997{
Linus Walleij2744e8a2011-05-02 20:50:54 +0200998 struct pinctrl_dev *pctldev;
999 int ret;
1000
1001 if (pctldesc == NULL)
1002 return NULL;
1003 if (pctldesc->name == NULL)
1004 return NULL;
1005
Stephen Warren02f5b982012-02-22 14:26:00 -07001006 pctldev = kzalloc(sizeof(*pctldev), GFP_KERNEL);
Stephen Warren95dcd4a2012-02-22 14:25:59 -07001007 if (pctldev == NULL) {
1008 dev_err(dev, "failed to alloc struct pinctrl_dev\n");
Linus Walleij2744e8a2011-05-02 20:50:54 +02001009 return NULL;
Stephen Warren95dcd4a2012-02-22 14:25:59 -07001010 }
Linus Walleij2744e8a2011-05-02 20:50:54 +02001011
1012 /* Initialize pin control device struct */
1013 pctldev->owner = pctldesc->owner;
1014 pctldev->desc = pctldesc;
1015 pctldev->driver_data = driver_data;
1016 INIT_RADIX_TREE(&pctldev->pin_desc_tree, GFP_KERNEL);
Linus Walleij2744e8a2011-05-02 20:50:54 +02001017 INIT_LIST_HEAD(&pctldev->gpio_ranges);
1018 mutex_init(&pctldev->gpio_ranges_lock);
Stephen Warren51cd24e2011-12-09 16:59:05 -07001019 pctldev->dev = dev;
Linus Walleij2744e8a2011-05-02 20:50:54 +02001020
Tony Lindgrenb9130b72012-01-24 16:28:08 -08001021 /* If we're implementing pinmuxing, check the ops for sanity */
1022 if (pctldesc->pmxops) {
1023 ret = pinmux_check_ops(pctldev);
1024 if (ret) {
1025 pr_err("%s pinmux ops lacks necessary functions\n",
1026 pctldesc->name);
1027 goto out_err;
1028 }
1029 }
1030
1031 /* If we're implementing pinconfig, check the ops for sanity */
1032 if (pctldesc->confops) {
1033 ret = pinconf_check_ops(pctldev);
1034 if (ret) {
1035 pr_err("%s pin config ops lacks necessary functions\n",
1036 pctldesc->name);
1037 goto out_err;
1038 }
1039 }
1040
Linus Walleij2744e8a2011-05-02 20:50:54 +02001041 /* Register all the pins */
1042 pr_debug("try to register %d pins on %s...\n",
1043 pctldesc->npins, pctldesc->name);
1044 ret = pinctrl_register_pins(pctldev, pctldesc->pins, pctldesc->npins);
1045 if (ret) {
1046 pr_err("error during pin registration\n");
1047 pinctrl_free_pindescs(pctldev, pctldesc->pins,
1048 pctldesc->npins);
Stephen Warren51cd24e2011-12-09 16:59:05 -07001049 goto out_err;
Linus Walleij2744e8a2011-05-02 20:50:54 +02001050 }
1051
Linus Walleij2744e8a2011-05-02 20:50:54 +02001052 mutex_lock(&pinctrldev_list_mutex);
Stephen Warren8b9c1392012-02-19 23:45:42 -07001053 list_add_tail(&pctldev->node, &pinctrldev_list);
Linus Walleij2744e8a2011-05-02 20:50:54 +02001054 mutex_unlock(&pinctrldev_list_mutex);
Stephen Warren46919ae2012-03-01 18:48:32 -07001055 pctldev->p = pinctrl_get(pctldev->dev, PINCTRL_STATE_DEFAULT);
1056 if (!IS_ERR(pctldev->p))
1057 pinctrl_enable(pctldev->p);
Stephen Warren2304b472012-02-22 14:26:01 -07001058 pinctrl_init_device_debugfs(pctldev);
1059
Linus Walleij2744e8a2011-05-02 20:50:54 +02001060 return pctldev;
1061
Stephen Warren51cd24e2011-12-09 16:59:05 -07001062out_err:
1063 kfree(pctldev);
Linus Walleij2744e8a2011-05-02 20:50:54 +02001064 return NULL;
1065}
1066EXPORT_SYMBOL_GPL(pinctrl_register);
1067
1068/**
1069 * pinctrl_unregister() - unregister pinmux
1070 * @pctldev: pin controller to unregister
1071 *
1072 * Called by pinmux drivers to unregister a pinmux.
1073 */
1074void pinctrl_unregister(struct pinctrl_dev *pctldev)
1075{
1076 if (pctldev == NULL)
1077 return;
1078
Tony Lindgren02157162012-01-20 08:17:22 -08001079 pinctrl_remove_device_debugfs(pctldev);
Stephen Warren46919ae2012-03-01 18:48:32 -07001080 if (!IS_ERR(pctldev->p)) {
1081 pinctrl_disable(pctldev->p);
1082 pinctrl_put(pctldev->p);
1083 }
Linus Walleij2744e8a2011-05-02 20:50:54 +02001084 /* TODO: check that no pinmuxes are still active? */
1085 mutex_lock(&pinctrldev_list_mutex);
1086 list_del(&pctldev->node);
1087 mutex_unlock(&pinctrldev_list_mutex);
1088 /* Destroy descriptor tree */
1089 pinctrl_free_pindescs(pctldev, pctldev->desc->pins,
1090 pctldev->desc->npins);
Stephen Warren51cd24e2011-12-09 16:59:05 -07001091 kfree(pctldev);
Linus Walleij2744e8a2011-05-02 20:50:54 +02001092}
1093EXPORT_SYMBOL_GPL(pinctrl_unregister);
1094
1095static int __init pinctrl_init(void)
1096{
1097 pr_info("initialized pinctrl subsystem\n");
1098 pinctrl_init_debugfs();
1099 return 0;
1100}
1101
1102/* init early since many drivers really need to initialized pinmux early */
1103core_initcall(pinctrl_init);