gpio.c 2.1 KB

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