gpio-au1300.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * gpio-au1300.h -- GPIO control for Au1300 GPIC and compatibles.
  4. *
  5. * Copyright (c) 2009-2011 Manuel Lauss <[email protected]>
  6. */
  7. #ifndef _GPIO_AU1300_H_
  8. #define _GPIO_AU1300_H_
  9. #include <asm/addrspace.h>
  10. #include <asm/io.h>
  11. #include <asm/mach-au1x00/au1000.h>
  12. struct gpio;
  13. struct gpio_chip;
  14. /* with the current GPIC design, up to 128 GPIOs are possible.
  15. * The only implementation so far is in the Au1300, which has 75 externally
  16. * available GPIOs.
  17. */
  18. #define AU1300_GPIO_BASE 0
  19. #define AU1300_GPIO_NUM 75
  20. #define AU1300_GPIO_MAX (AU1300_GPIO_BASE + AU1300_GPIO_NUM - 1)
  21. #define AU1300_GPIC_ADDR \
  22. (void __iomem *)KSEG1ADDR(AU1300_GPIC_PHYS_ADDR)
  23. static inline int au1300_gpio_get_value(unsigned int gpio)
  24. {
  25. void __iomem *roff = AU1300_GPIC_ADDR;
  26. int bit;
  27. gpio -= AU1300_GPIO_BASE;
  28. roff += GPIC_GPIO_BANKOFF(gpio);
  29. bit = GPIC_GPIO_TO_BIT(gpio);
  30. return __raw_readl(roff + AU1300_GPIC_PINVAL) & bit;
  31. }
  32. static inline int au1300_gpio_direction_input(unsigned int gpio)
  33. {
  34. void __iomem *roff = AU1300_GPIC_ADDR;
  35. unsigned long bit;
  36. gpio -= AU1300_GPIO_BASE;
  37. roff += GPIC_GPIO_BANKOFF(gpio);
  38. bit = GPIC_GPIO_TO_BIT(gpio);
  39. __raw_writel(bit, roff + AU1300_GPIC_DEVCLR);
  40. wmb();
  41. return 0;
  42. }
  43. static inline int au1300_gpio_set_value(unsigned int gpio, int v)
  44. {
  45. void __iomem *roff = AU1300_GPIC_ADDR;
  46. unsigned long bit;
  47. gpio -= AU1300_GPIO_BASE;
  48. roff += GPIC_GPIO_BANKOFF(gpio);
  49. bit = GPIC_GPIO_TO_BIT(gpio);
  50. __raw_writel(bit, roff + (v ? AU1300_GPIC_PINVAL
  51. : AU1300_GPIC_PINVALCLR));
  52. wmb();
  53. return 0;
  54. }
  55. static inline int au1300_gpio_direction_output(unsigned int gpio, int v)
  56. {
  57. /* hw switches to output automatically */
  58. return au1300_gpio_set_value(gpio, v);
  59. }
  60. static inline int au1300_gpio_to_irq(unsigned int gpio)
  61. {
  62. return AU1300_FIRST_INT + (gpio - AU1300_GPIO_BASE);
  63. }
  64. static inline int au1300_irq_to_gpio(unsigned int irq)
  65. {
  66. return (irq - AU1300_FIRST_INT) + AU1300_GPIO_BASE;
  67. }
  68. static inline int au1300_gpio_is_valid(unsigned int gpio)
  69. {
  70. int ret;
  71. switch (alchemy_get_cputype()) {
  72. case ALCHEMY_CPU_AU1300:
  73. ret = ((gpio >= AU1300_GPIO_BASE) && (gpio <= AU1300_GPIO_MAX));
  74. break;
  75. default:
  76. ret = 0;
  77. }
  78. return ret;
  79. }
  80. static inline int au1300_gpio_cansleep(unsigned int gpio)
  81. {
  82. return 0;
  83. }
  84. /* hardware remembers gpio 0-63 levels on powerup */
  85. static inline int au1300_gpio_getinitlvl(unsigned int gpio)
  86. {
  87. void __iomem *roff = AU1300_GPIC_ADDR;
  88. unsigned long v;
  89. if (unlikely(gpio > 63))
  90. return 0;
  91. else if (gpio > 31) {
  92. gpio -= 32;
  93. roff += 4;
  94. }
  95. v = __raw_readl(roff + AU1300_GPIC_RSTVAL);
  96. return (v >> gpio) & 1;
  97. }
  98. #endif /* _GPIO_AU1300_H_ */