2 * (C) Copyright 2008 Stefan Roese <sr@denx.de>, DENX Software Engineering
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * Find out to which of the 2 gpio modules the pin specified in the
27 * GPIO_MODULE yields 0 for pins 0 to 31,
30 #define GPIO_MODULE(pin) ((pin) >> 5)
33 * Bit position within a 32-bit peripheral register (where every
34 * bit is one bitslice)
36 #define MASK(pin) (1 << ((pin) & 0x1F))
37 #define BASE_ADDR(mod) module_base[mod]
40 * Lookup table for transforming gpio module number 0 to 2 to
43 static u32 module_base[] = {
48 static void clrsetbits(u32 addr, u32 and_mask, u32 or_mask)
50 reg_write(addr, (reg_read(addr) & ~and_mask) | or_mask);
53 int vct_gpio_dir(int pin, int dir)
57 gpio_base = BASE_ADDR(GPIO_MODULE(pin));
60 clrsetbits(GPIO_SWPORTA_DDR(gpio_base), MASK(pin), 0);
62 clrsetbits(GPIO_SWPORTA_DDR(gpio_base), 0, MASK(pin));
67 void vct_gpio_set(int pin, int val)
71 gpio_base = BASE_ADDR(GPIO_MODULE(pin));
74 clrsetbits(GPIO_SWPORTA_DR(gpio_base), MASK(pin), 0);
76 clrsetbits(GPIO_SWPORTA_DR(gpio_base), 0, MASK(pin));
79 int vct_gpio_get(int pin)
84 gpio_base = BASE_ADDR(GPIO_MODULE(pin));
85 value = reg_read(GPIO_EXT_PORTA(gpio_base));
87 return ((value & MASK(pin)) ? 1 : 0);