aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc
diff options
context:
space:
mode:
authorPeter Korsgaard <jacmet@sunsite.dk>2008-09-23 11:35:38 -0400
committerKumar Gala <galak@kernel.crashing.org>2008-09-23 11:41:16 -0400
commit1e16dfc1baa745dd89b95f6e33e4142df6218066 (patch)
treeeabec7954c03bde518f32f40fe3c544803b74497 /arch/powerpc
parent1afb7f809bfb8fad9eec9419f3dfd75cee746ebd (diff)
powerpc: gpio driver for mpc8349/8572/8610 and compatible
Structured similar to the existing QE GPIO support. Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk> Acked-by: Anton Vorontsov <avorontsov@ru.mvista.com> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Diffstat (limited to 'arch/powerpc')
-rw-r--r--arch/powerpc/sysdev/Kconfig9
-rw-r--r--arch/powerpc/sysdev/Makefile1
-rw-r--r--arch/powerpc/sysdev/mpc8xxx_gpio.c171
3 files changed, 181 insertions, 0 deletions
diff --git a/arch/powerpc/sysdev/Kconfig b/arch/powerpc/sysdev/Kconfig
index 396582835cb5..d0e7bb05c3a4 100644
--- a/arch/powerpc/sysdev/Kconfig
+++ b/arch/powerpc/sysdev/Kconfig
@@ -7,6 +7,15 @@ config PPC4xx_PCI_EXPRESS
7 depends on PCI && 4xx 7 depends on PCI && 4xx
8 default n 8 default n
9 9
10config MPC8xxx_GPIO
11 bool "MPC8xxx GPIO support"
12 depends on PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || PPC_85xx || PPC_86xx
13 select GENERIC_GPIO
14 select ARCH_REQUIRE_GPIOLIB
15 help
16 Say Y here if you're going to use hardware that connects to the
17 MPC831x/834x/837x/8572/8610 GPIOs.
18
10config PPC_MSI_BITMAP 19config PPC_MSI_BITMAP
11 bool 20 bool
12 depends on PCI_MSI 21 depends on PCI_MSI
diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile
index b6c269eb2650..55618ba9eff0 100644
--- a/arch/powerpc/sysdev/Makefile
+++ b/arch/powerpc/sysdev/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_FSL_SOC) += fsl_soc.o
16obj-$(CONFIG_FSL_PCI) += fsl_pci.o $(fsl-msi-obj-y) 16obj-$(CONFIG_FSL_PCI) += fsl_pci.o $(fsl-msi-obj-y)
17obj-$(CONFIG_FSL_LBC) += fsl_lbc.o 17obj-$(CONFIG_FSL_LBC) += fsl_lbc.o
18obj-$(CONFIG_FSL_GTM) += fsl_gtm.o 18obj-$(CONFIG_FSL_GTM) += fsl_gtm.o
19obj-$(CONFIG_MPC8xxx_GPIO) += mpc8xxx_gpio.o
19obj-$(CONFIG_RAPIDIO) += fsl_rio.o 20obj-$(CONFIG_RAPIDIO) += fsl_rio.o
20obj-$(CONFIG_TSI108_BRIDGE) += tsi108_pci.o tsi108_dev.o 21obj-$(CONFIG_TSI108_BRIDGE) += tsi108_pci.o tsi108_dev.o
21obj-$(CONFIG_QUICC_ENGINE) += qe_lib/ 22obj-$(CONFIG_QUICC_ENGINE) += qe_lib/
diff --git a/arch/powerpc/sysdev/mpc8xxx_gpio.c b/arch/powerpc/sysdev/mpc8xxx_gpio.c
new file mode 100644
index 000000000000..103eace36194
--- /dev/null
+++ b/arch/powerpc/sysdev/mpc8xxx_gpio.c
@@ -0,0 +1,171 @@
1/*
2 * GPIOs on MPC8349/8572/8610 and compatible
3 *
4 * Copyright (C) 2008 Peter Korsgaard <jacmet@sunsite.dk>
5 *
6 * This file is licensed under the terms of the GNU General Public License
7 * version 2. This program is licensed "as is" without any warranty of any
8 * kind, whether express or implied.
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/spinlock.h>
14#include <linux/io.h>
15#include <linux/of.h>
16#include <linux/of_gpio.h>
17#include <linux/gpio.h>
18
19#define MPC8XXX_GPIO_PINS 32
20
21#define GPIO_DIR 0x00
22#define GPIO_ODR 0x04
23#define GPIO_DAT 0x08
24#define GPIO_IER 0x0c
25#define GPIO_IMR 0x10
26#define GPIO_ICR 0x14
27
28struct mpc8xxx_gpio_chip {
29 struct of_mm_gpio_chip mm_gc;
30 spinlock_t lock;
31
32 /*
33 * shadowed data register to be able to clear/set output pins in
34 * open drain mode safely
35 */
36 u32 data;
37};
38
39static inline u32 mpc8xxx_gpio2mask(unsigned int gpio)
40{
41 return 1u << (MPC8XXX_GPIO_PINS - 1 - gpio);
42}
43
44static inline struct mpc8xxx_gpio_chip *
45to_mpc8xxx_gpio_chip(struct of_mm_gpio_chip *mm)
46{
47 return container_of(mm, struct mpc8xxx_gpio_chip, mm_gc);
48}
49
50static void mpc8xxx_gpio_save_regs(struct of_mm_gpio_chip *mm)
51{
52 struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
53
54 mpc8xxx_gc->data = in_be32(mm->regs + GPIO_DAT);
55}
56
57static int mpc8xxx_gpio_get(struct gpio_chip *gc, unsigned int gpio)
58{
59 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
60
61 return in_be32(mm->regs + GPIO_DAT) & mpc8xxx_gpio2mask(gpio);
62}
63
64static void mpc8xxx_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
65{
66 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
67 struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
68 unsigned long flags;
69
70 spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
71
72 if (val)
73 mpc8xxx_gc->data |= mpc8xxx_gpio2mask(gpio);
74 else
75 mpc8xxx_gc->data &= ~mpc8xxx_gpio2mask(gpio);
76
77 out_be32(mm->regs + GPIO_DAT, mpc8xxx_gc->data);
78
79 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
80}
81
82static int mpc8xxx_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
83{
84 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
85 struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
86 unsigned long flags;
87
88 spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
89
90 clrbits32(mm->regs + GPIO_DIR, mpc8xxx_gpio2mask(gpio));
91
92 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
93
94 return 0;
95}
96
97static int mpc8xxx_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
98{
99 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
100 struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
101 unsigned long flags;
102
103 mpc8xxx_gpio_set(gc, gpio, val);
104
105 spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
106
107 setbits32(mm->regs + GPIO_DIR, mpc8xxx_gpio2mask(gpio));
108
109 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
110
111 return 0;
112}
113
114static void __init mpc8xxx_add_controller(struct device_node *np)
115{
116 struct mpc8xxx_gpio_chip *mpc8xxx_gc;
117 struct of_mm_gpio_chip *mm_gc;
118 struct of_gpio_chip *of_gc;
119 struct gpio_chip *gc;
120 int ret;
121
122 mpc8xxx_gc = kzalloc(sizeof(*mpc8xxx_gc), GFP_KERNEL);
123 if (!mpc8xxx_gc) {
124 ret = -ENOMEM;
125 goto err;
126 }
127
128 spin_lock_init(&mpc8xxx_gc->lock);
129
130 mm_gc = &mpc8xxx_gc->mm_gc;
131 of_gc = &mm_gc->of_gc;
132 gc = &of_gc->gc;
133
134 mm_gc->save_regs = mpc8xxx_gpio_save_regs;
135 of_gc->gpio_cells = 2;
136 gc->ngpio = MPC8XXX_GPIO_PINS;
137 gc->direction_input = mpc8xxx_gpio_dir_in;
138 gc->direction_output = mpc8xxx_gpio_dir_out;
139 gc->get = mpc8xxx_gpio_get;
140 gc->set = mpc8xxx_gpio_set;
141
142 ret = of_mm_gpiochip_add(np, mm_gc);
143 if (ret)
144 goto err;
145
146 return;
147
148err:
149 pr_err("%s: registration failed with status %d\n",
150 np->full_name, ret);
151 kfree(mpc8xxx_gc);
152
153 return;
154}
155
156static int __init mpc8xxx_add_gpiochips(void)
157{
158 struct device_node *np;
159
160 for_each_compatible_node(np, NULL, "fsl,mpc8349-gpio")
161 mpc8xxx_add_controller(np);
162
163 for_each_compatible_node(np, NULL, "fsl,mpc8572-gpio")
164 mpc8xxx_add_controller(np);
165
166 for_each_compatible_node(np, NULL, "fsl,mpc8610-gpio")
167 mpc8xxx_add_controller(np);
168
169 return 0;
170}
171arch_initcall(mpc8xxx_add_gpiochips);