From patchwork Fri Feb 19 09:26:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 585123 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 57A5E14031F for ; Fri, 19 Feb 2016 21:04:46 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1426996AbcBSKEp (ORCPT ); Fri, 19 Feb 2016 05:04:45 -0500 Received: from mail-bl2on0090.outbound.protection.outlook.com ([65.55.169.90]:11680 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757368AbcBSKEh (ORCPT ); Fri, 19 Feb 2016 05:04:37 -0500 Received: from DM2PR03CA0045.namprd03.prod.outlook.com (10.141.96.44) by BLUPR03MB1490.namprd03.prod.outlook.com (10.163.81.20) with Microsoft SMTP Server (TLS) id 15.1.409.15; Fri, 19 Feb 2016 09:30:23 +0000 Received: from BL2FFO11OLC016.protection.gbl (2a01:111:f400:7c09::186) by DM2PR03CA0045.outlook.office365.com (2a01:111:e400:2428::44) with Microsoft SMTP Server (TLS) id 15.1.409.15 via Frontend Transport; Fri, 19 Feb 2016 09:30:24 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; freescale.mail.onmicrosoft.com; dmarc=none action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BL2FFO11OLC016.mail.protection.outlook.com (10.173.160.82) with Microsoft SMTP Server (TLS) id 15.1.415.6 via Frontend Transport; Fri, 19 Feb 2016 09:30:23 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id u1J9UHpg024857; Fri, 19 Feb 2016 02:30:18 -0700 From: Peter Chen To: , CC: , , , , , , , , , , , , Peter Chen Subject: [PATCH v6 1/1] USB: core: let USB device know device node Date: Fri, 19 Feb 2016 17:26:15 +0800 Message-ID: <1455873975-19531-1-git-send-email-peter.chen@nxp.com> X-Mailer: git-send-email 1.9.1 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131003478242532562; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11OLC016; 1:u3h0LJAYb/8AUDVblpd5DcSMQw1Fk4VFmQiWIW4SaRekeaVnLz1BmNnOl+HOuqrUJfhtMN/Jk1bfNoBuCtQFFNAcZ3U26w/2FgAN8X11k3rLZTAIxyTkOdumAL7f2hlOl0jBkKXjh225UOdHO7lnZ1/OUVMl6Tv10QLrZ4m7SfrSLwnr9txXuyfOPyyJI+r5VzcQ4Cm+jLp0QTp/AquGW01SjxxBqg0ca7RIFqq/913F6A+FeSxHUxerOmHMSLIUR594GNPbNmKaz83d6iaIgzMHSvk7gSL3jt23p4j1kZjkz0IiuLC74PFmwW9uzn5Rhri+LqaBz2NJqC4Dwst/pZQ5kkg4BvfGFZUKvj9gjYLYt3f9FRNcH4Va48o5ea5PsY1CMMNpn7sSvTnUOjy0Udqc1YPQccUkDDL/Zw2IxHwIt/Y+6d5ps+trtTF9MbcoRXQKbsnxFYkZCsfPfMyl8S+zFHeJuBKXYUQRjOWH1yOCb35PxUxKuUlK+Z2lN9UXTZCqrng9iZmiIENOseIGm/ScxtCB6DGn9H7g5ECPvwM= X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(1109001)(1110001)(3190300001)(339900001)(189002)(199003)(19580405001)(48376002)(87936001)(47776003)(77096005)(5001960100002)(7520500002)(2171001)(4326007)(15975445007)(85426001)(107886002)(5001770100001)(97736004)(36756003)(19580395003)(189998001)(2906002)(105606002)(229853001)(50466002)(86362001)(106466001)(50986999)(50226001)(586003)(1220700001)(4001430100002)(6806005)(33646002)(92566002)(1096002)(5008740100001)(5003940100001)(104016004)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR03MB1490; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:nov; MX:1; A:1; PTR:InfoDomainNonexistent; LANG:en; MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 8e7174cd-5acc-4acc-3096-08d3390f4b5e X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB1490; 2:+1R8e8iOxNdIzJ2Pw5QO6/PMWfO/yZC7ukFqBVv1fjCpyOrWVBkdslNPkPuWh74Nu/4sIuvXxpq+AlRJ/jS6aP5QS5/zfEnROdYe0bWgEwKC7mxn0eN5lSsFDAA65ubX3tjel2OutbvgWoSd/effcruZwLWY/4kcHG0m+4WLAM6G8XMgCfqEBU+7oWNuNdvf; 3:pA4k9M6w0ZaHmyG3fDc22XlMdwP2uyzyqg7gfIeLUNYViZ6KEB/eH6PfuMtxUdgG4CTAEP1b8/e0/mLOReuoiQ6SE/qkooJFiI3lbT/qXpEwGC8tlRcHriro5T6Ygh4cCiD9gRm/APn3vXkgQ1gnpE31UrGe+GQd8YvIy6grETT4Wjy7PMChMlRl74N5j1mx5Dxa2ktxZi8Tuigi4SkGlLyHsAunje4H1UxoDGtBOWk=; 25:gjP0L1uM9fn0CS9ezjzyaZNdbtTsGLFnSLcTKkNJEV2bECuaNHc5QKhl5yssHWpz0qhI4ARd2xPRp1YB5DFyrPAQR5kWlN3SIgBJ4Kku7L4py0UdTlbWnQzeRIkUuPBl88dPN+eYWXHUkgPzTUqzc5W/3B2o8fRAqpZMBfl5lcbNMD2Wf5f8bldRLhMoNkKtReGY/+Ydsr4xJmez6OWxhuXF8MSzZ+mBV79mnlu8FdLxqF+0Y6FE9+dJ0OsNPQsg273pSPkhFEbaogqiEXBvmTNUgKUByv48r6K3ymO48d5NZ9tIUHgsJtRUz6QhnlANGab6wtq3835V7fmyjGtJxpRwfh0VOOV3ViphLtVeUes= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1490; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(35762410373642); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13015025)(13023025)(5005006)(13018025)(13017025)(13024025)(8121501046)(10201501046)(3002001); SRVR:BLUPR03MB1490; BCL:0; PCL:0; RULEID:(400006); SRVR:BLUPR03MB1490; X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB1490; 4:HaDMVAj9cFz00SRZLR0TdDH7tAt4DuL32hI3bD9LuEINl81u69bPiXmXqTpAqOMFNAiTsitlk4NsHYOuWR/JtTJbza/4+mXU5AjKl5nAUahE6vReflF35FZWoIRB5euLkznwxjZEUCLfpVUl/tiDKRjPcmFdvFbfmJrS7BuEpoid1BGhTg7+u6ztBlXYEvZpJhFhKeSSStOkSfe1TicxsJ8Ziq0z9IoakN+n2/ZVUmEzwmgGLdzg+oDrDGv1k4tgRL7/WEySwMTj6y/X15SV1iUpYFFgpyuWOvmdAZN4JM2ukycWclln3RRo5ATm0Kk2rkCXXG6uZv2WoiF5AQ2/YxyIqyaC6IQwQdrpv1oagRh3Djpbc+zouoBJdrOzwo2OcfA7iau40z1gKlg2RNXmwAIBZVuuLBofpuSbE3D1QIQ0elG5sVnOZQjlEa5LpipUWjLhZbqDeNqkJWqXx6IGT3hf6O9pJGryrVPoNhYRXSrNXlQMAfYJwgDk+TryaxLc X-Forefront-PRVS: 08572BD77F X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR03MB1490; 23:p76pUyfyXmsXzyx6tGPUWG+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QvFB9VneAUwAA9HEYMB03EhJc331ac5bbEnpX5dN6O2oxxA?= =?us-ascii?Q?07qKXA3H0Ra8dGO1JATVRzyGFwl4BQy+NwEgA3TNZqaIBKyHk1L7bGatJgds?= =?us-ascii?Q?8BXMkOCMvoYQ2ZKP/sD4J5ERtRGJLqeBJz1mnIwUtrxb2bF7aXsNU7B3AipM?= =?us-ascii?Q?E/tLOp0L9jVC5MgNnNWWKEXoEb9TDPxhmy21GcdYrrbhrfT1zIZ4NgQKQMij?= =?us-ascii?Q?RaBtJhtkkB1SWmdj4PjZ5YocIchUjw/Db+KhNbHO98Unp1hu777Qw=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB1490; 5:UDGdSd4GHMcf9RkUZE7+HX1wOugpJPBieXvK15F1bd0hX8BPMvMCtqNkPZzk2DtgLEKh3EyQLWLPxfylmAFvnm6hkUiC88msDS6UTPjEvAu0/cFv+FQlO2/gLHf/PB9lgxoVJKL9WjWcl/dUs6xUmR3nw0Iq+GGAQjcE1Cb/OyA=; 24:cS2QDprCn+wMUfPBolYsGFcRnv2ErrA07CkNm5/VaOiJMr8DNta0wf1qBuR3gyoRbl7JUTDQOrvZN7WIs67o/JzWq7z5ByUJ+AXG19udKq4= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Feb 2016 09:30:23.8788 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR03MB1490 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Peter Chen 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 Acked-by: Philipp Zabel Acked-by: Alan Stern Acked-by: Rob Herring Acked-by: Arnd Bergmann --- Changes for v6: - Add textual representation for VID and PID in binding doc, and changing example accordingly. - Add three Acks. Changes for v5: - Refine the code how to get the device node at usb_alloc_dev according to Alan's comment. - Point out "usbVID,PID" is the recommented compatible, and others compatibles at binding doc could also be used. Changes for v4: - The range of "reg" should be 1-31, changing device node address style as in lower case hexadecimal with leading zeroes suppressed [binding doc, usb-device.txt] - Improve the example at binding doc, it describes node from the top (the controller) - Delete the struct of_node * within struct usb_device - Using usb_hcd_find_raw_port_number to get raw port number under root hub port Changes for v3: - typo: s/descirbe/describe/ Changes for v2: - Fix build error reported by kbuild robot, lack of "static" for inline usb_of_get_child_node - Fix typo, "devcie_node" -> "device_node" - Add kernel-doc for of_node at struct usb_device Changes from RFC: - Fix the error address for binding doc, and add compatible for binding doc - Change get child node API from "usb_of_find_node" to "usb_of_get_child_node" - Delete unecessary header files - One typo .../devicetree/bindings/usb/usb-device.txt | 28 +++++++++++++ drivers/usb/core/Makefile | 2 +- drivers/usb/core/of.c | 47 ++++++++++++++++++++++ drivers/usb/core/usb.c | 10 +++++ include/linux/usb/of.h | 7 ++++ 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/usb/usb-device.txt create mode 100644 drivers/usb/core/of.c diff --git a/Documentation/devicetree/bindings/usb/usb-device.txt b/Documentation/devicetree/bindings/usb/usb-device.txt new file mode 100644 index 0000000..1c35e7b --- /dev/null +++ b/Documentation/devicetree/bindings/usb/usb-device.txt @@ -0,0 +1,28 @@ +Generic USB Device Properties + +Usually, we only use device tree for hard wired USB device. +The reference binding doc is from: +http://www.firmware.org/1275/bindings/usb/usb-1_0.ps + +Required properties: +- compatible: usbVID,PID. The textual representation of VID, PID shall + be in lower case hexadecimal with leading zeroes suppressed. The + other compatible strings from the above standard binding could also + be used, but a device adhering to this binding may leave out all except + for usbVID,PID. +- reg: the port number which this device is connecting to, the range + is 1-31. + +Example: + +&usb1 { + status = "okay"; + + #address-cells = <1>; + #size-cells = <0>; + + hub: genesys@1 { + compatible = "usb5e3,608"; + reg = <1>; + }; +} diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile index 2f6f932..9780877 100644 --- a/drivers/usb/core/Makefile +++ b/drivers/usb/core/Makefile @@ -5,7 +5,7 @@ usbcore-y := usb.o hub.o hcd.o urb.o message.o driver.o usbcore-y += config.o file.o buffer.o sysfs.o endpoint.o usbcore-y += devio.o notify.o generic.o quirks.o devices.o -usbcore-y += port.o +usbcore-y += port.o of.o usbcore-$(CONFIG_PCI) += hcd-pci.o usbcore-$(CONFIG_ACPI) += usb-acpi.o diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c new file mode 100644 index 0000000..2289700 --- /dev/null +++ b/drivers/usb/core/of.c @@ -0,0 +1,47 @@ +/* + * of.c The helpers for hcd device tree support + * + * Copyright (C) 2016 Freescale Semiconductor, Inc. + * Author: Peter Chen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 of + * the License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +/** + * usb_of_get_child_node - Find the device node match port number + * @parent: the parent device node + * @portnum: the port number which device is connecting + * + * Find the node from device tree according to its port number. + * + * Return: On success, a pointer to the device node, %NULL on failure. + */ +struct device_node *usb_of_get_child_node(struct device_node *parent, + int portnum) +{ + struct device_node *node; + u32 port; + + for_each_child_of_node(parent, node) { + if (!of_property_read_u32(node, "reg", &port)) { + if (port == portnum) + return node; + } + } + + return NULL; +} +EXPORT_SYMBOL_GPL(usb_of_get_child_node); + diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 524c982..ffa5cf1 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -470,6 +471,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, dev->route = 0; dev->dev.parent = bus->controller; + dev->dev.of_node = bus->controller->of_node; dev_set_name(&dev->dev, "usb%d", bus->busnum); root_hub = 1; } else { @@ -494,6 +496,14 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, dev->dev.parent = &parent->dev; dev_set_name(&dev->dev, "%d-%s", bus->busnum, dev->devpath); + if (!parent->parent) { + /* device under root hub's port */ + port1 = usb_hcd_find_raw_port_number(usb_hcd, + port1); + } + dev->dev.of_node = usb_of_get_child_node(parent->dev.of_node, + port1); + /* hub driver sets up TT records */ } diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h index 974bce9..de3237f 100644 --- a/include/linux/usb/of.h +++ b/include/linux/usb/of.h @@ -16,6 +16,8 @@ enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np); bool of_usb_host_tpl_support(struct device_node *np); int of_usb_update_otg_caps(struct device_node *np, struct usb_otg_caps *otg_caps); +struct device_node *usb_of_get_child_node(struct device_node *parent, + int portnum); #else static inline enum usb_dr_mode 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, { return 0; } +static inline struct device_node *usb_of_get_child_node + (struct device_node *parent, int portnum) +{ + return NULL; +} #endif #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_SUPPORT)