From patchwork Tue Sep 20 03:36:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 9340969 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 3BC96601C2 for ; Tue, 20 Sep 2016 03:38:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B93629B58 for ; Tue, 20 Sep 2016 03:38:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F8F029BEA; Tue, 20 Sep 2016 03:38:02 +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 832A129B58 for ; Tue, 20 Sep 2016 03:38:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754040AbcITDhk (ORCPT ); Mon, 19 Sep 2016 23:37:40 -0400 Received: from mail-by2nam03on0046.outbound.protection.outlook.com ([104.47.42.46]:42496 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753778AbcITDhc (ORCPT ); Mon, 19 Sep 2016 23:37:32 -0400 Received: from BLUPR0301CA0014.namprd03.prod.outlook.com (10.162.113.152) by MWHPR03MB2447.namprd03.prod.outlook.com (10.169.200.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.629.8; Tue, 20 Sep 2016 03:37:30 +0000 Received: from BN1BFFO11FD039.protection.gbl (2a01:111:f400:7c10::1:126) by BLUPR0301CA0014.outlook.office365.com (2a01:111:e400:5259::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.629.8 via Frontend Transport; Tue, 20 Sep 2016 03:37:30 +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 BN1BFFO11FD039.mail.protection.outlook.com (10.58.144.102) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.629.5 via Frontend Transport; Tue, 20 Sep 2016 03:37:30 +0000 Received: from b29397-desktop.ap.freescale.net (b29397-desktop.ap.freescale.net [10.192.242.114]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u8K3antl006721; Mon, 19 Sep 2016 20:37:22 -0700 From: Peter Chen To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , Peter Chen Subject: [PATCH v7 4/8] usb: core: add power sequence handling for USB devices Date: Tue, 20 Sep 2016 11:36:43 +0800 Message-ID: <1474342607-27512-5-git-send-email-peter.chen@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1474342607-27512-1-git-send-email-peter.chen@nxp.com> References: <1474342607-27512-1-git-send-email-peter.chen@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131188162505380625; (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)(1110001)(1109001)(339900001)(189002)(199003)(50226002)(68736007)(19580405001)(36756003)(2906002)(105606002)(92566002)(19580395003)(586003)(4326007)(106466001)(104016004)(85426001)(229853001)(87936001)(2171001)(33646002)(2950100001)(77096005)(11100500001)(189998001)(97736004)(5001770100001)(76176999)(356003)(5003940100001)(305945005)(86362001)(5660300001)(2201001)(50466002)(7416002)(81166006)(626004)(8676002)(81156014)(8936002)(50986999)(8666005)(47776003)(48376002)(7846002)(7059030)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR03MB2447; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD039; 1:C8sBXo1X8qD7Dsfpm6N614G7aL+DxVHPvVmWewXgABbB1s6tW5MigWusMPKJZfqD9o67LPtpA3iMXaX3e10sYXJ+BuFcpplBLCEB9POoHy5Mc/PedLTIGl110hqfG93ga1nMECYvUBEiN9yEesj9yxgYD5OVGcwD510VxDHPPGsfur4JEiJPbWl18MTpCqN3xISCVZZ+4oeMo7vbp2B66IPI1XJ1ZeyrdBbxfS2S/jMi425iLhmxVr4w+88e3ktlgTDWYiYhRjOu9Ii9sJzCxk4WDQHya4Ns3bCQn6tt4HmrxSATiykqa14tfZnNMh0Q/lgrisX+tOsjeFQOXznl22Ehv5bbjKRN6D6QWKNDPZfsuRyDmUGbqb3aJS5OH1HpjnzaskX8UcRhhiNqjrarSN3HU2PY3ZzEttSLoXSVyBw94jxP+2PYqLVbE0Binib++0UWfXAUE0LOMH0gnTfKtf+PSY9OkL7BbSBxA4EmwOKklMzralKF/vNdh0Ax8k+Ys8EmB2T6QDKO/yxJ+plu/DfkUN9ZP7egWJ/UCGrhr3hWng6JrcBm24n1FaG9vY8BxYlVAuuYP8xIeYWsIHJPQm5NcqmfsfMriR5EQ0855rMyulUb27qRTaySxjm9BGljogbsoY3KtfKCysc9c/GOnXznSy/7zSChneZW9r6taf///ER7Kypn7VkhgxCfhaRKrgrEkaryCx5UKB6GU6l1UCS2aje+YyQ1LX8/4Efkuq2/jUnxGokxgGi93hPsOSQK MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: feebb164-6852-4510-31b1-08d3e1077353 X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2447; 2:FKDe+R3SgfdtJt5HwpE7QShhTTkZ+YMFOvd9NJNERyJEnm9KM1edohAEzOXkn0iYudzYUTTJLNfeNbR0Ywu25tyyrEMsHUtV69D2TTBe880xmM9Gk3tpUcU5824xXRNUZ0pwGODOK4f33oeUYonGmVO5ApDh7fBTPf/nFgTnbmrwTubI8+MsEUT3R9BHx4by; 3:bMqWdBz29+71rtY9qsom6puNVzWAbZY8Jw4Ah4ZxEh/fHevMYEhV9NnUz77p7tvIc7PIllKRt8ZO1z9cOw6CyzFIVVayBPSWiMlm1L+fJCrcbJwHW4b3kHz2rIJ9bOAufqnG2guRsU1DcPxSOp+zf6/G+jzDtD9NRCLs+/ZlawtCDxD+NsHG7nMECeZTECbeZrl1n1X1b93ShDKiquJBqE1KPYR0sVrG40FGrqaBF24= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:MWHPR03MB2447; X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2447; 25:XAuCjQPlrFhHMajS/dFsYN+VJlioFnXAKpJFy87g86pxUuEEH8du8/PfkHUTjiQsKs4LOek9O6BN8GIdlG4s4wEPaJtSwKKWOoAk/aS3u74Se+QxQtGXS9nHgEbZiCK6e+LygOxMMnUJgGs8Tjdj6ij458PzbiAskfUPD8HzHhyBf1X7gEY/ktIIhUwdH70b3h2al0aZR2O9m+n8rLpuWQ4IDkbI85kH6fAcJQczTSjccYGxfukiKAzaoKYIfnYKiBwu9iThh34ge10PIzmjd8M81y5nPnSb67it796rUYYVIQkfwqvYprwYhzRG9rZVDm0HVqm6bOV2NYQ5peQHR6a1hOrXYQcjC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ZKLsMWgT9c40aiqRlJmw1Bzp16q9R9vW4lyIyMS/Cw0eW8t/E96aKFnPzmv+KrB39da9ugzSZiiYQwLILcVT2AGIQRm754xEi91LGqJlEbjQcebj7YPyikZyiZe7Zpw4SXz2wqS4CICaE= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(13015025)(13017025)(13023025)(13024025)(13018025)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:MWHPR03MB2447; BCL:0; PCL:0; RULEID:(400006); SRVR:MWHPR03MB2447; X-Forefront-PRVS: 0071BFA85B X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR03MB2447; 23:tJm1a4+35fVjkF0+smHjzKhwAVFm+pRMWNEvxevOC?= =?us-ascii?Q?lHAlKa8M1Mk95yyvI5XmifZviMm4hhuJ4RblLCOVTgToue4BXwGTKyRsKDpM?= =?us-ascii?Q?HLYcCzbCrKAtKU2fgRzyNx3R3LHzS98pdJEjNx5QaUE6AtGVo6wx3jOzJCN7?= =?us-ascii?Q?BSEfnjmNn/lmEJb/zddsOc5AUrNLC5JacvIE743zbRncKCB9z4nsMNC1wXSr?= =?us-ascii?Q?iQiyDJ0n7P6iin7mZ4F6alGdS80w6gYM3jLWnZOedDBOu9HbnmpXK82vaI/t?= =?us-ascii?Q?ppWOGWyXsyfheQsbQo0oz6QPhc+nuhjrJdiQjvi1UaDufw/V6pWopRBoqIZb?= =?us-ascii?Q?lU/61z+Dfl5jf+D04tIWNofSTDIwRINxtPhIbdUwwmH6OFSvjgvYKw0WWGbm?= =?us-ascii?Q?fAkVJ2Cqch9PGTH3vpJoihlMUls79j2Ye/aKcbNIieT8qZgncM32Hsr83lfH?= =?us-ascii?Q?jVA859XiP+x+1eR1Z48q9flELsq92olcUJ0M0IMrLGNpBoj84bGo75WIhHKC?= =?us-ascii?Q?cowsX1YnqTtskIO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v29xfM49qZeBIwnJkivCCydNk7I+Awb4cHVV75iJl/uKSwGphbMAf8o7W554PZRlZTx8Epuy3Uj5/oaw2dA3Q95xyiJSK+OL2X+I00a90L08f1agSWp8/3ascK09SZjiqV/WrRaQ6p/+wgi2V630NAGM=; 5:rxUsJuVTJFTM2EVaJPrGOufwrsmMFZuT6m30tOTP8lNyPkyNH/1J3v0dp3QqlEEDqSld3MRI+9gvZB89QFNHXfgsZT+r2L5ngPmyOMZTU6AqeviYmp+IdnKAL/8sOxkvFAYWQORIcZolNwsxGqoy883wp4WEZg6WNIVj/sGv/Tk=; 24:T4p/NY3CmyMRdqnke/+4K0MAlq1cfxcJQbS3oahEQJA6F8b64BI08exkLOKgQhbDuTdJDrHtyZLi6PCkxzUOXeRppQ+ZVexrc2AeKVnUgss=; 7:Y6GGQkNOmzb78SnUYxU+SfOlSIyIykwdLmv46GYswN4mG+Ux7VTvffIqXoRRr2JGSzA2diPUBfMLPTCnA/VglZ1IHJVQYq5swL72gG/w0fv+C2dLN7VuK7TMvasxGGob6rbHH2/7PeowSrnE+eoMZLgNF+/5OEOaevxW4kDeuvFLOKzuzEMQTaZCWLVLXa9vBzMP+uOGEnycHnNOcKxaosPPMXlALuSAnPVjKMgtw0xyUEUtv0qg7dDj9GPg15KjwaKiqJ3orEJdSpIvlEe6W+eP1+rsggwtvzkovVaPW/K9MeTQMFwxFWvOt9Ve03PB SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2016 03:37:30.1012 (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: MWHPR03MB2447 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. 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/hub.c | 41 ++++++++++++++++++++++++++++++++++++++--- drivers/usb/core/hub.h | 1 + 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index b48dc76..f3de1de 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -1695,6 +1696,7 @@ static void hub_disconnect(struct usb_interface *intf) hub->error = 0; hub_quiesce(hub, HUB_DISCONNECT); + of_pwrseq_off_list(&hub->pwrseq_on_list); mutex_lock(&usb_port_peer_mutex); /* Avoid races with recursively_mark_NOTATTACHED() */ @@ -1722,12 +1724,41 @@ static void hub_disconnect(struct usb_interface *intf) kref_put(&hub->kref, hub_release); } +#ifdef CONFIG_OF +static int hub_of_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 = of_pwrseq_on_list(np, &hub->pwrseq_on_list); + if (ret) + return ret; + } + + return 0; +} +#else +static int hub_of_pwrseq_on(struct usb_hub *hub) +{ + return 0; +} +#endif + static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct usb_host_interface *desc; 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); @@ -1832,6 +1863,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); @@ -1845,11 +1877,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_of_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..cd86f91 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 */ }; /**