gpio.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. static inline void gpio_set_value(unsigned gpio, int value)
  34. {
  35. switch (bcm47xx_bus_type) {
  36. #ifdef CONFIG_BCM47XX_SSB
  37. case BCM47XX_BUS_TYPE_SSB:
  38. ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
  39. value ? 1 << gpio : 0);
  40. return;
  41. #endif
  42. #ifdef CONFIG_BCM47XX_BCMA
  43. case BCM47XX_BUS_TYPE_BCMA:
  44. bcma_chipco_gpio_out(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
  45. value ? 1 << gpio : 0);
  46. return;
  47. #endif
  48. }
  49. }
  50. static inline int gpio_direction_input(unsigned gpio)
  51. {
  52. switch (bcm47xx_bus_type) {
  53. #ifdef CONFIG_BCM47XX_SSB
  54. case BCM47XX_BUS_TYPE_SSB:
  55. ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 0);
  56. return 0;
  57. #endif
  58. #ifdef CONFIG_BCM47XX_BCMA
  59. case BCM47XX_BUS_TYPE_BCMA:
  60. bcma_chipco_gpio_outen(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
  61. 0);
  62. return 0;
  63. #endif
  64. }
  65. return -EINVAL;
  66. }
  67. static inline int gpio_direction_output(unsigned gpio, int value)
  68. {
  69. switch (bcm47xx_bus_type) {
  70. #ifdef CONFIG_BCM47XX_SSB
  71. case BCM47XX_BUS_TYPE_SSB:
  72. /* first set the gpio out value */
  73. ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
  74. value ? 1 << gpio : 0);
  75. /* then set the gpio mode */
  76. ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 1 << gpio);
  77. return 0;
  78. #endif
  79. #ifdef CONFIG_BCM47XX_BCMA
  80. case BCM47XX_BUS_TYPE_BCMA:
  81. /* first set the gpio out value */
  82. bcma_chipco_gpio_out(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
  83. value ? 1 << gpio : 0);
  84. /* then set the gpio mode */
  85. bcma_chipco_gpio_outen(&bcm47xx_bus.bcma.bus.drv_cc, 1 << gpio,
  86. 1 << gpio);
  87. return 0;
  88. #endif
  89. }
  90. return -EINVAL;
  91. }
  92. static inline int gpio_intmask(unsigned gpio, int value)
  93. {
  94. switch (bcm47xx_bus_type) {
  95. #ifdef CONFIG_BCM47XX_SSB
  96. case BCM47XX_BUS_TYPE_SSB:
  97. ssb_gpio_intmask(&bcm47xx_bus.ssb, 1 << gpio,
  98. value ? 1 << gpio : 0);
  99. return 0;
  100. #endif
  101. #ifdef CONFIG_BCM47XX_BCMA
  102. case BCM47XX_BUS_TYPE_BCMA:
  103. bcma_chipco_gpio_intmask(&bcm47xx_bus.bcma.bus.drv_cc,
  104. 1 << gpio, value ? 1 << gpio : 0);
  105. return 0;
  106. #endif
  107. }
  108. return -EINVAL;
  109. }
  110. static inline int gpio_polarity(unsigned gpio, int value)
  111. {
  112. switch (bcm47xx_bus_type) {
  113. #ifdef CONFIG_BCM47XX_SSB
  114. case BCM47XX_BUS_TYPE_SSB:
  115. ssb_gpio_polarity(&bcm47xx_bus.ssb, 1 << gpio,
  116. value ? 1 << gpio : 0);
  117. return 0;
  118. #endif
  119. #ifdef CONFIG_BCM47XX_BCMA
  120. case BCM47XX_BUS_TYPE_BCMA:
  121. bcma_chipco_gpio_polarity(&bcm47xx_bus.bcma.bus.drv_cc,
  122. 1 << gpio, value ? 1 << gpio : 0);
  123. return 0;
  124. #endif
  125. }
  126. return -EINVAL;
  127. }
  128. /* cansleep wrappers */
  129. #include <asm-generic/gpio.h>
  130. #endif /* __BCM47XX_GPIO_H */