uboot/drivers/gpio/spear_gpio.c
<<
>>
Prefs
   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
  33static 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(&regs->gpiodir);
  40
  41        if (direction == GPIO_DIRECTION_OUT)
  42                val |= 1 << gpio;
  43        else
  44                val &= ~(1 << gpio);
  45
  46        writel(val, &regs->gpiodir);
  47
  48        return 0;
  49}
  50
  51int gpio_set_value(unsigned gpio, int value)
  52{
  53        struct gpio_regs *regs = (struct gpio_regs *)CONFIG_GPIO_BASE;
  54
  55        writel(1 << gpio, &regs->gpiodata[DATA_REG_ADDR(gpio)]);
  56
  57        return 0;
  58}
  59
  60int gpio_get_value(unsigned gpio)
  61{
  62        struct gpio_regs *regs = (struct gpio_regs *)CONFIG_GPIO_BASE;
  63        u32 val;
  64
  65        val = readl(&regs->gpiodata[DATA_REG_ADDR(gpio)]);
  66
  67        return !!val;
  68}
  69
  70int gpio_request(unsigned gpio, const char *label)
  71{
  72        if (gpio >= SPEAR_GPIO_COUNT)
  73                return -EINVAL;
  74
  75        return 0;
  76}
  77
  78int gpio_free(unsigned gpio)
  79{
  80        return 0;
  81}
  82
  83void gpio_toggle_value(unsigned gpio)
  84{
  85        gpio_set_value(gpio, !gpio_get_value(gpio));
  86}
  87
  88int gpio_direction_input(unsigned gpio)
  89{
  90        return gpio_direction(gpio, GPIO_DIRECTION_IN);
  91}
  92
  93int 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}
 103