From patchwork Thu Mar 3 10:01:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 8490831 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 2D64C9F314 for ; Thu, 3 Mar 2016 10:09:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DE0DA20225 for ; Thu, 3 Mar 2016 10:09:01 +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 B459A202AE for ; Thu, 3 Mar 2016 10:08:59 +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 1abQ9b-00035f-1m; Thu, 03 Mar 2016 10:06:43 +0000 Received: from mail-bl2on0088.outbound.protection.outlook.com ([65.55.169.88] helo=na01-bl2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1abQ9P-00033X-LL for linux-arm-kernel@lists.infradead.org; Thu, 03 Mar 2016 10:06:34 +0000 Received: from BN3PR0301CA0006.namprd03.prod.outlook.com (10.160.180.144) by BY2PR03MB313.namprd03.prod.outlook.com (10.141.139.13) with Microsoft SMTP Server (TLS) id 15.1.409.15; Thu, 3 Mar 2016 10:06:13 +0000 Received: from BN1BFFO11FD013.protection.gbl (2a01:111:f400:7c10::1:167) by BN3PR0301CA0006.outlook.office365.com (2a01:111:e400:4000::16) with Microsoft SMTP Server (TLS) id 15.1.427.16 via Frontend Transport; Thu, 3 Mar 2016 10:06:13 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.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 BN1BFFO11FD013.mail.protection.outlook.com (10.58.144.76) with Microsoft SMTP Server (TLS) id 15.1.427.7 via Frontend Transport; Thu, 3 Mar 2016 10:06:12 +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 u23A60Ks025904; Thu, 3 Mar 2016 03:06:08 -0700 From: Peter Chen To: , Subject: [PATCH 1/3] usb: core: add power sequence for USB devices Date: Thu, 3 Mar 2016 18:01:14 +0800 Message-ID: <1456999276-6315-2-git-send-email-peter.chen@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1456999276-6315-1-git-send-email-peter.chen@nxp.com> References: <1456999276-6315-1-git-send-email-peter.chen@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131014731731668067; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.158.2; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(87936001)(2171001)(50986999)(6806005)(48376002)(2906002)(1096002)(5001960100004)(76176999)(4326007)(47776003)(85426001)(11100500001)(586003)(189998001)(36756003)(50226001)(92566002)(50466002)(33646002)(19580395003)(105606002)(5008740100001)(2950100001)(229853001)(104016004)(5001770100001)(86362001)(1220700001)(5003940100001)(19580405001)(106466001)(15975445007)(77096005)(7059030)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR03MB313; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:sfv; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD013; 1:pBR8NMgC11uVwa0DCx81789/geW/gYCcTp0DesTddLUReQEI9+7SXiv3U/AFm9fSDL8UBAfHNyPaif8sqmgu7WURjquoAXA33yaTsu2HOUskD34kaLrzlzGZBk7Umq3/+49IWyX8N3NaS3xo50klsZlZpJ0e8Pvdegm8LZQbucQo9sUBjWeVQaro9+O63EKflwFaoxzSZ5YqplX4qz8rAiDpddTIwTN5d9h/gU+ln6Onp1U6mxp3pfGpI4R7n2pBcd11RmYugdCtTrPzkT9HR9O5/L3p6Z3xumRv0Y/jZtnlje2IhKNHTaGTzDqSe/IZ3w6gzMr7a02mjbFI3yqTOG3VPvpyHS77962oMmLQYLXrgDg4DX5hiGweEkpA/1dDPYywByZ+HJhl4F5QwvHu7QsQVeSTJh3kGj63hHFicc7oOO+Q47mjMO90lO6WnjE30Am2bGNOSDk5LjesmHkahGaN79I99QWtoidy6z9WCXjlVAVi0OfKUQ7O4LgsJF8n/6CeaLd83ykpm3LYxrWKoF8blafb8jPQubYrnVKi1IgW9Iu+OVjj2dKfuKDU8+9D99rrjnQvMFnhzn2BdYqy0RfPoL0GGrI7XLMkBkmRmUVv7k9cZcoyVUDBSILHYbcz MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: cf3e4c54-e14f-49b4-8c63-08d3434b73ac X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB313; 2:U/5hbdth/cecKcv2ASm+DAESXkW5R4XQabNIyBDGF0i7j5VXpPu1/slqpDQ+ZLr+nnN+h1C2SxgIoz7U9T6DNyRSMttemAm9l4ChrA+am/GiQwTGBgMlvWzyeHQb0/xafX2tLV9n1yoVOjRzpCGElyqlHvlTfE06Lr9M17qx8gPvEiUzuRyLDbpLsbi1jWKI; 3:ZczLZODF96q/9+ZcGh1baigsZbN2oyYaSbK3rGMdu3g/rRDLZ/gGdtaQJEmZRijteqbL+yxxsEq1AdQawJ9sFkiPKyQXD6dmNZ8OmkXs22jMCJUpVKIITBjkW8wK40t/F4IXN3/UCdpmkOKCJRZUtwm3vWy8LbfIsZt1GFwdzdJQxwdZCDDx3kIM5pg8/49uSSiUNxj2G3/uGeVWt0+A5NxNHI/muLa5Agc6afojg+w=; 25:UKqc8bpU22GVlgbN4Uz6ZJx2uFivUnu0Kkk6UAO3ouX9wjUgoj6Fy5/S6eKnsv4Ch2B4kN8NiCi1xMHG/GRa6evr3peGUU8hgYXeAv1XR98qH6yydmu4ZVK5okZaaw77cgd4/Yz+YBOjeMCjGwlqpcbt14ekJu/Bx9iYMxvUxkrVLdgvXCywz/HGKy8cVIWR+rC7oW0s03/7I+5J9rx7Tsa9j1ZHSf4rcOT5o9Z/QUhqOInsD2Kjq8XAzchqiU4He7ri/IammAXTwGCuhOnD62HMTNQSvnTEUIG78T2oiQO6qKhmnjy9sk3R0vIz0Jj75jpJ6Y0jKZEkX8dGGN66w8um+OpQMW8MADruQnUpzh8= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB313; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13023025)(13024025)(5005006)(13018025)(8121501046)(13017025)(13015025)(10201501046)(3002001); SRVR:BY2PR03MB313; BCL:0; PCL:0; RULEID:(400006); SRVR:BY2PR03MB313; X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB313; 4:eNDCxFY10XBKA3NP86sRy6uhbzKZ2b8NYO8Vezl4DHjN+r9h/FvObxO0+bnxIGva0YBPYhNkCo8GQHLd9EbIUtlSzIjN5cPZYmHvFuyN9337dG1dyJKwIbkO6ScxDipQTvMQpFXALY0Wr1mknVl7W2Cwr0j1rs1tT8gDQ7IteQJadnyk8wm+OYqaxWAHMpb1jzJlIhits541ciDXIvCVNgGncOav3ZQaC6KQkXd0cz9gypwb+kUHPDqYbGGVbrkqexSsCmt0qJ7aqPjVNkuKlaiARmAQDVqrjTPMKpaZFAt1iKBNItsiAAoKI+au2vH5ZbzpcjCa7zyLRT+7NikotXgmJBXGkcJIA31xE1nRtSpuZ5XOUiCjRWLNw26sFmWypheWb7XqjwjvvzjHe/T2mA8rKVyOLH7YpH53ua/FOzzmqkGpfkoSuTKMJ0toJ9JXv2X4k9ZQ1SeSffd/T+jmpA== X-Forefront-PRVS: 0870212862 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR03MB313; 23:oXFGXDqrPmMvxzOPyQzmsSaJAstu3KvZYprMmtPIyq?= =?us-ascii?Q?ZTwceMGnrDESMxxaz7uRzxrGBf1+ato+DzFqpBCzDE/xglC00aX+zxld0tV4?= =?us-ascii?Q?LD87yLnXy9NW+f38Ayr0Bj8rWxJYp+sF8w03CUSYKH0RY5TnQq8l5GqTO9eV?= =?us-ascii?Q?6IFnDc5FUMB9Q/lo5Ln+2QJK5zdD60FSuo5F3FABGycf7hJ92SYkdz7rQpwu?= =?us-ascii?Q?CEcoFu0GUKsZ0L0AxTJ0/G6U1+inesBXKWh7tTyU5Zw2DqX25vto26kUJrvr?= =?us-ascii?Q?Ys87tNI7IV6zP4VnAzXbNsvFqfd3DUwiVPdx2L6YMtLjBtmCu2SgF1jYbVeD?= =?us-ascii?Q?/F0GQ4peIazZag4bfMrePAntFBLUqgn8uV0FI3ESaMykv7GY/waP5B5fML6D?= =?us-ascii?Q?xqgInqUfUXVeIXYmijb+YzDpTAbtmITFn4/aHykA91hjaEj9vm8wvUNBOZkS?= =?us-ascii?Q?Yi+8zPFzrRh6tRZ9NL4hXRZscAUkbDOylX+8umjz6RB9shAukqRm8WbUlP7w?= =?us-ascii?Q?qDNb0w708Ed0AuyQ1tO9RIKKbsB4yD4E+HNBvtq3wkYeCiwHNTRPx+qp7PVu?= =?us-ascii?Q?PhOLQmcEPZJn69gDzOWnqq5CqZB6VACwhwPH4uSJky7Xs0MttcHgMC3u4KDk?= =?us-ascii?Q?5/aKqlrL5mFsyxwEnz/ylb2HJC33RlpZIIYLgwZT37Bsx7Hl5NOKK7r1H+Df?= =?us-ascii?Q?zzUfZIKf+ojNUcH85Rf7w8L5NcrToWXIhjXByymyHQN2s1zQBkUAJ3rBuVxJ?= =?us-ascii?Q?jE6jJLX+t3/Flwy3D2xbk45tF9ljMIcwu92rWk6TDi4TQeP9r4S5uKtv2sMs?= =?us-ascii?Q?PKr4S4rlvwY3xjZAfHv29xdqRYvO94ESVB6CRsnZ6LDnJKSTpkyM8nnXXoXk?= =?us-ascii?Q?XK99CsGHCw05KdxUdlQGgu9johkQbib03FNAKsIPyWIFzPHCb35llvtt7A1O?= =?us-ascii?Q?Mk6KRd9CsKel9ObHqRS6Tsnsv2aIZYji5V3inCrX0j2BvWFfsHAXuTXj55tp?= =?us-ascii?Q?JxomRCXcSACTAHXMadn+ri7hVH0zhDc+SDfbpcJMvjFLMhppJE+GpGwQBfMD?= =?us-ascii?Q?qF43dJRd3RNaffavrrFvyfQPcQe05UEHWCIraWfnesYyCBViML6bXMk3xba3?= =?us-ascii?Q?HBzV0ATjVCOgnl+qhxjp6QzW1S4Ga8?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB313; 5:So8jC68m+nU7rpsPxLZDGqGBMMrcG7/czMao8Zj4DjmI8R9DyNVG4UQlB/kRxvwrlpk68X3GNafE/8IpltQ7qWRSMycRVfzj9W/2yJTMjO/D/aCdp9SHN85FtG6rgDQYIfArqBVvJkjWRD4HyeSny7z6T9GwLbhEHIkSJ1qWgjs=; 24:BNKZ+3iv6eHQEUHaJr4wgJxfqRPTe+j26hGQABK+A6VY4IdAyjDMo9Dm4nWz9l7mox/jPx3YFbyt0jU+4knuT6GxY3IyL7pczvakJJoodt8= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Mar 2016 10:06:12.7924 (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: BY2PR03MB313 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160303_020632_084840_C2513954 X-CRM114-Status: GOOD ( 22.93 ) 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, mail@maciej.szmigiero.name, arnd@arndb.de, pawel.moll@arm.com, Peter Chen , s.hauer@pengutronix.de, linux-usb@vger.kernel.org, troy.kisky@boundarydevices.com, robh+dt@kernel.org, p.zabel@pengutronix.de, festevam@gmail.com, 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 Some hard-wired USB devices need to do power sequence to let the device work normally, the typical power sequence like: enable USB PHY clock, toggle reset pin, etc. But current Linux USB driver lacks of such code to do it, it may cause some hard-wired USB devices works abnormal or can't be recognized by controller at all. In this patch, it will do power on sequence at hub's probe for all devices under this hub (includes root hub) if this device is described at dts and there is a phandle "usb-pwrseq" for it. At hub_disconnect, it will do power off sequence. Signed-off-by: Peter Chen --- .../devicetree/bindings/usb/usb-device.txt | 41 +++++- drivers/usb/core/Makefile | 2 +- drivers/usb/core/hub.c | 32 +++++ drivers/usb/core/pwrseq.c | 149 +++++++++++++++++++++ include/linux/usb/of.h | 10 ++ 5 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 drivers/usb/core/pwrseq.c diff --git a/Documentation/devicetree/bindings/usb/usb-device.txt b/Documentation/devicetree/bindings/usb/usb-device.txt index 1c35e7b..c7a298c 100644 --- a/Documentation/devicetree/bindings/usb/usb-device.txt +++ b/Documentation/devicetree/bindings/usb/usb-device.txt @@ -13,8 +13,37 @@ Required properties: - reg: the port number which this device is connecting to, the range is 1-31. +Optional properties: +- usb-pwrseq: the power sequence handler which need to do before this USB + device can work. +- clocks: the input clock for USB device. +- clock-frequency: the frequency for device's clock. +- reset-gpios: Should specify the GPIO for reset. +- reset-duration-us: the duration in microsecond for assert reset signal. + Example: +/ { + ... + + hub_genesys_1_pwrseq: hub_genesys_1_pwrseq { + compatible = "usb-pwrseq"; + reset-gpios = <&gpio4 5 GPIO_ACTIVE_LOW>; /* hub reset pin */ + reset-duration-us = <10>; + clocks = <&clks IMX6QDL_CLK_CKO>; + }; + + ethernet_asix_2_pwrseq: ethernet_asix_2_pwrseq { + compatible = "usb-pwrseq"; + reset-gpios = <&gpio4 6 GPIO_ACTIVE_HIGH>; /* ethernet_rst */ + reset-duration-us = <20>; + clock-frequency = <24000000>; + clocks = <&clks IMX6QDL_CLK_CKO1>; + }; + + ... +}; + &usb1 { status = "okay"; @@ -24,5 +53,15 @@ Example: hub: genesys@1 { compatible = "usb5e3,608"; reg = <1>; + usb-pwrseq = <&hub_genesys_1_pwrseq>; + + #address-cells = <1>; + #size-cells = <0>; + + ethernet: asix@1 { + compatible = "usbb95,1708"; + reg = <1>; + usb-pwrseq = <ðernet_asix_1_pwrseq>; + }; }; -} +}; diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile index 9780877..9cdc548 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 of.o +usbcore-y += port.o of.o pwrseq.o usbcore-$(CONFIG_PCI) += hcd-pci.o usbcore-$(CONFIG_ACPI) += usb-acpi.o diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 0f82db4..0091428 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include @@ -1680,6 +1682,27 @@ static void hub_release(struct kref *kref) kfree(hub); } +static int hub_of_pwrseq(struct usb_device *hdev, bool on) +{ + struct device *parent; + struct device_node *node; + int ret = 0; + + if (hdev->parent) + parent = &hdev->dev; + else + parent = bus_to_hcd(hdev->bus)->self.controller; + + for_each_child_of_node(parent->of_node, node) { + ret = on ? usb_child_pwrseq_on(node) + : usb_child_pwrseq_off(node); + if (ret) + return ret; + } + + return 0; +} + static unsigned highspeed_hubs; static void hub_disconnect(struct usb_interface *intf) @@ -1722,6 +1745,10 @@ static void hub_disconnect(struct usb_interface *intf) kfree(hub->buffer); pm_suspend_ignore_children(&intf->dev, false); + + if (hub_of_pwrseq(hdev, false)) + dev_err(&hdev->dev, "failed to do power operations off\n"); + kref_put(&hub->kref, hub_release); } @@ -1731,6 +1758,7 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id) struct usb_endpoint_descriptor *endpoint; struct usb_device *hdev; struct usb_hub *hub; + int ret; desc = intf->cur_altsetting; hdev = interface_to_usbdev(intf); @@ -1850,6 +1878,10 @@ descriptor_error: if (id->driver_info & HUB_QUIRK_CHECK_PORT_AUTOSUSPEND) hub->quirk_check_port_auto_suspend = 1; + ret = hub_of_pwrseq(hdev, true); + if (ret) + dev_err(&hdev->dev, "failed to do power operations on\n"); + if (hub_configure(hub, endpoint) >= 0) return 0; diff --git a/drivers/usb/core/pwrseq.c b/drivers/usb/core/pwrseq.c new file mode 100644 index 0000000..eeb231d --- /dev/null +++ b/drivers/usb/core/pwrseq.c @@ -0,0 +1,149 @@ +/* + * pwrseq.c USB device power sequence management + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct usb_pwrseq_data { + struct clk *clk; +}; + +static int __usb_child_pwrseq_on(struct device *dev) +{ + struct usb_pwrseq_data *pwrseq; + int ret = -EINVAL; + struct gpio_desc *gpiod_reset = NULL; + struct device_node *node = dev->of_node; + u32 duration_us = 50, clk_rate = 0; + + pwrseq = devm_kzalloc(dev, sizeof(*pwrseq), GFP_KERNEL); + if (!pwrseq) + return -ENOMEM; + + dev_set_drvdata(dev, pwrseq); + + pwrseq->clk = devm_clk_get(dev, NULL); + if (IS_ERR(pwrseq->clk)) { + dev_dbg(dev, "Can't get clock: %ld\n", + PTR_ERR(pwrseq->clk)); + pwrseq->clk = NULL; + } else { + ret = clk_prepare_enable(pwrseq->clk); + if (ret) { + dev_err(dev, + "Can't enable external clock: %d\n", + ret); + return ret; + } + + of_property_read_u32(node, "clock-frequency", &clk_rate); + if (clk_rate) { + ret = clk_set_rate(pwrseq->clk, clk_rate); + if (ret) { + dev_err(dev, "Error setting clock rate\n"); + goto disable_clk; + } + } + } + + gpiod_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS); + ret = PTR_ERR_OR_ZERO(gpiod_reset); + if (ret) { + dev_err(dev, "Failed to get reset gpio, err = %d\n", ret); + goto disable_clk; + } + + of_property_read_u32(node, "reset-duration-us", &duration_us); + + if (gpiod_reset) { + gpiod_direction_output(gpiod_reset, 1); + + gpiod_set_value(gpiod_reset, 1); + usleep_range(duration_us, duration_us + 10); + gpiod_set_value(gpiod_reset, 0); + } + + return ret; + +disable_clk: + clk_disable_unprepare(pwrseq->clk); + return ret; +} + +static struct device *usb_get_pwrseq_device(struct device_node *node) +{ + struct platform_device *pdev; + struct device_node *np; + int ret; + + np = of_parse_phandle(node, "usb-pwrseq", 0); + if (!np) + return ERR_PTR(-ENOENT); + + pdev = of_find_device_by_node(np); + if (!pdev) { + ret = -ENODEV; + goto err; + } + + return &pdev->dev; +err: + of_node_put(np); + return ERR_PTR(ret); +} + +int usb_child_pwrseq_on(struct device_node *node) +{ + struct device *dev; + + dev = usb_get_pwrseq_device(node); + if (dev == ERR_PTR(-ENOENT)) + return 0; + else if (IS_ERR(dev)) + return PTR_ERR(dev); + + return __usb_child_pwrseq_on(dev); +} + +int usb_child_pwrseq_off(struct device_node *node) +{ + struct device *dev; + struct usb_pwrseq_data *pwrseq; + + dev = usb_get_pwrseq_device(node); + if (dev == ERR_PTR(-ENOENT)) + return 0; + else if (IS_ERR(dev)) + return PTR_ERR(dev); + + pwrseq = dev_get_drvdata(dev); + clk_disable_unprepare(pwrseq->clk); + + return 0; +} diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h index de3237f..1adf065 100644 --- a/include/linux/usb/of.h +++ b/include/linux/usb/of.h @@ -18,6 +18,8 @@ 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); +int usb_child_pwrseq_on(struct device_node *node); +int usb_child_pwrseq_off(struct device_node *node); #else static inline enum usb_dr_mode of_usb_get_dr_mode_by_phy(struct device_node *phy_np) @@ -38,6 +40,14 @@ static inline struct device_node *usb_of_get_child_node { return NULL; } +static inline int usb_child_pwrseq_on(struct device_node *node) +{ + return 0; +} +static inline int usb_child_pwrseq_off(struct device_node *node) +{ + return 0; +} #endif #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_SUPPORT)