common.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Provides code common for host and device side USB.
  4. *
  5. * (C) Copyright 2016
  6. * Texas Instruments Incorporated, <www.ti.com>
  7. */
  8. #include <common.h>
  9. #include <dm.h>
  10. #include <linux/usb/otg.h>
  11. #include <linux/usb/ch9.h>
  12. #include <linux/usb/phy.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. static const char *const usb_dr_modes[] = {
  15. [USB_DR_MODE_UNKNOWN] = "",
  16. [USB_DR_MODE_HOST] = "host",
  17. [USB_DR_MODE_PERIPHERAL] = "peripheral",
  18. [USB_DR_MODE_OTG] = "otg",
  19. };
  20. enum usb_dr_mode usb_get_dr_mode(ofnode node)
  21. {
  22. const char *dr_mode;
  23. int i;
  24. dr_mode = ofnode_read_string(node, "dr_mode");
  25. if (!dr_mode) {
  26. pr_err("usb dr_mode not found\n");
  27. return USB_DR_MODE_UNKNOWN;
  28. }
  29. for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
  30. if (!strcmp(dr_mode, usb_dr_modes[i]))
  31. return i;
  32. return USB_DR_MODE_UNKNOWN;
  33. }
  34. static const char *const speed_names[] = {
  35. [USB_SPEED_UNKNOWN] = "UNKNOWN",
  36. [USB_SPEED_LOW] = "low-speed",
  37. [USB_SPEED_FULL] = "full-speed",
  38. [USB_SPEED_HIGH] = "high-speed",
  39. [USB_SPEED_WIRELESS] = "wireless",
  40. [USB_SPEED_SUPER] = "super-speed",
  41. };
  42. enum usb_device_speed usb_get_maximum_speed(ofnode node)
  43. {
  44. const char *max_speed;
  45. int i;
  46. max_speed = ofnode_read_string(node, "maximum-speed");
  47. if (!max_speed) {
  48. pr_err("usb maximum-speed not found\n");
  49. return USB_SPEED_UNKNOWN;
  50. }
  51. for (i = 0; i < ARRAY_SIZE(speed_names); i++)
  52. if (!strcmp(max_speed, speed_names[i]))
  53. return i;
  54. return USB_SPEED_UNKNOWN;
  55. }
  56. #if CONFIG_IS_ENABLED(DM_USB)
  57. static const char *const usbphy_modes[] = {
  58. [USBPHY_INTERFACE_MODE_UNKNOWN] = "",
  59. [USBPHY_INTERFACE_MODE_UTMI] = "utmi",
  60. [USBPHY_INTERFACE_MODE_UTMIW] = "utmi_wide",
  61. };
  62. enum usb_phy_interface usb_get_phy_mode(ofnode node)
  63. {
  64. const char *phy_type;
  65. int i;
  66. phy_type = ofnode_get_property(node, "phy_type", NULL);
  67. if (!phy_type)
  68. return USBPHY_INTERFACE_MODE_UNKNOWN;
  69. for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++)
  70. if (!strcmp(phy_type, usbphy_modes[i]))
  71. return i;
  72. return USBPHY_INTERFACE_MODE_UNKNOWN;
  73. }
  74. #endif