[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230516132225.3012541-2-sean@geanix.com>
Date: Tue, 16 May 2023 15:22:23 +0200
From: Sean Nyekjaer <sean@...nix.com>
To: robh+dt@...nel.org, Lee Jones <lee@...nel.org>
Cc: devicetree@...r.kernel.org, Sean Nyekjaer <sean@...nix.com>,
linux-kernel@...r.kernel.org
Subject: [PATCH v2 2/3] mfd: stpmic1: add pmic poweroff via sys-off handler
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@...nix.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
Powered by blists - more mailing lists