otg.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. if (x)
  42. put_device(x->dev);
  43. }
  44. EXPORT_SYMBOL(otg_put_transceiver);
  45. /**
  46. * otg_set_transceiver - declare the (single) OTG transceiver
  47. * @x: the USB OTG transceiver to be used; or NULL
  48. *
  49. * This call is exclusively for use by transceiver drivers, which
  50. * coordinate the activities of drivers for host and peripheral
  51. * controllers, and in some cases for VBUS current regulation.
  52. */
  53. int otg_set_transceiver(struct otg_transceiver *x)
  54. {
  55. if (xceiv && x)
  56. return -EBUSY;
  57. xceiv = x;
  58. return 0;
  59. }
  60. EXPORT_SYMBOL(otg_set_transceiver);
  61. const char *otg_state_string(enum usb_otg_state state)
  62. {
  63. switch (state) {
  64. case OTG_STATE_A_IDLE:
  65. return "a_idle";
  66. case OTG_STATE_A_WAIT_VRISE:
  67. return "a_wait_vrise";
  68. case OTG_STATE_A_WAIT_BCON:
  69. return "a_wait_bcon";
  70. case OTG_STATE_A_HOST:
  71. return "a_host";
  72. case OTG_STATE_A_SUSPEND:
  73. return "a_suspend";
  74. case OTG_STATE_A_PERIPHERAL:
  75. return "a_peripheral";
  76. case OTG_STATE_A_WAIT_VFALL:
  77. return "a_wait_vfall";
  78. case OTG_STATE_A_VBUS_ERR:
  79. return "a_vbus_err";
  80. case OTG_STATE_B_IDLE:
  81. return "b_idle";
  82. case OTG_STATE_B_SRP_INIT:
  83. return "b_srp_init";
  84. case OTG_STATE_B_PERIPHERAL:
  85. return "b_peripheral";
  86. case OTG_STATE_B_WAIT_ACON:
  87. return "b_wait_acon";
  88. case OTG_STATE_B_HOST:
  89. return "b_host";
  90. default:
  91. return "UNDEFINED";
  92. }
  93. }
  94. EXPORT_SYMBOL(otg_state_string);