gpio-iop.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * arch/arm/plat-iop/gpio.c
  3. * GPIO handling for Intel IOP3xx processors.
  4. *
  5. * Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. */
  12. #include <linux/device.h>
  13. #include <linux/init.h>
  14. #include <linux/types.h>
  15. #include <linux/errno.h>
  16. #include <linux/gpio.h>
  17. #include <linux/export.h>
  18. #define IOP3XX_N_GPIOS 8
  19. static void gpio_line_config(int line, int direction)
  20. {
  21. unsigned long flags;
  22. local_irq_save(flags);
  23. if (direction == GPIO_IN) {
  24. *IOP3XX_GPOE |= 1 << line;
  25. } else if (direction == GPIO_OUT) {
  26. *IOP3XX_GPOE &= ~(1 << line);
  27. }
  28. local_irq_restore(flags);
  29. }
  30. static int gpio_line_get(int line)
  31. {
  32. return !!(*IOP3XX_GPID & (1 << line));
  33. }
  34. static void gpio_line_set(int line, int value)
  35. {
  36. unsigned long flags;
  37. local_irq_save(flags);
  38. if (value == GPIO_LOW) {
  39. *IOP3XX_GPOD &= ~(1 << line);
  40. } else if (value == GPIO_HIGH) {
  41. *IOP3XX_GPOD |= 1 << line;
  42. }
  43. local_irq_restore(flags);
  44. }
  45. static int iop3xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
  46. {
  47. gpio_line_config(gpio, GPIO_IN);
  48. return 0;
  49. }
  50. static int iop3xx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int level)
  51. {
  52. gpio_line_set(gpio, level);
  53. gpio_line_config(gpio, GPIO_OUT);
  54. return 0;
  55. }
  56. static int iop3xx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
  57. {
  58. return gpio_line_get(gpio);
  59. }
  60. static void iop3xx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
  61. {
  62. gpio_line_set(gpio, value);
  63. }
  64. static struct gpio_chip iop3xx_chip = {
  65. .label = "iop3xx",
  66. .direction_input = iop3xx_gpio_direction_input,
  67. .get = iop3xx_gpio_get_value,
  68. .direction_output = iop3xx_gpio_direction_output,
  69. .set = iop3xx_gpio_set_value,
  70. .base = 0,
  71. .ngpio = IOP3XX_N_GPIOS,
  72. };
  73. static int __init iop3xx_gpio_setup(void)
  74. {
  75. return gpiochip_add(&iop3xx_chip);
  76. }
  77. arch_initcall(iop3xx_gpio_setup);