common.c 839 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Provides code common for host and device side USB.
  3. *
  4. * (C) Copyright 2016
  5. * Texas Instruments Incorporated, <www.ti.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <libfdt.h>
  11. #include <linux/usb/otg.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. error("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. }