gpio-sa1100.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * linux/arch/arm/mach-sa1100/gpio.c
  3. *
  4. * Generic SA-1100 GPIO handling
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/gpio.h>
  11. #include <linux/init.h>
  12. #include <linux/module.h>
  13. #include <mach/hardware.h>
  14. static int sa1100_gpio_get(struct gpio_chip *chip, unsigned offset)
  15. {
  16. return GPLR & GPIO_GPIO(offset);
  17. }
  18. static void sa1100_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  19. {
  20. if (value)
  21. GPSR = GPIO_GPIO(offset);
  22. else
  23. GPCR = GPIO_GPIO(offset);
  24. }
  25. static int sa1100_direction_input(struct gpio_chip *chip, unsigned offset)
  26. {
  27. unsigned long flags;
  28. local_irq_save(flags);
  29. GPDR &= ~GPIO_GPIO(offset);
  30. local_irq_restore(flags);
  31. return 0;
  32. }
  33. static int sa1100_direction_output(struct gpio_chip *chip, unsigned offset, int value)
  34. {
  35. unsigned long flags;
  36. local_irq_save(flags);
  37. sa1100_gpio_set(chip, offset, value);
  38. GPDR |= GPIO_GPIO(offset);
  39. local_irq_restore(flags);
  40. return 0;
  41. }
  42. static struct gpio_chip sa1100_gpio_chip = {
  43. .label = "gpio",
  44. .direction_input = sa1100_direction_input,
  45. .direction_output = sa1100_direction_output,
  46. .set = sa1100_gpio_set,
  47. .get = sa1100_gpio_get,
  48. .base = 0,
  49. .ngpio = GPIO_MAX + 1,
  50. };
  51. void __init sa1100_init_gpio(void)
  52. {
  53. gpiochip_add(&sa1100_gpio_chip);
  54. }