Skip to content

Commit 69bec72

Browse files
Peter Chengregkh
authored andcommitted
USB: core: let USB device know device node
Although most of USB devices are hot-plug's, there are still some devices are hard wired on the board, eg, for HSIC and SSIC interface USB devices. If these kinds of USB devices are multiple functions, and they can supply other interfaces like i2c, gpios for other devices, we may need to describe these at device tree. In this commit, it uses "reg" in dts as physical port number to match the phyiscal port number decided by USB core, if they are the same, then the device node is for the device we are creating for USB core. Signed-off-by: Peter Chen <peter.chen@freescale.com> Acked-by: Philipp Zabel <p.zabel@pengutronix.de> Acked-by: Alan Stern <stern@rowland.harvard.edu> Acked-by: Rob Herring <robh@kernel.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d883f52 commit 69bec72

File tree

5 files changed

+93
-1
lines changed

5 files changed

+93
-1
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Generic USB Device Properties
2+
3+
Usually, we only use device tree for hard wired USB device.
4+
The reference binding doc is from:
5+
http://www.firmware.org/1275/bindings/usb/usb-1_0.ps
6+
7+
Required properties:
8+
- compatible: usbVID,PID. The textual representation of VID, PID shall
9+
be in lower case hexadecimal with leading zeroes suppressed. The
10+
other compatible strings from the above standard binding could also
11+
be used, but a device adhering to this binding may leave out all except
12+
for usbVID,PID.
13+
- reg: the port number which this device is connecting to, the range
14+
is 1-31.
15+
16+
Example:
17+
18+
&usb1 {
19+
status = "okay";
20+
21+
#address-cells = <1>;
22+
#size-cells = <0>;
23+
24+
hub: genesys@1 {
25+
compatible = "usb5e3,608";
26+
reg = <1>;
27+
};
28+
}

drivers/usb/core/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o
66
usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o
77
usbcore-y += devio.o notify.o generic.o quirks.o devices.o
8-
usbcore-y += port.o
8+
usbcore-y += port.o of.o
99

1010
usbcore-$(CONFIG_PCI) += hcd-pci.o
1111
usbcore-$(CONFIG_ACPI) += usb-acpi.o

drivers/usb/core/of.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* of.c The helpers for hcd device tree support
3+
*
4+
* Copyright (C) 2016 Freescale Semiconductor, Inc.
5+
* Author: Peter Chen <peter.chen@freescale.com>
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License version 2 of
9+
* the License as published by the Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include <linux/of.h>
21+
22+
/**
23+
* usb_of_get_child_node - Find the device node match port number
24+
* @parent: the parent device node
25+
* @portnum: the port number which device is connecting
26+
*
27+
* Find the node from device tree according to its port number.
28+
*
29+
* Return: On success, a pointer to the device node, %NULL on failure.
30+
*/
31+
struct device_node *usb_of_get_child_node(struct device_node *parent,
32+
int portnum)
33+
{
34+
struct device_node *node;
35+
u32 port;
36+
37+
for_each_child_of_node(parent, node) {
38+
if (!of_property_read_u32(node, "reg", &port)) {
39+
if (port == portnum)
40+
return node;
41+
}
42+
}
43+
44+
return NULL;
45+
}
46+
EXPORT_SYMBOL_GPL(usb_of_get_child_node);
47+

drivers/usb/core/usb.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <linux/mutex.h>
3737
#include <linux/workqueue.h>
3838
#include <linux/debugfs.h>
39+
#include <linux/usb/of.h>
3940

4041
#include <asm/io.h>
4142
#include <linux/scatterlist.h>
@@ -470,6 +471,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
470471
dev->route = 0;
471472

472473
dev->dev.parent = bus->controller;
474+
dev->dev.of_node = bus->controller->of_node;
473475
dev_set_name(&dev->dev, "usb%d", bus->busnum);
474476
root_hub = 1;
475477
} else {
@@ -494,6 +496,14 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
494496
dev->dev.parent = &parent->dev;
495497
dev_set_name(&dev->dev, "%d-%s", bus->busnum, dev->devpath);
496498

499+
if (!parent->parent) {
500+
/* device under root hub's port */
501+
port1 = usb_hcd_find_raw_port_number(usb_hcd,
502+
port1);
503+
}
504+
dev->dev.of_node = usb_of_get_child_node(parent->dev.of_node,
505+
port1);
506+
497507
/* hub driver sets up TT records */
498508
}
499509

include/linux/usb/of.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np);
1616
bool of_usb_host_tpl_support(struct device_node *np);
1717
int of_usb_update_otg_caps(struct device_node *np,
1818
struct usb_otg_caps *otg_caps);
19+
struct device_node *usb_of_get_child_node(struct device_node *parent,
20+
int portnum);
1921
#else
2022
static inline enum usb_dr_mode
2123
of_usb_get_dr_mode_by_phy(struct device_node *phy_np)
@@ -31,6 +33,11 @@ static inline int of_usb_update_otg_caps(struct device_node *np,
3133
{
3234
return 0;
3335
}
36+
static inline struct device_node *usb_of_get_child_node
37+
(struct device_node *parent, int portnum)
38+
{
39+
return NULL;
40+
}
3441
#endif
3542

3643
#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_SUPPORT)

0 commit comments

Comments
 (0)