From patchwork Fri Jan 15 09:17:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 8039341 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 084E0BEEE5 for ; Fri, 15 Jan 2016 09:22:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E3EF92044C for ; Fri, 15 Jan 2016 09:22:24 +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 BCBE92041F for ; Fri, 15 Jan 2016 09:22:23 +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 1aK0Yg-0008Pi-0D; Fri, 15 Jan 2016 09:20:38 +0000 Received: from mail-bn1bon0141.outbound.protection.outlook.com ([157.56.111.141] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aK0Yb-0008Lv-Jm for linux-arm-kernel@lists.infradead.org; Fri, 15 Jan 2016 09:20:35 +0000 Received: from BLUPR03CA011.namprd03.prod.outlook.com (10.255.124.28) by CY1PR0301MB1996.namprd03.prod.outlook.com (10.164.2.14) with Microsoft SMTP Server (TLS) id 15.1.365.19; Fri, 15 Jan 2016 09:20:10 +0000 Received: from BL2FFO11FD019.protection.gbl (10.255.124.4) by BLUPR03CA011.outlook.office365.com (10.255.124.28) with Microsoft SMTP Server (TLS) id 15.1.365.19 via Frontend Transport; Fri, 15 Jan 2016 09:20:10 +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 BL2FFO11FD019.mail.protection.outlook.com (10.173.161.37) with Microsoft SMTP Server (TLS) id 15.1.355.15 via Frontend Transport; Fri, 15 Jan 2016 09:20:09 +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 u0F9K2M3021707; Fri, 15 Jan 2016 02:20:04 -0700 From: Peter Chen To: , Subject: [PATCH v3 1/1] USB: core: let USB device know device node Date: Fri, 15 Jan 2016 17:17:27 +0800 Message-ID: <1452849447-25025-1-git-send-email-peter.chen@freescale.com> X-Mailer: git-send-email 1.9.1 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD019; 1:77CBPfX43bzFFFO6yxYKu5figj5+gZQjci+B5vnPOEHvNpuBgwjzxQkFlS85B51MWlecDJBtXZ3QJW3T8qOJnXWKc/qyrlc3Jkpiui3Rx7DIkZoHdNIhxZCESm8UZPsqqLm/pApGVmRpy00qc894+bqrgSj1O+6WYKQhZs3RO2rul8lxgdrILqvMJLmM6viFd3xrkd/iPXNnIXP/8SSDECM4Oh4W/VEr58pfw5S/RskhjQ2TskNGRi8Dp82d+f3Hfufptbn+xgxZOPPwojoGQGpYfMm5hHHbKg8ooQpA/KVmc6qvftSm8MSQJQyJUUpWOr72rqx8GcreQDR2fJRNasT21I1BEOPvXhyfptQqJdo5iedGKFwFaMA+k+xmTvnyIziHQVgnpp7ofgn1+JOfKjrQvn71tb+UiFymrHfwD5wFCFyQKX7TwA9yr1aW/5UeVS2QjcebT4DiQydJ3xtmpQ== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(448002)(3190300001)(199003)(189002)(97736004)(4326007)(586003)(50986999)(86362001)(5001960100002)(229853001)(5001770100001)(33646002)(92566002)(50466002)(81156007)(85326001)(5008740100001)(19580395003)(4001430100002)(19580405001)(6806005)(106466001)(107886002)(104016004)(48376002)(189998001)(36756003)(15975445007)(5003940100001)(77096005)(2171001)(11100500001)(50226001)(2906002)(1096002)(47776003)(1220700001)(87936001)(2004002)(309714004); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR0301MB1996; H:tx30smr01.am.freescale.net; FPR:; SPF:PermError; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: a3e2d9bf-e135-4dfa-9fd5-08d31d8d10f0 X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1996; 2:8tgS/Vvo/HgexkXdzrBCiaSXBqOkThox0lo7vy8p8QryZXkoACaTclU0BQ/SygKM5w2wTS4/NH2tHl1WyfzZE4DIwk/WF/IAba1X3TOz1TF0IHJG3WvuojXyyNRcqCsjhwDCgVjQroYM4W4zyScO3LSpIGyh/bjtVn5KF8PItTc2olyQoHHkcPrpHJ9Jloz5; 3:+/UDMNcvl9fF8+hfQRfiprNLeH2ne94CwX/8AuLXbIYz2u+rcgwxY2fKJvydyKPozmb8SOGEJy12t6LcQznWVba4ahcf1j11zZASueNivofhG0BnSbiUnSDjIQ6NNTwO8e8+W86AV0bTXhhOD4HFwV85pRcvtdZZbZJZKrqeWZ3tElZGL3IV5jUEwKscQ1OV1rq4BSECg2CX0oGJOjUgi98rTkofg8IIxStAg68ju4w=; 25:EO9hTV5dsjaH3ZyfWnyTgVFpaS1AdM2Kht51iC1yllNAqbSlBqDLDy2Ek3WHYQN1oSZoi1esgri0Kmndw5CbIFjGvQ/FJu0tfApYU30Eb/zWoSCgvuZBMZnSAhd8j9RKKYCrcUMSTDu9Ae7vwNGmDIrqBonhBtAFm8lkwOmczeOT1djbPQegYKPRQCus0b+KIUG6X+ss9C2vKAi/+s/T9PX3RjhKh9j5nMGpjr5YzP18vhrVsh9uQ3TJkd8hiA/d X-Exchange-Antispam-Report-Test: UriScan:; BCL:0; PCL:0; RULEID:; SRVR:CY1PR0301MB1996; UriScan:(101931422205132); X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1996; 20:l/Pg3TtE+1E4cCSL9ugEldE3e39EpbfB2NbeU8STg2o6YNWjJtjhcJpy/f0otT1stKmKnnMd+/o+FKEVBMUShuB4hgagfHXSkjQw5739ngewxXyVeGv8kFe+CDAgydm5ctNKP4deDquvAwJo5+uWbZm7vJkKc3KJ1tWYVBdNXMnpWaRf4G4YYuySlq+RVzvnVOY+9OJ6h2j2GiHQ3BzqZycGHUn61kwB4uRQSQH5Quahf/bSLwSppQYJ2xpK599mi0U3l5VkfHP9P0Ob1XH+F4LWG5xaNaWIpp2o6kfEFmlkiKp2oTgNjdvbNwHzGMC0WXJZV7rStNVuwWMFRcB4Q8xEqNxG79zf7Nl9uzQrmp9NRlpBKVQqq0C+TF7WUejGol4Kbr3DY7t4kO9zFIfwe9MDIGs1MhXtf5IXWHQ5KVhH2Eh3zueTzYReLHjAJV8E; 4:02fJ7ICHJjg9SppVhrpASwaO/1WoAfWW8SxBKjf/aWgaImUnqq+/8/23EBlFxiMJXH6iy0jH1Z57lwYOHqoT4YNhkJYvfabGIZ0UQm0BXkDa+1UToLk/eYoQkpbAxHEiKJuF4N0WDCGCEYGGZBY3681HYMbyg6Eo+NodSqFUQictZROsBjtGVBLOmgRULS22a3adKhFkyJnvZdoPA/cb0Z5JvUCFx36n77WOj78YMylUFpNx7j5ef0WKEbsVGZT1ZZveoEG7ArwoEm3TT+S25/rYJ4xECPz1ZuzvEZD9KceVLelUTigetn4VOyHoF8covnfIQ2zqyASbXQeKp/PI/XsJAo30ipg3814DH/LC98NImAi3gSTO4kLbQSRE1Dcq0y1tG7srIcUjhatUi+9Xe/bi2vZOLRWB5lPyBwd7Ocua+QJbdlaewijo4xICmOgJvMALGjRpwMzsu3UNKSgbzLfuRWIGJqlvQIl7eG71sjA= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(13018025)(8121501046)(13017025)(13015025)(520078)(10201501046)(3002001); SRVR:CY1PR0301MB1996; BCL:0; PCL:0; RULEID:; SRVR:CY1PR0301MB1996; X-Forefront-PRVS: 08220FA8D6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR0301MB1996; 23:Vs9OY8tzL16hWkYh571TcBKrQI6CbTpDDRwKs2F?= =?us-ascii?Q?isP4GtQNrp/VN+nzaAfyKWvG0lKfoDet3+pFv4BdUkW6t1azRiCgXgj7rpT5?= =?us-ascii?Q?s6R4cdc5aToXikRWXK20LsFe4529qWiA2XzSV4/miIXd7hOfxL/AzrY7370s?= =?us-ascii?Q?8PTfF5ULVf6S9BD0SQpYdDr33hxR5yO8ubPDfRbQ/RNuAC+IdaGgSOOPwIRb?= =?us-ascii?Q?qv3YD+Mt2Lkj1QTog3IPNKZQtQ02ZL0azgBFXtHjaYcIcUydd1OU6FlydN3s?= =?us-ascii?Q?x+U3iscRluE1o/nAHX9bOO6Ov4GReSIylPgE9yRULzfWbwUIeXMst1CCKSS7?= =?us-ascii?Q?PWa/iXZrsjNuwXCDxVphefQ8KCm35hF0S6vAEWDH5Dg2J9DtnYnjSpzkgclw?= =?us-ascii?Q?BmrG0rOFNT50I2Iq0dm01bYBbMfcQozkYT59nTm5I/3EXxeLKlEfMH7I69dM?= =?us-ascii?Q?jR4bAs8Hw1jTdTqD7jGEjSCRNJHvq0rC0KBL2UIrHo88DiVdBJHqx83eqJMh?= =?us-ascii?Q?m8sr8V+62uISNUEdpkrJ8Fk1ca3w9KmjVLRKqQvK8Gt7OgvsNn0TK/Q5w9vL?= =?us-ascii?Q?6UvCeCzxpm9xklCIMhGRdw1go3XFvPXz4tX3vjgsWVo9WP4s5m6kRHCgEQOD?= =?us-ascii?Q?408jpDqQP3D8n5DqnEUIDHd2Lq4QB1rXLjAhu80jsLTGDuxhGgkFO/+LuL4Q?= =?us-ascii?Q?bnJlZ8T9In7+MnB8mzqlUJEWJK9kgnGE9XVk7/UEM2KxfJZ1OeMr1+RnoJ81?= =?us-ascii?Q?mPLE8JK5DOBNgkJ6d/Tj5FIkBR3byVc2PiVI5s+sOa5uM6u8T6oBKpGn87hq?= =?us-ascii?Q?5H7yaNtZ0zdvvg5us5ThphLIgq7ZHC58zirUkE2D4ABOPalkieTBNQ84F8cm?= =?us-ascii?Q?mXp2UebMKUaGJ2XWv5I9Zvbg4HrnmC4xfbYWinjgF9qIuX3IHFewbCtJzum0?= =?us-ascii?Q?qtECW/pd76D9zJW4U6wC24CDOtxRoJpkA98vqvYl3f7oCxA8Y75wf9ypoC1J?= =?us-ascii?Q?YM2TGZjND+Zo3z0VKqSc+jnNUajkGS0Pg4WQjSGlT+1oL0zUC5ciVJxQj+tT?= =?us-ascii?Q?QrRHairQoTDQz8c4laD1ieWEabRNvtGzJFsEHRiPliStQ5gpsqGGlcYI+Xs0?= =?us-ascii?Q?9mC+Iy5hGFjfoJ22f0leEXjpTK+unG/QU?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1996; 5:XHEma7tiUoS8fhj2izVfElfigyeX1fNII/Y6gXzy/o0eKTobUayHO6UXWQpxYHSlYQhtxPJLG477V+xxYACatrZsNx5NwWji2PwQRgaDzTYV475Ux1mh18T681SlR7B7cNHS++lX2WDccZQJwEeJ+g==; 24:hyTS8RQyzqOr/p+BuKk+UzVj1IaXAErmKH65mrVjF6AIbN4v5w/TPfur3sR3ee2jK9+PiLMoUMiURfofC52aDoGuRxpsLZzQBoZw7UyZSJI= X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2016 09:20:09.8363 (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: CY1PR0301MB1996 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160115_012033_999213_57A36FDD X-CRM114-Status: GOOD ( 26.44 ) 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, stillcompiling@gmail.com, arnd@arndb.de, pawel.moll@arm.com, valentin.longchamp@keymile.com, s.hauer@pengutronix.de, linux-usb@vger.kernel.org, balbi@ti.com, robh+dt@kernel.org, Peter Chen , kernel@pengutronix.de, 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 describe 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 Acked-by: Arnd Bergmann --- 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 | 17 ++++++++ drivers/usb/core/Makefile | 2 +- drivers/usb/core/of.c | 47 ++++++++++++++++++++++ drivers/usb/core/usb.c | 8 +++- include/linux/usb.h | 3 ++ include/linux/usb/of.h | 7 ++++ 6 files changed, 81 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..0468834 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/usb-device.txt @@ -0,0 +1,17 @@ +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 +- reg: the port number which this device is connecting to. + + +Example: + +hub: genesys@01 { + compatible = "usb05e3,0608"; + reg = <0x01>; +}; 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 77e4c9b..64c094e 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_get_child_node + (parent->of_node, dev->portnum); } return dev; } diff --git a/include/linux/usb.h b/include/linux/usb.h index 89533ba..98fa1f4 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -25,6 +25,7 @@ struct usb_device; struct usb_driver; struct wusb_dev; +struct device_node; /*-------------------------------------------------------------------------*/ @@ -536,6 +537,7 @@ struct usb3_lpm_parameters { * to keep track of the number of functions that require USB 3.0 Link Power * Management to be disabled for this usb_device. This count should only * be manipulated by those functions, with the bandwidth_mutex is held. + * @of_node: Associated device tree node * * Notes: * Usbcore drivers should not set usbdev->state directly. Instead use @@ -616,6 +618,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; }; #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..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)