.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * pinmux driver for CSR SiRFprimaII |
---|
3 | 4 | * |
---|
.. | .. |
---|
8 | 9 | * |
---|
9 | 10 | * Copyright (c) 2011 - 2014 Cambridge Silicon Radio Limited, a CSR plc group |
---|
10 | 11 | * company. |
---|
11 | | - * |
---|
12 | | - * Licensed under GPLv2 or later. |
---|
13 | 12 | */ |
---|
14 | 13 | |
---|
15 | 14 | #include <linux/init.h> |
---|
.. | .. |
---|
27 | 26 | #include <linux/of_device.h> |
---|
28 | 27 | #include <linux/of_platform.h> |
---|
29 | 28 | #include <linux/bitops.h> |
---|
30 | | -#include <linux/gpio.h> |
---|
| 29 | +#include <linux/gpio/driver.h> |
---|
31 | 30 | #include <linux/of_gpio.h> |
---|
32 | 31 | |
---|
33 | 32 | #include "pinctrl-sirf.h" |
---|
.. | .. |
---|
782 | 781 | static int sirfsoc_gpio_probe(struct device_node *np) |
---|
783 | 782 | { |
---|
784 | 783 | int i, err = 0; |
---|
785 | | - static struct sirfsoc_gpio_chip *sgpio; |
---|
| 784 | + struct sirfsoc_gpio_chip *sgpio; |
---|
786 | 785 | struct sirfsoc_gpio_bank *bank; |
---|
787 | 786 | void __iomem *regs; |
---|
788 | 787 | struct platform_device *pdev; |
---|
| 788 | + struct gpio_irq_chip *girq; |
---|
789 | 789 | |
---|
790 | 790 | u32 pullups[SIRFSOC_GPIO_NO_OF_BANKS], pulldowns[SIRFSOC_GPIO_NO_OF_BANKS]; |
---|
791 | 791 | |
---|
.. | .. |
---|
794 | 794 | return -ENODEV; |
---|
795 | 795 | |
---|
796 | 796 | sgpio = devm_kzalloc(&pdev->dev, sizeof(*sgpio), GFP_KERNEL); |
---|
797 | | - if (!sgpio) |
---|
798 | | - return -ENOMEM; |
---|
| 797 | + if (!sgpio) { |
---|
| 798 | + err = -ENOMEM; |
---|
| 799 | + goto out_put_device; |
---|
| 800 | + } |
---|
799 | 801 | spin_lock_init(&sgpio->lock); |
---|
800 | 802 | |
---|
801 | 803 | regs = of_iomap(np, 0); |
---|
802 | | - if (!regs) |
---|
803 | | - return -ENOMEM; |
---|
| 804 | + if (!regs) { |
---|
| 805 | + err = -ENOMEM; |
---|
| 806 | + goto out_put_device; |
---|
| 807 | + } |
---|
804 | 808 | |
---|
805 | 809 | sgpio->chip.gc.request = sirfsoc_gpio_request; |
---|
806 | 810 | sgpio->chip.gc.free = sirfsoc_gpio_free; |
---|
.. | .. |
---|
817 | 821 | sgpio->chip.gc.parent = &pdev->dev; |
---|
818 | 822 | sgpio->chip.regs = regs; |
---|
819 | 823 | |
---|
820 | | - err = gpiochip_add_data(&sgpio->chip.gc, sgpio); |
---|
821 | | - if (err) { |
---|
822 | | - dev_err(&pdev->dev, "%pOF: error in probe function with status %d\n", |
---|
823 | | - np, err); |
---|
824 | | - goto out; |
---|
| 824 | + girq = &sgpio->chip.gc.irq; |
---|
| 825 | + girq->chip = &sirfsoc_irq_chip; |
---|
| 826 | + girq->parent_handler = sirfsoc_gpio_handle_irq; |
---|
| 827 | + girq->num_parents = SIRFSOC_GPIO_NO_OF_BANKS; |
---|
| 828 | + girq->parents = devm_kcalloc(&pdev->dev, SIRFSOC_GPIO_NO_OF_BANKS, |
---|
| 829 | + sizeof(*girq->parents), |
---|
| 830 | + GFP_KERNEL); |
---|
| 831 | + if (!girq->parents) { |
---|
| 832 | + err = -ENOMEM; |
---|
| 833 | + goto out_put_device; |
---|
825 | 834 | } |
---|
826 | | - |
---|
827 | | - err = gpiochip_irqchip_add(&sgpio->chip.gc, |
---|
828 | | - &sirfsoc_irq_chip, |
---|
829 | | - 0, handle_level_irq, |
---|
830 | | - IRQ_TYPE_NONE); |
---|
831 | | - if (err) { |
---|
832 | | - dev_err(&pdev->dev, |
---|
833 | | - "could not connect irqchip to gpiochip\n"); |
---|
834 | | - goto out_banks; |
---|
835 | | - } |
---|
836 | | - |
---|
837 | 835 | for (i = 0; i < SIRFSOC_GPIO_NO_OF_BANKS; i++) { |
---|
838 | 836 | bank = &sgpio->sgpio_bank[i]; |
---|
839 | 837 | spin_lock_init(&bank->lock); |
---|
840 | 838 | bank->parent_irq = platform_get_irq(pdev, i); |
---|
841 | 839 | if (bank->parent_irq < 0) { |
---|
842 | 840 | err = bank->parent_irq; |
---|
843 | | - goto out_banks; |
---|
| 841 | + goto out; |
---|
844 | 842 | } |
---|
| 843 | + girq->parents[i] = bank->parent_irq; |
---|
| 844 | + } |
---|
| 845 | + girq->default_type = IRQ_TYPE_NONE; |
---|
| 846 | + girq->handler = handle_level_irq; |
---|
845 | 847 | |
---|
846 | | - gpiochip_set_chained_irqchip(&sgpio->chip.gc, |
---|
847 | | - &sirfsoc_irq_chip, |
---|
848 | | - bank->parent_irq, |
---|
849 | | - sirfsoc_gpio_handle_irq); |
---|
| 848 | + err = gpiochip_add_data(&sgpio->chip.gc, sgpio); |
---|
| 849 | + if (err) { |
---|
| 850 | + dev_err(&pdev->dev, "%pOF: error in probe function with status %d\n", |
---|
| 851 | + np, err); |
---|
| 852 | + goto out; |
---|
850 | 853 | } |
---|
851 | 854 | |
---|
852 | 855 | err = gpiochip_add_pin_range(&sgpio->chip.gc, dev_name(&pdev->dev), |
---|
.. | .. |
---|
868 | 871 | return 0; |
---|
869 | 872 | |
---|
870 | 873 | out_no_range: |
---|
871 | | -out_banks: |
---|
872 | 874 | gpiochip_remove(&sgpio->chip.gc); |
---|
873 | 875 | out: |
---|
874 | 876 | iounmap(regs); |
---|
| 877 | +out_put_device: |
---|
| 878 | + put_device(&pdev->dev); |
---|
875 | 879 | return err; |
---|
876 | 880 | } |
---|
877 | 881 | |
---|