gpio.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #define NR_FPGA_GPIOS 8
  19. static const char *usrgpir_gpio_names[NR_FPGA_GPIOS] = {
  20. "in0", "in1", "in2", "in3", "in4", "in5", "in6", "in7",
  21. };
  22. static int usrgpir_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
  23. {
  24. /* always in */
  25. return 0;
  26. }
  27. static int usrgpir_gpio_get(struct gpio_chip *chip, unsigned gpio)
  28. {
  29. return !!(fpga_read_reg(USRGPIR) & (1 << gpio));
  30. }
  31. static struct gpio_chip usrgpir_gpio_chip = {
  32. .label = "sdk7786-fpga",
  33. .names = usrgpir_gpio_names,
  34. .direction_input = usrgpir_gpio_direction_input,
  35. .get = usrgpir_gpio_get,
  36. .base = -1, /* don't care */
  37. .ngpio = NR_FPGA_GPIOS,
  38. };
  39. static int __init usrgpir_gpio_setup(void)
  40. {
  41. return gpiochip_add(&usrgpir_gpio_chip);
  42. }
  43. device_initcall(usrgpir_gpio_setup);