gpio.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include <linux/ssb/ssb.h>
  9. #include <linux/ssb/ssb_driver_chipcommon.h>
  10. #include <linux/ssb/ssb_driver_extif.h>
  11. #include <asm/mach-bcm47xx/bcm47xx.h>
  12. #include <asm/mach-bcm47xx/gpio.h>
  13. int bcm47xx_gpio_to_irq(unsigned gpio)
  14. {
  15. if (ssb_bcm47xx.chipco.dev)
  16. return ssb_mips_irq(ssb_bcm47xx.chipco.dev) + 2;
  17. else if (ssb_bcm47xx.extif.dev)
  18. return ssb_mips_irq(ssb_bcm47xx.extif.dev) + 2;
  19. else
  20. return -EINVAL;
  21. }
  22. EXPORT_SYMBOL_GPL(bcm47xx_gpio_to_irq);
  23. int bcm47xx_gpio_get_value(unsigned gpio)
  24. {
  25. if (ssb_bcm47xx.chipco.dev)
  26. return ssb_chipco_gpio_in(&ssb_bcm47xx.chipco, 1 << gpio);
  27. else if (ssb_bcm47xx.extif.dev)
  28. return ssb_extif_gpio_in(&ssb_bcm47xx.extif, 1 << gpio);
  29. else
  30. return 0;
  31. }
  32. EXPORT_SYMBOL_GPL(bcm47xx_gpio_get_value);
  33. void bcm47xx_gpio_set_value(unsigned gpio, int value)
  34. {
  35. if (ssb_bcm47xx.chipco.dev)
  36. ssb_chipco_gpio_out(&ssb_bcm47xx.chipco,
  37. 1 << gpio,
  38. value ? 1 << gpio : 0);
  39. else if (ssb_bcm47xx.extif.dev)
  40. ssb_extif_gpio_out(&ssb_bcm47xx.extif,
  41. 1 << gpio,
  42. value ? 1 << gpio : 0);
  43. }
  44. EXPORT_SYMBOL_GPL(bcm47xx_gpio_set_value);
  45. int bcm47xx_gpio_direction_input(unsigned gpio)
  46. {
  47. if (ssb_bcm47xx.chipco.dev && (gpio < BCM47XX_CHIPCO_GPIO_LINES))
  48. ssb_chipco_gpio_outen(&ssb_bcm47xx.chipco,
  49. 1 << gpio, 0);
  50. else if (ssb_bcm47xx.extif.dev && (gpio < BCM47XX_EXTIF_GPIO_LINES))
  51. ssb_extif_gpio_outen(&ssb_bcm47xx.extif,
  52. 1 << gpio, 0);
  53. else
  54. return -EINVAL;
  55. return 0;
  56. }
  57. EXPORT_SYMBOL_GPL(bcm47xx_gpio_direction_input);
  58. int bcm47xx_gpio_direction_output(unsigned gpio, int value)
  59. {
  60. bcm47xx_gpio_set_value(gpio, value);
  61. if (ssb_bcm47xx.chipco.dev && (gpio < BCM47XX_CHIPCO_GPIO_LINES))
  62. ssb_chipco_gpio_outen(&ssb_bcm47xx.chipco,
  63. 1 << gpio, 1 << gpio);
  64. else if (ssb_bcm47xx.extif.dev && (gpio < BCM47XX_EXTIF_GPIO_LINES))
  65. ssb_extif_gpio_outen(&ssb_bcm47xx.extif,
  66. 1 << gpio, 1 << gpio);
  67. else
  68. return -EINVAL;
  69. return 0;
  70. }
  71. EXPORT_SYMBOL_GPL(bcm47xx_gpio_direction_output);