gpio-sa1100.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 <linux/io.h>
  14. #include <mach/hardware.h>
  15. #include <mach/irqs.h>
  16. static int sa1100_gpio_get(struct gpio_chip *chip, unsigned offset)
  17. {
  18. return GPLR & GPIO_GPIO(offset);
  19. }
  20. static void sa1100_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  21. {
  22. if (value)
  23. GPSR = GPIO_GPIO(offset);
  24. else
  25. GPCR = GPIO_GPIO(offset);
  26. }
  27. static int sa1100_direction_input(struct gpio_chip *chip, unsigned offset)
  28. {
  29. unsigned long flags;
  30. local_irq_save(flags);
  31. GPDR &= ~GPIO_GPIO(offset);
  32. local_irq_restore(flags);
  33. return 0;
  34. }
  35. static int sa1100_direction_output(struct gpio_chip *chip, unsigned offset, int value)
  36. {
  37. unsigned long flags;
  38. local_irq_save(flags);
  39. sa1100_gpio_set(chip, offset, value);
  40. GPDR |= GPIO_GPIO(offset);
  41. local_irq_restore(flags);
  42. return 0;
  43. }
  44. static int sa1100_to_irq(struct gpio_chip *chip, unsigned offset)
  45. {
  46. return offset < 11 ? (IRQ_GPIO0 + offset) : (IRQ_GPIO11 - 11 + offset);
  47. }
  48. static struct gpio_chip sa1100_gpio_chip = {
  49. .label = "gpio",
  50. .direction_input = sa1100_direction_input,
  51. .direction_output = sa1100_direction_output,
  52. .set = sa1100_gpio_set,
  53. .get = sa1100_gpio_get,
  54. .to_irq = sa1100_to_irq,
  55. .base = 0,
  56. .ngpio = GPIO_MAX + 1,
  57. };
  58. void __init sa1100_init_gpio(void)
  59. {
  60. gpiochip_add(&sa1100_gpio_chip);
  61. }