Skip to content

Commit

Permalink
regulator: pfuze100: Use devm_register_sys_off_handler()
Browse files Browse the repository at this point in the history
Use devm_register_sys_off_handler() that replaces global
pm_power_off_prepare variable and allows to register multiple
power-off handlers.

Acked-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Dmitry Osipenko authored and Rafael J. Wysocki committed May 19, 2022
1 parent 98f30d0 commit 02a1124
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions drivers/regulator/pfuze100-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <linux/of_device.h>
#include <linux/regulator/of_regulator.h>
#include <linux/platform_device.h>
#include <linux/reboot.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
#include <linux/regulator/pfuze100.h>
Expand Down Expand Up @@ -569,10 +570,10 @@ static inline struct device_node *match_of_node(int index)
return pfuze_matches[index].of_node;
}

static struct pfuze_chip *syspm_pfuze_chip;

static void pfuze_power_off_prepare(void)
static int pfuze_power_off_prepare(struct sys_off_data *data)
{
struct pfuze_chip *syspm_pfuze_chip = data->cb_data;

dev_info(syspm_pfuze_chip->dev, "Configure standby mode for power off");

/* Switch from default mode: APS/APS to APS/Off */
Expand Down Expand Up @@ -607,28 +608,30 @@ static void pfuze_power_off_prepare(void)
regmap_update_bits(syspm_pfuze_chip->regmap, PFUZE100_VGEN6VOL,
PFUZE100_VGENxLPWR | PFUZE100_VGENxSTBY,
PFUZE100_VGENxSTBY);

return NOTIFY_DONE;
}

static int pfuze_power_off_prepare_init(struct pfuze_chip *pfuze_chip)
{
int err;

if (pfuze_chip->chip_id != PFUZE100) {
dev_warn(pfuze_chip->dev, "Requested pm_power_off_prepare handler for not supported chip\n");
return -ENODEV;
}

if (pm_power_off_prepare) {
dev_warn(pfuze_chip->dev, "pm_power_off_prepare is already registered.\n");
return -EBUSY;
err = devm_register_sys_off_handler(pfuze_chip->dev,
SYS_OFF_MODE_POWER_OFF_PREPARE,
SYS_OFF_PRIO_DEFAULT,
pfuze_power_off_prepare,
pfuze_chip);
if (err) {
dev_err(pfuze_chip->dev, "failed to register sys-off handler: %d\n",
err);
return err;
}

if (syspm_pfuze_chip) {
dev_warn(pfuze_chip->dev, "syspm_pfuze_chip is already set.\n");
return -EBUSY;
}

syspm_pfuze_chip = pfuze_chip;
pm_power_off_prepare = pfuze_power_off_prepare;

return 0;
}

Expand Down Expand Up @@ -837,23 +840,12 @@ static int pfuze100_regulator_probe(struct i2c_client *client,
return 0;
}

static int pfuze100_regulator_remove(struct i2c_client *client)
{
if (syspm_pfuze_chip) {
syspm_pfuze_chip = NULL;
pm_power_off_prepare = NULL;
}

return 0;
}

static struct i2c_driver pfuze_driver = {
.driver = {
.name = "pfuze100-regulator",
.of_match_table = pfuze_dt_ids,
},
.probe = pfuze100_regulator_probe,
.remove = pfuze100_regulator_remove,
};
module_i2c_driver(pfuze_driver);

Expand Down

0 comments on commit 02a1124

Please sign in to comment.