aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/core.c
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2012-03-02 15:05:44 -0500
committerLinus Walleij <linus.walleij@linaro.org>2012-03-05 05:19:49 -0500
commit57b676f9c1b7cd84397fe5a86c9bd2788ac4bd32 (patch)
treee07d87bba28678aa80d9325a9c48eac0f57a7fe2 /drivers/pinctrl/core.c
parent962bcbc57aa244eeb1176fa2e9f65ac865cca68a (diff)
pinctrl: fix and simplify locking
There are many problems with the current pinctrl locking: struct pinctrl_dev's gpio_ranges_lock isn't effective; pinctrl_match_gpio_range() only holds this lock while searching for a gpio range, but the found range is return and manipulated after releading the lock. This could allow pinctrl_remove_gpio_range() for that range while it is in use, and the caller may very well delete the range after removing it, causing pinctrl code to touch the now-free range object. Solving this requires the introduction of a higher-level lock, at least a lock per pin controller, which both gpio range registration and pinctrl_get()/put() will acquire. There is missing locking on HW programming; pin controllers may pack the configuration for different pins/groups/config options/... into one register, and hence have to read-modify-write the register. This needs to be protected, but currently isn't. Related, a future change will add a "complete" op to the pin controller drivers, the idea being that each state's programming will be programmed into the pinctrl driver followed by the "complete" call, which may e.g. flush a register cache to HW. For this to work, it must not be possible to interleave the pinctrl driver calls for different devices. As above, solving this requires the introduction of a higher-level lock, at least a lock per pin controller, which will be held for the duration of any pinctrl_enable()/disable() call. However, each pinctrl mapping table entry may affect a different pin controller if necessary. Hence, with a per-pin-controller lock, almost any pinctrl API may need to acquire multiple locks, one per controller. To avoid deadlock, these would need to be acquired in the same order in all cases. This is extremely difficult to implement in the case of pinctrl_get(), which doesn't know which pin controllers to lock until it has parsed the entire mapping table, since it contains somewhat arbitrary data. The simplest solution here is to introduce a single lock that covers all pin controllers at once. This will be acquired by all pinctrl APIs. This then makes struct pinctrl's mutex irrelevant, since that single lock will always be held whenever this mutex is currently held. Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl/core.c')
-rw-r--r--drivers/pinctrl/core.c198
1 files changed, 123 insertions, 75 deletions
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 6af6d8d117df..aefc3394db91 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -18,11 +18,8 @@
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/device.h> 19#include <linux/device.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/radix-tree.h>
22#include <linux/err.h> 21#include <linux/err.h>
23#include <linux/list.h> 22#include <linux/list.h>
24#include <linux/mutex.h>
25#include <linux/spinlock.h>
26#include <linux/sysfs.h> 23#include <linux/sysfs.h>
27#include <linux/debugfs.h> 24#include <linux/debugfs.h>
28#include <linux/seq_file.h> 25#include <linux/seq_file.h>
@@ -44,16 +41,16 @@ struct pinctrl_maps {
44 unsigned num_maps; 41 unsigned num_maps;
45}; 42};
46 43
47/* Global list of pin control devices */ 44/* Mutex taken by all entry points */
48static DEFINE_MUTEX(pinctrldev_list_mutex); 45DEFINE_MUTEX(pinctrl_mutex);
46
47/* Global list of pin control devices (struct pinctrl_dev) */
49static LIST_HEAD(pinctrldev_list); 48static LIST_HEAD(pinctrldev_list);
50 49
51/* List of pin controller handles */ 50/* List of pin controller handles (struct pinctrl) */
52static DEFINE_MUTEX(pinctrl_list_mutex);
53static LIST_HEAD(pinctrl_list); 51static LIST_HEAD(pinctrl_list);
54 52
55/* Global pinctrl maps */ 53/* List of pinctrl maps (struct pinctrl_maps) */
56static DEFINE_MUTEX(pinctrl_maps_mutex);
57static LIST_HEAD(pinctrl_maps); 54static LIST_HEAD(pinctrl_maps);
58 55
59#define for_each_maps(_maps_node_, _i_, _map_) \ 56#define for_each_maps(_maps_node_, _i_, _map_) \
@@ -90,7 +87,6 @@ struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *devname)
90 if (!devname) 87 if (!devname)
91 return NULL; 88 return NULL;
92 89
93 mutex_lock(&pinctrldev_list_mutex);
94 list_for_each_entry(pctldev, &pinctrldev_list, node) { 90 list_for_each_entry(pctldev, &pinctrldev_list, node) {
95 if (!strcmp(dev_name(pctldev->dev), devname)) { 91 if (!strcmp(dev_name(pctldev->dev), devname)) {
96 /* Matched on device name */ 92 /* Matched on device name */
@@ -98,7 +94,6 @@ struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *devname)
98 break; 94 break;
99 } 95 }
100 } 96 }
101 mutex_unlock(&pinctrldev_list_mutex);
102 97
103 return found ? pctldev : NULL; 98 return found ? pctldev : NULL;
104} 99}
@@ -143,11 +138,11 @@ bool pin_is_valid(struct pinctrl_dev *pctldev, int pin)
143 if (pin < 0) 138 if (pin < 0)
144 return false; 139 return false;
145 140
141 mutex_lock(&pinctrl_mutex);
146 pindesc = pin_desc_get(pctldev, pin); 142 pindesc = pin_desc_get(pctldev, pin);
147 if (pindesc == NULL) 143 mutex_unlock(&pinctrl_mutex);
148 return false;
149 144
150 return true; 145 return pindesc != NULL;
151} 146}
152EXPORT_SYMBOL_GPL(pin_is_valid); 147EXPORT_SYMBOL_GPL(pin_is_valid);
153 148
@@ -191,8 +186,6 @@ static int pinctrl_register_one_pin(struct pinctrl_dev *pctldev,
191 return -ENOMEM; 186 return -ENOMEM;
192 } 187 }
193 188
194 spin_lock_init(&pindesc->lock);
195
196 /* Set owner */ 189 /* Set owner */
197 pindesc->pctldev = pctldev; 190 pindesc->pctldev = pctldev;
198 191
@@ -243,16 +236,13 @@ pinctrl_match_gpio_range(struct pinctrl_dev *pctldev, unsigned gpio)
243 struct pinctrl_gpio_range *range = NULL; 236 struct pinctrl_gpio_range *range = NULL;
244 237
245 /* Loop over the ranges */ 238 /* Loop over the ranges */
246 mutex_lock(&pctldev->gpio_ranges_lock);
247 list_for_each_entry(range, &pctldev->gpio_ranges, node) { 239 list_for_each_entry(range, &pctldev->gpio_ranges, node) {
248 /* Check if we're in the valid range */ 240 /* Check if we're in the valid range */
249 if (gpio >= range->base && 241 if (gpio >= range->base &&
250 gpio < range->base + range->npins) { 242 gpio < range->base + range->npins) {
251 mutex_unlock(&pctldev->gpio_ranges_lock);
252 return range; 243 return range;
253 } 244 }
254 } 245 }
255 mutex_unlock(&pctldev->gpio_ranges_lock);
256 246
257 return NULL; 247 return NULL;
258} 248}
@@ -274,7 +264,6 @@ static int pinctrl_get_device_gpio_range(unsigned gpio,
274 struct pinctrl_dev *pctldev = NULL; 264 struct pinctrl_dev *pctldev = NULL;
275 265
276 /* Loop over the pin controllers */ 266 /* Loop over the pin controllers */
277 mutex_lock(&pinctrldev_list_mutex);
278 list_for_each_entry(pctldev, &pinctrldev_list, node) { 267 list_for_each_entry(pctldev, &pinctrldev_list, node) {
279 struct pinctrl_gpio_range *range; 268 struct pinctrl_gpio_range *range;
280 269
@@ -282,11 +271,9 @@ static int pinctrl_get_device_gpio_range(unsigned gpio,
282 if (range != NULL) { 271 if (range != NULL) {
283 *outdev = pctldev; 272 *outdev = pctldev;
284 *outrange = range; 273 *outrange = range;
285 mutex_unlock(&pinctrldev_list_mutex);
286 return 0; 274 return 0;
287 } 275 }
288 } 276 }
289 mutex_unlock(&pinctrldev_list_mutex);
290 277
291 return -EINVAL; 278 return -EINVAL;
292} 279}
@@ -302,9 +289,9 @@ static int pinctrl_get_device_gpio_range(unsigned gpio,
302void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev, 289void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,
303 struct pinctrl_gpio_range *range) 290 struct pinctrl_gpio_range *range)
304{ 291{
305 mutex_lock(&pctldev->gpio_ranges_lock); 292 mutex_lock(&pinctrl_mutex);
306 list_add_tail(&range->node, &pctldev->gpio_ranges); 293 list_add_tail(&range->node, &pctldev->gpio_ranges);
307 mutex_unlock(&pctldev->gpio_ranges_lock); 294 mutex_unlock(&pinctrl_mutex);
308} 295}
309EXPORT_SYMBOL_GPL(pinctrl_add_gpio_range); 296EXPORT_SYMBOL_GPL(pinctrl_add_gpio_range);
310 297
@@ -316,9 +303,9 @@ EXPORT_SYMBOL_GPL(pinctrl_add_gpio_range);
316void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev, 303void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev,
317 struct pinctrl_gpio_range *range) 304 struct pinctrl_gpio_range *range)
318{ 305{
319 mutex_lock(&pctldev->gpio_ranges_lock); 306 mutex_lock(&pinctrl_mutex);
320 list_del(&range->node); 307 list_del(&range->node);
321 mutex_unlock(&pctldev->gpio_ranges_lock); 308 mutex_unlock(&pinctrl_mutex);
322} 309}
323EXPORT_SYMBOL_GPL(pinctrl_remove_gpio_range); 310EXPORT_SYMBOL_GPL(pinctrl_remove_gpio_range);
324 311
@@ -368,14 +355,21 @@ int pinctrl_request_gpio(unsigned gpio)
368 int ret; 355 int ret;
369 int pin; 356 int pin;
370 357
358 mutex_lock(&pinctrl_mutex);
359
371 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range); 360 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
372 if (ret) 361 if (ret) {
362 mutex_unlock(&pinctrl_mutex);
373 return -EINVAL; 363 return -EINVAL;
364 }
374 365
375 /* Convert to the pin controllers number space */ 366 /* Convert to the pin controllers number space */
376 pin = gpio - range->base + range->pin_base; 367 pin = gpio - range->base + range->pin_base;
377 368
378 return pinmux_request_gpio(pctldev, range, pin, gpio); 369 ret = pinmux_request_gpio(pctldev, range, pin, gpio);
370
371 mutex_unlock(&pinctrl_mutex);
372 return ret;
379} 373}
380EXPORT_SYMBOL_GPL(pinctrl_request_gpio); 374EXPORT_SYMBOL_GPL(pinctrl_request_gpio);
381 375
@@ -394,14 +388,20 @@ void pinctrl_free_gpio(unsigned gpio)
394 int ret; 388 int ret;
395 int pin; 389 int pin;
396 390
391 mutex_lock(&pinctrl_mutex);
392
397 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range); 393 ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
398 if (ret) 394 if (ret) {
395 mutex_unlock(&pinctrl_mutex);
399 return; 396 return;
397 }
400 398
401 /* Convert to the pin controllers number space */ 399 /* Convert to the pin controllers number space */
402 pin = gpio - range->base + range->pin_base; 400 pin = gpio - range->base + range->pin_base;
403 401
404 return pinmux_free_gpio(pctldev, pin, range); 402 pinmux_free_gpio(pctldev, pin, range);
403
404 mutex_unlock(&pinctrl_mutex);
405} 405}
406EXPORT_SYMBOL_GPL(pinctrl_free_gpio); 406EXPORT_SYMBOL_GPL(pinctrl_free_gpio);
407 407
@@ -432,7 +432,11 @@ static int pinctrl_gpio_direction(unsigned gpio, bool input)
432 */ 432 */
433int pinctrl_gpio_direction_input(unsigned gpio) 433int pinctrl_gpio_direction_input(unsigned gpio)
434{ 434{
435 return pinctrl_gpio_direction(gpio, true); 435 int ret;
436 mutex_lock(&pinctrl_mutex);
437 ret = pinctrl_gpio_direction(gpio, true);
438 mutex_unlock(&pinctrl_mutex);
439 return ret;
436} 440}
437EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input); 441EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input);
438 442
@@ -446,7 +450,11 @@ EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input);
446 */ 450 */
447int pinctrl_gpio_direction_output(unsigned gpio) 451int pinctrl_gpio_direction_output(unsigned gpio)
448{ 452{
449 return pinctrl_gpio_direction(gpio, false); 453 int ret;
454 mutex_lock(&pinctrl_mutex);
455 ret = pinctrl_gpio_direction(gpio, false);
456 mutex_unlock(&pinctrl_mutex);
457 return ret;
450} 458}
451EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output); 459EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);
452 460
@@ -479,7 +487,6 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)
479 dev_err(dev, "failed to alloc struct pinctrl\n"); 487 dev_err(dev, "failed to alloc struct pinctrl\n");
480 return ERR_PTR(-ENOMEM); 488 return ERR_PTR(-ENOMEM);
481 } 489 }
482 mutex_init(&p->mutex);
483 pinmux_init_pinctrl_handle(p); 490 pinmux_init_pinctrl_handle(p);
484 491
485 /* Iterate over the pin control maps to locate the right ones */ 492 /* Iterate over the pin control maps to locate the right ones */
@@ -531,9 +538,7 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)
531 num_maps, devname, name ? name : "(undefined)"); 538 num_maps, devname, name ? name : "(undefined)");
532 539
533 /* Add the pinmux to the global list */ 540 /* Add the pinmux to the global list */
534 mutex_lock(&pinctrl_list_mutex);
535 list_add_tail(&p->node, &pinctrl_list); 541 list_add_tail(&p->node, &pinctrl_list);
536 mutex_unlock(&pinctrl_list_mutex);
537 542
538 return p; 543 return p;
539} 544}
@@ -549,74 +554,91 @@ struct pinctrl *pinctrl_get(struct device *dev, const char *name)
549{ 554{
550 struct pinctrl *p; 555 struct pinctrl *p;
551 556
552 mutex_lock(&pinctrl_maps_mutex); 557 mutex_lock(&pinctrl_mutex);
553 p = pinctrl_get_locked(dev, name); 558 p = pinctrl_get_locked(dev, name);
554 mutex_unlock(&pinctrl_maps_mutex); 559 mutex_unlock(&pinctrl_mutex);
555 560
556 return p; 561 return p;
557} 562}
558EXPORT_SYMBOL_GPL(pinctrl_get); 563EXPORT_SYMBOL_GPL(pinctrl_get);
559 564
560/** 565static void pinctrl_put_locked(struct pinctrl *p)
561 * pinctrl_put() - release a previously claimed pin control handle
562 * @p: a pin control handle previously claimed by pinctrl_get()
563 */
564void pinctrl_put(struct pinctrl *p)
565{ 566{
566 if (p == NULL) 567 if (p == NULL)
567 return; 568 return;
568 569
569 mutex_lock(&p->mutex);
570 if (p->usecount) 570 if (p->usecount)
571 pr_warn("releasing pin control handle with active users!\n"); 571 pr_warn("releasing pin control handle with active users!\n");
572 /* Free the groups and all acquired pins */ 572 /* Free the groups and all acquired pins */
573 pinmux_put(p); 573 pinmux_put(p);
574 mutex_unlock(&p->mutex);
575 574
576 /* Remove from list */ 575 /* Remove from list */
577 mutex_lock(&pinctrl_list_mutex);
578 list_del(&p->node); 576 list_del(&p->node);
579 mutex_unlock(&pinctrl_list_mutex);
580 577
581 kfree(p); 578 kfree(p);
582} 579}
583EXPORT_SYMBOL_GPL(pinctrl_put);
584 580
585/** 581/**
586 * pinctrl_enable() - enable a certain pin controller setting 582 * pinctrl_put() - release a previously claimed pin control handle
587 * @p: the pin control handle to enable, previously claimed by pinctrl_get() 583 * @p: a pin control handle previously claimed by pinctrl_get()
588 */ 584 */
589int pinctrl_enable(struct pinctrl *p) 585void pinctrl_put(struct pinctrl *p)
586{
587 mutex_lock(&pinctrl_mutex);
588 pinctrl_put(p);
589 mutex_unlock(&pinctrl_mutex);
590}
591EXPORT_SYMBOL_GPL(pinctrl_put);
592
593static int pinctrl_enable_locked(struct pinctrl *p)
590{ 594{
591 int ret = 0; 595 int ret = 0;
592 596
593 if (p == NULL) 597 if (p == NULL)
594 return -EINVAL; 598 return -EINVAL;
595 mutex_lock(&p->mutex); 599
596 if (p->usecount++ == 0) { 600 if (p->usecount++ == 0) {
597 ret = pinmux_enable(p); 601 ret = pinmux_enable(p);
598 if (ret) 602 if (ret)
599 p->usecount--; 603 p->usecount--;
600 } 604 }
601 mutex_unlock(&p->mutex); 605
602 return ret; 606 return ret;
603} 607}
604EXPORT_SYMBOL_GPL(pinctrl_enable);
605 608
606/** 609/**
607 * pinctrl_disable() - disable a certain pin control setting 610 * pinctrl_enable() - enable a certain pin controller setting
608 * @p: the pin control handle to disable, previously claimed by pinctrl_get() 611 * @p: the pin control handle to enable, previously claimed by pinctrl_get()
609 */ 612 */
610void pinctrl_disable(struct pinctrl *p) 613int pinctrl_enable(struct pinctrl *p)
614{
615 int ret;
616 mutex_lock(&pinctrl_mutex);
617 ret = pinctrl_enable_locked(p);
618 mutex_unlock(&pinctrl_mutex);
619 return ret;
620}
621EXPORT_SYMBOL_GPL(pinctrl_enable);
622
623static void pinctrl_disable_locked(struct pinctrl *p)
611{ 624{
612 if (p == NULL) 625 if (p == NULL)
613 return; 626 return;
614 627
615 mutex_lock(&p->mutex);
616 if (--p->usecount == 0) { 628 if (--p->usecount == 0) {
617 pinmux_disable(p); 629 pinmux_disable(p);
618 } 630 }
619 mutex_unlock(&p->mutex); 631}
632
633/**
634 * pinctrl_disable() - disable a certain pin control setting
635 * @p: the pin control handle to disable, previously claimed by pinctrl_get()
636 */
637void pinctrl_disable(struct pinctrl *p)
638{
639 mutex_lock(&pinctrl_mutex);
640 pinctrl_disable_locked(p);
641 mutex_unlock(&pinctrl_mutex);
620} 642}
621EXPORT_SYMBOL_GPL(pinctrl_disable); 643EXPORT_SYMBOL_GPL(pinctrl_disable);
622 644
@@ -676,9 +698,9 @@ int pinctrl_register_mappings(struct pinctrl_map const *maps,
676 return -ENOMEM; 698 return -ENOMEM;
677 } 699 }
678 700
679 mutex_lock(&pinctrl_maps_mutex); 701 mutex_lock(&pinctrl_mutex);
680 list_add_tail(&maps_node->node, &pinctrl_maps); 702 list_add_tail(&maps_node->node, &pinctrl_maps);
681 mutex_unlock(&pinctrl_maps_mutex); 703 mutex_unlock(&pinctrl_mutex);
682 704
683 return 0; 705 return 0;
684} 706}
@@ -693,6 +715,8 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
693 715
694 seq_printf(s, "registered pins: %d\n", pctldev->desc->npins); 716 seq_printf(s, "registered pins: %d\n", pctldev->desc->npins);
695 717
718 mutex_lock(&pinctrl_mutex);
719
696 /* The pin number can be retrived from the pin controller descriptor */ 720 /* The pin number can be retrived from the pin controller descriptor */
697 for (i = 0; i < pctldev->desc->npins; i++) { 721 for (i = 0; i < pctldev->desc->npins; i++) {
698 struct pin_desc *desc; 722 struct pin_desc *desc;
@@ -713,6 +737,8 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
713 seq_puts(s, "\n"); 737 seq_puts(s, "\n");
714 } 738 }
715 739
740 mutex_unlock(&pinctrl_mutex);
741
716 return 0; 742 return 0;
717} 743}
718 744
@@ -726,6 +752,8 @@ static int pinctrl_groups_show(struct seq_file *s, void *what)
726 if (!ops) 752 if (!ops)
727 return 0; 753 return 0;
728 754
755 mutex_lock(&pinctrl_mutex);
756
729 seq_puts(s, "registered pin groups:\n"); 757 seq_puts(s, "registered pin groups:\n");
730 while (ops->list_groups(pctldev, selector) >= 0) { 758 while (ops->list_groups(pctldev, selector) >= 0) {
731 const unsigned *pins; 759 const unsigned *pins;
@@ -748,6 +776,7 @@ static int pinctrl_groups_show(struct seq_file *s, void *what)
748 selector++; 776 selector++;
749 } 777 }
750 778
779 mutex_unlock(&pinctrl_mutex);
751 780
752 return 0; 781 return 0;
753} 782}
@@ -759,8 +788,9 @@ static int pinctrl_gpioranges_show(struct seq_file *s, void *what)
759 788
760 seq_puts(s, "GPIO ranges handled:\n"); 789 seq_puts(s, "GPIO ranges handled:\n");
761 790
791 mutex_lock(&pinctrl_mutex);
792
762 /* Loop over the ranges */ 793 /* Loop over the ranges */
763 mutex_lock(&pctldev->gpio_ranges_lock);
764 list_for_each_entry(range, &pctldev->gpio_ranges, node) { 794 list_for_each_entry(range, &pctldev->gpio_ranges, node) {
765 seq_printf(s, "%u: %s GPIOS [%u - %u] PINS [%u - %u]\n", 795 seq_printf(s, "%u: %s GPIOS [%u - %u] PINS [%u - %u]\n",
766 range->id, range->name, 796 range->id, range->name,
@@ -768,7 +798,8 @@ static int pinctrl_gpioranges_show(struct seq_file *s, void *what)
768 range->pin_base, 798 range->pin_base,
769 (range->pin_base + range->npins - 1)); 799 (range->pin_base + range->npins - 1));
770 } 800 }
771 mutex_unlock(&pctldev->gpio_ranges_lock); 801
802 mutex_unlock(&pinctrl_mutex);
772 803
773 return 0; 804 return 0;
774} 805}
@@ -778,7 +809,9 @@ static int pinctrl_devices_show(struct seq_file *s, void *what)
778 struct pinctrl_dev *pctldev; 809 struct pinctrl_dev *pctldev;
779 810
780 seq_puts(s, "name [pinmux] [pinconf]\n"); 811 seq_puts(s, "name [pinmux] [pinconf]\n");
781 mutex_lock(&pinctrldev_list_mutex); 812
813 mutex_lock(&pinctrl_mutex);
814
782 list_for_each_entry(pctldev, &pinctrldev_list, node) { 815 list_for_each_entry(pctldev, &pinctrldev_list, node) {
783 seq_printf(s, "%s ", pctldev->desc->name); 816 seq_printf(s, "%s ", pctldev->desc->name);
784 if (pctldev->desc->pmxops) 817 if (pctldev->desc->pmxops)
@@ -791,7 +824,8 @@ static int pinctrl_devices_show(struct seq_file *s, void *what)
791 seq_puts(s, "no"); 824 seq_puts(s, "no");
792 seq_puts(s, "\n"); 825 seq_puts(s, "\n");
793 } 826 }
794 mutex_unlock(&pinctrldev_list_mutex); 827
828 mutex_unlock(&pinctrl_mutex);
795 829
796 return 0; 830 return 0;
797} 831}
@@ -804,7 +838,8 @@ static int pinctrl_maps_show(struct seq_file *s, void *what)
804 838
805 seq_puts(s, "Pinctrl maps:\n"); 839 seq_puts(s, "Pinctrl maps:\n");
806 840
807 mutex_lock(&pinctrl_maps_mutex); 841 mutex_lock(&pinctrl_mutex);
842
808 for_each_maps(maps_node, i, map) { 843 for_each_maps(maps_node, i, map) {
809 seq_printf(s, "%s:\n", map->name); 844 seq_printf(s, "%s:\n", map->name);
810 seq_printf(s, " device: %s\n", map->dev_name); 845 seq_printf(s, " device: %s\n", map->dev_name);
@@ -813,7 +848,8 @@ static int pinctrl_maps_show(struct seq_file *s, void *what)
813 seq_printf(s, " group: %s\n", map->group ? map->group : 848 seq_printf(s, " group: %s\n", map->group ? map->group :
814 "(default)"); 849 "(default)");
815 } 850 }
816 mutex_unlock(&pinctrl_maps_mutex); 851
852 mutex_unlock(&pinctrl_mutex);
817 853
818 return 0; 854 return 0;
819} 855}
@@ -823,6 +859,9 @@ static int pinctrl_show(struct seq_file *s, void *what)
823 struct pinctrl *p; 859 struct pinctrl *p;
824 860
825 seq_puts(s, "Requested pin control handlers their pinmux maps:\n"); 861 seq_puts(s, "Requested pin control handlers their pinmux maps:\n");
862
863 mutex_lock(&pinctrl_mutex);
864
826 list_for_each_entry(p, &pinctrl_list, node) { 865 list_for_each_entry(p, &pinctrl_list, node) {
827 struct pinctrl_dev *pctldev = p->pctldev; 866 struct pinctrl_dev *pctldev = p->pctldev;
828 867
@@ -841,6 +880,8 @@ static int pinctrl_show(struct seq_file *s, void *what)
841 p->dev ? dev_name(p->dev) : "(system)"); 880 p->dev ? dev_name(p->dev) : "(system)");
842 } 881 }
843 882
883 mutex_unlock(&pinctrl_mutex);
884
844 return 0; 885 return 0;
845} 886}
846 887
@@ -1008,7 +1049,6 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
1008 pctldev->driver_data = driver_data; 1049 pctldev->driver_data = driver_data;
1009 INIT_RADIX_TREE(&pctldev->pin_desc_tree, GFP_KERNEL); 1050 INIT_RADIX_TREE(&pctldev->pin_desc_tree, GFP_KERNEL);
1010 INIT_LIST_HEAD(&pctldev->gpio_ranges); 1051 INIT_LIST_HEAD(&pctldev->gpio_ranges);
1011 mutex_init(&pctldev->gpio_ranges_lock);
1012 pctldev->dev = dev; 1052 pctldev->dev = dev;
1013 1053
1014 /* If we're implementing pinmuxing, check the ops for sanity */ 1054 /* If we're implementing pinmuxing, check the ops for sanity */
@@ -1042,12 +1082,16 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
1042 goto out_err; 1082 goto out_err;
1043 } 1083 }
1044 1084
1045 mutex_lock(&pinctrldev_list_mutex); 1085 mutex_lock(&pinctrl_mutex);
1086
1046 list_add_tail(&pctldev->node, &pinctrldev_list); 1087 list_add_tail(&pctldev->node, &pinctrldev_list);
1047 mutex_unlock(&pinctrldev_list_mutex); 1088
1048 pctldev->p = pinctrl_get(pctldev->dev, PINCTRL_STATE_DEFAULT); 1089 pctldev->p = pinctrl_get_locked(pctldev->dev, PINCTRL_STATE_DEFAULT);
1049 if (!IS_ERR(pctldev->p)) 1090 if (!IS_ERR(pctldev->p))
1050 pinctrl_enable(pctldev->p); 1091 pinctrl_enable_locked(pctldev->p);
1092
1093 mutex_unlock(&pinctrl_mutex);
1094
1051 pinctrl_init_device_debugfs(pctldev); 1095 pinctrl_init_device_debugfs(pctldev);
1052 1096
1053 return pctldev; 1097 return pctldev;
@@ -1070,18 +1114,22 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev)
1070 return; 1114 return;
1071 1115
1072 pinctrl_remove_device_debugfs(pctldev); 1116 pinctrl_remove_device_debugfs(pctldev);
1117
1118 mutex_lock(&pinctrl_mutex);
1119
1073 if (!IS_ERR(pctldev->p)) { 1120 if (!IS_ERR(pctldev->p)) {
1074 pinctrl_disable(pctldev->p); 1121 pinctrl_disable_locked(pctldev->p);
1075 pinctrl_put(pctldev->p); 1122 pinctrl_put_locked(pctldev->p);
1076 } 1123 }
1124
1077 /* TODO: check that no pinmuxes are still active? */ 1125 /* TODO: check that no pinmuxes are still active? */
1078 mutex_lock(&pinctrldev_list_mutex);
1079 list_del(&pctldev->node); 1126 list_del(&pctldev->node);
1080 mutex_unlock(&pinctrldev_list_mutex);
1081 /* Destroy descriptor tree */ 1127 /* Destroy descriptor tree */
1082 pinctrl_free_pindescs(pctldev, pctldev->desc->pins, 1128 pinctrl_free_pindescs(pctldev, pctldev->desc->pins,
1083 pctldev->desc->npins); 1129 pctldev->desc->npins);
1084 kfree(pctldev); 1130 kfree(pctldev);
1131
1132 mutex_unlock(&pinctrl_mutex);
1085} 1133}
1086EXPORT_SYMBOL_GPL(pinctrl_unregister); 1134EXPORT_SYMBOL_GPL(pinctrl_unregister);
1087 1135