From patchwork Fri Jan 8 05:44:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 7982771 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6E6739F54F for ; Fri, 8 Jan 2016 05:49:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6604120142 for ; Fri, 8 Jan 2016 05:49:13 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4E6BA2013D for ; Fri, 8 Jan 2016 05:49:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aHPtR-0003Mp-4R; Fri, 08 Jan 2016 05:47:21 +0000 Received: from mail-bn1bn0106.outbound.protection.outlook.com ([157.56.110.106] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aHPtH-0003KV-N2 for linux-arm-kernel@lists.infradead.org; Fri, 08 Jan 2016 05:47:13 +0000 Received: from BY2PR03CA002.namprd03.prod.outlook.com (10.255.93.19) by SN1PR0301MB2000.namprd03.prod.outlook.com (10.163.225.29) with Microsoft SMTP Server (TLS) id 15.1.361.13; Fri, 8 Jan 2016 05:46:47 +0000 Received: from BY2FFO11OLC011.protection.gbl (10.255.93.4) by BY2PR03CA002.outlook.office365.com (10.255.93.19) with Microsoft SMTP Server (TLS) id 15.1.365.18 via Frontend Transport; Fri, 8 Jan 2016 05:46:47 +0000 Authentication-Results: spf=permerror (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; freescale.mail.onmicrosoft.com; dmarc=none action=none header.from=freescale.com; Received-SPF: PermError (protection.outlook.com: domain of freescale.com used an invalid SPF mechanism) Received: from tx30smr01.am.freescale.net (192.88.168.50) by BY2FFO11OLC011.mail.protection.outlook.com (10.1.15.22) with Microsoft SMTP Server (TLS) id 15.1.355.15 via Frontend Transport; Fri, 8 Jan 2016 05:46:47 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u085kahm029292; Thu, 7 Jan 2016 22:46:43 -0700 From: Peter Chen To: , Subject: [RFC PATCH 1/2] USB: core: let USB device know device node Date: Fri, 8 Jan 2016 13:44:23 +0800 Message-ID: <1452231864-11171-2-git-send-email-peter.chen@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1452231864-11171-1-git-send-email-peter.chen@freescale.com> References: <1452231864-11171-1-git-send-email-peter.chen@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11OLC011; 1:A2HTM43eYvCYUBlY0LRrKxMEeMJngEEe83LJphBJ1CQNEFkljwbrJ18A84tFibdBHlOa1DxnnAuWbf8BiqqXGVJwxXbJW+MtUNOKreT13oe46IsdahDxsWpRkV4woHA05WuDX4Ubyi6rG9lP6mY7lqRmKd2JQK5BJ3EwCM8MqtFXKH4OWDqbWM+LRcdgwGC8SasS5Z/ilAET+Zwh21iIoRi0w+EFCGcxrRSQpEww45E0iFrFZ7HVM7Te4GaLnymSp/SF8eiFMIY4FPzmylTwcvtYSnGs14xhBqpE5k5kBxMD15V8fedES/Zt0gJYDEl6cxt8/2XZMFPls7aYs5qYVft++ZGgCA21/D8dsWpwlV7rpO98IaSExNdkc7YoBYeNBO3nxflE2jT3PJydKD/mNYBtzi9tTQ36OYw8Io4Wmhy5VOA4yRAAB8S2hwjdmmszGTEFdMf8HB/Z5jmvDrViWw== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(448002)(3190300001)(189002)(199003)(106466001)(5001960100002)(19580395003)(77096005)(47776003)(1096002)(15975445007)(229853001)(5003940100001)(107886002)(36756003)(5001770100001)(2906002)(1220700001)(19580405001)(92566002)(4001430100002)(2171001)(4326007)(2950100001)(104016004)(575784001)(81156007)(97736004)(5008740100001)(6806005)(87936001)(189998001)(586003)(50466002)(76176999)(50986999)(48376002)(85326001)(50226001)(11100500001)(33646002)(86362001)(2004002)(217873001)(309714004); DIR:OUT; SFP:1102; SCL:1; SRVR:SN1PR0301MB2000; H:tx30smr01.am.freescale.net; FPR:; SPF:PermError; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB2000; 2:/oIJiXSACQ4YwWpupG2ksjJsE8t29YnSlTn3lUPag9yqUo70Q8ZT2Zoy/0vIjnVxey1xz+TfE6NZvl8CHvTNh+DldIz11BGuvkSx2b8e5iO4fK/K+x/QTRzhwKr9KlkMF9DIhkwEnWK01ygpffUHQQ==; 3:hzhQ4SpV+F1d2ie2zQZxXoJx6je53BNjmXxo6GEwcL/2SOtuoub+au2V6YU6upyhOI8N550nsXqVA+ld2uTv4lSc8Nd0gdOWeOqE/BO4pbQQoP1NXnAA7keUFp0plCLf8b8SuRITZTRHxoa57cyu3gTgOHx/UcchAgW8e59uDZtfM0+LCxsv+bkjlxTaWCKDAHDh6ZRA7AqO25mlNe/5jAFMmNsPeavjkv6OJGPnlb4=; 25:wcttflqcryv1hv1+sEceBnZexDFb2zk+D9mkRYILA57h7SXy/UqYFJYBqkmfAMyWLvKuyCwseKaOJ8xL0kpGfvZwRAnrzDq+UpvVjd+Ysma5W+BzORsxX/sP3Sl/HmukYDNEnXRU7p5As6PmxjPoCm2e61X4/xf17o+idGUPEmmC1ve42GhYRjqFngyoBszJRMUUtfZ079OdutxDjosRK3Zd27T8dx/71vRgvdoKQLae2iro9jVkL3/yqo9lptNT X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0301MB2000; X-MS-Office365-Filtering-Correlation-Id: 919c3245-c0a6-415d-c58b-08d317ef191f X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB2000; 20:zQ1SIu0ZdeTj6Jhj+/71tyUeTp8Jmuc7l/cQBd0lTwdLlDjU36kjjzpoPrF0p2pGZ6S1dZ2UdTcu2AF7JpAySR45VwJzGzDP43dW0vEe04JyF/RokD03HwufozgZnUcw5Fl2RdbdiBOXBrAMCPUThjVhmeo2Uhh/C045aNhxuhe28h3QBf8rhWHsMSMi2FD3RbKRoX8KlIUerZCI1FWCU6ddzLJoZ03y/kxhZPoFpF7NoMAfMinbvAUwoaW2M9X+27NIOdy7f3IxSVdXfuSN31iLGVVD8e73x5Aq0JAPsZ6fLuqNvQP9id4vVF148Q6yhitUrOUlZgsMQFE7m4Cm8orTC/VrCP+NEvN0VbnL58sqqCd4k18NdvAAKtfMZIAQidI0cKfY4sRLS5usODh7QI/dOGM2JDdRaVq1T4inz6SYUTqDp9KQaaLg2POCqNYM; 4:q1SxCbmWQXueJuhUMK8IBfICme7r/YZ/kbUC5eR2l9rl0g+HOKsCJexytIUrSWhZYV6HsTMrUAOMGx3Pt+CQgod1bsrvdUXbDImsQWqxPEw03BdQI9qXaHiyUH1/61sMUH3+LWSZIOaIFG1KDMbe38QdKi8ZidsJdAe2MSw6DjQNgUGW4jMaaC27L8DDyPIPpIE0fv6/L/uGKc+jpmYqhauw3UJtwkxRq7R8p97g5sX/m29rsyanv/W6dTVE+OYtr/CcizH7Gh8BKbNnchGzhV220dC9YIY/jpY1A591YSBjQjgTlGFrLaLira/LIvolk6IvXDvLFSPKVwKu8CFNuwIkUswmbRtr7wCAq+Rb+eiDEtuxiVpOqhvKcCECWZ/rnl7MJfw4xPwO6+/t4yflVUBiNd133Np1ti7RzbJbfvaBUMv+44zxRqWwqvo8opCX8a/aBtXGWjxmDWP6ZiABPQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(520078)(13017025)(13015025)(8121501046)(5005006)(10201501046)(3002001); SRVR:SN1PR0301MB2000; BCL:0; PCL:0; RULEID:; SRVR:SN1PR0301MB2000; X-Forefront-PRVS: 0815F8251E X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR0301MB2000; 23:NDUxhlj6yDZzIArDhjusNPGfh3FRkSbXg1+SXVU?= =?us-ascii?Q?cmhO8dwDc2rRn76p+UBXT1tQEgj+vjbVCt74VQvNd3nhbw4dkfZD/VePnG4B?= =?us-ascii?Q?ZhxCtHiSzGQMyivb13jkuk6m4cr/HG6qQy7jTGr5MeAxtxtlnTFC5T7yHyEe?= =?us-ascii?Q?knTnIrhU64LBPYhvwB+Ya5fTxI63vQ7dftxrf9AsgL9sa0tvQ1m/LW6VN5QE?= =?us-ascii?Q?vpdWsqgWqT1F9aWpBerd2LbSWE/g+/EkoQmNs11xghSLlzVl4fGSLVYhBceJ?= =?us-ascii?Q?jB7rtcZSYp7GDAsdY2s1tkglQ7PxaYqJGUE+z9YSqG7pWBRuSvZ2BYPwIZje?= =?us-ascii?Q?czazvNW0Y9f2X4Zo7mIija6kn/VvXoKnfpztTgaAudvy3UYEsP0V4K4UWF18?= =?us-ascii?Q?YAkGKHdrnVIiWJPihuHnn7FICBhUreHAoSm75lSj0qy7AVEoS24ncO/XZS1g?= =?us-ascii?Q?MhN0KIX58Zr5ZOh7U8o26/CWQuH5q4fOleTa0Tp6QQAQvG3uXI0eWMMQebnA?= =?us-ascii?Q?R7anXbSzaYuhSbc3w0R7KzTPjoqLzJIMLF7W6ZtG7mikmkRUn9Esrd8JLqQD?= =?us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gjv7MHU3YRL5NzHsTRIXvEDnLT+WGxd19DiFb6AU6A2TIE6o= X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jan 2016 05:46:47.3479 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR0301MB2000 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160107_214712_025695_E6F5E43F X-CRM114-Status: GOOD ( 26.22 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, devicetree@vger.kernel.org, arnd@arndb.de, pawel.moll@arm.com, valentin.longchamp@keymile.com, linux-usb@vger.kernel.org, balbi@ti.com, robh+dt@kernel.org, Peter Chen , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 descirbe these at device tree. In this commit, it uses "reg" in dts as port number to match the 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 --- .../devicetree/bindings/usb/usb-device.txt | 8 ++++ drivers/usb/core/Makefile | 2 +- drivers/usb/core/of.c | 48 ++++++++++++++++++++++ drivers/usb/core/usb.c | 8 +++- include/linux/usb.h | 2 + include/linux/usb/of.h | 6 +++ 6 files changed, 71 insertions(+), 3 deletions(-) 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..d35facd --- /dev/null +++ b/Documentation/devicetree/bindings/usb/usb-device.txt @@ -0,0 +1,8 @@ +Generic USB Device Properties + +Usually, we only use device tree for hard wired USB device. +The reference binding doc is from: +http://playground.sun.com/1275/bindings/usb/usb-1_0.ps. + +Required properties: +- reg: the port number which this device is connecting to. 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..008ae6a --- /dev/null +++ b/drivers/usb/core/of.c @@ -0,0 +1,48 @@ +/* + * 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 +#include +#include + +/** + * usb_of_find_node - Find the device node match port number + * @dev: 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_find_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_find_node); + diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 77e4c9b..211cb6e 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -502,11 +503,14 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, dev->connect_time = jiffies; dev->active_duration = -jiffies; #endif - if (root_hub) /* Root hub always ok [and always wired] */ + if (root_hub) { /* Root hub always ok [and always wired] */ dev->authorized = 1; - else { + dev->of_node = bus->controller->of_node; + } else { dev->authorized = !!HCD_DEV_AUTHORIZED(usb_hcd); dev->wusb = usb_bus_is_wusb(bus) ? 1 : 0; + dev->dev.of_node = usb_of_find_node + (parent->of_node, dev->portnum); } return dev; } diff --git a/include/linux/usb.h b/include/linux/usb.h index 89533ba..a3a0b07 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -21,6 +21,7 @@ #include /* for current && schedule_timeout */ #include /* for struct mutex */ #include /* for runtime PM */ +#include /* for device tree */ struct usb_device; struct usb_driver; @@ -616,6 +617,7 @@ struct usb_device { struct usb3_lpm_parameters u1_params; struct usb3_lpm_parameters u2_params; unsigned lpm_disable_count; + struct device_node *of_node; /* associated device tree node */ }; #define to_usb_device(d) container_of(d, struct usb_device, dev) diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h index 974bce9..94340cb 100644 --- a/include/linux/usb/of.h +++ b/include/linux/usb/of.h @@ -16,6 +16,7 @@ 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_find_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 +32,11 @@ static inline int of_usb_update_otg_caps(struct device_node *np, { return 0; } +struct inline device_node *usb_of_find_node(struct device_node *parent, + int portnum) +{ + return NULL; +} #endif #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_SUPPORT)