devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Nyekjaer <sean@geanix.com>
To: robh+dt@kernel.org, Lee Jones <lee@kernel.org>
Cc: devicetree@vger.kernel.org, Sean Nyekjaer <sean@geanix.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/3] mfd: stpmic1: add pmic poweroff via sys-off handler
Date: Tue, 16 May 2023 15:22:23 +0200	[thread overview]
Message-ID: <20230516132225.3012541-2-sean@geanix.com> (raw)
In-Reply-To: <20230516132225.3012541-1-sean@geanix.com>

Use devm_register_sys_off_handler() that allows to register multiple
power-off handlers.

This can be enabled by adding "st,pmic-poweroff" to device-tree.

Signed-off-by: Sean Nyekjaer <sean@geanix.com>
---
Changes since v1:
 - Removed superfluous function

 drivers/mfd/stpmic1.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/mfd/stpmic1.c b/drivers/mfd/stpmic1.c
index 4c9b18d9dec8..5b82cd37d57a 100644
--- a/drivers/mfd/stpmic1.c
+++ b/drivers/mfd/stpmic1.c
@@ -7,6 +7,7 @@
 #include <linux/mfd/core.h>
 #include <linux/mfd/stpmic1.h>
 #include <linux/module.h>
+#include <linux/reboot.h>
 #include <linux/of.h>
 #include <linux/of_irq.h>
 #include <linux/of_platform.h>
@@ -117,6 +118,16 @@ static const struct regmap_irq_chip stpmic1_regmap_irq_chip = {
 	.num_irqs = ARRAY_SIZE(stpmic1_irqs),
 };
 
+static int stpmic1_power_off(struct sys_off_data *data)
+{
+	struct stpmic1 *ddata = data->cb_data;
+
+	regmap_update_bits(ddata->regmap, MAIN_CR,
+			   SOFTWARE_SWITCH_OFF, SOFTWARE_SWITCH_OFF);
+
+	return NOTIFY_DONE;
+}
+
 static int stpmic1_probe(struct i2c_client *i2c)
 {
 	struct stpmic1 *ddata;
@@ -159,6 +170,18 @@ static int stpmic1_probe(struct i2c_client *i2c)
 		return ret;
 	}
 
+	if (of_property_read_bool(i2c->dev.of_node,  "st,pmic-poweroff")) {
+		ret = devm_register_sys_off_handler(ddata->dev,
+						    SYS_OFF_MODE_POWER_OFF,
+						    SYS_OFF_PRIO_DEFAULT,
+						    stpmic1_power_off,
+						    ddata);
+		if (ret) {
+			dev_err(ddata->dev, "failed to register sys-off handler: %d\n", ret);
+			return ret;
+		}
+	}
+
 	return devm_of_platform_populate(dev);
 }
 
-- 
2.40.0


  reply	other threads:[~2023-05-16 13:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16 13:22 [PATCH v2 1/3] mfd: stpmic1: fixup main control register and bits naming Sean Nyekjaer
2023-05-16 13:22 ` Sean Nyekjaer [this message]
2023-05-25 11:46   ` [PATCH v2 2/3] mfd: stpmic1: add pmic poweroff via sys-off handler Lee Jones
2023-05-16 13:22 ` [PATCH v2 3/3] dt-bindings: mfd: stpmic1: add fsl,pmic-poweroff property Sean Nyekjaer
2023-05-16 18:06   ` Conor Dooley
2023-05-23  9:55     ` Sean Nyekjær
2023-05-23 17:29       ` Conor Dooley
2023-05-24  8:16         ` Sean Nyekjær
2023-05-24 10:08           ` Conor Dooley
2023-05-24 10:30             ` Sean Nyekjaer
2023-05-24 19:57               ` Conor Dooley
2023-06-01  7:12               ` Krzysztof Kozlowski
2023-06-01 14:05                 ` Sean Nyekjaer
2023-06-01 15:25                   ` Krzysztof Kozlowski
2023-06-01 20:03                     ` Conor Dooley
2023-05-25 11:46 ` [PATCH v2 1/3] mfd: stpmic1: fixup main control register and bits naming Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230516132225.3012541-2-sean@geanix.com \
    --to=sean@geanix.com \
    --cc=devicetree@vger.kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).