mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Potin Lai <potin.lai.pt@gmail.com>
Cc: Jean Delvare <jdelvare@suse.com>,
	Patrick Williams <patrick@stwcx.xyz>,
	linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
	Cosmo Chou <cosmo.chou@quantatw.com>,
	Potin Lai <potin.lai@quantatw.com>
Subject: Re: [PATCH] hwmon: ina238: Add support for shunt voltage scaling
Date: Mon, 20 Jan 2025 17:45:50 -0800	[thread overview]
Message-ID: <db04ca68-dea3-4c1d-9378-cb0316759d16@roeck-us.net> (raw)
In-Reply-To: <CAGfYmwX2fEPmLbc2rP=R10WaV_LpX-_uy+SZnJ+gYg3bnO_Yag@mail.gmail.com>

On 1/20/25 17:18, Potin Lai wrote:
> On Tue, Jan 21, 2025 at 12:38 AM Guenter Roeck <linux@roeck-us.net> 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@gmail.com>
>>
>> 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


  reply	other threads:[~2025-01-21  1:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-20 16:23 Potin Lai
2025-01-20 16:38 ` Guenter Roeck
2025-01-21  1:18   ` Potin Lai
2025-01-21  1:45     ` Guenter Roeck [this message]
2025-01-20 21:00 ` kernel test robot
2025-01-21  3:01 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=db04ca68-dea3-4c1d-9378-cb0316759d16@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=cosmo.chou@quantatw.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patrick@stwcx.xyz \
    --cc=potin.lai.pt@gmail.com \
    --cc=potin.lai@quantatw.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®