gpio.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Alchemy GPIO support.
  3. *
  4. * With CONFIG_GPIOLIB=y different types of on-chip GPIO can be supported within
  5. * the same kernel image.
  6. * With CONFIG_GPIOLIB=n, your board must select ALCHEMY_GPIOINT_AU1XXX for the
  7. * appropriate CPU type (AU1000 currently).
  8. */
  9. #ifndef _ALCHEMY_GPIO_H_
  10. #define _ALCHEMY_GPIO_H_
  11. #include <asm/mach-au1x00/au1000.h>
  12. #include <asm/mach-au1x00/gpio-au1000.h>
  13. #include <asm/mach-au1x00/gpio-au1300.h>
  14. /* On Au1000, Au1500 and Au1100 GPIOs won't work as inputs before
  15. * SYS_PININPUTEN is written to at least once. On Au1550/Au1200/Au1300 this
  16. * register enables use of GPIOs as wake source.
  17. */
  18. static inline void alchemy_gpio1_input_enable(void)
  19. {
  20. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_SYS_PHYS_ADDR);
  21. __raw_writel(0, base + 0x110); /* the write op is key */
  22. wmb();
  23. }
  24. /* Linux gpio framework integration.
  25. *
  26. * 4 use cases of Alchemy GPIOS:
  27. *(1) GPIOLIB=y, ALCHEMY_GPIO_INDIRECT=y:
  28. * Board must register gpiochips.
  29. *(2) GPIOLIB=y, ALCHEMY_GPIO_INDIRECT=n:
  30. * A gpiochip for the 75 GPIOs is registered.
  31. *
  32. *(3) GPIOLIB=n, ALCHEMY_GPIO_INDIRECT=y:
  33. * the boards' gpio.h must provide the linux gpio wrapper functions,
  34. *
  35. *(4) GPIOLIB=n, ALCHEMY_GPIO_INDIRECT=n:
  36. * inlinable gpio functions are provided which enable access to the
  37. * Au1300 gpios only by using the numbers straight out of the data-
  38. * sheets.
  39. * Cases 1 and 3 are intended for boards which want to provide their own
  40. * GPIO namespace and -operations (i.e. for example you have 8 GPIOs
  41. * which are in part provided by spare Au1300 GPIO pins and in part by
  42. * an external FPGA but you still want them to be accssible in linux
  43. * as gpio0-7. The board can of course use the alchemy_gpioX_* functions
  44. * as required).
  45. */
  46. #ifdef CONFIG_GPIOLIB
  47. /* wraps the cpu-dependent irq_to_gpio functions */
  48. /* FIXME: gpiolib needs an irq_to_gpio hook */
  49. static inline int __au_irq_to_gpio(unsigned int irq)
  50. {
  51. switch (alchemy_get_cputype()) {
  52. case ALCHEMY_CPU_AU1000...ALCHEMY_CPU_AU1200:
  53. return alchemy_irq_to_gpio(irq);
  54. case ALCHEMY_CPU_AU1300:
  55. return au1300_irq_to_gpio(irq);
  56. }
  57. return -EINVAL;
  58. }
  59. /* using gpiolib to provide up to 2 gpio_chips for on-chip gpios */
  60. #ifndef CONFIG_ALCHEMY_GPIO_INDIRECT /* case (2) */
  61. /* get everything through gpiolib */
  62. #define gpio_to_irq __gpio_to_irq
  63. #define gpio_get_value __gpio_get_value
  64. #define gpio_set_value __gpio_set_value
  65. #define gpio_cansleep __gpio_cansleep
  66. #define irq_to_gpio __au_irq_to_gpio
  67. #include <asm-generic/gpio.h>
  68. #endif /* !CONFIG_ALCHEMY_GPIO_INDIRECT */
  69. #endif /* CONFIG_GPIOLIB */
  70. #endif /* _ALCHEMY_GPIO_H_ */