gpio.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #include <asm/hardware/iop3xx.h>
  19. #include <mach/gpio.h>
  20. void gpio_line_config(int line, int direction)
  21. {
  22. unsigned long flags;
  23. local_irq_save(flags);
  24. if (direction == GPIO_IN) {
  25. *IOP3XX_GPOE |= 1 << line;
  26. } else if (direction == GPIO_OUT) {
  27. *IOP3XX_GPOE &= ~(1 << line);
  28. }
  29. local_irq_restore(flags);
  30. }
  31. EXPORT_SYMBOL(gpio_line_config);
  32. int gpio_line_get(int line)
  33. {
  34. return !!(*IOP3XX_GPID & (1 << line));
  35. }
  36. EXPORT_SYMBOL(gpio_line_get);
  37. void gpio_line_set(int line, int value)
  38. {
  39. unsigned long flags;
  40. local_irq_save(flags);
  41. if (value == GPIO_LOW) {
  42. *IOP3XX_GPOD &= ~(1 << line);
  43. } else if (value == GPIO_HIGH) {
  44. *IOP3XX_GPOD |= 1 << line;
  45. }
  46. local_irq_restore(flags);
  47. }
  48. EXPORT_SYMBOL(gpio_line_set);
  49. static int iop3xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
  50. {
  51. gpio_line_config(gpio, GPIO_IN);
  52. return 0;
  53. }
  54. static int iop3xx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int level)
  55. {
  56. gpio_line_set(gpio, level);
  57. gpio_line_config(gpio, GPIO_OUT);
  58. return 0;
  59. }
  60. static int iop3xx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
  61. {
  62. return gpio_line_get(gpio);
  63. }
  64. static void iop3xx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
  65. {
  66. gpio_line_set(gpio, value);
  67. }
  68. static struct gpio_chip iop3xx_chip = {
  69. .label = "iop3xx",
  70. .direction_input = iop3xx_gpio_direction_input,
  71. .get = iop3xx_gpio_get_value,
  72. .direction_output = iop3xx_gpio_direction_output,
  73. .set = iop3xx_gpio_set_value,
  74. .base = 0,
  75. .ngpio = IOP3XX_N_GPIOS,
  76. };
  77. static int __init iop3xx_gpio_setup(void)
  78. {
  79. return gpiochip_add(&iop3xx_chip);
  80. }
  81. arch_initcall(iop3xx_gpio_setup);