From patchwork Thu Jul 7 09:14:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 9218657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2118F607D9 for ; Thu, 7 Jul 2016 09:25:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11FCC287E8 for ; Thu, 7 Jul 2016 09:25:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 05891287EA; Thu, 7 Jul 2016 09:25:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 86FD7287E8 for ; Thu, 7 Jul 2016 09:25:04 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bL5X1-0003vf-Aw; Thu, 07 Jul 2016 09:23:39 +0000 Received: from mail-by2nam03on0051.outbound.protection.outlook.com ([104.47.42.51] helo=NAM03-BY2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bL5WU-0003JD-M4 for linux-arm-kernel@lists.infradead.org; Thu, 07 Jul 2016 09:23:08 +0000 Received: from BN3PR0301CA0072.namprd03.prod.outlook.com (10.160.152.168) by CY1PR03MB1503.namprd03.prod.outlook.com (10.163.17.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.528.16; Thu, 7 Jul 2016 09:22:44 +0000 Received: from BN1AFFO11FD013.protection.gbl (2a01:111:f400:7c10::164) by BN3PR0301CA0072.outlook.office365.com (2a01:111:e400:401e::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.528.16 via Frontend Transport; Thu, 7 Jul 2016 09:22:44 +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=fail action=none header.from=nxp.com; nxp.com; dkim=none (message not signed) header.d=none; 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 BN1AFFO11FD013.mail.protection.outlook.com (10.58.52.73) with Microsoft SMTP Server (TLS) id 15.1.534.7 via Frontend Transport; Thu, 7 Jul 2016 09:22:44 +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 u679M9nW024626; Thu, 7 Jul 2016 02:22:37 -0700 From: Peter Chen To: , , , , , , Subject: [PATCH 4/6] usb: core: add power sequence handling for USB devices Date: Thu, 7 Jul 2016 17:14:50 +0800 Message-ID: <1467882892-27589-5-git-send-email-peter.chen@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1467882892-27589-1-git-send-email-peter.chen@nxp.com> References: <1467882892-27589-1-git-send-email-peter.chen@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131123569645178180; (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)(7916002)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(19580395003)(19580405001)(189998001)(69596002)(97736004)(77096005)(15975445007)(85426001)(2201001)(48376002)(2950100001)(105606002)(5001770100001)(36756003)(87936001)(2171001)(86362001)(50466002)(76176999)(50986999)(33646002)(586003)(106466001)(104016004)(6806005)(5003940100001)(11100500001)(92566002)(4326007)(50226002)(7846002)(356003)(8676002)(305945005)(229853001)(81166006)(81156014)(47776003)(8936002)(68736007)(2906002)(8666005)(7059030)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR03MB1503; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD013; 1:NnBb+edF+mkaM/CYv5jN7ZUjmyUMhWqKwoh/aWSo5x+efBPEh4/DJWCx7YPE5fC93oI4ZQDOxL2v8FVQcbOf0jlnmbDFqBDQLWUjbbJeu4i5Kzrmy9lsXYG8O5IagiD9K7TH5RDQqTs2qx9DAfc2U4TuFGqxUAi5+nPe6ilwdrgAy3kzdfav/dPxsNq6vnQoF8e4tymlfp338czk0r76cRaCpV4tzq3+D+DA9+6duj3n5yQt9XlexOSkxXjj472XZ6/DPuSzac0Uqi4qa6E7ImvvA3pEkcM1vntdkJEWUN5WWNWKnjgYkcIeYwxqJcBe8sKZJrIfOqSXNvam0OgQtO5mEup6tRSEpXLbHgfN9OFD/yR1C3svyPc+5lr+D6kOdf+K74HPk3+Ewg9dJ8HpFtAcofgBzu2UkhxlY8d6bWNksnViRo8bG7n7epNZ4eqzva6kuvitLJBfqKPpZWnxyexLJ19P5ayk+cmi14oqxBJq3bD9Wyd+BfskIvP+hv9IDYq57bTWAYKem6AHqPz0oln6eNSLdAS9sBepUVB7671f4z+BKEq6Can7h4gkMFCrXQcSI4FeKFLN7BmkDHDsG+HVb06+owNlhZbTHzR9obI7HjoLhVcXHCKEVQ4coVomXmJso+BhOcLNRbiOoraIMAz78gMyqQqHXEo2GFu8S0oxv5DjQTmqZOq5y9dZqL9+hmQ8bQmdFLHG/kEIwrDqGqB4ZQ+u5VeL3E8H0UBN6PcipySTBMPX2SaVzPjLwcu/ MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 455d5fea-c2ca-4244-6be6-08d3a64840d6 X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB1503; 2:1Ao1QFWoLQ4poxEoTkJDOdn3YxikFmCSgzCa207RAg+uYt9pdsQR2EvlAkEpoq2PTfTSj81M1EAkBPi8Uflwt2b9JYSzSLqdmRC2MOTviI2MNOX363M1d50e/6YocTPemr/5yyDFcTL1gKqamx+hJFZxFYFOGLSPVTV+Kt3Bj74rM+0XQ6KrM7tXGJcyKDC8; 3:C7gExPb5m/Xp3+hREgCcxB7NzInxudyHeNHFBCZclHqNQwCKWmmgJVRUR3l3tq81EpYIi5ULAo6aut0yp+xa2E9HuolTPy3OXeEwlTteNLch5Q09taZ2jhw6kw0F6REiv3QCIzVV3PJnFbYasI4ED4V0gN3itZj9jtYrSQ6t3vGf8QtY02yUOW2LbHDeTZmYF+jE9/gYqUOBqC9QS5wlFT/fL3YaoOMcPHguj6P96oY= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR03MB1503; X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB1503; 25:4f17fDZjPsoqJcXK9rXuUn/VtBRLd1pz9Wf6OvLeNf5wKpxnSdbPIcBcabXBsofYH9bVJ3AJEEl8HUT1XVRzBgn92Y+rTFgBQssR2xV+5LctVIDHMv3PK7q/clXSW5+EsSbIdLSAj7UQjxnlplrFIBzeBMzGuhxCtVXzRUqO5y22RQN08woZ5IR6b8QAuwnr1YiDrmyYBJvVy+oYTiLThJzZG88LqRrgGX/irHmZ388kv7imhxRrHQJU5iPkv5w5injbdRITMcZA3RyE9jP9csLEWjdrjYe25TDD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Vs86xY1l3r4QoPQvxMgr+ceRbNSpWjI7yQ4fnKxjxGClmCyT/VCeQLVhTy3sUv7Wj1IhpDINZH0ydp/cAZqAuGpjhZMy01o/J1t5RuEvTrbsU/r3rnQ5fH88cwRL+BSVj7xP9lGGOc3ywFnorThgHVvdmRBl2ZD/eJv8PEpTRvem2a2INo1yGQpHqgBU3ZVdgNmDOuAkiYZo+DeCritBOylqIZzL9LAraryywfzrZVH3J3tMxc7WwponsUH7uJoXS4QEx3p1ax90HOIIadeBaiOVtOlv1Ubx2t5AuxDxi4bmX6EOWZUdi9wWw74JInjc4ukRSkisw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(250305191791016)(22074186197030)(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13023025)(13024025)(13018025)(13015025)(13017025)(5005006)(8121501046)(10201501046)(3002001)(6055026); SRVR:CY1PR03MB1503; BCL:0; PCL:0; RULEID:(400006); SRVR:CY1PR03MB1503; X-Forefront-PRVS: 0996D1900D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR03MB1503; 23:pcL6tfTGYLfXGznot9fd0WFky2p4Qii6lTy0t6Mfm?= =?us-ascii?Q?I1wbndVSyu1L0TqA88NYB8rnWbS062d3U7f690y8rRfHABUxMEHSPC4LBaMJ?= =?us-ascii?Q?aI8VmR/PKJOGQ86GEccar2hrUgxjUIXd4syEnhTCNAMfzxA51tR7TTQtrL0r?= =?us-ascii?Q?u/50UdvVat1CBWZ6TiT+RITQ7hvFBhPhb7S7hyIH5V7tfj0SObOnKGkTpF6o?= =?us-ascii?Q?x/JPb6qQ0WE1vFTk8p/TbXxXYenil7ZU3PUQiuBuyC5xTYjVQx0fCYlI8bYr?= =?us-ascii?Q?GiV2qds8dq3mWbphGwI2ISND/cHV7hxzeEo2O1xOWt/x9EUMsh/a0jCxRyl9?= =?us-ascii?Q?QRp/sNPx2KWgws9kfkYNy9Yr2RW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wKpiLAJGkY=3D?= X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB1503; 6:o5tVtGI2WPqXLbGtBWvQATl4zPiHguwTg6CTpZBAqQlmVNjwi1/L2znXwQmAPY5FSSQLMdyvpMyEz2iKxo+T17LtJBhFTRx1dPLIs6CE4OK/83u74K+SaW45/LZsqQCYk+inWDQHRuMq27UYNV8q+kJuu6ZbYNqoTKmhuDi7j1ozId1gEvb+JGTwbFgMVSlNhFmhOgvut1X7dojtajQsk601o/2lz8JmgJ6yZ0niZaqsNiNfLyFyK7zdeXBvfZeuwiOloNw+492/O/EVNTug0cPruo10rZZ6Zk+sMu9KKXg=; 5:qB2uHrxDjbl8n+fGsDPxCehWOghzRogveZdYINVba0MG5VTtWmLkyn8NqVdlqQnb5L52h4siqWazWf3d55BzSnu7twGnFY2qpz8A1FKmbPtND/m/AdXJ8UMfm+ClXQEBQN3e3/RjcMwrR29YY70WQi5+22VtBZt6dr67g7/faQs=; 24:meU9KEROqzmmwDWWGy0bkyatAao2MOVU6UCM70MG+xhtgMFpYCQDwNAwkS1Jd6/kTtIGvFRJkEDFmYqC85H4kEcVfdYAnOKnYoHwTPPif/k=; 7:XeD6ycGk8Lz7TCCV07A5vY+RVAxKxUtbrZMs3U1VYtAmiSgq6sZ47RHcLXj7k+PjbB3VXuAIWwe44POsszbuRVg2sxdUN7201M/T7mO/bliNuCyJ3PE9snplIhyncGz7rub9FMKFZy3mgCoO5dxeG/utUDKj1p1OWanN4f63N9IZAfBWkGGhaQALgnRqIr6EihXXXTIebAv5CV2JKL6CqtS30tb5TgroJHzcBkPOEb4dYQIQD22CNA1W2zMxPOG5 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2016 09:22:44.1902 (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: CY1PR03MB1503 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160707_022306_792483_F9923366 X-CRM114-Status: GOOD ( 22.82 ) 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, k.kozlowski@samsung.com, stephen.boyd@linaro.org, oscar@naiandei.net, arnd@arndb.de, pawel.moll@arm.com, linux-pm@vger.kernel.org, s.hauer@pengutronix.de, linux-usb@vger.kernel.org, mail@maciej.szmigiero.name, troy.kisky@boundarydevices.com, Peter Chen , 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-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 calls power sequence library APIs to finish the power sequence events. At first, it calls pwrseq_alloc_generic to create a generic power sequence instance, then 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 property "power-sequence" for it. At hub_disconnect, it will do power off sequence which is at powered on list. Signed-off-by: Peter Chen --- drivers/usb/core/Makefile | 1 + drivers/usb/core/hub.c | 12 ++++-- drivers/usb/core/hub.h | 12 ++++++ drivers/usb/core/pwrseq.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 drivers/usb/core/pwrseq.c diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile index 9780877..39f2149 100644 --- a/drivers/usb/core/Makefile +++ b/drivers/usb/core/Makefile @@ -9,5 +9,6 @@ usbcore-y += port.o of.o usbcore-$(CONFIG_PCI) += hcd-pci.o usbcore-$(CONFIG_ACPI) += usb-acpi.o +usbcore-$(CONFIG_PWRSEQ_GENERIC) += pwrseq.o obj-$(CONFIG_USB) += usbcore.o diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index bee1351..a346a8b 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -1700,6 +1700,7 @@ static void hub_disconnect(struct usb_interface *intf) hub->error = 0; hub_quiesce(hub, HUB_DISCONNECT); + hub_pwrseq_off(hub); mutex_lock(&usb_port_peer_mutex); /* Avoid races with recursively_mark_NOTATTACHED() */ @@ -1733,6 +1734,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 = -ENODEV; desc = intf->cur_altsetting; hdev = interface_to_usbdev(intf); @@ -1839,6 +1841,7 @@ descriptor_error: INIT_DELAYED_WORK(&hub->leds, led_work); INIT_DELAYED_WORK(&hub->init_work, NULL); INIT_WORK(&hub->events, hub_event); + INIT_LIST_HEAD(&hub->pwrseq_on_list); usb_get_intf(intf); usb_get_dev(hdev); @@ -1852,11 +1855,14 @@ descriptor_error: if (id->driver_info & HUB_QUIRK_CHECK_PORT_AUTOSUSPEND) hub->quirk_check_port_auto_suspend = 1; - if (hub_configure(hub, endpoint) >= 0) - return 0; + if (hub_configure(hub, endpoint) >= 0) { + ret = hub_pwrseq_on(hub); + if (!ret) + return 0; + } hub_disconnect(intf); - return -ENODEV; + return ret; } static int diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h index 34c1a7e..9473f6f 100644 --- a/drivers/usb/core/hub.h +++ b/drivers/usb/core/hub.h @@ -78,6 +78,7 @@ struct usb_hub { struct delayed_work init_work; struct work_struct events; struct usb_port **ports; + struct list_head pwrseq_on_list; /* powered pwrseq node list */ }; /** @@ -166,3 +167,14 @@ static inline int hub_port_debounce_be_stable(struct usb_hub *hub, { return hub_port_debounce(hub, port1, false); } + +#if IS_ENABLED(CONFIG_PWRSEQ_GENERIC) +int hub_pwrseq_on(struct usb_hub *hub); +void hub_pwrseq_off(struct usb_hub *hub); +#else +static inline int hub_pwrseq_on(struct usb_hub *hub) +{ + return 0; +} +static inline void hub_pwrseq_off(struct usb_hub *hub) {} +#endif /* CONFIG_PWRSEQ_GENERIC */ diff --git a/drivers/usb/core/pwrseq.c b/drivers/usb/core/pwrseq.c new file mode 100644 index 0000000..fbfa122 --- /dev/null +++ b/drivers/usb/core/pwrseq.c @@ -0,0 +1,102 @@ +/* + * 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 "hub.h" + +struct usb_pwrseq_node { + struct pwrseq *pwrseq; + struct list_head list; +}; + +static int hub_of_pwrseq_on(struct device_node *np, struct usb_hub *hub) +{ + struct pwrseq *pwrseq; + struct usb_pwrseq_node *pwrseq_node; + int ret; + + pwrseq = pwrseq_alloc_generic(); + if (IS_ERR(pwrseq)) + return PTR_ERR(pwrseq); + + ret = pwrseq_get(np, pwrseq); + if (ret) + goto pwr_free; + + ret = pwrseq_on(np, pwrseq); + if (ret) + goto pwr_put; + + pwrseq_node = kzalloc(sizeof(pwrseq_node), GFP_KERNEL); + pwrseq_node->pwrseq = pwrseq; + list_add(&pwrseq_node->list, &hub->pwrseq_on_list); + + return 0; + +pwr_put: + pwrseq_put(pwrseq); +pwr_free: + pwrseq_free(pwrseq); + return ret; +} + +int hub_pwrseq_on(struct usb_hub *hub) +{ + struct device *parent; + struct usb_device *hdev = hub->hdev; + struct device_node *np; + int ret; + + if (hdev->parent) + parent = &hdev->dev; + else + parent = bus_to_hcd(hdev->bus)->self.controller; + + for_each_child_of_node(parent->of_node, np) { + if (is_pwrseq_supported(np)) { + ret = hub_of_pwrseq_on(np, hub); + if (ret) + return ret; + } + } + + return 0; +} + +void hub_pwrseq_off(struct usb_hub *hub) +{ + struct pwrseq *pwrseq; + struct usb_pwrseq_node *pwrseq_node, *tmp_node; + + list_for_each_entry_safe(pwrseq_node, tmp_node, + &hub->pwrseq_on_list, list) { + pwrseq = pwrseq_node->pwrseq; + pwrseq_off(pwrseq); + pwrseq_put(pwrseq); + pwrseq_free(pwrseq); + list_del(&pwrseq_node->list); + kfree(pwrseq_node); + } +}