From patchwork Mon Aug 15 09:13: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: 9280647 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 E04F4607FD for ; Mon, 15 Aug 2016 09:25:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD82C28BF0 for ; Mon, 15 Aug 2016 09:25:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C045E28BFA; Mon, 15 Aug 2016 09:25:14 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC10128BF0 for ; Mon, 15 Aug 2016 09:25:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752961AbcHOJX3 (ORCPT ); Mon, 15 Aug 2016 05:23:29 -0400 Received: from mail-sn1nam01on0045.outbound.protection.outlook.com ([104.47.32.45]:31296 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752941AbcHOJXZ (ORCPT ); Mon, 15 Aug 2016 05:23:25 -0400 Received: from BN6PR03CA0046.namprd03.prod.outlook.com (10.175.124.32) by BN3PR0301MB0836.namprd03.prod.outlook.com (10.160.154.146) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.549.15; Mon, 15 Aug 2016 09:23:20 +0000 Received: from BN1BFFO11OLC003.protection.gbl (2a01:111:f400:7c10::1:143) by BN6PR03CA0046.outlook.office365.com (2603:10b6:404:10c::32) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.557.21 via Frontend Transport; Mon, 15 Aug 2016 09:23:21 +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 BN1BFFO11OLC003.mail.protection.outlook.com (10.58.145.14) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.567.7 via Frontend Transport; Mon, 15 Aug 2016 09:23:21 +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 u7F9Mh8e020596; Mon, 15 Aug 2016 02:23:14 -0700 From: Peter Chen To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , Peter Chen Subject: [PATCH v6 4/8] usb: core: add power sequence handling for USB devices Date: Mon, 15 Aug 2016 17:13:14 +0800 Message-ID: <1471252398-957-5-git-send-email-peter.chen@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1471252398-957-1-git-send-email-peter.chen@nxp.com> References: <1471252398-957-1-git-send-email-peter.chen@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131157266022269219; (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)(68736007)(4326007)(47776003)(2906002)(76176999)(356003)(81156014)(229853001)(81166006)(106466001)(86362001)(7416002)(11100500001)(33646002)(77096005)(2201001)(19580395003)(19580405001)(5003940100001)(305945005)(48376002)(36756003)(50466002)(626004)(50986999)(586003)(8676002)(69596002)(92566002)(5001770100001)(15975445007)(2950100001)(104016004)(7846002)(8936002)(105606002)(50226002)(189998001)(85426001)(97736004)(87936001)(2171001)(8666005)(7059030)(2004002)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR0301MB0836; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11OLC003; 1:YfA7mibfxFsn6bVbFzWKdEMp4Bt21xGoFE5JWMHDSgbBfz6stfbFopzzYfNTArieh1xg+cLCAwxLEqBRdQVAJhOEvCIqk53o6LZOivyWYEmpJyZNCarBMXGD1niiMoKro7vsxTatYb1YuXZ4MLpLVKH35DMAHO3kA4X/xPFREfoPCqYVW8eJOA1RAvdt1eX+vK9D+izkPViTCnNnkXgGloBVIcZbekmdNt2LxXivQJLiHB460qWvM+f7TfdnoLqgzVNtP6rqbz3Q/5OvGck2GjTkZ9BfpP1ZxYdtpLo3RWH1yLFmdZD2nchZQIvz2jJaACmVR74cfF5Nl0T+KR4VlRYOp83aVlxBmjqUFSAy1x9Q0uJSDSqTS9tQn5TtUFxRoyXvhHBiGf8YYV1O745H9s3Jc+nnWvK02tlieHKlNG6iCcmoalbzpyEVYY2zvqrnFX4jloP/mGIDW/dAsM5R620OE1rl44k3BEB2s003dNJxrq2VGiTZkxjKJAI5LFm4ZGTGC0OVlAPssokzLqvPBGrmYW8v+Lqry3p6jz8pH3OGo0Vr/ZFHF0cX5u6z7KLeai97miNcr3LtW5rGUn+If0eiAtjEuzBGXCSZOi23fsFNV9eNy+x8Gws6Z1EuPDofvcLcNndcZW1FloK8SU4wo8jkw8YfYS8WutiZedq1sNfRPU4/JARbFz1BqbECwY1YUjmoov1yNlodJrT70Z1pmNVyYqH/LQzBLQXVQdlawsxYkgrSkreT8vXCNHVEvXMw MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 9cb2131d-1e46-4fce-9fc6-08d3c4edcd6c X-Microsoft-Exchange-Diagnostics: 1; BN3PR0301MB0836; 2:DTFNdB/5PskftodzYsf62UU3FBWR63e7q6iZngIRCnWTmeyzPBpYRveTYMUepm+8P9+3BnFCGiebN3q3UBTay9fL7yb6aYSf4npV4Rh7WpkdFPlhGXqlZjwMytEF0oZry6YOCLIi1WSWnUeTmNG0Nz0kAuMTpUUoQX25Mn15g+BYtvJnQuiz+MsiA9o2TnMO; 3:zYEcFOLaDylBKDYUgGUkiz2+7xLLSUuIPFRFZ3Dx2rJpXmfK3+qxxiKvYKgQobMw0/eK7aINuEfrVRVGWHRw7WFkT+FCpPxpF59bIEs5OVJ72qq+xlE6q1wjeY9bNayW02819QkwZ6o9buMoPxxieIknIy6N+pT3InkwQ43OhVbz874KtsKIzxZFIPp5tv8FE3Kw8S4H9go5UCvvEM7iNT/nxcwUwiUnf+fkibZUe/E= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR0301MB0836; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0301MB0836; 25:PEZy9Iox6mq95gPPfC59IYqa71ZCUn59m1Jm6fBznvZc93aSIsjm+pW5O4p/lju7e8tajY1ROcxCBNrxbodaMt67AWgk2GibPhPGN8iQ+hQaaqO5gbfy7u7wQblv8KDtnT//Kulf8Zeloe06epw87Led/U3pzrKqYJBd3W11pxAtG8WwZSW+Gb51TcC4nU1DbHYTsY1MzdH8Bh/hyDyktbTnuW787TE1kL0FbR5Uakpdj7i4laBDl4GFEbOrKuoloUMbv/70rTmx/qvdim4XCfC9P9NVzZj3v6HsS6PtSjRn2gX0KdgwFzveaLbXYHKDAIYimQkIjuneMBgXRrqAv2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7EPL2SbCAExBt7RZDYgDWUMTYmaWJ0mLks0oFDjubuhePpvWkC5H/wVNbEQiOsWH6Fa2Ccpc99lvmkkm5UnJ4PwnRg4SckfTDgKBv8H/ewXrwc/G4eGElzmicHN2TNX/8FnHN9jzZiMsJPumkWGVI/elqO6NOPLxP3eiUx6SPlmvAISLgZ5TdAlHpBIuYRmEHthLAYRoUZ7zEN0iKrFhm5YQa6Kd5A7EsD/MDocP0bUS/0ZfBwPXjq/vuISXDy6FTb2s4lvy/hHkYnSrOcLz2HcgEpRncLxj/OsTUvp6+p0AMjtZaIdqSRTU77Yu+DTm1o= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(250305191791016)(22074186197030)(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(13015025)(13024025)(13023025)(13018025)(5005006)(8121501046)(13017025)(10201501046)(3002001)(6055026); SRVR:BN3PR0301MB0836; BCL:0; PCL:0; RULEID:(400006); SRVR:BN3PR0301MB0836; X-Forefront-PRVS: 0035B15214 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR0301MB0836; 23:bqxcOFla08qIPSYXsX0v2dlzZJIspIeIQqv3CCf?= =?us-ascii?Q?kfF+QsMxTVKrN4Fd8+WuZiZaK/iOTkwvZhqJUUdUTco9ILiG+0RfQ4jF4TVc?= =?us-ascii?Q?UJvjyBMgL5lmdDOIbneJhh4Lba/zRxED+co7lHdqkjRp/8Kg7nBCza7tuzMX?= =?us-ascii?Q?nQIZx0zK8qm8h7iU7o/PMUB9Js3oDt4I+kmpKvwuTif8JQC0MJbY1PtLtLIZ?= =?us-ascii?Q?GOruN15t9uUk/lhvpkZBXmTSt3jPcpkumSCV55xhLOTwEj3t7kBjdyQahgAH?= =?us-ascii?Q?/LpEDgS9y0DMgkc6nAEVSHwPUwkEybjOX3T1BzLR6ZMzwuvQdu1HlPopfByY?= =?us-ascii?Q?GvSiSaqI08fs2Sw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Q?bXhA143GSdUoA3ev4O2n1Tjplbal4M5LGt9ineV1f1PbCEI5PvrBXPyT8Mg2?= =?us-ascii?Q?W6g=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN3PR0301MB0836; 6:nj2qaez/qK855hRgD3+8czj62PjQ+SN8s2zMceUdjWZ/shmRGUM0FqPMRoG0lLzvuxy18jmxThb3Z0vLcS16fy3j0wTW3eZN49ZN3u3iMzIWFljGxrIuv8uFqd9XwIF3D5uWrCr14vz/PRrFXwsSM1Lui3N0iXtc2WZKEX0Yoxpi8guey5tt3s48TqfUuruIGIUpyat/u6vTZo6dCji7tZD9YIwKfZgCMHBX0GeuYl4AQgDzpcgu8EAPru8T1uVNSse2KXP7Wk/ozHbsMMPrZeSZKsrQqmYMt6p41dkUZnE=; 5:dmBSVJL2vfV6lvzrh25NtLV0jkCMhmViVIwr5UhIIGsyDFNCqmYQ2Ssm6ehKn7E+RPVdkUoUoX+IHk2y0YajwIxHLnHuIQUHQBCju2wmN8wp1cmwFUOA3a/0ocY3Kp7MOlFanEFCyazi8wXWVEg00QPNb6IMjSeKuaxSd6o2l6g=; 24:DQXrPbhUe4Tk2qDMWJlpfXSOdV2hLSFL8Ao2fR45p6jNz3gOi8vAI+MZYibfwdtYWpfj67HJNMdze8Hy3ZwNK4H+zS62WkIIahA8b8VQYoY=; 7:ZsV+0FSsXDyUOCJmBwApamAbBDfmbpKkJWGBwliYuzgB/c8e6sICB9Kq3k3dH3ADRZjf7iJfUy1wV/MNkc35vvE54xhCEFZuQqMDxzNdI2e5SCovGF/AOi5V7hAvElSGt5htIqaBEAF5Ps/4DhCcogl7tl5KSxDN3/bBK2berPii3zjsxuyHbEfQTSf+rumWCPAsjzUo/BD4z1z4p155hIetWRnqzVPERPyElhJ9uQvE6cRfMgFjcmMGWAKSrZQH SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2016 09:23:21.6497 (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: BN3PR0301MB0836 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.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 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). At hub_disconnect, it will do power off sequence which is at powered on list. Signed-off-by: Peter Chen Tested-by Joshua Clayton --- drivers/usb/core/Makefile | 1 + drivers/usb/core/hub.c | 12 ++++-- drivers/usb/core/hub.h | 12 ++++++ drivers/usb/core/pwrseq.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 122 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..837fe66 --- /dev/null +++ b/drivers/usb/core/pwrseq.c @@ -0,0 +1,100 @@ +/* + * 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) { + 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); + } +}