gpio.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 <asm/mach-bcm47xx/bcm47xx.h>
  12. #define BCM47XX_EXTIF_GPIO_LINES 5
  13. #define BCM47XX_CHIPCO_GPIO_LINES 16
  14. extern int gpio_request(unsigned gpio, const char *label);
  15. extern void gpio_free(unsigned gpio);
  16. extern int gpio_to_irq(unsigned gpio);
  17. static inline int gpio_get_value(unsigned gpio)
  18. {
  19. switch (bcm47xx_bus_type) {
  20. #ifdef CONFIG_BCM47XX_SSB
  21. case BCM47XX_BUS_TYPE_SSB:
  22. return ssb_gpio_in(&bcm47xx_bus.ssb, 1 << gpio);
  23. #endif
  24. }
  25. return -EINVAL;
  26. }
  27. static inline void gpio_set_value(unsigned gpio, int value)
  28. {
  29. switch (bcm47xx_bus_type) {
  30. #ifdef CONFIG_BCM47XX_SSB
  31. case BCM47XX_BUS_TYPE_SSB:
  32. ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
  33. value ? 1 << gpio : 0);
  34. #endif
  35. }
  36. }
  37. static inline int gpio_direction_input(unsigned gpio)
  38. {
  39. switch (bcm47xx_bus_type) {
  40. #ifdef CONFIG_BCM47XX_SSB
  41. case BCM47XX_BUS_TYPE_SSB:
  42. ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 0);
  43. return 0;
  44. #endif
  45. }
  46. return -EINVAL;
  47. }
  48. static inline int gpio_direction_output(unsigned gpio, int value)
  49. {
  50. switch (bcm47xx_bus_type) {
  51. #ifdef CONFIG_BCM47XX_SSB
  52. case BCM47XX_BUS_TYPE_SSB:
  53. /* first set the gpio out value */
  54. ssb_gpio_out(&bcm47xx_bus.ssb, 1 << gpio,
  55. value ? 1 << gpio : 0);
  56. /* then set the gpio mode */
  57. ssb_gpio_outen(&bcm47xx_bus.ssb, 1 << gpio, 1 << gpio);
  58. return 0;
  59. #endif
  60. }
  61. return -EINVAL;
  62. }
  63. static inline int gpio_intmask(unsigned gpio, int value)
  64. {
  65. switch (bcm47xx_bus_type) {
  66. #ifdef CONFIG_BCM47XX_SSB
  67. case BCM47XX_BUS_TYPE_SSB:
  68. ssb_gpio_intmask(&bcm47xx_bus.ssb, 1 << gpio,
  69. value ? 1 << gpio : 0);
  70. return 0;
  71. #endif
  72. }
  73. return -EINVAL;
  74. }
  75. static inline int gpio_polarity(unsigned gpio, int value)
  76. {
  77. switch (bcm47xx_bus_type) {
  78. #ifdef CONFIG_BCM47XX_SSB
  79. case BCM47XX_BUS_TYPE_SSB:
  80. ssb_gpio_polarity(&bcm47xx_bus.ssb, 1 << gpio,
  81. value ? 1 << gpio : 0);
  82. return 0;
  83. #endif
  84. }
  85. return -EINVAL;
  86. }
  87. /* cansleep wrappers */
  88. #include <asm-generic/gpio.h>
  89. #endif /* __BCM47XX_GPIO_H */