[PATCH v4 3/7] regulator: pm8008: Add mode voting support for PM8010

From: Jishnu Prakash

Date: Wed Nov 11 2026 - 12:17:50 EST


From: Dhruvin Rajpura <drajpura@xxxxxxxxxxxxxxxx>

Implement set_mode/get_mode/get_optimum_mode support for PM8010 LDOs
using the mode control and status registers to allow clients to vote
for LDO modes. Mode voting is supported for L1 and L2 alone of PM8010
LDOs and not supported for any of the PM8008 LDOs.

Signed-off-by: Dhruvin Rajpura <drajpura@xxxxxxxxxxxxxxxx>
Co-developed-by: Jishnu Prakash <jishnu.prakash@xxxxxxxxxxxxxxxx>
Signed-off-by: Jishnu Prakash <jishnu.prakash@xxxxxxxxxxxxxxxx>
---
drivers/regulator/qcom-pm8008-regulator.c | 102 ++++++++++++++++++++++++++++--
1 file changed, 98 insertions(+), 4 deletions(-)

diff --git a/drivers/regulator/qcom-pm8008-regulator.c b/drivers/regulator/qcom-pm8008-regulator.c
index 0ea4ac016dc2..395d5582f6af 100644
--- a/drivers/regulator/qcom-pm8008-regulator.c
+++ b/drivers/regulator/qcom-pm8008-regulator.c
@@ -24,6 +24,13 @@

#define LDO_VSET_LB_REG 0x40

+#define LDO_MODE_CTL1_REG 0x45
+#define MODE_PRIMARY_MASK GENMASK(2, 0)
+#define LDO_MODE_NPM 7
+#define LDO_MODE_LPM 4
+
+#define MODE_CHANGE_UNSUPPORTED 0
+
#define LDO_ENABLE_REG 0x46
#define ENABLE_BIT BIT(7)

@@ -31,6 +38,7 @@ struct pm8008_regulator {
struct regmap *regmap;
struct regulator_desc desc;
unsigned int base;
+ int hpm_min_load_uA;
};

struct pm8008_regulator_data {
@@ -40,6 +48,7 @@ struct pm8008_regulator_data {
int min_dropout_uV;
const struct linear_range *voltage_range;
int n_linear_ranges;
+ int hpm_min_load_uA;
};

struct pm8008_match_data {
@@ -71,8 +80,12 @@ static const struct linear_range pm8010_pldo_lv_ranges[] = {
REGULATOR_LINEAR_RANGE(3312000, 31, 31, 0),
};

-#define PM8008_REGULATOR(_name, _supply, _base, _dropout, _range) \
- { _name, _supply, _base, _dropout, _range, ARRAY_SIZE(_range) }
+#define PM8008_REGULATOR(_name, _supply, _base, _dropout, _range) \
+ { _name, _supply, _base, _dropout, _range, ARRAY_SIZE(_range), \
+ MODE_CHANGE_UNSUPPORTED }
+
+#define PM8010_REGULATOR(_name, _supply, _base, _dropout, _range, _min_load) \
+ { _name, _supply, _base, _dropout, _range, ARRAY_SIZE(_range), _min_load }

static const struct pm8008_regulator_data pm8008_reg_data[] = {
PM8008_REGULATOR("ldo1", "vdd-l1-l2", 0x4000, 225000, pm8008_nldo_ranges),
@@ -84,9 +97,10 @@ static const struct pm8008_regulator_data pm8008_reg_data[] = {
PM8008_REGULATOR("ldo7", "vdd-l7", 0x4600, 200000, pm8008_pldo_ranges),
};

+/* LPM setting is supported for only N-type LDOs of PM8010 (L1 and L2) */
static const struct pm8008_regulator_data pm8010_reg_data[] = {
- PM8008_REGULATOR("ldo1", "vdd-l1-l2", 0x4000, 172000, pm8010_nldo_ranges),
- PM8008_REGULATOR("ldo2", "vdd-l1-l2", 0x4100, 172000, pm8010_nldo_ranges),
+ PM8010_REGULATOR("ldo1", "vdd-l1-l2", 0x4000, 172000, pm8010_nldo_ranges, 100000),
+ PM8010_REGULATOR("ldo2", "vdd-l1-l2", 0x4100, 172000, pm8010_nldo_ranges, 100000),
PM8008_REGULATOR("ldo3", "vdd-l3-l4", 0x4200, 80000, pm8010_pldo_lv_ranges),
PM8008_REGULATOR("ldo4", "vdd-l3-l4", 0x4300, 80000, pm8010_pldo_lv_ranges),
PM8008_REGULATOR("ldo5", "vdd-l5", 0x4400, 296000, pm8010_pldo_ranges),
@@ -134,6 +148,69 @@ static int pm8008_regulator_get_voltage_sel(struct regulator_dev *rdev)
return regulator_map_voltage_linear_range(rdev, uV, INT_MAX);
}

+static int pm8010_regulator_set_mode(struct regulator_dev *rdev, unsigned int mode)
+{
+ struct pm8008_regulator *preg = rdev_get_drvdata(rdev);
+ unsigned int val;
+
+ switch (mode) {
+ case REGULATOR_MODE_NORMAL:
+ val = LDO_MODE_NPM;
+ break;
+ case REGULATOR_MODE_IDLE:
+ val = LDO_MODE_LPM;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return regmap_update_bits(preg->regmap, preg->base + LDO_MODE_CTL1_REG,
+ MODE_PRIMARY_MASK, val);
+}
+
+static unsigned int pm8010_regulator_get_mode(struct regulator_dev *rdev)
+{
+ struct pm8008_regulator *preg = rdev_get_drvdata(rdev);
+ unsigned int val;
+ int ret;
+
+ ret = regmap_read(preg->regmap, preg->base + LDO_MODE_CTL1_REG, &val);
+ if (ret < 0)
+ return REGULATOR_MODE_INVALID;
+
+ switch (val & MODE_PRIMARY_MASK) {
+ case LDO_MODE_NPM:
+ return REGULATOR_MODE_NORMAL;
+ case LDO_MODE_LPM:
+ return REGULATOR_MODE_IDLE;
+ default:
+ return REGULATOR_MODE_INVALID;
+ }
+}
+
+static unsigned int pm8010_regulator_get_optimum_mode(struct regulator_dev *rdev,
+ int input_uV, int output_uV,
+ int load_uA)
+{
+ struct pm8008_regulator *preg = rdev_get_drvdata(rdev);
+
+ if (load_uA >= preg->hpm_min_load_uA)
+ return REGULATOR_MODE_NORMAL;
+ else
+ return REGULATOR_MODE_IDLE;
+}
+
+static unsigned int pm8010_regulator_of_map_mode(unsigned int mode)
+{
+ switch (mode) {
+ case REGULATOR_MODE_NORMAL:
+ case REGULATOR_MODE_IDLE:
+ return mode;
+ default:
+ return REGULATOR_MODE_INVALID;
+ }
+}
+
static const struct regulator_ops pm8008_regulator_ops = {
.list_voltage = regulator_list_voltage_linear_range,
.set_voltage_sel = pm8008_regulator_set_voltage_sel,
@@ -143,6 +220,18 @@ static const struct regulator_ops pm8008_regulator_ops = {
.is_enabled = regulator_is_enabled_regmap,
};

+static const struct regulator_ops pm8010_regulator_mode_set_ops = {
+ .list_voltage = regulator_list_voltage_linear_range,
+ .set_voltage_sel = pm8008_regulator_set_voltage_sel,
+ .get_voltage_sel = pm8008_regulator_get_voltage_sel,
+ .enable = regulator_enable_regmap,
+ .disable = regulator_disable_regmap,
+ .is_enabled = regulator_is_enabled_regmap,
+ .set_mode = pm8010_regulator_set_mode,
+ .get_mode = pm8010_regulator_get_mode,
+ .get_optimum_mode = pm8010_regulator_get_optimum_mode,
+};
+
static int pm8008_regulator_probe(struct platform_device *pdev)
{
const struct pm8008_match_data *match_data;
@@ -186,6 +275,11 @@ static int pm8008_regulator_probe(struct platform_device *pdev)
desc->of_match = data->name;
desc->regulators_node = of_match_ptr("regulators");
desc->ops = &pm8008_regulator_ops;
+ if (data->hpm_min_load_uA) {
+ desc->of_map_mode = pm8010_regulator_of_map_mode;
+ preg->hpm_min_load_uA = data->hpm_min_load_uA;
+ desc->ops = &pm8010_regulator_mode_set_ops;
+ }
desc->type = REGULATOR_VOLTAGE;
desc->owner = THIS_MODULE;


--
2.43.0