gpio-sa1100.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 int sa1100_to_irq(struct gpio_chip *chip, unsigned offset)
  43. {
  44. return offset < 11 ? (IRQ_GPIO0 + offset) : (IRQ_GPIO11 - 11 + offset);
  45. }
  46. static struct gpio_chip sa1100_gpio_chip = {
  47. .label = "gpio",
  48. .direction_input = sa1100_direction_input,
  49. .direction_output = sa1100_direction_output,
  50. .set = sa1100_gpio_set,
  51. .get = sa1100_gpio_get,
  52. .to_irq = sa1100_to_irq,
  53. .base = 0,
  54. .ngpio = GPIO_MAX + 1,
  55. };
  56. void __init sa1100_init_gpio(void)
  57. {
  58. gpiochip_add(&sa1100_gpio_chip);
  59. }