linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 0/2] cpcap charger and battery fixes
@ 2019-10-16 22:30 Tony Lindgren
  2019-10-16 22:30 ` [PATCH 1/2] power: supply: cpcap-battery: Check voltage before orderly_poweroff Tony Lindgren
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ 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] 5+ messages in thread

* [PATCH 1/2] power: supply: cpcap-battery: Check voltage before orderly_poweroff
  2019-10-16 22:30 [PATCHv2 0/2] cpcap charger and battery fixes Tony Lindgren
@ 2019-10-16 22:30 ` Tony Lindgren
  2019-10-16 22:30 ` [PATCH 2/2] power: supply: cpcap-charger: Improve battery detection Tony Lindgren
  2019-10-20 20:35 ` [PATCHv2 0/2] cpcap charger and battery fixes Sebastian Reichel
  2 siblings, 0 replies; 5+ 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

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 | 8 +++++---
 1 file changed, 5 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,14 @@ 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 <= 3200000) {
 			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] 5+ messages in thread

* [PATCH 2/2] power: supply: cpcap-charger: Improve battery detection
  2019-10-16 22:30 [PATCHv2 0/2] cpcap charger and battery fixes Tony Lindgren
  2019-10-16 22:30 ` [PATCH 1/2] power: supply: cpcap-battery: Check voltage before orderly_poweroff Tony Lindgren
@ 2019-10-16 22:30 ` Tony Lindgren
  2019-10-20 20:35 ` [PATCHv2 0/2] cpcap charger and battery fixes Sebastian Reichel
  2 siblings, 0 replies; 5+ 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

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] 5+ 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-16 22:30 ` [PATCH 1/2] power: supply: cpcap-battery: Check voltage before orderly_poweroff Tony Lindgren
  2019-10-16 22:30 ` [PATCH 2/2] power: supply: cpcap-charger: Improve battery detection Tony Lindgren
@ 2019-10-20 20:35 ` Sebastian Reichel
  2 siblings, 0 replies; 5+ 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] 5+ messages in thread

* [PATCHv2 0/2] cpcap charger and battery fixes
@ 2019-10-09 20:52 Tony Lindgren
  0 siblings, 0 replies; 5+ 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] 5+ messages in thread

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-16 22:30 [PATCHv2 0/2] cpcap charger and battery fixes Tony Lindgren
2019-10-16 22:30 ` [PATCH 1/2] power: supply: cpcap-battery: Check voltage before orderly_poweroff Tony Lindgren
2019-10-16 22:30 ` [PATCH 2/2] power: supply: cpcap-charger: Improve battery detection Tony Lindgren
2019-10-20 20:35 ` [PATCHv2 0/2] cpcap charger and battery fixes Sebastian Reichel
  -- strict thread matches above, loose matches on Subject: below --
2019-10-09 20:52 Tony Lindgren

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