aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Grzeschik <m.grzeschik@pengutronix.de>2013-06-13 10:59:55 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-06-17 16:47:09 -0400
commit1c9af65357a309b60d78a442bd61d27cad458d00 (patch)
tree5768aa043e4597b4691fcebe8bc7706487379ce8
parent2e270412968d961ecde347343ffa67dfe39f6c95 (diff)
usb: add devicetree helpers for determining dr_mode and phy_type
This adds two little devicetree helper functions for determining the dr_mode (host, peripheral, otg) and phy_type (utmi, ulpi,...) from the devicetree. Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Acked-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/usb/phy/Makefile1
-rw-r--r--drivers/usb/phy/of.c47
-rw-r--r--drivers/usb/usb-common.c35
-rw-r--r--include/linux/usb/of.h28
-rw-r--r--include/linux/usb/otg.h7
-rw-r--r--include/linux/usb/phy.h9
6 files changed, 127 insertions, 0 deletions
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index a9169cb1e6fc..070eca3af18b 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -5,6 +5,7 @@
5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG 5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
6 6
7obj-$(CONFIG_USB_PHY) += phy.o 7obj-$(CONFIG_USB_PHY) += phy.o
8obj-$(CONFIG_OF) += of.o
8 9
9# transceiver drivers, keep the list sorted 10# transceiver drivers, keep the list sorted
10 11
diff --git a/drivers/usb/phy/of.c b/drivers/usb/phy/of.c
new file mode 100644
index 000000000000..7ea0154da9d5
--- /dev/null
+++ b/drivers/usb/phy/of.c
@@ -0,0 +1,47 @@
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
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/of.h>
13#include <linux/usb/of.h>
14#include <linux/usb/otg.h>
15
16static const char *const usbphy_modes[] = {
17 [USBPHY_INTERFACE_MODE_UNKNOWN] = "",
18 [USBPHY_INTERFACE_MODE_UTMI] = "utmi",
19 [USBPHY_INTERFACE_MODE_UTMIW] = "utmi_wide",
20 [USBPHY_INTERFACE_MODE_ULPI] = "ulpi",
21 [USBPHY_INTERFACE_MODE_SERIAL] = "serial",
22 [USBPHY_INTERFACE_MODE_HSIC] = "hsic",
23};
24
25/**
26 * of_usb_get_phy_mode - Get phy mode for given device_node
27 * @np: Pointer to the given device_node
28 *
29 * The function gets phy interface string from property 'phy_type',
30 * and returns the correspondig enum usb_phy_interface
31 */
32enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np)
33{
34 const char *phy_type;
35 int err, i;
36
37 err = of_property_read_string(np, "phy_type", &phy_type);
38 if (err < 0)
39 return USBPHY_INTERFACE_MODE_UNKNOWN;
40
41 for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++)
42 if (!strcmp(phy_type, usbphy_modes[i]))
43 return i;
44
45 return USBPHY_INTERFACE_MODE_UNKNOWN;
46}
47EXPORT_SYMBOL_GPL(of_usb_get_phy_mode);
diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
index 0db0a919d72b..675384dabfe9 100644
--- a/drivers/usb/usb-common.c
+++ b/drivers/usb/usb-common.c
@@ -13,7 +13,9 @@
13 13
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/of.h>
16#include <linux/usb/ch9.h> 17#include <linux/usb/ch9.h>
18#include <linux/usb/of.h>
17#include <linux/usb/otg.h> 19#include <linux/usb/otg.h>
18 20
19const char *usb_otg_state_string(enum usb_otg_state state) 21const char *usb_otg_state_string(enum usb_otg_state state)
@@ -79,4 +81,37 @@ const char *usb_state_string(enum usb_device_state state)
79} 81}
80EXPORT_SYMBOL_GPL(usb_state_string); 82EXPORT_SYMBOL_GPL(usb_state_string);
81 83
84#ifdef CONFIG_OF
85static const char *const usb_dr_modes[] = {
86 [USB_DR_MODE_UNKNOWN] = "",
87 [USB_DR_MODE_HOST] = "host",
88 [USB_DR_MODE_PERIPHERAL] = "peripheral",
89 [USB_DR_MODE_OTG] = "otg",
90};
91
92/**
93 * of_usb_get_dr_mode - Get dual role mode for given device_node
94 * @np: Pointer to the given device_node
95 *
96 * The function gets phy interface string from property 'dr_mode',
97 * and returns the correspondig enum usb_dr_mode
98 */
99enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
100{
101 const char *dr_mode;
102 int err, i;
103
104 err = of_property_read_string(np, "dr_mode", &dr_mode);
105 if (err < 0)
106 return USB_DR_MODE_UNKNOWN;
107
108 for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
109 if (!strcmp(dr_mode, usb_dr_modes[i]))
110 return i;
111
112 return USB_DR_MODE_UNKNOWN;
113}
114EXPORT_SYMBOL_GPL(of_usb_get_dr_mode);
115#endif
116
82MODULE_LICENSE("GPL"); 117MODULE_LICENSE("GPL");
diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h
new file mode 100644
index 000000000000..e460a24115ca
--- /dev/null
+++ b/include/linux/usb/of.h
@@ -0,0 +1,28 @@
1/*
2 * OF helpers for usb devices.
3 *
4 * This file is released under the GPLv2
5 */
6
7#ifndef __LINUX_USB_OF_H
8#define __LINUX_USB_OF_H
9
10#include <linux/usb/otg.h>
11#include <linux/usb/phy.h>
12
13#ifdef CONFIG_OF
14enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np);
15enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np);
16#else
17static inline enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np)
18{
19 return USBPHY_INTERFACE_MODE_UNKNOWN;
20}
21
22static inline enum usb_dr_mode of_usb_get_dr_mode(struct device_node *np)
23{
24 return USB_DR_MODE_UNKNOWN;
25}
26#endif
27
28#endif /* __LINUX_USB_OF_H */
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index 291e01ba32e5..154332b7c8c0 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -92,4 +92,11 @@ otg_start_srp(struct usb_otg *otg)
92/* for OTG controller drivers (and maybe other stuff) */ 92/* for OTG controller drivers (and maybe other stuff) */
93extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num); 93extern int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num);
94 94
95enum usb_dr_mode {
96 USB_DR_MODE_UNKNOWN,
97 USB_DR_MODE_HOST,
98 USB_DR_MODE_PERIPHERAL,
99 USB_DR_MODE_OTG,
100};
101
95#endif /* __LINUX_USB_OTG_H */ 102#endif /* __LINUX_USB_OTG_H */
diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
index 6b5978f57633..44036808bf0f 100644
--- a/include/linux/usb/phy.h
+++ b/include/linux/usb/phy.h
@@ -12,6 +12,15 @@
12#include <linux/notifier.h> 12#include <linux/notifier.h>
13#include <linux/usb.h> 13#include <linux/usb.h>
14 14
15enum usb_phy_interface {
16 USBPHY_INTERFACE_MODE_UNKNOWN,
17 USBPHY_INTERFACE_MODE_UTMI,
18 USBPHY_INTERFACE_MODE_UTMIW,
19 USBPHY_INTERFACE_MODE_ULPI,
20 USBPHY_INTERFACE_MODE_SERIAL,
21 USBPHY_INTERFACE_MODE_HSIC,
22};
23
15enum usb_phy_events { 24enum usb_phy_events {
16 USB_EVENT_NONE, /* no events or cable disconnected */ 25 USB_EVENT_NONE, /* no events or cable disconnected */
17 USB_EVENT_VBUS, /* vbus valid event */ 26 USB_EVENT_VBUS, /* vbus valid event */