1 diff -urN linux-2.6.21.1/arch/mips/au1000/common/gpio.c linux-2.6.21.1.new/arch/mips/au1000/common/gpio.c
2 --- linux-2.6.21.1/arch/mips/au1000/common/gpio.c 2007-04-27 23:49:26.000000000 +0200
3 +++ linux-2.6.21.1.new/arch/mips/au1000/common/gpio.c 2007-05-22 21:41:55.000000000 +0200
6 + * Copyright (C) 2007, OpenWrt.org, Florian Fainelli <florian@openwrt.org>
7 + * Architecture specific GPIO support
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 675 Mass Ave, Cambridge, MA 02139, USA.
18 + * au1000 SoC have only one GPIO line : GPIO1
19 + * others have a second one : GPIO2
22 +#include <linux/autoconf.h>
23 +#include <linux/init.h>
24 +#include <linux/types.h>
25 #include <linux/module.h>
27 -#include <au1xxx_gpio.h>
29 +#include <asm/addrspace.h>
32 +#include <asm/mach-au1x00/au1000.h>
33 +#include <asm/gpio.h>
36 #if !defined(CONFIG_SOC_AU1000)
37 static AU1X00_GPIO2 * const gpio2 = (AU1X00_GPIO2 *)GPIO2_BASE;
38 +#define GPIO2_OUTPUT_ENABLE_MASK 0x00010000
40 -#define GPIO2_OUTPUT_ENABLE_MASK 0x00010000
42 -int au1xxx_gpio2_read(int signal)
43 +static int au1xxx_gpio2_read(unsigned gpio)
46 -/* gpio2->dir &= ~(0x01 << signal); //Set GPIO to input */
47 - return ((gpio2->pinstate >> signal) & 0x01);
48 + gpio -= AU1XXX_GPIO_BASE;
49 + return ((gpio2->pinstate >> gpio) & 0x01);
52 -void au1xxx_gpio2_write(int signal, int value)
53 +static void au1xxx_gpio2_write(unsigned gpio, int value)
56 + gpio -= AU1XXX_GPIO_BASE;
58 - gpio2->output = (GPIO2_OUTPUT_ENABLE_MASK << signal) |
60 + gpio2->output = (GPIO2_OUTPUT_ENABLE_MASK << gpio) |
64 -void au1xxx_gpio2_tristate(int signal)
65 +static int au1xxx_gpio2_direction_input(unsigned gpio)
68 - gpio2->dir &= ~(0x01 << signal); /* Set GPIO to input */
69 + gpio -= AU1XXX_GPIO_BASE;
70 + gpio2->dir &= ~(0x01 << gpio);
75 -int au1xxx_gpio1_read(int signal)
76 +static int au1xxx_gpio2_direction_output(unsigned gpio, int value)
78 + gpio -= AU1XXX_GPIO_BASE;
79 + gpio2->dir = (0x01 << gpio) | (value << gpio);
83 +#endif /* !defined(CONFIG_SOC_AU1000) */
85 +static int au1xxx_gpio1_read(unsigned gpio)
87 -/* gpio1->trioutclr |= (0x01 << signal); */
88 - return ((gpio1->pinstaterd >> signal) & 0x01);
89 + return ((gpio1->pinstaterd >> gpio) & 0x01);
92 -void au1xxx_gpio1_write(int signal, int value)
93 +static void au1xxx_gpio1_write(unsigned gpio, int value)
96 - gpio1->outputset = (0x01 << signal);
97 + gpio1->outputset = (0x01 << gpio);
99 - gpio1->outputclr = (0x01 << signal); /* Output a Zero */
100 + /* Output a zero */
101 + gpio1->outputclr = (0x01 << gpio);
104 -void au1xxx_gpio1_tristate(int signal)
105 +static int au1xxx_gpio1_direction_input(unsigned gpio)
107 - gpio1->trioutclr = (0x01 << signal); /* Tristate signal */
108 + gpio1->pininputen = (0x01 << gpio);
112 +static int au1xxx_gpio1_direction_output(unsigned gpio, int value)
114 + gpio1->trioutclr = (0x01 & gpio);
118 -int au1xxx_gpio_read(int signal)
119 +int au1xxx_gpio_get_value(unsigned gpio)
122 + if(gpio >= AU1XXX_GPIO_BASE)
123 #if defined(CONFIG_SOC_AU1000)
126 - return au1xxx_gpio2_read(signal);
127 + return au1xxx_gpio2_read(gpio);
130 - return au1xxx_gpio1_read(signal);
131 + return au1xxx_gpio1_read(gpio);
134 -void au1xxx_gpio_write(int signal, int value)
135 +void au1xxx_gpio_set_value(unsigned gpio, int value)
138 + if(gpio >= AU1XXX_GPIO_BASE)
139 #if defined(CONFIG_SOC_AU1000)
142 - au1xxx_gpio2_write(signal, value);
143 + au1xxx_gpio2_write(gpio, value);
146 - au1xxx_gpio1_write(signal, value);
147 + au1xxx_gpio1_write(gpio, value);
150 -void au1xxx_gpio_tristate(int signal)
151 +int au1xxx_gpio_direction_input(unsigned gpio)
154 + if (gpio >= AU1XXX_GPIO_BASE)
155 #if defined(CONFIG_SOC_AU1000)
158 - au1xxx_gpio2_tristate(signal);
159 + return au1xxx_gpio2_direction_input(gpio);
162 - au1xxx_gpio1_tristate(signal);
163 + return au1xxx_gpio1_direction_input(gpio);
166 -void au1xxx_gpio1_set_inputs(void)
167 +int au1xxx_gpio_direction_output(unsigned gpio, int value)
169 - gpio1->pininputen = 0;
170 + if (gpio >= AU1XXX_GPIO_BASE)
171 +#if defined(CONFIG_SOC_AU1000)
174 + return au1xxx_gpio2_direction_output(gpio, value);
177 + return au1xxx_gpio1_direction_output(gpio, value);
180 -EXPORT_SYMBOL(au1xxx_gpio1_set_inputs);
181 -EXPORT_SYMBOL(au1xxx_gpio_tristate);
182 -EXPORT_SYMBOL(au1xxx_gpio_write);
183 -EXPORT_SYMBOL(au1xxx_gpio_read);
184 +EXPORT_SYMBOL(au1xxx_gpio_direction_output);
185 +EXPORT_SYMBOL(au1xxx_gpio_direction_input);
186 +EXPORT_SYMBOL(au1xxx_gpio_get_value);
187 +EXPORT_SYMBOL(au1xxx_gpio_set_value);
188 --- linux-2.6.21.1/arch/mips/Kconfig 2007-04-27 23:49:26.000000000 +0200
189 +++ linux-2.6.21.1.new/arch/mips/Kconfig 2007-05-21 08:04:42.000000000 +0200
190 @@ -1044,6 +1044,7 @@
191 select SYS_SUPPORTS_32BIT_KERNEL
192 select SYS_SUPPORTS_APM_EMULATION
193 select SYS_SUPPORTS_KGDB
194 + select GENERIC_GPIO
198 diff -urN linux-2.6.21.1/include/asm-mips/mach-au1x00/au1xxx_gpio.h linux-2.6.21.1.new/include/asm-mips/mach-au1x00/au1xxx_gpio.h
199 --- linux-2.6.21.1/include/asm-mips/mach-au1x00/au1xxx_gpio.h 2007-04-27 23:49:26.000000000 +0200
200 +++ linux-2.6.21.1.new/include/asm-mips/mach-au1x00/au1xxx_gpio.h 1970-01-01 01:00:00.000000000 +0100
202 -#ifndef __AU1XXX_GPIO_H
203 -#define __AU1XXX_GPIO_H
205 -void au1xxx_gpio1_set_inputs(void);
206 -void au1xxx_gpio_tristate(int signal);
207 -void au1xxx_gpio_write(int signal, int value);
208 -int au1xxx_gpio_read(int signal);
210 -typedef volatile struct
221 -#endif //__AU1XXX_GPIO_H
222 diff -urN linux-2.6.21.1/include/asm-mips/mach-au1x00/gpio.h linux-2.6.21.1.new/include/asm-mips/mach-au1x00/gpio.h
223 --- linux-2.6.21.1/include/asm-mips/mach-au1x00/gpio.h 1970-01-01 01:00:00.000000000 +0100
224 +++ linux-2.6.21.1.new/include/asm-mips/mach-au1x00/gpio.h 2007-05-21 01:10:22.000000000 +0200
226 +#ifndef _AU1XXX_GPIO_H_
227 +#define _AU1XXX_GPIO_H_
229 +#define AU1XXX_GPIO_BASE 200
231 +typedef volatile struct
242 +extern int au1xxx_gpio_get_value(unsigned gpio);
243 +extern void au1xxx_gpio_set_value(unsigned gpio, int value);
244 +extern int au1xxx_gpio_direction_input(unsigned gpio);
245 +extern int au1xxx_gpio_direction_output(unsigned gpio, int value);
248 +/* Wrappers for the arch-neutral GPIO API */
250 +static inline int gpio_request(unsigned gpio, const char *label)
252 + /* Not yet implemented */
256 +static inline void gpio_free(unsigned gpio)
258 + /* Not yet implemented */
261 +static inline int gpio_direction_input(unsigned gpio)
263 + return au1xxx_gpio_direction_input(gpio);
266 +static inline int gpio_direction_output(unsigned gpio, int value)
268 + return au1xxx_gpio_direction_output(gpio, value);
271 +static inline int gpio_get_value(unsigned gpio)
273 + return au1xxx_gpio_get_value(gpio);
276 +static inline void gpio_set_value(unsigned gpio, int value)
278 + au1xxx_gpio_set_value(gpio, value);
281 +static inline int gpio_to_irq(unsigned gpio)
286 +static inline int irq_to_gpio(unsigned irq)
292 +#include <asm-generic/gpio.h>
294 +#endif /* _AU1XXX_GPIO_H_ */