linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 0/2] cpcap charger and battery fixes
@ 2019-10-09 20:52 Tony Lindgren
  2019-10-09 20:52 ` [PATCH 1/2] power: supply: cpcap-battery: Check voltage before orderly_poweroff Tony Lindgren
  2019-10-09 20:52 ` [PATCH 2/2] power: supply: cpcap-charger: Improve battery detection Tony Lindgren
  0 siblings, 2 replies; 7+ messages in thread
From: Tony Lindgren @ 2019-10-09 20:52 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-pm, linux-omap, Merlijn Wajer, Pavel Machek

Hi,

Here are few fixes for cpcap charger and battery. These can probably wait
for v5.5 if preferred that way and can be applied separate from the 4.2V
charger fix.

Regards,

Tony

Changes since v1:

- Sent the updated 4.2V voltage fix separately

Tony Lindgren (2):
  power: supply: cpcap-battery: Check voltage before orderly_poweroff
  power: supply: cpcap-charger: Improve battery detection

 drivers/power/supply/cpcap-battery.c | 9 ++++++---
 drivers/power/supply/cpcap-charger.c | 7 ++++---
 2 files changed, 10 insertions(+), 6 deletions(-)

-- 
2.23.0

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

* [PATCH 1/2] power: supply: cpcap-battery: Check voltage before orderly_poweroff
  2019-10-09 20:52 [PATCHv2 0/2] cpcap charger and battery fixes Tony Lindgren
@ 2019-10-09 20:52 ` Tony Lindgren
  2019-10-13 11:28   ` Pavel Machek
  2019-10-09 20:52 ` [PATCH 2/2] power: supply: cpcap-charger: Improve battery detection Tony Lindgren
  1 sibling, 1 reply; 7+ messages in thread
From: Tony Lindgren @ 2019-10-09 20:52 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-pm, linux-omap, Merlijn Wajer, Pavel Machek

We can get the low voltage interrupt trigger sometimes way too early,
maybe because of CPU load spikes. This causes orderly_poweroff() be
called too easily.

Let's check the voltage before orderly_poweroff in case it was not
yet a permanent condition. We will be getting more interrupts anyways
if the condition persists.

Let's also show the measured voltages for low battery and battery
empty warnings since we have them.

Cc: Merlijn Wajer <merlijn@wizzup.org>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/power/supply/cpcap-battery.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -562,12 +562,15 @@ static irqreturn_t cpcap_battery_irq_thread(int irq, void *data)
 	switch (d->action) {
 	case CPCAP_BATTERY_IRQ_ACTION_BATTERY_LOW:
 		if (latest->current_ua >= 0)
-			dev_warn(ddata->dev, "Battery low at 3.3V!\n");
+			dev_warn(ddata->dev, "Battery low at %imV!\n",
+				latest->voltage / 1000);
 		break;
 	case CPCAP_BATTERY_IRQ_ACTION_POWEROFF:
-		if (latest->current_ua >= 0) {
+		if (latest->current_ua >= 0 && latest->voltage >= 0 &&
+		    latest->voltage <= 3100000) {
 			dev_emerg(ddata->dev,
-				  "Battery empty at 3.1V, powering off\n");
+				  "Battery empty at %imV, powering off\n",
+				  latest->voltage / 1000);
 			orderly_poweroff(true);
 		}
 		break;
-- 
2.23.0

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

* [PATCH 2/2] power: supply: cpcap-charger: Improve battery detection
  2019-10-09 20:52 [PATCHv2 0/2] cpcap charger and battery fixes Tony Lindgren
  2019-10-09 20:52 ` [PATCH 1/2] power: supply: cpcap-battery: Check voltage before orderly_poweroff Tony Lindgren
@ 2019-10-09 20:52 ` Tony Lindgren
  1 sibling, 0 replies; 7+ messages in thread
From: Tony Lindgren @ 2019-10-09 20:52 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-pm, linux-omap, Merlijn Wajer, Pavel Machek

We are currently using a wrong ADC range for the battery detection.
The ADC returns the battery temperature if connected.

Cc: Merlijn Wajer <merlijn@wizzup.org>
Cc: Pavel Machek <pavel@ucw.cz>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/power/supply/cpcap-charger.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/power/supply/cpcap-charger.c b/drivers/power/supply/cpcap-charger.c
--- a/drivers/power/supply/cpcap-charger.c
+++ b/drivers/power/supply/cpcap-charger.c
@@ -176,20 +176,21 @@ static enum power_supply_property cpcap_charger_props[] = {
 	POWER_SUPPLY_PROP_CURRENT_NOW,
 };
 
+/* No battery always shows temperature of -40000 */
 static bool cpcap_charger_battery_found(struct cpcap_charger_ddata *ddata)
 {
 	struct iio_channel *channel;
-	int error, value;
+	int error, temperature;
 
 	channel = ddata->channels[CPCAP_CHARGER_IIO_BATTDET];
-	error = iio_read_channel_raw(channel, &value);
+	error = iio_read_channel_processed(channel, &temperature);
 	if (error < 0) {
 		dev_warn(ddata->dev, "%s failed: %i\n", __func__, error);
 
 		return false;
 	}
 
-	return value == 1;
+	return temperature > -20000 && temperature < 60000;
 }
 
 static int cpcap_charger_get_charge_voltage(struct cpcap_charger_ddata *ddata)
-- 
2.23.0

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

* Re: [PATCH 1/2] power: supply: cpcap-battery: Check voltage before orderly_poweroff
  2019-10-09 20:52 ` [PATCH 1/2] power: supply: cpcap-battery: Check voltage before orderly_poweroff Tony Lindgren
@ 2019-10-13 11:28   ` Pavel Machek
  2019-10-15 17:26     ` Tony Lindgren
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Machek @ 2019-10-13 11:28 UTC (permalink / raw)
  To: Tony Lindgren; +Cc: Sebastian Reichel, linux-pm, linux-omap, Merlijn Wajer

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

On Wed 2019-10-09 13:52:51, Tony Lindgren wrote:
> We can get the low voltage interrupt trigger sometimes way too early,
> maybe because of CPU load spikes. This causes orderly_poweroff() be
> called too easily.
> 
> Let's check the voltage before orderly_poweroff in case it was not
> yet a permanent condition. We will be getting more interrupts anyways
> if the condition persists.
> 
> Let's also show the measured voltages for low battery and battery
> empty warnings since we have them.

> +++ b/drivers/power/supply/cpcap-battery.c
> @@ -562,12 +562,15 @@ static irqreturn_t cpcap_battery_irq_thread(int irq, void *data)
>  	switch (d->action) {
>  	case CPCAP_BATTERY_IRQ_ACTION_BATTERY_LOW:
>  		if (latest->current_ua >= 0)
> -			dev_warn(ddata->dev, "Battery low at 3.3V!\n");
> +			dev_warn(ddata->dev, "Battery low at %imV!\n",
> +				latest->voltage / 1000);
>  		break;
>  	case CPCAP_BATTERY_IRQ_ACTION_POWEROFF:
> -		if (latest->current_ua >= 0) {
> +		if (latest->current_ua >= 0 && latest->voltage >= 0 &&
> +		    latest->voltage <= 3100000) {
>  			dev_emerg(ddata->dev,
> -				  "Battery empty at 3.1V, powering off\n");
> +				  "Battery empty at %imV, powering off\n",
> +				  latest->voltage / 1000);
>  			orderly_poweroff(true);
>  		}

Hmm.

So if latest->voltage is < 0, I'd preffer to shut down the machine,
too.

Actually, if we got POWEROFF irq, and voltage is close to 3.1V (like
maybe < 3.2V), maybe it would be good to shutdown anyway?

Best regards,
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

* Re: [PATCH 1/2] power: supply: cpcap-battery: Check voltage before orderly_poweroff
  2019-10-13 11:28   ` Pavel Machek
@ 2019-10-15 17:26     ` Tony Lindgren
  0 siblings, 0 replies; 7+ messages in thread
From: Tony Lindgren @ 2019-10-15 17:26 UTC (permalink / raw)
  To: Pavel Machek; +Cc: Sebastian Reichel, linux-pm, linux-omap, Merlijn Wajer

* Pavel Machek <pavel@ucw.cz> [191013 11:28]:
> On Wed 2019-10-09 13:52:51, Tony Lindgren wrote:
> > We can get the low voltage interrupt trigger sometimes way too early,
> > maybe because of CPU load spikes. This causes orderly_poweroff() be
> > called too easily.
> > 
> > Let's check the voltage before orderly_poweroff in case it was not
> > yet a permanent condition. We will be getting more interrupts anyways
> > if the condition persists.
> > 
> > Let's also show the measured voltages for low battery and battery
> > empty warnings since we have them.
> 
> > +++ b/drivers/power/supply/cpcap-battery.c
> > @@ -562,12 +562,15 @@ static irqreturn_t cpcap_battery_irq_thread(int irq, void *data)
> >  	switch (d->action) {
> >  	case CPCAP_BATTERY_IRQ_ACTION_BATTERY_LOW:
> >  		if (latest->current_ua >= 0)
> > -			dev_warn(ddata->dev, "Battery low at 3.3V!\n");
> > +			dev_warn(ddata->dev, "Battery low at %imV!\n",
> > +				latest->voltage / 1000);
> >  		break;
> >  	case CPCAP_BATTERY_IRQ_ACTION_POWEROFF:
> > -		if (latest->current_ua >= 0) {
> > +		if (latest->current_ua >= 0 && latest->voltage >= 0 &&
> > +		    latest->voltage <= 3100000) {
> >  			dev_emerg(ddata->dev,
> > -				  "Battery empty at 3.1V, powering off\n");
> > +				  "Battery empty at %imV, powering off\n",
> > +				  latest->voltage / 1000);
> >  			orderly_poweroff(true);
> >  		}
> 
> Hmm.
> 
> So if latest->voltage is < 0, I'd preffer to shut down the machine,
> too.

Hmm I need to recheck if that is needed or not when booting without
a battery on a power supply.

> Actually, if we got POWEROFF irq, and voltage is close to 3.1V (like
> maybe < 3.2V), maybe it would be good to shutdown anyway?

No, this is some spurious interrupt issue that I've seen triggering
at way higher voltages than it should be happening at.

Regards,

Tony


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

* Re: [PATCHv2 0/2] cpcap charger and battery fixes
  2019-10-16 22:30 [PATCHv2 0/2] cpcap charger and battery fixes Tony Lindgren
@ 2019-10-20 20:35 ` Sebastian Reichel
  0 siblings, 0 replies; 7+ messages in thread
From: Sebastian Reichel @ 2019-10-20 20:35 UTC (permalink / raw)
  To: Tony Lindgren; +Cc: linux-pm, linux-omap, Merlijn Wajer, Pavel Machek

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

Hi,

On Wed, Oct 16, 2019 at 03:30:03PM -0700, Tony Lindgren wrote:
> Hi,
> 
> Here are few fixes for cpcap charger and battery. These can probably wait
> for v5.5 if preferred that way and can be applied separate from the 4.2V
> charger fix.
> 
> Regards,
> 
> Tony
> 
> Changes since v2:
> 
> - Drop the pointless test for latest->voltage >= 0 as noted by Pavel
> 
> - Allow poweroff to trigger at 3.2V and lower as suggested by Pavel
> 
> Changes since v1:
> 
> - Sent the updated 4.2V voltage fix separately
> 
> Tony Lindgren (2):
>   power: supply: cpcap-battery: Check voltage before orderly_poweroff
>   power: supply: cpcap-charger: Improve battery detection
> 
>  drivers/power/supply/cpcap-battery.c | 8 +++++---
>  drivers/power/supply/cpcap-charger.c | 7 ++++---
>  2 files changed, 9 insertions(+), 6 deletions(-)

Thanks, queued.

-- Sebastian

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

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

* [PATCHv2 0/2] cpcap charger and battery fixes
@ 2019-10-16 22:30 Tony Lindgren
  2019-10-20 20:35 ` Sebastian Reichel
  0 siblings, 1 reply; 7+ messages in thread
From: Tony Lindgren @ 2019-10-16 22:30 UTC (permalink / raw)
  To: Sebastian Reichel; +Cc: linux-pm, linux-omap, Merlijn Wajer, Pavel Machek

Hi,

Here are few fixes for cpcap charger and battery. These can probably wait
for v5.5 if preferred that way and can be applied separate from the 4.2V
charger fix.

Regards,

Tony

Changes since v2:

- Drop the pointless test for latest->voltage >= 0 as noted by Pavel

- Allow poweroff to trigger at 3.2V and lower as suggested by Pavel

Changes since v1:

- Sent the updated 4.2V voltage fix separately

Tony Lindgren (2):
  power: supply: cpcap-battery: Check voltage before orderly_poweroff
  power: supply: cpcap-charger: Improve battery detection

 drivers/power/supply/cpcap-battery.c | 8 +++++---
 drivers/power/supply/cpcap-charger.c | 7 ++++---
 2 files changed, 9 insertions(+), 6 deletions(-)

-- 
2.23.0

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

end of thread, other threads:[~2019-10-20 20:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-09 20:52 [PATCHv2 0/2] cpcap charger and battery fixes Tony Lindgren
2019-10-09 20:52 ` [PATCH 1/2] power: supply: cpcap-battery: Check voltage before orderly_poweroff Tony Lindgren
2019-10-13 11:28   ` Pavel Machek
2019-10-15 17:26     ` Tony Lindgren
2019-10-09 20:52 ` [PATCH 2/2] power: supply: cpcap-charger: Improve battery detection Tony Lindgren
2019-10-16 22:30 [PATCHv2 0/2] cpcap charger and battery fixes Tony Lindgren
2019-10-20 20:35 ` 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).