aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/gpio/moxa,moxart-gpio.txt19
-rw-r--r--drivers/gpio/Kconfig7
-rw-r--r--drivers/gpio/Makefile1
-rw-r--r--drivers/gpio/gpio-moxart.c162
4 files changed, 189 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/gpio/moxa,moxart-gpio.txt b/Documentation/devicetree/bindings/gpio/moxa,moxart-gpio.txt
new file mode 100644
index 000000000000..f8e8f185a3db
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/moxa,moxart-gpio.txt
@@ -0,0 +1,19 @@
1MOXA ART GPIO Controller
2
3Required properties:
4
5- #gpio-cells : Should be 2, The first cell is the pin number,
6 the second cell is used to specify polarity:
7 0 = active high
8 1 = active low
9- compatible : Must be "moxa,moxart-gpio"
10- reg : Should contain registers location and length
11
12Example:
13
14 gpio: gpio@98700000 {
15 gpio-controller;
16 #gpio-cells = <2>;
17 compatible = "moxa,moxart-gpio";
18 reg = <0x98700000 0xC>;
19 };
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 58d98dd9e4b9..ae3682d25a3c 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -156,6 +156,13 @@ config GPIO_F7188X
156 To compile this driver as a module, choose M here: the module will 156 To compile this driver as a module, choose M here: the module will
157 be called f7188x-gpio. 157 be called f7188x-gpio.
158 158
159config GPIO_MOXART
160 bool "MOXART GPIO support"
161 depends on ARCH_MOXART
162 help
163 Select this option to enable GPIO driver for
164 MOXA ART SoC devices.
165
159config GPIO_MPC5200 166config GPIO_MPC5200
160 def_bool y 167 def_bool y
161 depends on PPC_MPC52xx 168 depends on PPC_MPC52xx
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 7971e36b8b12..ee95154cb1d2 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -46,6 +46,7 @@ obj-$(CONFIG_GPIO_MC9S08DZ60) += gpio-mc9s08dz60.o
46obj-$(CONFIG_GPIO_MCP23S08) += gpio-mcp23s08.o 46obj-$(CONFIG_GPIO_MCP23S08) += gpio-mcp23s08.o
47obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o 47obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o
48obj-$(CONFIG_GPIO_MM_LANTIQ) += gpio-mm-lantiq.o 48obj-$(CONFIG_GPIO_MM_LANTIQ) += gpio-mm-lantiq.o
49obj-$(CONFIG_GPIO_MOXART) += gpio-moxart.o
49obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o 50obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o
50obj-$(CONFIG_GPIO_MPC8XXX) += gpio-mpc8xxx.o 51obj-$(CONFIG_GPIO_MPC8XXX) += gpio-mpc8xxx.o
51obj-$(CONFIG_GPIO_MSIC) += gpio-msic.o 52obj-$(CONFIG_GPIO_MSIC) += gpio-msic.o
diff --git a/drivers/gpio/gpio-moxart.c b/drivers/gpio/gpio-moxart.c
new file mode 100644
index 000000000000..d662cdededac
--- /dev/null
+++ b/drivers/gpio/gpio-moxart.c
@@ -0,0 +1,162 @@
1/*
2 * MOXA ART SoCs GPIO driver.
3 *
4 * Copyright (C) 2013 Jonas Jensen
5 *
6 * Jonas Jensen <jonas.jensen@gmail.com>
7 *
8 * This file is licensed under the terms of the GNU General Public
9 * License version 2. This program is licensed "as is" without any
10 * warranty of any kind, whether express or implied.
11 */
12
13#include <linux/err.h>
14#include <linux/init.h>
15#include <linux/irq.h>
16#include <linux/io.h>
17#include <linux/gpio.h>
18#include <linux/platform_device.h>
19#include <linux/module.h>
20#include <linux/of_address.h>
21#include <linux/of_gpio.h>
22#include <linux/pinctrl/consumer.h>
23#include <linux/delay.h>
24#include <linux/timer.h>
25#include <linux/bitops.h>
26
27#define GPIO_DATA_OUT 0x00
28#define GPIO_DATA_IN 0x04
29#define GPIO_PIN_DIRECTION 0x08
30
31struct moxart_gpio_chip {
32 struct gpio_chip gpio;
33 void __iomem *moxart_gpio_base;
34};
35
36static inline struct moxart_gpio_chip *to_moxart_gpio(struct gpio_chip *chip)
37{
38 return container_of(chip, struct moxart_gpio_chip, gpio);
39}
40
41static int moxart_gpio_request(struct gpio_chip *chip, unsigned offset)
42{
43 return pinctrl_request_gpio(offset);
44}
45
46static void moxart_gpio_free(struct gpio_chip *chip, unsigned offset)
47{
48 pinctrl_free_gpio(offset);
49}
50
51static int moxart_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
52{
53 struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
54 void __iomem *ioaddr = gc->moxart_gpio_base + GPIO_PIN_DIRECTION;
55
56 writel(readl(ioaddr) & ~BIT(offset), ioaddr);
57 return 0;
58}
59
60static int moxart_gpio_direction_output(struct gpio_chip *chip,
61 unsigned offset, int value)
62{
63 struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
64 void __iomem *ioaddr = gc->moxart_gpio_base + GPIO_PIN_DIRECTION;
65
66 writel(readl(ioaddr) | BIT(offset), ioaddr);
67 return 0;
68}
69
70static void moxart_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
71{
72 struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
73 void __iomem *ioaddr = gc->moxart_gpio_base + GPIO_DATA_OUT;
74 u32 reg = readl(ioaddr);
75
76 if (value)
77 reg = reg | BIT(offset);
78 else
79 reg = reg & ~BIT(offset);
80
81
82 writel(reg, ioaddr);
83}
84
85static int moxart_gpio_get(struct gpio_chip *chip, unsigned offset)
86{
87 struct moxart_gpio_chip *gc = to_moxart_gpio(chip);
88 u32 ret = readl(gc->moxart_gpio_base + GPIO_PIN_DIRECTION);
89
90 if (ret & BIT(offset))
91 return !!(readl(gc->moxart_gpio_base + GPIO_DATA_OUT) &
92 BIT(offset));
93 else
94 return !!(readl(gc->moxart_gpio_base + GPIO_DATA_IN) &
95 BIT(offset));
96}
97
98static struct gpio_chip moxart_template_chip = {
99 .label = "moxart-gpio",
100 .request = moxart_gpio_request,
101 .free = moxart_gpio_free,
102 .direction_input = moxart_gpio_direction_input,
103 .direction_output = moxart_gpio_direction_output,
104 .set = moxart_gpio_set,
105 .get = moxart_gpio_get,
106 .base = 0,
107 .ngpio = 32,
108 .can_sleep = 0,
109};
110
111static int moxart_gpio_probe(struct platform_device *pdev)
112{
113 struct device *dev = &pdev->dev;
114 struct resource *res;
115 struct moxart_gpio_chip *mgc;
116 int ret;
117
118 mgc = devm_kzalloc(dev, sizeof(*mgc), GFP_KERNEL);
119 if (!mgc) {
120 dev_err(dev, "can't allocate GPIO chip container\n");
121 return -ENOMEM;
122 }
123 mgc->gpio = moxart_template_chip;
124
125 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
126 mgc->moxart_gpio_base = devm_ioremap_resource(dev, res);
127 if (IS_ERR(mgc->moxart_gpio_base)) {
128 dev_err(dev, "%s: devm_ioremap_resource res_gpio failed\n",
129 dev->of_node->full_name);
130 return PTR_ERR(mgc->moxart_gpio_base);
131 }
132
133 mgc->gpio.dev = dev;
134
135 ret = gpiochip_add(&mgc->gpio);
136 if (ret) {
137 dev_err(dev, "%s: gpiochip_add failed\n",
138 dev->of_node->full_name);
139 return ret;
140 }
141
142 return 0;
143}
144
145static const struct of_device_id moxart_gpio_match[] = {
146 { .compatible = "moxa,moxart-gpio" },
147 { }
148};
149
150static struct platform_driver moxart_gpio_driver = {
151 .driver = {
152 .name = "moxart-gpio",
153 .owner = THIS_MODULE,
154 .of_match_table = moxart_gpio_match,
155 },
156 .probe = moxart_gpio_probe,
157};
158module_platform_driver(moxart_gpio_driver);
159
160MODULE_DESCRIPTION("MOXART GPIO chip driver");
161MODULE_LICENSE("GPL");
162MODULE_AUTHOR("Jonas Jensen <jonas.jensen@gmail.com>");