Currently we don't properly map between the regulator mode ID enum and
the appropriate register values in the mode map, as a result we always
unintentionally vote for retention mode if we actually attempt to set
it. In the set_mode path we did find the appropriate entry in the mode
map but we wrote the id instead of the register values. Clean this up
and properly map id -> mode and vice versa.

Signed-off-by: Casey Connolly <[email protected]>
---
 drivers/power/regulator/qcom-rpmh-regulator.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/power/regulator/qcom-rpmh-regulator.c 
b/drivers/power/regulator/qcom-rpmh-regulator.c
index cabdf089819d..3f0f18454698 100644
--- a/drivers/power/regulator/qcom-rpmh-regulator.c
+++ b/drivers/power/regulator/qcom-rpmh-regulator.c
@@ -368,11 +368,13 @@ static int rpmh_regulator_vrm_set_mode_bypass(struct 
rpmh_vreg *vreg,
                return -EINVAL;
        }
 
        if (bypassed)
-               cmd.data = PMIC4_BOB_MODE_PASS;
+               // XXX: should have a version check for PMIC4 but we don't have 
any yet
+               // and we don't use bypass mode
+               cmd.data = PMIC5_BOB_MODE_PASS;
        else
-               cmd.data = pmic_mode->id;
+               cmd.data = pmic_mode->register_value;
 
        return rpmh_regulator_send_request(vreg, &cmd, true);
 }
 
@@ -398,17 +400,25 @@ static int rpmh_regulator_vrm_get_pmic_mode(struct 
rpmh_vreg *vreg, int *pmic_mo
 {
        struct tcs_cmd cmd = {
                .addr = vreg->addr + RPMH_REGULATOR_REG_VRM_MODE,
        };
-       int ret;
+       struct dm_regulator_mode *pmic_mode_map = vreg->hw_data->pmic_mode_map;
+       int ret, register_value;
 
        ret = rpmh_regulator_read_data(vreg, &cmd);
        if (!ret)
-               *pmic_mode = cmd.data & RPMH_REGULATOR_MODE_MASK;
+               register_value = cmd.data & RPMH_REGULATOR_MODE_MASK;
        else
                return -EINVAL;
 
-       return 0;
+       for (int i = 0; i < vreg->hw_data->n_modes; i++) {
+               if (pmic_mode_map[i].register_value == register_value) {
+                       *pmic_mode = pmic_mode_map[i].id;
+                       return 0;
+               }
+       }
+
+       return -EINVAL;
 }
 
 static int rpmh_regulator_vrm_get_mode(struct udevice *rdev)
 {

-- 
2.51.0

Reply via email to