usb-common.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Provides code common for host and device side USB.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation, version 2.
  7. *
  8. * If either host side (ie. CONFIG_USB=y) or device side USB stack
  9. * (ie. CONFIG_USB_GADGET=y) is compiled in the kernel, this module is
  10. * compiled-in as well. Otherwise, if either of the two stacks is
  11. * compiled as module, this file is compiled as module as well.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/usb/ch9.h>
  16. #include <linux/usb/otg.h>
  17. const char *usb_otg_state_string(enum usb_otg_state state)
  18. {
  19. static const char *const names[] = {
  20. [OTG_STATE_A_IDLE] = "a_idle",
  21. [OTG_STATE_A_WAIT_VRISE] = "a_wait_vrise",
  22. [OTG_STATE_A_WAIT_BCON] = "a_wait_bcon",
  23. [OTG_STATE_A_HOST] = "a_host",
  24. [OTG_STATE_A_SUSPEND] = "a_suspend",
  25. [OTG_STATE_A_PERIPHERAL] = "a_peripheral",
  26. [OTG_STATE_A_WAIT_VFALL] = "a_wait_vfall",
  27. [OTG_STATE_A_VBUS_ERR] = "a_vbus_err",
  28. [OTG_STATE_B_IDLE] = "b_idle",
  29. [OTG_STATE_B_SRP_INIT] = "b_srp_init",
  30. [OTG_STATE_B_PERIPHERAL] = "b_peripheral",
  31. [OTG_STATE_B_WAIT_ACON] = "b_wait_acon",
  32. [OTG_STATE_B_HOST] = "b_host",
  33. };
  34. if (state < 0 || state >= ARRAY_SIZE(names))
  35. return "UNDEFINED";
  36. return names[state];
  37. }
  38. EXPORT_SYMBOL_GPL(usb_otg_state_string);
  39. const char *usb_speed_string(enum usb_device_speed speed)
  40. {
  41. static const char *const names[] = {
  42. [USB_SPEED_UNKNOWN] = "UNKNOWN",
  43. [USB_SPEED_LOW] = "low-speed",
  44. [USB_SPEED_FULL] = "full-speed",
  45. [USB_SPEED_HIGH] = "high-speed",
  46. [USB_SPEED_WIRELESS] = "wireless",
  47. [USB_SPEED_SUPER] = "super-speed",
  48. };
  49. if (speed < 0 || speed >= ARRAY_SIZE(names))
  50. speed = USB_SPEED_UNKNOWN;
  51. return names[speed];
  52. }
  53. EXPORT_SYMBOL_GPL(usb_speed_string);
  54. const char *usb_state_string(enum usb_device_state state)
  55. {
  56. static const char *const names[] = {
  57. [USB_STATE_NOTATTACHED] = "not attached",
  58. [USB_STATE_ATTACHED] = "attached",
  59. [USB_STATE_POWERED] = "powered",
  60. [USB_STATE_RECONNECTING] = "reconnecting",
  61. [USB_STATE_UNAUTHENTICATED] = "unauthenticated",
  62. [USB_STATE_DEFAULT] = "default",
  63. [USB_STATE_ADDRESS] = "addresssed",
  64. [USB_STATE_CONFIGURED] = "configured",
  65. [USB_STATE_SUSPENDED] = "suspended",
  66. };
  67. if (state < 0 || state >= ARRAY_SIZE(names))
  68. return "UNKNOWN";
  69. return names[state];
  70. }
  71. EXPORT_SYMBOL_GPL(usb_state_string);
  72. MODULE_LICENSE("GPL");