gpio.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2007 Aurelien Jarno <aurelien@aurel32.net>
  7. */
  8. #ifndef __BCM47XX_GPIO_H
  9. #define __BCM47XX_GPIO_H
  10. #include <linux/ssb/ssb_embedded.h>
  11. #include <linux/bcma/bcma.h>
  12. #include <asm/mach-bcm47xx/bcm47xx.h>
  13. #define BCM47XX_EXTIF_GPIO_LINES 5
  14. #define BCM47XX_CHIPCO_GPIO_LINES 16
  15. extern int gpio_request(unsigned gpio, const char *label);
  16. extern void gpio_free(unsigned gpio);
  17. extern int gpio_to_irq(unsigned gpio);
  18. static inline int gpio_get_value(unsigned gpio)
  19. {
  20. switch (bcm47xx_bus_type) {
  21. #ifdef CONFIG_BCM47XX_SSB
  22. case BCM47XX_BUS_TYPE_SSB:
  23. return ssb_gpio_in(&bcm47xx_bus.ssb, 1 << gpio);
  24. #endif
  25. #ifdef CONFIG_BCM47XX_BCMA
  26. case BCM47XX_BUS_TYPE_BCMA:
  27. return bcma_chipco_gpio_in(&bcm47xx_bus.bcma.bus.drv_cc,
  28. 1 << gpio);
  29. #endif
  30. }
  31. return -EINVAL;
  32. }
  33. #define gpio_get_value_cansleep gpio_get_value
  34. static inline void gpio_set_value(unsigned gpio, int value)
  35. {
  36. switch (bcm47xx_bus_type) {
  37. #ifdef CONFIG_BCM47XX_SSB
  38. case BCM47XX_BUS_TYPE_SSB:
  39. ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
  40. value ? 1 << gpio : 0);
  41. return;
  42. #endif
  43. #ifdef CONFIG_BCM47XX_BCMA
  44. case BCM47XX_BUS_TYPE_BCMA:
  45. bcma_chipco_gpio_out(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
  46. value ? 1 << gpio : 0);
  47. return;
  48. #endif
  49. }
  50. }
  51. #define gpio_set_value_cansleep gpio_set_value
  52. static inline int gpio_cansleep(unsigned gpio)
  53. {
  54. return 0;
  55. }
  56. static inline int gpio_is_valid(unsigned gpio)
  57. {
  58. return gpio < (BCM47XX_EXTIF_GPIO_LINES + BCM47XX_CHIPCO_GPIO_LINES);
  59. }
  60. static inline int gpio_direction_input(unsigned gpio)
  61. {
  62. switch (bcm47xx_bus_type) {
  63. #ifdef CONFIG_BCM47XX_SSB
  64. case BCM47XX_BUS_TYPE_SSB:
  65. ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 0);
  66. return 0;
  67. #endif
  68. #ifdef CONFIG_BCM47XX_BCMA
  69. case BCM47XX_BUS_TYPE_BCMA:
  70. bcma_chipco_gpio_outen(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
  71. 0);
  72. return 0;
  73. #endif
  74. }
  75. return -EINVAL;
  76. }
  77. static inline int gpio_direction_output(unsigned gpio, int value)
  78. {
  79. switch (bcm47xx_bus_type) {
  80. #ifdef CONFIG_BCM47XX_SSB
  81. case BCM47XX_BUS_TYPE_SSB:
  82. /* first set the gpio out value */
  83. ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
  84. value ? 1 << gpio : 0);
  85. /* then set the gpio mode */
  86. ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 1 << gpio);
  87. return 0;
  88. #endif
  89. #ifdef CONFIG_BCM47XX_BCMA
  90. case BCM47XX_BUS_TYPE_BCMA:
  91. /* first set the gpio out value */
  92. bcma_chipco_gpio_out(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
  93. value ? 1 << gpio : 0);
  94. /* then set the gpio mode */
  95. bcma_chipco_gpio_outen(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
  96. 1 << gpio);
  97. return 0;
  98. #endif
  99. }
  100. return -EINVAL;
  101. }
  102. static inline int gpio_intmask(unsigned gpio, int value)
  103. {
  104. switch (bcm47xx_bus_type) {
  105. #ifdef CONFIG_BCM47XX_SSB
  106. case BCM47XX_BUS_TYPE_SSB:
  107. ssb_gpio_intmask(&bcm47xx_bus.ssb, 1 << gpio,
  108. value ? 1 << gpio : 0);
  109. return 0;
  110. #endif
  111. #ifdef CONFIG_BCM47XX_BCMA
  112. case BCM47XX_BUS_TYPE_BCMA:
  113. bcma_chipco_gpio_intmask(&bcm47xx_bus.bcma.bus.drv_cc,
  114. 1 << gpio, value ? 1 << gpio : 0);
  115. return 0;
  116. #endif
  117. }
  118. return -EINVAL;
  119. }
  120. static inline int gpio_polarity(unsigned gpio, int value)
  121. {
  122. switch (bcm47xx_bus_type) {
  123. #ifdef CONFIG_BCM47XX_SSB
  124. case BCM47XX_BUS_TYPE_SSB:
  125. ssb_gpio_polarity(&bcm47xx_bus.ssb, 1 << gpio,
  126. value ? 1 << gpio : 0);
  127. return 0;
  128. #endif
  129. #ifdef CONFIG_BCM47XX_BCMA
  130. case BCM47XX_BUS_TYPE_BCMA:
  131. bcma_chipco_gpio_polarity(&bcm47xx_bus.bcma.bus.drv_cc,
  132. 1 << gpio, value ? 1 << gpio : 0);
  133. return 0;
  134. #endif
  135. }
  136. return -EINVAL;
  137. }
  138. #endif /* __BCM47XX_GPIO_H */