~postmarketos/upstreaming

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 3

[PATCH] power: supply: max17042_battery: Fix SOC threshold calc w/ no current sense

Details
Message ID
<20240817-max17042-soc-threshold-fix-v1-1-72b45899c3cc@gmail.com>
DKIM signature
pass
Download raw message
Patch: +4 -1
Commit 223a3b82834f ("power: supply: max17042_battery: use VFSOC for
capacity when no rsns") made it so that capacity on systems without
current sensing would be read from VFSOC instead of RepSOC. However,
the SOC threshold calculation still read RepSOC to get the SOC
regardless of the current sensing option state.

Fix this by applying the same conditional to determine which register
should be read.

This also seems to be the intended behavior as per the datasheet - SOC
alert config value in MiscCFG on setups without current sensing is set
to a value of 0b11, indicating SOC alerts being generated based on
VFSOC, instead of 0b00 which indicates SOC alerts being generated based
on RepSOC.

This fixes an issue on the Galaxy S3/Midas boards, where the alert
interrupt would be constantly retriggered, causing high CPU usage
on idle (around ~12%-15%).

Fixes: e5f3872d2044 ("max17042: Add support for signalling change in SOC")
Signed-off-by: Artur Weber <aweber.kernel@gmail.com>
---
Commit 223a3b82834f ("power: supply: max17042_battery: use VFSOC for
capacity when no rsns") made it so that capacity on systems without
current sensing would be read from VFSOC instead of RepSOC. However,
the SOC threshold calculation still read RepSOC to get the SOC
regardless of the current sensing option state.

Fix this by applying the same conditional to determine which register
should be read.

This also seems to be the intended behavior as per the datasheet - SOC
alert config value in MiscCFG on setups without current sensing is set
to a value of 0b11, indicating SOC alerts being generated based on
VFSOC, instead of 0b00 which indicates SOC alerts being generated based
on RepSOC.

This fixes an issue on the Galaxy S3/Midas boards, where the alert
interrupt would be constantly retriggered, causing high CPU usage
on idle (around ~12%-15%).
---
 drivers/power/supply/max17042_battery.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
index e7d37e422c3f..496c3e1f2ee6 100644
--- a/drivers/power/supply/max17042_battery.c
+++ b/drivers/power/supply/max17042_battery.c
@@ -853,7 +853,10 @@ static void max17042_set_soc_threshold(struct max17042_chip *chip, u16 off)
	/* program interrupt thresholds such that we should
	 * get interrupt for every 'off' perc change in the soc
	 */
	regmap_read(map, MAX17042_RepSOC, &soc);
	if (chip->pdata->enable_current_sense)
		regmap_read(map, MAX17042_RepSOC, &soc);
	else
		regmap_read(map, MAX17042_VFSOC, &soc);
	soc >>= 8;
	soc_tr = (soc + off) << 8;
	if (off < soc)

---
base-commit: 0c3836482481200ead7b416ca80c68a29cfdaabd
change-id: 20240817-max17042-soc-threshold-fix-e96f15a622e5

Best regards,
-- 
Artur Weber <aweber.kernel@gmail.com>
Details
Message ID
<20240817185136.GA102892@l14.localdomain>
In-Reply-To
<20240817-max17042-soc-threshold-fix-v1-1-72b45899c3cc@gmail.com> (view parent)
DKIM signature
pass
Download raw message
On Sat, Aug 17, 2024 at 12:51:14PM +0200, Artur Weber wrote:
> Commit 223a3b82834f ("power: supply: max17042_battery: use VFSOC for
> capacity when no rsns") made it so that capacity on systems without
> current sensing would be read from VFSOC instead of RepSOC. However,
> the SOC threshold calculation still read RepSOC to get the SOC
> regardless of the current sensing option state.
> 
> Fix this by applying the same conditional to determine which register
> should be read.
> 
> This also seems to be the intended behavior as per the datasheet - SOC
> alert config value in MiscCFG on setups without current sensing is set
> to a value of 0b11, indicating SOC alerts being generated based on
> VFSOC, instead of 0b00 which indicates SOC alerts being generated based
> on RepSOC.
> 
> This fixes an issue on the Galaxy S3/Midas boards, where the alert
> interrupt would be constantly retriggered, causing high CPU usage
> on idle (around ~12%-15%).
> 
> Fixes: e5f3872d2044 ("max17042: Add support for signalling change in SOC")
> Signed-off-by: Artur Weber <aweber.kernel@gmail.com>

Reviewed-by: Henrik Grimler <henrik@grimler.se>

Can confirm that this fixes high irq CPU usage on exynos4412-i9300 and
exynos4412-i9305, thanks!

Best regards
Henrik Grimler

> ---
> Commit 223a3b82834f ("power: supply: max17042_battery: use VFSOC for
> capacity when no rsns") made it so that capacity on systems without
> current sensing would be read from VFSOC instead of RepSOC. However,
> the SOC threshold calculation still read RepSOC to get the SOC
> regardless of the current sensing option state.
> 
> Fix this by applying the same conditional to determine which register
> should be read.
> 
> This also seems to be the intended behavior as per the datasheet - SOC
> alert config value in MiscCFG on setups without current sensing is set
> to a value of 0b11, indicating SOC alerts being generated based on
> VFSOC, instead of 0b00 which indicates SOC alerts being generated based
> on RepSOC.
> 
> This fixes an issue on the Galaxy S3/Midas boards, where the alert
> interrupt would be constantly retriggered, causing high CPU usage
> on idle (around ~12%-15%).
> ---
>  drivers/power/supply/max17042_battery.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
> index e7d37e422c3f..496c3e1f2ee6 100644
> --- a/drivers/power/supply/max17042_battery.c
> +++ b/drivers/power/supply/max17042_battery.c
> @@ -853,7 +853,10 @@ static void max17042_set_soc_threshold(struct max17042_chip *chip, u16 off)
>  	/* program interrupt thresholds such that we should
>  	 * get interrupt for every 'off' perc change in the soc
>  	 */
> -	regmap_read(map, MAX17042_RepSOC, &soc);
> +	if (chip->pdata->enable_current_sense)
> +		regmap_read(map, MAX17042_RepSOC, &soc);
> +	else
> +		regmap_read(map, MAX17042_VFSOC, &soc);
>  	soc >>= 8;
>  	soc_tr = (soc + off) << 8;
>  	if (off < soc)
> 
> ---
> base-commit: 0c3836482481200ead7b416ca80c68a29cfdaabd
> change-id: 20240817-max17042-soc-threshold-fix-e96f15a622e5
> 
> Best regards,
> -- 
> Artur Weber <aweber.kernel@gmail.com>
> 
Krzysztof Kozlowski <krzk@kernel.org>
Details
Message ID
<4289e248-842a-4883-8c71-bd2fcbeecae1@kernel.org>
In-Reply-To
<20240817-max17042-soc-threshold-fix-v1-1-72b45899c3cc@gmail.com> (view parent)
DKIM signature
pass
Download raw message
On 17/08/2024 12:51, Artur Weber wrote:
> Commit 223a3b82834f ("power: supply: max17042_battery: use VFSOC for
> capacity when no rsns") made it so that capacity on systems without
> current sensing would be read from VFSOC instead of RepSOC. However,
> the SOC threshold calculation still read RepSOC to get the SOC
> regardless of the current sensing option state.
> 
> Fix this by applying the same conditional to determine which register
> should be read.
> 
> This also seems to be the intended behavior as per the datasheet - SOC
> alert config value in MiscCFG on setups without current sensing is set
> to a value of 0b11, indicating SOC alerts being generated based on
> VFSOC, instead of 0b00 which indicates SOC alerts being generated based
> on RepSOC.
> 
> This fixes an issue on the Galaxy S3/Midas boards, where the alert
> interrupt would be constantly retriggered, causing high CPU usage
> on idle (around ~12%-15%).
> 
> Fixes: e5f3872d2044 ("max17042: Add support for signalling change in SOC")
> Signed-off-by: Artur Weber <aweber.kernel@gmail.com>

Cc: <stable@vger.kernel.org>

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Best regards,
Krzysztof
Details
Message ID
<172477791953.367469.12003415047436890038.b4-ty@collabora.com>
In-Reply-To
<20240817-max17042-soc-threshold-fix-v1-1-72b45899c3cc@gmail.com> (view parent)
DKIM signature
missing
Download raw message
On Sat, 17 Aug 2024 12:51:14 +0200, Artur Weber wrote:
> Commit 223a3b82834f ("power: supply: max17042_battery: use VFSOC for
> capacity when no rsns") made it so that capacity on systems without
> current sensing would be read from VFSOC instead of RepSOC. However,
> the SOC threshold calculation still read RepSOC to get the SOC
> regardless of the current sensing option state.
> 
> Fix this by applying the same conditional to determine which register
> should be read.
> 
> [...]

Applied, thanks!

[1/1] power: supply: max17042_battery: Fix SOC threshold calc w/ no current sense
      commit: 3a3acf839b2cedf092bdd1ff65b0e9895df1656b

Best regards,
-- 
Sebastian Reichel <sebastian.reichel@collabora.com>
Reply to thread Export thread (mbox)