diff options
author | Mark Brown <broonie@kernel.org> | 2021-06-23 18:56:31 +0300 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2021-06-23 18:56:31 +0300 |
commit | 7fb593cbd88cf4df01c096d4dc320f027dfa2560 (patch) | |
tree | 1970f6b62728d95ab52de9813bfcf66cd59a48b5 /drivers/regulator/hi6421v600-regulator.c | |
parent | ebad413c3cb04d60bb6b5f2ec4009af52a8761cb (diff) | |
parent | ddf275b219ab22bc07c14ac88c290694089dced0 (diff) | |
download | linux-7fb593cbd88cf4df01c096d4dc320f027dfa2560.tar.xz |
Merge remote-tracking branch 'regulator/for-5.14' into regulator-next
Diffstat (limited to 'drivers/regulator/hi6421v600-regulator.c')
-rw-r--r-- | drivers/regulator/hi6421v600-regulator.c | 59 |
1 files changed, 26 insertions, 33 deletions
diff --git a/drivers/regulator/hi6421v600-regulator.c b/drivers/regulator/hi6421v600-regulator.c index d6340bb49296..9b162c0555c3 100644 --- a/drivers/regulator/hi6421v600-regulator.c +++ b/drivers/regulator/hi6421v600-regulator.c @@ -16,14 +16,15 @@ #include <linux/regulator/driver.h> #include <linux/spmi.h> +struct hi6421_spmi_reg_priv { + /* Serialize regulator enable logic */ + struct mutex enable_mutex; +}; + struct hi6421_spmi_reg_info { struct regulator_desc desc; - struct hi6421_spmi_pmic *pmic; u8 eco_mode_mask; u32 eco_uA; - - /* Serialize regulator enable logic */ - struct mutex enable_mutex; }; static const unsigned int ldo3_voltages[] = { @@ -97,41 +98,31 @@ static const unsigned int ldo34_voltages[] = { static int hi6421_spmi_regulator_enable(struct regulator_dev *rdev) { - struct hi6421_spmi_reg_info *sreg = rdev_get_drvdata(rdev); - struct hi6421_spmi_pmic *pmic = sreg->pmic; + struct hi6421_spmi_reg_priv *priv; int ret; + priv = dev_get_drvdata(rdev->dev.parent); /* cannot enable more than one regulator at one time */ - mutex_lock(&sreg->enable_mutex); + mutex_lock(&priv->enable_mutex); - ret = regmap_update_bits(pmic->regmap, rdev->desc->enable_reg, + ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, rdev->desc->enable_mask, rdev->desc->enable_mask); /* Avoid powering up multiple devices at the same time */ usleep_range(rdev->desc->off_on_delay, rdev->desc->off_on_delay + 60); - mutex_unlock(&sreg->enable_mutex); + mutex_unlock(&priv->enable_mutex); return ret; } -static int hi6421_spmi_regulator_disable(struct regulator_dev *rdev) -{ - struct hi6421_spmi_reg_info *sreg = rdev_get_drvdata(rdev); - struct hi6421_spmi_pmic *pmic = sreg->pmic; - - return regmap_update_bits(pmic->regmap, rdev->desc->enable_reg, - rdev->desc->enable_mask, 0); -} - static unsigned int hi6421_spmi_regulator_get_mode(struct regulator_dev *rdev) { struct hi6421_spmi_reg_info *sreg = rdev_get_drvdata(rdev); - struct hi6421_spmi_pmic *pmic = sreg->pmic; - u32 reg_val; + unsigned int reg_val; - regmap_read(pmic->regmap, rdev->desc->enable_reg, ®_val); + regmap_read(rdev->regmap, rdev->desc->enable_reg, ®_val); if (reg_val & sreg->eco_mode_mask) return REGULATOR_MODE_IDLE; @@ -143,21 +134,23 @@ static int hi6421_spmi_regulator_set_mode(struct regulator_dev *rdev, unsigned int mode) { struct hi6421_spmi_reg_info *sreg = rdev_get_drvdata(rdev); - struct hi6421_spmi_pmic *pmic = sreg->pmic; - u32 val; + unsigned int val; switch (mode) { case REGULATOR_MODE_NORMAL: val = 0; break; case REGULATOR_MODE_IDLE: - val = sreg->eco_mode_mask << (ffs(sreg->eco_mode_mask) - 1); + if (!sreg->eco_mode_mask) + return -EINVAL; + + val = sreg->eco_mode_mask; break; default: return -EINVAL; } - return regmap_update_bits(pmic->regmap, rdev->desc->enable_reg, + return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, sreg->eco_mode_mask, val); } @@ -177,9 +170,9 @@ hi6421_spmi_regulator_get_optimum_mode(struct regulator_dev *rdev, static const struct regulator_ops hi6421_spmi_ldo_rops = { .is_enabled = regulator_is_enabled_regmap, .enable = hi6421_spmi_regulator_enable, - .disable = hi6421_spmi_regulator_disable, + .disable = regulator_disable_regmap, .list_voltage = regulator_list_voltage_table, - .map_voltage = regulator_map_voltage_iterate, + .map_voltage = regulator_map_voltage_ascend, .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = regulator_set_voltage_sel_regmap, .get_mode = hi6421_spmi_regulator_get_mode, @@ -238,7 +231,7 @@ static int hi6421_spmi_regulator_probe(struct platform_device *pdev) { struct device *pmic_dev = pdev->dev.parent; struct regulator_config config = { }; - struct hi6421_spmi_reg_info *sreg; + struct hi6421_spmi_reg_priv *priv; struct hi6421_spmi_reg_info *info; struct device *dev = &pdev->dev; struct hi6421_spmi_pmic *pmic; @@ -254,18 +247,18 @@ static int hi6421_spmi_regulator_probe(struct platform_device *pdev) if (WARN_ON(!pmic)) return -ENODEV; - sreg = devm_kzalloc(dev, sizeof(*sreg), GFP_KERNEL); - if (!sreg) + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) return -ENOMEM; - sreg->pmic = pmic; - mutex_init(&sreg->enable_mutex); + mutex_init(&priv->enable_mutex); + platform_set_drvdata(pdev, priv); for (i = 0; i < ARRAY_SIZE(regulator_info); i++) { info = ®ulator_info[i]; config.dev = pdev->dev.parent; - config.driver_data = sreg; + config.driver_data = info; config.regmap = pmic->regmap; rdev = devm_regulator_register(dev, &info->desc, &config); |