Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756954AbcJNDQQ (ORCPT ); Thu, 13 Oct 2016 23:16:16 -0400 Received: from mail-bl2nam02on0086.outbound.protection.outlook.com ([104.47.38.86]:43637 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755651AbcJNDP6 (ORCPT ); Thu, 13 Oct 2016 23:15:58 -0400 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; From: Peter Chen To: , , , , , , , CC: , , , , , , , , , , , , , , , , , , , Peter Chen Subject: [PATCH v8 4/8] usb: core: add power sequence handling for USB devices Date: Fri, 14 Oct 2016 10:59:51 +0800 Message-ID: <1476413995-20361-5-git-send-email-peter.chen@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476413995-20361-1-git-send-email-peter.chen@nxp.com> References: <1476413995-20361-1-git-send-email-peter.chen@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131208876487839585;(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)(8676002)(305945005)(77096005)(50226002)(4326007)(33646002)(5660300001)(81166006)(85426001)(2171001)(81156014)(87936001)(48376002)(19580405001)(19580395003)(586003)(189998001)(50466002)(68736007)(2906002)(86362001)(575784001)(2201001)(8936002)(229853001)(7416002)(106466001)(97736004)(104016004)(47776003)(8666005)(5003940100001)(11100500001)(356003)(626004)(7846002)(6666003)(50986999)(92566002)(105606002)(5001770100001)(36756003)(76176999)(2950100002)(7059030);DIR:OUT;SFP:1101;SCL:1;SRVR:BY1PR03MB1419;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD015;1:X5TuAVfNMwd6LBJersyoT6odiet0A8Nzu8spSHAOK6HJELsFRQudggqiouxXsx+urVHhIoky5MTlzhUtBt2MBH/CbTklFt/gC1VMVc4QDzKD2Zu02+qqlHHBprmhhJD1F42MrargqFo93y/ni9eOqAzWipR1UlCtrg+ukd9el9kRVy7xQEp2i3ppPAdUelg97KaQWwe077CY5DjZI87bZShoIBcNSMWGD2J43AaYMkFTQkO5IB2XOO/pQF3jySp4NWpDlcj5n644b0FtwAqBV5IpuX0mxRClKh8SNnjFWztnofNclJtFrjsYWwt8wm84uunROUsKzfy/+w84QpbzjL+r3ndPd8uulbuhxo3DJRaT0/+f2zSVlnyjw2851/bNoGl16uc4wwoKoH7p1beCzJu6kQC9CTfw5qKxaKe2ppyYTp0c4Hu0xGWaBXkM54sxPQaWGbOkRmjFl8HW8CK4uucWiUUo+dFeEBBijQUsvIUFkbP7/PLjngSDVjYAByUOpoY3OTb+7IncOGZcky0oLTHb73C5i/fiUxzLuzRHcyMZ3UoMwDog3fGTKKTUmsbBT2ZUboLjAGhm3onNWIlHqn7VEXZHWa4bdd7s3Ej5p6565PDNeVsLq+FcotosyfqQcyHkYU2ZyZ6y8QxEGy1gMaQACPa8QuuXYJ5S8EiOSr7ptuetxF2/6ZwO5evzRVcu05KdAvFv8NLOaoTDWEHsxHYHHPx7+u1Vly5i5Ej8VSKY9Mh+t+NKazRRn+6eomAf MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 8e56a5db-f68c-4eb6-2e00-08d3f3de4ce4 X-Microsoft-Exchange-Diagnostics: 1;BY1PR03MB1419;2:u6Q+yQbDwph4LL8vyfFJgwixRSJ18rZMUD0aRNzF4XErZCIO6+46F6dXlSFdWZwYHe39MIlwmiJCPH/C9TglZ0u2j2khn8rNGSZ/FRL+XT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+NB0FNxMfoIsyUHYkbNCDVTiPnAS6uLweoy1t7mRrKw9tSheIilpopMGbvDr58YaSQ3ASH9ZjSbkD7NW1P68NFmXvtYvYaz4dgqbnMbgOjv6yxC414WeKRQXwYjBA==;4:VBZGyudQks/HVjktsTqZ5gM6VA9oiNKGd6GTuYXpaSC6+u25KtoI9aJHwcVa1vAWAAEHCn311XfAX7rqOGLAqSpUPRgMV5cFqxpknOVrEhmJgrGG7SWsAqTGubrglvgr2lnNmUCDlko55Z3Y2nB4NQmSyiYZJBqY8HbpJ9p+XBqVCgH2T0/almVMoT6uDb6egtC7OxeCyawVC3VXyuMMk4bB7LyLlDYU4uAhQxtfuG9fn86Xo+rVN3TUwZfcoCIZEUc18EMZewoQ4GXnHe39eGQsbS4x5M8bJrdiBbyLEC6t7ALzcFZV7Fh2j+Oc4TkFWoz9D1sGgWgPpMg3EklL0g72m3WZx3sflnBa9nY39fsbqSzzA3rEnr7Q3V3Q1WfWWXybd7FJoLSW/d9rrMDHnvSOT3Pqb7QRYfNSA5gAP9WTBSOCVQE7XhtVN2xArvDTj6c3a6fcVa4md0BcOE2JCTyAxhXaKT01MlksgNYGRD/vzdeUmWNXqwPYjfWdHUzIURA2S0uX9cZkVJLt4fXyq0utTtN551pkmtNNBgaynrgc/UJQsP7Wj0xeuCf4h+Ps 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)(13023025)(13024025)(5005006)(13015025)(8121501046)(13018025)(13017025)(10201501046)(3002001)(6055026);SRVR:BY1PR03MB1419;BCL:0;PCL:0;RULEID:(400006);SRVR:BY1PR03MB1419; X-Forefront-PRVS: 0095BCF226 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY1PR03MB1419;23:yxkHzDbBqAWLxfPXgcTzS4BZMkZxTZCOJGaPzfUIX?= =?us-ascii?Q?bC3KyjqZbpW9mV1YVc9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9W3w/fBEofyGfBW8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BY1PR03MB1419;7:aW0up/EjWARWDW6eMz0z3J6iNqb+FGj4r5La9y5rvt6SyEvc+07BapKoAzbOSsRfCpxn/JGpEck5IxMO32puHVj3ijhue6hhHWimJTmsfCiSixo9sOSZrREbxUVm9nqizsmHLJlxIacH9uuReq8yCSdRdmHN75isbJxkEXC/jmnqVZ++DD9zv+ZsCxWhaw81OwB+VTVLvTyIeo1fFYBw/i5SRXGZPgKpYjC5rWmbiBQp/yCqQU9gjzaQHezgozEEpwcUHlj3rk+wKNl/+qAF2U95dI6byv0tJYfs0oAfEkUcI8EM6j2Ly3CAo7V8mrTADSIGs/wRLaQJ9ygByi4IAQDCLlpoDmPzudW8q0w9fIg= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Oct 2016 03:00:48.5187 (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: BY1PR03MB1419 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3389 Lines: 121 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 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 @@ 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 */ }; /** -- 2.7.4