common.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 <linux/libfdt.h>
  10. #include <linux/usb/otg.h>
  11. #include <linux/usb/ch9.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. static const char *const usb_dr_modes[] = {
  14. [USB_DR_MODE_UNKNOWN] = "",
  15. [USB_DR_MODE_HOST] = "host",
  16. [USB_DR_MODE_PERIPHERAL] = "peripheral",
  17. [USB_DR_MODE_OTG] = "otg",
  18. };
  19. enum usb_dr_mode usb_get_dr_mode(int node)
  20. {
  21. const void *fdt = gd->fdt_blob;
  22. const char *dr_mode;
  23. int i;
  24. dr_mode = fdt_getprop(fdt, node, "dr_mode", NULL);
  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(int node)
  43. {
  44. const void *fdt = gd->fdt_blob;
  45. const char *max_speed;
  46. int i;
  47. max_speed = fdt_getprop(fdt, node, "maximum-speed", NULL);
  48. if (!max_speed) {
  49. pr_err("usb maximum-speed not found\n");
  50. return USB_SPEED_UNKNOWN;
  51. }
  52. for (i = 0; i < ARRAY_SIZE(speed_names); i++)
  53. if (!strcmp(max_speed, speed_names[i]))
  54. return i;
  55. return USB_SPEED_UNKNOWN;
  56. }