1
0

082-0001-USB-core-let-USB-device-know-device-node.patch 5.7 KB

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