gpio.c 1.4 KB

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