From patchwork Wed Jul 13 02:06:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 9226717 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 4A72360868 for ; Wed, 13 Jul 2016 02:16:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 388EF26A4D for ; Wed, 13 Jul 2016 02:16:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CB1927BFC; Wed, 13 Jul 2016 02:16:51 +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 76D6926A4D for ; Wed, 13 Jul 2016 02:16:50 +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 1bN9ht-0000vZ-17; Wed, 13 Jul 2016 02:15:25 +0000 Received: from mail-by2nam01on0058.outbound.protection.outlook.com ([104.47.34.58] helo=NAM01-BY2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bN9hZ-0007ul-Ep for linux-arm-kernel@lists.infradead.org; Wed, 13 Jul 2016 02:15:09 +0000 Received: from BLUPR0301CA0034.namprd03.prod.outlook.com (10.162.113.172) by MWHPR03MB2510.namprd03.prod.outlook.com (10.169.201.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.523.12; Wed, 13 Jul 2016 02:14:48 +0000 Received: from BY2FFO11FD048.protection.gbl (2a01:111:f400:7c0c::112) by BLUPR0301CA0034.outlook.office365.com (2a01:111:e400:5259::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.528.16 via Frontend Transport; Wed, 13 Jul 2016 02:14:47 +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 BY2FFO11FD048.mail.protection.outlook.com (10.1.15.176) with Microsoft SMTP Server (TLS) id 15.1.523.9 via Frontend Transport; Wed, 13 Jul 2016 02:14:47 +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 u6D2EQev028042; Tue, 12 Jul 2016 19:14:41 -0700 From: Peter Chen To: , , , , , , Subject: [PATCH v2 2/6] power: add power sequence library Date: Wed, 13 Jul 2016 10:06:46 +0800 Message-ID: <1468375610-18625-3-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: 131128496877325052; (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)(1110001)(1109001)(339900001)(189002)(199003)(36756003)(15975445007)(8666005)(6806005)(8936002)(104016004)(33646002)(189998001)(68736007)(586003)(97736004)(92566002)(50986999)(11100500001)(86362001)(356003)(7846002)(5001770100001)(77096005)(50226002)(19580395003)(81166006)(81156014)(47776003)(2906002)(5003940100001)(105606002)(4326007)(50466002)(8676002)(305945005)(69596002)(106466001)(19580405001)(85426001)(48376002)(2950100001)(2171001)(87936001)(2201001)(229853001)(76176999)(7059030)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR03MB2510; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD048; 1:NFciafeXxSwQD3MjQdJ57RS+tNpxOLQgwYiHtaX90pQesLMRmEEwIedUofTSX0VTmN/RyL+cc80ZbPBsGeQK/iqkQJahZxRVWLYm8pE5Q5ehZTS6gpe7+Ye2wIQ8fw3rLlXsi6AC3TmT4oI3E72XADG9hx42Op0IvYK7QKqwFr7Zek/BqFATp5m4DKbEejkgO062MYdlphywzyrpBKlA87GQtN8nnj2g7ntl53t/41OFz7YnttQdEgN+dpNm6bCvZn96LuJyO2R70LqkQ43qwaKf1sVS0AzBKt4o/XKEz9eA/Iko7SWNksskqIjerNtE/s76A6R5Rw9e7DnMk1cTsBV14uPcq+gwfGwyI/Nc9gpglAcQeDO0FRtkPxlfJXlpyfwYZoiqCwQRDE8cLI7vtrD4nDqzToa1B3bM+fsBCeH2ME1WV8Y9/tMrgYxFzIS/FP/SDdFsB8UMJVIrKhko9DvROb8HRzm41nKoJHwdwBXKj2NZvqVAHDJ1BH3Rt09YIHwkExqOQWuliB58ti+gqDaF9ULZXIKmBwLlJp3v3jItSEdw8volSPqJvHVhIaIGehMRi5SaFn/QT1gDuF3CfB7rDlC3iAxLwaLTzNj0AkdZ1cPcgfqBuTAYoFn0IVBxfw4USEc02yY/ELphnuNzNvoeTx6UOjnw1a1mX027LBhS5dHijCg6dRhdKz9DZ+GbwyEbMTVQdTpYgFFM76nKTlf/h+lTANffFwWxS5IZa7vppu1CCl7+4yMpmQNJEGo9 MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 2745ffc6-17d9-465a-699f-08d3aac376c2 X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2510; 2:tMGuq+I4hon8VgyiIqjovNnE5M7+OjJEvqQlQr+ErXEdiEjToHqHTJf4Qk6nVlxeyFLmQDjbsX3PqP12h8SZtB0Cps1cndkWCyf+Mtcv5hC0tEd+jKoZubi1geLtbdulx3A1fgOECwodNu6wIFTql0Rb9ttUsmJFPBE5SLsn8c+uUEHoNZs8VetzLS4oQHR7; 3:DrN60vq1S3bEhzTb8vY93Go+6Q1szoCliuW5j+7OLljB1rBpvCcXXv40aCoCJ/CH0GKW0EY1ZUIIia5qsVxYW5eIbDxmPwqmTooTO4K0C6Zz8w67J1uC24d+Hwa4lQWuakHchYXjF0/bJpWw8tDgtwfkrKfjlYaOAIRVhI3OjeyyzCAjGmQfq72ynCUBpuaVM+5GHT9Idt9wvAXEINOD2pukJvS0pH7M2PlEcMb7mzg= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:MWHPR03MB2510; X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2510; 25:ySW+wEIwLJ6hOy1HTXaHSRnVviPZ7+LYujse3bGbRpJQIkl2qa6S0ou7Ghj+HJRaneSHuJkGlpMTfZXviDjdGLWtICWwpOJ+94yuFoLlyL1hb9DUB2hgN4JnR7xU75+Qi+gWtmQJ/OcOG6a0J01O3qgNiKUc81Phiv1lkqElJGVb5Jsztns7SgiO4ixiyVKLRb5+WHG2hv56tR1G60u3uUwQJO9SGioVQbUnxNeQmSZe9mEvtunfwe3pxgfdWLNVdw8117cdHMR7lCB+rGKW6FDqruIsLNiNlu70mbnY0D7ni6kVSquQEX5td1t3RVCqPmCNp/UsStKv8rZrY3HXHDoT8NgYZVk2pmtin4ceuo5gWuWsf6UBixdnD++5z+qFialQpFXqKDqjtNij+YuMESuw6Kweb0N3Yd6gHXUbqEpVDAgECXQFbEfl04EMFjVBiuGEfoYczlPof8JKGziOP3IHWWIG8rYS0OxFC+Vs+Z/plc8LQ1vp3w6g29hRf2wko00z36vWZ/telhZgHGwjTZiJWirviyG18VQg2zMe/cniS0exwzZYdKKC1Hw5e2cxmqWrnTLpjRQaXU6Kn6pilGuwQ0g9rj82GyMBojRwzrN6L+TsDH3sZ+bq3agus1rUOC5VjouU+EhqoPqsSc4yqzQCoGmGW+3SQAVqJYFAAJBJeSa5oSF746xhEL7TdvvQuO3qM9kiQUHM/vnEKFbhGcdxKVqtImzCKg0O44EQygMQYZr6KOPAOhVy+0yc8zEFvjlgNPh8OtB4HEapfhUvE38vJ1COYoF5jyGwocvLmGtFuoKMgwTc6rUVRN+aXzPH 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)(13017025)(5005006)(8121501046)(13023025)(13018025)(13015025)(13024025)(10201501046)(3002001)(6055026); SRVR:MWHPR03MB2510; BCL:0; PCL:0; RULEID:(400006); SRVR:MWHPR03MB2510; X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2510; 4:o6PHDIwJPuHlX+ZMMvg5XHLM7JfzjbqTl13+N00/IFmNsPvARbaeCOq/1hjngnM2psTNJHb+/6ScSsHdvr3JI3EcBzMjStjc24jB1MlFg7BVGvKP3O+Fnr8LHDh5soPLFu1+U7W3oexc/kgm+5vAey6KzFquV0hUxtTn93vbG77WdjgPx0GxYovHKja+4qnNKrurrKNTICFmEm6elRvMyQ/QsA3bnasI7vj6itk2QsHm4ls/+Ou0qLutX4WRFloK1iqtKtRYCRyACHJ3AmpODbeign4JMxnEObUVrdccrC3AoF8GSH+lHqbdf8AHdZDG5P27ybYEYGP1D7hvtQKfPL/fecFMeLTGk3EypdKTwakiPqowVm5JMdYOc+/zfxEtdDCpIykAJHAcKBD2BWVqE3SFdseci/OOdX5jXF5NZi4yri/zFouux0Ch3VYrfgLyZOISA8eTXnPqmWLuuYFZl7MHsgbqF1SU3ix0/p9oweFMO79uNtP9tQfBA5wYy/U5wg4bAXHPfAdbz+u3BONCCdEzq8GOYbasZ2mwnClWiFLMdjvSkAHLZNjDoezy4p9OEDfaMNG2ycOb//b3nBdvTQ== X-Forefront-PRVS: 000227DA0C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR03MB2510; 23:iLRxHfMOSlLOxOh/MJnG0pkINKjJ+FfUeC2bqL1Zj?= =?us-ascii?Q?7NQJOnPKXfWWryAZPYSxTfI6WSaXil299kDgXYEW/AZnN5srRHIOYxewkfI4?= =?us-ascii?Q?O/+EP8DLhgdeg+JFIZi9hCrpxEBWLhtWghb+IJVB1+LhEKh4YCs9l7YatNDN?= =?us-ascii?Q?FoNAd3zVQlxRtivIjW7BdGPPOD2dlaEP82whaRc4+Um1XnUI3Rsyfo1myS0Y?= =?us-ascii?Q?lY22TJPcAbV5ToCZVSzF9bCUCERWThiMBVA/25JtXmMzUxfLZ3fAyY/gLtNy?= =?us-ascii?Q?zyGjyovY9G8SRP5oZ3ZETE0vVOTG4dIXAKmA6AXxMfJ9zD5e/tVh+2AinTih?= =?us-ascii?Q?upii7xMRwOjr4ClI5nAO337WYY/uE4oNZqDGhH4EVnu73ploRwo/lK+Zm8aW?= =?us-ascii?Q?EvdzrI3nO3QQM+aJ2KxtzzmFkP4/7GazCZSLh41YHtvYJARzWe1ZimzRDQ13?= =?us-ascii?Q?Ysx3904r/QBmIfDn6IEKiiNepaO6fna+MTw65TOdhj9ALDYpT+G9A+wOtsOw?= =?us-ascii?Q?gBe2PUc0q0NsadVr1j1Mu+miOeRb4KOOsBt64LpnhJ3SDBAQ1/Y6ZyZl559F?= =?us-ascii?Q?HHMCM6ScQjjrIw78T1WQ3FlJjVjqjVTYjQH0+KlctWiUf+BLSeZjF3jpFNer?= =?us-ascii?Q?NnQvqSfDcnSfy0MgAotO0iHfxFiGXMbEUKCwOmLdF45sVd8xFuwVdYgU62bP?= =?us-ascii?Q?eoA/cZFJbSA+xuNcazEx/2KVhBF4LFyPi93vjGth7e9o4ZmVf+Gp+hm2/4/q?= =?us-ascii?Q?d6Wcr3I/eu8jKofOrWtvZFwyUGQEw/2hEVUgjQGBYc8Mis4u5VAKONC8+mr3?= =?us-ascii?Q?LRiieTytRU/Ns405uroP3FtPBwT7+og7q8/2vDvkYDvh1awzAaD7VF3jYAHj?= =?us-ascii?Q?zkmcT1hQuPpxnmOoWWxhnS/J/J1dFp8nCF71sKxg7khWj22iQLx1eruniKn7?= =?us-ascii?Q?rgzWsdIYo2ZlNrSnBSREmxt5txU9Dha0ZNcb/XZWymqhZEUwKGfhGyboYWLl?= =?us-ascii?Q?15powHylwhS542BlyVItNw9hyIcRfZbWVOFfotgDG7y6gjkK7+QJFR0yzuDV?= =?us-ascii?Q?jeEAe2W+kkWy9ej2zKWIZJoDdxnhR5PGsfJVYlCBGdzojK/Ad74m0qsxdnqc?= =?us-ascii?Q?iRNZSiqkijAKBswmQf+wAevv1Vkr2h0zLanN0cLwJUXOJU4tZtlkAV9iKNwG?= =?us-ascii?Q?jh2OuVD6INRg2dEvqRT9WNfUoH2bKqLVBISAC7L7XXt5hK6W34dJHt00gIdY?= =?us-ascii?Q?ivEja6Hs2P0WozzctI=3D?= X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2510; 6:fA3hF1zg+IXiW4m/5g8WiMiQAI9eBbaKfaipsq01p4eg49mUaaXmpGqWr8mDtLfWHjtZGdCDK5l0Mh3I0B5bZ+akiGUriyqes3Rc2z+ugjayebGtIRcaHUuQwiVAShekn61UOEV2Z6hFZoa2UpnZx+NplBKGLgfOEaXTtj3KDifJnbfeGKDU/osMqvIMoGsXz3Rs/UyOhZFj/dZB0Qp2GX+uZkHgB95Gxu4tnrkmjlj6FWF0ox6PAboY16KVbFE2uz2+/CeKElYVyDiBkoGv0T/edWhcMnqsEoW3AL6E3Og=; 5:WRYIXHk9jW0NCOncxFZCPeYQe7atbXp76fmNLKFgmw9t+mV7r15EgYLtvIBCe9yLXamK6Snz5WZUg2RN+b0XUWDGGP3OAlQGRbPTZFDKX0eCMKnEl9CpC2WdggQ8W+fuOELsuX5GNKxtH3tdJQ0BqvcSDVRj37Vm3jXCg2V67YY=; 24:NoCCjfOZtl0rzzvN41N1HaPQ6APYAyP3wLLmWGY677ZrMC03/L6hHvf2RvaREATrXJcX9Wuba1KLTAwcReYCl9Iu3WvTnIen3zuf+ZXGx14=; 7:+i2Y8QLoMrYDvTgxzghSljpWlPoF4vuszG965VTy8AeKnf3oTvjQiJ4I5J9YawZ3QIIPkcrPc/NsMfui94ztRFbZ+0KbaLFJtnEyybrcfJ3QYMS01im/Uds4tbbau/0TyI6aXJxQ1pB1hi9cUTc3pxnHyxba46vxut8rBrm1deibW4tzeTblEoRlKsavLWbNJH9fB24xc7dmgNO2EvWD7rLy4yMY1AW6abkD/9a2iWwcJWcSTcsUwX9Zu/LCvIbC SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2016 02:14:47.5453 (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: MWHPR03MB2510 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160712_191505_689278_77FAB95A X-CRM114-Status: GOOD ( 17.63 ) 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 We have an well-known problem that the device needs to do some power sequence before it can be recognized by related host, the typical example like hard-wired mmc devices and usb devices. This power sequence is hard to be described at device tree and handled by related host driver, so we have created a common power sequence library to cover this requirement. The core code has supplied some common helpers for host driver, and individual power sequence libraries handle kinds of power sequence for devices. pwrseq_generic is intended for general purpose of power sequence, which handles gpios and clocks currently, and can cover regulator and pinctrl in future. The host driver calls pwrseq_alloc_generic to create an generic pwrseq instance. Signed-off-by: Peter Chen --- drivers/power/Kconfig | 1 + drivers/power/Makefile | 1 + drivers/power/pwrseq/Kconfig | 20 +++++ drivers/power/pwrseq/Makefile | 2 + drivers/power/pwrseq/core.c | 79 ++++++++++++++++++++ drivers/power/pwrseq/pwrseq_generic.c | 134 ++++++++++++++++++++++++++++++++++ include/linux/power/pwrseq.h | 55 ++++++++++++++ 7 files changed, 292 insertions(+) create mode 100644 drivers/power/pwrseq/Kconfig create mode 100644 drivers/power/pwrseq/Makefile create mode 100644 drivers/power/pwrseq/core.c create mode 100644 drivers/power/pwrseq/pwrseq_generic.c create mode 100644 include/linux/power/pwrseq.h diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index acd4a15..f6aa4fd 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig @@ -515,3 +515,4 @@ endif # POWER_SUPPLY source "drivers/power/reset/Kconfig" source "drivers/power/avs/Kconfig" +source "drivers/power/pwrseq/Kconfig" diff --git a/drivers/power/Makefile b/drivers/power/Makefile index e46b75d..4ed2e12 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -74,3 +74,4 @@ obj-$(CONFIG_CHARGER_TPS65217) += tps65217_charger.o obj-$(CONFIG_POWER_RESET) += reset/ obj-$(CONFIG_AXP288_FUEL_GAUGE) += axp288_fuel_gauge.o obj-$(CONFIG_AXP288_CHARGER) += axp288_charger.o +obj-$(CONFIG_POWER_SEQUENCE) += pwrseq/ diff --git a/drivers/power/pwrseq/Kconfig b/drivers/power/pwrseq/Kconfig new file mode 100644 index 0000000..188729e --- /dev/null +++ b/drivers/power/pwrseq/Kconfig @@ -0,0 +1,20 @@ +# +# Power Sequence library +# + +config POWER_SEQUENCE + bool + +menu "Power Sequence Support" + +config PWRSEQ_GENERIC + bool "Generic power sequence control" + depends on OF + select POWER_SEQUENCE + help + It is used for drivers which needs to do power sequence + (eg, turn on clock, toggle reset gpio) before the related + devices can be found by hardware. This generic one can be + used for common power sequence control. + +endmenu diff --git a/drivers/power/pwrseq/Makefile b/drivers/power/pwrseq/Makefile new file mode 100644 index 0000000..ad82389 --- /dev/null +++ b/drivers/power/pwrseq/Makefile @@ -0,0 +1,2 @@ +obj-$(CONFIG_POWER_SEQUENCE) += core.o +obj-$(CONFIG_PWRSEQ_GENERIC) += pwrseq_generic.o diff --git a/drivers/power/pwrseq/core.c b/drivers/power/pwrseq/core.c new file mode 100644 index 0000000..e40315c --- /dev/null +++ b/drivers/power/pwrseq/core.c @@ -0,0 +1,79 @@ +/* + * core.c power sequence core file + * + * 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 + +static DEFINE_MUTEX(pwrseq_list_mutex); +static LIST_HEAD(pwrseq_list); + +int pwrseq_get(struct device_node *np, struct pwrseq *p) +{ + if (p && p->get) + return p->get(np, p); + + return -ENOTSUPP; +} + +int pwrseq_on(struct device_node *np, struct pwrseq *p) +{ + if (p && p->on) + return p->on(np, p); + + return -ENOTSUPP; +} + +void pwrseq_off(struct pwrseq *p) +{ + if (p && p->off) + p->off(p); +} + +void pwrseq_put(struct pwrseq *p) +{ + if (p && p->put) + p->put(p); +} + +void pwrseq_free(struct pwrseq *p) +{ + if (p && p->free) + p->free(p); +} + +void pwrseq_register(struct pwrseq *pwrseq) +{ + mutex_lock(&pwrseq_list_mutex); + list_add(&pwrseq->node, &pwrseq_list); + mutex_unlock(&pwrseq_list_mutex); +} + +void pwrseq_unregister(struct pwrseq *pwrseq) +{ + mutex_lock(&pwrseq_list_mutex); + list_del(&pwrseq->node); + mutex_unlock(&pwrseq_list_mutex); +} + +bool is_pwrseq_supported(struct device_node *np) +{ + if (of_find_property(np, "power-sequence", NULL)) + return true; + + return false; +} diff --git a/drivers/power/pwrseq/pwrseq_generic.c b/drivers/power/pwrseq/pwrseq_generic.c new file mode 100644 index 0000000..20398aa --- /dev/null +++ b/drivers/power/pwrseq/pwrseq_generic.c @@ -0,0 +1,134 @@ +/* + * pwrseq_generic.c Generic power sequence handling + * + * 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 + +#include + +struct pwrseq_generic { + struct pwrseq pwrseq; + struct gpio_desc *gpiod_reset; + struct clk *clk; +}; + +#define to_generic_pwrseq(p) container_of(p, struct pwrseq_generic, pwrseq) + +static void pwrseq_generic_free(struct pwrseq *pwrseq) +{ + struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq); + + pwrseq_unregister(pwrseq); + kfree(pwrseq_gen); +} + +static void pwrseq_generic_put(struct pwrseq *pwrseq) +{ + struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq); + + if (pwrseq_gen->gpiod_reset) + gpiod_put(pwrseq_gen->gpiod_reset); + + clk_put(pwrseq_gen->clk); +} + +static void pwrseq_generic_off(struct pwrseq *pwrseq) +{ + struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq); + + clk_disable_unprepare(pwrseq_gen->clk); +} + +static int pwrseq_generic_on(struct device_node *np, struct pwrseq *pwrseq) +{ + struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq); + int ret = 0; + u32 duration_us = 50; + struct gpio_desc *gpiod_reset = pwrseq_gen->gpiod_reset; + + if (pwrseq_gen->clk) { + ret = clk_prepare_enable(pwrseq_gen->clk); + if (ret) { + pr_err("Can't enable clock on %s: %d\n", + np->name, ret); + return ret; + } + } + + if (gpiod_reset) { + of_property_read_u32(np, "reset-duration-us", + &duration_us); + gpiod_direction_output(gpiod_reset, 1); + gpiod_set_value(gpiod_reset, 1); + usleep_range(duration_us, duration_us + 10); + gpiod_set_value(gpiod_reset, 0); + } + + return ret; +} + +static int pwrseq_generic_get(struct device_node *np, struct pwrseq *pwrseq) +{ + struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq); + int gpio; + + pwrseq_gen->clk = of_clk_get_by_name(np, NULL); + if (IS_ERR(pwrseq_gen->clk)) { + pr_debug("Can't get clock on %s: %ld\n", + np->name, PTR_ERR(pwrseq_gen->clk)); + pwrseq_gen->clk = NULL; + } + + gpio = of_get_named_gpio_flags(np, "reset-gpios", 0, NULL); + if (IS_ERR_VALUE(gpio) && (gpio != -ENODEV)) { + pr_err("Failed to get reset gpio on %s, err = %d\n", + np->name, gpio); + clk_put(pwrseq_gen->clk); + return gpio; + } + + if (gpio != -ENODEV) + pwrseq_gen->gpiod_reset = gpio_to_desc(gpio); + + return 0; +} + +struct pwrseq *pwrseq_alloc_generic(void) +{ + struct pwrseq_generic *pwrseq_gen; + + pwrseq_gen = kzalloc(sizeof(*pwrseq_gen), GFP_KERNEL); + if (!pwrseq_gen) + return ERR_PTR(-ENOMEM); + + pwrseq_gen->pwrseq.get = pwrseq_generic_get; + pwrseq_gen->pwrseq.on = pwrseq_generic_on; + pwrseq_gen->pwrseq.off = pwrseq_generic_off; + pwrseq_gen->pwrseq.put = pwrseq_generic_put; + pwrseq_gen->pwrseq.free = pwrseq_generic_free; + + pwrseq_register(&pwrseq_gen->pwrseq); + return &pwrseq_gen->pwrseq; +} +EXPORT_SYMBOL_GPL(pwrseq_alloc_generic); diff --git a/include/linux/power/pwrseq.h b/include/linux/power/pwrseq.h new file mode 100644 index 0000000..600f70c --- /dev/null +++ b/include/linux/power/pwrseq.h @@ -0,0 +1,55 @@ +#ifndef __LINUX_PWRSEQ_H +#define __LINUX_PWRSEQ_H + +#include + +struct pwrseq { + char *name; + struct list_head node; + int (*get)(struct device_node *np, struct pwrseq *p); + int (*on)(struct device_node *np, struct pwrseq *p); + void (*off)(struct pwrseq *p); + void (*put)(struct pwrseq *p); + void (*free)(struct pwrseq *p); +}; + +#if IS_ENABLED(CONFIG_POWER_SEQUENCE) +int pwrseq_get(struct device_node *np, struct pwrseq *p); +int pwrseq_on(struct device_node *np, struct pwrseq *p); +void pwrseq_off(struct pwrseq *p); +void pwrseq_put(struct pwrseq *p); +void pwrseq_free(struct pwrseq *p); +void pwrseq_register(struct pwrseq *pwrseq); +void pwrseq_unregister(struct pwrseq *pwrseq); +bool is_pwrseq_supported(struct device_node *np); + +#else +static inline int pwrseq_get(struct device_node *np, struct pwrseq *p) +{ + return 0; +} +static inline int pwrseq_on(struct device_node *np, struct pwrseq *p) +{ + return 0; +} +static inline void pwrseq_off(struct pwrseq *p) {} +static inline void pwrseq_put(struct pwrseq *p) {} +static inline void pwrseq_free(struct pwrseq *p) {} +static inline void pwrseq_register(struct pwrseq *pwrseq) {} +static inline void pwrseq_unregister(struct pwrseq *pwrseq) {} +static inline bool is_pwrseq_supported(struct device_node *np) +{ + return false; +} +#endif /* CONFIG_POWER_SEQUENCE */ + +#if IS_ENABLED(CONFIG_PWRSEQ_GENERIC) +struct pwrseq *pwrseq_alloc_generic(void); +#else +static inline struct pwrseq *pwrseq_alloc_generic(void) +{ + return NULL; +} +#endif /* CONFIG_PWRSEQ_GENERIC */ + +#endif /* __LINUX_PWRSEQ_H */