3 * Guennadi Liakhovetski, DENX Software Engineering, <lg@denx.de>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 #include <asm/arch/mx31-regs.h>
27 #if defined(CONFIG_MX51) || defined(CONFIG_MX53)
28 #include <asm/arch/imx-regs.h>
33 /* GPIO port description */
34 static unsigned long gpio_ports[] = {
35 [0] = GPIO1_BASE_ADDR,
36 [1] = GPIO2_BASE_ADDR,
37 [2] = GPIO3_BASE_ADDR,
38 #if defined(CONFIG_MX51) || defined(CONFIG_MX53)
39 [3] = GPIO4_BASE_ADDR,
41 #if defined(CONFIG_MX53)
42 [4] = GPIO5_BASE_ADDR,
43 [5] = GPIO6_BASE_ADDR,
44 [6] = GPIO7_BASE_ADDR,
48 int mxc_gpio_direction(unsigned int gpio, enum mxc_gpio_direction direction)
50 unsigned int port = gpio >> 5;
51 struct gpio_regs *regs;
54 if (port >= ARRAY_SIZE(gpio_ports))
59 regs = (struct gpio_regs *)gpio_ports[port];
61 l = readl(®s->gpio_dir);
64 case MXC_GPIO_DIRECTION_OUT:
67 case MXC_GPIO_DIRECTION_IN:
70 writel(l, ®s->gpio_dir);
75 void mxc_gpio_set(unsigned int gpio, unsigned int value)
77 unsigned int port = gpio >> 5;
78 struct gpio_regs *regs;
81 if (port >= ARRAY_SIZE(gpio_ports))
86 regs = (struct gpio_regs *)gpio_ports[port];
88 l = readl(®s->gpio_dr);
93 writel(l, ®s->gpio_dr);
96 int mxc_gpio_get(unsigned int gpio)
98 unsigned int port = gpio >> 5;
99 struct gpio_regs *regs;
102 if (port >= ARRAY_SIZE(gpio_ports))
107 regs = (struct gpio_regs *)gpio_ports[port];
109 l = (readl(®s->gpio_dr) >> gpio) & 0x01;