From patchwork Wed Jul 13 02:06:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 9226723 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 A26AD60868 for ; Wed, 13 Jul 2016 02:17:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FFE526A4D for ; Wed, 13 Jul 2016 02:17:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8435027BFC; Wed, 13 Jul 2016 02:17:09 +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 DBA4626A4D for ; Wed, 13 Jul 2016 02:17:08 +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 1bN9iL-0001Iw-Qt; Wed, 13 Jul 2016 02:15:53 +0000 Received: from mail-sn1nam02on0050.outbound.protection.outlook.com ([104.47.36.50] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bN9hq-00081Z-Tf for linux-arm-kernel@lists.infradead.org; Wed, 13 Jul 2016 02:15:26 +0000 Received: from BLUPR0301CA0025.namprd03.prod.outlook.com (10.162.113.163) by CO2PR03MB2405.namprd03.prod.outlook.com (10.166.93.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.528.16; Wed, 13 Jul 2016 02:15:01 +0000 Received: from BL2FFO11FD011.protection.gbl (2a01:111:f400:7c09::167) by BLUPR0301CA0025.outlook.office365.com (2a01:111:e400:5259::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.539.14 via Frontend Transport; Wed, 13 Jul 2016 02:15:00 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) 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.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BL2FFO11FD011.mail.protection.outlook.com (10.173.161.17) with Microsoft SMTP Server (TLS) id 15.1.534.7 via Frontend Transport; Wed, 13 Jul 2016 02:15:00 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id u6D2EQex028042; Tue, 12 Jul 2016 19:14:54 -0700 From: Peter Chen To: , , , , , , Subject: [PATCH v2 4/6] usb: core: add power sequence handling for USB devices Date: Wed, 13 Jul 2016 10:06:48 +0800 Message-ID: <1468375610-18625-5-git-send-email-peter.chen@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468375610-18625-1-git-send-email-peter.chen@nxp.com> References: <1468375610-18625-1-git-send-email-peter.chen@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131128497008330621; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.158.2; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(8936002)(106466001)(356003)(50466002)(68736007)(229853001)(7846002)(105606002)(50226002)(11100500001)(85426001)(2906002)(5001770100001)(48376002)(305945005)(33646002)(81166006)(87936001)(189998001)(77096005)(2201001)(47776003)(15975445007)(19580405001)(2171001)(104016004)(50986999)(19580395003)(5003940100001)(586003)(6806005)(69596002)(4326007)(86362001)(8676002)(97736004)(8666005)(36756003)(2950100001)(81156014)(76176999)(92566002)(7059030)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:CO2PR03MB2405; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD011; 1:zf+X7Te4SDsxkK8ESeMSP9XYEMoLBHFQF3IxJM2JFE4dtd4P3SEofYkmGg8DfjrUM9B7lX6xSMWzNNvxYGFEquUM7mRdgV+BXsS7krJo+YI3ZO92iQx5qHTF2Ap7fcaZIsWukH4tGwAPjTJxyutrtIdpjkzZ7si7vTs4ZXQ25x8YqtlKbzUjlwYMVp6+UcLYoj81h43LSN+D8GJ7r7lBNgRZkIQEh8kYcwSMezQ0gKdQLsR/YYSMWl9hfN18iagNVLAsRoL6oElAgjpKfgEuKILN1YYt173wMbZneyeONF4VQctgUATOmFn+29/Pccpz56fd27vMU8qqBf4b14KaGJw5FJkwkKBEp+RfJFxADkyZD+cH2w7hMAz3zJJIPHB5h8OueEXp2iSnb1TEtudZbVaEWlcNM/7+xlZS2DBZ9EFNLg5nm3MAo4DDZ2DztPku3sB82K2TsEKbSGYZMI0IXaJaoIAS9UNHRgmEtACBv0C3kwSNSJ7PiApCYJLENEMwnFi7IenFfwrZrM/JTT0N5HEyqc6VD0R7x8XsLwns2r28ZpbKPzo4QCSH6IepbHD1nKqLiOaou0HT2ID34Jfd/Uj62RH+KCbh7wh0XAi7W9T/E0s7jailmZFNcUoMXExb1sKWfc2HTemnNpxQ56avfhVZJcgrYRfH6WyVe/XpDIPzQcv0/FwFMK7lb3a0YXOMX/P7btSs7/aFccQQm0f6L3+mJjwzqOtmkgNTO96C85yipD2CD2mBBaCUjhFDzha1 MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: cea44068-17a6-4f4d-c77d-08d3aac37e93 X-Microsoft-Exchange-Diagnostics: 1; CO2PR03MB2405; 2:3wBa6s2E9y/NVkUR2v6umKY/GxuPKxCycjbUObI6PYdtG9rs/T3+NCT8ZOQhqOyfPL3J4k5CbbnnBJGsj7QiK2SJ7rkvCfAD2kj5gICmQy0Hqa3iTkixgxUBIPOvL/BLV2Ocrk5jA/22xmaXjkRmJhS5vlTFjYd8b11wSyPKpqiNbVhwFngdmZSA73XTGuwU; 3:63Fz1CbbjTOo4U/Ujfv6oczxrh2f8ONrDrbmPNtLe5UobtJHNX7pUDfhrbSf0TWszr0UHUM96UMOCLDojWBK4nusR2+c1itxKy6ujETPjHntOyo1z1+Iqzq8qTJMHIjgewDOY+O5lF4+obdHlyVil1Rw2uLCWrnu2roygKaR2wULOL59t1I83H1QH/w8yF8tCx+kGikQTxa2C4HROuF3TijlW3lakSCw7wInL14VCFU=; 25:Cyan6h7p8E6Ppn7EdsmQvpFNTe/o4BzB5gNz4oCw5jh8/LZ27FLFuPqwvQjzgbFRoa6nhF6xxlIIrnwXy5p1l/jVqNICGVAkWzNTM5PvWKLN/3VxXUOzo7adgbq+WhFA8WiRETgzIPVjZZ4t6yLdFHspUz1CvkxsSlY44+pb8QtZ7gxelLg/q+boUcfmS79NTXG8zGfT2DQ6f7c5Urow4bvVTdIt1TUHVZ+ymfukGt8ckSxhlP7DuCAPaskj4XJpv9FErRME/dkqkXqqHz3ZgJweSZXs7A+evU1o8CXV2HUw5V5XaivXV6bCMbOj/v9TmbbR1nfYyYdQW8qCyylrn2hktnjNaAJtrxuX27rAVNM6G2fglHxJz/9yj+4VjuulXBdgA80v7MvMvedWM6xdKjW6D0pKIo7TlDJq8d6v0I0= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CO2PR03MB2405; X-Microsoft-Exchange-Diagnostics: 1; CO2PR03MB2405; 31:i7wjEyn16+LJ9KOViFvOpJipgK3QvakkGjcbQ1aZl9IKtD0fwzCW2gSDBusSYtYS3iVcTAOLR2IXQU5iZFUcy/O9XfIak8lCJ+HVQ4V13mY0PyEEsH7T32vFlOUiTkaAvCndBxSngdb66gJ2nZ3mS56ZpucG3ec0fjIPfiMPhXTrPkEGgIionN6ytvyF3wMByyH5BXPsQxzOPt+Km+XwHw==; 4:DBh3LV0uEhRZ6rSjDJABfk8UioO3TwbljkNhbn2KlDwrg0X+YIERCYsTea6l4dG/rKnc94PPWf5M1ssCHBLK7Flgy7aD+cTcGvA5aH85czR0WfLiImnBfrffJJ96FQIR2UQiSVYRnqrpYtsD+2r9YP0k8uAWP9m5GCFQgoIJ2hdDfxkogVxPNKRZ9rQe4HxQmmlyiN+Gr2G7Tw8svJUDhtIKSL8gjEt5gPINAyWA2eP2GSQ9GnwNEAPy5qWidsbPrE1ClagkZnVQD4ItuyDjMO0XaNmEFJVs2B/58rHT9mgXReO0phKYjrvM2VSYPmJxKrQrIjet09jYav2YyqYVz0R4CsScs1aN32SfrIWKq++qAQfdmuoiPWtLxhg37rcqGwIHtIBFp0D6OQaUlMOxN7rb87CTK5vUEa5wyp20R2e1wKY6u4WBlf7DWLKoZwtOWRogN/iyauh8N8ojIK2JZAfg4z2YMlDTK8inR88/hLR/EUJv8/VpZ5HMZDXMbZ/yLirE5esllxGO/1HKbFLYrS/8YkLwaQTrUJWujPgtiV/TU7Qpu6a/JWQqhjTz4aovzw3XYuPW+iXX5qdikMVy9g== 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)(13015025)(13024025)(13017025)(13023025)(13018025)(5005006)(8121501046)(10201501046)(3002001)(6055026); SRVR:CO2PR03MB2405; BCL:0; PCL:0; RULEID:(400006); SRVR:CO2PR03MB2405; X-Forefront-PRVS: 000227DA0C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CO2PR03MB2405; 23:zm5S4QYncoZ4jw/brVRp8RJP5Mbxlf+7Lmi5uVM2q?= =?us-ascii?Q?vSAUihknqWaSORff1fn19RG3bYP65sargCO97DMFrFK8po5neFHObCbC35yA?= =?us-ascii?Q?p3REY2dq/IHPE3G6C4vkXoPbgOiX2P1TIsXga3+WB7gGvgZ16X7i8DC60tGa?= =?us-ascii?Q?wWrnG56IG/UXY9ooZPbbd8be6I/ckdKUbhjLQNlssoee5O/kcAX1a7R/Mgjn?= =?us-ascii?Q?/oE/AQ+g81BG5l0EzYz26yNAvAFo+YgVd3OJRkdI7+4d7uC3zOQKHftgcxfC?= =?us-ascii?Q?DySaH7paAKIMZUzk5tAv8F4wHGGirxNYAaqMAR3qNAcQ3sOFVre281i33+SQ?= =?us-ascii?Q?e71aqe3dsGyxN/vTLyz7xLOGlbVOa3sLQnl0Zs6AqCbsE4z54AmBBLin6HNN?= =?us-ascii?Q?Y5Ky3fXl+FYMPRZmOUfJ7FqGvCBX37PxdSFBBRCr6vaOaWbp7EnPSbBIcCR2?= =?us-ascii?Q?/hUrZqlNLdFtObcbVeBC8kNfwAKLFyfpG3M4cipVA7GeQt/NPiFBNXYhhUOX?= =?us-ascii?Q?1QMNgKUDaZCWPK2dEd5gm5rjUs0OFYB9IlmgOLZB2GYm4LGCUQx69xOktYsd?= =?us-ascii?Q?UjlskPDu2/awyYdEEiHs8lDWoYR1asiMpln8049JKqymOM4Eiq5xULp5E/XJ?= =?us-ascii?Q?GKdBkMwlj1YpF1Hz0IQB04692thpf0H6X7TFs6K/fR6G1552dxXjRjfh5Jjk?= =?us-ascii?Q?9pGk9viuAI6JxeheccEjZ/HmV/eOB7ykTzfCWaxxKzrBfK/MkRH1neEavgk2?= =?us-ascii?Q?pbuC/HdUl4l0rFIVH9JrKuo84pDkropLwrMRUoRtUhOm4PGQ5kji91oLPz4H?= =?us-ascii?Q?lS8ASzpDti7WlUivLSTsStULSBs14CAfmMNSdHaaIcurqXILwj4niMNv6JOJ?= =?us-ascii?Q?bbBRehJ/oNBYmOBC0U9Fpsjkr3bPCyXr07H1n68quzI5UUxU0sbSzLBPJPjk?= =?us-ascii?Q?2wtwZPiUFcvTKUaPa6PYEf4B3UcDWTNt9zYYOhioeaHwctBVg+hwiiP4biEt?= =?us-ascii?Q?IujFO8Y2qtglpyrIFcauz75/Z1HAjRmSeAVBtz4qy2Zhegl8lr2wUthfNfHD?= =?us-ascii?Q?fxrTQ7riFxnRCF0LfqeAJiPjWPTOpMi+GDs3D6W6MwDJ1y3AFLPevbIUC4DB?= =?us-ascii?Q?cwxNdwgQUTgbtgbbE4b7iizD7JAMsPcqA9tDdNH89lmHNNPUozMPElbRuP6g?= =?us-ascii?Q?fCn/rLsdFDqX0iYxPeHBUQToFc4Kjb7Kby5mk/p3V6Rgfv3sisM275kJYyTa?= =?us-ascii?Q?t0eUMcX9JMTennYHVY=3D?= X-Microsoft-Exchange-Diagnostics: 1; CO2PR03MB2405; 6:ML7N1iwAxTCmK5ztvu5jicEJmKh97G2CKsgL2TVAMHe+KaIgNCZmisbPV7bTUFS0Qlmn0iBo+x4fqwTkpa4SxKAn5BAZnC7ElZ39wov9HfXuQWoS+ABf4mNwRA3P8xrtDsflp3aDKhzd0dq5zJBWbsX372va5iBi8fcoYs+B2vJTZp5IUMV21QS7ax/nb5sbUCjoaMn1QakhQQU8hMWbcYs3yaoR+77jHI1lbjWfLQV1Xb5hnkHvos4wAlTLVf5s4zW5p5s9iQAjdmswdBO3a7O3C8FTQIQWs0XGksW3w/0=; 5:kYcanUInu01oyVP3EmOwJLcGT76PJDlqS0+T8+Qgpphe5zrCKyjK8XmHH51tsQCjXdnRiio+UtE2sWMThK5NW1Ha16KejRyWNDeCQcQltkYtTDXdMgmBI/XavooBed1oIg1wHjl9aq86lEDD2HdM9uUgJ//35xeq/PqxzicBvYs=; 24:lZWiGaVVHTRL3HQBSMLvfNv/v6VyaEc5ViP28AWuaBXbsrna/ixMb9PofwAXNclg+SNuU1fdhX9jw8XZuR6K9ngv7j5apeyVwv05KvWNtCs=; 7:4jGJZz4qtuCbTWqdOei5+ErsqaWn7zbouDr9YFIWQ2/Z8c9U9U2dPOUwsDLHsNMiVWkFak2TNB43YVpyACZdS4Xd/zURVe8c4HeSCqDu6+fXG6YFKhsC4ec0a5dVxrov6lq4Gw9UfxY5d9GNt+uxFIcv0RE29z9toEpohmEst4AQnSPQRtn2mvxIEyQNJ6zav207tLn6c4OH9sVIPse4C27AFZua3/6RZq7tDgEQs2wT9uVRpLsrSue1upHVND37 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2016 02:15:00.4742 (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.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO2PR03MB2405 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160712_191523_304659_2821EEC6 X-CRM114-Status: GOOD ( 22.78 ) 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, 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, 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) if this device is described at dts and there is a property "power-sequence" for it. At hub_disconnect, it will do power off sequence which is at powered on list. Signed-off-by: Peter Chen --- drivers/usb/core/Makefile | 1 + drivers/usb/core/hub.c | 12 ++++-- drivers/usb/core/hub.h | 12 ++++++ drivers/usb/core/pwrseq.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 124 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..df171ed --- /dev/null +++ b/drivers/usb/core/pwrseq.c @@ -0,0 +1,102 @@ +/* + * 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) { + if (is_pwrseq_supported(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); + } +}