gpio-au1300.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * gpio-au1300.h -- GPIO control for Au1300 GPIC and compatibles.
  3. *
  4. * Copyright (c) 2009-2011 Manuel Lauss <manuel.lauss@googlemail.com>
  5. */
  6. #ifndef _GPIO_AU1300_H_
  7. #define _GPIO_AU1300_H_
  8. #include <asm/addrspace.h>
  9. #include <asm/io.h>
  10. #include <asm/mach-au1x00/au1000.h>
  11. /* with the current GPIC design, up to 128 GPIOs are possible.
  12. * The only implementation so far is in the Au1300, which has 75 externally
  13. * available GPIOs.
  14. */
  15. #define AU1300_GPIO_BASE 0
  16. #define AU1300_GPIO_NUM 75
  17. #define AU1300_GPIO_MAX (AU1300_GPIO_BASE + AU1300_GPIO_NUM - 1)
  18. #define AU1300_GPIC_ADDR \
  19. (void __iomem *)KSEG1ADDR(AU1300_GPIC_PHYS_ADDR)
  20. static inline int au1300_gpio_get_value(unsigned int gpio)
  21. {
  22. void __iomem *roff = AU1300_GPIC_ADDR;
  23. int bit;
  24. gpio -= AU1300_GPIO_BASE;
  25. roff += GPIC_GPIO_BANKOFF(gpio);
  26. bit = GPIC_GPIO_TO_BIT(gpio);
  27. return __raw_readl(roff + AU1300_GPIC_PINVAL) & bit;
  28. }
  29. static inline int au1300_gpio_direction_input(unsigned int gpio)
  30. {
  31. void __iomem *roff = AU1300_GPIC_ADDR;
  32. unsigned long bit;
  33. gpio -= AU1300_GPIO_BASE;
  34. roff += GPIC_GPIO_BANKOFF(gpio);
  35. bit = GPIC_GPIO_TO_BIT(gpio);
  36. __raw_writel(bit, roff + AU1300_GPIC_DEVCLR);
  37. wmb();
  38. return 0;
  39. }
  40. static inline int au1300_gpio_set_value(unsigned int gpio, int v)
  41. {
  42. void __iomem *roff = AU1300_GPIC_ADDR;
  43. unsigned long bit;
  44. gpio -= AU1300_GPIO_BASE;
  45. roff += GPIC_GPIO_BANKOFF(gpio);
  46. bit = GPIC_GPIO_TO_BIT(gpio);
  47. __raw_writel(bit, roff + (v ? AU1300_GPIC_PINVAL
  48. : AU1300_GPIC_PINVALCLR));
  49. wmb();
  50. return 0;
  51. }
  52. static inline int au1300_gpio_direction_output(unsigned int gpio, int v)
  53. {
  54. /* hw switches to output automatically */
  55. return au1300_gpio_set_value(gpio, v);
  56. }
  57. static inline int au1300_gpio_to_irq(unsigned int gpio)
  58. {
  59. return AU1300_FIRST_INT + (gpio - AU1300_GPIO_BASE);
  60. }
  61. static inline int au1300_irq_to_gpio(unsigned int irq)
  62. {
  63. return (irq - AU1300_FIRST_INT) + AU1300_GPIO_BASE;
  64. }
  65. static inline int au1300_gpio_is_valid(unsigned int gpio)
  66. {
  67. int ret;
  68. switch (alchemy_get_cputype()) {
  69. case ALCHEMY_CPU_AU1300:
  70. ret = ((gpio >= AU1300_GPIO_BASE) && (gpio <= AU1300_GPIO_MAX));
  71. break;
  72. default:
  73. ret = 0;
  74. }
  75. return ret;
  76. }
  77. static inline int au1300_gpio_cansleep(unsigned int gpio)
  78. {
  79. return 0;
  80. }
  81. /* hardware remembers gpio 0-63 levels on powerup */
  82. static inline int au1300_gpio_getinitlvl(unsigned int gpio)
  83. {
  84. void __iomem *roff = AU1300_GPIC_ADDR;
  85. unsigned long v;
  86. if (unlikely(gpio > 63))
  87. return 0;
  88. else if (gpio > 31) {
  89. gpio -= 32;
  90. roff += 4;
  91. }
  92. v = __raw_readl(roff + AU1300_GPIC_RSTVAL);
  93. return (v >> gpio) & 1;
  94. }
  95. /**********************************************************************/
  96. /* Linux gpio framework integration.
  97. *
  98. * 4 use cases of Alchemy GPIOS:
  99. *(1) GPIOLIB=y, ALCHEMY_GPIO_INDIRECT=y:
  100. * Board must register gpiochips.
  101. *(2) GPIOLIB=y, ALCHEMY_GPIO_INDIRECT=n:
  102. * A gpiochip for the 75 GPIOs is registered.
  103. *
  104. *(3) GPIOLIB=n, ALCHEMY_GPIO_INDIRECT=y:
  105. * the boards' gpio.h must provide the linux gpio wrapper functions,
  106. *
  107. *(4) GPIOLIB=n, ALCHEMY_GPIO_INDIRECT=n:
  108. * inlinable gpio functions are provided which enable access to the
  109. * Au1300 gpios only by using the numbers straight out of the data-
  110. * sheets.
  111. * Cases 1 and 3 are intended for boards which want to provide their own
  112. * GPIO namespace and -operations (i.e. for example you have 8 GPIOs
  113. * which are in part provided by spare Au1300 GPIO pins and in part by
  114. * an external FPGA but you still want them to be accssible in linux
  115. * as gpio0-7. The board can of course use the alchemy_gpioX_* functions
  116. * as required).
  117. */
  118. #ifndef CONFIG_GPIOLIB
  119. #ifdef CONFIG_ALCHEMY_GPIOINT_AU1300
  120. #ifndef CONFIG_ALCHEMY_GPIO_INDIRECT /* case (4) */
  121. static inline int gpio_direction_input(unsigned int gpio)
  122. {
  123. return au1300_gpio_direction_input(gpio);
  124. }
  125. static inline int gpio_direction_output(unsigned int gpio, int v)
  126. {
  127. return au1300_gpio_direction_output(gpio, v);
  128. }
  129. static inline int gpio_get_value(unsigned int gpio)
  130. {
  131. return au1300_gpio_get_value(gpio);
  132. }
  133. static inline void gpio_set_value(unsigned int gpio, int v)
  134. {
  135. au1300_gpio_set_value(gpio, v);
  136. }
  137. static inline int gpio_get_value_cansleep(unsigned gpio)
  138. {
  139. return gpio_get_value(gpio);
  140. }
  141. static inline void gpio_set_value_cansleep(unsigned gpio, int value)
  142. {
  143. gpio_set_value(gpio, value);
  144. }
  145. static inline int gpio_is_valid(unsigned int gpio)
  146. {
  147. return au1300_gpio_is_valid(gpio);
  148. }
  149. static inline int gpio_cansleep(unsigned int gpio)
  150. {
  151. return au1300_gpio_cansleep(gpio);
  152. }
  153. static inline int gpio_to_irq(unsigned int gpio)
  154. {
  155. return au1300_gpio_to_irq(gpio);
  156. }
  157. static inline int irq_to_gpio(unsigned int irq)
  158. {
  159. return au1300_irq_to_gpio(irq);
  160. }
  161. static inline int gpio_request(unsigned int gpio, const char *label)
  162. {
  163. return 0;
  164. }
  165. static inline void gpio_free(unsigned int gpio)
  166. {
  167. }
  168. static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
  169. {
  170. return -ENOSYS;
  171. }
  172. static inline void gpio_unexport(unsigned gpio)
  173. {
  174. }
  175. static inline int gpio_export(unsigned gpio, bool direction_may_change)
  176. {
  177. return -ENOSYS;
  178. }
  179. static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
  180. {
  181. return -ENOSYS;
  182. }
  183. static inline int gpio_export_link(struct device *dev, const char *name,
  184. unsigned gpio)
  185. {
  186. return -ENOSYS;
  187. }
  188. #endif /* !CONFIG_ALCHEMY_GPIO_INDIRECT */
  189. #endif /* CONFIG_ALCHEMY_GPIOINT_AU1300 */
  190. #endif /* CONFIG GPIOLIB */
  191. #endif /* _GPIO_AU1300_H_ */