Messages in this thread Patch in this message | | | From | Benjamin Bara <> | Date | Tue, 20 Jun 2023 22:02:57 +0200 | Subject | [PATCH RFC v4 04/13] regulator: bd718x7: implement get_active_protections() |
| |
From: Benjamin Bara <benjamin.bara@skidata.com>
This is required as the mon_disable_reg_set_higher workaround property requires the ops to find out if it the monitor is set without the device-tree being aware of it.
Signed-off-by: Benjamin Bara <benjamin.bara@skidata.com> --- drivers/regulator/bd718x7-regulator.c | 74 ++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 14 deletions(-)
diff --git a/drivers/regulator/bd718x7-regulator.c b/drivers/regulator/bd718x7-regulator.c index b0b9938c20a1..fbf609d219fc 100644 --- a/drivers/regulator/bd718x7-regulator.c +++ b/drivers/regulator/bd718x7-regulator.c @@ -56,7 +56,7 @@ #define BD718XX_OPS(name, _list_voltage, _map_voltage, _set_voltage_sel, \ _get_voltage_sel, _set_voltage_time_sel, _set_ramp_delay, \ - _set_uvp, _set_ovp) \ + _set_uvp, _set_ovp, _get_prot) \ static const struct regulator_ops name = { \ .enable = regulator_enable_regmap, \ .disable = regulator_disable_regmap, \ @@ -69,6 +69,7 @@ static const struct regulator_ops name = { \ .set_ramp_delay = (_set_ramp_delay), \ .set_under_voltage_protection = (_set_uvp), \ .set_over_voltage_protection = (_set_ovp), \ + .get_active_protections = (_get_prot), \ }; \ \ static const struct regulator_ops BD718XX_HWOPNAME(name) = { \ @@ -81,6 +82,7 @@ static const struct regulator_ops BD718XX_HWOPNAME(name) = { \ .set_ramp_delay = (_set_ramp_delay), \ .set_under_voltage_protection = (_set_uvp), \ .set_over_voltage_protection = (_set_ovp), \ + .get_active_protections = (_get_prot), \ } \ /* @@ -457,6 +459,23 @@ static int bd718x7_xvp_sanity_check(struct regulator_dev *rdev, int lim_uV, return 0; } +static int bd717x7_get_ldo_prot(struct regulator_dev *rdev, unsigned int *state) +{ + int ldo_offset = rdev->desc->id - BD718XX_LDO1; + int prot_bit = BD718XX_LDO1_VRMON80 << ldo_offset; + int ret; + + ret = regmap_test_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2, prot_bit); + if (ret < 0) + return ret; + + *state = REGULATOR_MONITOR_NONE; + if (ret) + *state = REGULATOR_MONITOR_UNDER_VOLTAGE; + + return 0; +} + static int bd718x7_set_ldo_uvp(struct regulator_dev *rdev, int lim_uV, int severity, bool enable) { @@ -519,6 +538,33 @@ static int bd718x7_get_buck_uvp_info(int id, int *reg, int *bit) return 0; } +static int bd717x7_get_buck_prot(struct regulator_dev *rdev, unsigned int *state) +{ + int ret, reg, bit; + + ret = bd718x7_get_buck_uvp_info(rdev->desc->id, ®, &bit); + if (ret) + return ret; + ret = regmap_test_bits(rdev->regmap, reg, bit); + if (ret < 0) + return ret; + + *state = REGULATOR_MONITOR_NONE; + if (ret) + *state = REGULATOR_MONITOR_UNDER_VOLTAGE; + + ret = bd718x7_get_buck_ovp_info(rdev->desc->id, ®, &bit); + if (ret) + return ret; + ret = regmap_test_bits(rdev->regmap, reg, bit); + if (ret < 0) + return ret; + if (ret) + *state |= REGULATOR_MONITOR_OVER_VOLTAGE; + + return 0; +} + static int bd718x7_set_buck_uvp(struct regulator_dev *rdev, int lim_uV, int severity, bool enable) { @@ -566,7 +612,7 @@ BD718XX_OPS(bd718xx_pickable_range_ldo_ops, regulator_list_voltage_pickable_linear_range, NULL, bd718xx_set_voltage_sel_pickable_restricted, regulator_get_voltage_sel_pickable_regmap, NULL, NULL, - bd718x7_set_ldo_uvp, NULL); + bd718x7_set_ldo_uvp, NULL, bd717x7_get_ldo_prot); /* BD71847 and BD71850 LDO 5 is by default OFF at RUN state */ static const struct regulator_ops bd718xx_ldo5_ops_hwstate = { @@ -582,27 +628,27 @@ BD718XX_OPS(bd718xx_pickable_range_buck_ops, regulator_set_voltage_sel_pickable_regmap, regulator_get_voltage_sel_pickable_regmap, regulator_set_voltage_time_sel, NULL, bd718x7_set_buck_uvp, - bd718x7_set_buck_ovp); + bd718x7_set_buck_ovp, bd717x7_get_buck_prot); BD718XX_OPS(bd718xx_ldo_regulator_ops, regulator_list_voltage_linear_range, NULL, bd718xx_set_voltage_sel_restricted, regulator_get_voltage_sel_regmap, NULL, NULL, bd718x7_set_ldo_uvp, - NULL); + NULL, bd717x7_get_ldo_prot); BD718XX_OPS(bd718xx_ldo_regulator_nolinear_ops, regulator_list_voltage_table, NULL, bd718xx_set_voltage_sel_restricted, regulator_get_voltage_sel_regmap, NULL, NULL, bd718x7_set_ldo_uvp, - NULL); + NULL, bd717x7_get_ldo_prot); BD718XX_OPS(bd718xx_buck_regulator_ops, regulator_list_voltage_linear_range, NULL, regulator_set_voltage_sel_regmap, regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel, - NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp); + NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp, bd717x7_get_buck_prot); BD718XX_OPS(bd718xx_buck_regulator_nolinear_ops, regulator_list_voltage_table, regulator_map_voltage_ascend, regulator_set_voltage_sel_regmap, regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel, - NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp); + NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp, bd717x7_get_buck_prot); /* * OPS for BD71837 @@ -611,34 +657,34 @@ BD718XX_OPS(bd71837_pickable_range_ldo_ops, regulator_list_voltage_pickable_linear_range, NULL, bd71837_set_voltage_sel_pickable_restricted, regulator_get_voltage_sel_pickable_regmap, NULL, NULL, - bd718x7_set_ldo_uvp, NULL); + bd718x7_set_ldo_uvp, NULL, bd717x7_get_ldo_prot); BD718XX_OPS(bd71837_pickable_range_buck_ops, regulator_list_voltage_pickable_linear_range, NULL, bd71837_set_voltage_sel_pickable_restricted, regulator_get_voltage_sel_pickable_regmap, regulator_set_voltage_time_sel, NULL, bd718x7_set_buck_uvp, - bd718x7_set_buck_ovp); + bd718x7_set_buck_ovp, bd717x7_get_buck_prot); BD718XX_OPS(bd71837_ldo_regulator_ops, regulator_list_voltage_linear_range, NULL, rohm_regulator_set_voltage_sel_restricted, regulator_get_voltage_sel_regmap, NULL, NULL, bd718x7_set_ldo_uvp, - NULL); + NULL, bd717x7_get_ldo_prot); BD718XX_OPS(bd71837_ldo_regulator_nolinear_ops, regulator_list_voltage_table, NULL, rohm_regulator_set_voltage_sel_restricted, regulator_get_voltage_sel_regmap, NULL, NULL, bd718x7_set_ldo_uvp, - NULL); + NULL, bd717x7_get_ldo_prot); BD718XX_OPS(bd71837_buck_regulator_ops, regulator_list_voltage_linear_range, NULL, rohm_regulator_set_voltage_sel_restricted, regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel, - NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp); + NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp, bd717x7_get_buck_prot); BD718XX_OPS(bd71837_buck_regulator_nolinear_ops, regulator_list_voltage_table, regulator_map_voltage_ascend, rohm_regulator_set_voltage_sel_restricted, regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel, - NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp); + NULL, bd718x7_set_buck_uvp, bd718x7_set_buck_ovp, bd717x7_get_buck_prot); /* * BD71837 bucks 3 and 4 support defining their enable/disable state also * when buck enable state is under HW state machine control. In that case the @@ -662,7 +708,7 @@ BD718XX_OPS(bd718xx_dvs_buck_regulator_ops, regulator_list_voltage_linear_range, NULL, regulator_set_voltage_sel_regmap, regulator_get_voltage_sel_regmap, regulator_set_voltage_time_sel, regulator_set_ramp_delay_regmap, bd718x7_set_buck_uvp, - bd718x7_set_buck_ovp); + bd718x7_set_buck_ovp, bd717x7_get_buck_prot); -- 2.34.1
| |