otg.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * otg.c -- USB OTG utility code
  3. *
  4. * Copyright (C) 2004 Texas Instruments
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/device.h>
  13. #include <linux/usb/otg.h>
  14. static struct otg_transceiver *xceiv;
  15. /**
  16. * otg_get_transceiver - find the (single) OTG transceiver
  17. *
  18. * Returns the transceiver driver, after getting a refcount to it; or
  19. * null if there is no such transceiver. The caller is responsible for
  20. * calling otg_put_transceiver() to release that count.
  21. *
  22. * For use by USB host and peripheral drivers.
  23. */
  24. struct otg_transceiver *otg_get_transceiver(void)
  25. {
  26. if (xceiv)
  27. get_device(xceiv->dev);
  28. return xceiv;
  29. }
  30. EXPORT_SYMBOL(otg_get_transceiver);
  31. /**
  32. * otg_put_transceiver - release the (single) OTG transceiver
  33. * @x: the transceiver returned by otg_get_transceiver()
  34. *
  35. * Releases a refcount the caller received from otg_get_transceiver().
  36. *
  37. * For use by USB host and peripheral drivers.
  38. */
  39. void otg_put_transceiver(struct otg_transceiver *x)
  40. {
  41. put_device(x->dev);
  42. }
  43. EXPORT_SYMBOL(otg_put_transceiver);
  44. /**
  45. * otg_set_transceiver - declare the (single) OTG transceiver
  46. * @x: the USB OTG transceiver to be used; or NULL
  47. *
  48. * This call is exclusively for use by transceiver drivers, which
  49. * coordinate the activities of drivers for host and peripheral
  50. * controllers, and in some cases for VBUS current regulation.
  51. */
  52. int otg_set_transceiver(struct otg_transceiver *x)
  53. {
  54. if (xceiv && x)
  55. return -EBUSY;
  56. xceiv = x;
  57. return 0;
  58. }
  59. EXPORT_SYMBOL(otg_set_transceiver);