[PATCH 4/5] hwmon: pmbus: mpq8785: Implement voltage scale loop configuration

Pawel Dembicki posted 5 patches 9 months, 2 weeks ago
[PATCH 4/5] hwmon: pmbus: mpq8785: Implement voltage scale loop configuration
Posted by Pawel Dembicki 9 months, 2 weeks ago
Implement support for setting the VOUT_SCALE_LOOP PMBus register
based on an optional device tree property "voltage-scale-loop".

This allows the driver to provide the correct VOUT value depending
on the feedback voltage divider configuration for chips where the
bootloader does not configure the voltage scale.

Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
---
 drivers/hwmon/pmbus/mpq8785.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/hwmon/pmbus/mpq8785.c b/drivers/hwmon/pmbus/mpq8785.c
index e6a643856f08..6e2325d7f37b 100644
--- a/drivers/hwmon/pmbus/mpq8785.c
+++ b/drivers/hwmon/pmbus/mpq8785.c
@@ -78,6 +78,8 @@ static int mpq8785_probe(struct i2c_client *client)
 	struct device *dev = &client->dev;
 	struct pmbus_driver_info *info;
 	enum chips chip_id;
+	u32 voltage_scale;
+	int ret;
 
 	info = devm_kmemdup(dev, &mpq8785_info, sizeof(*info), GFP_KERNEL);
 	if (!info)
@@ -105,6 +107,14 @@ static int mpq8785_probe(struct i2c_client *client)
 		return -ENODEV;
 	}
 
+	if (!of_property_read_u32(dev->of_node, "voltage-scale-loop",
+				  &voltage_scale)) {
+		ret = i2c_smbus_write_word_data(client, PMBUS_VOUT_SCALE_LOOP,
+						voltage_scale);
+		if (ret)
+			return ret;
+	}
+
 	return pmbus_do_probe(client, info);
 };
 
-- 
2.43.0
Re: [PATCH 4/5] hwmon: pmbus: mpq8785: Implement voltage scale loop configuration
Posted by Guenter Roeck 9 months, 2 weeks ago
On 4/28/25 15:13, Pawel Dembicki wrote:
> Implement support for setting the VOUT_SCALE_LOOP PMBus register
> based on an optional device tree property "voltage-scale-loop".
> 
> This allows the driver to provide the correct VOUT value depending
> on the feedback voltage divider configuration for chips where the
> bootloader does not configure the voltage scale.
> 
> Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com>
> ---
>   drivers/hwmon/pmbus/mpq8785.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/hwmon/pmbus/mpq8785.c b/drivers/hwmon/pmbus/mpq8785.c
> index e6a643856f08..6e2325d7f37b 100644
> --- a/drivers/hwmon/pmbus/mpq8785.c
> +++ b/drivers/hwmon/pmbus/mpq8785.c
> @@ -78,6 +78,8 @@ static int mpq8785_probe(struct i2c_client *client)
>   	struct device *dev = &client->dev;
>   	struct pmbus_driver_info *info;
>   	enum chips chip_id;
> +	u32 voltage_scale;
> +	int ret;
>   
>   	info = devm_kmemdup(dev, &mpq8785_info, sizeof(*info), GFP_KERNEL);
>   	if (!info)
> @@ -105,6 +107,14 @@ static int mpq8785_probe(struct i2c_client *client)
>   		return -ENODEV;
>   	}
>   
> +	if (!of_property_read_u32(dev->of_node, "voltage-scale-loop",
> +				  &voltage_scale)) {
> +		ret = i2c_smbus_write_word_data(client, PMBUS_VOUT_SCALE_LOOP,
> +						voltage_scale);

Per PMBus specification this value can be in any supported scale.
Also, the chips do not support the full 16-bit value range. I see 10 bit for
mpq8785 and mpm3695, 7 bit for mp2853, and 12 bit for MPM82504. There will
have to be some device specific range check.

I don't understand the units. The devicetree document talks about
VOUT_SCALE_LOOP = VFB / VOUT * 1000, but I don't see how that translates
into chip values. For MPM82504, the datasheet says 1 LSB=2mV. For mpm3695
it is 0.001/LSB. I have no idea how that is supposed to translate to the
units suggested in the property patch.

Either case, I think the property needs to be something generic that is well
defined. Maybe "pmbus,voltage-scale-loop", but I really don't know what would
be acceptable for DT maintainers.

Guenter