]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/arm926ejs/mx25/gpio.c
imported Ka-Ro specific additions to U-Boot 2009.08 for TX28
[karo-tx-uboot.git] / cpu / arm926ejs / mx25 / gpio.c
1 /*
2  * (c) Copyright 2009 Freescale Semiconductors
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20  * MA 02111-1307 USA
21  */
22
23 #include <common.h>
24 #include <asm/arch/mx25.h>
25 #include <asm/arch/mx25_pins.h>
26 #include <asm/arch/gpio.h>
27
28 enum gpio_reg {
29         DR = 0x00,
30         GDIR = 0x04,
31         PSR = 0x08,
32         ICR1 = 0x0C,
33         ICR2 = 0x10,
34         IMR = 0x14,
35         ISR = 0x18,
36 };
37
38 struct gpio_port_addr {
39         int num;
40         int base;
41 };
42
43 struct gpio_port_addr gpio_port[4] = {
44                                 {0, GPIO1_BASE},
45                                 {1, GPIO2_BASE},
46                                 {2, GPIO3_BASE},
47                                 {3, GPIO4_BASE}
48                                 };
49
50 /*
51  * Set a GPIO pin's direction
52  * @param port          pointer to a gpio_port
53  * @param index         gpio pin index value (0~31)
54  * @param is_input      0 for output; non-zero for input
55  */
56 static void _set_gpio_direction(u32 port, u32 index, int is_input)
57 {
58         u32 reg = gpio_port[port].base + GDIR;
59         u32 l;
60
61         l = __REG(reg);
62         if (is_input)
63                 l &= ~(1 << index);
64         else
65                 l |= 1 << index;
66         __REG(reg) = l;
67 }
68
69
70 /*!
71  * Exported function to set a GPIO pin's direction
72  * @param pin           a name defined by \b iomux_pin_name_t
73  * @param is_input      1 (or non-zero) for input; 0 for output
74  */
75 void mxc_set_gpio_direction(iomux_pin_name_t pin, int is_input)
76 {
77         u32 port;
78         u32 gpio = IOMUX_TO_GPIO(pin);
79
80         port = GPIO_TO_PORT(gpio);
81         _set_gpio_direction(port, GPIO_TO_INDEX(gpio), is_input);
82 }
83
84 /*
85  * Set a GPIO pin's data output
86  * @param port          number of gpio port
87  * @param index         gpio pin index value (0~31)
88  * @param data          value to be set (only 0 or 1 is valid)
89  */
90 static void _set_gpio_dataout(u32 port, u32 index, u32 data)
91 {
92         u32 reg = gpio_port[port].base + DR;
93         u32 l = 0;
94
95         l = (__REG(reg) & (~(1 << index))) | (data << index);
96         __REG(reg) = l;
97 }
98
99 /*!
100  * Exported function to set a GPIO pin's data output
101  * @param pin           a name defined by \b iomux_pin_name_t
102  * @param data          value to be set (only 0 or 1 is valid)
103  */
104
105 void mxc_set_gpio_dataout(iomux_pin_name_t pin, u32 data)
106 {
107         u32 port;
108         u32 gpio = IOMUX_TO_GPIO(pin);
109
110         port = GPIO_TO_PORT(gpio);
111         _set_gpio_dataout(port, GPIO_TO_INDEX(gpio), (data == 0) ? 0 : 1);
112 }
113