Stefan Roese | ad38e5d | 2012-02-14 14:01:36 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2012 Stefan Roese <sr@denx.de> |
| 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 | /* |
| 24 | * Driver for SPEAr600 GPIO controller |
| 25 | */ |
| 26 | |
| 27 | #include <common.h> |
| 28 | #include <asm/arch/hardware.h> |
| 29 | #include <asm/gpio.h> |
| 30 | #include <asm/io.h> |
| 31 | #include <errno.h> |
| 32 | |
| 33 | static int gpio_direction(unsigned gpio, |
| 34 | enum gpio_direction direction) |
| 35 | { |
| 36 | struct gpio_regs *regs = (struct gpio_regs *)CONFIG_GPIO_BASE; |
| 37 | u32 val; |
| 38 | |
| 39 | val = readl(®s->gpiodir); |
| 40 | |
| 41 | if (direction == GPIO_DIRECTION_OUT) |
| 42 | val |= 1 << gpio; |
| 43 | else |
| 44 | val &= ~(1 << gpio); |
| 45 | |
| 46 | writel(val, ®s->gpiodir); |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | int gpio_set_value(unsigned gpio, int value) |
| 52 | { |
| 53 | struct gpio_regs *regs = (struct gpio_regs *)CONFIG_GPIO_BASE; |
| 54 | |
| 55 | writel(1 << gpio, ®s->gpiodata[DATA_REG_ADDR(gpio)]); |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | int gpio_get_value(unsigned gpio) |
| 61 | { |
| 62 | struct gpio_regs *regs = (struct gpio_regs *)CONFIG_GPIO_BASE; |
| 63 | u32 val; |
| 64 | |
| 65 | val = readl(®s->gpiodata[DATA_REG_ADDR(gpio)]); |
| 66 | |
| 67 | return !!val; |
| 68 | } |
| 69 | |
| 70 | int gpio_request(unsigned gpio, const char *label) |
| 71 | { |
| 72 | if (gpio >= SPEAR_GPIO_COUNT) |
| 73 | return -EINVAL; |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | int gpio_free(unsigned gpio) |
| 79 | { |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | void gpio_toggle_value(unsigned gpio) |
| 84 | { |
| 85 | gpio_set_value(gpio, !gpio_get_value(gpio)); |
| 86 | } |
| 87 | |
| 88 | int gpio_direction_input(unsigned gpio) |
| 89 | { |
| 90 | return gpio_direction(gpio, GPIO_DIRECTION_IN); |
| 91 | } |
| 92 | |
| 93 | int gpio_direction_output(unsigned gpio, int value) |
| 94 | { |
| 95 | int ret = gpio_direction(gpio, GPIO_DIRECTION_OUT); |
| 96 | |
| 97 | if (ret < 0) |
| 98 | return ret; |
| 99 | |
| 100 | gpio_set_value(gpio, value); |
| 101 | return 0; |
| 102 | } |