2 * Copyright (C) 2007, OpenWrt.org, Florian Fainelli <florian@openwrt.org>
3 * Architecture specific GPIO support
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
11 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
13 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
14 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
15 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
16 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
17 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
18 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
19 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 675 Mass Ave, Cambridge, MA 02139, USA.
26 * au1000 SoC have only one GPIO line : GPIO1
27 * others have a second one : GPIO2
30 #include <linux/autoconf.h>
31 #include <linux/init.h>
33 #include <linux/types.h>
34 #include <linux/module.h>
36 #include <asm/addrspace.h>
38 #include <asm/mach-au1x00/au1000.h>
42 #if !defined(CONFIG_SOC_AU1000)
44 static struct au1x00_gpio2 *const gpio2 = (struct au1x00_gpio2 *) GPIO2_BASE;
45 #define GPIO2_OUTPUT_ENABLE_MASK 0x00010000
47 static int au1xxx_gpio2_read(unsigned gpio)
49 gpio -= AU1XXX_GPIO_BASE;
50 return ((gpio2->pinstate >> gpio) & 0x01);
53 static void au1xxx_gpio2_write(unsigned gpio, int value)
55 gpio -= AU1XXX_GPIO_BASE;
57 gpio2->output = (GPIO2_OUTPUT_ENABLE_MASK << gpio) | (value << gpio);
60 static int au1xxx_gpio2_direction_input(unsigned gpio)
62 gpio -= AU1XXX_GPIO_BASE;
63 gpio2->dir &= ~(0x01 << gpio);
67 static int au1xxx_gpio2_direction_output(unsigned gpio, int value)
69 gpio -= AU1XXX_GPIO_BASE;
70 gpio2->dir = (0x01 << gpio) | (value << gpio);
74 #endif /* !defined(CONFIG_SOC_AU1000) */
76 static int au1xxx_gpio1_read(unsigned gpio)
78 return ((gpio1->pinstaterd >> gpio) & 0x01);
81 static void au1xxx_gpio1_write(unsigned gpio, int value)
84 gpio1->outputset = (0x01 << gpio);
87 gpio1->outputclr = (0x01 << gpio);
90 static int au1xxx_gpio1_direction_input(unsigned gpio)
92 gpio1->pininputen = (0x01 << gpio);
96 static int au1xxx_gpio1_direction_output(unsigned gpio, int value)
98 gpio1->trioutclr = (0x01 & gpio);
102 int au1xxx_gpio_get_value(unsigned gpio)
104 if (gpio >= AU1XXX_GPIO_BASE)
105 #if defined(CONFIG_SOC_AU1000)
108 return au1xxx_gpio2_read(gpio);
111 return au1xxx_gpio1_read(gpio);
114 EXPORT_SYMBOL(au1xxx_gpio_get_value);
116 void au1xxx_gpio_set_value(unsigned gpio, int value)
118 if (gpio >= AU1XXX_GPIO_BASE)
119 #if defined(CONFIG_SOC_AU1000)
122 au1xxx_gpio2_write(gpio, value);
125 au1xxx_gpio1_write(gpio, value);
128 EXPORT_SYMBOL(au1xxx_gpio_set_value);
130 int au1xxx_gpio_direction_input(unsigned gpio)
132 if (gpio >= AU1XXX_GPIO_BASE)
133 #if defined(CONFIG_SOC_AU1000)
136 return au1xxx_gpio2_direction_input(gpio);
139 return au1xxx_gpio1_direction_input(gpio);
142 EXPORT_SYMBOL(au1xxx_gpio_direction_input);
144 int au1xxx_gpio_direction_output(unsigned gpio, int value)
146 if (gpio >= AU1XXX_GPIO_BASE)
147 #if defined(CONFIG_SOC_AU1000)
150 return au1xxx_gpio2_direction_output(gpio, value);
153 return au1xxx_gpio1_direction_output(gpio, value);
156 EXPORT_SYMBOL(au1xxx_gpio_direction_output);