of.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * USB of helper code
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/module.h>
  7. #include <linux/of.h>
  8. #include <linux/usb/of.h>
  9. #include <linux/usb/otg.h>
  10. static const char *const usbphy_modes[] = {
  11. [USBPHY_INTERFACE_MODE_UNKNOWN] = "",
  12. [USBPHY_INTERFACE_MODE_UTMI] = "utmi",
  13. [USBPHY_INTERFACE_MODE_UTMIW] = "utmi_wide",
  14. [USBPHY_INTERFACE_MODE_ULPI] = "ulpi",
  15. [USBPHY_INTERFACE_MODE_SERIAL] = "serial",
  16. [USBPHY_INTERFACE_MODE_HSIC] = "hsic",
  17. };
  18. /**
  19. * of_usb_get_phy_mode - Get phy mode for given device_node
  20. * @np: Pointer to the given device_node
  21. *
  22. * The function gets phy interface string from property 'phy_type',
  23. * and returns the corresponding enum usb_phy_interface
  24. */
  25. enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np)
  26. {
  27. const char *phy_type;
  28. int err, i;
  29. err = of_property_read_string(np, "phy_type", &phy_type);
  30. if (err < 0)
  31. return USBPHY_INTERFACE_MODE_UNKNOWN;
  32. for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++)
  33. if (!strcmp(phy_type, usbphy_modes[i]))
  34. return i;
  35. return USBPHY_INTERFACE_MODE_UNKNOWN;
  36. }
  37. EXPORT_SYMBOL_GPL(of_usb_get_phy_mode);