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,
37 #define GPIO_TO_PORT(n) (n / 32)
39 /* GPIO port description */
40 static unsigned long gpio_ports[] = {
41 [0] = GPIO1_BASE_ADDR,
42 [1] = GPIO2_BASE_ADDR,
43 [2] = GPIO3_BASE_ADDR,
44 #if defined(CONFIG_MX25) || defined(CONFIG_MX27) || defined(CONFIG_MX51) || \
45 defined(CONFIG_MX53) || defined(CONFIG_MX6)
46 [3] = GPIO4_BASE_ADDR,
48 #if defined(CONFIG_MX27) || defined(CONFIG_MX53) || defined(CONFIG_MX6)
49 [4] = GPIO5_BASE_ADDR,
50 [5] = GPIO6_BASE_ADDR,
52 #if defined(CONFIG_MX53) || defined(CONFIG_MX6)
53 [6] = GPIO7_BASE_ADDR,
57 static int mxc_gpio_direction(unsigned int gpio,
58 enum mxc_gpio_direction direction)
60 unsigned int port = GPIO_TO_PORT(gpio);
61 struct gpio_regs *regs;
64 if (port >= ARRAY_SIZE(gpio_ports))
69 regs = (struct gpio_regs *)gpio_ports[port];
71 l = readl(®s->gpio_dir);
74 case MXC_GPIO_DIRECTION_OUT:
77 case MXC_GPIO_DIRECTION_IN:
80 writel(l, ®s->gpio_dir);
85 int gpio_set_value(unsigned gpio, int value)
87 unsigned int port = GPIO_TO_PORT(gpio);
88 struct gpio_regs *regs;
91 if (port >= ARRAY_SIZE(gpio_ports))
96 regs = (struct gpio_regs *)gpio_ports[port];
98 l = readl(®s->gpio_dr);
103 writel(l, ®s->gpio_dr);
108 int gpio_get_value(unsigned gpio)
110 unsigned int port = GPIO_TO_PORT(gpio);
111 struct gpio_regs *regs;
114 if (port >= ARRAY_SIZE(gpio_ports))
119 regs = (struct gpio_regs *)gpio_ports[port];
121 val = (readl(®s->gpio_psr) >> gpio) & 0x01;
126 int gpio_request(unsigned gpio, const char *label)
128 unsigned int port = GPIO_TO_PORT(gpio);
129 if (port >= ARRAY_SIZE(gpio_ports))
134 int gpio_free(unsigned gpio)
139 int gpio_direction_input(unsigned gpio)
141 return mxc_gpio_direction(gpio, MXC_GPIO_DIRECTION_IN);
144 int gpio_direction_output(unsigned gpio, int value)
146 int ret = gpio_set_value(gpio, value);
151 return mxc_gpio_direction(gpio, MXC_GPIO_DIRECTION_OUT);