3 * Guennadi Liakhovetski, DENX Software Engineering, <lg@denx.de>
6 * Stefano Babic, DENX Software Engineering, <sbabic@denx.de>
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <asm/arch/imx-regs.h>
32 enum mxc_gpio_direction {
33 MXC_GPIO_DIRECTION_IN,
34 MXC_GPIO_DIRECTION_OUT,
38 /* GPIO port description */
39 static unsigned long gpio_ports[] = {
40 [0] = GPIO1_BASE_ADDR,
41 [1] = GPIO2_BASE_ADDR,
42 [2] = GPIO3_BASE_ADDR,
43 #if defined(CONFIG_MX51) || defined(CONFIG_MX53)
44 [3] = GPIO4_BASE_ADDR,
46 #if defined(CONFIG_MX53)
47 [4] = GPIO5_BASE_ADDR,
48 [5] = GPIO6_BASE_ADDR,
49 [6] = GPIO7_BASE_ADDR,
53 static int mxc_gpio_direction(unsigned int gpio,
54 enum mxc_gpio_direction direction)
56 unsigned int port = gpio >> 5;
57 struct gpio_regs *regs;
60 if (port >= ARRAY_SIZE(gpio_ports))
65 regs = (struct gpio_regs *)gpio_ports[port];
67 l = readl(®s->gpio_dir);
70 case MXC_GPIO_DIRECTION_OUT:
73 case MXC_GPIO_DIRECTION_IN:
76 writel(l, ®s->gpio_dir);
81 void gpio_set_value(int gpio, int value)
83 unsigned int port = gpio >> 5;
84 struct gpio_regs *regs;
87 if (port >= ARRAY_SIZE(gpio_ports))
92 regs = (struct gpio_regs *)gpio_ports[port];
94 l = readl(®s->gpio_dr);
99 writel(l, ®s->gpio_dr);
102 int gpio_get_value(int gpio)
104 unsigned int port = gpio >> 5;
105 struct gpio_regs *regs;
108 if (port >= ARRAY_SIZE(gpio_ports))
113 regs = (struct gpio_regs *)gpio_ports[port];
115 l = (readl(®s->gpio_dr) >> gpio) & 0x01;
120 int gpio_request(int gp, const char *label)
122 unsigned int port = gp >> 5;
123 if (port >= ARRAY_SIZE(gpio_ports))
128 void gpio_free(int gp)
132 void gpio_toggle_value(int gp)
134 gpio_set_value(gp, !gpio_get_value(gp));
137 int gpio_direction_input(int gp)
139 return mxc_gpio_direction(gp, MXC_GPIO_DIRECTION_IN);
142 int gpio_direction_output(int gp, int value)
144 int ret = mxc_gpio_direction(gp, MXC_GPIO_DIRECTION_OUT);
149 gpio_set_value(gp, value);