[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220830192212.28570-13-farbere@amazon.com>
Date: Tue, 30 Aug 2022 19:22:05 +0000
From: Eliav Farber <farbere@...zon.com>
To: <jdelvare@...e.com>, <linux@...ck-us.net>, <robh+dt@...nel.org>,
<p.zabel@...gutronix.de>, <rtanwar@...linear.com>,
<linux-hwmon@...r.kernel.org>, <devicetree@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
CC: <farbere@...zon.com>, <talel@...zon.com>, <hhhawa@...zon.com>,
<jonnyc@...zon.com>, <hanochu@...zon.com>, <ronenk@...zon.com>,
<itamark@...zon.com>, <shellykz@...zon.com>, <shorer@...zon.com>,
<amitlavi@...zon.com>, <almogbs@...zon.com>, <dkl@...zon.com>,
<rahul.tanwar@...ux.intel.com>, <andriy.shevchenko@...el.com>
Subject: [PATCH v3 12/19] hwmon: (mr75203) fix voltage equation for negative source input
According to Moortec Embedded Voltage Monitor (MEVM) series 3 data sheet,
the minimum input signal is -100mv and maximum input signal is +1000mv.
When n was small enough, such that PVT_N_CONST * n < PVT_R_CONST it
resulted in n overflowing to a very large number (since n is u32 type).
This change fixes the problem by casting n to long and replacing shift
right with div operation.
Signed-off-by: Eliav Farber <farbere@...zon.com>
---
V3 -> V2:
- Fix equation to support negative values instead of limiting value to
zero.
drivers/hwmon/mr75203.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/mr75203.c b/drivers/hwmon/mr75203.c
index 1cd5ff6eacce..d1f090a9baac 100644
--- a/drivers/hwmon/mr75203.c
+++ b/drivers/hwmon/mr75203.c
@@ -222,10 +222,11 @@ static int pvt_read_in(struct device *dev, u32 attr, int channel, long *val)
return ret;
n &= SAMPLE_DATA_MSK;
+
/* Convert the N bitstream count into voltage */
pre_scaler = pvt->vd[channel].pre_scaler;
- *val = pre_scaler * (PVT_N_CONST * n - PVT_R_CONST) >>
- PVT_CONV_BITS;
+ *val = pre_scaler * (PVT_N_CONST * (long)n - PVT_R_CONST) /
+ (1 << PVT_CONV_BITS);
return 0;
default:
--
2.37.1
Powered by blists - more mailing lists