From patchwork Tue Sep 17 21:34:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 11149399 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 81645912 for ; Tue, 17 Sep 2019 21:35:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5977621881 for ; Tue, 17 Sep 2019 21:35:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726888AbfIQVfI (ORCPT ); Tue, 17 Sep 2019 17:35:08 -0400 Received: from muru.com ([72.249.23.125]:33528 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726693AbfIQVfH (ORCPT ); Tue, 17 Sep 2019 17:35:07 -0400 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 0A1738140; Tue, 17 Sep 2019 21:35:38 +0000 (UTC) From: Tony Lindgren To: Sebastian Reichel Cc: linux-pm@vger.kernel.org, linux-omap@vger.kernel.org, Pavel Machek , Merlijn Wajer Subject: [PATCH 1/3] power: supply: cpcap-charger: Limit voltage to 4.2V for battery Date: Tue, 17 Sep 2019 14:34:59 -0700 Message-Id: <20190917213501.16907-2-tony@atomide.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190917213501.16907-1-tony@atomide.com> References: <20190917213501.16907-1-tony@atomide.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Pavel Machek There have been some cases of droid4 battery bulging that seem to be related to being left connected to the charger for several weeks. It is suspected that the 4.35V charge voltage configured for the battery is too much in the long run, so lets limit the charge voltage to 4.2V. Note that we are using the same register values as the Android distros on droid4, so it is suspected that the same problem also exists in Android. Fixes: 3ae5f06681fc ("power: supply: cpcap-charger: Fix charge voltage configuration") Reported-by: Merlijn Wajer Signed-off-by: Pavel Machek [tony@atomide.com: added description of the problem and fixes tag] Signed-off-by: Tony Lindgren --- drivers/power/supply/cpcap-charger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 @@ -457,7 +457,7 @@ static void cpcap_usb_detect(struct work_struct *work) max_current = CPCAP_REG_CRM_ICHRG_0A532; error = cpcap_charger_set_state(ddata, - CPCAP_REG_CRM_VCHRG_4V35, + CPCAP_REG_CRM_VCHRG_4V20, max_current, 0); if (error) goto out_err; From patchwork Tue Sep 17 21:35:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 11149403 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B0F12112B for ; Tue, 17 Sep 2019 21:35:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8F21F2189D for ; Tue, 17 Sep 2019 21:35:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726931AbfIQVfJ (ORCPT ); Tue, 17 Sep 2019 17:35:09 -0400 Received: from muru.com ([72.249.23.125]:33534 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726693AbfIQVfI (ORCPT ); Tue, 17 Sep 2019 17:35:08 -0400 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 2D5D881A0; Tue, 17 Sep 2019 21:35:40 +0000 (UTC) From: Tony Lindgren To: Sebastian Reichel Cc: linux-pm@vger.kernel.org, linux-omap@vger.kernel.org, Merlijn Wajer , Pavel Machek Subject: [PATCH 2/3] power: supply: cpcap-battery: Check voltage before orderly_poweroff Date: Tue, 17 Sep 2019 14:35:00 -0700 Message-Id: <20190917213501.16907-3-tony@atomide.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190917213501.16907-1-tony@atomide.com> References: <20190917213501.16907-1-tony@atomide.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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 Cc: Pavel Machek Signed-off-by: Tony Lindgren --- 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 %i!\n", + latest->voltage); 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 %i, powering off\n", + latest->voltage); orderly_poweroff(true); } break; From patchwork Tue Sep 17 21:35:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 11149409 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1468616B1 for ; Tue, 17 Sep 2019 21:35:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F01C42171F for ; Tue, 17 Sep 2019 21:35:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726974AbfIQVfK (ORCPT ); Tue, 17 Sep 2019 17:35:10 -0400 Received: from muru.com ([72.249.23.125]:33544 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726693AbfIQVfK (ORCPT ); Tue, 17 Sep 2019 17:35:10 -0400 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 484CB81BC; Tue, 17 Sep 2019 21:35:41 +0000 (UTC) From: Tony Lindgren To: Sebastian Reichel Cc: linux-pm@vger.kernel.org, linux-omap@vger.kernel.org, Merlijn Wajer , Pavel Machek Subject: [PATCH 3/3] power: supply: cpcap-charger: Improve battery detection Date: Tue, 17 Sep 2019 14:35:01 -0700 Message-Id: <20190917213501.16907-4-tony@atomide.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190917213501.16907-1-tony@atomide.com> References: <20190917213501.16907-1-tony@atomide.com> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org We are currently using a wrong ADC range for the battery detection. The ADC returns the battery temperature if connected. Cc: Merlijn Wajer Cc: Pavel Machek Signed-off-by: Tony Lindgren Acked-by: Pavel Machek --- 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 @@ -166,20 +166,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)