Message ID | 20190613212531.10452-1-jeffrey.l.hugo@gmail.com |
---|---|
State | New |
Headers | show |
Series | [v4,1/7] regulator: qcom_spmi: enable linear range info | expand |
On Thu 13 Jun 14:25 PDT 2019, Jeffrey Hugo wrote: > spmi_regulator_common_get_mode and spmi_regulator_common_set_mode use > multi-level ifs which mirror a switch statement. Refactor to use a switch > statement to make the code flow more clear. > Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org> > Signed-off-by: Jeffrey Hugo <jeffrey.l.hugo@gmail.com> > --- > drivers/regulator/qcom_spmi-regulator.c | 26 +++++++++++++++++-------- > 1 file changed, 18 insertions(+), 8 deletions(-) > > diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c > index 42c429d50743..1b3383a24c9d 100644 > --- a/drivers/regulator/qcom_spmi-regulator.c > +++ b/drivers/regulator/qcom_spmi-regulator.c > @@ -911,13 +911,16 @@ static unsigned int spmi_regulator_common_get_mode(struct regulator_dev *rdev) > > spmi_vreg_read(vreg, SPMI_COMMON_REG_MODE, ®, 1); > > - if (reg & SPMI_COMMON_MODE_HPM_MASK) > - return REGULATOR_MODE_NORMAL; > + reg &= SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK; > > - if (reg & SPMI_COMMON_MODE_AUTO_MASK) > + switch (reg) { > + case SPMI_COMMON_MODE_HPM_MASK: > + return REGULATOR_MODE_NORMAL; > + case SPMI_COMMON_MODE_AUTO_MASK: > return REGULATOR_MODE_FAST; > - > - return REGULATOR_MODE_IDLE; > + default: > + return REGULATOR_MODE_IDLE; > + } > } > > static int > @@ -925,12 +928,19 @@ spmi_regulator_common_set_mode(struct regulator_dev *rdev, unsigned int mode) > { > struct spmi_regulator *vreg = rdev_get_drvdata(rdev); > u8 mask = SPMI_COMMON_MODE_HPM_MASK | SPMI_COMMON_MODE_AUTO_MASK; > - u8 val = 0; > + u8 val; > > - if (mode == REGULATOR_MODE_NORMAL) > + switch (mode) { > + case REGULATOR_MODE_NORMAL: > val = SPMI_COMMON_MODE_HPM_MASK; > - else if (mode == REGULATOR_MODE_FAST) > + break; > + case REGULATOR_MODE_FAST: > val = SPMI_COMMON_MODE_AUTO_MASK; > + break; > + default: > + val = 0; > + break; > + } > > return spmi_vreg_update_bits(vreg, SPMI_COMMON_REG_MODE, val, mask); > } > -- > 2.17.1 >
diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c index 53a61fb65642..42c429d50743 100644 --- a/drivers/regulator/qcom_spmi-regulator.c +++ b/drivers/regulator/qcom_spmi-regulator.c @@ -1744,6 +1744,7 @@ MODULE_DEVICE_TABLE(of, qcom_spmi_regulator_match); static int qcom_spmi_regulator_probe(struct platform_device *pdev) { const struct spmi_regulator_data *reg; + const struct spmi_voltage_range *range; const struct of_device_id *match; struct regulator_config config = { }; struct regulator_dev *rdev; @@ -1833,6 +1834,12 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev) } } + if (vreg->set_points->count == 1) { + /* since there is only one range */ + range = vreg->set_points->range; + vreg->desc.uV_step = range->step_uV; + } + config.dev = dev; config.driver_data = vreg; config.regmap = regmap;