gpio.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #if (BCM47XX_CHIPCO_GPIO_LINES > BCM47XX_EXTIF_GPIO_LINES)
  14. static DECLARE_BITMAP(gpio_in_use, BCM47XX_CHIPCO_GPIO_LINES);
  15. #else
  16. static DECLARE_BITMAP(gpio_in_use, BCM47XX_EXTIF_GPIO_LINES);
  17. #endif
  18. int gpio_request(unsigned gpio, const char *tag)
  19. {
  20. if (ssb_chipco_available(&ssb_bcm47xx.chipco) &&
  21. ((unsigned)gpio >= BCM47XX_CHIPCO_GPIO_LINES))
  22. return -EINVAL;
  23. if (ssb_extif_available(&ssb_bcm47xx.extif) &&
  24. ((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES))
  25. return -EINVAL;
  26. if (test_and_set_bit(gpio, gpio_in_use))
  27. return -EBUSY;
  28. return 0;
  29. }
  30. EXPORT_SYMBOL(gpio_request);
  31. void gpio_free(unsigned gpio)
  32. {
  33. if (ssb_chipco_available(&ssb_bcm47xx.chipco) &&
  34. ((unsigned)gpio >= BCM47XX_CHIPCO_GPIO_LINES))
  35. return;
  36. if (ssb_extif_available(&ssb_bcm47xx.extif) &&
  37. ((unsigned)gpio >= BCM47XX_EXTIF_GPIO_LINES))
  38. return;
  39. clear_bit(gpio, gpio_in_use);
  40. }
  41. EXPORT_SYMBOL(gpio_free);
  42. int gpio_to_irq(unsigned gpio)
  43. {
  44. if (ssb_chipco_available(&ssb_bcm47xx.chipco))
  45. return ssb_mips_irq(ssb_bcm47xx.chipco.dev) + 2;
  46. else if (ssb_extif_available(&ssb_bcm47xx.extif))
  47. return ssb_mips_irq(ssb_bcm47xx.extif.dev) + 2;
  48. else
  49. return -EINVAL;
  50. }
  51. EXPORT_SYMBOL_GPL(gpio_to_irq);