2 * Copyright (C) 2012 Stefan Roese <sr@denx.de>
4 * See file CREDITS for list of people who contributed to this
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.
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.
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,
24 * Driver for SPEAr600 GPIO controller
28 #include <asm/arch/hardware.h>
33 static int gpio_direction(unsigned gpio,
34 enum gpio_direction direction)
36 struct gpio_regs *regs = (struct gpio_regs *)CONFIG_GPIO_BASE;
39 val = readl(®s->gpiodir);
41 if (direction == GPIO_DIRECTION_OUT)
46 writel(val, ®s->gpiodir);
51 int gpio_set_value(unsigned gpio, int value)
53 struct gpio_regs *regs = (struct gpio_regs *)CONFIG_GPIO_BASE;
55 writel(1 << gpio, ®s->gpiodata[DATA_REG_ADDR(gpio)]);
60 int gpio_get_value(unsigned gpio)
62 struct gpio_regs *regs = (struct gpio_regs *)CONFIG_GPIO_BASE;
65 val = readl(®s->gpiodata[DATA_REG_ADDR(gpio)]);
70 int gpio_request(unsigned gpio, const char *label)
72 if (gpio >= SPEAR_GPIO_COUNT)
78 int gpio_free(unsigned gpio)
83 void gpio_toggle_value(unsigned gpio)
85 gpio_set_value(gpio, !gpio_get_value(gpio));
88 int gpio_direction_input(unsigned gpio)
90 return gpio_direction(gpio, GPIO_DIRECTION_IN);
93 int gpio_direction_output(unsigned gpio, int value)
95 int ret = gpio_direction(gpio, GPIO_DIRECTION_OUT);
100 gpio_set_value(gpio, value);