Skip to content

Commit 8bd141b

Browse files
benjamin-bara-skidatalag-linaro
authored andcommitted
mfd: tps6586x: Use devm-based power off handler
Convert the power off handler to a devm-based power off handler. Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Signed-off-by: Benjamin Bara <benjamin.bara@skidata.com> Link: https://lore.kernel.org/r/20230327-tegra-pmic-reboot-v7-4-18699d5dcd76@skidata.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent db2d603 commit 8bd141b

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

drivers/mfd/tps6586x.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/err.h>
2323
#include <linux/i2c.h>
2424
#include <linux/platform_device.h>
25+
#include <linux/reboot.h>
2526
#include <linux/regmap.h>
2627
#include <linux/of.h>
2728

@@ -457,13 +458,21 @@ static const struct regmap_config tps6586x_regmap_config = {
457458
.cache_type = REGCACHE_RBTREE,
458459
};
459460

460-
static struct device *tps6586x_dev;
461-
static void tps6586x_power_off(void)
461+
static int tps6586x_power_off_handler(struct sys_off_data *data)
462462
{
463-
if (tps6586x_clr_bits(tps6586x_dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT))
464-
return;
463+
int ret;
464+
465+
/* Put the PMIC into sleep state. This takes at least 20ms. */
466+
ret = tps6586x_clr_bits(data->dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT);
467+
if (ret)
468+
return notifier_from_errno(ret);
469+
470+
ret = tps6586x_set_bits(data->dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT);
471+
if (ret)
472+
return notifier_from_errno(ret);
465473

466-
tps6586x_set_bits(tps6586x_dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT);
474+
mdelay(50);
475+
return notifier_from_errno(-ETIME);
467476
}
468477

469478
static void tps6586x_print_version(struct i2c_client *client, int version)
@@ -559,9 +568,13 @@ static int tps6586x_i2c_probe(struct i2c_client *client)
559568
goto err_add_devs;
560569
}
561570

562-
if (pdata->pm_off && !pm_power_off) {
563-
tps6586x_dev = &client->dev;
564-
pm_power_off = tps6586x_power_off;
571+
if (pdata->pm_off) {
572+
ret = devm_register_power_off_handler(&client->dev, &tps6586x_power_off_handler,
573+
NULL);
574+
if (ret) {
575+
dev_err(&client->dev, "register power off handler failed: %d\n", ret);
576+
goto err_add_devs;
577+
}
565578
}
566579

567580
return 0;

0 commit comments

Comments
 (0)