#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>
+#include <linux/reboot.h>
#include <linux/regmap.h>
#include <linux/slab.h>
-static struct max77620_chip *max77620_scratch;
-
static const struct resource gpio_resources[] = {
DEFINE_RES_IRQ(MAX77620_IRQ_TOP_GPIO),
};
return ret;
}
-static void max77620_pm_power_off(void)
+static int max77620_pm_power_off(struct sys_off_data *data)
{
- struct max77620_chip *chip = max77620_scratch;
+ struct max77620_chip *chip = data->cb_data;
regmap_update_bits(chip->rmap, MAX77620_REG_ONOFFCNFG1,
MAX77620_ONOFFCNFG1_SFT_RST,
MAX77620_ONOFFCNFG1_SFT_RST);
+
+ return NOTIFY_DONE;
}
static int max77620_probe(struct i2c_client *client)
struct regmap_irq_chip *chip_desc;
const struct mfd_cell *mfd_cells;
int n_mfd_cells;
- bool pm_off;
int ret;
chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
return ret;
}
- pm_off = of_device_is_system_power_controller(client->dev.of_node);
- if (pm_off && !pm_power_off) {
- max77620_scratch = chip;
- pm_power_off = max77620_pm_power_off;
+ if (of_device_is_system_power_controller(client->dev.of_node)) {
+ ret = devm_register_sys_off_handler(&client->dev,
+ SYS_OFF_MODE_POWER_OFF,
+ SYS_OFF_PRIO_DEFAULT,
+ max77620_pm_power_off, chip);
+ if (ret)
+ return dev_err_probe(&client->dev, ret,
+ "failed to register power-off handler\n");
}
return 0;