regulator: mp886x: add MP8864 support
Subsystems (3)
cover regulator: mp886x: add MP8864 support
The MP8864 is a 4 A, 21 V synchronous step-down converter. Its register layout and voltage transition handling are compatible with the MP8867, but its selectable switching frequencies are 600 kHz, 850 kHz, 1.1 MHz and 1.6 MHz.
Add the compatible and chip-specific switching-frequency table.
patch1 fixes the vsel_mask
patch2 document the mp8864 dt-binding
patch3 add the mp8864 support to the driver
Jisheng Zhang (3):
regulator: mp886x: fix vsel_mask
regulator: dt-bindings: mp886x: support mp8864
regulator: mp886x: add MP8864 support
.../bindings/regulator/mps,mp886x.yaml | 16 +++++++++++-- drivers/regulator/Kconfig | 2 +- drivers/regulator/mp886x.c | 23 +++++++++++++++++-- 3 files changed, 36 insertions(+), 5 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/3 regulator: mp886x: fix vsel_mask
The MP886X vsel is 7bits, fix the vsel_mask.
--- drivers/regulator/mp886x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/regulator/mp886x.c +1 -1
@@ -267,7 +267,7 @@ static int mp886x_regulator_register(struct mp886x_device_info *di, rdesc->min_uV =600000 ; rdesc->uV_step =10000 ; rdesc->vsel_reg =MP886X_VSEL ; - rdesc->vsel_mask =0x3f ; + rdesc->vsel_mask =0x7f ; rdesc->ramp_reg =MP886X_SYSCNTLREG1 ; rdesc->ramp_mask =MP886X_SLEW_MASK ; rdesc->ramp_delay_table = di->ci->slew_rates;
Signature · 1 line
2.51.0
[email protected]
AI reviewRe: [PATCH 1/3] regulator: mp886x: fix vsel_mask
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Hardware I2C read/write errors during initialization are silently ignored, resulting in negative error codes stored in unsigned integers and corrupted state logic.
- [Medium] Potential division by zero in mp8869_scale due to unvalidated device tree properties.
--
commit e23dcb351cfbd15403625e41999e01844e07121f
Author: Jisheng Zhang <[email protected]>
regulator: mp886x: fix vsel_mask
The MP886X vsel is 7bits, fix the vsel_mask.
Quoted 10 lines
drivers/regulator/mp886x.c +1
-1@@ -267,14 +267,14 @@ static int mp886x_regulator_register(struct mp886x_device_info *di, rdesc->min_uV =600000 ; rdesc->uV_step =10000 ; rdesc->vsel_reg =MP886X_VSEL ; - rdesc->vsel_mask =0x3f ; + rdesc->vsel_mask =0x7f ;
drivers/regulator/mp886x.c static int mp886x_regulator_register(struct mp886x_device_info *di, · line 280
Quoted 10 lines
drivers/regulator/mp886x.c +0
-0rdesc->ramp_reg =MP886X_SYSCNTLREG1 ; rdesc->ramp_mask =MP886X_SLEW_MASK ; rdesc->ramp_delay_table = di->ci->slew_rates; rdesc->n_ramp_values =ARRAY_SIZE (di->ci->slew_rates); rdesc->owner =THIS_MODULE ; rdev =devm_regulator_register (di->dev, &di->desc, config);if (IS_ERR (rdev))return PTR_ERR (rdev); di->sel = rdesc->ops->get_voltage_sel (rdev);
[Severity: High]
This is a pre-existing issue, but does this code properly handle negative error codes if I2C communication fails?
If get_voltage_sel() fails and returns -EIO or another negative error code, it gets implicitly cast and stored in the unsigned int di->sel. The error is never returned to the caller.
This negative value could later cause issues in mp8867_set_voltage_sel():
drivers/regulator/mp886x.c:mp8867_set_voltage_sel() {
...
delta = di->sel - sel;
if (abs(delta) <= 5)
ret = regmap_update_bits(rdev->regmap, MP886X_SYSCNTLREG1,
MP886X_GO, 0);
...
}If di->sel holds an error code like -5 (0xFFFFFFFB), and sel is 0, delta becomes -5. Since abs(-5) <= 5 is true, the driver incorrectly writes to the register to clear MP886X_GO, masquerading an I2C error as a valid small voltage step.
Additionally, hardware initialization errors appear to be ignored elsewhere, such as in mp886x_set_switch_freq() where the return value of regmap_update_bits() is not checked. Could the driver end up succeeding in its probe even if the hardware is completely unresponsive?
[Severity: Medium]
This is also a pre-existing issue, but is there a risk of a division by zero when reading the divider values from the device tree?
In mp886x_i2c_probe(), the driver reads the mps,fb-voltage-divider array:
drivers/regulator/mp886x.c:mp886x_i2c_probe() {
...
ret = of_property_read_u32_array(np, "mps,fb-voltage-divider",
di->r, 2);
if (ret)
return ret;
...
}There does not seem to be a check ensuring that the denominator (di->r[1]) is strictly positive. If the device tree provides a zero value for this second resistor, wouldn't this cause a kernel panic when mp8869_scale() divides by r2:
drivers/regulator/mp886x.c:mp8869_scale() {
...
u32 tmp = uv * r1 / r2;
...
}Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH 2/3 regulator: dt-bindings: mp886x: support mp8864
In reply to Jisheng ZhangThe MP8864 is a 4 A, 21 V synchronous step-down converter. Its register layout and voltage transition handling are compatible with the MP8867, but its selectable switching frequencies are 600 kHz, 850 kHz, 1.1 MHz and 1.6 MHz.
Add the compatible and chip-specific switching-frequency table.
--- .../bindings/regulator/mps,mp886x.yaml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/regulator/mps,mp886x.yaml +14 -2
@@ -4,17 +4,30 @@ $id: http://devicetree.org/schemas/regulator/mps,mp886x.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Monolithic Power Systems MP8867/MP8869 voltage regulator +title: Monolithic Power Systems MP8864/MP8867/MP8869 voltage regulator maintainers: - Jisheng Zhang <[email protected]> allOf: - $ref: regulator.yaml# + - if: + properties: + compatible: + const: mps,mp8864 + then: + properties: + mps,switch-frequency-hz: + enum: [600000, 850000, 1100000, 1600000] + else: + properties: + mps,switch-frequency-hz: + enum: [500000, 750000, 1000000, 1250000, 1500000] properties: compatible: enum: + - mps,mp8864 - mps,mp8867 - mps,mp8869
@@ -33,7 +46,6 @@ properties: mps,switch-frequency-hz: description: The valid switch frequency in Hertz. - enum: [500000, 750000, 1000000, 1250000, 1500000] required: - compatible
Signature · 1 line
2.51.0
Re: [PATCH 2/3] regulator: dt-bindings: mp886x: support mp8864
pw-bot: not-applicable
PATCH 3/3 regulator: mp886x: add MP8864 support
In reply to Jisheng ZhangThe MP8864 is a 4 A, 21 V synchronous step-down converter. Its register layout and voltage transition handling are compatible with the MP8867, but its selectable switching frequencies are 600 kHz, 850 kHz, 1.1 MHz and 1.6 MHz.
Add the compatible and chip-specific switching-frequency table.
--- drivers/regulator/Kconfig | 2 +- drivers/regulator/mp886x.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-)
drivers/regulator/Kconfig +1 -1
@@ -864,7 +864,7 @@ config REGULATOR_MP8859 module. The module will be named "mp8859". config REGULATOR_MP886X - tristate "MPS MP8869 regulator driver" + tristate "MPS MP8864/MP8867/MP8869 regulator driver" depends on I2C && OF select REGMAP_I2C help
drivers/regulator/mp886x.c +20 -1
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 // -// MP8867/MP8869 regulator driver +// MP8864/MP8867/MP8869 regulator driver // // Copyright (C) 2020 Synaptics Incorporated //
@@ -229,6 +229,23 @@ static const struct regulator_ops mp8867_regulator_ops = { .set_ramp_delay = regulator_set_ramp_delay_regmap, }; +static const struct mp886x_cfg_info mp8864_ci = { + .rops = &mp8867_regulator_ops, + .slew_rates = { +64000 , +32000 , +16000 , +8000 , +4000 , +2000 , +1000 , +500 , + }, + .switch_freq = {600000 ,850000 ,1100000 ,1600000 }, + .fs_reg =MP886X_SYSCNTLREG1 , + .fs_shift =1 , +}; +static const struct mp886x_cfg_info mp8867_ci = { .rops = &mp8867_regulator_ops, .slew_rates = {
@@ -341,6 +358,7 @@ static int mp886x_i2c_probe(struct i2c_client *client) }static const struct of_device_id mp886x_dt_ids[] = { + { .compatible ="mps,mp8864" , .data = &mp8864_ci }, { .compatible ="mps,mp8867" , .data = &mp8867_ci }, { .compatible ="mps,mp8869" , .data = &mp8869_ci }, { }
@@ -348,6 +366,7 @@ static const struct of_device_id mp886x_dt_ids[] = {MODULE_DEVICE_TABLE (of, mp886x_dt_ids);static const struct i2c_device_id mp886x_id[] = { + { .name ="mp8864" , .driver_data = (kernel_ulong_t)&mp8864_ci }, { .name ="mp8867" , .driver_data = (kernel_ulong_t)&mp8867_ci }, { .name ="mp8869" , .driver_data = (kernel_ulong_t)&mp8869_ci }, { }
Signature · 1 line
2.51.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Regulator map failure for scaled feedback voltages exceeding the internal reference limit.
- [Medium] Division by zero in mp8869_scale if mps,fb-voltage-divider provides 0 for the second resistor value. --
commit 11c9edb9604a047f4176e93b2eddadc949a9e73b
Author: Jisheng Zhang <[email protected]>
regulator: mp886x: add MP8864 support
This commit adds support for the MP8864 synchronous step-down converter to the mp886x regulator driver. It updates the Kconfig description and adds a new device tree compatible and specific switching-frequency table.
Quoted 4 lines
drivers/regulator/mp886x.c +0
-0
[ ... ]
drivers/regulator/mp886x.c static const struct regulator_ops mp8867_regulator_ops = { · line 233
Quoted 6 lines
drivers/regulator/mp886x.c +2
-0@@ -229,6 +229,23 @@ static const struct regulator_ops mp8867_regulator_ops = { .set_ramp_delay = regulator_set_ramp_delay_regmap, }; +static const struct mp886x_cfg_info mp8864_ci = { + .rops = &mp8867_regulator_ops,
[Severity: High]
This is a pre-existing issue, but by using mp8867_regulator_ops, does the MP8864 inherit a potential initialization failure for typical step-down output voltages?
In drivers/regulator/mp886x.c:mp8867_get_voltage_sel(), when fbloop is true, the driver scales up the internal reference voltage and attempts to map it:
uv = mp8869_scale(uv, di->r[0], di->r[1]); return regulator_map_voltage_linear(rdev, uv, uv);
However, since rdev->desc->min_uV (0.6V) and rdev->desc->uV_step (10mV) are hardcoded for the unscaled internal reference, the maximum mappable voltage appears capped at 1.87V. If the scaled voltage is above 1.87V, does regulator_map_voltage_linear() return -EINVAL and prevent the regulator from syncing its state?
Quoted 15 lines
drivers/regulator/mp886x.c +15
-0+ .slew_rates = { +64000 , +32000 , +16000 , +8000 , +4000 , +2000 , +1000 , + 500, + }, + .switch_freq = { 600000, 850000, 1100000, 1600000 }, + .fs_reg = MP886X_SYSCNTLREG1, + .fs_shift = 1, +}; +
[ ... ]
drivers/regulator/mp886x.c static int mp886x_i2c_probe(struct i2c_client *client) · line 361
Quoted 5 lines
drivers/regulator/mp886x.c +1
-0@@ -341,6 +358,7 @@ static int mp886x_i2c_probe(struct i2c_client *client) }static const struct of_device_id mp886x_dt_ids[] = { + { .compatible ="mps,mp8864" , .data = &mp8864_ci },
[Severity: Medium]
This is a pre-existing issue, but if the device tree for an MP8864 device includes the "mps,fb-voltage-divider" property with a 0 value for the second resistor, could this cause a division by zero during boot?
In drivers/regulator/mp886x.c:mp886x_i2c_probe(), the resistor values are read without validation:
ret = of_property_read_u32_array(np, "mps,fb-voltage-divider", di->r, 2);
If the initial voltage selector is queried, mp8869_scale() uses di->r[1] as a divisor:
u32 tmp = uv * r1 / r2;
Quoted 3 lines
drivers/regulator/mp886x.c +0
-0{ .compatible = "mps,mp8867", .data = &mp8867_ci }, { .compatible = "mps,mp8869", .data = &mp8869_ci }, { }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Mark Brown
maintainerQuoted 8 lines · Jisheng Zhang
regulator: mp886x: add MP8864 support
The MP8864 is a 4 A, 21 V synchronous step-down converter. Its register layout and voltage transition handling are compatible with the MP8867, but its selectable switching frequencies are 600 kHz, 850 kHz, 1.1 MHz and 1.6 MHz.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-7.4
Thanks!
[1/3] regulator: mp886x: fix vsel_mask
https://git.kernel.org/broonie/regulator/c/24fa0eadc2e3 [2/3] regulator: dt-bindings: mp886x: support mp8864 https://git.kernel.org/broonie/regulator/c/c75d4f104f81 [3/3] regulator: mp886x: add MP8864 support https://git.kernel.org/broonie/regulator/c/6c45fd3e1854
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark