Re: [PATCH] hwmon: ina238: Add support for shunt voltage scaling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 1/20/25 17:18, Potin Lai wrote:
On Tue, Jan 21, 2025 at 12:38 AM Guenter Roeck <linux@xxxxxxxxxxxx> wrote:

On 1/20/25 08:23, Potin Lai wrote:
The INA238 sensor reports shunt voltage with microvolt precision.
However, the hwmon driver currently exposes this value only in
millivolts via `in0_input`, which results in a loss of precision for
readings within the range of ±1 mV.

This patch introduces an `in0_scale` attribute to provide the scaling
factor applied to the shunt voltage reading. By exposing this attribute,
users can accurately interpret the in0_input values in microvolts,
preserving the sensor's full precision.

Signed-off-by: Potin Lai <potin.lai.pt@xxxxxxxxx>

Sorry, this is an ABI violation and thus a no-go. in0_input is and will
always be reported in mV.

Guenter


Hi Guenter,
In our use case, the shunt voltage is less than 1 mv most of the time.
I would like to get your advice on the correct way of getting
microvolt reading from the driver? Thank you.


Given that V = I * R, assuming you know the shunt resistor value,
it is an easy calculation which does not require any code changes.

Possible alternatives:
- Create a debugfs file to display the voltage in uV.
  See drivers/hwmon/isl28022.c for an example.
- Implement a hwmon -> iio bridge and use IIO to report
  the voltage.

Having said that, do you have an actual use case ? What is the point
of knowing the voltage across the shunt resistor ? "Because the chip
reports it" is not a use case. Literally _every_ current sensor chip
ultimately reports the shunt resistor voltage, after all (typically
as current; calculation see above). Commit 63fb21afc1f5 ("hwmon:
(ina2xx) Use shunt voltage to calculate current") is a case in point.

Guenter





[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux