From patchwork Mon Aug 8 08:52:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 9267153 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 8BA216075A for ; Mon, 8 Aug 2016 09:05:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B35E24B5B for ; Mon, 8 Aug 2016 09:05:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F05126E8A; Mon, 8 Aug 2016 09:05:10 +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 E221724B5B for ; Mon, 8 Aug 2016 09:05:09 +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 1bWgT8-00074T-BI; Mon, 08 Aug 2016 09:03:34 +0000 Received: from mail-by2nam03on0067.outbound.protection.outlook.com ([104.47.42.67] helo=NAM03-BY2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bWgRs-0006DP-U1 for linux-arm-kernel@lists.infradead.org; Mon, 08 Aug 2016 09:02:20 +0000 Received: from BN6PR03CA0025.namprd03.prod.outlook.com (10.175.124.11) by CY1PR0301MB0697.namprd03.prod.outlook.com (10.160.159.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.549.15; Mon, 8 Aug 2016 09:01:55 +0000 Received: from BL2FFO11FD033.protection.gbl (2a01:111:f400:7c09::166) by BN6PR03CA0025.outlook.office365.com (2603:10b6:404:10c::11) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.549.15 via Frontend Transport; Mon, 8 Aug 2016 09:01:54 +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 BL2FFO11FD033.mail.protection.outlook.com (10.173.161.129) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.557.8 via Frontend Transport; Mon, 8 Aug 2016 09:01:55 +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 u7891D1t013331; Mon, 8 Aug 2016 02:01:47 -0700 From: Peter Chen To: , , , , , , , , Subject: [PATCH v5 4/6] usb: core: add power sequence handling for USB devices Date: Mon, 8 Aug 2016 16:52:09 +0800 Message-ID: <1470646331-23227-5-git-send-email-peter.chen@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470646331-23227-1-git-send-email-peter.chen@nxp.com> References: <1470646331-23227-1-git-send-email-peter.chen@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131151205153906669; (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)(85426001)(50466002)(97736004)(19580405001)(19580395003)(105606002)(33646002)(5003940100001)(48376002)(86362001)(92566002)(7846002)(4326007)(77096005)(68736007)(5001770100001)(356003)(7416002)(15975445007)(47776003)(8666005)(87936001)(2171001)(305945005)(2950100001)(586003)(81156014)(2906002)(50226002)(8936002)(8676002)(76176999)(81166006)(189998001)(106466001)(229853001)(50986999)(104016004)(36756003)(2201001)(7059030)(2004002)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR0301MB0697; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD033; 1:/GzRGTA7WhTIOTm6hFqREIglAUpyqhakn/onr0eQXCJIbiBkx6mGGCkCx7KLu7qWevh5X7i3JCmVuta2K8r1442mhNJV0ywAAvNDmMXLcOZCvo9mTD/Js4kG30T+Pix2nTrVFNRgmMT7PZqTvUQV5hRxiOXOnxw+dwAgx6mHUxDX9h1hZFmSC/PD1Hy2B5fCUgAdV6tFOm83rK4ksZP41V5OdosJ48G0O1ets+bWkyYyazzQezKdcuScb4tOOd7qHjGadCPv3ZNDHWYhrY8yDisIDis6BKbeQiCKnKrKqcMxoRUdLpEKcA+NmNo6LlfLPGDqm8WfEnOUDtleNFt/X2YpRyPw1jcC6imwSaFnAAEiIy2ieqQAO6cajcdJN2jf8F5Ui+S3q8aO5dB8Ubz9smuNe+i3jOTIOvHgvUhxHccHTTq/xm1QzvJGLi/KLATGzlqshirTzO5bfKjhyAU5aEqD1v/WNN/xw2CHBMlqG2ffgB3OFqrJT1UJ7L+IZaUJrdd/yvPuZo3wgn1Id0R8Ph+xNx7FDO3YNB2yDihPOZJj6G3Ub7RMqcB3Fc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BFS33MRGmiVblqySesvfngJXsuGsCZU5aFJIjSyfxKGuGShdWIWsSw0+5/uOy/ln5TRZtf4AgT/wrDM06VRu3d1LdU= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB0697; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB0697; 31:aod4HrDcyu5cjXt9SzinnYW6OSuO3HndY2hycsVAb95OKHu1JGoW+TCjLyzA3LfaBeEvHcq8CL41THm5Y94yMaT+V8XMVkNV76I1GQn978X4ksw+0czV10Lv2BR0H7gOTr/RViZWb5qUgEDVH6TMY1F+p8BcRI9sp3eqtPAYw6fBzqOs8B5C03bZMyyOT40QN/dGO4zg9eRZSyz2hyN3cHQ/0ctv/+wA3mPXYHUhyIU=; 4:0QEsv0w46aUOHXCzaXYjGGA6CtsMMdUECpJok9rmloBcngizHnVhPVeYuwdJ/AERBXPltiWKavOdCdXJfz8i7FIyLEaTdaLyXPl9OIS+E17RkA8F3qvDDIxSDvs5P7tWOh61AtPS/D5g48Xj1L9yEnLq6WkTOtbjcBeUQckWd2hd+XH/uIilZlJN+naRpv1nKjZ+xOeq0oHQQHoQsaFJRIcaRkIkDfdaDhODr9XqcgI8Hlca6NIyB4sln31ZOp7u3OuB7ncmL+P2EREwpQ3/6zuSZkDhJWoeZuLRP/4Pz+5dlzdgItu5GdsvXwPgZ/7lIAnMA+QjgQ/ohN8n5NMqSicWJMGIGqL0MUZ5d5tLGb4LWGvooYm4Ta9upgUPkxzixRaT8YHHzSc1Zg+n3rnL1Hm2bMBEggITaouSYEE/HleZVHXPyTgRbc3RZcowZYGP+QQY8hcgPCydLAW6Aie4IGmr+kPErTC6dvcRtv955rAodNh0hF4yJgt2JAqFTWSrQvvPr3LCMD0zZjROTFIc/YSN/JV5fdp2B6LU8uyDYW49js9S9+vac2h5B+2L9rR26ir+VI+NYkLcugenRicvng== 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)(13023025)(13024025)(13015025)(13018025)(13017025)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:CY1PR0301MB0697; BCL:0; PCL:0; RULEID:(400006); SRVR:CY1PR0301MB0697; X-Forefront-PRVS: 00286C0CA6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR0301MB0697; 23:+N3oSRREow6mlG8tWuRoPvc/LG8hIjr2BU5ZiVP?= =?us-ascii?Q?bqoXaj+IPqJnPLdbqodyIT5UX/Pzt06WNG0BSeOh59vnS4kyMBndhSXNnvOr?= =?us-ascii?Q?w1dJQQNwtsY9QQfNYRV6PqIUFg65Pbp2CArpEZpASnrXJhsjoWeeoo63JgwG?= =?us-ascii?Q?yWEWiMdyj7qkpcXhmeYy7ka8NMo6pPPRhJkb4cmK2ZmL7ieNud/dXVZccHe3?= =?us-ascii?Q?MqYAvp+nncwdU/qPhEcqEC03UrC04eCZIOoIynGi0ODK/7vdTkLFvSbyy4Jt?= =?us-ascii?Q?5bWoHuBwJX8E4WQJmW8GQI208Ij+mJuLCEaLJuoxKOz9NwMCfTandDTovGjQ?= =?us-ascii?Q?oEwf+IcvosmZ/PlnlxNi4Ri2a9umJEzmZlu8e43UvKSgo+9083jaoOrCBt6o?= =?us-ascii?Q?n4itmQFIioz6Kj/tbuzyw8snzoWYV51kZiQ9U8jyqUvez6uKgNqDOC092TWN?= =?us-ascii?Q?gDeuOZjwlA9xEIiRJdQ6oAzJE8u22fA0Iv9hDb1JQOXoujnIA/3RdsCB/5/C?= =?us-ascii?Q?Rx8Oz6gNFdLYiFdq2U7UlgnqRoUjFbtph7994spm33dYCICSO2Y9P/X599zM?= =?us-ascii?Q?DeqbRVKk0VW1eaL9nzTrLrETFvSJaYUAjKN0Mitzm+EI7AydZcAY8WrxjprB?= =?us-ascii?Q?uN1GDB/Shv/OoBAjB5HTJBFAjCGp88bZEgfRGJybg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qVaC20mqy28fEFr9j9Cu3f/6j5G90IAsYjyWVTRmhlCCf3snChlHjnJ9LOaZg9YCZcVoxKwKxJkY2IqxG1NiCctvJ6b0//ROFRF3xZK2hsLUa4+OWoLL+uP4XRcMHWO8FY0DwlyaTqpu94=; 24:Zegi2KbvB3EofT4I6Assjz0BTW7h4xMfVHnc1XOC+oymYgNfJTW6sEuynN1bEwlR1nN/QlfNI8bNOTW88iZiO8Y9qj36vdi5S23xgAVyBuY=; 7:bAsHm7/np2epOhxEfLNENN5fbfBbrzKWllQb7M8woYgpkKhd3CkNDi3JmWytsMz9VYrxwIXprgSJin24mYQS5Mu49PxCH0z+gFnnmi8lH47reoyerf8g4UKyvVBcbNoqVTIvqNePvf2n5FTY9FKrR9wD6WRc2KcjPva0z80tKXM/g23/2PnQmBhItMoZHagnhp9Pb9fcefJvI0qjmRjP7SP3WVv0S7VJX9FSiLV4GDqOLlMe9WVndivkPPeRWaGQ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Aug 2016 09:01:55.2034 (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: CY1PR0301MB0697 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160808_020217_152355_501BB0EB X-CRM114-Status: GOOD ( 25.21 ) 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); + } +}