of.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * USB of helper code
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/of.h>
  12. #include <linux/usb/of.h>
  13. #include <linux/usb/otg.h>
  14. static const char *const usbphy_modes[] = {
  15. [USBPHY_INTERFACE_MODE_UNKNOWN] = "",
  16. [USBPHY_INTERFACE_MODE_UTMI] = "utmi",
  17. [USBPHY_INTERFACE_MODE_UTMIW] = "utmi_wide",
  18. [USBPHY_INTERFACE_MODE_ULPI] = "ulpi",
  19. [USBPHY_INTERFACE_MODE_SERIAL] = "serial",
  20. [USBPHY_INTERFACE_MODE_HSIC] = "hsic",
  21. };
  22. /**
  23. * of_usb_get_phy_mode - Get phy mode for given device_node
  24. * @np: Pointer to the given device_node
  25. *
  26. * The function gets phy interface string from property 'phy_type',
  27. * and returns the corresponding enum usb_phy_interface
  28. */
  29. enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np)
  30. {
  31. const char *phy_type;
  32. int err, i;
  33. err = of_property_read_string(np, "phy_type", &phy_type);
  34. if (err < 0)
  35. return USBPHY_INTERFACE_MODE_UNKNOWN;
  36. for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++)
  37. if (!strcmp(phy_type, usbphy_modes[i]))
  38. return i;
  39. return USBPHY_INTERFACE_MODE_UNKNOWN;
  40. }
  41. EXPORT_SYMBOL_GPL(of_usb_get_phy_mode);