From patchwork Tue Aug 2 03:30: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: 9255057 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 A659E6048B for ; Tue, 2 Aug 2016 03:42:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96530284F8 for ; Tue, 2 Aug 2016 03:42:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A3BB284FB; Tue, 2 Aug 2016 03:42:06 +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 96DB0284F7 for ; Tue, 2 Aug 2016 03:42:05 +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 1bUQZ6-0007kb-Cj; Tue, 02 Aug 2016 03:40:24 +0000 Received: from mail-co1nam03on0048.outbound.protection.outlook.com ([104.47.40.48] helo=NAM03-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bUQYv-0006XX-7r for linux-arm-kernel@lists.infradead.org; Tue, 02 Aug 2016 03:40:14 +0000 Received: from BN3PR0301CA0014.namprd03.prod.outlook.com (10.160.180.152) by BN1PR0301MB0689.namprd03.prod.outlook.com (10.160.171.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.549.15; Tue, 2 Aug 2016 03:40:03 +0000 Received: from BN1BFFO11FD052.protection.gbl (2a01:111:f400:7c10::1:171) by BN3PR0301CA0014.outlook.office365.com (2a01:111:e400:4000::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.549.15 via Frontend Transport; Tue, 2 Aug 2016 03:40:03 +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 BN1BFFO11FD052.mail.protection.outlook.com (10.58.145.7) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.549.5 via Frontend Transport; Tue, 2 Aug 2016 03:40:03 +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 u723dYUJ006554; Mon, 1 Aug 2016 20:39:55 -0700 From: Peter Chen To: , , , , , , , , Subject: [PATCH v4 2/6] power: add power sequence library Date: Tue, 2 Aug 2016 11:30:48 +0800 Message-ID: <1470108652-16812-3-git-send-email-peter.chen@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470108652-16812-1-git-send-email-peter.chen@nxp.com> References: <1470108652-16812-1-git-send-email-peter.chen@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131145828043979959; (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)(77096005)(2950100001)(15975445007)(586003)(229853001)(2201001)(50466002)(92566002)(2171001)(36756003)(106466001)(33646002)(104016004)(50226002)(86362001)(8676002)(87936001)(48376002)(11100500001)(7846002)(305945005)(81156014)(2906002)(8666005)(19580405001)(5003940100001)(85426001)(50986999)(105606002)(8936002)(19580395003)(68736007)(47776003)(97736004)(76176999)(189998001)(5001770100001)(81166006)(4326007)(7416002)(356003)(7059030)(2004002)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BN1PR0301MB0689; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD052; 1:hCXqaxxKxbxQY0sAe48ABwZjdiN455v0E3HUrVdeIyGaBXhP5znzoOB2FgwP4UFb8t7+6AnfrFffegHY5hOkaY1qmKVkAXusSr6bOKFveQdrlEWH9SYGqpDSDhr4chYDBMkqw6jpRjkz++rekEvAykquri5Fv5V3AtLC2mrGjQOMTNGtwffFST/TIgCCQOxV5EzV80+dx9w8HSUvMMMOAMyiMYPiH/z8lqYHSE4Cm2Q2s5a8lJ8iggkcvIyszoPrDejPJt9//Nn5hctp62Pc7ve1GOuMYJNnwXt/lHeSVTX9gbS93O412KamiuqWHcJGxttzwvumqGAR/94kRFj51xZOnmd1UbyXnAkjeQaOdbiOJqeAh+7MdQot7akIBxrMYejdjbZIDBdXODxq+oKmgCeDFw8VV/neVod6QXOXu4MuSCg5cleVJa1qr3mtfIIF9b4OjrHFoOFyr9ZQONWKVusAfxGmne4Heg6KDuaPbTTZ/g5gJuXPUuWPFcH7ggyCbmQZBRspwt5+G0OmG3iNlapq5TGJPSWTbjq65l4VwsU7wDWTFynX/c5NeTfoBpE+a401Woq0BVP92MnUDuP1OrvE64ODciGbLl6VFaTzbRYI2TJRgidbGoDDq3mhwtyvVCq0jbsKmgu6X5va29hW9YyiEZ9qcRCYROJy2TFe2WqTHbXrJ8Qpq5dhOmr3/O1/SBJr951h1G5isFeowYPEeYI72JZ0ElACoaf5MkiacdidvO44JDqME3mbZk2gfr3S MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: bf6aba4d-57cf-49ab-fcb7-08d3ba86b0cc X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0689; 2:K8KQgfUf3S8lb0moH4+Ca6NJZwfMUiBBzHXPtjxqs8pTfIoaaeatedq0ARDr0DdyD5YfixDn/W+JNUMyyjPBtNL9m+gRILjh2UHY+Qg430pzqGJOmvehZPxnTp4SYujeqRXaq77c4mZYJM1ddK0CgQnt0VwcSewX435Sbh9xMjNxdsxL6gEX2eW+gpwsUi4T; 3:3sLSsncqCCunXo0vFn++IyRbbQgqC9j1L7wmiG5LUJhgTfCsXY9ygauesPL5P+LpCbhQhmEhCctE17Tpeozul5NtLwjpWGFnetvPyyF1B8WDIsUCE/trbnzEwnjq/ewWaWRgtIS3hga5tGHrD8g1o0CLlTmeZp+AwRGU5yY69K8XdptyquAhWoRljbzg7bXNn2h6GUcCPHEGUD5o3FCCC7k2KWsjJt7QRXreMHbH5is= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN1PR0301MB0689; X-Microsoft-Exchange-Diagnostics: 1; BN1PR0301MB0689; 25:hmXN9zJqym8T2bhEz/YQ5LhkRRUI46Nuvl4ABzOM5whscSa1HtwhDSqPPzY3/GP980kQt+n5ofCF2sodVZqJG16sKF4v6B2p9mOqVUik0VuVlHUES9aWrlI3kyjKbOlK6wW6CdlneMd27iE3EmWpS3E54p3nf9h1kp9ogZ8lgWzd5pAIGZ1qpmsCfNjJ3hgzyjpe9rIQYMRQiSFEMgo0/1svGb0JZblJWG34CNArt7B1Umh+3nVNZSjgsbrYaYm6lvRzX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wejcHbxuYsF3X12hANFgtHEtjxOUv02iOWk/xKJMMpsHr/xPI2SMngMbtGA1PQ3F1WjHMcR7LaZ1IfJZIcqRJWpDg9UQrAniz3HhQ4th1CjsgHcxC2ENriNWInIcS0AJviTumb+bEo1ro6OUHPBVN2yT3MDC7HBx8Ls/p5CITWzRhcb89GcQDwZIZLRRcr22+xQ6Hcx4qlPklLgd6CZo3oc+rcAR5BI/fxgD/rZLko97A3ETDFyu5N+9AhH+32XaCGlV39BUXgLc1ziZ6aPpeZF91EN9Fe1SGO2yytG4MYX3ymQXFQ9DwmYEHW3lhuLYKn2pJ+XFOvsj1yJCXvOGmOXhbIo8s6rbvkdrrR90oLKS0uvZAqmZd5cFm/zPA/Iw/dpryGEXbQjq3QrQtChPSz+2NUTRgdiyy9Hzg== 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:(601004)(2401047)(8121501046)(13018025)(13015025)(13024025)(13017025)(13023025)(5005006)(3002001)(10201501046)(6055026); SRVR:BN1PR0301MB0689; BCL:0; PCL:0; RULEID:(400006); SRVR:BN1PR0301MB0689; X-Forefront-PRVS: 0022134A87 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN1PR0301MB0689; 23:r0LUuLalzForWS3d7EkEJ6vCH8uPMvGaJujeDpF?= =?us-ascii?Q?aODM3gDupR/4m/KAll9h/FNAiJcoAHd9mbF2N06Nr9l9LZ5+XFDP0LTE8/03?= =?us-ascii?Q?qut14oUeyjr8ws6GIUauZLh/YDqboxUc0Nc3u9jMGAdmMQf4AjtK/uxsFAJk?= =?us-ascii?Q?PArj7oeTPcAFdF2rKH6gqx5Wv8vdhwgicyuq+ZxSpHen5q7kvZAm8Z4ysGfj?= =?us-ascii?Q?sUYidTKb3ugQixShooKiOdluwdYqTRGdWwmGX9jmwDMax0onWvJFkpOZn2Bz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99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Aug 2016 03:40:03.8988 (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: BN1PR0301MB0689 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160801_204013_408862_2638B3FC X-CRM114-Status: GOOD ( 21.36 ) 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 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 --- 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 | 71 ++++++++++++++ drivers/power/pwrseq/pwrseq_generic.c | 170 ++++++++++++++++++++++++++++++++++ include/linux/power/pwrseq.h | 52 +++++++++++ 8 files changed, 326 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..60f1e4e --- /dev/null +++ b/drivers/power/pwrseq/core.c @@ -0,0 +1,71 @@ +/* + * 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); +} diff --git a/drivers/power/pwrseq/pwrseq_generic.c b/drivers/power/pwrseq/pwrseq_generic.c new file mode 100644 index 0000000..99c772e --- /dev/null +++ b/drivers/power/pwrseq/pwrseq_generic.c @@ -0,0 +1,170 @@ +/* + * 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); + + pwrseq_unregister(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; + + 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..c8d72eb --- /dev/null +++ b/include/linux/power/pwrseq.h @@ -0,0 +1,52 @@ +#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); +void pwrseq_register(struct pwrseq *pwrseq); +void pwrseq_unregister(struct pwrseq *pwrseq); + +#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) {} +#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 */