From patchwork Mon Aug 15 09:13:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 9280651 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 0871C607FD for ; Mon, 15 Aug 2016 09:25:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E955328BF0 for ; Mon, 15 Aug 2016 09:25:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCEAD28BF9; Mon, 15 Aug 2016 09:25:19 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1AEB28BF8 for ; Mon, 15 Aug 2016 09:25:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932205AbcHOJZR (ORCPT ); Mon, 15 Aug 2016 05:25:17 -0400 Received: from mail-sn1nam01on0040.outbound.protection.outlook.com ([104.47.32.40]:42240 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752778AbcHOJXK (ORCPT ); Mon, 15 Aug 2016 05:23:10 -0400 Received: from BN3PR0301CA0079.namprd03.prod.outlook.com (10.160.152.175) by BN6PR03MB2706.namprd03.prod.outlook.com (10.173.144.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.549.15; Mon, 15 Aug 2016 09:23:06 +0000 Received: from BL2FFO11OLC007.protection.gbl (2a01:111:f400:7c09::119) by BN3PR0301CA0079.outlook.office365.com (2a01:111:e400:401e::47) 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, 15 Aug 2016 09:23:06 +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 BL2FFO11OLC007.mail.protection.outlook.com (10.173.160.142) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.567.7 via Frontend Transport; Mon, 15 Aug 2016 09:23:07 +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 u7F9Mh8c020596; Mon, 15 Aug 2016 02:22:59 -0700 From: Peter Chen To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , Peter Chen Subject: [PATCH v6 2/8] power: add power sequence library Date: Mon, 15 Aug 2016 17:13:12 +0800 Message-ID: <1471252398-957-3-git-send-email-peter.chen@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1471252398-957-1-git-send-email-peter.chen@nxp.com> References: <1471252398-957-1-git-send-email-peter.chen@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131157265876729448; (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)(5003940100001)(2201001)(106466001)(4326007)(2906002)(86362001)(586003)(48376002)(69596002)(105606002)(626004)(47776003)(19580405001)(2950100001)(50466002)(229853001)(85426001)(15975445007)(97736004)(36756003)(189998001)(11100500001)(19580395003)(76176999)(81166006)(81156014)(305945005)(50986999)(7846002)(8676002)(68736007)(87936001)(104016004)(5001770100001)(8936002)(356003)(8666005)(50226002)(7416002)(77096005)(33646002)(92566002)(2171001)(7059030)(2004002)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR03MB2706; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11OLC007; 1:gAJBZ6TUw6nRbd0E8wGYtwVDozaVpCT0YYZhhUrKBifh0Awdhgu1zEx9WL9ZDwcn217Ha7SR5NJNEHBSWEvhX1iSsLZf7RzajTYcptfIQC0XgGjAuLn7Ri3g9k7x1rZmrWY1+ITLZWK9fhXuPRSNAP+74RuQyEwScl/rozmBGtneWvPuYonxnzfpaPzgHC1/GACxRPginXEZdx9jqRa0oGtVxcWtVeUH8aO0HN+PQX3MjraOk5BQVzI4zN7WRtkWiGzdGwNtO+VCp+qxcuWBDVXMuixw91L+NMDvVBpq40Gwa0cqSIJ9a0qi/gtc8PEimizXCxy3NWCdObfLMY0QLCsKS91IS3mGrHr257GmNj5gcZXWTuWApk3d76O0Xg3/SuKR/ulDGB5S12V15MvhZt0YJXGESbRZMEf2/zdyZz2N9nGpdTTSyGtmVBLhWB6YIwNNTOBZjn0JNbkdf/UfgK5xIsRNqHpHnNOQYLEuVwlMNA/EQ7o7s7/36Dh4MDaQJOteeYlDeYKSmSeD22dQF9FA1Gy6WVjHgMzdUeZF6bL2QgeDJOfCP0V1/oMdy0Jckm02F1X1J/RWyWjPBJ9cT52SwzZPGLF+ndaphoCNcSn1ovHzY3IaJmsihG3W5WTR8bdfWoC5aCX9glPn/pJuX9skg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MGo= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN6PR03MB2706; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2706; 31:lNfdgw+KfMAFld9Lp30XZgws1Edd0Z1zSfCq4jxrJi5QTnoFfJKZE937opl2n/LCC/id/PAbs5FQQHdEkU1wXDWNw0DCl9lFrzMVJDmv3ScMnLa+HUazbiM256ZMRUerSM2M8smP5jrBGSuWNJ9LYYdSUwJ/Pk9qgIdjX7nntgURImq5QdF3K+7C+hIaaevAAY7cE5UTiwi9YqBcDTDYqba83bq7uSjN4C6xTqxODQw=; 4:rYXJ88LjVL6Pvf3Kaky92vujA3Zzekes7I9pBGbkAw2dP3rymckpGVp3Yoi8eav+vpcffyx8TtpZqz09uARBADMDQRRP0qYEB6/RSyDIINFSXfkgDr3k0naOV0KSMXGxScP37bQJVR+EehLEtvCafIBBzao/TUi34PPQkrTG32LCBwWh3TYR6PUNzjeEGHAPspjt/JSfE7iIvtgQ9n+Wc39fSNGGuHhOqhWlv9r0K+UrE4oRZPYObmRhzfbsObp1RFKgxc5Ed1bWJSegf+95SvU0Csq2LLgOX/zOwAbzs0Pe8JZoaFd5NB+GtRoYK1LW3NaDqa5zdb5ZrP30PFsd0Kr7tunXxdLob8Q86QnZvmOGu8waP7GVPShDb+Z88KlFffxlwD2j5EsqBpSvEvz5jQUwuKxO+jYlQKEbD+K38zz+IcKo8NIrXORqgFzrxWfKmZktimvDxkjjSm5QzJ/aQRr0RSWSBvSFWaKDCPVUIAmONLFTAk0FJyaS1lbZm03lv55VJAUmycXaBUxiArgGVMzQ0Pmo6ty3J68+Ae5/2seiAbB7f+o0qI4cp8BPXIQuWy6KeZzSUwGd8eeClby+LQVJOq7knnucWTLb19oNr0f2risIHYGfAEuxBOcrjoULmDXRSPtAcGobGTOM41obbTRsFNj+hJWreneKvt+O068= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(250305191791016)(22074186197030)(9452136761055)(185117386973197)(84791874153150); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(13017025)(5005006)(8121501046)(13018025)(13015025)(13023025)(13024025)(10201501046)(3002001)(6055026); SRVR:BN6PR03MB2706; BCL:0; PCL:0; RULEID:(400006); SRVR:BN6PR03MB2706; X-Forefront-PRVS: 0035B15214 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR03MB2706; 23:0mlPSyhiAtzNMspppEfZOuG10nHHvlwFLcDV6Ne1N?= =?us-ascii?Q?5883vxUYcl1eg4veTq+Wpp/8iLrGNMzhKkF7y6jktvkLp0Eq+LBWrZZK+nnc?= =?us-ascii?Q?atiLQqv9ugc+eesAl0q7fZrjNDbYVmEatZjW2WpF9L+dVdVYyJw+wkWa/UUI?= =?us-ascii?Q?ONIGBYsDHSbEjexJEHvBWLQvCXVM56BKOk4lKWUuer99kcxBjoWAUNJBcSAf?= =?us-ascii?Q?FQnTnP5IRzQBc0qxbPeB8Xf4/b+aXDl/fqhebXt/e5M+YqXpIDu0/70sD9a+?= =?us-ascii?Q?F7uI5l/fkPR8EjmarBfwGhRPJxC0LB7pbfIlYQJQLqxlSjGXlpBZGWXzd4Yk?= =?us-ascii?Q?fs1rUraLQgAngVvjjzTquQ88XZgC5pRlywIfOSCLaLh4iXDY9s/xjuyLC4El?= =?us-ascii?Q?XnqlE2W+Tu+PGP7FRxGewq/zKQcvxrBo6aem4GA5a8tc0SXWYO6uaj84BBma?= =?us-ascii?Q?PYuf4xso43QNxWO7cp2YozCI+P9RyeG7KpS4zLtnoIEPPP3WINgreDO6Nry6?= =?us-ascii?Q?Zpda1rr5V6jCnb4sLgPEhkUOD0fCrOe8Q6JZfmCmKTQ+gDpdd2ayqREDKiRa?= =?us-ascii?Q?eg3m5JMZwoYtGTLVPuZhoWB1kmjza07AZnqI9zCs8e8ZMdeX4aLpU5m0NK6B?= =?us-ascii?Q?KVhv7zNo+w6vq75nAJQnjalZR3Shlke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Mr3yF3+Jatk8DesJZoC2vYRVXkuV2gUf6T9LgEJg=; 5:GlSqEFthsJVCJh4BOjXVksZTRFUmk0IIp4fPpRu5gK4gqt1bkdavLDlUfA7Nh8gnojLKNjK5vIA1w133U7BWKRcgvniSwdyd4SK8j2GFD0MDdozgsmr2WwESGl2FFtbYp+x1UOwan2c/IsxWd+armCq3gMvy4LjDrY8Mf8PeGoM=; 24:OPRFDEOhzVzR76KimVR1Ykhm6H/XO/m7fwm8LDiSO2sw4aar4r8lSU2TRwghgaScQtoTGDq1z7m3tdJQjIFC+MH8qAvOft4WJ0XU6lOmrdI=; 7:T6XqKjtT/DCfADYihm+NqAIPJ2/r3uAU/5ucng76h7AdkNB2eaSUBTndfKOGY7UsTeaOozjaphJmGL8/9RrkHyFBppBbxKpzN067tzuyOH9aiWjaCVvzYdbEqtEJYJtr3aLCFT0Op9124qB0/o0/SC9j8lDj/5etuF9v5qxnRg4agumQuw3anO0LaXsOeh1wHpd5A3qgmqGucigrVba7fAa2BOVqAfrzgZmFxd+qVU7OE72Y3zrZh8mV1I6U6KVy SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2016 09:23:07.2517 (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: BN6PR03MB2706 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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 Tested-by Joshua Clayton Reviewed-by: Matthias Kaehlcke Tested-by: Matthias Kaehlcke --- MAINTAINERS | 9 ++ drivers/power/Kconfig | 1 + drivers/power/Makefile | 1 + drivers/power/pwrseq/Kconfig | 20 ++++ drivers/power/pwrseq/Makefile | 2 + drivers/power/pwrseq/core.c | 62 +++++++++++++ drivers/power/pwrseq/pwrseq_generic.c | 168 ++++++++++++++++++++++++++++++++++ include/linux/power/pwrseq.h | 47 ++++++++++ 8 files changed, 310 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/MAINTAINERS b/MAINTAINERS index 1ae6c84..407254b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9283,6 +9283,15 @@ F: include/linux/pm_* F: include/linux/powercap.h F: drivers/powercap/ +POWER SEQUENCE LIBRARY +M: Peter Chen +T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git +L: linux-pm@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/power/pwrseq/ +F: drivers/power/pwrseq/ +F: include/linux/power/pwrseq.h/ + POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS M: Sebastian Reichel M: Dmitry Eremin-Solenikov 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..dcf96c4 --- /dev/null +++ b/drivers/power/pwrseq/core.c @@ -0,0 +1,62 @@ +/* + * 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; +} +EXPORT_SYMBOL(pwrseq_get); + +int pwrseq_on(struct device_node *np, struct pwrseq *p) +{ + if (p && p->on) + return p->on(np, p); + + return -ENOTSUPP; +} +EXPORT_SYMBOL(pwrseq_on); + +void pwrseq_off(struct pwrseq *p) +{ + if (p && p->off) + p->off(p); +} +EXPORT_SYMBOL(pwrseq_off); + +void pwrseq_put(struct pwrseq *p) +{ + if (p && p->put) + p->put(p); +} +EXPORT_SYMBOL(pwrseq_put); + +void pwrseq_free(struct pwrseq *p) +{ + if (p && p->free) + p->free(p); +} +EXPORT_SYMBOL(pwrseq_free); diff --git a/drivers/power/pwrseq/pwrseq_generic.c b/drivers/power/pwrseq/pwrseq_generic.c new file mode 100644 index 0000000..8af626f --- /dev/null +++ b/drivers/power/pwrseq/pwrseq_generic.c @@ -0,0 +1,168 @@ +/* + * 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 *clks[PWRSEQ_MAX_CLKS]; +}; + +#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); + + kfree(pwrseq_gen); +} + +static void pwrseq_generic_put(struct pwrseq *pwrseq) +{ + struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq); + int clk; + + if (pwrseq_gen->gpiod_reset) + gpiod_put(pwrseq_gen->gpiod_reset); + + for (clk = 0; clk < PWRSEQ_MAX_CLKS; clk++) + clk_put(pwrseq_gen->clks[clk]); +} + +static void pwrseq_generic_off(struct pwrseq *pwrseq) +{ + struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq); + int clk; + + for (clk = PWRSEQ_MAX_CLKS - 1; clk >= 0; clk--) + clk_disable_unprepare(pwrseq_gen->clks[clk]); +} + +static int pwrseq_generic_on(struct device_node *np, struct pwrseq *pwrseq) +{ + struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq); + int clk, ret = 0; + struct gpio_desc *gpiod_reset = pwrseq_gen->gpiod_reset; + + for (clk = 0; clk < PWRSEQ_MAX_CLKS && pwrseq_gen->clks[clk]; clk++) { + ret = clk_prepare_enable(pwrseq_gen->clks[clk]); + if (ret) { + pr_err("Can't enable clock on %s: %d\n", + np->full_name, ret); + goto err_disable_clks; + } + } + + if (gpiod_reset) { + u32 duration_us = 50; + + of_property_read_u32(np, "reset-duration-us", + &duration_us); + if (duration_us <= 10) + udelay(10); + else + usleep_range(duration_us, duration_us + 100); + gpiod_set_value(gpiod_reset, 0); + } + + return ret; + +err_disable_clks: + while (--clk >= 0) + clk_disable_unprepare(pwrseq_gen->clks[clk]); + + return ret; +} + +static int pwrseq_generic_get(struct device_node *np, struct pwrseq *pwrseq) +{ + struct pwrseq_generic *pwrseq_gen = to_generic_pwrseq(pwrseq); + enum of_gpio_flags flags; + int reset_gpio, clk, ret = 0; + + for (clk = 0; clk < PWRSEQ_MAX_CLKS; clk++) { + pwrseq_gen->clks[clk] = of_clk_get(np, clk); + if (IS_ERR(pwrseq_gen->clks[clk])) { + ret = PTR_ERR(pwrseq_gen->clks[clk]); + if (ret == -EPROBE_DEFER) + goto err_put_clks; + pwrseq_gen->clks[clk] = NULL; + break; + } + } + + reset_gpio = of_get_named_gpio_flags(np, "reset-gpios", 0, &flags); + if (gpio_is_valid(reset_gpio)) { + unsigned long gpio_flags; + + if (flags & OF_GPIO_ACTIVE_LOW) + gpio_flags = GPIOF_ACTIVE_LOW | GPIOF_OUT_INIT_LOW; + else + gpio_flags = GPIOF_OUT_INIT_HIGH; + + ret = gpio_request_one(reset_gpio, gpio_flags, + "pwrseq-reset-gpios"); + if (ret) + goto err_put_clks; + + pwrseq_gen->gpiod_reset = gpio_to_desc(reset_gpio); + } else { + if (reset_gpio == -ENOENT) + return 0; + + ret = reset_gpio; + pr_err("Failed to get reset gpio on %s, err = %d\n", + np->full_name, reset_gpio); + goto err_put_clks; + } + + return ret; + +err_put_clks: + while (--clk >= 0) + clk_put(pwrseq_gen->clks[clk]); + return ret; +} + +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; + + 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..ebb2280 --- /dev/null +++ b/include/linux/power/pwrseq.h @@ -0,0 +1,47 @@ +#ifndef __LINUX_PWRSEQ_H +#define __LINUX_PWRSEQ_H + +#include + +#define PWRSEQ_MAX_CLKS 3 + +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); +#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) {} +#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 */