From: Benjamin Bara <benjamin.bara@xxxxxxxxxxx> The PCA9450 supports both, a warm and a cold reset. Implement both and register the respective handlers. Acked-by: Mark Brown <broonie@xxxxxxxxxx> Signed-off-by: Benjamin Bara <benjamin.bara@xxxxxxxxxxx> --- drivers/regulator/pca9450-regulator.c | 59 +++++++++++++++++++++++++++++++++++ include/linux/regulator/pca9450.h | 7 +++++ 2 files changed, 66 insertions(+) diff --git a/drivers/regulator/pca9450-regulator.c b/drivers/regulator/pca9450-regulator.c index 2ab365d2749f..86903d677bf6 100644 --- a/drivers/regulator/pca9450-regulator.c +++ b/drivers/regulator/pca9450-regulator.c @@ -38,6 +38,11 @@ struct pca9450 { int irq; }; +static inline struct pca9450 *dev_to_pca9450(struct device *dev) +{ + return dev_get_drvdata(dev); +} + static const struct regmap_range pca9450_status_range = { .range_min = PCA9450_REG_INT1, .range_max = PCA9450_REG_PWRON_STAT, @@ -219,6 +224,42 @@ static int pca9450_set_dvs_levels(struct device_node *np, return ret; } +static int pca9450_cold_reset(struct pca9450 *pca9450) +{ + int ret; + + ret = regmap_write(pca9450->regmap, PCA9450_REG_SWRST, + SWRST_RESET_COLD_LDO12); + if (ret) + return ret; + + /* t_RESTART is 250 ms. */ + mdelay(500); + return -ETIME; +} + +static int pca9450_warm_reset(struct pca9450 *pca9450) +{ + int ret; + + ret = regmap_write(pca9450->regmap, PCA9450_REG_SWRST, + SWRST_RESET_WARM); + if (ret) + return ret; + + /* t_RESET is 20 ms. */ + mdelay(50); + return -ETIME; +} + +static int pca9450_restart_handler(struct sys_off_data *data) +{ + int (*handler)(struct pca9450 *) = data->cb_data; + struct pca9450 *pca9450 = dev_to_pca9450(data->dev); + + return handler(pca9450); +} + static const struct pca9450_regulator_desc pca9450a_regulators[] = { { .desc = { @@ -845,6 +886,24 @@ static int pca9450_i2c_probe(struct i2c_client *i2c) return PTR_ERR(pca9450->sd_vsel_gpio); } + ret = devm_register_cold_restart_handler(pca9450->dev, + pca9450_restart_handler, + pca9450_cold_reset); + if (ret) { + dev_err(&i2c->dev, "register cold restart handler failed: %d\n", + ret); + return ret; + } + + ret = devm_register_warm_restart_handler(pca9450->dev, + pca9450_restart_handler, + pca9450_warm_reset); + if (ret) { + dev_err(&i2c->dev, "register warm restart handler failed: %d\n", + ret); + return ret; + } + dev_info(&i2c->dev, "%s probed.\n", type == PCA9450_TYPE_PCA9450A ? "pca9450a" : "pca9450bc"); diff --git a/include/linux/regulator/pca9450.h b/include/linux/regulator/pca9450.h index 505c908dbb81..a72fd4942d5f 100644 --- a/include/linux/regulator/pca9450.h +++ b/include/linux/regulator/pca9450.h @@ -93,6 +93,13 @@ enum { PCA9450_MAX_REGISTER = 0x2F, }; +/* PCA9450 SW_RST bits */ +#define SWRST_NOACTION 0x00 +#define SWRST_RESET_REGS 0x05 +#define SWRST_RESET_COLD_LDO12 0x14 +#define SWRST_RESET_WARM 0x35 +#define SWRST_RESET_COLD 0x64 + /* PCA9450 BUCK ENMODE bits */ #define BUCK_ENMODE_OFF 0x00 #define BUCK_ENMODE_ONREQ 0x01 -- 2.34.1