gpio.c 2.1 KB

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