linux/arch/sh/boards/mach-sdk7786/gpio.c
<<
>>
Prefs
   1/*
   2 * SDK7786 FPGA USRGPIR Support.
   3 *
   4 * Copyright (C) 2010  Paul Mundt
   5 *
   6 * This file is subject to the terms and conditions of the GNU General Public
   7 * License.  See the file "COPYING" in the main directory of this archive
   8 * for more details.
   9 */
  10#include <linux/init.h>
  11#include <linux/interrupt.h>
  12#include <linux/gpio.h>
  13#include <linux/irq.h>
  14#include <linux/kernel.h>
  15#include <linux/spinlock.h>
  16#include <linux/io.h>
  17#include <mach/fpga.h>
  18
  19#define NR_FPGA_GPIOS   8
  20
  21static const char *usrgpir_gpio_names[NR_FPGA_GPIOS] = {
  22        "in0", "in1", "in2", "in3", "in4", "in5", "in6", "in7",
  23};
  24
  25static int usrgpir_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
  26{
  27        /* always in */
  28        return 0;
  29}
  30
  31static int usrgpir_gpio_get(struct gpio_chip *chip, unsigned gpio)
  32{
  33        return !!(fpga_read_reg(USRGPIR) & (1 << gpio));
  34}
  35
  36static struct gpio_chip usrgpir_gpio_chip = {
  37        .label                  = "sdk7786-fpga",
  38        .names                  = usrgpir_gpio_names,
  39        .direction_input        = usrgpir_gpio_direction_input,
  40        .get                    = usrgpir_gpio_get,
  41        .base                   = -1, /* don't care */
  42        .ngpio                  = NR_FPGA_GPIOS,
  43};
  44
  45static int __init usrgpir_gpio_setup(void)
  46{
  47        return gpiochip_add(&usrgpir_gpio_chip);
  48}
  49device_initcall(usrgpir_gpio_setup);
  50