All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
To: Sebastian Reichel <sre@kernel.org>,
	linux-pm@vger.kernel.org,
	Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Cc: linux-kernel@vger.kernel.org,
	Anton Vorontsov <anton.vorontsov@linaro.org>,
	Ramakrishna Pallala <ramakrishna.pallala@intel.com>,
	Dirk Brandewie <dirk.brandewie@gmail.com>,
	stable@vger.kernel.org, kernel@puri.sm
Subject: Re: [PATCH 1/2] power: supply: max17042_battery: Clear status bits in interrupt handler
Date: Mon, 13 Sep 2021 20:32:52 +0200	[thread overview]
Message-ID: <5702731.UytLkSCjyO@pliszka> (raw)
In-Reply-To: <0123524d-b767-5b5b-8b14-60d8cea3c429@canonical.com>

[-- Attachment #1: Type: text/plain, Size: 3286 bytes --]

On poniedziałek, 13 września 2021 15:02:34 CEST Krzysztof Kozlowski wrote:
> On 12/09/2021 22:54, Sebastian Krzyszkowiak wrote:
> > The gauge requires us to clear the status bits manually for some alerts
> > to be properly dismissed. Previously the IRQ was configured to react only
> > on falling edge, which wasn't technically correct (the ALRT line is active
> > low), but it had a happy side-effect of preventing interrupt storms
> > on uncleared alerts from happening.
> > 
> > Fixes: 7fbf6b731bca ("power: supply: max17042: Do not enforce (incorrect)
> > interrupt trigger type") Cc: <stable@vger.kernel.org>
> > Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
> > ---
> > 
> >  drivers/power/supply/max17042_battery.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/drivers/power/supply/max17042_battery.c
> > b/drivers/power/supply/max17042_battery.c index
> > 8dffae76b6a3..c53980c8432a 100644
> > --- a/drivers/power/supply/max17042_battery.c
> > +++ b/drivers/power/supply/max17042_battery.c
> > @@ -876,6 +876,9 @@ static irqreturn_t max17042_thread_handler(int id,
> > void *dev)> 
> >  		max17042_set_soc_threshold(chip, 1);
> >  	
> >  	}
> > 
> > +	regmap_clear_bits(chip->regmap, MAX17042_STATUS,
> > +			  0xFFFF & ~(STATUS_POR_BIT | 
STATUS_BST_BIT));
> > +
> 
> Are you sure that this was the reason of interrupt storm? Not incorrect
> SoC value (read from register for ModelGauge m3 while not configuring
> fuel gauge model).

Yes, I am sure. I have observed this on a fully configured max17055 with 
ModelGauge m5. It also makes sense to me based on what I read in the code and 
datasheets.

There were two kinds of storms - the short ones happening on each SOC change 
caused by SOC threshold alerts set by max17042_set_soc_threshold which 
eventually got cleared by reconfiguring the thresholds; and a huge one 
happening when SOC got down to 0% that did not get away until the battery got 
charged to at least 1% at which point the thresholds got reconfigured again 
(which is how I noticed the underflow fixed by the second patch).

Besides, I also have patches for configuring m5 gauge via DT that I'll send 
once I clean them up.

> You should only clear bits which you are awaken for... Have in mind that
> in DT-configuration the fuel gauge is most likely broken by missing
> configuration. With alert enabled, several other config fields should be
> cleared.

I have checked all the bits in the Status register and aside of Bst, POR and 
bunch of "don't-care" bits they're all alert indicators that we either handle 
explicitly in the interrupt handler (Smn/Smx) or implicitly via 
power_supply_changed (Imn/Imx, Vmn/Vmx, Tmn/Tmx, dSOCi, Bi/Br). The driver 
unconditionally enables alerts for SOC thresholds and all the rest stays 
effectively disabled at POR; however, a bootloader or firmware may configure it 
differently, which may be wanted for things like resuming from suspend when a 
bad condition happens. Therefore we need to clear all the bits anyway and I'm 
not sure whether iterating through them in a "if set then clear" loop gains us 
anything aside of additional lines of code.

> Best regards,
> Krzysztof

Cheers,
Sebastian

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2021-09-13 18:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-12 20:54 [PATCH 1/2] power: supply: max17042_battery: Clear status bits in interrupt handler Sebastian Krzyszkowiak
2021-09-12 20:54 ` [PATCH 2/2] power: supply: max17042_battery: Prevent int underflow in set_soc_threshold Sebastian Krzyszkowiak
2021-09-13  5:43   ` Greg KH
2021-09-13 13:05   ` Krzysztof Kozlowski
2021-09-13 13:02 ` [PATCH 1/2] power: supply: max17042_battery: Clear status bits in interrupt handler Krzysztof Kozlowski
2021-09-13 18:32   ` Sebastian Krzyszkowiak [this message]
2021-09-14  7:21     ` Krzysztof Kozlowski

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=5702731.UytLkSCjyO@pliszka \
    --to=sebastian.krzyszkowiak@puri.sm \
    --cc=anton.vorontsov@linaro.org \
    --cc=dirk.brandewie@gmail.com \
    --cc=kernel@puri.sm \
    --cc=krzysztof.kozlowski@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=ramakrishna.pallala@intel.com \
    --cc=sre@kernel.org \
    --cc=stable@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.