gpio-au1300.h 5.5 KB

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