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