Re: [PATCH 1/4] regulator: rk808: Fix BUCK1/2 voltages on rk805

2019-01-31 Thread Otavio Salvador
Hello Mark,

On Wed, Jan 30, 2019 at 1:40 PM Mark Brown  wrote:
> On Tue, Jan 29, 2019 at 05:54:21PM -0200, Otavio Salvador wrote:
> > RK805 has the following voltage range for the BUCK1 and BUCK2 regulators:
>
> I'm missing the other patches in this series and don't see a cover
> letter - what's the story with dependencies?

Those are just adjustments on dts files fixing the regulator handle. I
am preparing the v2 without those as they are independent.

-- 
Otavio Salvador O.S. Systems
http://www.ossystems.com.brhttp://code.ossystems.com.br
Mobile: +55 (53) 9 9981-7854  Mobile: +1 (347) 903-9750


Re: [PATCH 1/4] regulator: rk808: Fix BUCK1/2 voltages on rk805

2019-01-30 Thread Mark Brown
On Tue, Jan 29, 2019 at 05:54:21PM -0200, Otavio Salvador wrote:
> RK805 has the following voltage range for the BUCK1 and BUCK2 regulators:

I'm missing the other patches in this series and don't see a cover
letter - what's the story with dependencies?


signature.asc
Description: PGP signature


[PATCH 1/4] regulator: rk808: Fix BUCK1/2 voltages on rk805

2019-01-29 Thread Otavio Salvador
RK805 has the following voltage range for the BUCK1 and BUCK2 regulators:

>From 0.7125V to 1.45V in 12.5mV steps, 1.8V, 2V, 2.2V and 2.3V

, which corresponds to the following values as per the RK805
datasheet:

000 000: 0.7125V
000 001: 0.725V
……
111 011: 1.45V
111 100: 1.8V
111 101: 2.0V
111 110: 2.2V
111 111: 2.3V

This means that the voltage range is not linear and so RK805 can not
reuse the same regulator_ops structure from RK808.

Fix it by creating a list with the correct supported voltage values
for RK805 BUCK1 and BUCK2 regulators.

Tested on a rv1108-elgin-r1 board that now correctly reports a BUCK2
voltage of 2.2V instead of the unsupported value of 1.4875V.

Signed-off-by: Otavio Salvador 
---

 drivers/regulator/rk808-regulator.c | 53 -
 1 file changed, 45 insertions(+), 8 deletions(-)

diff --git a/drivers/regulator/rk808-regulator.c 
b/drivers/regulator/rk808-regulator.c
index 213b68743cc8..1463c65c85db 100644
--- a/drivers/regulator/rk808-regulator.c
+++ b/drivers/regulator/rk808-regulator.c
@@ -289,6 +289,21 @@ static int rk808_set_ramp_delay(struct regulator_dev 
*rdev, int ramp_delay)
  RK808_RAMP_RATE_MASK, ramp_value);
 }
 
+static int rk805_set_suspend_voltage(struct regulator_dev *rdev, int uv)
+{
+   unsigned int reg;
+   int sel = regulator_map_voltage_ascend(rdev, uv, uv);
+
+   if (sel < 0)
+   return -EINVAL;
+
+   reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
+
+   return regmap_update_bits(rdev->regmap, reg,
+ rdev->desc->vsel_mask,
+ sel);
+}
+
 static int rk808_set_suspend_voltage(struct regulator_dev *rdev, int uv)
 {
unsigned int reg;
@@ -376,6 +391,19 @@ static struct regulator_ops rk805_reg_ops = {
.set_suspend_disable= rk805_set_suspend_disable,
 };
 
+static struct regulator_ops rk805_buck1_2_ops = {
+   .list_voltage   = regulator_list_voltage_table,
+   .map_voltage= regulator_map_voltage_ascend,
+   .get_voltage_sel= regulator_get_voltage_sel_regmap,
+   .set_voltage_sel= regulator_set_voltage_sel_regmap,
+   .enable = regulator_enable_regmap,
+   .disable= regulator_disable_regmap,
+   .is_enabled = regulator_is_enabled_regmap,
+   .set_suspend_voltage= rk805_set_suspend_voltage,
+   .set_suspend_enable = rk805_set_suspend_enable,
+   .set_suspend_disable= rk805_set_suspend_disable,
+};
+
 static struct regulator_ops rk805_switch_ops = {
.enable = regulator_enable_regmap,
.disable= regulator_disable_regmap,
@@ -433,6 +461,17 @@ static struct regulator_ops rk808_switch_ops = {
.set_suspend_disable= rk808_set_suspend_disable,
 };
 
+static const int rk805_buck_1_2_voltages[] = {
+   712500, 725000, 737500, 75, 762500, 775000, 787500, 80,
+   812500, 825000, 837500, 85, 862500, 875000, 887500, 90,
+   912500, 925000, 937500, 95, 962500, 975000, 987500, 100,
+   1012500, 1025000, 1037500, 105, 1062500, 1075000, 1087500, 110,
+   1112500, 1125000, 1137500, 115, 1162500, 1175000, 1187500, 120,
+   1212500, 1225000, 1237500, 125, 1262500, 1275000, 1287500, 130,
+   1312500, 1325000, 1337500, 135, 1362500, 1375000, 1387500, 140,
+   1412500, 1425000, 1437500, 145, 180, 200, 220, 230,
+};
+
 static const struct regulator_desc rk805_reg[] = {
{
.name = "DCDC_REG1",
@@ -440,11 +479,10 @@ static const struct regulator_desc rk805_reg[] = {
.of_match = of_match_ptr("DCDC_REG1"),
.regulators_node = of_match_ptr("regulators"),
.id = RK805_ID_DCDC1,
-   .ops = _reg_ops,
+   .ops = _buck1_2_ops,
.type = REGULATOR_VOLTAGE,
-   .min_uV = 712500,
-   .uV_step = 12500,
-   .n_voltages = 64,
+   .n_voltages = ARRAY_SIZE(rk805_buck_1_2_voltages),
+   .volt_table = rk805_buck_1_2_voltages,
.vsel_reg = RK805_BUCK1_ON_VSEL_REG,
.vsel_mask = RK818_BUCK_VSEL_MASK,
.enable_reg = RK805_DCDC_EN_REG,
@@ -456,11 +494,10 @@ static const struct regulator_desc rk805_reg[] = {
.of_match = of_match_ptr("DCDC_REG2"),
.regulators_node = of_match_ptr("regulators"),
.id = RK805_ID_DCDC2,
-   .ops = _reg_ops,
+   .ops = _buck1_2_ops,
.type = REGULATOR_VOLTAGE,
-   .min_uV = 712500,
-   .uV_step = 12500,
-   .n_voltages = 64,
+   .n_voltages = ARRAY_SIZE(rk805_buck_1_2_voltages),
+