From patchwork Thu Nov 23 14:41:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Looijmans X-Patchwork-Id: 10072941 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3B6566056E for ; Thu, 23 Nov 2017 14:48:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2960D2A0C4 for ; Thu, 23 Nov 2017 14:48:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1CD692A0CA; Thu, 23 Nov 2017 14:48:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4BF52A0C4 for ; Thu, 23 Nov 2017 14:48:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752260AbdKWOsY (ORCPT ); Thu, 23 Nov 2017 09:48:24 -0500 Received: from atl4mhfb03.myregisteredsite.com ([209.17.115.119]:59208 "EHLO atl4mhfb03.myregisteredsite.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751921AbdKWOsX (ORCPT ); Thu, 23 Nov 2017 09:48:23 -0500 X-Greylist: delayed 419 seconds by postgrey-1.27 at vger.kernel.org; Thu, 23 Nov 2017 09:48:23 EST Received: from atl4mhob19.registeredsite.com (atl4mhob19.registeredsite.com [209.17.115.112]) by atl4mhfb03.myregisteredsite.com (8.14.4/8.14.4) with ESMTP id vANEfOn1026371 for ; Thu, 23 Nov 2017 09:41:25 -0500 Received: from mailpod.hostingplatform.com ([10.30.71.203]) by atl4mhob19.registeredsite.com (8.14.4/8.14.4) with ESMTP id vANEfMot040274 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Thu, 23 Nov 2017 09:41:22 -0500 Received: (qmail 14324 invoked by uid 0); 23 Nov 2017 14:41:22 -0000 X-TCPREMOTEIP: 37.74.225.130 X-Authenticated-UID: mike@milosoftware.com Received: from unknown (HELO mikebuntu.TOPIC.LOCAL) (mike@milosoftware.com@37.74.225.130) by 0 with ESMTPA; 23 Nov 2017 14:41:21 -0000 From: Mike Looijmans To: linux-pm@vger.kernel.org, sre@kernel.org Cc: linux-kernel@vger.kernel.org, ladis@linux-mips.org, Dragos.Bogdan@analog.com, Mike Looijmans Subject: [PATCH] power: ltc2941-battery-gauge: Disable continuous monitoring on shutdown Date: Thu, 23 Nov 2017 15:41:05 +0100 Message-Id: <1511448065-2727-1-git-send-email-mike.looijmans@topic.nl> X-Mailer: git-send-email 1.9.1 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver sets the fuel gauge to continuous monitoring on startup, for the models that support this. When the board shuts down, the chip remains in that mode, causing a few mA drain on the battery every 2 or 10 seconds. This patch registers a shutdown handler that turns off the monitoring to prevent this battery drain. Signed-off-by: Mike Looijmans --- drivers/power/supply/ltc2941-battery-gauge.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/power/supply/ltc2941-battery-gauge.c b/drivers/power/supply/ltc2941-battery-gauge.c index 08e4fd9..4cfa3f0 100644 --- a/drivers/power/supply/ltc2941-battery-gauge.c +++ b/drivers/power/supply/ltc2941-battery-gauge.c @@ -60,6 +60,7 @@ enum ltc294x_id { #define LTC294X_REG_CONTROL_PRESCALER_SET(x) \ ((x << 3) & LTC294X_REG_CONTROL_PRESCALER_MASK) #define LTC294X_REG_CONTROL_ALCC_CONFIG_DISABLED 0 +#define LTC294X_REG_CONTROL_ADC_DISABLE(x) ((x) & ~(BIT(7) | BIT(6))) struct ltc294x_info { struct i2c_client *client; /* I2C Client pointer */ @@ -523,6 +524,29 @@ static int ltc294x_i2c_probe(struct i2c_client *client, return 0; } +static void ltc294x_i2c_shutdown(struct i2c_client *client) +{ + struct ltc294x_info *info = i2c_get_clientdata(client); + int ret; + u8 value; + u8 control; + + /* The LTC2941 does not need any special handling */ + if (info->id == LTC2941_ID) + return; + + /* Read control register */ + ret = ltc294x_read_regs(info->client, LTC294X_REG_CONTROL, &value, 1); + if (ret < 0) + return; + + /* Disable continuous ADC conversion as this drains the battery */ + control = LTC294X_REG_CONTROL_ADC_DISABLE(value); + if (control != value) + ltc294x_write_regs(info->client, LTC294X_REG_CONTROL, + &control, 1); +} + #ifdef CONFIG_PM_SLEEP static int ltc294x_suspend(struct device *dev) @@ -589,6 +613,7 @@ static int ltc294x_resume(struct device *dev) }, .probe = ltc294x_i2c_probe, .remove = ltc294x_i2c_remove, + .shutdown = ltc294x_i2c_shutdown, .id_table = ltc294x_i2c_id, }; module_i2c_driver(ltc294x_driver);