blob: 737aafa82281880f1e21283d7cd963106cc7acc7 [file] [log] [blame]
Guennadi Liakhovetskib30de3c2009-02-07 01:18:07 +01001/*
2 * Copyright (C) 2009
3 * Guennadi Liakhovetski, DENX Software Engineering, <lg@denx.de>
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23#include <common.h>
24#include <asm/arch/mx31.h>
25#include <asm/arch/mx31-regs.h>
26
27/* GPIO port description */
28static unsigned long gpio_ports[] = {
29 [0] = GPIO1_BASE,
30 [1] = GPIO2_BASE,
31 [2] = GPIO3_BASE,
32};
33
34int mx31_gpio_direction(unsigned int gpio, enum mx31_gpio_direction direction)
35{
36 unsigned int port = gpio >> 5;
37 u32 l;
38
39 if (port >= ARRAY_SIZE(gpio_ports))
40 return 1;
41
42 gpio &= 0x1f;
43
44 l = __REG(gpio_ports[port] + GPIO_GDIR);
45 switch (direction) {
46 case MX31_GPIO_DIRECTION_OUT:
47 l |= 1 << gpio;
48 break;
49 case MX31_GPIO_DIRECTION_IN:
50 l &= ~(1 << gpio);
51 }
52 __REG(gpio_ports[port] + GPIO_GDIR) = l;
53
54 return 0;
55}
56
57void mx31_gpio_set(unsigned int gpio, unsigned int value)
58{
59 unsigned int port = gpio >> 5;
60 u32 l;
61
62 if (port >= ARRAY_SIZE(gpio_ports))
63 return;
64
65 gpio &= 0x1f;
66
67 l = __REG(gpio_ports[port] + GPIO_DR);
68 if (value)
69 l |= 1 << gpio;
70 else
71 l &= ~(1 << gpio);
72 __REG(gpio_ports[port] + GPIO_DR) = l;
73}