From patchwork Thu Jul 7 09:14: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: 9218651 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 5C2D4607D9 for ; Thu, 7 Jul 2016 09:24:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CD3C287E7 for ; Thu, 7 Jul 2016 09:24:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 413A1287E9; Thu, 7 Jul 2016 09:24:46 +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 76059287E7 for ; Thu, 7 Jul 2016 09:24:45 +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 1bL5Wf-0003c2-Q5; Thu, 07 Jul 2016 09:23:17 +0000 Received: from mail-bn3nam01on0046.outbound.protection.outlook.com ([104.47.33.46] helo=NAM01-BN3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bL5WR-0003Hy-GD for linux-arm-kernel@lists.infradead.org; Thu, 07 Jul 2016 09:23:06 +0000 Received: from BN3PR0301CA0049.namprd03.prod.outlook.com (10.160.152.145) by SN1PR0301MB2032.namprd03.prod.outlook.com (10.163.226.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.534.14; Thu, 7 Jul 2016 09:22:41 +0000 Received: from BN1BFFO11FD030.protection.gbl (2a01:111:f400:7c10::1:189) by BN3PR0301CA0049.outlook.office365.com (2a01:111:e400:401e::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.534.14 via Frontend Transport; Thu, 7 Jul 2016 09:22:41 +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 BN1BFFO11FD030.mail.protection.outlook.com (10.58.144.93) with Microsoft SMTP Server (TLS) id 15.1.534.7 via Frontend Transport; Thu, 7 Jul 2016 09:22:32 +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 u679M9nU024626; Thu, 7 Jul 2016 02:22:25 -0700 From: Peter Chen To: , , , , , , Subject: [PATCH 2/6] power: add power sequence library Date: Thu, 7 Jul 2016 17:14:48 +0800 Message-ID: <1467882892-27589-3-git-send-email-peter.chen@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1467882892-27589-1-git-send-email-peter.chen@nxp.com> References: <1467882892-27589-1-git-send-email-peter.chen@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131123569611248281; (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)(199003)(189002)(81156014)(81166006)(356003)(36756003)(104016004)(189998001)(6806005)(8676002)(77096005)(15975445007)(7846002)(5001770100001)(8666005)(8936002)(50226002)(305945005)(11100500001)(2906002)(97736004)(92566002)(2171001)(2201001)(5003940100001)(50466002)(87936001)(19580395003)(19580405001)(69596002)(33646002)(2950100001)(85426001)(68736007)(50986999)(47776003)(105606002)(106466001)(229853001)(76176999)(86362001)(48376002)(4326007)(586003)(7059030)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR0301MB2032; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD030; 1:vjLP/oI2RMqK2TIXu7MqmpgA5O06RTGchuV59j7VL21TgV8zXXBWqZrR3ZxHQTzYMi6ReGUsQy2JyUye23Y5y1+eQhpd9wPpbIZSEMttXOsJoct0lDqpM0SU6QvyXj2aBWx6pZi/XKngqG+iOpUeCCzW6pE2JaGqERQZSahh1ArEgfIEkYGibMxW+VJW5DZ13thxDOt2fVDtLbx6iu61xyTSBK7Mr99T/OUCTv1Tx7kUtDtPh2q+i+2r2sYbeVGAKhmebVTQj96/vLivRdOrFk9a8q1akalrp0SRpXuXhvH/NB50vdXBDrQtS6SG6RhHMaqMqMcLCpNpEPFJB8FsMIpimWLJkSwDMPqyU3dlkPiNjKFqgdgxv4KlPt0DWS/4yZKEH0dOj5h4/fh0vP8idlbSOP7mQazbw3iBeK0oKlLHX6c29n3+/qfa72irOr2Y93WNzg4ljZJxykhAEjHHWC1hWcOARnKwvtN7fEfpgCWbsSTo2yruZd/43Oh3HhfsOzqzJNwEsv9jJkPe5iDKF+z8KjWB2EUM1ST83dcRMwjS579qwJcqKMCXDJuf3d06of7Shpl/US7M80RQmVu0YiTlGGlVhJN4b++xPM/OF5s1tzmcus9hD3yyMhL2x3NlhXCVz7SatUro7azuyMhZDNWJoqClfaFk59vyb3+NfB2s4x0zxuwHP706zrGZeR+GEoQlNNyRZhQVfE5QfA3KsveqzURfksswAxwTmUEOzQL07ZYBqSKLk0vp5m8IJLGu MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 47708222-8b01-4a28-0789-08d3a6483ec0 X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB2032; 2:CJKXPaAD0Jxy6j16gkYQoHYiYlZKfCBHcDiPDiYtlxPta8m3LQ36nWV5My4xaCCq8w2nK6vWx97BX7rLdfrBVYeEknXbLOiU99tVMgBWVMK1ScFLHYR49iA9Un3AK9SbbXNX060gLgm+BpRVdOFLqG1Q91vBP77mMC2rUXeO4t0HxjEIt12iGnJsDToV3d4l; 3:bvi9A7yRqSvbUDkK0/zxsWopRfwUZ8lNzZ6BW1cLW9Tf0GP0nB2IIpMgu7vzVRHoXsSRsTazpC6Fhc/2KED9DHkoYZTMZ0d86Ji/rQsbAU3DwPiqRstBLLgCoUhm7eAIw1tGnsjjk6tHy5GLh/axbE9tbYvTuunvX5LLH53hD6y5xPIMdNwB5a0bWL4x5T7JaqtnHL6RBE08dUt+IYRGV7C2x2rSMNVLmK/K4VJZnfM= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0301MB2032; X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB2032; 25:mR7ZOacjGdYn7eOsdA/6Zjy7WV6sfPaAKSf1CJgsf4wAfgebFmheXzGFS1kMaz9iZ4o8dwdoONGgq1/mgecFXdmwZ2WZ0u07QAMs1faSTGDidQ0r7bVE2KfPRp/yt/vDktxmW35hpxUhehT/dajUS2y4Q3aIcNBiMZDMEPVEhTsLRfbcIlvY39ry5+V3p05THJHmfvvMHraETiTCWYL+qMdXegjcX9NImAVN/1yIf5cb4HEmQYgdnoAmeLqCRrPDtaDdg9Nel9INVATvo2gHmH2wwi8LniD7ptkGSDLw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WaeEJ6AZze9wqA0HOuvHAtG5JLhS7EWaNFynWFA7glCAxoTTQh6emcg2JGVdJ44O25KeoGPSYFpVxxTkgKbK7znANBn8asA2Rj+KSALF+KNTuQxf4SgCSsNutSY621FAISJX7sWiWWLY6GG+xuY6lAs292uam3jz6VmxwBp+DvRYJoWJRpaF1fFnbC4dosoCgI9gr7vKBU5waIwvdZnb/K3FG3RB02/+c5Uo7FuxVMYoXxyY7cNa+pKVFnpODTYIj1OiMai0SYEAJqCXXGKVuMz4J0QhpeCre/EC+b0/X3EoxkdDjBjn+JOWydQg== 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)(13024025)(13023025)(13017025)(13015025)(13018025)(5005006)(8121501046)(10201501046)(3002001)(6055026); SRVR:SN1PR0301MB2032; BCL:0; PCL:0; RULEID:(400006); SRVR:SN1PR0301MB2032; X-Forefront-PRVS: 0996D1900D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN1PR0301MB2032; 23:gqWaOikCTn9pt2TAT0gy97Q01sV+VRyqvOW9ZMC?= =?us-ascii?Q?6m8vxk3Je8oC8+S3UHCwatvcHiEA7Izxw6tVTbwhynmOTUYUyiDAVOtjn4nd?= =?us-ascii?Q?Y/lLMeBR95qDfOa6ULNHGWpuw45t7RlC4h+hKqG3tp9yBofFGwWOlHxH2+Q7?= =?us-ascii?Q?avEwhINwp1XmYEWK++q+jmFXRgq4m4O31ls9NuhOUSpBOVU2YGwDu0Or/jpL?= =?us-ascii?Q?yvqaKk5PcadZ/t/dQhEwLnsXuQ7R2BA4ngFZ3R6Ppk1fROitIbK3bb+IuHFl?= =?us-ascii?Q?M1z9motS5kZoH2iU4P6TCfaNC1YdIvoT+2bk2xAcHiN58WFQ4mXJ6r0J4cxr?= =?us-ascii?Q?mkau1r86D3BRSVbh/tIDRHbvWTS1NOmGEYYW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D7ITR20=3D?= X-Microsoft-Exchange-Diagnostics: 1; SN1PR0301MB2032; 6:hiijzfvBtJKpOFOMgTf4wn8vxzIpHK4laBmZQHJM3CcnEOI1atCVovkhxs5B/kqQyEAwsWrH6hYVg78THEfH3xl7Jt/TSKCeF59JBUrUd1yyJI1jX9TlpVfeqvF56pnn5b+OMVhOC451+f9/8RwUa9SXOJ/uv+Xu2Tux7/UK/w1kndbS2Zw651yToqyLY2HpSJC60L/V+c8x5C/mOiOHQPIBkpPvEtRPrn1q9nLWEqEPFAKL6W2qsfpEzkJQgdp8Rta3/y9DEaDYq5T2xzeZwjZGAgCIhSNn0Sg4Tl+wFl4=; 5:Wz5VHn3ILQ52aN1F5pTeAEvVo3MxZTz9iRqjNpzJQYJytHSFCROxCLz4U9HIN4H8f8nX0GzCGO+GOPk7XApUhTq8PBNTSyAhEaDuaOs+WYCINqi/9l3LkJFoVyueGWZ7z0FjDK71okgPGmthtJX9aRHBT4JpSO8SHtK6RXqGcVE=; 24:nCYeA1plyfXWx8g6nIh+QJ6uiI5WRRAZumyr4c+fE6x3JqjabpAd0iLHlgZ9FlyBIfjWgLgLzjdAJLZ3Sxw39aBl5cDT3yYvHxgkoNYMay8=; 7:Q4smOQpTgsHV85Cf9VDqr+s7lh5Lrui9zFJ9Aq+XBf4LDs/ZsQV68Gql2ekSplgpn720pnrkABA8Eo6LWcg+WnQXNRLF1GzAIrkshZh4wG/NxlSsdjiPcCu1X9cdAs1Rj9eOaPcN19FQwmW60idzceHLiJ0sTEqoXv3Udkig0q7nuurhija9/CJXObyzFVPGmWriKjwe47R9FsJT5wRLcq/GvrhVk1AZ5VtWT6yF+VXVs0bqoq+d++Tgtcu+EUUx SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2016 09:22:32.4043 (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: SN1PR0301MB2032 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160707_022304_028661_7DFC9A51 X-CRM114-Status: GOOD ( 18.72 ) 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, 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..e3cacb0 --- /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, "pwrseq-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, "pwrseq-clk"); + 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, "pwrseq-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 */