diff mbox series

[v2,10/16] hwmon: (mr75203) add VM pre-scalar support

Message ID 20220817054321.6519-11-farbere@amazon.com (mailing list archive)
State Changes Requested
Headers show
Series Variety of fixes and new features for mr75203 driver | expand

Commit Message

Farber, Eliav Aug. 17, 2022, 5:43 a.m. UTC
Add pre-scalar support to normalzie the voltage output results for
channels the use pre-scalar units to get the measurement to be within
the range that the sensor supports.
The pre-scalar value is used if it exists in device-tree, otherwise
default value of 1 is used.

Signed-off-by: Eliav Farber <farbere@amazon.com>
---
 drivers/hwmon/mr75203.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c
index 2e6139c09efc..24a00339cfd8 100644
--- a/drivers/hwmon/mr75203.c
+++ b/drivers/hwmon/mr75203.c
@@ -112,8 +112,12 @@ 
 struct voltage_device {
 	u8 vm_map;
 	u8 ch_map;
+	u32 pre_scaler;
 };
 
+#define PRE_SCALR_PROPERTY_NAME	32
+#define PRE_SCALR_DEFAULT_VAL	1
+
 struct pvt_device {
 	struct regmap		*c_map;
 	struct regmap		*t_map;
@@ -215,7 +219,9 @@  static int pvt_read_in(struct device *dev, u32 attr, int channel, long *val)
 
 		n &= SAMPLE_DATA_MSK;
 		/* Convert the N bitstream count into voltage */
-		*val = (PVT_N_CONST * n - PVT_R_CONST) >> PVT_CONV_BITS;
+		*val = pvt->vd[channel].pre_scaler;
+		*val *= (PVT_N_CONST * n - PVT_R_CONST);
+		*val >>= PVT_CONV_BITS;
 
 		return 0;
 	default:
@@ -527,6 +533,7 @@  static int pvt_reset_control_deassert(struct device *dev, struct pvt_device *pvt
 static int mr75203_probe(struct platform_device *pdev)
 {
 	const struct hwmon_channel_info **pvt_info;
+	const struct device_node *np = pdev->dev.of_node;
 	u32 ts_num, vm_num, pd_num, ch_num, val, index, i, j, k;
 	struct device *dev = &pdev->dev;
 	u32 *temp_config, *in_config;
@@ -552,7 +559,7 @@  static int mr75203_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	if (of_property_read_bool(dev->of_node, "reset-control-skip")) {
+	if (of_property_read_bool(np, "reset-control-skip")) {
 		dev_info(dev, "skipping reset-control\n");
 	} else {
 		pvt->rst = devm_reset_control_get_exclusive(dev, NULL);
@@ -615,6 +622,8 @@  static int mr75203_probe(struct platform_device *pdev)
 	if (vm_num) {
 		u8 vm_idx[VM_NUM_MAX];
 		u8 vm_active_ch[VM_NUM_MAX];
+		char prop_name[PRE_SCALR_PROPERTY_NAME] = {0};
+		u32 pre_scaler;
 
 		ret = pvt_get_regmap(pdev, "vm", pvt);
 		if (ret)
@@ -686,6 +695,21 @@  static int mr75203_probe(struct platform_device *pdev)
 				k++;
 			}
 
+		/*
+		 * Incase vm-pre-scalar-ch# property is not defined, we assume
+		 * default pre-scaler of 1.
+		 */
+		for (i = 0; i < pvt->vm_ch_total; i++) {
+			snprintf(prop_name, sizeof(prop_name),
+				 "vm-pre-scalar-ch%u", i);
+
+			ret = of_property_read_u32(np, prop_name, &pre_scaler);
+			if (ret)
+				pvt->vd[i].pre_scaler = PRE_SCALR_DEFAULT_VAL;
+			else
+				pvt->vd[i].pre_scaler = pre_scaler;
+		}
+
 		in_config = devm_kcalloc(dev, pvt->vm_ch_total + 1,
 					 sizeof(*in_config), GFP_KERNEL);
 		if (!in_config)