Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752551AbcKNBvs (ORCPT ); Sun, 13 Nov 2016 20:51:48 -0500 Received: from mail-dm3nam03on0071.outbound.protection.outlook.com ([104.47.41.71]:57184 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752411AbcKNBvn (ORCPT ); Sun, 13 Nov 2016 20:51:43 -0500 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:1445;Count:10 From: Peter Chen To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Peter Chen Subject: [PATCH v10 4/8] usb: core: add power sequence handling for USB devices Date: Mon, 14 Nov 2016 09:35:55 +0800 Message-ID: <1479087359-7547-5-git-send-email-peter.chen@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479087359-7547-1-git-send-email-peter.chen@nxp.com> References: <1479087359-7547-1-git-send-email-peter.chen@nxp.com> X-IncomingHeaderCount: 10 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131235609925419583;(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)(336003)(199003)(189002)(50226002)(48376002)(5001770100001)(50466002)(356003)(8936002)(305945005)(97736004)(92566002)(47776003)(104016004)(2906002)(4326007)(189998001)(8666005)(7846002)(8676002)(76176999)(81166006)(50986999)(81156014)(586003)(5003940100001)(85426001)(5660300001)(2171001)(87936001)(2950100002)(626004)(7406005)(7416002)(2201001)(36756003)(68736007)(6666003)(106466001)(86362001)(105606002)(77096005)(33646002)(7059030);DIR:OUT;SFP:1101;SCL:1;SRVR:CY4PR03MB2471;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD047;1:JXJSg+MEpHOfp4+2eYmrlbtG/hu+SjD0nz/wOg6BqoCCJf9OYaFIrl5XA3hO2gCE7xkr0FZ557HaF5yDG/Rt2caeLcsrHtkr5idwRV3yr81uCSlDK15qS15KEFFhIoIqp4tcyp+eSMWV4TSFLBbAzFdwLafDq+FGFwv/kNOE3xvZMWzsAzDMGt0x6EgyYLCivP/4AOXek0DUmeTwofC49CLrGg+rPJMLdVFwXx7edi0zSJ5+bT7tKkpNY7q33gd4atIppdxipFy662sIxN+W8I5XpMJAyBEKm6Fzq7Ofq1pJIrPOEIDGTX/yxrclVAG0JO8G2rZN3t4VXErwG9o9msW8nAjYaALQP4XhfIbnjiC5NQduMDyKwWu6nMTwssUzRlCAobezQlTQZUqSKyYJWpoKU5EnMcxVJ37K7Ow5b2kOattm48pvZnRFXDq1obDVYEEN5n16T16urixJqMCk4ekDO33Qi8o5dfzQ3Zc3irPHMRWLzXiImtG4XbG76iP5GDqyXjBAkFOs47Py3QsGzLvRtHQpiR/EHqxzZ6RyBb7GPkLzY/THtejdySH4Wn4PMuinQczyB1h+6eZzzNR+LYU5Eq1nV9s7Sc51c6O2gPJY1cbfJsaBSz0SoV6WCR0W3009cT0jwUcH/+BzOnJk/Jo/Hyew1v06OvQHaBGdfaRDhCPmDg7S7wHX2Uhu6hl04JDgT1Yo/IMdGWfqYcPHrSVPpzu7cEyhpwWwa9WrhfAG7FoHSRSXTSVm8SOqjLiN MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;CY4PR03MB2471;2:pOqIPATQYuGNB7bYqyINcuPjCyqylwXfbCdqdMIUlBY4YcOv9wvgVffL3fMWAvXkm+7HsVloq786QN8hDjHko6s5E8PI2osZJ7xNqmRDQLJa84ARgZJOxWzZTUc4AN/BlZJ1RNcNE+hy+w29E1wtIkKVjS+VcR35JAk8aVJ2RNE=;3:7epxJATmhbKXdsPAyq3p/mMU7pVK2qTu+kVfHNG7JjTZUkIOrnqxy57Gp3Rk9Y4DiWe0x7f+K2YzICFSmURzkw2366K5a2KnNrhh9Skuh1xza7ZHvYIVFQMh8WGk9/xMc6m1rnkWV7f9KQA3NexbOzGez/xv5rAp3fHXqQTA5wewC5nZmiflvlCgLp45Tnu6EobvGpvWT/W+CPD12PzpVDI292OsgFVkmv7UypfxkIeTt4xTTHtFgobm3qidsqd5z58RjCbwxFJQlzXKyYUAmw==;25:BygkkCuyBPFdVXMq7uqznqZUFhDrAcZZZEVu1irPUBBx+pSVyukAvpEGn7s8Rh1Zdqvc47VBjNdGx/ajP3vLrSIdpJMWHevswxqewWLXt3xdXaZF3KT7yl+RcWK56X2CiGd/2L9nAKtcjdebbsqqtmnzjncAMXZnkXN361qBt1e7XyVm662WnDY6SXxKulz794SpUrkhQXkXBLsSYa1stGh2qB4nSL2dowRo0ZtG+fXg+WXQSX/OKDW1CmG7Tq3TAhixmeIoC+rGPDaHlJgM/nFwg+jPOAnWuZS5EWiZ2FXMu1BkLNqRG16y+hgP4Inurg1sLf0/DVeu9Dxx3F+cQvr6Ul22ep1gxt6ZyQZ1VGUuLMH+pIxItvfy0lBy2dJgAQg7+eNFDl1+zKbgL1qr3QaP+oK/bdMu3fGpaWUyrlEqKbiEuo7x24b9AK1O8nAiZK8M0NtENVlbr4CJzP5m6A== X-MS-Office365-Filtering-Correlation-Id: 1ba405c2-d8a2-46f5-20e0-08d40c2ea9f1 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:CY4PR03MB2471; X-Microsoft-Exchange-Diagnostics: 1;CY4PR03MB2471;31:IY7reCAFdK83rg4UD2Q4nV+2IG4btoruCG7uboUlnnZABOA8Dr6qqR1ofyr0sy0mJ+GpJgrdONywjLAM5hOCZx1ynxCRSvzGjt81Nj2O9247gear8oOSaQNCNP5qBh8PITsEwklMvECelGPJTADoxIyS1bTuuvYt+y0+zmcrwpR1PF6MRjOBR8ydzvRgFH8eLj/xCyt1pEdVU8R3qjZ84D+2pvJW8ZYIxJcRBF7DdSXlHcUmnIw1OHExUaqhIRYk4wkUQ8sZjv5KIzIB8Egi0w==;4:F5eVfFril/E6h5IDGtLAAHcI2kutByRqZUiH3IrZIL7fHAeo6F6g2kFIIeWKQeA77ZV7BjQSo5pMtniVTK2y8uMJQsHuF+ZAoSy8FS2MgQehHa2FQPPtjle+cjdt80+XfOvcMAYrGTX0Ij/NtaVhNggSGH+42cQp4GBM3P23lAs6ivnWK5eIbmOO5dmJFxjr7l23OL4W3N75PHAdJXeEJo7NE2suhfxLebGzfCOsbw7R7pVNpecBTeq5Hmt+l6dAz5FaNulx5aDEqLuAzyFg53b7OfuoZ2c3J8k1tlN9JV5JB8tdurIhB0HlMJze6z8QalXdacOCJKeb8u9hRyxrFF/gsyJfgzFW+VEM2T5tZkdQUyxYZ1DJF1+T7VyQc2uU2e4Kib8Z/2r5rkQssO2MJC5ZrEX0D3vJRjCEAo0ybYBkMRJSYa16NjKRv3O+5nhbHH5FouAEyiANjqpIDRzdcriPVt6pkraDy1ltcd23GnfPpo8bBZPXgeE3rgC76FLi5mxBq6tLHarwH04V1LKsDjJy9COzfOuhCX//gPIeca9zbY44xxe4Sm0LUzIDTQ/X 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)(5005006)(8121501046)(13015025)(13017025)(13023025)(13018025)(10201501046)(3002001)(6055026);SRVR:CY4PR03MB2471;BCL:0;PCL:0;RULEID:(400006);SRVR:CY4PR03MB2471; X-Forefront-PRVS: 0126A32F74 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY4PR03MB2471;23:NAUGOnZxgZQfC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iagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;CY4PR03MB2471;7:wxD7Cvr6psmW5cigdUTDUK49prVV9lfvuQrKM1yVz2eyPc+5uwGsefXhxKZfdK3IfC47B8S5bnvrX69VNtCEg+koYRm7C6+ZeapwH6j5wwqzywYddxS+jFFnSF0JJSK6OxD46hsQ2nPuYsUvM5XCMACrPCK4Kjcph/7bxJ6IwmWgNKbjQOMKlRpKWdgTIH6bjYBnRW8CmrkAi4RfxLSRs1v9dNd8gQziQjSU1prfr4Nnvwe348tngtzIUhnF3251i7syhwBsNCGccc36wzg9BxJOH6eSK3mDBmxidJLVbYox38q8Gh6zp+U5bEwr7ISLASRrlfRTnWXL5RMpY4nMhfXnUutwwoHtD41CArqgbww= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2016 01:36:32.2143 (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: CY4PR03MB2471 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4056 Lines: 136 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/Kconfig | 1 + drivers/usb/core/hub.c | 41 ++++++++++++++++++++++++++++++++++++++--- drivers/usb/core/hub.h | 1 + 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index fbe493d..706f261 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -40,6 +40,7 @@ config USB tristate "Support for Host-side USB" depends on USB_ARCH_HAS_HCD select USB_COMMON + select POWER_SEQUENCE select NLS # for UTF-8 strings ---help--- Universal Serial Bus (USB) is a specification for a serial bus diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 76e80d8..991340f 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -1697,6 +1698,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() */ @@ -1724,12 +1726,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); @@ -1834,6 +1865,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); @@ -1847,11 +1879,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