Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932213AbcKHDHL (ORCPT ); Mon, 7 Nov 2016 22:07:11 -0500 Received: from mail-bn3nam01on0068.outbound.protection.outlook.com ([104.47.33.68]:60422 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753227AbcKHDHH (ORCPT ); Mon, 7 Nov 2016 22:07:07 -0500 X-Greylist: delayed 937 seconds by postgrey-1.27 at vger.kernel.org; Mon, 07 Nov 2016 22:07:07 EST 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; X-IncomingTopHeaderMarker: OriginalChecksum:;UpperCasedChecksum:;SizeAsReceived:1446;Count:10 From: Peter Chen To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Peter Chen Subject: [PATCH v9 4/8] usb: core: add power sequence handling for USB devices Date: Tue, 8 Nov 2016 10:51:08 +0800 Message-ID: <1478573472-29516-5-git-send-email-peter.chen@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478573472-29516-1-git-send-email-peter.chen@nxp.com> References: <1478573472-29516-1-git-send-email-peter.chen@nxp.com> X-IncomingHeaderCount: 10 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131230471192034366;(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)(199003)(189002)(76176999)(106466001)(50226002)(68736007)(81166006)(81156014)(8936002)(5660300001)(50986999)(77096005)(50466002)(92566002)(48376002)(8676002)(5003940100001)(2171001)(33646002)(87936001)(586003)(85426001)(4326007)(5001770100001)(97736004)(626004)(7416002)(2906002)(2201001)(47776003)(7846002)(2950100002)(305945005)(575784001)(6666003)(8666005)(356003)(36756003)(104016004)(86362001)(229853001)(105606002)(189998001)(7406005)(7059030);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR03MB2896;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD051;1:6AyLEUfpP0C8zankUFY+dRPaYkc0C5vW2XLytCdMajcPQ6YBJM4EbbIZ/VyZvfnXdqOVuIqqDs1ZjubxCzr3aTnikIeLuh0oJFIA0ogF9zlYmLnIRcI6QlhoPMtHP7Pgu5gVMFk2T/8oJc/kWqDxqKsjwiFezfUyWP6idVa1gFgOcFWPsQ8kdZJN/udjNFt4FP5JDAnco0qbBiO1QlN8pcDnlY1uWB6AlnDDUOiIFkrcZT4NpNPN4ClEEQpwC+z3vVeHWLfkcK7KFAhhNvto1fBYhiVUlGE+Y9ALokQ7UNycoVSbW3dAyl9Cl/rVQBn+AxU4YjrfAWXr4NEdBlkZwYFOc8O7VMDetghvwytdanOX+F2Jdxd0Q0RQ7omc5I68Cos8TtnUh+hkwl3A244qtBX1kRwr71jFln2La7sLM8ZieN2gIEApLQIAQmwM6ZV+82PE7YFSKnA/XXQbemHDlZTdIRmo3G5LzczD8IMQuHilHKUxm7jLCNFDywdx+Ot4YA/IBEynA7P0D9PqVZam6PWjOn8Z59nXIbAHvUSHBAImgP3gIO1nbm4ylDlFUe4z7fZYnHc6io1ZordNSl+JOqFGRBj4qrnDNJxCAC4q2kIRTb0+svJNtaA3/HKVP/wcMqFS/33tt6ufgkvGrXDqa0QH5Av1AV0L07UYQJ5eZy60bOX7E8UnzfFb6eaXIUoo3rw1GgtkZbYR6hYhi0Q0T50T+Xk4dm43ltCxkTCH0Vq102osXbv6Y+Il63ea9EQ0 MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: c01fe081-61fb-47ec-5adf-08d407823590 X-Microsoft-Exchange-Diagnostics: 1;MWHPR03MB2896;2:DFI6QBBi2J5EXRwk+rait+u7z5YoCcDMec/qpquUzdE6mSZniP6bBkqjv11YLDqgWEcekGmxJbOHTu19gzrkj17bjfJZA0r8qjFydNgNhB0wTUYWygis4zCbhd3kVk2j5AstuYbnVamdEEQJM0J0Cw6iJs0lks0MBRTKSA0FaM2CQiGixJ2dfqJt+7of2VCsER3MkZTwxbK8kUpmSiz7cA==;3:bI4D5kqmFfk0evLvPvweubnHjtd8umYXzkqYNngL4+yGoSVDU9XecgFVznYT/w86u+9yKt+eeQ/HJsk9uovULExqRKbIRPY7JaGDk+OzoWWjvDrvS9oyAwJMvklBHvdTvekIpS9vWj6WxP7UEIykyyCRPdyQJP2Cb2suCc0em4HIWPb4kAS0zz+bXp14jA05YNit6ztgy0arX/eE0REv/BZJfsMPk2W3B5iCPV5ftJbyD/pWEpEXmb61pwcmc2Jt X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:MWHPR03MB2896; X-Microsoft-Exchange-Diagnostics: 1;MWHPR03MB2896;25:jPuxK/E9kmnWSIOewKp+nXczNuyrGypch9G3BDJQBjdxBRrCZYxUcCcvPGRa/6mQXCNlG0uygiyBSq3FWL82h+LHAfh2EsEqAxKRfCW+ted38yOCWHUQpErO8MXLt3y8krm9OALf++1dSkGtr+BUAc2CXiicc8Iz9f8yTVhdjMLh9Bf01gbm95irPPN2KjqAz72nvstSSE7BsDzbgQ6rHJMJaL/XrB6Ntm4QQynblLvJmXOeWBcStxPcezMW7StVNqGyfuz3kfcJiSJShU95Gv+3PfFy6ItN3gmfZ1udMCRRRgsySxTKtj0HBPhSDN6iK5MfKawdOsk0E+qNQS9PbleKCxAURMFfnRn6xUfyr8QGGi8rKbgbTS/9U8VAhemoAWIfGnRcoUu9u5yRiVJPN/syIZSgwHQ9HloZX2jkyF8g5Z9N5iJWM3DOYuJm+6TM5ksPhCYkq7wlWw+SbKSSXyfU+fS2ogTeBZ9KGe2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tPua6ut9X2rgVrepVgGr1I8k7Ekec9KYD/K0aycJ/qtTFNBiLXEwPq2mXhfCCdvYqiZwoZpyXg6UQFW3YZf6ezK2cI0lVPRLwwEjJc9NAcaYYyWUVgP3xUXogqngqksthY/X2vFt6wYK 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)(13024025)(13017025)(5005006)(8121501046)(13018025)(13015025)(13023025)(3002001)(10201501046)(6055026);SRVR:MWHPR03MB2896;BCL:0;PCL:0;RULEID:(400006);SRVR:MWHPR03MB2896; X-Forefront-PRVS: 01208B1E18 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;MWHPR03MB2896;23:f1f9eGS9j6hc4ljN+w4ePB5WAima8TCUwd/IsENtF?= =?us-ascii?Q?Wl8E3XInKaniokKtOSlpNNaEg4X3IHWS2a14GJ+jfiZvr1XgH1lSondaLA/+?= =?us-ascii?Q?pxAiuPN8VKRKLlwkfVj+VIxovuqR6NUsOlr+8KWgCRN9aX2C44FHN5vzEWPQ?= =?us-ascii?Q?Ri1T58asSIHDDMQTBbG57l81BoQfAoVF4QQLlpJVfy6WLC5V9/AivzHAntF+?= =?us-ascii?Q?VC6Vk+RcgQFxOAppnDkMvEfSrogmR9lUWBVpcsDTvZBiVpk6hnw7idjbFPGa?= =?us-ascii?Q?VmMtc5i7tYuLYv4TOqbo9xvugJu+snXtRvqu+bxDHU1rtx+7hxGtVGRKvEvz?= =?us-ascii?Q?2MQtuRnfo1NjbBFB4z4dnomXcNpwU7GzMPX5mJdjjnvsb5FL40JOm9CzO1yC?= =?us-ascii?Q?aGCpfrl3a954xxF4wYWgAud7RtkVoxWr8Z676N8Cm4mjtuJxXxYNVjy5L0UE?= =?us-ascii?Q?GkjC/KtTxPtX2albOHjY9FA0lKh5jUas8xKrqhD7FF8eVxAmuSwB8/9h2f6f?= =?us-ascii?Q?cnk+T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uANukZLNKNRfgoikf4QK8Vvk3nyrUxGoYD4vg6bDJA7LdONd8xOcA5bSeHVFBFdcRZxlNtV+9Y3Tj8T6UiHt7IiAlE4TjelsVyeZPNdgyRZb5qgtqtTreRP1A;5:jOQxodr9TAkESfi8N7u253JYX+pnh1RMvGhSNE9sUZWEc3wbUmUkbGk2N7srI8MpO/Z7BJZNkwQmzRI4co41tFbfB9K7xLm5oXwHE9JrX0+uL4McwId5i99HwJuyhPiHj+Zh/HDTXQyMU1PecO5+jwrHYmSWn1wpHGJcy51Lsj4IgydY5awQvxfpHuzgtxy1;24:jvQrwGrI8SXYKDbo8wUNNtvqiOTKwFDpn8GyL5OKrkoEhwYrCrlt+o3h9/HR3/8sfh/NxwFrCecVHcIMJ+92hYl2ajLhM98JZGAPQM8/9JI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;MWHPR03MB2896;7:fAlwH4KST1w1Yk54c6nDIdXOE/qNCdECQpI6vBpoHpJGbJ3iPfszDVsvb6Zi1JBy4O0VAG3Wr6vXI00PPQS8tx2DRz+cz/4p73fRBsGwBnUqj9sMgjj26Na7EI+AbE5h3k0Zut2m/OxVzv3Agxhmcc68L5CLakwIc+aKhGM9FxKV3J8YcioT9p17bSlKTMCUe9wEK5w7/MO0nvUJzmKJDfmTf6ZFTPWJi15pfLAtPQXDA/i+F9yopCffqm2NhcZOVZVOy5/6WBhhBg7nQx+OUL4mn3ynS6D7n37kmMExwghUUdErAOjpVngELuSl4EuvsvGj8TbUAeV7LHmRqzlVyzivFWbNx8cR3Bt4WQCaBvY= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2016 02:51:51.4346 (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: MWHPR03MB2896 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3632 Lines: 123 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 Tested-by: Maciej S. Szmigiero Reviewed-by: Vaibhav Hiremath --- 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 cbb1467..acbbf0a 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 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id) 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 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id) 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 */ }; /** -- 2.7.4