phone-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@ucw.cz>
To: kernel list <linux-kernel@vger.kernel.org>,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	linux-omap@vger.kernel.org, tony@atomide.com, sre@kernel.org,
	nekit1000@gmail.com, mpartap@gmx.net, merlijn@wizzup.org,
	martin_rysavy@centrum.cz, phone-devel@vger.kernel.org,
	maemo-leste@lists.dyne.org
Subject: Motorola Droid 4 -- Stopping charger when battery is full
Date: Tue, 7 Mar 2023 13:36:08 +0100	[thread overview]
Message-ID: <ZAcvuP8kmWveLoE/@duo.ucw.cz> (raw)

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

Hi!

I complained that "battery life is very poor" with leste. It seems to
be combination of several factors.

1) I was using very old battery

2) My charger is detected as "USB", not as "AC"

3) Charger was cycling on/off, which was annoying and I often ending
up dissconnecting the charger

4) It probably has a bit higher power consuption than original android

5) Android is more aggressive, charges to 4.35V, and allows deeper
discharge

According to my measurements "CPCAP_REG_CRM_FET_OVRD |
CPCAP_REG_CRM_FET_CTRL" results in battery discharding and 0A drawn
frmo the USB.  "CPCAP_REG_CRM_FET_OVRD" is phone powered from USB,
with battery more or less disconnected (<12mA), which is what we want
in battery full situation.

Second problem was that phone never really stayed in "battery full",
immediately exiting it.

This should solve both issues (plus it enables a lot of
debugging).

Best regards,
								Pavel

Signed-off-by: Pavel Machek <pavel@ucw.cz>

diff --git a/drivers/power/supply/cpcap-charger.c b/drivers/power/supply/cpcap-charger.c
index 8bd1abe246cc..af268fc87fbf 100644
--- a/drivers/power/supply/cpcap-charger.c
+++ b/drivers/power/supply/cpcap-charger.c
@@ -10,6 +10,7 @@
  * Copyright (C) 2009-2010 Motorola, Inc.
  */
 
+#define DEBUG
 #include <linux/atomic.h>
 #include <linux/init.h>
 #include <linux/module.h>
@@ -410,8 +411,7 @@ static int cpcap_charger_disable(struct cpcap_charger_ddata *ddata)
 	int error;
 
 	error = regmap_update_bits(ddata->reg, CPCAP_REG_CRM, 0x3fff,
-				   CPCAP_REG_CRM_FET_OVRD |
-				   CPCAP_REG_CRM_FET_CTRL);
+				   CPCAP_REG_CRM_FET_OVRD);
 	if (error)
 		dev_err(ddata->dev, "%s failed with %i\n", __func__, error);
 
@@ -686,8 +686,11 @@ static void cpcap_usb_detect(struct work_struct *work)
 	if (error)
 		return;
 
+	dev_dbg(ddata->dev, "%d %d %d %d\n", s.chrg_det, s.chrgcurr1, s.chrgcurr2, s.vbusvld);
+
 	/* Just init the state if a charger is connected with no chrg_det set */
 	if (!s.chrg_det && s.chrgcurr1 && s.vbusvld) {
+	  printk("Just init -- not chrg_det\n");
 		cpcap_charger_update_state(ddata,
 					   POWER_SUPPLY_STATUS_NOT_CHARGING);
 
@@ -699,6 +702,7 @@ static void cpcap_usb_detect(struct work_struct *work)
 	 * charged to 4.35V by Android. Try again in 10 minutes.
 	 */
 	if (cpcap_charger_get_charge_voltage(ddata) > ddata->voltage) {
+	  printk("Battery overcharged, wait\n");
 		cpcap_charger_disconnect(ddata,
 					 POWER_SUPPLY_STATUS_NOT_CHARGING,
 					 HZ * 60 * 10);
@@ -713,14 +717,24 @@ static void cpcap_usb_detect(struct work_struct *work)
 			break;
 		new_state = POWER_SUPPLY_STATUS_FULL;
 
+		printk("No current -> we are done\n");
+
 		if (s.chrgcurr1 && s.vbusvld) {
 			cpcap_charger_disconnect(ddata, new_state, HZ * 5);
 			return;
 		}
 		break;
 	case POWER_SUPPLY_STATUS_FULL:
+		if (s.vbusvld) {
+			printk("Full, stay full\n");
+			schedule_delayed_work(&ddata->detect_work, HZ * 10);
+			return;
+		}
 		if (!s.chrgcurr2)
 			break;
+
+		printk("Full but we need to do something\n");
+
 		if (s.vbusvld)
 			new_state = POWER_SUPPLY_STATUS_NOT_CHARGING;
 		else
@@ -762,6 +776,7 @@ static void cpcap_usb_detect(struct work_struct *work)
 		if (!delayed_work_pending(&ddata->ramp_work))
 			schedule_delayed_work(&ddata->ramp_work, HZ/20);
 	} else {
+	  printk("No feeding bus, disabling\n");
 		ddata->set_current = 0;
 		error = cpcap_charger_disable(ddata);
 		if (error)

-- 
People of Russia, stop Putin before his war on Ukraine escalates.

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

             reply	other threads:[~2023-03-07 12:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07 12:36 Pavel Machek [this message]
2023-03-07 14:10 ` Motorola Droid 4 -- Stopping charger when battery is full Ivaylo Dimitrov
2023-03-09  7:14   ` Tony Lindgren
2023-04-13  9:37     ` Pavel Machek
2023-04-13  9:45       ` Tony Lindgren
2023-04-13  9:34   ` Pavel Machek
2023-04-13 14:41     ` Ivaylo Dimitrov
2023-03-21 19:25 ` d4: Usable with some caveats Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZAcvuP8kmWveLoE/@duo.ucw.cz \
    --to=pavel@ucw.cz \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=maemo-leste@lists.dyne.org \
    --cc=martin_rysavy@centrum.cz \
    --cc=merlijn@wizzup.org \
    --cc=mpartap@gmx.net \
    --cc=nekit1000@gmail.com \
    --cc=phone-devel@vger.kernel.org \
    --cc=sre@kernel.org \
    --cc=tony@atomide.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).