linux-samsung-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] power: supply: max17042_battery: use VFSOC for capacity when no rsns
@ 2021-09-29 18:14 Henrik Grimler
  2021-09-29 18:14 ` [PATCH v2 2/2] power: supply: max17042_battery: fix typo in MAX17042_IAvg_empty Henrik Grimler
  2021-09-29 19:43 ` [PATCH v2 1/2] power: supply: max17042_battery: use VFSOC for capacity when no rsns Hans de Goede
  0 siblings, 2 replies; 5+ messages in thread
From: Henrik Grimler @ 2021-09-29 18:14 UTC (permalink / raw)
  To: sre, m.szyprowski, krzysztof.kozlowski, sebastian.krzyszkowiak,
	hdegoede, linux-pm, linux-samsung-soc, ~postmarketos/upstreaming
  Cc: Henrik Grimler, stable, Wolfgang Wiedmeyer

On Galaxy S3 (i9300/i9305), which has the max17047 fuel gauge and no
current sense resistor (rsns), the RepSOC register does not provide an
accurate state of charge value. The reported value is wrong, and does
not change over time. VFSOC however, which uses the voltage fuel gauge
to determine the state of charge, always shows an accurate value.

For devices without current sense, VFSOC is already used for the
soc-alert (0x0003 is written to MiscCFG register), so with this change
the source of the alert and the PROP_CAPACITY value match.

Fixes: 359ab9f5b154 ("power_supply: Add MAX17042 Fuel Gauge Driver")
Cc: <stable@vger.kernel.org>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Suggested-by: Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>
Signed-off-by: Henrik Grimler <henrik@grimler.se>
---
Changes in v2:
Re-write commit message to highlight that VFSOC is already used for
alert, after Krzysztof's comments
---
 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 8dffae76b6a3..5809ba997093 100644
--- a/drivers/power/supply/max17042_battery.c
+++ b/drivers/power/supply/max17042_battery.c
@@ -313,7 +313,10 @@ static int max17042_get_property(struct power_supply *psy,
 		val->intval = data * 625 / 8;
 		break;
 	case POWER_SUPPLY_PROP_CAPACITY:
-		ret = regmap_read(map, MAX17042_RepSOC, &data);
+		if (chip->pdata->enable_current_sense)
+			ret = regmap_read(map, MAX17042_RepSOC, &data);
+		else
+			ret = regmap_read(map, MAX17042_VFSOC, &data);
 		if (ret < 0)
 			return ret;
 

base-commit: 5816b3e6577eaa676ceb00a848f0fd65fe2adc29
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] power: supply: max17042_battery: fix typo in MAX17042_IAvg_empty
  2021-09-29 18:14 [PATCH v2 1/2] power: supply: max17042_battery: use VFSOC for capacity when no rsns Henrik Grimler
@ 2021-09-29 18:14 ` Henrik Grimler
  2021-09-30 11:42   ` Krzysztof Kozlowski
  2021-09-29 19:43 ` [PATCH v2 1/2] power: supply: max17042_battery: use VFSOC for capacity when no rsns Hans de Goede
  1 sibling, 1 reply; 5+ messages in thread
From: Henrik Grimler @ 2021-09-29 18:14 UTC (permalink / raw)
  To: sre, m.szyprowski, krzysztof.kozlowski, sebastian.krzyszkowiak,
	hdegoede, linux-pm, linux-samsung-soc, ~postmarketos/upstreaming
  Cc: Henrik Grimler

Datasheet gives the name IAvg_empty, not LAvg_empty.

Signed-off-by: Henrik Grimler <henrik@grimler.se>
---
 drivers/power/supply/max17042_battery.c | 2 +-
 include/linux/power/max17042_battery.h  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
index 5809ba997093..32f331480487 100644
--- a/drivers/power/supply/max17042_battery.c
+++ b/drivers/power/supply/max17042_battery.c
@@ -786,7 +786,7 @@ static inline void max17042_override_por_values(struct max17042_chip *chip)
 	if ((chip->chip_type == MAXIM_DEVICE_TYPE_MAX17042) ||
 	    (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17047) ||
 	    (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17050)) {
-		max17042_override_por(map, MAX17042_LAvg_empty, config->lavg_empty);
+		max17042_override_por(map, MAX17042_IAvg_empty, config->iavg_empty);
 		max17042_override_por(map, MAX17042_TempNom, config->temp_nom);
 		max17042_override_por(map, MAX17042_TempLim, config->temp_lim);
 		max17042_override_por(map, MAX17042_FCTC, config->fctc);
diff --git a/include/linux/power/max17042_battery.h b/include/linux/power/max17042_battery.h
index dd24756a8af7..c417abd2ab70 100644
--- a/include/linux/power/max17042_battery.h
+++ b/include/linux/power/max17042_battery.h
@@ -78,7 +78,7 @@ enum max17042_register {
 	MAX17042_T_empty	= 0x34,
 
 	MAX17042_FullCAP0       = 0x35,
-	MAX17042_LAvg_empty	= 0x36,
+	MAX17042_IAvg_empty	= 0x36,
 	MAX17042_FCTC		= 0x37,
 	MAX17042_RCOMP0		= 0x38,
 	MAX17042_TempCo		= 0x39,
@@ -221,7 +221,7 @@ struct max17042_config_data {
 	u16	fullcap;	/* 0x10 */
 	u16	fullcapnom;	/* 0x23 */
 	u16	socempty;	/* 0x33 */
-	u16	lavg_empty;	/* 0x36 */
+	u16	iavg_empty;	/* 0x36 */
 	u16	dqacc;		/* 0x45 */
 	u16	dpacc;		/* 0x46 */
 	u16	qrtbl00;	/* 0x12 */
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] power: supply: max17042_battery: use VFSOC for capacity when no rsns
  2021-09-29 18:14 [PATCH v2 1/2] power: supply: max17042_battery: use VFSOC for capacity when no rsns Henrik Grimler
  2021-09-29 18:14 ` [PATCH v2 2/2] power: supply: max17042_battery: fix typo in MAX17042_IAvg_empty Henrik Grimler
@ 2021-09-29 19:43 ` Hans de Goede
  2021-10-02 15:53   ` Sebastian Reichel
  1 sibling, 1 reply; 5+ messages in thread
From: Hans de Goede @ 2021-09-29 19:43 UTC (permalink / raw)
  To: Henrik Grimler, sre, m.szyprowski, krzysztof.kozlowski,
	sebastian.krzyszkowiak, linux-pm, linux-samsung-soc,
	~postmarketos/upstreaming
  Cc: stable, Wolfgang Wiedmeyer

Hi,

On 9/29/21 8:14 PM, Henrik Grimler wrote:
> On Galaxy S3 (i9300/i9305), which has the max17047 fuel gauge and no
> current sense resistor (rsns), the RepSOC register does not provide an
> accurate state of charge value. The reported value is wrong, and does
> not change over time. VFSOC however, which uses the voltage fuel gauge
> to determine the state of charge, always shows an accurate value.
> 
> For devices without current sense, VFSOC is already used for the
> soc-alert (0x0003 is written to MiscCFG register), so with this change
> the source of the alert and the PROP_CAPACITY value match.
> 
> Fixes: 359ab9f5b154 ("power_supply: Add MAX17042 Fuel Gauge Driver")
> Cc: <stable@vger.kernel.org>
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
> Suggested-by: Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>
> Signed-off-by: Henrik Grimler <henrik@grimler.se>
> ---
> Changes in v2:
> Re-write commit message to highlight that VFSOC is already used for
> alert, after Krzysztof's comments

Thanks, both patches looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

for the series.


Regards,

Hans


> ---
>  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 8dffae76b6a3..5809ba997093 100644
> --- a/drivers/power/supply/max17042_battery.c
> +++ b/drivers/power/supply/max17042_battery.c
> @@ -313,7 +313,10 @@ static int max17042_get_property(struct power_supply *psy,
>  		val->intval = data * 625 / 8;
>  		break;
>  	case POWER_SUPPLY_PROP_CAPACITY:
> -		ret = regmap_read(map, MAX17042_RepSOC, &data);
> +		if (chip->pdata->enable_current_sense)
> +			ret = regmap_read(map, MAX17042_RepSOC, &data);
> +		else
> +			ret = regmap_read(map, MAX17042_VFSOC, &data);
>  		if (ret < 0)
>  			return ret;
>  
> 
> base-commit: 5816b3e6577eaa676ceb00a848f0fd65fe2adc29
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] power: supply: max17042_battery: fix typo in MAX17042_IAvg_empty
  2021-09-29 18:14 ` [PATCH v2 2/2] power: supply: max17042_battery: fix typo in MAX17042_IAvg_empty Henrik Grimler
@ 2021-09-30 11:42   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2021-09-30 11:42 UTC (permalink / raw)
  To: Henrik Grimler, sre, m.szyprowski, sebastian.krzyszkowiak,
	hdegoede, linux-pm, linux-samsung-soc, ~postmarketos/upstreaming

On 29/09/2021 20:14, Henrik Grimler wrote:
> Datasheet gives the name IAvg_empty, not LAvg_empty.
> 
> Signed-off-by: Henrik Grimler <henrik@grimler.se>
> ---
>  drivers/power/supply/max17042_battery.c | 2 +-
>  include/linux/power/max17042_battery.h  | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 


Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] power: supply: max17042_battery: use VFSOC for capacity when no rsns
  2021-09-29 19:43 ` [PATCH v2 1/2] power: supply: max17042_battery: use VFSOC for capacity when no rsns Hans de Goede
@ 2021-10-02 15:53   ` Sebastian Reichel
  0 siblings, 0 replies; 5+ messages in thread
From: Sebastian Reichel @ 2021-10-02 15:53 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Henrik Grimler, m.szyprowski, krzysztof.kozlowski,
	sebastian.krzyszkowiak, linux-pm, linux-samsung-soc,
	~postmarketos/upstreaming, stable, Wolfgang Wiedmeyer

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

Hi,

On Wed, Sep 29, 2021 at 09:43:25PM +0200, Hans de Goede wrote:
> On 9/29/21 8:14 PM, Henrik Grimler wrote:
> > On Galaxy S3 (i9300/i9305), which has the max17047 fuel gauge and no
> > current sense resistor (rsns), the RepSOC register does not provide an
> > accurate state of charge value. The reported value is wrong, and does
> > not change over time. VFSOC however, which uses the voltage fuel gauge
> > to determine the state of charge, always shows an accurate value.
> > 
> > For devices without current sense, VFSOC is already used for the
> > soc-alert (0x0003 is written to MiscCFG register), so with this change
> > the source of the alert and the PROP_CAPACITY value match.
> > 
> > Fixes: 359ab9f5b154 ("power_supply: Add MAX17042 Fuel Gauge Driver")
> > Cc: <stable@vger.kernel.org>
> > Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
> > Suggested-by: Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>
> > Signed-off-by: Henrik Grimler <henrik@grimler.se>
> > ---
> > Changes in v2:
> > Re-write commit message to highlight that VFSOC is already used for
> > alert, after Krzysztof's comments
> 
> Thanks, both patches looks good to me:
> 
> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
> 
> for the series.

Thanks, both queued.

-- Sebastian

> 
> 
> Regards,
> 
> Hans
> 
> 
> > ---
> >  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 8dffae76b6a3..5809ba997093 100644
> > --- a/drivers/power/supply/max17042_battery.c
> > +++ b/drivers/power/supply/max17042_battery.c
> > @@ -313,7 +313,10 @@ static int max17042_get_property(struct power_supply *psy,
> >  		val->intval = data * 625 / 8;
> >  		break;
> >  	case POWER_SUPPLY_PROP_CAPACITY:
> > -		ret = regmap_read(map, MAX17042_RepSOC, &data);
> > +		if (chip->pdata->enable_current_sense)
> > +			ret = regmap_read(map, MAX17042_RepSOC, &data);
> > +		else
> > +			ret = regmap_read(map, MAX17042_VFSOC, &data);
> >  		if (ret < 0)
> >  			return ret;
> >  
> > 
> > base-commit: 5816b3e6577eaa676ceb00a848f0fd65fe2adc29
> > 
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-10-02 15:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-29 18:14 [PATCH v2 1/2] power: supply: max17042_battery: use VFSOC for capacity when no rsns Henrik Grimler
2021-09-29 18:14 ` [PATCH v2 2/2] power: supply: max17042_battery: fix typo in MAX17042_IAvg_empty Henrik Grimler
2021-09-30 11:42   ` Krzysztof Kozlowski
2021-09-29 19:43 ` [PATCH v2 1/2] power: supply: max17042_battery: use VFSOC for capacity when no rsns Hans de Goede
2021-10-02 15:53   ` Sebastian Reichel

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).