kernel: update kernel 4.4 to version 4.4.20
[openwrt/openwrt.git] / target / linux / brcm63xx / patches-4.4 / 374-gpio-add-a-simple-GPIO-driver-for-bcm63xx.patch
1 From dbe94a8daaa63ef81b7414f2a17bca8e36dd6daa Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jogo@openwrt.org>
3 Date: Fri, 20 Feb 2015 19:55:32 +0100
4 Subject: [PATCH 1/6] gpio: add a simple GPIO driver for bcm63xx
5
6
7 Signed-off-by: Jonas Gorski <jogo@openwrt.org>
8 ---
9 drivers/gpio/Kconfig | 8 +++
10 drivers/gpio/Makefile | 1 +
11 drivers/gpio/gpio-bcm63xx.c | 122 +++++++++++++++++++++++++++++++++++++++++++
12 3 files changed, 131 insertions(+)
13 create mode 100644 drivers/gpio/gpio-bcm63xx.c
14
15 --- a/drivers/gpio/Kconfig
16 +++ b/drivers/gpio/Kconfig
17 @@ -133,6 +133,13 @@ config GPIO_BCM_KONA
18 help
19 Turn on GPIO support for Broadcom "Kona" chips.
20
21 +config GPIO_BCM63XX
22 + bool "Broadcom BCM63XX GPIO"
23 + depends on MIPS || COMPILE_TEST
24 + select GPIO_GENERIC
25 + help
26 + Turn on GPIO support for Broadcom BCM63XX xDSL chips.
27 +
28 config GPIO_BRCMSTB
29 tristate "BRCMSTB GPIO support"
30 default y if ARCH_BRCMSTB
31 --- a/drivers/gpio/Makefile
32 +++ b/drivers/gpio/Makefile
33 @@ -24,6 +24,7 @@ obj-$(CONFIG_GPIO_AMDPT) += gpio-amdpt.o
34 obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o
35 obj-$(CONFIG_ATH79) += gpio-ath79.o
36 obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o
37 +obj-$(CONFIG_GPIO_BCM63XX) += gpio-bcm63xx.o
38 obj-$(CONFIG_GPIO_BRCMSTB) += gpio-brcmstb.o
39 obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o
40 obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o
41 --- /dev/null
42 +++ b/drivers/gpio/gpio-bcm63xx.c
43 @@ -0,0 +1,122 @@
44 +/*
45 + * Driver for BCM63XX memory-mapped GPIO controllers, based on
46 + * Generic driver for memory-mapped GPIO controllers.
47 + *
48 + * Copyright 2008 MontaVista Software, Inc.
49 + * Copyright 2008,2010 Anton Vorontsov <cbouatmailru@gmail.com>
50 + * Copyright 2015 Jonas Gorski <jogo@openwrt.org>
51 + *
52 + * This program is free software; you can redistribute it and/or modify it
53 + * under the terms of the GNU General Public License as published by the
54 + * Free Software Foundation; either version 2 of the License, or (at your
55 + * option) any later version.
56 + */
57 +
58 +#include <linux/init.h>
59 +#include <linux/err.h>
60 +#include <linux/bug.h>
61 +#include <linux/kernel.h>
62 +#include <linux/module.h>
63 +#include <linux/spinlock.h>
64 +#include <linux/compiler.h>
65 +#include <linux/types.h>
66 +#include <linux/errno.h>
67 +#include <linux/log2.h>
68 +#include <linux/ioport.h>
69 +#include <linux/io.h>
70 +#include <linux/gpio.h>
71 +#include <linux/slab.h>
72 +#include <linux/platform_device.h>
73 +#include <linux/mod_devicetable.h>
74 +#include <linux/basic_mmio_gpio.h>
75 +#include <linux/of.h>
76 +#include <linux/of_gpio.h>
77 +
78 +static int bcm63xx_gpio_probe(struct platform_device *pdev)
79 +{
80 + struct device *dev = &pdev->dev;
81 + struct resource *dat_r, *dirout_r;
82 + void __iomem *dat;
83 + void __iomem *dirout;
84 + unsigned long sz;
85 + int err;
86 + struct bgpio_chip *bgc;
87 + struct bgpio_pdata *pdata = dev_get_platdata(dev);
88 +
89 + dirout_r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
90 + dat_r = platform_get_resource(pdev, IORESOURCE_MEM, 1);
91 + if (!dat_r || !dirout_r)
92 + return -EINVAL;
93 +
94 + if (resource_size(dat_r) != resource_size(dirout_r))
95 + return -EINVAL;
96 +
97 + sz = resource_size(dat_r);
98 +
99 + dat = devm_ioremap_resource(dev, dat_r);
100 + if (IS_ERR(dat))
101 + return PTR_ERR(dat);
102 +
103 + dirout = devm_ioremap_resource(dev, dirout_r);
104 + if (IS_ERR(dirout))
105 + return PTR_ERR(dirout);
106 +
107 + bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL);
108 + if (!bgc)
109 + return -ENOMEM;
110 +
111 + err = bgpio_init(bgc, dev, sz, dat, NULL, NULL, dirout, NULL,
112 + BGPIOF_BIG_ENDIAN_BYTE_ORDER);
113 + if (err)
114 + return err;
115 +
116 + platform_set_drvdata(pdev, bgc);
117 +
118 + if (dev->of_node) {
119 + int id = of_alias_get_id(dev->of_node, "gpio");
120 + u32 ngpios;
121 +
122 + if (id >= 0)
123 + bgc->gc.label = devm_kasprintf(dev, GFP_KERNEL,
124 + "bcm63xx-gpio.%d", id);
125 +
126 + if (!of_property_read_u32(dev->of_node, "ngpios", &ngpios))
127 + bgc->gc.ngpio = ngpios;
128 +
129 + } else if (pdata) {
130 + bgc->gc.base = pdata->base;
131 + if (pdata->ngpio > 0)
132 + bgc->gc.ngpio = pdata->ngpio;
133 + }
134 +
135 + return gpiochip_add(&bgc->gc);
136 +}
137 +
138 +static int bcm63xx_gpio_remove(struct platform_device *pdev)
139 +{
140 + struct bgpio_chip *bgc = platform_get_drvdata(pdev);
141 +
142 + return bgpio_remove(bgc);
143 +}
144 +
145 +#ifdef CONFIG_OF
146 +static struct of_device_id bcm63xx_gpio_of_match[] = {
147 + { .compatible = "brcm,bcm6345-gpio" },
148 + { },
149 +};
150 +#endif
151 +
152 +static struct platform_driver bcm63xx_gpio_driver = {
153 + .probe = bcm63xx_gpio_probe,
154 + .remove = bcm63xx_gpio_remove,
155 + .driver = {
156 + .name = "bcm63xx-gpio",
157 + .of_match_table = of_match_ptr(bcm63xx_gpio_of_match),
158 + },
159 +};
160 +
161 +module_platform_driver(bcm63xx_gpio_driver);
162 +
163 +MODULE_DESCRIPTION("Driver for BCM63XX memory-mapped GPIO controllers");
164 +MODULE_AUTHOR("Jonas Gorski <jogo@openwrt.org>");
165 +MODULE_LICENSE("GPL");