Skip to content

Commit 9b20aec

Browse files
linchuyuangroeck
authored andcommitted
hwmon: (pmbus/max20730) adjust the vout reading given voltage divider
Problem: We use voltage dividers so that the voltage presented at the voltage sense pins is confusing. We might need to convert these readings to more meaningful readings given the voltage divider. Solution: Read the voltage divider resistance from dts and convert the voltage reading to a more meaningful reading. Testing: max20730 with voltage divider Signed-off-by: Chu Lin <linchuyuan@google.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/r/20201004031445.2321090-3-linchuyuan@google.com [groeck: Return -EINVAL instead of -ENODEV on bad deevicetree data] Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent b9a9a37 commit 9b20aec

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

drivers/hwmon/pmbus/max20730.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct max20730_data {
5353
u16 mfr_devset1;
5454
u16 mfr_devset2;
5555
u16 mfr_voutmin;
56+
u32 vout_voltage_divider[2];
5657
};
5758

5859
#define to_max20730_data(x) container_of(x, struct max20730_data, info)
@@ -468,6 +469,14 @@ static int max20730_read_word_data(struct i2c_client *client, int page,
468469
max_c = max_current[data->id][(data->mfr_devset1 >> 5) & 0x3];
469470
ret = val_to_direct(max_c, PSC_CURRENT_OUT, info);
470471
break;
472+
case PMBUS_READ_VOUT:
473+
ret = pmbus_read_word_data(client, page, phase, reg);
474+
if (ret > 0 && data->vout_voltage_divider[0] && data->vout_voltage_divider[1]) {
475+
u64 temp = DIV_ROUND_CLOSEST_ULL((u64)ret * data->vout_voltage_divider[1],
476+
data->vout_voltage_divider[0]);
477+
ret = clamp_val(temp, 0, 0xffff);
478+
}
479+
break;
471480
default:
472481
ret = -ENODATA;
473482
break;
@@ -717,6 +726,15 @@ static int max20730_probe(struct i2c_client *client)
717726
data->id = chip_id;
718727
mutex_init(&data->lock);
719728
memcpy(&data->info, &max20730_info[chip_id], sizeof(data->info));
729+
if (of_property_read_u32_array(client->dev.of_node, "vout-voltage-divider",
730+
data->vout_voltage_divider,
731+
ARRAY_SIZE(data->vout_voltage_divider)) != 0)
732+
memset(data->vout_voltage_divider, 0, sizeof(data->vout_voltage_divider));
733+
if (data->vout_voltage_divider[1] < data->vout_voltage_divider[0]) {
734+
dev_err(dev,
735+
"The total resistance of voltage divider is less than output resistance\n");
736+
return -EINVAL;
737+
}
720738

721739
ret = i2c_smbus_read_word_data(client, MAX20730_MFR_DEVSET1);
722740
if (ret < 0)

0 commit comments

Comments
 (0)