From: Frank Wunderlich <linux@fw-web.de>
To: Lee Jones <lee.jones@linaro.org>
Cc: Frank Wunderlich <frank-w@public-files.de>,
linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org,
Peter Geis <pgwipeout@gmail.com>
Subject: [PATCH 1/2] mfd: rk808: add reboot support to rk808 pmic
Date: Wed, 15 Dec 2021 22:32:59 +0100 [thread overview]
Message-ID: <20211215213300.4778-2-linux@fw-web.de> (raw)
In-Reply-To: <20211215213300.4778-1-linux@fw-web.de>
From: Peter Geis <pgwipeout@gmail.com>
This adds reboot support to the rk808 pmic. This only enables if the
rockchip,system-power-controller flag is set.
Signed-off-by: Peter Geis <pgwipeout@gmail.com>
---
drivers/mfd/rk808.c | 48 +++++++++++++++++++++++++++++++++++++++
include/linux/mfd/rk808.h | 2 ++
2 files changed, 50 insertions(+)
diff --git a/drivers/mfd/rk808.c b/drivers/mfd/rk808.c
index b181fe401330..afbd7e01df50 100644
--- a/drivers/mfd/rk808.c
+++ b/drivers/mfd/rk808.c
@@ -19,6 +19,7 @@
#include <linux/module.h>
#include <linux/of_device.h>
#include <linux/regmap.h>
+#include <linux/reboot.h>
struct rk808_reg_data {
int addr;
@@ -533,6 +534,7 @@ static void rk808_pm_power_off(void)
int ret;
unsigned int reg, bit;
struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
+ dev_err(&rk808_i2c_client->dev, "poweroff device!\n");
switch (rk808->variant) {
case RK805_ID:
@@ -552,6 +554,7 @@ static void rk808_pm_power_off(void)
bit = DEV_OFF;
break;
default:
+ dev_err(&rk808_i2c_client->dev, "poweroff device not supported!\n");
return;
}
ret = regmap_update_bits(rk808->regmap, reg, bit, bit);
@@ -559,6 +562,44 @@ static void rk808_pm_power_off(void)
dev_err(&rk808_i2c_client->dev, "Failed to shutdown device!\n");
}
+static int rk808_restart_notify(struct notifier_block *this, unsigned long mode, void *cmd)
+{
+ int ret;
+ unsigned int reg, bit;
+ struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
+
+ switch (rk808->variant) {
+ case RK805_ID:
+ reg = RK805_DEV_CTRL_REG;
+ bit = DEV_OFF_RST;
+ break;
+ case RK808_ID:
+ reg = RK808_DEVCTRL_REG,
+ bit = DEV_OFF;
+ break;
+ case RK817_ID:
+ reg = RK817_SYS_CFG(3);
+ bit = DEV_RST;
+ break;
+ case RK818_ID:
+ reg = RK818_DEVCTRL_REG;
+ bit = DEV_OFF_RST;
+ break;
+ default:
+ return NOTIFY_DONE;
+ }
+ ret = regmap_update_bits(rk808->regmap, reg, bit, bit);
+ if (ret)
+ dev_err(&rk808_i2c_client->dev, "Failed to restart device!\n");
+
+ return NOTIFY_DONE;
+}
+
+static struct notifier_block rk808_restart_handler = {
+ .notifier_call = rk808_restart_notify,
+ .priority = 255,
+};
+
static void rk8xx_shutdown(struct i2c_client *client)
{
struct rk808 *rk808 = i2c_get_clientdata(client);
@@ -727,6 +768,13 @@ static int rk808_probe(struct i2c_client *client,
if (of_property_read_bool(np, "rockchip,system-power-controller")) {
rk808_i2c_client = client;
pm_power_off = rk808_pm_power_off;
+ rk808->nb = &rk808_restart_handler;
+
+ dev_warn(&client->dev, "register restart handler\n");
+
+ ret = register_restart_handler(rk808->nb);
+ if (ret)
+ dev_err(&client->dev, "failed to register restart handler, %d\n", ret);
}
return 0;
diff --git a/include/linux/mfd/rk808.h b/include/linux/mfd/rk808.h
index a96e6d43ca06..5dfe0c4ceab1 100644
--- a/include/linux/mfd/rk808.h
+++ b/include/linux/mfd/rk808.h
@@ -373,6 +373,7 @@ enum rk805_reg {
#define SWITCH2_EN BIT(6)
#define SWITCH1_EN BIT(5)
#define DEV_OFF_RST BIT(3)
+#define DEV_RST BIT(2)
#define DEV_OFF BIT(0)
#define RTC_STOP BIT(0)
@@ -701,5 +702,6 @@ struct rk808 {
long variant;
const struct regmap_config *regmap_cfg;
const struct regmap_irq_chip *regmap_irq_chip;
+ struct notifier_block *nb;
};
#endif /* __LINUX_REGULATOR_RK808_H */
--
2.25.1
next prev parent reply other threads:[~2021-12-15 21:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-15 21:32 [PATCH 0/2] Add Poweroff/Reset for rk8xx PMIC Frank Wunderlich
2021-12-15 21:32 ` Frank Wunderlich [this message]
2021-12-15 23:07 ` [PATCH 1/2] mfd: rk808: add reboot support to rk808 pmic Nicolas Frattaroli
2021-12-15 23:52 ` Peter Geis
2021-12-16 13:17 ` Robin Murphy
2021-12-16 16:36 ` Aw: " Frank Wunderlich
2021-12-17 2:21 ` Peter Geis
2021-12-15 21:33 ` [PATCH 2/2] mfd: rk808: Add poweroff and reboot support for rk809 pmic Frank Wunderlich
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=20211215213300.4778-2-linux@fw-web.de \
--to=linux@fw-web.de \
--cc=frank-w@public-files.de \
--cc=lee.jones@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=pgwipeout@gmail.com \
/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