blob: 56317410c103baaef3bfdaeb12ce254270634cb4 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From dbe94a8daaa63ef81b7414f2a17bca8e36dd6daa Mon Sep 17 00:00:00 2001
2From: Jonas Gorski <jogo@openwrt.org>
3Date: Fri, 20 Feb 2015 19:55:32 +0100
4Subject: [PATCH 1/6] gpio: add a simple GPIO driver for bcm63xx
5
6
7Signed-off-by: Jonas Gorski <jogo@openwrt.org>
8---
9 drivers/gpio/Kconfig | 8 +++
10 drivers/gpio/Makefile | 1 +
11 drivers/gpio/gpio-bcm63xx.c | 135 +++++++++++++++++++++++++++++++++++++++++++
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@@ -147,6 +147,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 || BMIPS_GENERIC)
31--- a/drivers/gpio/Makefile
32+++ b/drivers/gpio/Makefile
33@@ -34,6 +34,7 @@ obj-$(CONFIG_GPIO_ARIZONA) += gpio-ariz
34 obj-$(CONFIG_GPIO_ASPEED) += gpio-aspeed.o
35 obj-$(CONFIG_GPIO_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_BD70528) += gpio-bd70528.o
39 obj-$(CONFIG_GPIO_BD9571MWV) += gpio-bd9571mwv.o
40 obj-$(CONFIG_GPIO_BRCMSTB) += gpio-brcmstb.o
41--- /dev/null
42+++ b/drivers/gpio/gpio-bcm63xx.c
43@@ -0,0 +1,135 @@
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/gpio/driver.h>
72+#include <linux/slab.h>
73+#include <linux/platform_device.h>
74+#include <linux/mod_devicetable.h>
75+#include <linux/of.h>
76+#include <linux/of_irq.h>
77+#include <linux/of_gpio.h>
78+
79+static int bcm63xx_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
80+{
81+ char irq_name[7]; /* "gpioXX" */
82+
83+ sprintf(irq_name, "gpio%d", gpio);
84+ return of_irq_get_byname(chip->of_node, irq_name);
85+}
86+
87+static int bcm63xx_gpio_probe(struct platform_device *pdev)
88+{
89+ struct device *dev = &pdev->dev;
90+ struct resource *dat_r, *dirout_r;
91+ void __iomem *dat;
92+ void __iomem *dirout;
93+ unsigned long sz;
94+ int err;
95+ struct gpio_chip *gc;
96+ struct bgpio_pdata *pdata = dev_get_platdata(dev);
97+
98+ dirout_r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
99+ dat_r = platform_get_resource(pdev, IORESOURCE_MEM, 1);
100+ if (!dat_r || !dirout_r)
101+ return -EINVAL;
102+
103+ if (resource_size(dat_r) != resource_size(dirout_r))
104+ return -EINVAL;
105+
106+ sz = resource_size(dat_r);
107+
108+ dat = devm_ioremap_resource(dev, dat_r);
109+ if (IS_ERR(dat))
110+ return PTR_ERR(dat);
111+
112+ dirout = devm_ioremap_resource(dev, dirout_r);
113+ if (IS_ERR(dirout))
114+ return PTR_ERR(dirout);
115+
116+ gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
117+ if (!gc)
118+ return -ENOMEM;
119+
120+ err = bgpio_init(gc, dev, sz, dat, NULL, NULL, dirout, NULL,
121+ BGPIOF_BIG_ENDIAN_BYTE_ORDER);
122+ if (err)
123+ return err;
124+
125+ platform_set_drvdata(pdev, gc);
126+
127+ if (dev->of_node) {
128+ int id = of_alias_get_id(dev->of_node, "gpio");
129+ u32 ngpios;
130+
131+ if (id >= 0)
132+ gc->label = devm_kasprintf(dev, GFP_KERNEL,
133+ "bcm63xx-gpio.%d", id);
134+
135+ if (!of_property_read_u32(dev->of_node, "ngpios", &ngpios))
136+ gc->ngpio = ngpios;
137+
138+ if (of_get_property(dev->of_node, "interrupt-names", NULL))
139+ gc->to_irq = bcm63xx_gpio_to_irq;
140+
141+ } else if (pdata) {
142+ gc->base = pdata->base;
143+ if (pdata->ngpio > 0)
144+ gc->ngpio = pdata->ngpio;
145+ }
146+
147+ return gpiochip_add(gc);
148+}
149+
150+static int bcm63xx_gpio_remove(struct platform_device *pdev)
151+{
152+ struct gpio_chip *gc = platform_get_drvdata(pdev);
153+
154+ gpiochip_remove(gc);
155+ return 0;
156+}
157+
158+#ifdef CONFIG_OF
159+static struct of_device_id bcm63xx_gpio_of_match[] = {
160+ { .compatible = "brcm,bcm6345-gpio" },
161+ { },
162+};
163+#endif
164+
165+static struct platform_driver bcm63xx_gpio_driver = {
166+ .probe = bcm63xx_gpio_probe,
167+ .remove = bcm63xx_gpio_remove,
168+ .driver = {
169+ .name = "bcm63xx-gpio",
170+ .of_match_table = of_match_ptr(bcm63xx_gpio_of_match),
171+ },
172+};
173+
174+module_platform_driver(bcm63xx_gpio_driver);
175+
176+MODULE_DESCRIPTION("Driver for BCM63XX memory-mapped GPIO controllers");
177+MODULE_AUTHOR("Jonas Gorski <jogo@openwrt.org>");
178+MODULE_LICENSE("GPL");