From patchwork Tue Mar 7 12:36:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Machek X-Patchwork-Id: 13163373 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 37CF8C678D5 for ; Tue, 7 Mar 2023 12:37:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: MIME-Version:Message-ID:Subject:To:From:Date:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=8pdcQl5srzZPO+AvUbYoBoQKxsQEz/w6yXQrfAvPza8=; b=1Is WmwQHTL4Qtjw1uUQ+4mVJMxFoCVlijYSoMxuZnaLk0aafGDnc5OPBxcXYrc0rOmZYX0VQRAT4Lf6M x6h00ujht4HA4BKJqRrSFzRHo5cPjhAT7+olSoRP8wVr473VLLljQmroc1/vyLV0gt97r3Jk6jlaG nIu5/SbbIUTa2/GkRpJ4cZlXiFfIUZgJg/GsWuaF2vMVBiXKTmLB4SoyNqw48eEkw1F2QdPLLAJ2Q +IOlKed5qAu5TJHffD+RT87L1yH7Fm6rf0z65L4GMZuwFyVm4WCXLHZltcQroOWH1DHyHsZVogGpJ vxvAjeRDnJ6DVaRqLK/f1tXkWXtKuUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZWYH-0007Y4-Mc; Tue, 07 Mar 2023 12:36:21 +0000 Received: from jabberwock.ucw.cz ([46.255.230.98]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZWYD-0007Wb-85 for linux-arm-kernel@lists.infradead.org; Tue, 07 Mar 2023 12:36:19 +0000 Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id B1CFD1C0DE7; Tue, 7 Mar 2023 13:36:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1678192568; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=1PlvY26tIHyNiqhAYJQIp+i1zuL+i9oLYMD+0Zno304=; b=ZdR2Q3VmAJbqIfmzQBuo80BePszCATog/JJr5+3pFSbAMZNNSxBs7oym0QL+HViHRo5h6B PYL3JAeEErPbwg/Wskp6+LcC+1vQxKIhkPWh8P1vtIY4vpfcbz0Tny+UxFtuZlkyCh9H4o 4dWOfIeGVD2Ar7HNt4W/L/jrIz+qUl8= Date: Tue, 7 Mar 2023 13:36:08 +0100 From: Pavel Machek To: kernel list , linux-arm-kernel , 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 Message-ID: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230307_043617_775058_BDD29764 X-CRM114-Status: GOOD ( 16.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 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 #include #include @@ -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)