From patchwork Tue Feb 16 08:42:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 583266 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 F2CC91401E7 for ; Tue, 16 Feb 2016 20:10:21 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754694AbcBPJKI (ORCPT ); Tue, 16 Feb 2016 04:10:08 -0500 Received: from mail-bl2on0068.outbound.protection.outlook.com ([65.55.169.68]:51200 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754628AbcBPJCc (ORCPT ); Tue, 16 Feb 2016 04:02:32 -0500 Received: from CH1PR03CA003.namprd03.prod.outlook.com (10.255.156.148) by BY1PR03MB1497.namprd03.prod.outlook.com (10.162.210.143) with Microsoft SMTP Server (TLS) id 15.1.403.16; Tue, 16 Feb 2016 08:46:51 +0000 Received: from BN1AFFO11FD014.protection.gbl (10.255.156.132) by CH1PR03CA003.outlook.office365.com (10.255.156.148) with Microsoft SMTP Server (TLS) id 15.1.409.15 via Frontend Transport; Tue, 16 Feb 2016 08:46:51 +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 BN1AFFO11FD014.mail.protection.outlook.com (10.58.52.74) with Microsoft SMTP Server (TLS) id 15.1.415.6 via Frontend Transport; Tue, 16 Feb 2016 08:46:51 +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 u1G8kj4j008827; Tue, 16 Feb 2016 01:46:45 -0700 From: Peter Chen To: , CC: , , , , , , , , , , , , Peter Chen Subject: [PATCH v5 1/1] USB: core: let USB device know device node Date: Tue, 16 Feb 2016 16:42:52 +0800 Message-ID: <1455612172-2081-1-git-send-email-peter.chen@nxp.com> X-Mailer: git-send-email 1.9.1 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131000860114316965; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD014; 1:2U1oHa7vIpIKEdhr5l+UtDvGdMYKJ3aKoxfwVfXS1Tu3EE8M9GCKdMIeDlitJ69JKJU/vevQhbgMwvuZZNrv2+BwzUbAKkyMjAaxtzw0pvNp01r34tlrNYey5WRaY6snVDW2Ww0B9d4Aa+RDSTsQdA+1VaRgary/wA9Ba28ObYW6/sPHHMZUDVcuOzhjlPQIVXI5SGWnYqytqY/pT4opgBD6aesg9uiwpC/amEwgobp8zxYaUHKUxMIpP08owA28Nu6nIX8b+Son3zYCg6IRRMxwLfLntJ/7XoLPbam+vqsnT1Cb27+k5pmC397f+/bqGrWFEC2tUSg+RS24DFMYzJcW5lYSqIdgqTLfW9g1h9NQyjmzOjSyIdUeanewtm4R7eC4B5ApZLkoxvd+eQo36KElJ50Lwm/ElfyfPcAHESjaKXLl4SlX9sYFErGkB0Vkk38yUuTSVpHiDcKvRILnpIDkKzciXOO/PmO1fqYfC7MTwXQVHtXfsnamtXUre6vs84zkDn98G9R4SZNvolqkYVBEo/H4ri+voDozCcvV90g= X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(1109001)(1110001)(339900001)(3190300001)(189002)(199003)(50466002)(36756003)(15975445007)(4326007)(86362001)(5008740100001)(2906002)(47776003)(92566002)(4001430100002)(50226001)(7520500002)(50986999)(48376002)(77096005)(6806005)(104016004)(5001960100002)(19580395003)(87936001)(105606002)(2171001)(11100500001)(19580405001)(106466001)(229853001)(33646002)(5001770100001)(107886002)(189998001)(1096002)(586003)(85426001)(1220700001)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:BY1PR03MB1497; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: c2cdc129-4c0a-4fbb-0d46-08d336adb6d7 X-Microsoft-Exchange-Diagnostics: 1; BY1PR03MB1497; 2:GsWNadz0pMxSdyRDdA2U/WJpI1eGl7H9OHCiQ6nEd0iqykpK78ML/v98B5hQS8DBRr3nO65bIVFLYvQLf8PMSVfzNP5DHzmLjYjDLC7v0hs01C8MgU8mY/rEh+aSBbfkbukadNG4poO/4VbwBKfvxJHBeyVrN2ehcJMF9bhY4w/xU5VRSGzjZ/yS3E12gXGq; 3:t5iVSySjAUw/5uLyicmYwEIIjG3LVwfUkzTDP6m1939GpiIIHN89KKZ74hA5d6ZwNqgi2/2AuiCpmR/LhSZust1xtBsTa+17D54rPWbcED+O306LSYNXZwFt3UikoMg8UZ818FzRQIJq7XYf9u99i5nah2+MM+fnBOyaWHr+IP70GitBg/MMFU4DrDbJ6GeHhzzoBLruOfpOMikBEG3NSmEgyRzHgxYb00p/rB9vaAk=; 25:AjBc/GUbALH2uywH/Lv5pUZp91iuXThcW7nwDpnJoMPzhY7WuE7d7stLMVCJPBsWb0NTHROAHlnVHMWqPH6eRtm6yMzNEUcU2pcU4IlarTt9IfdT0dkP40mhE1PKbHiYVh4+Jip9UgQ4BHg1OCaZ4gwWqxGjlXmNwdx/IHB4kyLRRKzkGROtxAhtQ1gOA4Y5TDKcyTWOQCfgEGn2iGYFFT2MhqyqTyuR8El0z8wLT1ILkGcWIYYdOTiXOdFGuDwR7nSq3e7gNda5itnBpBbXpzF0Oa0A9r+Jr88HLozzlHrhYLkDyKfvwhANKcWve1F0 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR03MB1497; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(13018025)(13017025)(13015025)(13023025)(13024025)(8121501046)(3002001)(10201501046); SRVR:BY1PR03MB1497; BCL:0; PCL:0; RULEID:(400006); SRVR:BY1PR03MB1497; X-Microsoft-Exchange-Diagnostics: 1; BY1PR03MB1497; 4:DODSFn0jf+XbXNXBywYTkAswe62/mna6RLQgTdwGQDFdFfs7otG+o2YQI5ci2UlDTTGUKLWtF0o1hTGOQlsK9DFqxi+utzXj9h3eRevRME5IWOQYR2JfC00TQEPsV20qLJjDV6nMwTevhj96Ifi1tH1OBuULBhtj+es1UFORc2uvWidk6eDvDhNwIDTzTeB8YwUSIhQXDBazuKO+d8/d+Q1A6doSNFjo1fkvJmAaAnKc66246YSn6M4BSFNoTT5JQTF0KAzHP7nM9eQRjFWP1VhgNtjxtU1sZ3hnYLFaWyLR2ZBHYIs2Lsls2POtdTR8b/gbiAd2pnNLkqSLd9jAU8h5oltDFGa7cb+uaZDGUxflTJBpUcJ8gUAFbvbhZWpE+PNTZCSH3NnCjWHgbGHel+hTUc7S5JsdXRq/tmXG9ScRfrhBUoK7TM9RwIQchItkmWwtgfjaOb0yAMqhknMUAMzb7OzIKw5O4iCFaMB1NvMkPQS6uibynofRVxRU8iR2 X-Forefront-PRVS: 0854128AF0 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY1PR03MB1497; 23:7oZ7/C3E2NayIfbTAo8gMNBLXo3U0AiE7WF7HY6U2?= =?us-ascii?Q?/9jug4NulV5goNJd0use1hOxVm8GyyPuXTYrVcm/9cIgGELtzhYWCEnAwYBb?= =?us-ascii?Q?ZMK0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BuDmfMSk/UQTi?= =?us-ascii?Q?3h77Xqh8Og/JXDniMACz2cp+mcmzduLe9B8OEXEQo67bEJnSsPnLSmutSK2s?= =?us-ascii?Q?7m984Os8uogchAIKp7nKcMtWWto9hVa+Y9VOf2C0pb9Xh5i4ayJU2ehvEsg1?= =?us-ascii?Q?nfcVjDBob67EWiaz1xKjH2BoMWMyozr?= X-Microsoft-Exchange-Diagnostics: 1; BY1PR03MB1497; 5:Csd2ATcaBIQ5VClehfgpyAVcfTeS767U54RIi0mm3J2P1ulw10qUouurgxPnenSztAVivlLkSVAUySakqEy5qzPKVQMw1eumW/2FWSeAs4Sa3XJYcjDpzQxCdnYxigduFplC6VnM0othuDQkhONTULGFHIpY154gVmch8Ju1u1k=; 24:PHoRf9rjn8z6WbLtUc6WuxME618eoNn23SJVTfBVYJ4yC81EP5X56DcQ4YfjOkYAGzLTw4PATvaO6PkIGk4/YoHq+8FR1vvrVK8X4X2bcI0= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Feb 2016 08:46:51.1820 (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: BY1PR03MB1497 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: Rob Herring Acked-by: Alan Stern Acked-by: Philipp Zabel --- 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 | 26 ++++++++++++ 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, 91 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..a997a23 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/usb-device.txt @@ -0,0 +1,26 @@ +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 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 = "usb05e3,0608"; + 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 16ade41..d9b2564 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)