Merge tag 'pinctrl-v4.14-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl

Pull pin control fixes from Linus Walleij:
"This slew of fixes for pin control was noticed and patched up early,
so to get the annoyance out of the way for -rc1 it would make sense to
send them already.

- Fix a build include in the Uniphier driver to keep pace with
ongoing refactorings.

- Fix a slew of minor semantic and syntactic issues as well as
stricting up Kconfig for the new Spreadtrum driver.

- Fix the GPIO interrupt set-up on the Marvell 37xx Armada as fallout
for dynamically allocating irq descriptors from the core. (Also
tagged for stable.)

- Fix AMD register suspend/resume state spool/unspooling so that
wakeup works as it should. (Also tagged for stable.)"

* tag 'pinctrl-v4.14-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl:
pinctrl/amd: save pin registers over suspend/resume
pinctrl: armada-37xx: Fix gpio interrupt setup
pinctrl: sprd: fix off by one bugs
pinctrl: sprd: check for allocation failure
pinctrl: sprd: Restrict PINCTRL_SPRD to ARCH_SPRD or COMPILE_TEST
pinctrl: sprd: fix build errors and dependencies
pinctrl: sprd: make three local functions static
pinctrl: uniphier: include <linux/build_bug.h> instead of <linux/bug.h>

+120 -34
+22 -19
drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
··· 550 550 spin_lock_irqsave(&info->irq_lock, flags); 551 551 val = readl(info->base + reg); 552 552 if (on) 553 - val |= d->mask; 553 + val |= (BIT(d->hwirq % GPIO_PER_REG)); 554 554 else 555 - val &= ~d->mask; 555 + val &= ~(BIT(d->hwirq % GPIO_PER_REG)); 556 556 writel(val, info->base + reg); 557 557 spin_unlock_irqrestore(&info->irq_lock, flags); 558 558 ··· 571 571 val = readl(info->base + reg); 572 572 switch (type) { 573 573 case IRQ_TYPE_EDGE_RISING: 574 - val &= ~d->mask; 574 + val &= ~(BIT(d->hwirq % GPIO_PER_REG)); 575 575 break; 576 576 case IRQ_TYPE_EDGE_FALLING: 577 - val |= d->mask; 577 + val |= (BIT(d->hwirq % GPIO_PER_REG)); 578 578 break; 579 579 default: 580 580 spin_unlock_irqrestore(&info->irq_lock, flags); ··· 624 624 chained_irq_exit(chip, desc); 625 625 } 626 626 627 + static unsigned int armada_37xx_irq_startup(struct irq_data *d) 628 + { 629 + struct gpio_chip *chip = irq_data_get_irq_chip_data(d); 630 + int irq = d->hwirq - chip->irq_base; 631 + /* 632 + * The mask field is a "precomputed bitmask for accessing the 633 + * chip registers" which was introduced for the generic 634 + * irqchip framework. As we don't use this framework, we can 635 + * reuse this field for our own usage. 636 + */ 637 + d->mask = BIT(irq % GPIO_PER_REG); 638 + 639 + armada_37xx_irq_unmask(d); 640 + 641 + return 0; 642 + } 643 + 627 644 static int armada_37xx_irqchip_register(struct platform_device *pdev, 628 645 struct armada_37xx_pinctrl *info) 629 646 { 630 647 struct device_node *np = info->dev->of_node; 631 - int nrirqs = info->data->nr_pins; 632 648 struct gpio_chip *gc = &info->gpio_chip; 633 649 struct irq_chip *irqchip = &info->irq_chip; 634 650 struct resource res; ··· 682 666 irqchip->irq_unmask = armada_37xx_irq_unmask; 683 667 irqchip->irq_set_wake = armada_37xx_irq_set_wake; 684 668 irqchip->irq_set_type = armada_37xx_irq_set_type; 669 + irqchip->irq_startup = armada_37xx_irq_startup; 685 670 irqchip->name = info->data->name; 686 - 687 671 ret = gpiochip_irqchip_add(gc, irqchip, 0, 688 672 handle_edge_irq, IRQ_TYPE_NONE); 689 673 if (ret) { ··· 696 680 * controller. But we do not take advantage of this and use 697 681 * the chained irq with all of them. 698 682 */ 699 - for (i = 0; i < nrirqs; i++) { 700 - struct irq_data *d = irq_get_irq_data(gc->irq_base + i); 701 - 702 - /* 703 - * The mask field is a "precomputed bitmask for 704 - * accessing the chip registers" which was introduced 705 - * for the generic irqchip framework. As we don't use 706 - * this framework, we can reuse this field for our own 707 - * usage. 708 - */ 709 - d->mask = BIT(i % GPIO_PER_REG); 710 - } 711 - 712 683 for (i = 0; i < nr_irq_parent; i++) { 713 684 int irq = irq_of_parse_and_map(np, i); 714 685
+75
drivers/pinctrl/pinctrl-amd.c
··· 36 36 #include <linux/pinctrl/pinconf.h> 37 37 #include <linux/pinctrl/pinconf-generic.h> 38 38 39 + #include "core.h" 39 40 #include "pinctrl-utils.h" 40 41 #include "pinctrl-amd.h" 41 42 ··· 726 725 .pin_config_group_set = amd_pinconf_group_set, 727 726 }; 728 727 728 + #ifdef CONFIG_PM_SLEEP 729 + static bool amd_gpio_should_save(struct amd_gpio *gpio_dev, unsigned int pin) 730 + { 731 + const struct pin_desc *pd = pin_desc_get(gpio_dev->pctrl, pin); 732 + 733 + if (!pd) 734 + return false; 735 + 736 + /* 737 + * Only restore the pin if it is actually in use by the kernel (or 738 + * by userspace). 739 + */ 740 + if (pd->mux_owner || pd->gpio_owner || 741 + gpiochip_line_is_irq(&gpio_dev->gc, pin)) 742 + return true; 743 + 744 + return false; 745 + } 746 + 747 + int amd_gpio_suspend(struct device *dev) 748 + { 749 + struct platform_device *pdev = to_platform_device(dev); 750 + struct amd_gpio *gpio_dev = platform_get_drvdata(pdev); 751 + struct pinctrl_desc *desc = gpio_dev->pctrl->desc; 752 + int i; 753 + 754 + for (i = 0; i < desc->npins; i++) { 755 + int pin = desc->pins[i].number; 756 + 757 + if (!amd_gpio_should_save(gpio_dev, pin)) 758 + continue; 759 + 760 + gpio_dev->saved_regs[i] = readl(gpio_dev->base + pin*4); 761 + } 762 + 763 + return 0; 764 + } 765 + 766 + int amd_gpio_resume(struct device *dev) 767 + { 768 + struct platform_device *pdev = to_platform_device(dev); 769 + struct amd_gpio *gpio_dev = platform_get_drvdata(pdev); 770 + struct pinctrl_desc *desc = gpio_dev->pctrl->desc; 771 + int i; 772 + 773 + for (i = 0; i < desc->npins; i++) { 774 + int pin = desc->pins[i].number; 775 + 776 + if (!amd_gpio_should_save(gpio_dev, pin)) 777 + continue; 778 + 779 + writel(gpio_dev->saved_regs[i], gpio_dev->base + pin*4); 780 + } 781 + 782 + return 0; 783 + } 784 + 785 + static const struct dev_pm_ops amd_gpio_pm_ops = { 786 + SET_LATE_SYSTEM_SLEEP_PM_OPS(amd_gpio_suspend, 787 + amd_gpio_resume) 788 + }; 789 + #endif 790 + 729 791 static struct pinctrl_desc amd_pinctrl_desc = { 730 792 .pins = kerncz_pins, 731 793 .npins = ARRAY_SIZE(kerncz_pins), ··· 827 763 dev_err(&pdev->dev, "Failed to get gpio IRQ: %d\n", irq_base); 828 764 return irq_base; 829 765 } 766 + 767 + #ifdef CONFIG_PM_SLEEP 768 + gpio_dev->saved_regs = devm_kcalloc(&pdev->dev, amd_pinctrl_desc.npins, 769 + sizeof(*gpio_dev->saved_regs), 770 + GFP_KERNEL); 771 + if (!gpio_dev->saved_regs) 772 + return -ENOMEM; 773 + #endif 830 774 831 775 gpio_dev->pdev = pdev; 832 776 gpio_dev->gc.direction_input = amd_gpio_direction_input; ··· 925 853 .driver = { 926 854 .name = "amd_gpio", 927 855 .acpi_match_table = ACPI_PTR(amd_gpio_acpi_match), 856 + #ifdef CONFIG_PM_SLEEP 857 + .pm = &amd_gpio_pm_ops, 858 + #endif 928 859 }, 929 860 .probe = amd_gpio_probe, 930 861 .remove = amd_gpio_remove,
+1
drivers/pinctrl/pinctrl-amd.h
··· 97 97 unsigned int hwbank_num; 98 98 struct resource *res; 99 99 struct platform_device *pdev; 100 + u32 *saved_regs; 100 101 }; 101 102 102 103 /* KERNCZ configuration*/
+3
drivers/pinctrl/sprd/Kconfig
··· 4 4 5 5 config PINCTRL_SPRD 6 6 bool "Spreadtrum pinctrl driver" 7 + depends on OF 8 + depends on ARCH_SPRD || COMPILE_TEST 7 9 select PINMUX 8 10 select PINCONF 9 11 select GENERIC_PINCONF ··· 15 13 16 14 config PINCTRL_SPRD_SC9860 17 15 bool "Spreadtrum SC9860 pinctrl driver" 16 + depends on PINCTRL_SPRD 18 17 help 19 18 Say Y here to enable Spreadtrum SC9860 pinctrl driver
+18 -14
drivers/pinctrl/sprd/pinctrl-sprd.c
··· 353 353 .dt_free_map = pinctrl_utils_free_map, 354 354 }; 355 355 356 - int sprd_pmx_get_function_count(struct pinctrl_dev *pctldev) 356 + static int sprd_pmx_get_function_count(struct pinctrl_dev *pctldev) 357 357 { 358 358 return PIN_FUNC_MAX; 359 359 } 360 360 361 - const char *sprd_pmx_get_function_name(struct pinctrl_dev *pctldev, 362 - unsigned int selector) 361 + static const char *sprd_pmx_get_function_name(struct pinctrl_dev *pctldev, 362 + unsigned int selector) 363 363 { 364 364 switch (selector) { 365 365 case PIN_FUNC_1: ··· 375 375 } 376 376 } 377 377 378 - int sprd_pmx_get_function_groups(struct pinctrl_dev *pctldev, 379 - unsigned int selector, 380 - const char * const **groups, 381 - unsigned int * const num_groups) 378 + static int sprd_pmx_get_function_groups(struct pinctrl_dev *pctldev, 379 + unsigned int selector, 380 + const char * const **groups, 381 + unsigned int * const num_groups) 382 382 { 383 383 struct sprd_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); 384 384 struct sprd_pinctrl_soc_info *info = pctl->info; ··· 400 400 unsigned long reg; 401 401 unsigned int val = 0; 402 402 403 - if (group_selector > info->ngroups) 403 + if (group_selector >= info->ngroups) 404 404 return -EINVAL; 405 405 406 406 switch (func_selector) { ··· 734 734 struct sprd_pin_group *grp; 735 735 unsigned int pin_id; 736 736 737 - if (selector > info->ngroups) 737 + if (selector >= info->ngroups) 738 738 return -EINVAL; 739 739 740 740 grp = &info->groups[selector]; ··· 753 753 struct sprd_pin_group *grp; 754 754 int ret, i; 755 755 756 - if (selector > info->ngroups) 756 + if (selector >= info->ngroups) 757 757 return -EINVAL; 758 758 759 759 grp = &info->groups[selector]; ··· 813 813 const char *name; 814 814 int i, ret; 815 815 816 - if (selector > info->ngroups) 816 + if (selector >= info->ngroups) 817 817 return; 818 818 819 819 grp = &info->groups[selector]; ··· 1100 1100 1101 1101 void sprd_pinctrl_shutdown(struct platform_device *pdev) 1102 1102 { 1103 - struct pinctrl *pinctl = devm_pinctrl_get(&pdev->dev); 1103 + struct pinctrl *pinctl; 1104 1104 struct pinctrl_state *state; 1105 1105 1106 + pinctl = devm_pinctrl_get(&pdev->dev); 1107 + if (IS_ERR(pinctl)) 1108 + return; 1106 1109 state = pinctrl_lookup_state(pinctl, "shutdown"); 1107 - if (!IS_ERR(state)) 1108 - pinctrl_select_state(pinctl, state); 1110 + if (IS_ERR(state)) 1111 + return; 1112 + pinctrl_select_state(pinctl, state); 1109 1113 } 1110 1114 1111 1115 MODULE_DESCRIPTION("SPREADTRUM Pin Controller Driver");
+1 -1
drivers/pinctrl/uniphier/pinctrl-uniphier.h
··· 17 17 #define __PINCTRL_UNIPHIER_H__ 18 18 19 19 #include <linux/bitops.h> 20 - #include <linux/bug.h> 20 + #include <linux/build_bug.h> 21 21 #include <linux/kernel.h> 22 22 #include <linux/types.h> 23 23