From patchwork Tue Aug 2 03:30: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: 9255063 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 E24C86048B for ; Tue, 2 Aug 2016 03:42:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3143284F5 for ; Tue, 2 Aug 2016 03:42:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7579284F7; Tue, 2 Aug 2016 03:42:33 +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 8AB2F284F5 for ; Tue, 2 Aug 2016 03:42:32 +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 1bUQZj-00085X-0D; Tue, 02 Aug 2016 03:41:03 +0000 Received: from mail-sn1nam01on0043.outbound.protection.outlook.com ([104.47.32.43] helo=NAM01-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bUQZN-0007kB-Fk for linux-arm-kernel@lists.infradead.org; Tue, 02 Aug 2016 03:40:46 +0000 Received: from BY2PR03CA053.namprd03.prod.outlook.com (10.141.249.26) by BY2PR0301MB2055.namprd03.prod.outlook.com (10.163.196.157) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.544.10; Tue, 2 Aug 2016 03:40:18 +0000 Received: from BL2FFO11FD055.protection.gbl (2a01:111:f400:7c09::120) by BY2PR03CA053.outlook.office365.com (2a01:111:e400:2c5d::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.549.15 via Frontend Transport; Tue, 2 Aug 2016 03:40:18 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) 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.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11FD055.mail.protection.outlook.com (10.173.161.183) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.549.5 via Frontend Transport; Tue, 2 Aug 2016 03:40:18 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u723dYUL006554; Mon, 1 Aug 2016 20:40:11 -0700 From: Peter Chen To: , , , , , , , , Subject: [PATCH v4 4/6] usb: core: add power sequence handling for USB devices Date: Tue, 2 Aug 2016 11:30:50 +0800 Message-ID: <1470108652-16812-5-git-send-email-peter.chen@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470108652-16812-1-git-send-email-peter.chen@nxp.com> References: <1470108652-16812-1-git-send-email-peter.chen@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131145828194315350; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(8666005)(106466001)(11100500001)(229853001)(15975445007)(2950100001)(81156014)(356003)(81166006)(305945005)(85426001)(7846002)(19580405001)(77096005)(7416002)(19580395003)(105606002)(92566002)(50466002)(48376002)(50986999)(76176999)(5001770100001)(4326007)(36756003)(189998001)(2171001)(8936002)(33646002)(87936001)(47776003)(104016004)(97736004)(50226002)(8676002)(2906002)(5003940100001)(68736007)(586003)(86362001)(2201001)(7059030)(2004002)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR0301MB2055; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD055; 1:lVfUms0//iuWI1zlJYa/CUDP9NBntcZtz5moZt/vRSb2r6RRUQb6DjxWNyTsnuul2HjpycmulO1bHaKAYhzpHqbwbtA160L12fFw5ntGf0WehVz3dj4lJQwZtfb6ufr4ANq1RXu6HX0HtuBnJgRTeSwaRVOymB5Wp3DgeFWwPlSPbTuwfNhSbdSmZAj4rg1p9Vaarz/WgHW7Sstin4D/S6xFDkCbkkXMgCOgpZ5eIvTcLFlfM6EEN4YlypebQpiPMimRbC2OnvwjJa2DEJZOyysreYIjjMmZrKCrYdTgonOf9OekEDDKBoWnCPOkbqLF7xPA6ZAAHURIE9Ow/aHXsh3/oLfk+A6Vtd0WXcjBsBW1DmEOQZ/gjsK472A6/0q/S9qpz6ZQCT5RloHtuSiBhsemtufvChi2mNrkDf3Nlws4Vo9P2ivlZLkWLioOXM4RPv2FA1zALVx4lzethyCLhFf0cxxDAmZk/aqsaz0QiDxwabucRex4QTcNbhJ0z0l2GEfu/Mye523NtPUY8odWDSxBwkWvo5R5u6PShHfWYTFCRda90Bvrn0Bkwr6OKI/Sk2BY8FjG7xynIiq5cviKHw8eFi43W0qkkUZzgN/VYO5WU14t/Jigur6PD868rqUY2rxb9WLeXZrtxIUpH+5rHrjhSVNjOImlRVzerf3Y3ltEkg3LedhsjMguMVsg/vw+EQlMTy2+OEnbYZYFMxf/lODf0neg/1+R+lgb7GB5cgExSMJY793LD7bI7W2pzmCz MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: d0e8a8c0-6535-4a13-a7bd-08d3ba86b982 X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB2055; 2:qDw8lZWXBmoRfzmaBabWK4VDjlRp3Vlgb/0O9pN41nHldNdRbRytUfY/JPA6MS62H3es4sSyCwGCrXcJ6eq0mQAt7OfO//7rM8ZDbihaMcYEHJXYETfXJv79eYeVbtTe7Co6exeJ+Y/f++FIKDD6UoDOrgFfc/3ez+Zdj0puO+XJJqlc/Xd7zNs9cUDFalFd; 3:Wl1N2BJHbWP62umqeTF3dyyKloPr0W97DKK/DsS3ekp5vHZmdJi0a8wNXIsb3Jk4w+mWfPazY6Sqs0JFd1NMjXReKmdL2uPOjc39M8QpgJgusRJe0f8l+Hoaoocik0JpIDHm5W6aZa/dJm970TvzdLgR8Zqc8qNnogT+AXImweIp2PV7gUkwe7nbQ11UJqk7Gkl9Q6tPUtBQdjM8c9A+60BnY6XpraH42JRYvJvyhP4= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR0301MB2055; X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB2055; 25:vEaLt7rVUJIb/WfpR/MkY8GdS+mFwd6UPvBW+oR2u7qqUku2vVm3h8A8sclJcaGIDbS2tlKaCovY0dEuPUOJG6Ncp7LvR9MyUl8Q7CPbkuys3DFQK37iGUmoIrFbvJA3qQfr18bYyiX1N9pPPiE/+wl3PPJVCV/MOr36WAHHG1UNGnyBP7chZ2dXQfT/tqlrzI237dpQ/9pDEHFQGWKWyjYaWYSByMw6fcWD3D+IWaXoiB+R03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Dxzkvg1azDFyx1RHcrlXCWbYLYpwUF77h3xIuU1nWz/8ufVgwdjwR9+gM2biKNI8/SY8tFnxyUBIrvSvCQC5eOnvOKEtm7tTOGl5iPZqv2WWLNOpkVVswsA24vU7kNHR6G9PzJR/kqEhekbxP419bBFVzD31nzoTUNop6N3GcsPBKILJBEZMsjzZ5V5Vo0gEsgAVDr1B7jjRGjIU8w/HUC18e1ZkhOsmLHOZibfabYYEQCgzLH4CC86z168azLILVSyIfbnJRFn4ZA/ntNoOJ2yHSmCbY8UhJgQyAXKs4HgX/Y/AOw1rf4uFH/TZY7SrTgmmu2Q8pBfGqMH8rV7i7a9b8161xQBIsigNRLtGrKrJgVKkz8HMSK17FvFB97m0pPbGqyUcK5Q== 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)(8121501046)(13018025)(5005006)(13024025)(13015025)(13023025)(13017025)(3002001)(10201501046)(6055026); SRVR:BY2PR0301MB2055; BCL:0; PCL:0; RULEID:(400006); SRVR:BY2PR0301MB2055; X-Forefront-PRVS: 0022134A87 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR0301MB2055; 23:6I9QWey9tCeBIFdGOcd+Tl6Nnc669jF0dIjQkLi?= =?us-ascii?Q?ADWCl8oZiKy2XljZkoGNV4F6Cgsfz0+cH8oJjN/vHt4qA5xJsPFaktDk883G?= =?us-ascii?Q?zXfAif0awctmPFFPC0Q6fm1LqfmPoJxOafJcGXDgpG0s48m8N+/53GGyO0jC?= =?us-ascii?Q?MutFtVL6KpsL5YeUme89jUN8VzFKxjgZ4c1E5fQDCqfaMnX7Q7HKf5IpPNVH?= =?us-ascii?Q?Ojf3yL1KLpqaeiJqwvLxOr7wL2goZiinu4PC1+pu4YfeAwqO+MawDCm+R97o?= =?us-ascii?Q?W8I0BCximOparcv3oSyL8JtA/+Ymm9He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jIg2OfCFu6P0ht8h1aZhCJchHLt0u93tiTezTKXJCIX2CoF1vis426?= =?us-ascii?Q?nsQwCHPqv6IGmuM6cfGw=3D?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB2055; 6:8vUtoVFTsIAukFZ/pCt6JvZOpwI7xJnMt7nA7v36znfe55eVYliBqpbyA13TEi6fpa5KgFfNb+1MXQ+QQvIviDAR5VxiCngDU5BW93gJbvz9Qk1WQVqSJIpMfiuJULO/qnt1fFdtC+Ou1qYDDsVLc2zoJyXP8wrOOPCnDwTIdc2SDW/NSjl0Kxnoq6qEetpWqhqi2BDF+ai1SxHEo1ot2yUWFqIYqwDw+gTnkmcSHH/LYY+rGMvVEuZzFRJ/ax784vGKPcXYSGA9ZdQz1+XQGXzswkazKiJUMzSP3hrzn4w=; 5:jAx13uCYF6ollfGvh7anpEhXPSmg8qhj2AtVAXSg3O8J/dS/36Tnteel021ldy38a+Ifnl+f74kWXjMgoqdiSRrDiKHmklv47Sq1pUedmhiM0QDheW9x/N2EvsxypzJB5WHbvT4oYcDRXFE05tCiznZDyarGsuZUETJYZKSxzak=; 24:+QJqUljUBo81ls7PAxLBvo7g3XzpqomC3dvTm9SXq5KjFHRsFhqxv1Atnx2k3CP/73064ehu/4rT9Wq8lKlFx5YbC5eq0XJJXbpTs0ijM6k=; 7:WNE6002bh7oTsVbK4z0m4ERvt5S7+UZk7rMBBOeX3nHGDGcqFkb8aKGq9gKkMAbOrBHl2ZzY50GYlkbr3bwQTNmKyGJ6nofrL2Hu71Bw7rdVpITy9jUsjKcxqXZdAtpvVgxL6eCTRKGT1Vj2cUWD+k08TEOzAGwNQTiyAxIOx7zm6AMvm+clSx7pyMD+xdL0+5aHvP+bdBqkuSGwuJC9r3W7zgH8P2QjSAa1LjatgGdZNC/Fp9TgUP4nJztZ8q4L SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Aug 2016 03:40:18.7451 (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.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR0301MB2055 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160801_204041_820489_F8E3E013 X-CRM114-Status: GOOD ( 24.27 ) 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, linux-kernel@vger.kernel.org, s.hauer@pengutronix.de, linux-usb@vger.kernel.org, mail@maciej.szmigiero.name, troy.kisky@boundarydevices.com, stillcompiling@gmail.com, Peter Chen , p.zabel@pengutronix.de, festevam@gmail.com, mka@chromium.org, 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). 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); + } +}