diff options
| author | Patrice Chotard <patrice.chotard@st.com> | 2013-04-11 05:01:27 -0400 |
|---|---|---|
| committer | Linus Walleij <linus.walleij@linaro.org> | 2013-04-26 11:01:35 -0400 |
| commit | 42fed7ba44e4e8c1fb27b28ad14490cb1daff3c7 (patch) | |
| tree | 3caafd69ed9807e9a15f14d6c482fa1f1a697a8b /drivers/pinctrl | |
| parent | cb6d315dc36ce56bc017051befa9ac9391300eb9 (diff) | |
pinctrl: move subsystem mutex to pinctrl_dev struct
This mutex avoids deadlock in case of use of multiple pin
controllers. Before this modification, by using a global
mutex, deadlock appeared when, for example, a call to
pinctrl_pins_show() locked the pinctrl_mutex, called the
ops->pin_dbg_show of a particular pin controller. If this
pin controller needs I2C access to retrieve configuration
information and I2C driver is using pinctrl to drive its
pins, a call to pinctrl_select_state() try to lock again
pinctrl_mutex which leads to a deadlock.
Notice that the mutex grab from the two direction functions
was moved into pinctrl_gpio_direction().
For several cases, we can't replace pinctrl_mutex by
pctldev->mutex, because at this stage, pctldev is
not accessible :
- pinctrl_get()/pinctrl_put()
- pinctrl_register_maps()
So add respectively pinctrl_list_mutex and
pinctrl_maps_mutex in order to protect
pinctrl_list and pinctrl_maps list instead.
Reintroduce pinctrldev_list_mutex in
find_pinctrl_by_of_node(),
pinctrl_find_and_add_gpio_range()
pinctrl_request_gpio(), pinctrl_free_gpio(),
pinctrl_gpio_direction(), pinctrl_devices_show(),
pinctrl_register() and pinctrl_unregister() to
protect pinctrldev_list.
Changes v2->v3:
- Fix a missing EXPORT_SYMBOL_GPL() for pinctrl_select_state().
Changes v1->v2:
- pinctrl_select_state_locked() is removed, all lock mechanism
is located inside pinctrl_select_state(). When parsing
the state->setting list, take the per-pin-controller driver
lock. (Patrice).
- Introduce pinctrldev_list_mutex to protect pinctrldev_list
in all functions which parse or modify pictrldev_list.
(Patrice).
- move find_pinctrl_by_of_node() from pinctrl/devicetree.c to
pinctrl/core.c in order to protect pinctrldev_list.
(Patrice).
- Sink mutex:es into some functions and remove some _locked
variants down to where the lists are actually accessed to
make things simpler. (Linus)
- Drop *all* mutexes completely from pinctrl_lookup_state()
and pinctrl_select_state() - no relevant mutex was taken
and it was unclear what this was protecting against. (Linus)
Reported by : Seraphin Bonnaffe <seraphin.bonnaffe@stericsson.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl')
| -rw-r--r-- | drivers/pinctrl/core.c | 265 | ||||
| -rw-r--r-- | drivers/pinctrl/core.h | 6 | ||||
| -rw-r--r-- | drivers/pinctrl/devicetree.c | 15 | ||||
| -rw-r--r-- | drivers/pinctrl/pinconf.c | 46 | ||||
| -rw-r--r-- | drivers/pinctrl/pinmux.c | 8 |
5 files changed, 176 insertions, 164 deletions
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index 8b832ce6a8e3..c3d222ed39a2 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c | |||
| @@ -40,11 +40,17 @@ | |||
| 40 | 40 | ||
| 41 | static bool pinctrl_dummy_state; | 41 | static bool pinctrl_dummy_state; |
| 42 | 42 | ||
| 43 | /* Mutex taken by all entry points */ | 43 | /* Mutex taken to protect pinctrl_list */ |
| 44 | DEFINE_MUTEX(pinctrl_mutex); | 44 | DEFINE_MUTEX(pinctrl_list_mutex); |
| 45 | |||
| 46 | /* Mutex taken to protect pinctrl_maps */ | ||
| 47 | DEFINE_MUTEX(pinctrl_maps_mutex); | ||
| 48 | |||
| 49 | /* Mutex taken to protect pinctrldev_list */ | ||
| 50 | DEFINE_MUTEX(pinctrldev_list_mutex); | ||
| 45 | 51 | ||
| 46 | /* Global list of pin control devices (struct pinctrl_dev) */ | 52 | /* Global list of pin control devices (struct pinctrl_dev) */ |
| 47 | LIST_HEAD(pinctrldev_list); | 53 | static LIST_HEAD(pinctrldev_list); |
| 48 | 54 | ||
| 49 | /* List of pin controller handles (struct pinctrl) */ | 55 | /* List of pin controller handles (struct pinctrl) */ |
| 50 | static LIST_HEAD(pinctrl_list); | 56 | static LIST_HEAD(pinctrl_list); |
| @@ -111,6 +117,23 @@ struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *devname) | |||
| 111 | return found ? pctldev : NULL; | 117 | return found ? pctldev : NULL; |
| 112 | } | 118 | } |
| 113 | 119 | ||
| 120 | struct pinctrl_dev *get_pinctrl_dev_from_of_node(struct device_node *np) | ||
| 121 | { | ||
| 122 | struct pinctrl_dev *pctldev; | ||
| 123 | |||
| 124 | mutex_lock(&pinctrldev_list_mutex); | ||
| 125 | |||
| 126 | list_for_each_entry(pctldev, &pinctrldev_list, node) | ||
| 127 | if (pctldev->dev->of_node == np) { | ||
| 128 | mutex_unlock(&pinctrldev_list_mutex); | ||
| 129 | return pctldev; | ||
| 130 | } | ||
| 131 | |||
| 132 | mutex_lock(&pinctrldev_list_mutex); | ||
| 133 | |||
| 134 | return NULL; | ||
| 135 | } | ||
| 136 | |||
| 114 | /** | 137 | /** |
| 115 | * pin_get_from_name() - look up a pin number from a name | 138 | * pin_get_from_name() - look up a pin number from a name |
| 116 | * @pctldev: the pin control device to lookup the pin on | 139 | * @pctldev: the pin control device to lookup the pin on |
| @@ -170,9 +193,9 @@ bool pin_is_valid(struct pinctrl_dev *pctldev, int pin) | |||
| 170 | if (pin < 0) | 193 | if (pin < 0) |
| 171 | return false; | 194 | return false; |
| 172 | 195 | ||
| 173 | mutex_lock(&pinctrl_mutex); | 196 | mutex_lock(&pctldev->mutex); |
| 174 | pindesc = pin_desc_get(pctldev, pin); | 197 | pindesc = pin_desc_get(pctldev, pin); |
| 175 | mutex_unlock(&pinctrl_mutex); | 198 | mutex_unlock(&pctldev->mutex); |
| 176 | 199 | ||
| 177 | return pindesc != NULL; | 200 | return pindesc != NULL; |
| 178 | } | 201 | } |
| @@ -269,15 +292,17 @@ pinctrl_match_gpio_range(struct pinctrl_dev *pctldev, unsigned gpio) | |||
| 269 | { | 292 | { |
| 270 | struct pinctrl_gpio_range *range = NULL; | 293 | struct pinctrl_gpio_range *range = NULL; |
| 271 | 294 | ||
| 295 | mutex_lock(&pctldev->mutex); | ||
| 272 | /* Loop over the ranges */ | 296 | /* Loop over the ranges */ |
| 273 | list_for_each_entry(range, &pctldev->gpio_ranges, node) { | 297 | list_for_each_entry(range, &pctldev->gpio_ranges, node) { |
| 274 | /* Check if we're in the valid range */ | 298 | /* Check if we're in the valid range */ |
| 275 | if (gpio >= range->base && | 299 | if (gpio >= range->base && |
| 276 | gpio < range->base + range->npins) { | 300 | gpio < range->base + range->npins) { |
| 301 | mutex_unlock(&pctldev->mutex); | ||
| 277 | return range; | 302 | return range; |
| 278 | } | 303 | } |
| 279 | } | 304 | } |
| 280 | 305 | mutex_unlock(&pctldev->mutex); | |
| 281 | return NULL; | 306 | return NULL; |
| 282 | } | 307 | } |
| 283 | 308 | ||
| @@ -361,9 +386,9 @@ static int pinctrl_get_device_gpio_range(unsigned gpio, | |||
| 361 | void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev, | 386 | void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev, |
| 362 | struct pinctrl_gpio_range *range) | 387 | struct pinctrl_gpio_range *range) |
| 363 | { | 388 | { |
| 364 | mutex_lock(&pinctrl_mutex); | 389 | mutex_lock(&pctldev->mutex); |
| 365 | list_add_tail(&range->node, &pctldev->gpio_ranges); | 390 | list_add_tail(&range->node, &pctldev->gpio_ranges); |
| 366 | mutex_unlock(&pinctrl_mutex); | 391 | mutex_unlock(&pctldev->mutex); |
| 367 | } | 392 | } |
| 368 | EXPORT_SYMBOL_GPL(pinctrl_add_gpio_range); | 393 | EXPORT_SYMBOL_GPL(pinctrl_add_gpio_range); |
| 369 | 394 | ||
| @@ -381,17 +406,25 @@ EXPORT_SYMBOL_GPL(pinctrl_add_gpio_ranges); | |||
| 381 | struct pinctrl_dev *pinctrl_find_and_add_gpio_range(const char *devname, | 406 | struct pinctrl_dev *pinctrl_find_and_add_gpio_range(const char *devname, |
| 382 | struct pinctrl_gpio_range *range) | 407 | struct pinctrl_gpio_range *range) |
| 383 | { | 408 | { |
| 384 | struct pinctrl_dev *pctldev = get_pinctrl_dev_from_devname(devname); | 409 | struct pinctrl_dev *pctldev; |
| 410 | |||
| 411 | mutex_lock(&pinctrldev_list_mutex); | ||
| 412 | |||
| 413 | pctldev = get_pinctrl_dev_from_devname(devname); | ||
| 385 | 414 | ||
| 386 | /* | 415 | /* |
| 387 | * If we can't find this device, let's assume that is because | 416 | * If we can't find this device, let's assume that is because |
| 388 | * it has not probed yet, so the driver trying to register this | 417 | * it has not probed yet, so the driver trying to register this |
| 389 | * range need to defer probing. | 418 | * range need to defer probing. |
| 390 | */ | 419 | */ |
| 391 | if (!pctldev) | 420 | if (!pctldev) { |
| 421 | mutex_unlock(&pinctrldev_list_mutex); | ||
| 392 | return ERR_PTR(-EPROBE_DEFER); | 422 | return ERR_PTR(-EPROBE_DEFER); |
| 393 | 423 | } | |
| 394 | pinctrl_add_gpio_range(pctldev, range); | 424 | pinctrl_add_gpio_range(pctldev, range); |
| 425 | |||
| 426 | mutex_unlock(&pinctrldev_list_mutex); | ||
| 427 | |||
| 395 | return pctldev; | 428 | return pctldev; |
| 396 | } | 429 | } |
| 397 | EXPORT_SYMBOL_GPL(pinctrl_find_and_add_gpio_range); | 430 | EXPORT_SYMBOL_GPL(pinctrl_find_and_add_gpio_range); |
| @@ -407,14 +440,17 @@ pinctrl_find_gpio_range_from_pin(struct pinctrl_dev *pctldev, | |||
| 407 | { | 440 | { |
| 408 | struct pinctrl_gpio_range *range = NULL; | 441 | struct pinctrl_gpio_range *range = NULL; |
| 409 | 442 | ||
| 443 | mutex_lock(&pctldev->mutex); | ||
| 410 | /* Loop over the ranges */ | 444 | /* Loop over the ranges */ |
| 411 | list_for_each_entry(range, &pctldev->gpio_ranges, node) { | 445 | list_for_each_entry(range, &pctldev->gpio_ranges, node) { |
| 412 | /* Check if we're in the valid range */ | 446 | /* Check if we're in the valid range */ |
| 413 | if (pin >= range->pin_base && | 447 | if (pin >= range->pin_base && |
| 414 | pin < range->pin_base + range->npins) { | 448 | pin < range->pin_base + range->npins) { |
| 449 | mutex_unlock(&pctldev->mutex); | ||
| 415 | return range; | 450 | return range; |
| 416 | } | 451 | } |
| 417 | } | 452 | } |
| 453 | mutex_unlock(&pctldev->mutex); | ||
| 418 | 454 | ||
| 419 | return NULL; | 455 | return NULL; |
| 420 | } | 456 | } |
| @@ -428,9 +464,9 @@ EXPORT_SYMBOL_GPL(pinctrl_find_gpio_range_from_pin); | |||
| 428 | void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev, | 464 | void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev, |
| 429 | struct pinctrl_gpio_range *range) | 465 | struct pinctrl_gpio_range *range) |
| 430 | { | 466 | { |
| 431 | mutex_lock(&pinctrl_mutex); | 467 | mutex_lock(&pctldev->mutex); |
| 432 | list_del(&range->node); | 468 | list_del(&range->node); |
| 433 | mutex_unlock(&pinctrl_mutex); | 469 | mutex_unlock(&pctldev->mutex); |
| 434 | } | 470 | } |
| 435 | EXPORT_SYMBOL_GPL(pinctrl_remove_gpio_range); | 471 | EXPORT_SYMBOL_GPL(pinctrl_remove_gpio_range); |
| 436 | 472 | ||
| @@ -481,13 +517,13 @@ int pinctrl_request_gpio(unsigned gpio) | |||
| 481 | int ret; | 517 | int ret; |
| 482 | int pin; | 518 | int pin; |
| 483 | 519 | ||
| 484 | mutex_lock(&pinctrl_mutex); | 520 | mutex_lock(&pinctrldev_list_mutex); |
| 485 | 521 | ||
| 486 | ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range); | 522 | ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range); |
| 487 | if (ret) { | 523 | if (ret) { |
| 488 | if (pinctrl_ready_for_gpio_range(gpio)) | 524 | if (pinctrl_ready_for_gpio_range(gpio)) |
| 489 | ret = 0; | 525 | ret = 0; |
| 490 | mutex_unlock(&pinctrl_mutex); | 526 | mutex_unlock(&pinctrldev_list_mutex); |
| 491 | return ret; | 527 | return ret; |
| 492 | } | 528 | } |
| 493 | 529 | ||
| @@ -496,7 +532,7 @@ int pinctrl_request_gpio(unsigned gpio) | |||
| 496 | 532 | ||
| 497 | ret = pinmux_request_gpio(pctldev, range, pin, gpio); | 533 | ret = pinmux_request_gpio(pctldev, range, pin, gpio); |
| 498 | 534 | ||
| 499 | mutex_unlock(&pinctrl_mutex); | 535 | mutex_unlock(&pinctrldev_list_mutex); |
| 500 | return ret; | 536 | return ret; |
| 501 | } | 537 | } |
| 502 | EXPORT_SYMBOL_GPL(pinctrl_request_gpio); | 538 | EXPORT_SYMBOL_GPL(pinctrl_request_gpio); |
| @@ -516,20 +552,22 @@ void pinctrl_free_gpio(unsigned gpio) | |||
| 516 | int ret; | 552 | int ret; |
| 517 | int pin; | 553 | int pin; |
| 518 | 554 | ||
| 519 | mutex_lock(&pinctrl_mutex); | 555 | mutex_lock(&pinctrldev_list_mutex); |
| 520 | 556 | ||
| 521 | ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range); | 557 | ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range); |
| 522 | if (ret) { | 558 | if (ret) { |
| 523 | mutex_unlock(&pinctrl_mutex); | 559 | mutex_unlock(&pinctrldev_list_mutex); |
| 524 | return; | 560 | return; |
| 525 | } | 561 | } |
| 562 | mutex_lock(&pctldev->mutex); | ||
| 526 | 563 | ||
| 527 | /* Convert to the pin controllers number space */ | 564 | /* Convert to the pin controllers number space */ |
| 528 | pin = gpio - range->base + range->pin_base; | 565 | pin = gpio - range->base + range->pin_base; |
| 529 | 566 | ||
| 530 | pinmux_free_gpio(pctldev, pin, range); | 567 | pinmux_free_gpio(pctldev, pin, range); |
| 531 | 568 | ||
| 532 | mutex_unlock(&pinctrl_mutex); | 569 | mutex_unlock(&pctldev->mutex); |
| 570 | mutex_unlock(&pinctrldev_list_mutex); | ||
| 533 | } | 571 | } |
| 534 | EXPORT_SYMBOL_GPL(pinctrl_free_gpio); | 572 | EXPORT_SYMBOL_GPL(pinctrl_free_gpio); |
| 535 | 573 | ||
| @@ -540,14 +578,24 @@ static int pinctrl_gpio_direction(unsigned gpio, bool input) | |||
| 540 | int ret; | 578 | int ret; |
| 541 | int pin; | 579 | int pin; |
| 542 | 580 | ||
| 581 | mutex_lock(&pinctrldev_list_mutex); | ||
| 582 | |||
| 543 | ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range); | 583 | ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range); |
| 544 | if (ret) | 584 | if (ret) { |
| 585 | mutex_unlock(&pinctrldev_list_mutex); | ||
| 545 | return ret; | 586 | return ret; |
| 587 | } | ||
| 588 | |||
| 589 | mutex_lock(&pctldev->mutex); | ||
| 546 | 590 | ||
| 547 | /* Convert to the pin controllers number space */ | 591 | /* Convert to the pin controllers number space */ |
| 548 | pin = gpio - range->base + range->pin_base; | 592 | pin = gpio - range->base + range->pin_base; |
| 593 | ret = pinmux_gpio_direction(pctldev, range, pin, input); | ||
| 594 | |||
| 595 | mutex_unlock(&pctldev->mutex); | ||
| 596 | mutex_unlock(&pinctrldev_list_mutex); | ||
| 549 | 597 | ||
| 550 | return pinmux_gpio_direction(pctldev, range, pin, input); | 598 | return ret; |
| 551 | } | 599 | } |
| 552 | 600 | ||
| 553 | /** | 601 | /** |
| @@ -560,11 +608,7 @@ static int pinctrl_gpio_direction(unsigned gpio, bool input) | |||
| 560 | */ | 608 | */ |
| 561 | int pinctrl_gpio_direction_input(unsigned gpio) | 609 | int pinctrl_gpio_direction_input(unsigned gpio) |
| 562 | { | 610 | { |
| 563 | int ret; | 611 | return pinctrl_gpio_direction(gpio, true); |
| 564 | mutex_lock(&pinctrl_mutex); | ||
| 565 | ret = pinctrl_gpio_direction(gpio, true); | ||
| 566 | mutex_unlock(&pinctrl_mutex); | ||
| 567 | return ret; | ||
| 568 | } | 612 | } |
| 569 | EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input); | 613 | EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input); |
| 570 | 614 | ||
| @@ -578,11 +622,7 @@ EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input); | |||
| 578 | */ | 622 | */ |
| 579 | int pinctrl_gpio_direction_output(unsigned gpio) | 623 | int pinctrl_gpio_direction_output(unsigned gpio) |
| 580 | { | 624 | { |
| 581 | int ret; | 625 | return pinctrl_gpio_direction(gpio, false); |
| 582 | mutex_lock(&pinctrl_mutex); | ||
| 583 | ret = pinctrl_gpio_direction(gpio, false); | ||
| 584 | mutex_unlock(&pinctrl_mutex); | ||
| 585 | return ret; | ||
| 586 | } | 626 | } |
| 587 | EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output); | 627 | EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output); |
| 588 | 628 | ||
| @@ -685,14 +725,18 @@ static struct pinctrl *find_pinctrl(struct device *dev) | |||
| 685 | { | 725 | { |
| 686 | struct pinctrl *p; | 726 | struct pinctrl *p; |
| 687 | 727 | ||
| 728 | mutex_lock(&pinctrl_list_mutex); | ||
| 688 | list_for_each_entry(p, &pinctrl_list, node) | 729 | list_for_each_entry(p, &pinctrl_list, node) |
| 689 | if (p->dev == dev) | 730 | if (p->dev == dev) { |
| 731 | mutex_unlock(&pinctrl_list_mutex); | ||
| 690 | return p; | 732 | return p; |
| 733 | } | ||
| 691 | 734 | ||
| 735 | mutex_unlock(&pinctrl_list_mutex); | ||
| 692 | return NULL; | 736 | return NULL; |
| 693 | } | 737 | } |
| 694 | 738 | ||
| 695 | static void pinctrl_put_locked(struct pinctrl *p, bool inlist); | 739 | static void pinctrl_free(struct pinctrl *p, bool inlist); |
| 696 | 740 | ||
| 697 | static struct pinctrl *create_pinctrl(struct device *dev) | 741 | static struct pinctrl *create_pinctrl(struct device *dev) |
| 698 | { | 742 | { |
| @@ -725,6 +769,7 @@ static struct pinctrl *create_pinctrl(struct device *dev) | |||
| 725 | 769 | ||
| 726 | devname = dev_name(dev); | 770 | devname = dev_name(dev); |
| 727 | 771 | ||
| 772 | mutex_lock(&pinctrl_maps_mutex); | ||
| 728 | /* Iterate over the pin control maps to locate the right ones */ | 773 | /* Iterate over the pin control maps to locate the right ones */ |
| 729 | for_each_maps(maps_node, i, map) { | 774 | for_each_maps(maps_node, i, map) { |
| 730 | /* Map must be for this device */ | 775 | /* Map must be for this device */ |
| @@ -746,13 +791,16 @@ static struct pinctrl *create_pinctrl(struct device *dev) | |||
| 746 | * an -EPROBE_DEFER later, as that is the worst case. | 791 | * an -EPROBE_DEFER later, as that is the worst case. |
| 747 | */ | 792 | */ |
| 748 | if (ret == -EPROBE_DEFER) { | 793 | if (ret == -EPROBE_DEFER) { |
| 749 | pinctrl_put_locked(p, false); | 794 | pinctrl_free(p, false); |
| 795 | mutex_unlock(&pinctrl_maps_mutex); | ||
| 750 | return ERR_PTR(ret); | 796 | return ERR_PTR(ret); |
| 751 | } | 797 | } |
| 752 | } | 798 | } |
| 799 | mutex_unlock(&pinctrl_maps_mutex); | ||
| 800 | |||
| 753 | if (ret < 0) { | 801 | if (ret < 0) { |
| 754 | /* If some other error than deferral occured, return here */ | 802 | /* If some other error than deferral occured, return here */ |
| 755 | pinctrl_put_locked(p, false); | 803 | pinctrl_free(p, false); |
| 756 | return ERR_PTR(ret); | 804 | return ERR_PTR(ret); |
| 757 | } | 805 | } |
| 758 | 806 | ||
| @@ -764,7 +812,11 @@ static struct pinctrl *create_pinctrl(struct device *dev) | |||
| 764 | return p; | 812 | return p; |
| 765 | } | 813 | } |
| 766 | 814 | ||
| 767 | static struct pinctrl *pinctrl_get_locked(struct device *dev) | 815 | /** |
| 816 | * pinctrl_get() - retrieves the pinctrl handle for a device | ||
| 817 | * @dev: the device to obtain the handle for | ||
| 818 | */ | ||
| 819 | struct pinctrl *pinctrl_get(struct device *dev) | ||
| 768 | { | 820 | { |
| 769 | struct pinctrl *p; | 821 | struct pinctrl *p; |
| 770 | 822 | ||
| @@ -785,21 +837,6 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev) | |||
| 785 | 837 | ||
| 786 | return create_pinctrl(dev); | 838 | return create_pinctrl(dev); |
| 787 | } | 839 | } |
| 788 | |||
| 789 | /** | ||
| 790 | * pinctrl_get() - retrieves the pinctrl handle for a device | ||
| 791 | * @dev: the device to obtain the handle for | ||
| 792 | */ | ||
| 793 | struct pinctrl *pinctrl_get(struct device *dev) | ||
| 794 | { | ||
| 795 | struct pinctrl *p; | ||
| 796 | |||
| 797 | mutex_lock(&pinctrl_mutex); | ||
| 798 | p = pinctrl_get_locked(dev); | ||
| 799 | mutex_unlock(&pinctrl_mutex); | ||
| 800 | |||
| 801 | return p; | ||
| 802 | } | ||
| 803 | EXPORT_SYMBOL_GPL(pinctrl_get); | 840 | EXPORT_SYMBOL_GPL(pinctrl_get); |
| 804 | 841 | ||
| 805 | static void pinctrl_free_setting(bool disable_setting, | 842 | static void pinctrl_free_setting(bool disable_setting, |
| @@ -820,11 +857,12 @@ static void pinctrl_free_setting(bool disable_setting, | |||
| 820 | } | 857 | } |
| 821 | } | 858 | } |
| 822 | 859 | ||
| 823 | static void pinctrl_put_locked(struct pinctrl *p, bool inlist) | 860 | static void pinctrl_free(struct pinctrl *p, bool inlist) |
| 824 | { | 861 | { |
| 825 | struct pinctrl_state *state, *n1; | 862 | struct pinctrl_state *state, *n1; |
| 826 | struct pinctrl_setting *setting, *n2; | 863 | struct pinctrl_setting *setting, *n2; |
| 827 | 864 | ||
| 865 | mutex_lock(&pinctrl_list_mutex); | ||
| 828 | list_for_each_entry_safe(state, n1, &p->states, node) { | 866 | list_for_each_entry_safe(state, n1, &p->states, node) { |
| 829 | list_for_each_entry_safe(setting, n2, &state->settings, node) { | 867 | list_for_each_entry_safe(setting, n2, &state->settings, node) { |
| 830 | pinctrl_free_setting(state == p->state, setting); | 868 | pinctrl_free_setting(state == p->state, setting); |
| @@ -840,6 +878,7 @@ static void pinctrl_put_locked(struct pinctrl *p, bool inlist) | |||
| 840 | if (inlist) | 878 | if (inlist) |
| 841 | list_del(&p->node); | 879 | list_del(&p->node); |
| 842 | kfree(p); | 880 | kfree(p); |
| 881 | mutex_unlock(&pinctrl_list_mutex); | ||
| 843 | } | 882 | } |
| 844 | 883 | ||
| 845 | /** | 884 | /** |
| @@ -850,7 +889,7 @@ static void pinctrl_release(struct kref *kref) | |||
| 850 | { | 889 | { |
| 851 | struct pinctrl *p = container_of(kref, struct pinctrl, users); | 890 | struct pinctrl *p = container_of(kref, struct pinctrl, users); |
| 852 | 891 | ||
| 853 | pinctrl_put_locked(p, true); | 892 | pinctrl_free(p, true); |
| 854 | } | 893 | } |
| 855 | 894 | ||
| 856 | /** | 895 | /** |
| @@ -859,14 +898,17 @@ static void pinctrl_release(struct kref *kref) | |||
| 859 | */ | 898 | */ |
| 860 | void pinctrl_put(struct pinctrl *p) | 899 | void pinctrl_put(struct pinctrl *p) |
| 861 | { | 900 | { |
| 862 | mutex_lock(&pinctrl_mutex); | ||
| 863 | kref_put(&p->users, pinctrl_release); | 901 | kref_put(&p->users, pinctrl_release); |
| 864 | mutex_unlock(&pinctrl_mutex); | ||
| 865 | } | 902 | } |
| 866 | EXPORT_SYMBOL_GPL(pinctrl_put); | 903 | EXPORT_SYMBOL_GPL(pinctrl_put); |
| 867 | 904 | ||
| 868 | static struct pinctrl_state *pinctrl_lookup_state_locked(struct pinctrl *p, | 905 | /** |
| 869 | const char *name) | 906 | * pinctrl_lookup_state() - retrieves a state handle from a pinctrl handle |
| 907 | * @p: the pinctrl handle to retrieve the state from | ||
| 908 | * @name: the state name to retrieve | ||
| 909 | */ | ||
| 910 | struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p, | ||
| 911 | const char *name) | ||
| 870 | { | 912 | { |
| 871 | struct pinctrl_state *state; | 913 | struct pinctrl_state *state; |
| 872 | 914 | ||
| @@ -883,26 +925,14 @@ static struct pinctrl_state *pinctrl_lookup_state_locked(struct pinctrl *p, | |||
| 883 | 925 | ||
| 884 | return state; | 926 | return state; |
| 885 | } | 927 | } |
| 928 | EXPORT_SYMBOL_GPL(pinctrl_lookup_state); | ||
| 886 | 929 | ||
| 887 | /** | 930 | /** |
| 888 | * pinctrl_lookup_state() - retrieves a state handle from a pinctrl handle | 931 | * pinctrl_select_state() - select/activate/program a pinctrl state to HW |
| 889 | * @p: the pinctrl handle to retrieve the state from | 932 | * @p: the pinctrl handle for the device that requests configuration |
| 890 | * @name: the state name to retrieve | 933 | * @state: the state handle to select/activate/program |
| 891 | */ | 934 | */ |
| 892 | struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p, const char *name) | 935 | int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state) |
| 893 | { | ||
| 894 | struct pinctrl_state *s; | ||
| 895 | |||
| 896 | mutex_lock(&pinctrl_mutex); | ||
| 897 | s = pinctrl_lookup_state_locked(p, name); | ||
| 898 | mutex_unlock(&pinctrl_mutex); | ||
| 899 | |||
| 900 | return s; | ||
| 901 | } | ||
| 902 | EXPORT_SYMBOL_GPL(pinctrl_lookup_state); | ||
| 903 | |||
| 904 | static int pinctrl_select_state_locked(struct pinctrl *p, | ||
| 905 | struct pinctrl_state *state) | ||
| 906 | { | 936 | { |
| 907 | struct pinctrl_setting *setting, *setting2; | 937 | struct pinctrl_setting *setting, *setting2; |
| 908 | struct pinctrl_state *old_state = p->state; | 938 | struct pinctrl_state *old_state = p->state; |
| @@ -956,8 +986,9 @@ static int pinctrl_select_state_locked(struct pinctrl *p, | |||
| 956 | break; | 986 | break; |
| 957 | } | 987 | } |
| 958 | 988 | ||
| 959 | if (ret < 0) | 989 | if (ret < 0) { |
| 960 | goto unapply_new_state; | 990 | goto unapply_new_state; |
| 991 | } | ||
| 961 | } | 992 | } |
| 962 | 993 | ||
| 963 | p->state = state; | 994 | p->state = state; |
| @@ -983,23 +1014,7 @@ unapply_new_state: | |||
| 983 | 1014 | ||
| 984 | /* There's no infinite recursive loop here because p->state is NULL */ | 1015 | /* There's no infinite recursive loop here because p->state is NULL */ |
| 985 | if (old_state) | 1016 | if (old_state) |
| 986 | pinctrl_select_state_locked(p, old_state); | 1017 | pinctrl_select_state(p, old_state); |
| 987 | |||
| 988 | return ret; | ||
| 989 | } | ||
| 990 | |||
| 991 | /** | ||
| 992 | * pinctrl_select() - select/activate/program a pinctrl state to HW | ||
| 993 | * @p: the pinctrl handle for the device that requests configuratio | ||
| 994 | * @state: the state handle to select/activate/program | ||
| 995 | */ | ||
| 996 | int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state) | ||
| 997 | { | ||
| 998 | int ret; | ||
| 999 | |||
| 1000 | mutex_lock(&pinctrl_mutex); | ||
| 1001 | ret = pinctrl_select_state_locked(p, state); | ||
| 1002 | mutex_unlock(&pinctrl_mutex); | ||
| 1003 | 1018 | ||
| 1004 | return ret; | 1019 | return ret; |
| 1005 | } | 1020 | } |
| @@ -1129,10 +1144,10 @@ int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps, | |||
| 1129 | } | 1144 | } |
| 1130 | 1145 | ||
| 1131 | if (!locked) | 1146 | if (!locked) |
| 1132 | mutex_lock(&pinctrl_mutex); | 1147 | mutex_lock(&pinctrl_maps_mutex); |
| 1133 | list_add_tail(&maps_node->node, &pinctrl_maps); | 1148 | list_add_tail(&maps_node->node, &pinctrl_maps); |
| 1134 | if (!locked) | 1149 | if (!locked) |
| 1135 | mutex_unlock(&pinctrl_mutex); | 1150 | mutex_unlock(&pinctrl_maps_mutex); |
| 1136 | 1151 | ||
| 1137 | return 0; | 1152 | return 0; |
| 1138 | } | 1153 | } |
| @@ -1154,12 +1169,15 @@ void pinctrl_unregister_map(struct pinctrl_map const *map) | |||
| 1154 | { | 1169 | { |
| 1155 | struct pinctrl_maps *maps_node; | 1170 | struct pinctrl_maps *maps_node; |
| 1156 | 1171 | ||
| 1172 | mutex_lock(&pinctrl_maps_mutex); | ||
| 1157 | list_for_each_entry(maps_node, &pinctrl_maps, node) { | 1173 | list_for_each_entry(maps_node, &pinctrl_maps, node) { |
| 1158 | if (maps_node->maps == map) { | 1174 | if (maps_node->maps == map) { |
| 1159 | list_del(&maps_node->node); | 1175 | list_del(&maps_node->node); |
| 1176 | mutex_unlock(&pinctrl_maps_mutex); | ||
| 1160 | return; | 1177 | return; |
| 1161 | } | 1178 | } |
| 1162 | } | 1179 | } |
| 1180 | mutex_unlock(&pinctrl_maps_mutex); | ||
| 1163 | } | 1181 | } |
| 1164 | 1182 | ||
| 1165 | /** | 1183 | /** |
| @@ -1196,7 +1214,7 @@ static int pinctrl_pins_show(struct seq_file *s, void *what) | |||
| 1196 | 1214 | ||
| 1197 | seq_printf(s, "registered pins: %d\n", pctldev->desc->npins); | 1215 | seq_printf(s, "registered pins: %d\n", pctldev->desc->npins); |
| 1198 | 1216 | ||
| 1199 | mutex_lock(&pinctrl_mutex); | 1217 | mutex_lock(&pctldev->mutex); |
| 1200 | 1218 | ||
| 1201 | /* The pin number can be retrived from the pin controller descriptor */ | 1219 | /* The pin number can be retrived from the pin controller descriptor */ |
| 1202 | for (i = 0; i < pctldev->desc->npins; i++) { | 1220 | for (i = 0; i < pctldev->desc->npins; i++) { |
| @@ -1218,7 +1236,7 @@ static int pinctrl_pins_show(struct seq_file *s, void *what) | |||
| 1218 | seq_puts(s, "\n"); | 1236 | seq_puts(s, "\n"); |
| 1219 | } | 1237 | } |
| 1220 | 1238 | ||
| 1221 | mutex_unlock(&pinctrl_mutex); | 1239 | mutex_unlock(&pctldev->mutex); |
| 1222 | 1240 | ||
| 1223 | return 0; | 1241 | return 0; |
| 1224 | } | 1242 | } |
| @@ -1229,8 +1247,9 @@ static int pinctrl_groups_show(struct seq_file *s, void *what) | |||
| 1229 | const struct pinctrl_ops *ops = pctldev->desc->pctlops; | 1247 | const struct pinctrl_ops *ops = pctldev->desc->pctlops; |
| 1230 | unsigned ngroups, selector = 0; | 1248 | unsigned ngroups, selector = 0; |
| 1231 | 1249 | ||
| 1250 | mutex_lock(&pctldev->mutex); | ||
| 1251 | |||
| 1232 | ngroups = ops->get_groups_count(pctldev); | 1252 | ngroups = ops->get_groups_count(pctldev); |
| 1233 | mutex_lock(&pinctrl_mutex); | ||
| 1234 | 1253 | ||
| 1235 | seq_puts(s, "registered pin groups:\n"); | 1254 | seq_puts(s, "registered pin groups:\n"); |
| 1236 | while (selector < ngroups) { | 1255 | while (selector < ngroups) { |
| @@ -1251,7 +1270,7 @@ static int pinctrl_groups_show(struct seq_file *s, void *what) | |||
| 1251 | for (i = 0; i < num_pins; i++) { | 1270 | for (i = 0; i < num_pins; i++) { |
| 1252 | pname = pin_get_name(pctldev, pins[i]); | 1271 | pname = pin_get_name(pctldev, pins[i]); |
| 1253 | if (WARN_ON(!pname)) { | 1272 | if (WARN_ON(!pname)) { |
| 1254 | mutex_unlock(&pinctrl_mutex); | 1273 | mutex_unlock(&pctldev->mutex); |
| 1255 | return -EINVAL; | 1274 | return -EINVAL; |
| 1256 | } | 1275 | } |
| 1257 | seq_printf(s, "pin %d (%s)\n", pins[i], pname); | 1276 | seq_printf(s, "pin %d (%s)\n", pins[i], pname); |
| @@ -1261,7 +1280,7 @@ static int pinctrl_groups_show(struct seq_file *s, void *what) | |||
| 1261 | selector++; | 1280 | selector++; |
| 1262 | } | 1281 | } |
| 1263 | 1282 | ||
| 1264 | mutex_unlock(&pinctrl_mutex); | 1283 | mutex_unlock(&pctldev->mutex); |
| 1265 | 1284 | ||
| 1266 | return 0; | 1285 | return 0; |
| 1267 | } | 1286 | } |
| @@ -1273,7 +1292,7 @@ static int pinctrl_gpioranges_show(struct seq_file *s, void *what) | |||
| 1273 | 1292 | ||
| 1274 | seq_puts(s, "GPIO ranges handled:\n"); | 1293 | seq_puts(s, "GPIO ranges handled:\n"); |
| 1275 | 1294 | ||
| 1276 | mutex_lock(&pinctrl_mutex); | 1295 | mutex_lock(&pctldev->mutex); |
| 1277 | 1296 | ||
| 1278 | /* Loop over the ranges */ | 1297 | /* Loop over the ranges */ |
| 1279 | list_for_each_entry(range, &pctldev->gpio_ranges, node) { | 1298 | list_for_each_entry(range, &pctldev->gpio_ranges, node) { |
| @@ -1284,7 +1303,7 @@ static int pinctrl_gpioranges_show(struct seq_file *s, void *what) | |||
| 1284 | (range->pin_base + range->npins - 1)); | 1303 | (range->pin_base + range->npins - 1)); |
| 1285 | } | 1304 | } |
| 1286 | 1305 | ||
| 1287 | mutex_unlock(&pinctrl_mutex); | 1306 | mutex_unlock(&pctldev->mutex); |
| 1288 | 1307 | ||
| 1289 | return 0; | 1308 | return 0; |
| 1290 | } | 1309 | } |
| @@ -1295,7 +1314,7 @@ static int pinctrl_devices_show(struct seq_file *s, void *what) | |||
| 1295 | 1314 | ||
| 1296 | seq_puts(s, "name [pinmux] [pinconf]\n"); | 1315 | seq_puts(s, "name [pinmux] [pinconf]\n"); |
| 1297 | 1316 | ||
| 1298 | mutex_lock(&pinctrl_mutex); | 1317 | mutex_lock(&pinctrldev_list_mutex); |
| 1299 | 1318 | ||
| 1300 | list_for_each_entry(pctldev, &pinctrldev_list, node) { | 1319 | list_for_each_entry(pctldev, &pinctrldev_list, node) { |
| 1301 | seq_printf(s, "%s ", pctldev->desc->name); | 1320 | seq_printf(s, "%s ", pctldev->desc->name); |
| @@ -1310,7 +1329,7 @@ static int pinctrl_devices_show(struct seq_file *s, void *what) | |||
| 1310 | seq_puts(s, "\n"); | 1329 | seq_puts(s, "\n"); |
| 1311 | } | 1330 | } |
| 1312 | 1331 | ||
| 1313 | mutex_unlock(&pinctrl_mutex); | 1332 | mutex_unlock(&pinctrldev_list_mutex); |
| 1314 | 1333 | ||
| 1315 | return 0; | 1334 | return 0; |
| 1316 | } | 1335 | } |
| @@ -1339,8 +1358,7 @@ static int pinctrl_maps_show(struct seq_file *s, void *what) | |||
| 1339 | 1358 | ||
| 1340 | seq_puts(s, "Pinctrl maps:\n"); | 1359 | seq_puts(s, "Pinctrl maps:\n"); |
| 1341 | 1360 | ||
| 1342 | mutex_lock(&pinctrl_mutex); | 1361 | mutex_lock(&pinctrl_maps_mutex); |
| 1343 | |||
| 1344 | for_each_maps(maps_node, i, map) { | 1362 | for_each_maps(maps_node, i, map) { |
| 1345 | seq_printf(s, "device %s\nstate %s\ntype %s (%d)\n", | 1363 | seq_printf(s, "device %s\nstate %s\ntype %s (%d)\n", |
| 1346 | map->dev_name, map->name, map_type(map->type), | 1364 | map->dev_name, map->name, map_type(map->type), |
| @@ -1364,8 +1382,7 @@ static int pinctrl_maps_show(struct seq_file *s, void *what) | |||
| 1364 | 1382 | ||
| 1365 | seq_printf(s, "\n"); | 1383 | seq_printf(s, "\n"); |
| 1366 | } | 1384 | } |
| 1367 | 1385 | mutex_unlock(&pinctrl_maps_mutex); | |
| 1368 | mutex_unlock(&pinctrl_mutex); | ||
| 1369 | 1386 | ||
| 1370 | return 0; | 1387 | return 0; |
| 1371 | } | 1388 | } |
| @@ -1378,7 +1395,7 @@ static int pinctrl_show(struct seq_file *s, void *what) | |||
| 1378 | 1395 | ||
| 1379 | seq_puts(s, "Requested pin control handlers their pinmux maps:\n"); | 1396 | seq_puts(s, "Requested pin control handlers their pinmux maps:\n"); |
| 1380 | 1397 | ||
| 1381 | mutex_lock(&pinctrl_mutex); | 1398 | mutex_lock(&pinctrl_list_mutex); |
| 1382 | 1399 | ||
| 1383 | list_for_each_entry(p, &pinctrl_list, node) { | 1400 | list_for_each_entry(p, &pinctrl_list, node) { |
| 1384 | seq_printf(s, "device: %s current state: %s\n", | 1401 | seq_printf(s, "device: %s current state: %s\n", |
| @@ -1410,7 +1427,7 @@ static int pinctrl_show(struct seq_file *s, void *what) | |||
| 1410 | } | 1427 | } |
| 1411 | } | 1428 | } |
| 1412 | 1429 | ||
| 1413 | mutex_unlock(&pinctrl_mutex); | 1430 | mutex_unlock(&pinctrl_list_mutex); |
| 1414 | 1431 | ||
| 1415 | return 0; | 1432 | return 0; |
| 1416 | } | 1433 | } |
| @@ -1596,6 +1613,7 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, | |||
| 1596 | INIT_RADIX_TREE(&pctldev->pin_desc_tree, GFP_KERNEL); | 1613 | INIT_RADIX_TREE(&pctldev->pin_desc_tree, GFP_KERNEL); |
| 1597 | INIT_LIST_HEAD(&pctldev->gpio_ranges); | 1614 | INIT_LIST_HEAD(&pctldev->gpio_ranges); |
| 1598 | pctldev->dev = dev; | 1615 | pctldev->dev = dev; |
| 1616 | mutex_init(&pctldev->mutex); | ||
| 1599 | 1617 | ||
| 1600 | /* check core ops for sanity */ | 1618 | /* check core ops for sanity */ |
| 1601 | if (pinctrl_check_ops(pctldev)) { | 1619 | if (pinctrl_check_ops(pctldev)) { |
| @@ -1625,38 +1643,37 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, | |||
| 1625 | goto out_err; | 1643 | goto out_err; |
| 1626 | } | 1644 | } |
| 1627 | 1645 | ||
| 1628 | mutex_lock(&pinctrl_mutex); | 1646 | mutex_lock(&pinctrldev_list_mutex); |
| 1629 | |||
| 1630 | list_add_tail(&pctldev->node, &pinctrldev_list); | 1647 | list_add_tail(&pctldev->node, &pinctrldev_list); |
| 1648 | mutex_unlock(&pinctrldev_list_mutex); | ||
| 1649 | |||
| 1650 | pctldev->p = pinctrl_get(pctldev->dev); | ||
| 1631 | 1651 | ||
| 1632 | pctldev->p = pinctrl_get_locked(pctldev->dev); | ||
| 1633 | if (!IS_ERR(pctldev->p)) { | 1652 | if (!IS_ERR(pctldev->p)) { |
| 1634 | pctldev->hog_default = | 1653 | pctldev->hog_default = |
| 1635 | pinctrl_lookup_state_locked(pctldev->p, | 1654 | pinctrl_lookup_state(pctldev->p, PINCTRL_STATE_DEFAULT); |
| 1636 | PINCTRL_STATE_DEFAULT); | ||
| 1637 | if (IS_ERR(pctldev->hog_default)) { | 1655 | if (IS_ERR(pctldev->hog_default)) { |
| 1638 | dev_dbg(dev, "failed to lookup the default state\n"); | 1656 | dev_dbg(dev, "failed to lookup the default state\n"); |
| 1639 | } else { | 1657 | } else { |
| 1640 | if (pinctrl_select_state_locked(pctldev->p, | 1658 | if (pinctrl_select_state(pctldev->p, |
| 1641 | pctldev->hog_default)) | 1659 | pctldev->hog_default)) |
| 1642 | dev_err(dev, | 1660 | dev_err(dev, |
| 1643 | "failed to select default state\n"); | 1661 | "failed to select default state\n"); |
| 1644 | } | 1662 | } |
| 1645 | 1663 | ||
| 1646 | pctldev->hog_sleep = | 1664 | pctldev->hog_sleep = |
| 1647 | pinctrl_lookup_state_locked(pctldev->p, | 1665 | pinctrl_lookup_state(pctldev->p, |
| 1648 | PINCTRL_STATE_SLEEP); | 1666 | PINCTRL_STATE_SLEEP); |
| 1649 | if (IS_ERR(pctldev->hog_sleep)) | 1667 | if (IS_ERR(pctldev->hog_sleep)) |
| 1650 | dev_dbg(dev, "failed to lookup the sleep state\n"); | 1668 | dev_dbg(dev, "failed to lookup the sleep state\n"); |
| 1651 | } | 1669 | } |
| 1652 | 1670 | ||
| 1653 | mutex_unlock(&pinctrl_mutex); | ||
| 1654 | |||
| 1655 | pinctrl_init_device_debugfs(pctldev); | 1671 | pinctrl_init_device_debugfs(pctldev); |
| 1656 | 1672 | ||
| 1657 | return pctldev; | 1673 | return pctldev; |
| 1658 | 1674 | ||
| 1659 | out_err: | 1675 | out_err: |
| 1676 | mutex_destroy(&pctldev->mutex); | ||
| 1660 | kfree(pctldev); | 1677 | kfree(pctldev); |
| 1661 | return NULL; | 1678 | return NULL; |
| 1662 | } | 1679 | } |
| @@ -1674,12 +1691,13 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev) | |||
| 1674 | if (pctldev == NULL) | 1691 | if (pctldev == NULL) |
| 1675 | return; | 1692 | return; |
| 1676 | 1693 | ||
| 1677 | pinctrl_remove_device_debugfs(pctldev); | 1694 | mutex_lock(&pinctrldev_list_mutex); |
| 1695 | mutex_lock(&pctldev->mutex); | ||
| 1678 | 1696 | ||
| 1679 | mutex_lock(&pinctrl_mutex); | 1697 | pinctrl_remove_device_debugfs(pctldev); |
| 1680 | 1698 | ||
| 1681 | if (!IS_ERR(pctldev->p)) | 1699 | if (!IS_ERR(pctldev->p)) |
| 1682 | pinctrl_put_locked(pctldev->p, true); | 1700 | pinctrl_put(pctldev->p); |
| 1683 | 1701 | ||
| 1684 | /* TODO: check that no pinmuxes are still active? */ | 1702 | /* TODO: check that no pinmuxes are still active? */ |
| 1685 | list_del(&pctldev->node); | 1703 | list_del(&pctldev->node); |
| @@ -1690,9 +1708,10 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev) | |||
| 1690 | list_for_each_entry_safe(range, n, &pctldev->gpio_ranges, node) | 1708 | list_for_each_entry_safe(range, n, &pctldev->gpio_ranges, node) |
| 1691 | list_del(&range->node); | 1709 | list_del(&range->node); |
| 1692 | 1710 | ||
| 1711 | mutex_unlock(&pctldev->mutex); | ||
| 1712 | mutex_destroy(&pctldev->mutex); | ||
| 1693 | kfree(pctldev); | 1713 | kfree(pctldev); |
| 1694 | 1714 | mutex_unlock(&pinctrldev_list_mutex); | |
| 1695 | mutex_unlock(&pinctrl_mutex); | ||
| 1696 | } | 1715 | } |
| 1697 | EXPORT_SYMBOL_GPL(pinctrl_unregister); | 1716 | EXPORT_SYMBOL_GPL(pinctrl_unregister); |
| 1698 | 1717 | ||
diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h index 6d3d40036d1b..75476b3d87da 100644 --- a/drivers/pinctrl/core.h +++ b/drivers/pinctrl/core.h | |||
| @@ -33,6 +33,7 @@ struct pinctrl_gpio_range; | |||
| 33 | * @p: result of pinctrl_get() for this device | 33 | * @p: result of pinctrl_get() for this device |
| 34 | * @hog_default: default state for pins hogged by this device | 34 | * @hog_default: default state for pins hogged by this device |
| 35 | * @hog_sleep: sleep state for pins hogged by this device | 35 | * @hog_sleep: sleep state for pins hogged by this device |
| 36 | * @mutex: mutex taken on each pin controller specific action | ||
| 36 | * @device_root: debugfs root for this device | 37 | * @device_root: debugfs root for this device |
| 37 | */ | 38 | */ |
| 38 | struct pinctrl_dev { | 39 | struct pinctrl_dev { |
| @@ -46,6 +47,7 @@ struct pinctrl_dev { | |||
| 46 | struct pinctrl *p; | 47 | struct pinctrl *p; |
| 47 | struct pinctrl_state *hog_default; | 48 | struct pinctrl_state *hog_default; |
| 48 | struct pinctrl_state *hog_sleep; | 49 | struct pinctrl_state *hog_sleep; |
| 50 | struct mutex mutex; | ||
| 49 | #ifdef CONFIG_DEBUG_FS | 51 | #ifdef CONFIG_DEBUG_FS |
| 50 | struct dentry *device_root; | 52 | struct dentry *device_root; |
| 51 | #endif | 53 | #endif |
| @@ -168,6 +170,7 @@ struct pinctrl_maps { | |||
| 168 | }; | 170 | }; |
| 169 | 171 | ||
| 170 | struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name); | 172 | struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name); |
| 173 | struct pinctrl_dev *get_pinctrl_dev_from_of_node(struct device_node *np); | ||
| 171 | int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name); | 174 | int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name); |
| 172 | const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin); | 175 | const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin); |
| 173 | int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, | 176 | int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, |
| @@ -186,8 +189,7 @@ void pinctrl_unregister_map(struct pinctrl_map const *map); | |||
| 186 | extern int pinctrl_force_sleep(struct pinctrl_dev *pctldev); | 189 | extern int pinctrl_force_sleep(struct pinctrl_dev *pctldev); |
| 187 | extern int pinctrl_force_default(struct pinctrl_dev *pctldev); | 190 | extern int pinctrl_force_default(struct pinctrl_dev *pctldev); |
| 188 | 191 | ||
| 189 | extern struct mutex pinctrl_mutex; | 192 | extern struct mutex pinctrl_maps_mutex; |
| 190 | extern struct list_head pinctrldev_list; | ||
| 191 | extern struct list_head pinctrl_maps; | 193 | extern struct list_head pinctrl_maps; |
| 192 | 194 | ||
| 193 | #define for_each_maps(_maps_node_, _i_, _map_) \ | 195 | #define for_each_maps(_maps_node_, _i_, _map_) \ |
diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c index c7b7cb477129..340fb4e6c600 100644 --- a/drivers/pinctrl/devicetree.c +++ b/drivers/pinctrl/devicetree.c | |||
| @@ -95,22 +95,11 @@ static int dt_remember_or_free_map(struct pinctrl *p, const char *statename, | |||
| 95 | return pinctrl_register_map(map, num_maps, false, true); | 95 | return pinctrl_register_map(map, num_maps, false, true); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | static struct pinctrl_dev *find_pinctrl_by_of_node(struct device_node *np) | ||
| 99 | { | ||
| 100 | struct pinctrl_dev *pctldev; | ||
| 101 | |||
| 102 | list_for_each_entry(pctldev, &pinctrldev_list, node) | ||
| 103 | if (pctldev->dev->of_node == np) | ||
| 104 | return pctldev; | ||
| 105 | |||
| 106 | return NULL; | ||
| 107 | } | ||
| 108 | |||
| 109 | struct pinctrl_dev *of_pinctrl_get(struct device_node *np) | 98 | struct pinctrl_dev *of_pinctrl_get(struct device_node *np) |
| 110 | { | 99 | { |
| 111 | struct pinctrl_dev *pctldev; | 100 | struct pinctrl_dev *pctldev; |
| 112 | 101 | ||
| 113 | pctldev = find_pinctrl_by_of_node(np); | 102 | pctldev = get_pinctrl_dev_from_of_node(np); |
| 114 | if (!pctldev) | 103 | if (!pctldev) |
| 115 | return NULL; | 104 | return NULL; |
| 116 | 105 | ||
| @@ -138,7 +127,7 @@ static int dt_to_map_one_config(struct pinctrl *p, const char *statename, | |||
| 138 | /* OK let's just assume this will appear later then */ | 127 | /* OK let's just assume this will appear later then */ |
| 139 | return -EPROBE_DEFER; | 128 | return -EPROBE_DEFER; |
| 140 | } | 129 | } |
| 141 | pctldev = find_pinctrl_by_of_node(np_pctldev); | 130 | pctldev = get_pinctrl_dev_from_of_node(np_pctldev); |
| 142 | if (pctldev) | 131 | if (pctldev) |
| 143 | break; | 132 | break; |
| 144 | /* Do not defer probing of hogs (circular loop) */ | 133 | /* Do not defer probing of hogs (circular loop) */ |
diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c index 32f96808202a..c67c37e23dd7 100644 --- a/drivers/pinctrl/pinconf.c +++ b/drivers/pinctrl/pinconf.c | |||
| @@ -89,14 +89,14 @@ int pin_config_get(const char *dev_name, const char *name, | |||
| 89 | struct pinctrl_dev *pctldev; | 89 | struct pinctrl_dev *pctldev; |
| 90 | int pin; | 90 | int pin; |
| 91 | 91 | ||
| 92 | mutex_lock(&pinctrl_mutex); | ||
| 93 | |||
| 94 | pctldev = get_pinctrl_dev_from_devname(dev_name); | 92 | pctldev = get_pinctrl_dev_from_devname(dev_name); |
| 95 | if (!pctldev) { | 93 | if (!pctldev) { |
| 96 | pin = -EINVAL; | 94 | pin = -EINVAL; |
| 97 | goto unlock; | 95 | return pin; |
| 98 | } | 96 | } |
| 99 | 97 | ||
| 98 | mutex_lock(&pctldev->mutex); | ||
| 99 | |||
| 100 | pin = pin_get_from_name(pctldev, name); | 100 | pin = pin_get_from_name(pctldev, name); |
| 101 | if (pin < 0) | 101 | if (pin < 0) |
| 102 | goto unlock; | 102 | goto unlock; |
| @@ -104,7 +104,7 @@ int pin_config_get(const char *dev_name, const char *name, | |||
| 104 | pin = pin_config_get_for_pin(pctldev, pin, config); | 104 | pin = pin_config_get_for_pin(pctldev, pin, config); |
| 105 | 105 | ||
| 106 | unlock: | 106 | unlock: |
| 107 | mutex_unlock(&pinctrl_mutex); | 107 | mutex_unlock(&pctldev->mutex); |
| 108 | return pin; | 108 | return pin; |
| 109 | } | 109 | } |
| 110 | EXPORT_SYMBOL(pin_config_get); | 110 | EXPORT_SYMBOL(pin_config_get); |
| @@ -145,14 +145,14 @@ int pin_config_set(const char *dev_name, const char *name, | |||
| 145 | struct pinctrl_dev *pctldev; | 145 | struct pinctrl_dev *pctldev; |
| 146 | int pin, ret; | 146 | int pin, ret; |
| 147 | 147 | ||
| 148 | mutex_lock(&pinctrl_mutex); | ||
| 149 | |||
| 150 | pctldev = get_pinctrl_dev_from_devname(dev_name); | 148 | pctldev = get_pinctrl_dev_from_devname(dev_name); |
| 151 | if (!pctldev) { | 149 | if (!pctldev) { |
| 152 | ret = -EINVAL; | 150 | ret = -EINVAL; |
| 153 | goto unlock; | 151 | return ret; |
| 154 | } | 152 | } |
| 155 | 153 | ||
| 154 | mutex_lock(&pctldev->mutex); | ||
| 155 | |||
| 156 | pin = pin_get_from_name(pctldev, name); | 156 | pin = pin_get_from_name(pctldev, name); |
| 157 | if (pin < 0) { | 157 | if (pin < 0) { |
| 158 | ret = pin; | 158 | ret = pin; |
| @@ -162,7 +162,7 @@ int pin_config_set(const char *dev_name, const char *name, | |||
| 162 | ret = pin_config_set_for_pin(pctldev, pin, config); | 162 | ret = pin_config_set_for_pin(pctldev, pin, config); |
| 163 | 163 | ||
| 164 | unlock: | 164 | unlock: |
| 165 | mutex_unlock(&pinctrl_mutex); | 165 | mutex_unlock(&pctldev->mutex); |
| 166 | return ret; | 166 | return ret; |
| 167 | } | 167 | } |
| 168 | EXPORT_SYMBOL(pin_config_set); | 168 | EXPORT_SYMBOL(pin_config_set); |
| @@ -174,13 +174,14 @@ int pin_config_group_get(const char *dev_name, const char *pin_group, | |||
| 174 | const struct pinconf_ops *ops; | 174 | const struct pinconf_ops *ops; |
| 175 | int selector, ret; | 175 | int selector, ret; |
| 176 | 176 | ||
| 177 | mutex_lock(&pinctrl_mutex); | ||
| 178 | |||
| 179 | pctldev = get_pinctrl_dev_from_devname(dev_name); | 177 | pctldev = get_pinctrl_dev_from_devname(dev_name); |
| 180 | if (!pctldev) { | 178 | if (!pctldev) { |
| 181 | ret = -EINVAL; | 179 | ret = -EINVAL; |
| 182 | goto unlock; | 180 | return ret; |
| 183 | } | 181 | } |
| 182 | |||
| 183 | mutex_lock(&pctldev->mutex); | ||
| 184 | |||
| 184 | ops = pctldev->desc->confops; | 185 | ops = pctldev->desc->confops; |
| 185 | 186 | ||
| 186 | if (!ops || !ops->pin_config_group_get) { | 187 | if (!ops || !ops->pin_config_group_get) { |
| @@ -200,7 +201,7 @@ int pin_config_group_get(const char *dev_name, const char *pin_group, | |||
| 200 | ret = ops->pin_config_group_get(pctldev, selector, config); | 201 | ret = ops->pin_config_group_get(pctldev, selector, config); |
| 201 | 202 | ||
| 202 | unlock: | 203 | unlock: |
| 203 | mutex_unlock(&pinctrl_mutex); | 204 | mutex_unlock(&pctldev->mutex); |
| 204 | return ret; | 205 | return ret; |
| 205 | } | 206 | } |
| 206 | EXPORT_SYMBOL(pin_config_group_get); | 207 | EXPORT_SYMBOL(pin_config_group_get); |
| @@ -217,13 +218,14 @@ int pin_config_group_set(const char *dev_name, const char *pin_group, | |||
| 217 | int ret; | 218 | int ret; |
| 218 | int i; | 219 | int i; |
| 219 | 220 | ||
| 220 | mutex_lock(&pinctrl_mutex); | ||
| 221 | |||
| 222 | pctldev = get_pinctrl_dev_from_devname(dev_name); | 221 | pctldev = get_pinctrl_dev_from_devname(dev_name); |
| 223 | if (!pctldev) { | 222 | if (!pctldev) { |
| 224 | ret = -EINVAL; | 223 | ret = -EINVAL; |
| 225 | goto unlock; | 224 | return ret; |
| 226 | } | 225 | } |
| 226 | |||
| 227 | mutex_lock(&pctldev->mutex); | ||
| 228 | |||
| 227 | ops = pctldev->desc->confops; | 229 | ops = pctldev->desc->confops; |
| 228 | pctlops = pctldev->desc->pctlops; | 230 | pctlops = pctldev->desc->pctlops; |
| 229 | 231 | ||
| @@ -279,7 +281,7 @@ int pin_config_group_set(const char *dev_name, const char *pin_group, | |||
| 279 | ret = 0; | 281 | ret = 0; |
| 280 | 282 | ||
| 281 | unlock: | 283 | unlock: |
| 282 | mutex_unlock(&pinctrl_mutex); | 284 | mutex_unlock(&pctldev->mutex); |
| 283 | 285 | ||
| 284 | return ret; | 286 | return ret; |
| 285 | } | 287 | } |
| @@ -487,7 +489,7 @@ static int pinconf_pins_show(struct seq_file *s, void *what) | |||
| 487 | seq_puts(s, "Pin config settings per pin\n"); | 489 | seq_puts(s, "Pin config settings per pin\n"); |
| 488 | seq_puts(s, "Format: pin (name): configs\n"); | 490 | seq_puts(s, "Format: pin (name): configs\n"); |
| 489 | 491 | ||
| 490 | mutex_lock(&pinctrl_mutex); | 492 | mutex_lock(&pctldev->mutex); |
| 491 | 493 | ||
| 492 | /* The pin number can be retrived from the pin controller descriptor */ | 494 | /* The pin number can be retrived from the pin controller descriptor */ |
| 493 | for (i = 0; i < pctldev->desc->npins; i++) { | 495 | for (i = 0; i < pctldev->desc->npins; i++) { |
| @@ -507,7 +509,7 @@ static int pinconf_pins_show(struct seq_file *s, void *what) | |||
| 507 | seq_printf(s, "\n"); | 509 | seq_printf(s, "\n"); |
| 508 | } | 510 | } |
| 509 | 511 | ||
| 510 | mutex_unlock(&pinctrl_mutex); | 512 | mutex_unlock(&pctldev->mutex); |
| 511 | 513 | ||
| 512 | return 0; | 514 | return 0; |
| 513 | } | 515 | } |
| @@ -608,7 +610,7 @@ static int pinconf_dbg_config_print(struct seq_file *s, void *d) | |||
| 608 | bool found = false; | 610 | bool found = false; |
| 609 | unsigned long config; | 611 | unsigned long config; |
| 610 | 612 | ||
| 611 | mutex_lock(&pinctrl_mutex); | 613 | mutex_lock(&pctldev->mutex); |
| 612 | 614 | ||
| 613 | /* Parse the pinctrl map and look for the elected pin/state */ | 615 | /* Parse the pinctrl map and look for the elected pin/state */ |
| 614 | for_each_maps(maps_node, i, map) { | 616 | for_each_maps(maps_node, i, map) { |
| @@ -657,7 +659,7 @@ static int pinconf_dbg_config_print(struct seq_file *s, void *d) | |||
| 657 | confops->pin_config_config_dbg_show(pctldev, s, config); | 659 | confops->pin_config_config_dbg_show(pctldev, s, config); |
| 658 | 660 | ||
| 659 | exit: | 661 | exit: |
| 660 | mutex_unlock(&pinctrl_mutex); | 662 | mutex_unlock(&pctldev->mutex); |
| 661 | 663 | ||
| 662 | return 0; | 664 | return 0; |
| 663 | } | 665 | } |
| @@ -747,7 +749,7 @@ static int pinconf_dbg_config_write(struct file *file, | |||
| 747 | return -EINVAL; | 749 | return -EINVAL; |
| 748 | strncpy(config, token, MAX_NAME_LEN); | 750 | strncpy(config, token, MAX_NAME_LEN); |
| 749 | 751 | ||
| 750 | mutex_lock(&pinctrl_mutex); | 752 | mutex_lock(&pinctrl_maps_mutex); |
| 751 | 753 | ||
| 752 | /* Parse the pinctrl map and look for the selected dev/state/pin */ | 754 | /* Parse the pinctrl map and look for the selected dev/state/pin */ |
| 753 | for_each_maps(maps_node, i, map) { | 755 | for_each_maps(maps_node, i, map) { |
| @@ -785,7 +787,7 @@ static int pinconf_dbg_config_write(struct file *file, | |||
| 785 | } | 787 | } |
| 786 | 788 | ||
| 787 | exit: | 789 | exit: |
| 788 | mutex_unlock(&pinctrl_mutex); | 790 | mutex_unlock(&pinctrl_maps_mutex); |
| 789 | 791 | ||
| 790 | return count; | 792 | return count; |
| 791 | } | 793 | } |
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c index bd83c8b01cd1..88cc5095d0c9 100644 --- a/drivers/pinctrl/pinmux.c +++ b/drivers/pinctrl/pinmux.c | |||
| @@ -506,7 +506,7 @@ static int pinmux_functions_show(struct seq_file *s, void *what) | |||
| 506 | if (!pmxops) | 506 | if (!pmxops) |
| 507 | return 0; | 507 | return 0; |
| 508 | 508 | ||
| 509 | mutex_lock(&pinctrl_mutex); | 509 | mutex_lock(&pctldev->mutex); |
| 510 | nfuncs = pmxops->get_functions_count(pctldev); | 510 | nfuncs = pmxops->get_functions_count(pctldev); |
| 511 | while (func_selector < nfuncs) { | 511 | while (func_selector < nfuncs) { |
| 512 | const char *func = pmxops->get_function_name(pctldev, | 512 | const char *func = pmxops->get_function_name(pctldev, |
| @@ -530,7 +530,7 @@ static int pinmux_functions_show(struct seq_file *s, void *what) | |||
| 530 | func_selector++; | 530 | func_selector++; |
| 531 | } | 531 | } |
| 532 | 532 | ||
| 533 | mutex_unlock(&pinctrl_mutex); | 533 | mutex_unlock(&pctldev->mutex); |
| 534 | 534 | ||
| 535 | return 0; | 535 | return 0; |
| 536 | } | 536 | } |
| @@ -548,7 +548,7 @@ static int pinmux_pins_show(struct seq_file *s, void *what) | |||
| 548 | seq_puts(s, "Pinmux settings per pin\n"); | 548 | seq_puts(s, "Pinmux settings per pin\n"); |
| 549 | seq_puts(s, "Format: pin (name): mux_owner gpio_owner hog?\n"); | 549 | seq_puts(s, "Format: pin (name): mux_owner gpio_owner hog?\n"); |
| 550 | 550 | ||
| 551 | mutex_lock(&pinctrl_mutex); | 551 | mutex_lock(&pctldev->mutex); |
| 552 | 552 | ||
| 553 | /* The pin number can be retrived from the pin controller descriptor */ | 553 | /* The pin number can be retrived from the pin controller descriptor */ |
| 554 | for (i = 0; i < pctldev->desc->npins; i++) { | 554 | for (i = 0; i < pctldev->desc->npins; i++) { |
| @@ -583,7 +583,7 @@ static int pinmux_pins_show(struct seq_file *s, void *what) | |||
| 583 | seq_printf(s, "\n"); | 583 | seq_printf(s, "\n"); |
| 584 | } | 584 | } |
| 585 | 585 | ||
| 586 | mutex_unlock(&pinctrl_mutex); | 586 | mutex_unlock(&pctldev->mutex); |
| 587 | 587 | ||
| 588 | return 0; | 588 | return 0; |
| 589 | } | 589 | } |
