USB: add generic onboard USB driver
Subsystems (4)
cover USB: add generic onboard USB driver
Hi all,
This is later patch set for generic onboard HUB dirver [1], since I find it can apply for all generic onboard USB devices, so I changed a little for it, it should be work for the use case found at imx6qdl udoo board, but several people have comments for its design, I mark RFC for disucssion, and see how to implement it properly.
The purpose for this patch set is to let the USB handle platform parameters properly, since some usb devices need to pre-setup before it can be recognized by controller [2], some usb devices has more interfaces for others use, like i2c, gpios, etc.[3]
Thanks.
[1] http://www.spinics.net/lists/linux-usb/msg134082.html
[2] http://www.spinics.net/lists/linux-usb/msg131502.html
[3] http://marc.info/?l=linux-usb&m=142772952730243&w=2
Peter Chen (5):
usb: hub: add device tree support for populating onboard usb device
doc: dt-binding: generic onboard USB device
usb: misc: generic_onboard_hub: add generic onboard USB device driver
usb: chipidea: host: let the hcd know's parent device node
ARM: dts: imx6qdl-udoo.dtsi: fix onboard USB HUB property
.../bindings/usb/generic-onboard-device.txt | 31 +++++ MAINTAINERS | 7 + arch/arm/boot/dts/imx6qdl-udoo.dtsi | 35 ++--- drivers/usb/chipidea/host.c | 18 ++- drivers/usb/core/hub.c | 37 ++++++ drivers/usb/misc/Kconfig | 10 ++ drivers/usb/misc/Makefile | 1 + drivers/usb/misc/generic_onboard_device.c | 144 +++++++++++++++++++++ 8 files changed, 258 insertions(+), 25 deletions(-) create mode 100644 Documentation/devicetree/bindings/usb/generic-onboard-device.txt create mode 100644 drivers/usb/misc/generic_onboard_device.c
Signature · 1 line
1.9.1
RFC PATCH 1/5 usb: hub: add device tree support for populating onboard usb device
Although most of USB device is hot-plug's, there are still some USB devices are soldered on the board, and these kinds of devices maybe the upstream device at 1st or 2nd level hub's, so in order to detect all onboard devices, we put the detect device node code at hub's driver, and it will populate platform device under this HUB.
--- drivers/usb/core/hub.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
drivers/usb/core/hub.c +37 -0
@@ -26,6 +26,7 @@#include <linux/mutex.h> #include <linux/random.h> #include <linux/pm_qos.h> +#include <linux/of_platform.h> #include <asm/uaccess.h> #include <asm/byteorder.h>
@@ -1334,6 +1335,34 @@ static int hub_post_reset(struct usb_interface *intf)return 0 ; } +static int hub_of_children_register (struct usb_device *hdev) +{ +struct device *dev; + +if (hdev->parent) + dev = &hdev->dev; +else + dev =bus_to_hcd (hdev->bus)->self.controller; + +if (!dev->of_node) +return 0 ; + +return of_platform_populate (dev->of_node,NULL ,NULL , dev); +} + +static void hub_of_children_unregister (struct usb_device *hdev) +{ +struct device *dev; + +if (hdev->parent) + dev = &hdev->dev; +else + dev =bus_to_hcd (hdev->bus)->self.controller; + +if (dev->of_node) +of_platform_depopulate (dev); +} +static int hub_configure (struct usb_hub *hub,struct usb_endpoint_descriptor *endpoint) {
@@ -1677,6 +1706,7 @@ static void hub_disconnect(struct usb_interface *intf)usb_set_intfdata (intf,NULL );spin_unlock_irq (&device_state_lock); +hub_of_children_unregister (hdev);for (; port1 >0 ; --port1)usb_hub_remove_port_device (hub, port1);
@@ -1701,6 +1731,7 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id)struct usb_endpoint_descriptor *endpoint;struct usb_device *hdev;struct usb_hub *hub; +int ret; desc = intf->cur_altsetting; hdev =interface_to_usbdev (intf);
@@ -1820,6 +1851,12 @@ descriptor_error:if (id->driver_info &HUB_QUIRK_CHECK_PORT_AUTOSUSPEND ) hub->quirk_check_port_auto_suspend =1 ; + ret =hub_of_children_register (hdev); +if (ret) { +dev_err (&hdev->dev,"Failed to register child device\n" ); +return ret; + } +if (hub_configure (hub, endpoint) >=0 )return 0 ;
Signature · 1 line
1.9.1
RFC PATCH 2/5 doc: dt-binding: generic onboard USB device
In reply to Peter ChenAdd dt-binding documentation for generic onboard USB device.
--- .../bindings/usb/generic-onboard-device.txt | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/generic-onboard-device.txt
Documentation/devicetree/bindings/usb/generic-onboard-device.txt new file +31 -0
@@ -0,0 +1,31 @@ +Generic Onboard USB Device + +The node should be located at USB host controller's node or +any USB HUB's node. + +Required properties: +- compatible: should be "generic-onboard-device" + +Optional properties: +- clocks: the input clock for USB device. +- clock-frequency: the frequency for device's clock. +- reset-gpios: Should specify the GPIO for reset. +- reset-duration-us: the duration for assert reset signal, the time unit + is microsecond. + +Example: + +&usbh1 { + vbus-supply = <®_usb_h1_vbus>; + status = "okay"; + + #address-cells = <1>; + #size-cells = <0>; + hub: usb2415 at 01 { + compatible = "generic-onboard-device"; + reg = <0x01>; + clocks = <&clks IMX6QDL_CLK_CKO>; + reset-gpios = <&gpio7 12 GPIO_ACTIVE_LOW>; + reset-duration-us = <10>; + }; +};
Signature · 1 line
1.9.1
Rob Herring
maintainerRFC PATCH 2/5 doc: dt-binding: generic onboard USB device
Quoted 1 line · Peter Chen
Add dt-binding documentation for generic onboard USB device.
As has already been mentioned, please following the existing USB device binding convention. We can debate whether the kernel driver is tied into existing USB drivers or separate platform drivers, but the binding needs to reflect the h/w.
Rob
Quoted 47 lines
Signed-off-by Peter Chen <[email protected]>--- .../bindings/usb/generic-onboard-device.txt | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/generic-onboard-device.txtDocumentation/devicetree/bindings/usb/generic-onboard-device.txt new file +31
-0@@ -0,0 +1,31 @@ +Generic Onboard USB Device + +The node should be located at USB host controller's node or +any USB HUB's node. + +Required properties: +- compatible: should be "generic-onboard-device" + +Optional properties: +- clocks: the input clock for USB device. +- clock-frequency: the frequency for device's clock. +- reset-gpios: Should specify the GPIO for reset. +- reset-duration-us: the duration for assert reset signal, the time unit + is microsecond. + +Example: + +&usbh1 { + vbus-supply = <®_usb_h1_vbus>; + status = "okay"; + + #address-cells = <1>; + #size-cells = <0>; + hub: usb2415 at 01 { + compatible = "generic-onboard-device"; + reg = <0x01>; + clocks = <&clks IMX6QDL_CLK_CKO>; + reset-gpios = <&gpio7 12 GPIO_ACTIVE_LOW>; + reset-duration-us = <10>; + }; +};Signature · 1 line
1.9.1
RFC PATCH 2/5 doc: dt-binding: generic onboard USB device
Quoted 10 lines · Rob Herring
Quoted 1 line · Peter Chen
Add dt-binding documentation for generic onboard USB device.
As has already been mentioned, please following the existing USB device binding convention. We can debate whether the kernel driver is tied into existing USB drivers or separate platform drivers, but the binding needs to reflect the h/w.
Rob
There is no USB device binding currently, would you mean this:
http://playground.sun.com/1275/bindings/usb/usb-1_0.ps
In fact, we hardly describe USB device at dts. No matter device address, Device class, or compatible string, neither can work, since we know nothing before enumeration, and there are maybe two or more usb devices at the USB bus, only possible is {pid, vid}, but there are may be two same devices on the bus.
Quoted 51 lines
Quoted 45 lines
Signed-off-by Peter Chen <[email protected]>--- .../bindings/usb/generic-onboard-device.txt | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/generic-onboard-device.txtDocumentation/devicetree/bindings/usb/generic-onboard-device.txt new file +31
-1@@ -0,0 +1,31 @@ +Generic Onboard USB Device + +The node should be located at USB host controller's node or +any USB HUB's node. + +Required properties: +- compatible: should be "generic-onboard-device" + +Optional properties: +- clocks: the input clock for USB device. +- clock-frequency: the frequency for device's clock. +- reset-gpios: Should specify the GPIO for reset. +- reset-duration-us: the duration for assert reset signal, the time unit + is microsecond. + +Example: + +&usbh1 { + vbus-supply = <®_usb_h1_vbus>; + status = "okay"; + + #address-cells = <1>; + #size-cells = <0>; + hub: usb2415 at 01 { + compatible = "generic-onboard-device"; + reg = <0x01>; + clocks = <&clks IMX6QDL_CLK_CKO>; + reset-gpios = <&gpio7 12 GPIO_ACTIVE_LOW>; + reset-duration-us = <10>; + }; +}; --Quoted 2 lines
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
BR, Peter Chen
RFC PATCH 3/5 usb: misc: generic_onboard_hub: add generic onboard USB device driver
In reply to Peter ChenCurrent USB device driver lacks of platform interfaces to configure external signal on HUB chip, eg, the PHY input clock and gpio reset pin for HUB, these kinds of devices are usually soldered at the board, and they are not hot-plug USB devices.
With this patch, the user can configure the device's pins at device tree, and these configuration will be effective before the USB bus can be used, it can avoid unexpected signals at USB bus during this USB device hardware reset process, so we use subsys_initcall for this driver.
--- MAINTAINERS | 7 ++ drivers/usb/misc/Kconfig | 10 +++ drivers/usb/misc/Makefile | 1 + drivers/usb/misc/generic_onboard_device.c | 144 ++++++++++++++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 drivers/usb/misc/generic_onboard_device.c
MAINTAINERS +7 -0
@@ -11140,6 +11140,13 @@ S: Maintained F: Documentation/usb/ohci.txt F: drivers/usb/host/ohci* +USB Generic Onboard Device Driver +M: Peter Chen <[email protected]> +T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git +L: linux-usb at vger.kernel.org +S: Maintained +F: drivers/usb/misc/generic_onboard_device.c + USB OTG FSM (Finite State Machine) M: Peter Chen <[email protected]> T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git
drivers/usb/misc/Kconfig +10 -0
@@ -268,3 +268,13 @@ config USB_CHAOSKEY To compile this driver as a module, choose M here: the module will be called chaoskey. + +config USB_ONBOARD_DEVICE + tristate "Generic USB Onboard Device" + help + depends on OF + Say Y here if your board has an onboard device, and this device + needs to control its PHY clock and reset pin through external + signals. If you are not sure, say N. + + To compile this driver as a module, choose M here.
drivers/usb/misc/Makefile +1 -0
@@ -29,3 +29,4 @@ obj-$(CONFIG_USB_CHAOSKEY) += chaoskey.o obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga/ obj-$(CONFIG_USB_LINK_LAYER_TEST) += lvstest.o +obj-$(CONFIG_USB_ONBOARD_DEVICE) += generic_onboard_device.o
drivers/usb/misc/generic_onboard_device.c new file +144 -0
144 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC PATCH 4/5 usb: chipidea: host: let the hcd know's parent device node
In reply to Peter ChenSince the hcd (chipidea core device) has no device node, so if we want to describe the child node under the hcd, we had to put it under its parent's node (glue layer device), and in the code, we need to let the hcd knows glue layer's code, then the USB core can handle this node.
--- drivers/usb/chipidea/host.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/usb/chipidea/host.c +14 -4
@@ -109,15 +109,25 @@ static int host_start(struct ci_hdrc *ci)struct ehci_hcd *ehci;struct ehci_ci_priv *priv;int ret; +struct device *dev = ci->dev; -if (usb_disabled ()) +if (usb_disabled () || !dev)return -ENODEV ; - hcd =usb_create_hcd (&ci_ehci_hc_driver, ci->dev,dev_name (ci->dev)); +/* +* USB Core will try to get child node under roothub, +* but chipidea core has no of_node, and the child node +* for controller is located at glue layer's node which +* is chipidea core's parent. +*/ +if (dev->parent && dev->parent->of_node) + dev->of_node = dev->parent->of_node; + + hcd =usb_create_hcd (&ci_ehci_hc_driver, dev,dev_name (dev));if (!hcd)return -ENOMEM ; -dev_set_drvdata (ci->dev, ci); +dev_set_drvdata (dev, ci); hcd->rsrc_start = ci->hw_bank.phys; hcd->rsrc_len = ci->hw_bank.size; hcd->regs = ci->hw_bank.abs;
@@ -143,7 +153,7 @@ static int host_start(struct ci_hdrc *ci)if (ci->platdata->flags &CI_HDRC_TURN_VBUS_EARLY_ON ) { ret =regulator_enable (ci->platdata->reg_vbus);if (ret) { -dev_err (ci->dev, +dev_err (dev,"Failed to enable vbus regulator, ret=%d\n" , ret); goto put_hcd;
Signature · 1 line
1.9.1
RFC PATCH 5/5 ARM: dts: imx6qdl-udoo.dtsi: fix onboard USB HUB property
In reply to Peter ChenThe current dts describes USB HUB's property at USB controller's entry, it is improper. The USB HUB should be the child node under USB controller.
--- arch/arm/boot/dts/imx6qdl-udoo.dtsi | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-)
arch/arm/boot/dts/imx6qdl-udoo.dtsi +14 -21
@@ -9,6 +9,8 @@ * */ +#include <dt-bindings/gpio/gpio.h> + / { chosen { stdout-path = &uart2;
@@ -17,23 +19,6 @@ memory { reg = <0x10000000 0x40000000>; }; - - regulators { - compatible = "simple-bus"; - #address-cells = <1>; - #size-cells = <0>; - - reg_usb_h1_vbus: regulator at 0 { - compatible = "regulator-fixed"; - reg = <0>; - regulator-name = "usb_h1_vbus"; - regulator-min-microvolt = <5000000>; - regulator-max-microvolt = <5000000>; - enable-active-high; - startup-delay-us = <2>; /* USB2415 requires a POR of 1 us minimum */ - gpio = <&gpio7 12 0>; - }; - }; }; &fec {
@@ -119,11 +104,19 @@ }; &usbh1 { - pinctrl-names = "default"; - pinctrl-0 = <&pinctrl_usbh>; - vbus-supply = <®_usb_h1_vbus>; - clocks = <&clks 201>; status = "okay"; + + #address-cells = <1>; + #size-cells = <0>; + hub: usb2415 at 01 { + compatible = "generic-onboard-device"; + reg = <0x01>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_usbh>; + clocks = <&clks IMX6QDL_CLK_CKO>; + reset-gpios = <&gpio7 12 GPIO_ACTIVE_LOW>; + reset-duration-us = <2>; + }; }; &usdhc3 {
Signature · 1 line
1.9.1