* [PATCH 1/2] power: supply: max17042_battery: Clear status bits in interrupt handler @ 2021-09-12 20:54 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 13:02 ` [PATCH 1/2] power: supply: max17042_battery: Clear status bits in interrupt handler Krzysztof Kozlowski 0 siblings, 2 replies; 7+ messages in thread From: Sebastian Krzyszkowiak @ 2021-09-12 20:54 UTC (permalink / raw) To: Sebastian Reichel, linux-pm Cc: linux-kernel, Krzysztof Kozlowski, Anton Vorontsov, Ramakrishna Pallala, Dirk Brandewie, Sebastian Krzyszkowiak, stable 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)); + power_supply_changed(chip->battery); return IRQ_HANDLED; } -- 2.33.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] power: supply: max17042_battery: Prevent int underflow in set_soc_threshold 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 ` 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 1 sibling, 2 replies; 7+ messages in thread From: Sebastian Krzyszkowiak @ 2021-09-12 20:54 UTC (permalink / raw) To: Sebastian Reichel, linux-pm Cc: linux-kernel, Krzysztof Kozlowski, Anton Vorontsov, Ramakrishna Pallala, Dirk Brandewie, Sebastian Krzyszkowiak, stable Fixes: e5f3872d2044 ("max17042: Add support for signalling change in SOC") Cc: <stable@vger.kernel.org> Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm> --- drivers/power/supply/max17042_battery.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c index c53980c8432a..caf83b4d622f 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -857,7 +857,8 @@ static void max17042_set_soc_threshold(struct max17042_chip *chip, u16 off) regmap_read(map, MAX17042_RepSOC, &soc); soc >>= 8; soc_tr = (soc + off) << 8; - soc_tr |= (soc - off); + if (off < soc) + soc_tr |= soc - off; regmap_write(map, MAX17042_SALRT_Th, soc_tr); } -- 2.33.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] power: supply: max17042_battery: Prevent int underflow in set_soc_threshold 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 1 sibling, 0 replies; 7+ messages in thread From: Greg KH @ 2021-09-13 5:43 UTC (permalink / raw) To: Sebastian Krzyszkowiak Cc: Sebastian Reichel, linux-pm, linux-kernel, Krzysztof Kozlowski, Anton Vorontsov, Ramakrishna Pallala, Dirk Brandewie, stable On Sun, Sep 12, 2021 at 10:54:02PM +0200, Sebastian Krzyszkowiak wrote: > Fixes: e5f3872d2044 ("max17042: Add support for signalling change in SOC") > Cc: <stable@vger.kernel.org> > Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm> > --- > drivers/power/supply/max17042_battery.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) I know I do not take patches without any changelog text. Perhaps other maintainers are more leniant :( thanks, greg k-h ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] power: supply: max17042_battery: Prevent int underflow in set_soc_threshold 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 1 sibling, 0 replies; 7+ messages in thread From: Krzysztof Kozlowski @ 2021-09-13 13:05 UTC (permalink / raw) To: Sebastian Krzyszkowiak, Sebastian Reichel, linux-pm Cc: linux-kernel, Anton Vorontsov, Ramakrishna Pallala, Dirk Brandewie, stable On 12/09/2021 22:54, Sebastian Krzyszkowiak wrote: > Fixes: e5f3872d2044 ("max17042: Add support for signalling change in SOC") You need commit and bug description. > Cc: <stable@vger.kernel.org> > Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm> > --- > drivers/power/supply/max17042_battery.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c > index c53980c8432a..caf83b4d622f 100644 > --- a/drivers/power/supply/max17042_battery.c > +++ b/drivers/power/supply/max17042_battery.c > @@ -857,7 +857,8 @@ static void max17042_set_soc_threshold(struct max17042_chip *chip, u16 off) > regmap_read(map, MAX17042_RepSOC, &soc); > soc >>= 8; > soc_tr = (soc + off) << 8; > - soc_tr |= (soc - off); > + if (off < soc) > + soc_tr |= soc - off; > regmap_write(map, MAX17042_SALRT_Th, soc_tr); > } > > Best regards, Krzysztof ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] power: supply: max17042_battery: Clear status bits in interrupt handler 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 13:02 ` Krzysztof Kozlowski 2021-09-13 18:32 ` Sebastian Krzyszkowiak 1 sibling, 1 reply; 7+ messages in thread From: Krzysztof Kozlowski @ 2021-09-13 13:02 UTC (permalink / raw) To: Sebastian Krzyszkowiak, Sebastian Reichel, linux-pm Cc: linux-kernel, Anton Vorontsov, Ramakrishna Pallala, Dirk Brandewie, stable 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). 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. Best regards, Krzysztof ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] power: supply: max17042_battery: Clear status bits in interrupt handler 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 2021-09-14 7:21 ` Krzysztof Kozlowski 0 siblings, 1 reply; 7+ messages in thread From: Sebastian Krzyszkowiak @ 2021-09-13 18:32 UTC (permalink / raw) To: Sebastian Reichel, linux-pm, Krzysztof Kozlowski Cc: linux-kernel, Anton Vorontsov, Ramakrishna Pallala, Dirk Brandewie, stable, kernel [-- 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 --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] power: supply: max17042_battery: Clear status bits in interrupt handler 2021-09-13 18:32 ` Sebastian Krzyszkowiak @ 2021-09-14 7:21 ` Krzysztof Kozlowski 0 siblings, 0 replies; 7+ messages in thread From: Krzysztof Kozlowski @ 2021-09-14 7:21 UTC (permalink / raw) To: Sebastian Krzyszkowiak, Sebastian Reichel, linux-pm Cc: linux-kernel, Anton Vorontsov, Ramakrishna Pallala, Dirk Brandewie, stable, kernel On 13/09/2021 20:32, Sebastian Krzyszkowiak wrote: > 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). OK, undestood. > > Besides, I also have patches for configuring m5 gauge via DT that I'll send > once I clean them up. That's cool! Happy to see such work. > >> 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. Seems reasonable, you're right. Could you mention this expolanation in commit msg or comment in the code? Best regards, Krzysztof ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-09-14 7:21 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 2021-09-14 7:21 ` Krzysztof Kozlowski
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).