From: Guenter Roeck <linux@roeck-us.net>
To: Jared Kangas <jkangas@redhat.com>
Cc: Tzung-Bi Shih <tzungbi@kernel.org>,
Lothar Felten <lothar.felten@gmail.com>,
linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 4/4] hwmon: (ina2xx) Decouple in0 and curr1 alarms
Date: Fri, 21 Aug 2026 12:48:22 -0700 [thread overview]
Message-ID: <b60db310-a747-472c-b85c-808951b347a4@roeck-us.net> (raw)
In-Reply-To: <20260820-upstream-ina2xx-in0-curr1-alarms-v2-4-fdce35abc41e@redhat.com>
On Thu, Aug 20, 2026 at 06:09:24AM -0700, Jared Kangas wrote:
> INA2XX current limits are converted into shunt voltage limits internally
> using the shunt resistor value. Once a current limit's corresponding
> voltage limit is written to the hardware, shunt voltage and current
> alarms are indistinguishable from each other.
>
> This causes two issues:
>
> 1. in0/curr1 alarms may be unintentionally cleared by reading from the
> opposite input's alarm.
>
> 2. When a limit for either in0 (shunt voltage) or curr1 (current) is
> set, both of their alarms are triggered, and both of their limits
> read nonzero.
>
> An example of this behavior on an INA231:
>
> # cd /sys/class/hwmon/hwmon0
> # head {curr1,in0}_input
> ==> curr1_input <==
> 1713
>
> ==> in0_input <==
> 2
> # echo 1800 >curr1_lcrit
> # head {curr1,in0}_lcrit_alarm
> ==> curr1_lcrit_alarm <==
> 1
>
> ==> in0_lcrit_alarm <==
> 0
> # head {in0,curr1}_lcrit_alarm
> ==> in0_lcrit_alarm <==
> 1
>
> ==> curr1_lcrit_alarm <==
> 0
> # head {in0,curr1}_lcrit_alarm
> ==> in0_lcrit_alarm <==
> 1
>
> ==> curr1_lcrit_alarm <==
> 1
>
> This is because curr1 uses the same underlying masks
> (INA226_SHUNT_*_VOLTAGE_MASK) as in0 on the hardware. As a result,
> ina2xx_{curr,in}_read() both read the shunt voltage alarms/limits
> without considering whether the voltage or current is currently set.
>
> To fix this, track the active alarm type in ina2xx_data and guard
> alarm/limit reads with a check that returns zero if the active alarm is
> for a different type. The new field is initialized based on the
> MASK_ENABLE register's set function, assuming voltage instead of current
> when the shunt voltage mask is set.
>
> After this fix, the alarms only read back 1 if their corresponding limit
> is set:
>
> # echo 0 >curr1_lcrit
> # head {curr1,in0}_lcrit_alarm
> ==> curr1_lcrit_alarm <==
> 0
>
> ==> in0_lcrit_alarm <==
> 0
> # echo 9999 >curr1_lcrit
> # head {curr1,in0}_lcrit_alarm
> ==> curr1_lcrit_alarm <==
> 1
>
> ==> in0_lcrit_alarm <==
> 0
> # echo 9999 >in0_lcrit
> # head {curr1,in0}_lcrit_alarm
> ==> curr1_lcrit_alarm <==
> 0
>
> ==> in0_lcrit_alarm <==
> 1
>
> Fixes: 4d5c2d986757 ("hwmon: (ina2xx) Add support for current limits")
> Signed-off-by: Jared Kangas <jkangas@redhat.com>
Applied.
Thanks,
Guenter
prev parent reply other threads:[~2026-08-21 19:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 13:09 [PATCH v2 0/4] " Jared Kangas
2026-08-20 13:09 ` [PATCH v2 1/4] hwmon: (ina2xx) Acquire hwmon_lock in shunt_resistor_show() Jared Kangas
2026-08-21 5:11 ` Guenter Roeck
2026-08-20 13:09 ` [PATCH v2 2/4] hwmon: (ina2xx) Parameterize ina2xx_data in ina226_alert_read() Jared Kangas
2026-08-21 19:47 ` Guenter Roeck
2026-08-20 13:09 ` [PATCH v2 3/4] hwmon: (ina2xx) Replace masks with enum in alert functions Jared Kangas
2026-08-21 19:47 ` Guenter Roeck
2026-08-20 13:09 ` [PATCH v2 4/4] hwmon: (ina2xx) Decouple in0 and curr1 alarms Jared Kangas
2026-08-21 19:48 ` Guenter Roeck [this message]
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=b60db310-a747-472c-b85c-808951b347a4@roeck-us.net \
--to=linux@roeck-us.net \
--cc=jkangas@redhat.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lothar.felten@gmail.com \
--cc=tzungbi@kernel.org \
/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®