Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * USB of helper code
0004  */
0005 
0006 #include <linux/kernel.h>
0007 #include <linux/module.h>
0008 #include <linux/of.h>
0009 #include <linux/usb/of.h>
0010 #include <linux/usb/otg.h>
0011 
0012 static const char *const usbphy_modes[] = {
0013     [USBPHY_INTERFACE_MODE_UNKNOWN] = "",
0014     [USBPHY_INTERFACE_MODE_UTMI]    = "utmi",
0015     [USBPHY_INTERFACE_MODE_UTMIW]   = "utmi_wide",
0016     [USBPHY_INTERFACE_MODE_ULPI]    = "ulpi",
0017     [USBPHY_INTERFACE_MODE_SERIAL]  = "serial",
0018     [USBPHY_INTERFACE_MODE_HSIC]    = "hsic",
0019 };
0020 
0021 /**
0022  * of_usb_get_phy_mode - Get phy mode for given device_node
0023  * @np: Pointer to the given device_node
0024  *
0025  * The function gets phy interface string from property 'phy_type',
0026  * and returns the corresponding enum usb_phy_interface
0027  */
0028 enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np)
0029 {
0030     const char *phy_type;
0031     int err, i;
0032 
0033     err = of_property_read_string(np, "phy_type", &phy_type);
0034     if (err < 0)
0035         return USBPHY_INTERFACE_MODE_UNKNOWN;
0036 
0037     for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++)
0038         if (!strcmp(phy_type, usbphy_modes[i]))
0039             return i;
0040 
0041     return USBPHY_INTERFACE_MODE_UNKNOWN;
0042 }
0043 EXPORT_SYMBOL_GPL(of_usb_get_phy_mode);