[PATCH v2 6/6] regulator: qcom-pm8008-regulator: Add support for PM8010 PMIC
From: Nihal Kumar Gupta
Date: Mon Sep 07 2026 - 04:17:40 EST
From: Jishnu Prakash <jishnu.prakash@xxxxxxxxxxxxxxxx>
The PM8010 is a variant of the PM8008 PMIC with additional LDO
regulators, a wider voltage range on some LDOs, and LPM/NPM mode
support. Add PM8010 regulator data tables and voltage ranges, and
implement set_mode()/get_mode() for switching between LPM and NPM.
Detect PM8010 via the parent I2C client's compatible string and
select the matching regulator_ops and register data accordingly.
Signed-off-by: Jishnu Prakash <jishnu.prakash@xxxxxxxxxxxxxxxx>
Signed-off-by: Dhruvin Rajpura <drajpura@xxxxxxxxxxxxxxxx>
Signed-off-by: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>
Signed-off-by: Nihal Kumar Gupta <nihal.gupta@xxxxxxxxxxxxxxxx>
---
drivers/regulator/qcom-pm8008-regulator.c | 184 ++++++++++++++++++++++++++----
1 file changed, 159 insertions(+), 25 deletions(-)
diff --git a/drivers/regulator/qcom-pm8008-regulator.c b/drivers/regulator/qcom-pm8008-regulator.c
index 9c9b8be2e15a499fa61a05cc9650338d0bbcd122..87807d5d9e8fdbbe422202156bcbf1d0e3fbc155 100644
--- a/drivers/regulator/qcom-pm8008-regulator.c
+++ b/drivers/regulator/qcom-pm8008-regulator.c
@@ -8,6 +8,7 @@
#include <linux/array_size.h>
#include <linux/bits.h>
#include <linux/device.h>
+#include <linux/i2c.h>
#include <linux/math.h>
#include <linux/module.h>
#include <linux/of.h>
@@ -24,9 +25,19 @@
#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 LDO_ENABLE_REG 0x46
#define ENABLE_BIT BIT(7)
+#define LDO_STATUS1_REG 0x08
+#define MODE_STATE_MASK GENMASK(1, 0)
+#define MODE_STATE_NPM 3
+#define MODE_STATE_LPM 2
+
struct pm8008_regulator {
struct regmap *regmap;
struct regulator_desc desc;
@@ -39,24 +50,59 @@ struct pm8008_regulator_data {
unsigned int base;
int min_dropout_uV;
const struct linear_range *voltage_range;
+ int n_linear_ranges;
+};
+
+struct pm8008_match_data {
+ const bool has_stepper_ctl_reg;
+ const struct pm8008_regulator_data *regulator_data;
+ const int num_regulators;
};
-static const struct linear_range nldo_ranges[] = {
+static const struct linear_range pm8008_nldo_ranges[] = {
REGULATOR_LINEAR_RANGE(528000, 0, 122, 8000),
};
-static const struct linear_range pldo_ranges[] = {
+static const struct linear_range pm8008_pldo_ranges[] = {
REGULATOR_LINEAR_RANGE(1504000, 0, 237, 8000),
};
+static const struct linear_range pm8010_nldo_ranges[] = {
+ REGULATOR_LINEAR_RANGE(528000, 0, 127, 8000),
+};
+
+static const struct linear_range pm8010_pldo_ranges[] = {
+ REGULATOR_LINEAR_RANGE(1504000, 0, 255, 8000),
+};
+
+static const struct linear_range pm8010_pldo_lv_ranges[] = {
+ REGULATOR_LINEAR_RANGE(1800000, 0, 2, 200000),
+ REGULATOR_LINEAR_RANGE(2608000, 3, 28, 16000),
+ REGULATOR_LINEAR_RANGE(3104000, 29, 30, 96000),
+ REGULATOR_LINEAR_RANGE(3312000, 31, 31, 0),
+};
+
+#define PM8008_REGULATOR(_name, _supply, _base, _dropout, _range) \
+ { _name, _supply, _base, _dropout, _range, ARRAY_SIZE(_range) }
+
static const struct pm8008_regulator_data pm8008_reg_data[] = {
- { "ldo1", "vdd-l1-l2", 0x4000, 225000, nldo_ranges, },
- { "ldo2", "vdd-l1-l2", 0x4100, 225000, nldo_ranges, },
- { "ldo3", "vdd-l3-l4", 0x4200, 300000, pldo_ranges, },
- { "ldo4", "vdd-l3-l4", 0x4300, 300000, pldo_ranges, },
- { "ldo5", "vdd-l5", 0x4400, 200000, pldo_ranges, },
- { "ldo6", "vdd-l6", 0x4500, 200000, pldo_ranges, },
- { "ldo7", "vdd-l7", 0x4600, 200000, pldo_ranges, },
+ PM8008_REGULATOR("ldo1", "vdd-l1-l2", 0x4000, 225000, pm8008_nldo_ranges),
+ PM8008_REGULATOR("ldo2", "vdd-l1-l2", 0x4100, 225000, pm8008_nldo_ranges),
+ PM8008_REGULATOR("ldo3", "vdd-l3-l4", 0x4200, 300000, pm8008_pldo_ranges),
+ PM8008_REGULATOR("ldo4", "vdd-l3-l4", 0x4300, 300000, pm8008_pldo_ranges),
+ PM8008_REGULATOR("ldo5", "vdd-l5", 0x4400, 200000, pm8008_pldo_ranges),
+ PM8008_REGULATOR("ldo6", "vdd-l6", 0x4500, 200000, pm8008_pldo_ranges),
+ PM8008_REGULATOR("ldo7", "vdd-l7", 0x4600, 200000, pm8008_pldo_ranges),
+};
+
+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),
+ 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),
+ PM8008_REGULATOR("ldo6", "vdd-l6", 0x4500, 80000, pm8010_pldo_lv_ranges),
+ PM8008_REGULATOR("ldo7", "vdd-l7", 0x4600, 296000, pm8010_pldo_ranges),
};
static int pm8008_regulator_set_voltage_sel(struct regulator_dev *rdev, unsigned int sel)
@@ -99,8 +145,53 @@ 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_STATUS1_REG, &val);
+ if (ret < 0)
+ return REGULATOR_MODE_INVALID;
+
+ return (val & MODE_STATE_MASK) == MODE_STATE_NPM ?
+ REGULATOR_MODE_NORMAL : 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,
+ .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,
@@ -108,8 +199,20 @@ static const struct regulator_ops pm8008_regulator_ops = {
.is_enabled = regulator_is_enabled_regmap,
};
+static const struct regulator_ops pm8010_regulator_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,
+};
+
static int pm8008_regulator_probe(struct platform_device *pdev)
{
+ const struct pm8008_match_data *match_data;
const struct pm8008_regulator_data *data;
struct regulator_config config = {};
struct device *dev = &pdev->dev;
@@ -117,15 +220,28 @@ static int pm8008_regulator_probe(struct platform_device *pdev)
struct regulator_desc *desc;
struct regulator_dev *rdev;
struct regmap *regmap;
+ const struct platform_device_id *id;
unsigned int val;
+ bool is_pm8010;
int ret, i;
+ id = platform_get_device_id(pdev);
+ if (!id)
+ return dev_err_probe(dev, -ENODEV, "Missing platform device id\n");
+
+ match_data = (const struct pm8008_match_data *)id->driver_data;
+ if (!match_data)
+ return dev_err_probe(dev, -ENODATA, "Missing driver match data\n");
+
regmap = dev_get_regmap(dev->parent, "secondary");
if (!regmap)
return -EINVAL;
- for (i = 0; i < ARRAY_SIZE(pm8008_reg_data); i++) {
- data = &pm8008_reg_data[i];
+ is_pm8010 = of_device_is_compatible(to_i2c_client(dev->parent)->dev.of_node,
+ "qcom,pm8010-i2c");
+
+ for (i = 0; i < match_data->num_regulators; i++) {
+ data = &match_data->regulator_data[i];
preg = devm_kzalloc(dev, sizeof(*preg), GFP_KERNEL);
if (!preg)
@@ -140,23 +256,28 @@ static int pm8008_regulator_probe(struct platform_device *pdev)
desc->supply_name = data->supply_name;
desc->of_match = data->name;
desc->regulators_node = of_match_ptr("regulators");
- desc->ops = &pm8008_regulator_ops;
+ desc->ops = is_pm8010 ? &pm8010_regulator_ops : &pm8008_regulator_ops;
+ if (is_pm8010)
+ desc->of_map_mode = pm8010_regulator_of_map_mode;
desc->type = REGULATOR_VOLTAGE;
desc->owner = THIS_MODULE;
desc->linear_ranges = data->voltage_range;
- desc->n_linear_ranges = 1;
- desc->uV_step = desc->linear_ranges[0].step;
- desc->min_uV = desc->linear_ranges[0].min;
- desc->n_voltages = linear_range_values_in_range(&desc->linear_ranges[0]);
-
- ret = regmap_read(regmap, preg->base + LDO_STEPPER_CTL_REG, &val);
- if (ret < 0) {
- dev_err(dev, "failed to read step rate: %d\n", ret);
- return ret;
+ desc->n_linear_ranges = data->n_linear_ranges;
+ desc->n_voltages = linear_range_values_in_range_array(desc->linear_ranges,
+ desc->n_linear_ranges);
+
+ if (match_data->has_stepper_ctl_reg) {
+ ret = regmap_read(regmap, preg->base + LDO_STEPPER_CTL_REG, &val);
+ if (ret < 0) {
+ dev_err(dev, "failed to read step rate: %d\n", ret);
+ return ret;
+ }
+ val &= STEP_RATE_MASK;
+ desc->ramp_delay = DEFAULT_VOLTAGE_STEPPER_RATE >> val;
+ } else {
+ desc->ramp_delay = DEFAULT_VOLTAGE_STEPPER_RATE;
}
- val &= STEP_RATE_MASK;
- desc->ramp_delay = DEFAULT_VOLTAGE_STEPPER_RATE >> val;
desc->min_dropout_uV = data->min_dropout_uV;
@@ -179,8 +300,21 @@ static int pm8008_regulator_probe(struct platform_device *pdev)
return 0;
}
+static const struct pm8008_match_data pm8008_data = {
+ .has_stepper_ctl_reg = true,
+ .regulator_data = pm8008_reg_data,
+ .num_regulators = ARRAY_SIZE(pm8008_reg_data),
+};
+
+static const struct pm8008_match_data pm8010_data = {
+ .has_stepper_ctl_reg = false,
+ .regulator_data = pm8010_reg_data,
+ .num_regulators = ARRAY_SIZE(pm8010_reg_data),
+};
+
static const struct platform_device_id pm8008_regulator_id_table[] = {
- { .name = "pm8008-regulator" },
+ { .name = "pm8008-regulator", .driver_data = (kernel_ulong_t)&pm8008_data },
+ { .name = "pm8010-regulator", .driver_data = (kernel_ulong_t)&pm8010_data },
{ }
};
MODULE_DEVICE_TABLE(platform, pm8008_regulator_id_table);
--
2.34.1