diff options
author | Axel Lin <axel.lin@ingics.com> | 2021-05-23 15:23:20 +0800 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2021-06-03 14:04:51 +0100 |
commit | 8cdded982a6cf95d5ed7e3a014fb3d8dde6b3a94 (patch) | |
tree | 462b4332e46b1aa5ae92d7a1777e6286dfa9b754 | |
parent | 8f4ef0788c68bf99370a91df5cb83f90d707583e (diff) |
regulator: max77802: Convert to use regulator_set_ramp_delay_regmap
Use regulator_set_ramp_delay_regmap instead of open-coded.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Link: https://lore.kernel.org/r/20210523072320.2174443-2-axel.lin@ingics.com
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/regulator/max77802-regulator.c | 69 |
1 files changed, 12 insertions, 57 deletions
diff --git a/drivers/regulator/max77802-regulator.c b/drivers/regulator/max77802-regulator.c index 903c6fc10efb..21e0eb0f43f9 100644 --- a/drivers/regulator/max77802-regulator.c +++ b/drivers/regulator/max77802-regulator.c @@ -43,15 +43,14 @@ #define MAX77802_OFF_PWRREQ 0x1 #define MAX77802_LP_PWRREQ 0x2 -/* MAX77802 has two register formats: 2-bit and 4-bit */ -static const unsigned int ramp_table_77802_2bit[] = { +static const unsigned int max77802_buck234_ramp_table[] = { 12500, 25000, 50000, 100000, }; -static unsigned int ramp_table_77802_4bit[] = { +static const unsigned int max77802_buck16_ramp_table[] = { 1000, 2000, 3030, 4000, 5000, 5880, 7140, 8330, 9090, 10000, 11110, 12500, @@ -221,58 +220,6 @@ static int max77802_enable(struct regulator_dev *rdev) max77802->opmode[id] << shift); } -static int max77802_find_ramp_value(struct regulator_dev *rdev, - const unsigned int limits[], int size, - unsigned int ramp_delay) -{ - int i; - - for (i = 0; i < size; i++) { - if (ramp_delay <= limits[i]) - return i; - } - - /* Use maximum value for no ramp control */ - dev_warn(&rdev->dev, "%s: ramp_delay: %d not supported, setting 100000\n", - rdev->desc->name, ramp_delay); - return size - 1; -} - -/* Used for BUCKs 2-4 */ -static int max77802_set_ramp_delay_2bit(struct regulator_dev *rdev, - int ramp_delay) -{ - int id = rdev_get_id(rdev); - unsigned int ramp_value; - - if (id > MAX77802_BUCK4) { - dev_warn(&rdev->dev, - "%s: regulator: ramp delay not supported\n", - rdev->desc->name); - return -EINVAL; - } - ramp_value = max77802_find_ramp_value(rdev, ramp_table_77802_2bit, - ARRAY_SIZE(ramp_table_77802_2bit), ramp_delay); - - return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, - MAX77802_RAMP_RATE_MASK_2BIT, - ramp_value << MAX77802_RAMP_RATE_SHIFT_2BIT); -} - -/* For BUCK1, 6 */ -static int max77802_set_ramp_delay_4bit(struct regulator_dev *rdev, - int ramp_delay) -{ - unsigned int ramp_value; - - ramp_value = max77802_find_ramp_value(rdev, ramp_table_77802_4bit, - ARRAY_SIZE(ramp_table_77802_4bit), ramp_delay); - - return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, - MAX77802_RAMP_RATE_MASK_4BIT, - ramp_value << MAX77802_RAMP_RATE_SHIFT_4BIT); -} - /* * LDOs 2, 4-19, 22-35 */ @@ -316,7 +263,7 @@ static const struct regulator_ops max77802_buck_16_dvs_ops = { .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = regulator_set_voltage_sel_regmap, .set_voltage_time_sel = regulator_set_voltage_time_sel, - .set_ramp_delay = max77802_set_ramp_delay_4bit, + .set_ramp_delay = regulator_set_ramp_delay_regmap, .set_suspend_disable = max77802_set_suspend_disable, }; @@ -330,7 +277,7 @@ static const struct regulator_ops max77802_buck_234_ops = { .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = regulator_set_voltage_sel_regmap, .set_voltage_time_sel = regulator_set_voltage_time_sel, - .set_ramp_delay = max77802_set_ramp_delay_2bit, + .set_ramp_delay = regulator_set_ramp_delay_regmap, .set_suspend_disable = max77802_set_suspend_disable, .set_suspend_mode = max77802_set_suspend_mode, }; @@ -408,6 +355,10 @@ static const struct regulator_ops max77802_buck_dvs_ops = { .vsel_mask = MAX77802_DVS_VSEL_MASK, \ .enable_reg = MAX77802_REG_BUCK ## num ## CTRL, \ .enable_mask = MAX77802_OPMODE_MASK, \ + .ramp_reg = MAX77802_REG_BUCK ## num ## CTRL, \ + .ramp_mask = MAX77802_RAMP_RATE_MASK_4BIT, \ + .ramp_delay_table = max77802_buck16_ramp_table, \ + .n_ramp_values = ARRAY_SIZE(max77802_buck16_ramp_table), \ .of_map_mode = max77802_map_mode, \ } @@ -430,6 +381,10 @@ static const struct regulator_ops max77802_buck_dvs_ops = { .enable_reg = MAX77802_REG_BUCK ## num ## CTRL1, \ .enable_mask = MAX77802_OPMODE_MASK << \ MAX77802_OPMODE_BUCK234_SHIFT, \ + .ramp_reg = MAX77802_REG_BUCK ## num ## CTRL1, \ + .ramp_mask = MAX77802_RAMP_RATE_MASK_2BIT, \ + .ramp_delay_table = max77802_buck234_ramp_table, \ + .n_ramp_values = ARRAY_SIZE(max77802_buck234_ramp_table), \ .of_map_mode = max77802_map_mode, \ } |