From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43E83C433FE for ; Tue, 8 Dec 2020 10:12:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E8F5923A9C for ; Tue, 8 Dec 2020 10:12:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729078AbgLHKMD (ORCPT ); Tue, 8 Dec 2020 05:12:03 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:56893 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729063AbgLHKMC (ORCPT ); Tue, 8 Dec 2020 05:12:02 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id BA0B5C4E; Tue, 8 Dec 2020 05:10:55 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 08 Dec 2020 05:10:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=IZMTMn4wRKlczmZfBuLVqpHG2s4 w07cs+psbge8qouM=; b=LDCcM9gWBuPYaWTmfEAB2bJcoP3GjzN0AxqnNTlXG2j Mq4qYhbj1RBOiW2WuzAdRFwOxOlzdJ4KXQjTKxXXJbL7NcB2IEtbEiejTfXi7Lj1 PbPWz7TEE0NiP+vv5nlfbKNDM8W64dggqW7r85a+hTsk+Agr5bqe15jd+BtYv2kc nI55rjJxivHsvxGVuUXcwQu5W6eWN+IPFGNJLs9TzzjoKOgesdhK1ml100FuKM1W UPrTGrHlILU092nDWHDjaL8Z/0e82aLdSBYf9fcyC9BSI9aFbgGxCYvLRBD2b37+ g3C73khigvSN/XpGuWRkMTG4lyezTfuCdldiGvyV3lw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=IZMTMn 4wRKlczmZfBuLVqpHG2s4w07cs+psbge8qouM=; b=g6ccMHznz2ANZ/wJfEXtEu 1r0lnW/H4PfqDZBEdOnCSnbtiMe2MYEVHWvwPU8hHf4kyAVPcpZEjAG8wBXsoCaj /a6MofJxwtKWiyYJeTXxJHon23Q2fLmsgsu2SWKdyMM5d2AcmPCDWO3X+sM+rLac 3V9V5VHZRKMxSH9A5ntete7QJMZFgofJDGCwmVrExWKWB9qlydtCK9DGRbeKiPLr +xAR0BzzRWO+2rVGm38QVHORqZCAX0iZcMdNjN6kYtyN9s0ibYJmskIYqmSdk4v3 Nu90Qx5Y+3dnKpHhZP+wIyMJRyQaJkN2kZeJUPaYbJ+6cQUmsvt2kLApMGFfgTGg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudejiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpeforgigihhm vgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrfgrth htvghrnhepleekgeehhfdutdeljefgleejffehfffgieejhffgueefhfdtveetgeehieeh gedunecukfhppeeltddrkeelrdeikedrjeeinecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhgrgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Received: from localhost (lfbn-tou-1-1502-76.w90-89.abo.wanadoo.fr [90.89.68.76]) by mail.messagingengine.com (Postfix) with ESMTPA id 0301A1080057; Tue, 8 Dec 2020 05:10:53 -0500 (EST) Date: Tue, 8 Dec 2020 11:10:52 +0100 From: Maxime Ripard To: Michael Klein Cc: Sebastian Reichel , Rob Herring , Chen-Yu Tsai , Jernej Skrabec , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v3 1/3] power: reset: new driver regulator-poweroff Message-ID: <20201208101052.ecq2hbixxi45h4mr@gilmour> References: <20201128103958.q6glewhhch7vtczr@gilmour> <20201207142756.17819-1-michael@fossekall.de> <20201207142756.17819-2-michael@fossekall.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2oq2ncswqe5ho6wm" Content-Disposition: inline In-Reply-To: <20201207142756.17819-2-michael@fossekall.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --2oq2ncswqe5ho6wm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Dec 07, 2020 at 03:27:54PM +0100, Michael Klein wrote: > This driver registers a pm_power_off function to disable a set of > regulators defined in the devicetree to turn off the board. >=20 > Signed-off-by: Michael Klein > --- > drivers/power/reset/Kconfig | 7 ++ > drivers/power/reset/Makefile | 1 + > drivers/power/reset/regulator-poweroff.c | 107 +++++++++++++++++++++++ > 3 files changed, 115 insertions(+) > create mode 100644 drivers/power/reset/regulator-poweroff.c >=20 > diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig > index d55b3727e00e..ae6cb7b0bd4d 100644 > --- a/drivers/power/reset/Kconfig > +++ b/drivers/power/reset/Kconfig > @@ -177,6 +177,13 @@ config POWER_RESET_QNAP > =20 > Say Y if you have a QNAP NAS. > =20 > +config POWER_RESET_REGULATOR > + bool "Regulator subsystem power-off driver" > + depends on OF && REGULATOR > + help > + This driver supports turning off your board by disabling a set > + of regulators defined in the devicetree. > + > config POWER_RESET_RESTART > bool "Restart power-off driver" > help > diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile > index c51eceba9ea3..9dc49d3a57ff 100644 > --- a/drivers/power/reset/Makefile > +++ b/drivers/power/reset/Makefile > @@ -19,6 +19,7 @@ obj-$(CONFIG_POWER_RESET_OCELOT_RESET) +=3D ocelot-rese= t.o > obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) +=3D piix4-poweroff.o > obj-$(CONFIG_POWER_RESET_LTC2952) +=3D ltc2952-poweroff.o > obj-$(CONFIG_POWER_RESET_QNAP) +=3D qnap-poweroff.o > +obj-$(CONFIG_POWER_RESET_REGULATOR) +=3D regulator-poweroff.o > obj-$(CONFIG_POWER_RESET_RESTART) +=3D restart-poweroff.o > obj-$(CONFIG_POWER_RESET_ST) +=3D st-poweroff.o > obj-$(CONFIG_POWER_RESET_VERSATILE) +=3D arm-versatile-reboot.o > diff --git a/drivers/power/reset/regulator-poweroff.c b/drivers/power/res= et/regulator-poweroff.c > new file mode 100644 > index 000000000000..df2ca4fdcc49 > --- /dev/null > +++ b/drivers/power/reset/regulator-poweroff.c > @@ -0,0 +1,107 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Force-disables a regulator to power down a device > + * > + * Michael Klein > + * > + * Copyright (C) 2020 Michael Klein > + * > + * Based on the gpio-poweroff driver. > + */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define DEFAULT_TIMEOUT_MS 3000 > + > +/* > + * Hold configuration here, cannot be more than one instance of the driv= er > + * since pm_power_off itself is global. > + */ > +static struct regulator **poweroff_regulators; > +static u32 timeout =3D DEFAULT_TIMEOUT_MS; > + > +static void regulator_poweroff_do_poweroff(void) > +{ > + struct regulator **it; > + > + if (poweroff_regulators) > + for (it =3D poweroff_regulators; *it; ++it) > + if (regulator_is_enabled(*it)) > + regulator_force_disable(*it); > + > + /* give it some time */ > + mdelay(timeout); > + > + WARN_ON(1); > +} > + > +static int regulator_poweroff_probe(struct platform_device *pdev) > +{ > + int count; > + const char *name; > + struct regulator **it; > + struct property *prop; > + struct device_node *node =3D pdev->dev.of_node; > + > + /* If a pm_power_off function has already been added, leave it alone */ > + if (pm_power_off !=3D NULL) { > + dev_err(&pdev->dev, > + "%s: pm_power_off function already registered\n", > + __func__); > + return -EBUSY; > + } > + > + count =3D of_property_count_strings(node, "regulator-names"); > + if (count <=3D 0) > + return -ENOENT; > + > + poweroff_regulators =3D devm_kcalloc(&pdev->dev, count + 1, > + sizeof(struct regulator *), GFP_KERNEL); > + > + it =3D poweroff_regulators; > + of_property_for_each_string(node, "regulator-names", prop, name) { > + *it =3D devm_regulator_get(&pdev->dev, name); > + if (IS_ERR(*it)) > + return PTR_ERR(*it); > + it++; > + } > + > + of_property_read_u32(node, "timeout-ms", &timeout); > + > + pm_power_off =3D ®ulator_poweroff_do_poweroff; > + return 0; > +} > + > +static int regulator_poweroff_remove(__maybe_unused struct platform_devi= ce *pdev) > +{ > + if (pm_power_off =3D=3D ®ulator_poweroff_do_poweroff) > + pm_power_off =3D NULL; > + > + return 0; > +} > + > +static const struct of_device_id of_regulator_poweroff_match[] =3D { > + { .compatible =3D "regulator-poweroff", }, > + {}, > +}; > + > +static struct platform_driver regulator_poweroff_driver =3D { > + .probe =3D regulator_poweroff_probe, > + .remove =3D regulator_poweroff_remove, > + .driver =3D { > + .name =3D "poweroff-regulator", > + .of_match_table =3D of_regulator_poweroff_match, > + }, > +}; > + > +module_platform_driver(regulator_poweroff_driver); Since this can't be compiled as a module, you can use module_platform_driver_probe instead. Maxime --2oq2ncswqe5ho6wm Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRcEzekXsqa64kGDp7j7w1vZxhRxQUCX89RLAAKCRDj7w1vZxhR xYtVAP0c0fzec8KxHO/a2lG5JN9lp/jXTsHoamD5+8e8G53xnwEAniwDyn2gvqjS f1ceoeFITgRaS9n7Noj1lGaieeO0cwY= =2QeK -----END PGP SIGNATURE----- --2oq2ncswqe5ho6wm-- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC959C1B0D9 for ; Tue, 8 Dec 2020 10:12:19 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 74B7E23A9B for ; Tue, 8 Dec 2020 10:12:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 74B7E23A9B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cerno.tech Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=a0lG0zPup7+Dvxcl2AnRADuNKPYKGIkzHZ/T9fjNdMs=; b=QhKU5AHMGjHbtdvSm+xyGerBu Ast1lrHdwXCinNFLl2RFgUdhARj7/Z402bym9HROs+Jb+z82HFKLgd7CynWXwRfKEtP3FZXILWWFd Z/aHAd7a6L9TSKqyA/6QDDb9cRjbAvzTAARQzBcKyGMUYyQRpui4/HAsNrI4JrY1moTmlTBjCNpr5 ejG6URGA6Ci94yhUjJANleKSLYWd5AvOSny0hVovBSnYnw8rTr27ROU+uJ9M/0mm/In9Qkiw73bEg nzVHDMJf5kloVidAarjgWV6nFQnib0KARt9hLHiM6S+U+Em7Q6zIsMqvQjXmb60k8bvfOdHiT+pkc ygGh85KkQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmZxW-0000MT-A5; Tue, 08 Dec 2020 10:11:02 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmZxR-0000Kn-F8 for linux-arm-kernel@lists.infradead.org; Tue, 08 Dec 2020 10:10:58 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id BA0B5C4E; Tue, 8 Dec 2020 05:10:55 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 08 Dec 2020 05:10:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=IZMTMn4wRKlczmZfBuLVqpHG2s4 w07cs+psbge8qouM=; b=LDCcM9gWBuPYaWTmfEAB2bJcoP3GjzN0AxqnNTlXG2j Mq4qYhbj1RBOiW2WuzAdRFwOxOlzdJ4KXQjTKxXXJbL7NcB2IEtbEiejTfXi7Lj1 PbPWz7TEE0NiP+vv5nlfbKNDM8W64dggqW7r85a+hTsk+Agr5bqe15jd+BtYv2kc nI55rjJxivHsvxGVuUXcwQu5W6eWN+IPFGNJLs9TzzjoKOgesdhK1ml100FuKM1W UPrTGrHlILU092nDWHDjaL8Z/0e82aLdSBYf9fcyC9BSI9aFbgGxCYvLRBD2b37+ g3C73khigvSN/XpGuWRkMTG4lyezTfuCdldiGvyV3lw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=IZMTMn 4wRKlczmZfBuLVqpHG2s4w07cs+psbge8qouM=; b=g6ccMHznz2ANZ/wJfEXtEu 1r0lnW/H4PfqDZBEdOnCSnbtiMe2MYEVHWvwPU8hHf4kyAVPcpZEjAG8wBXsoCaj /a6MofJxwtKWiyYJeTXxJHon23Q2fLmsgsu2SWKdyMM5d2AcmPCDWO3X+sM+rLac 3V9V5VHZRKMxSH9A5ntete7QJMZFgofJDGCwmVrExWKWB9qlydtCK9DGRbeKiPLr +xAR0BzzRWO+2rVGm38QVHORqZCAX0iZcMdNjN6kYtyN9s0ibYJmskIYqmSdk4v3 Nu90Qx5Y+3dnKpHhZP+wIyMJRyQaJkN2kZeJUPaYbJ+6cQUmsvt2kLApMGFfgTGg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudejiedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpeforgigihhm vgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrfgrth htvghrnhepleekgeehhfdutdeljefgleejffehfffgieejhffgueefhfdtveetgeehieeh gedunecukfhppeeltddrkeelrdeikedrjeeinecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhgrgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Received: from localhost (lfbn-tou-1-1502-76.w90-89.abo.wanadoo.fr [90.89.68.76]) by mail.messagingengine.com (Postfix) with ESMTPA id 0301A1080057; Tue, 8 Dec 2020 05:10:53 -0500 (EST) Date: Tue, 8 Dec 2020 11:10:52 +0100 From: Maxime Ripard To: Michael Klein Subject: Re: [PATCH v3 1/3] power: reset: new driver regulator-poweroff Message-ID: <20201208101052.ecq2hbixxi45h4mr@gilmour> References: <20201128103958.q6glewhhch7vtczr@gilmour> <20201207142756.17819-1-michael@fossekall.de> <20201207142756.17819-2-michael@fossekall.de> MIME-Version: 1.0 In-Reply-To: <20201207142756.17819-2-michael@fossekall.de> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201208_051057_643350_BF26A0DC X-CRM114-Status: GOOD ( 29.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Jernej Skrabec , linux-pm@vger.kernel.org, Sebastian Reichel , linux-kernel@vger.kernel.org, Chen-Yu Tsai , Rob Herring , linux-arm-kernel@lists.infradead.org Content-Type: multipart/mixed; boundary="===============8894720596952893826==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============8894720596952893826== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2oq2ncswqe5ho6wm" Content-Disposition: inline --2oq2ncswqe5ho6wm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Dec 07, 2020 at 03:27:54PM +0100, Michael Klein wrote: > This driver registers a pm_power_off function to disable a set of > regulators defined in the devicetree to turn off the board. >=20 > Signed-off-by: Michael Klein > --- > drivers/power/reset/Kconfig | 7 ++ > drivers/power/reset/Makefile | 1 + > drivers/power/reset/regulator-poweroff.c | 107 +++++++++++++++++++++++ > 3 files changed, 115 insertions(+) > create mode 100644 drivers/power/reset/regulator-poweroff.c >=20 > diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig > index d55b3727e00e..ae6cb7b0bd4d 100644 > --- a/drivers/power/reset/Kconfig > +++ b/drivers/power/reset/Kconfig > @@ -177,6 +177,13 @@ config POWER_RESET_QNAP > =20 > Say Y if you have a QNAP NAS. > =20 > +config POWER_RESET_REGULATOR > + bool "Regulator subsystem power-off driver" > + depends on OF && REGULATOR > + help > + This driver supports turning off your board by disabling a set > + of regulators defined in the devicetree. > + > config POWER_RESET_RESTART > bool "Restart power-off driver" > help > diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile > index c51eceba9ea3..9dc49d3a57ff 100644 > --- a/drivers/power/reset/Makefile > +++ b/drivers/power/reset/Makefile > @@ -19,6 +19,7 @@ obj-$(CONFIG_POWER_RESET_OCELOT_RESET) +=3D ocelot-rese= t.o > obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) +=3D piix4-poweroff.o > obj-$(CONFIG_POWER_RESET_LTC2952) +=3D ltc2952-poweroff.o > obj-$(CONFIG_POWER_RESET_QNAP) +=3D qnap-poweroff.o > +obj-$(CONFIG_POWER_RESET_REGULATOR) +=3D regulator-poweroff.o > obj-$(CONFIG_POWER_RESET_RESTART) +=3D restart-poweroff.o > obj-$(CONFIG_POWER_RESET_ST) +=3D st-poweroff.o > obj-$(CONFIG_POWER_RESET_VERSATILE) +=3D arm-versatile-reboot.o > diff --git a/drivers/power/reset/regulator-poweroff.c b/drivers/power/res= et/regulator-poweroff.c > new file mode 100644 > index 000000000000..df2ca4fdcc49 > --- /dev/null > +++ b/drivers/power/reset/regulator-poweroff.c > @@ -0,0 +1,107 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * Force-disables a regulator to power down a device > + * > + * Michael Klein > + * > + * Copyright (C) 2020 Michael Klein > + * > + * Based on the gpio-poweroff driver. > + */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define DEFAULT_TIMEOUT_MS 3000 > + > +/* > + * Hold configuration here, cannot be more than one instance of the driv= er > + * since pm_power_off itself is global. > + */ > +static struct regulator **poweroff_regulators; > +static u32 timeout =3D DEFAULT_TIMEOUT_MS; > + > +static void regulator_poweroff_do_poweroff(void) > +{ > + struct regulator **it; > + > + if (poweroff_regulators) > + for (it =3D poweroff_regulators; *it; ++it) > + if (regulator_is_enabled(*it)) > + regulator_force_disable(*it); > + > + /* give it some time */ > + mdelay(timeout); > + > + WARN_ON(1); > +} > + > +static int regulator_poweroff_probe(struct platform_device *pdev) > +{ > + int count; > + const char *name; > + struct regulator **it; > + struct property *prop; > + struct device_node *node =3D pdev->dev.of_node; > + > + /* If a pm_power_off function has already been added, leave it alone */ > + if (pm_power_off !=3D NULL) { > + dev_err(&pdev->dev, > + "%s: pm_power_off function already registered\n", > + __func__); > + return -EBUSY; > + } > + > + count =3D of_property_count_strings(node, "regulator-names"); > + if (count <=3D 0) > + return -ENOENT; > + > + poweroff_regulators =3D devm_kcalloc(&pdev->dev, count + 1, > + sizeof(struct regulator *), GFP_KERNEL); > + > + it =3D poweroff_regulators; > + of_property_for_each_string(node, "regulator-names", prop, name) { > + *it =3D devm_regulator_get(&pdev->dev, name); > + if (IS_ERR(*it)) > + return PTR_ERR(*it); > + it++; > + } > + > + of_property_read_u32(node, "timeout-ms", &timeout); > + > + pm_power_off =3D ®ulator_poweroff_do_poweroff; > + return 0; > +} > + > +static int regulator_poweroff_remove(__maybe_unused struct platform_devi= ce *pdev) > +{ > + if (pm_power_off =3D=3D ®ulator_poweroff_do_poweroff) > + pm_power_off =3D NULL; > + > + return 0; > +} > + > +static const struct of_device_id of_regulator_poweroff_match[] =3D { > + { .compatible =3D "regulator-poweroff", }, > + {}, > +}; > + > +static struct platform_driver regulator_poweroff_driver =3D { > + .probe =3D regulator_poweroff_probe, > + .remove =3D regulator_poweroff_remove, > + .driver =3D { > + .name =3D "poweroff-regulator", > + .of_match_table =3D of_regulator_poweroff_match, > + }, > +}; > + > +module_platform_driver(regulator_poweroff_driver); Since this can't be compiled as a module, you can use module_platform_driver_probe instead. Maxime --2oq2ncswqe5ho6wm Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRcEzekXsqa64kGDp7j7w1vZxhRxQUCX89RLAAKCRDj7w1vZxhR xYtVAP0c0fzec8KxHO/a2lG5JN9lp/jXTsHoamD5+8e8G53xnwEAniwDyn2gvqjS f1ceoeFITgRaS9n7Noj1lGaieeO0cwY= =2QeK -----END PGP SIGNATURE----- --2oq2ncswqe5ho6wm-- --===============8894720596952893826== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============8894720596952893826==--