From patchwork Mon Jan 25 07:24:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 572621 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 CAA75140321 for ; Mon, 25 Jan 2016 18:28:00 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752188AbcAYH17 (ORCPT ); Mon, 25 Jan 2016 02:27:59 -0500 Received: from mail-bn1on0136.outbound.protection.outlook.com ([157.56.110.136]:59635 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751458AbcAYH15 (ORCPT ); Mon, 25 Jan 2016 02:27:57 -0500 Received: from BLUPR0301CA0007.namprd03.prod.outlook.com (10.162.113.145) by CY1PR0301MB1996.namprd03.prod.outlook.com (10.164.2.14) with Microsoft SMTP Server (TLS) id 15.1.390.13; Mon, 25 Jan 2016 07:27:53 +0000 Received: from BN1BFFO11FD037.protection.gbl (2a01:111:f400:7c10::1:105) by BLUPR0301CA0007.outlook.office365.com (2a01:111:e400:5259::17) with Microsoft SMTP Server (TLS) id 15.1.390.13 via Frontend Transport; Mon, 25 Jan 2016 07:27:53 +0000 Authentication-Results: spf=permerror (sender IP is 192.88.158.2) 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 az84smr01.freescale.net (192.88.158.2) by BN1BFFO11FD037.mail.protection.outlook.com (10.58.144.100) with Microsoft SMTP Server (TLS) id 15.1.355.15 via Frontend Transport; Mon, 25 Jan 2016 07:27:53 +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 u0P7RlmU006040; Mon, 25 Jan 2016 00:27:47 -0700 From: Peter Chen To: , CC: , , , , , , , , , , , , Peter Chen Subject: [PATCH v4 1/1] USB: core: let USB device know device node Date: Mon, 25 Jan 2016 15:24:39 +0800 Message-ID: <1453706679-18948-1-git-send-email-peter.chen@freescale.com> X-Mailer: git-send-email 1.9.1 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD037; 1:kaplSXmAibB5fMwGQJpkx3D4ygU3/KfZ6Ap/0RdyXaFphJtxlc90hO345l2yEqc3/sMV4VOSOqH/0I3VdVHwP6iTCvhnbXhRJkRMH6vezS31TpgTUq2OKa+m/VUzLpGM/Za7HiL3nngHkcrIZyfmm2w1QxrHOn9HjkgfNcSCm/g971z3DRn1L6SjA5wvD1l84hqYcjDtx3kFnjeqNGTgb1K3VX7eJaEnq0waGGKfIdkC+QaZohrMvFY0oUvXu6pFtbYJp7NerEaTG/PDKTPj+VOMZQoll55+YBTb0ifY5tHb3IficP75XXokrHBw5E5uECmDe9SAf+dxTj4NwPYSGxakvA9QSjN0KNLABkuwekXfAXk+C+epJrnNmDZ5ilZm5uW/cM8U3LFDSuwR43CFFoxo8YuaZv3YQzEvG3asLj4tSEj5JcbTpUBDlSMCpCgZxQKctP2NzROB+E4fQqmRvA== X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(448002)(189002)(199003)(5001960100002)(15975445007)(77096005)(229853001)(107886002)(4001430100002)(1096002)(1220700001)(104016004)(11100500001)(6806005)(106466001)(50986999)(5008740100001)(586003)(97736004)(5001770100001)(48376002)(81156007)(189998001)(47776003)(19580405001)(19580395003)(69596002)(50466002)(2906002)(2171001)(87936001)(4326007)(36756003)(5003940100001)(85326001)(50226001)(86362001)(33646002)(92566002)(2004002)(309714004); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR0301MB1996; H:az84smr01.freescale.net; FPR:; SPF:PermError; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 36904c31-5df8-484b-d4ea-08d3255909ee X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1996; 2:crEExloVYiqfmXfsEWVUofRQr3bKtLREiebdBF3p1onQpqmfhQEBnTKM9BPV0LY2uwnfSv/zWD4pjn4z0zjE63l+QeP+Fvh8QkOBjeefJaPKtEWdzyUHOImLgiJ7MZR4nHV/Ypl8tvosPjCA3LaATxMYIkkiBH2EUwWL+CYx5oehQUEGAcChmIaJSzS+snFH; 3:FTNDtykW6Aru3R0d6OKM0GzI6b4bdB/yNVCEotpVNuidkJvqj3L/E0KXOrXzSJjMEe8eIQ39ovbKn5jWlf39pvGMp/f8syeup+yCZYmw0jjg3Q4PR4/1GDV/wghfjW+pOV6LVzUv/knP2YLz5fypqEkyEWXOy+4+OwBIw7JZ19OHh6huppLurCdOYtmkgwbZfjKLy9QCeJAgurhwlWSOZkqRJmp1bEL3B8UZY8QgmTI=; 25:LRBHNtoQlKTvSq8M4lQOHancHAqVXvQQa1jTeJ94PlRRmkTrBMqKbKNLvAtS0zTWQGq5nkhHZPiE/xPN0++miAKbwn605pLdQlkTwTLH54qHfPO+G4sigYCCiGGS8G25s4kH1v7lakoL2XvJFvGsQYv69RStqM0jPj3NQ/asMDGGFkC8GKhBsVt91WPcm1aYZB1u4oPVXdMVHLjQC2KpuxbTob3Es1wyzrjDqySiAMzuQiRmMlRBEthM7KnO2kk/ X-Exchange-Antispam-Report-Test: UriScan:; BCL:0; PCL:0; RULEID:; SRVR:CY1PR0301MB1996; UriScan:(101931422205132); X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1996; 20:6JuvNwxfGL/gFdKASLa8aQJkFOvqxrEX5ys7PgbZVQIu0EfW5NDbVEhBFtunmc5wohwv69EcpWATV7bAW4kBpp+rZ60g/2mEat7Fs6h/AurPsKsnDsQ2tTxFLv8z6Fk2xQwAOixEPtFvO+USav+p6PU3OLoXNTCPt2w1UFCGywHbQWC42h5Ncibb32MOvwj6JGxZ8NbTyP3qLELCGHG/aTJ6zSM9V5GTzWoryVWDCmlKKWRWfjsLc7QTTfKLq1TWVIeoJvYyatbbRjRyIqBfC2yjJlciAYGxG/fRaEZkApgPmiEpqoTScBdviE5FGHEGDP3wCQ4VPjNEXOEhj/5LMjYwS9Cn9Vz3UPcdy7pD6Ie3ds4soo8KZIGqs9yiAMfleGPCDXbMfecIIVzibtSXVnuECcr7jKe3Y+88WdPakqjTMIGIuN/mo32h1u1EMz6+ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(123027)(601004)(2401047)(13024025)(13017025)(13023025)(5005006)(13018025)(13015025)(520078)(8121501046)(3002001)(10201501046); SRVR:CY1PR0301MB1996; BCL:0; PCL:0; RULEID:; SRVR:CY1PR0301MB1996; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1996; 4:akeQZomjoWu+QG291NrwjmPYRq8WCM129zxSVTsQ6vXq1ebEK9ioharkKCdShTpjODDYbDNQgSC/fS5p347M6jwugvj8f2BpS0ztuNEB9E2+SIQeQ9UfrGGNtXxK+kCanKA/YT9Ias+kjzsEaw50Nz82C590WCw7AY4AVuV4yDtWsnJkyrhP1N5Ibq3ziD1xUJbtp6epAerVVgeFjyxKK4yaRwf/A+mlLFp1hVDWbkqIlm6tCqK1/ROKQx7I3dm6tic3D9fpGUtAWC/SSeeEck0QZ6j2ZlNCN5RUkJkOI0WRxaqelk31MW8f6kCscFTU8mpQedZsiCWw4gi2DMCwui//nalPeHvylzv11hRwU6YL71UI7k4XAw80FYIyfiJmhKq+HJOU0oOe5f6o5Hb7dw82kqs3Ki2V5izSAEDEUJ+ZdBVrKZKitoHHMzrCsgDJaDntTzEqhWAhVMO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= =?us-ascii?Q?0iaqMvBNyoOo0tKllPmcyyRQte99tVloOV2K/udbm4kCnxkdVMwDi1PyYnr9?= =?us-ascii?Q?4LpA78gzfyN7N+Oi+5L1czqtswnn5Jdcap1cIfk9IDgVL6hgZWcT70e4zQgt?= =?us-ascii?Q?mPEkrxhTygS8+oiiGFOy4ZmoI0jExsWxR2aDjeCMw2k4eu25TlzjnAhAnQEm?= =?us-ascii?Q?bWEuxssBYDAwsT/C2HQrw3E6AjMUdkooie03TbZDW9bH6nPDgQyxnnCblKyG?= =?us-ascii?Q?aANMnox65srJFKvcvrp6E+s+ruz+3341QjDVy0hWP2BIH+C9ra/DvmrhDUro?= =?us-ascii?Q?cuaQ8OM8LDs2LZPtqquOf90pGCMUpd4ZztZ4GETU9F3QhXx9DID34RFuXi2j?= =?us-ascii?Q?YzMXpIApnKULdPOHyJCsuYueiceAtBemr?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1996; 5:tmOblhxIiBTtddwbre77clx8bGUwr3uYk5+gzijGkP8P5sVgliha6+mK46cm5MjgSuAlzLO5YgpTEpfTtavxVj13LThtaLmtOf3ofFpVB81tVFhG+gYvZlddWsi6ZqTVJk5nnbyCq7hQ814PpYlj3g==; 24:9/PenX/P1+X+aIzgHxK+iZqunhge6LTdCZ9DefpLMIcvviGAAgm/OFWNbOd8qksaZjQVWVlEW7/5GuZ7f2z2IISoNJvHdhOjDd9rKDoIs0c= X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jan 2016 07:27:53.5215 (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.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0301MB1996 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org 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 --- 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 | 25 ++++++++++++ drivers/usb/core/Makefile | 2 +- drivers/usb/core/of.c | 47 ++++++++++++++++++++++ drivers/usb/core/usb.c | 14 ++++++- include/linux/usb/of.h | 7 ++++ 5 files changed, 92 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..c702885 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/usb-device.txt @@ -0,0 +1,25 @@ +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, the range + is 1-31. + + +Example: + +&usb1 { + status = "okay"; + + #address-cells = <1>; + #size-cells = <0>; + + hub: genesys@1 { + compatible = "usb05e3,0608"; + reg = <0x1>; + }; +} 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 ebb29ca..25d9770 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -508,11 +509,20 @@ 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->dev.of_node = bus->controller->of_node; + } else { dev->authorized = !!HCD_DEV_AUTHORIZED(usb_hcd); dev->wusb = usb_bus_is_wusb(bus) ? 1 : 0; + + if (dev->dev.parent->parent == bus->controller) + /* 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); } return 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)