@@ -21,6 +21,7 @@
#include <linux/mfd/rk808.h>
#include <linux/mfd/core.h>
#include <linux/module.h>
+#include <linux/pm.h>
#include <linux/regmap.h>
struct rk808_reg_data {
@@ -147,23 +148,16 @@ static struct regmap_irq_chip rk808_irq_chip = {
.init_ack_masked = true,
};
-static struct i2c_client *rk808_i2c_client;
-static void rk808_device_shutdown(void)
+static void rk808_device_shutdown(struct power_off_handler_block *this)
{
+ struct rk808 *rk808 = container_of(this, struct rk808, power_off_hb);
int ret;
- struct rk808 *rk808 = i2c_get_clientdata(rk808_i2c_client);
-
- if (!rk808) {
- dev_warn(&rk808_i2c_client->dev,
- "have no rk808, so do nothing here\n");
- return;
- }
ret = regmap_update_bits(rk808->regmap,
RK808_DEVCTRL_REG,
DEV_OFF_RST, DEV_OFF_RST);
if (ret)
- dev_err(&rk808_i2c_client->dev, "power off error!\n");
+ dev_err(&rk808->i2c->dev, "power off error!\n");
}
static int rk808_probe(struct i2c_client *client,
@@ -222,9 +216,14 @@ static int rk808_probe(struct i2c_client *client,
pm_off = of_property_read_bool(np,
"rockchip,system-power-controller");
- if (pm_off && !pm_power_off) {
- rk808_i2c_client = client;
- pm_power_off = rk808_device_shutdown;
+ if (pm_off) {
+ rk808->power_off_hb.handler = rk808_device_shutdown;
+ rk808->power_off_hb.priority = POWER_OFF_PRIORITY_LOW;
+ ret = devm_register_power_off_handler(&client->dev,
+ &rk808->power_off_hb);
+ if (ret)
+ dev_warn(&client->dev,
+ "Failed to register power-off handler\n");
}
return 0;
@@ -240,7 +239,6 @@ static int rk808_remove(struct i2c_client *client)
regmap_del_irq_chip(client->irq, rk808->irq_data);
mfd_remove_devices(&client->dev);
- pm_power_off = NULL;
return 0;
}
@@ -19,6 +19,7 @@
#ifndef __LINUX_REGULATOR_rk808_H
#define __LINUX_REGULATOR_rk808_H
+#include <linux/pm.h>
#include <linux/regulator/machine.h>
#include <linux/regmap.h>
@@ -192,5 +193,6 @@ struct rk808 {
struct i2c_client *i2c;
struct regmap_irq_chip_data *irq_data;
struct regmap *regmap;
+ struct power_off_handler_block power_off_hb;
};
#endif /* __LINUX_REGULATOR_rk808_H */