kernel: split patches folder up into backport, pending and hack folders
[openwrt/openwrt.git] / target / linux / generic / pending-4.4 / 082-0001-USB-core-let-USB-device-know-device-node.patch
1 From 69bec725985324e79b1c47ea287815ac4ddb0521 Mon Sep 17 00:00:00 2001
2 From: Peter Chen <peter.chen@freescale.com>
3 Date: Fri, 19 Feb 2016 17:26:15 +0800
4 Subject: [PATCH] USB: core: let USB device know device node
5
6 Although most of USB devices are hot-plug's, there are still some devices
7 are hard wired on the board, eg, for HSIC and SSIC interface USB devices.
8 If these kinds of USB devices are multiple functions, and they can supply
9 other interfaces like i2c, gpios for other devices, we may need to
10 describe these at device tree.
11
12 In this commit, it uses "reg" in dts as physical port number to match
13 the phyiscal port number decided by USB core, if they are the same,
14 then the device node is for the device we are creating for USB core.
15
16 Signed-off-by: Peter Chen <peter.chen@freescale.com>
17 Acked-by: Philipp Zabel <p.zabel@pengutronix.de>
18 Acked-by: Alan Stern <stern@rowland.harvard.edu>
19 Acked-by: Rob Herring <robh@kernel.org>
20 Acked-by: Arnd Bergmann <arnd@arndb.de>
21 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
22 ---
23 .../devicetree/bindings/usb/usb-device.txt | 28 +++++++++++++
24 drivers/usb/core/Makefile | 2 +-
25 drivers/usb/core/of.c | 47 ++++++++++++++++++++++
26 drivers/usb/core/usb.c | 10 +++++
27 include/linux/usb/of.h | 7 ++++
28 5 files changed, 93 insertions(+), 1 deletion(-)
29 create mode 100644 Documentation/devicetree/bindings/usb/usb-device.txt
30 create mode 100644 drivers/usb/core/of.c
31
32 --- /dev/null
33 +++ b/Documentation/devicetree/bindings/usb/usb-device.txt
34 @@ -0,0 +1,28 @@
35 +Generic USB Device Properties
36 +
37 +Usually, we only use device tree for hard wired USB device.
38 +The reference binding doc is from:
39 +http://www.firmware.org/1275/bindings/usb/usb-1_0.ps
40 +
41 +Required properties:
42 +- compatible: usbVID,PID. The textual representation of VID, PID shall
43 + be in lower case hexadecimal with leading zeroes suppressed. The
44 + other compatible strings from the above standard binding could also
45 + be used, but a device adhering to this binding may leave out all except
46 + for usbVID,PID.
47 +- reg: the port number which this device is connecting to, the range
48 + is 1-31.
49 +
50 +Example:
51 +
52 +&usb1 {
53 + status = "okay";
54 +
55 + #address-cells = <1>;
56 + #size-cells = <0>;
57 +
58 + hub: genesys@1 {
59 + compatible = "usb5e3,608";
60 + reg = <1>;
61 + };
62 +}
63 --- a/drivers/usb/core/Makefile
64 +++ b/drivers/usb/core/Makefile
65 @@ -5,7 +5,7 @@
66 usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o
67 usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o
68 usbcore-y += devio.o notify.o generic.o quirks.o devices.o
69 -usbcore-y += port.o
70 +usbcore-y += port.o of.o
71
72 usbcore-$(CONFIG_PCI) += hcd-pci.o
73 usbcore-$(CONFIG_ACPI) += usb-acpi.o
74 --- /dev/null
75 +++ b/drivers/usb/core/of.c
76 @@ -0,0 +1,47 @@
77 +/*
78 + * of.c The helpers for hcd device tree support
79 + *
80 + * Copyright (C) 2016 Freescale Semiconductor, Inc.
81 + * Author: Peter Chen <peter.chen@freescale.com>
82 + *
83 + * This program is free software: you can redistribute it and/or modify
84 + * it under the terms of the GNU General Public License version 2 of
85 + * the License as published by the Free Software Foundation.
86 + *
87 + * This program is distributed in the hope that it will be useful,
88 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
89 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90 + * GNU General Public License for more details.
91 + *
92 + * You should have received a copy of the GNU General Public License
93 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
94 + */
95 +
96 +#include <linux/of.h>
97 +
98 +/**
99 + * usb_of_get_child_node - Find the device node match port number
100 + * @parent: the parent device node
101 + * @portnum: the port number which device is connecting
102 + *
103 + * Find the node from device tree according to its port number.
104 + *
105 + * Return: On success, a pointer to the device node, %NULL on failure.
106 + */
107 +struct device_node *usb_of_get_child_node(struct device_node *parent,
108 + int portnum)
109 +{
110 + struct device_node *node;
111 + u32 port;
112 +
113 + for_each_child_of_node(parent, node) {
114 + if (!of_property_read_u32(node, "reg", &port)) {
115 + if (port == portnum)
116 + return node;
117 + }
118 + }
119 +
120 + return NULL;
121 +}
122 +EXPORT_SYMBOL_GPL(usb_of_get_child_node);
123 +
124 --- a/drivers/usb/core/usb.c
125 +++ b/drivers/usb/core/usb.c
126 @@ -36,6 +36,7 @@
127 #include <linux/mutex.h>
128 #include <linux/workqueue.h>
129 #include <linux/debugfs.h>
130 +#include <linux/usb/of.h>
131
132 #include <asm/io.h>
133 #include <linux/scatterlist.h>
134 @@ -469,6 +470,7 @@ struct usb_device *usb_alloc_dev(struct
135 dev->route = 0;
136
137 dev->dev.parent = bus->controller;
138 + dev->dev.of_node = bus->controller->of_node;
139 dev_set_name(&dev->dev, "usb%d", bus->busnum);
140 root_hub = 1;
141 } else {
142 @@ -493,6 +495,14 @@ struct usb_device *usb_alloc_dev(struct
143 dev->dev.parent = &parent->dev;
144 dev_set_name(&dev->dev, "%d-%s", bus->busnum, dev->devpath);
145
146 + if (!parent->parent) {
147 + /* device under root hub's port */
148 + port1 = usb_hcd_find_raw_port_number(usb_hcd,
149 + port1);
150 + }
151 + dev->dev.of_node = usb_of_get_child_node(parent->dev.of_node,
152 + port1);
153 +
154 /* hub driver sets up TT records */
155 }
156
157 --- a/include/linux/usb/of.h
158 +++ b/include/linux/usb/of.h
159 @@ -15,6 +15,8 @@
160 bool of_usb_host_tpl_support(struct device_node *np);
161 int of_usb_update_otg_caps(struct device_node *np,
162 struct usb_otg_caps *otg_caps);
163 +struct device_node *usb_of_get_child_node(struct device_node *parent,
164 + int portnum);
165 #else
166 static inline bool of_usb_host_tpl_support(struct device_node *np)
167 {
168 @@ -25,6 +27,11 @@ static inline int of_usb_update_otg_caps
169 {
170 return 0;
171 }
172 +static inline struct device_node *usb_of_get_child_node
173 + (struct device_node *parent, int portnum)
174 +{
175 + return NULL;
176 +}
177 #endif
178
179 #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_SUPPORT)