Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753215AbdLEJ4y convert rfc822-to-8bit (ORCPT ); Tue, 5 Dec 2017 04:56:54 -0500 Received: from out1-7.antispamcloud.com ([185.201.16.7]:56554 "EHLO out1-7.antispamcloud.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752783AbdLEJ4v (ORCPT ); Tue, 5 Dec 2017 04:56:51 -0500 X-Greylist: delayed 9978 seconds by postgrey-1.27 at vger.kernel.org; Tue, 05 Dec 2017 04:56:50 EST Subject: Re: [PATCH] power: ltc2941-battery-gauge: Disable continuous monitoring on shutdown To: Sebastian Reichel CC: , , , References: <1511448065-2727-1-git-send-email-mike.looijmans@topic.nl> <20171201154210.l5wrmqipb5eeamzc@earth> From: Mike Looijmans Organization: Topic Message-ID: <708849a5-5b66-effc-21d7-f8d7c2f7be61@topic.nl> Date: Tue, 5 Dec 2017 08:10:27 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20171201154210.l5wrmqipb5eeamzc@earth> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8BIT X-Originating-IP: [85.150.144.104] X-EXCLAIMER-MD-CONFIG: 9833cda7-5b21-4d34-9a38-8d025ddc3664 X-EXCLAIMER-MD-BIFURCATION-INSTANCE: 0 X-Originating-IP: 37.74.225.130 X-AntiSpamCloud-Domain: topic.nl X-AntiSpamCloud-Username: 37.74.225.128/28 Authentication-Results: antispamcloud.com; auth=pass smtp.auth=37.74.225.128/28@topic.nl X-AntiSpamCloud-Outgoing-Class: ham X-AntiSpamCloud-Outgoing-Evidence: Combined (0.01) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5kaH2jsOZXOguBPvV5jQTcDj1g3/PwYZaTCzSym8uE9HqMARKqh6m2Yf kdC07uk+Yty0HO3aVC27hoV0qWVkAvzK2LHn5aq9c/e6BdkxWGjhWFfL3gAPUkRxQwp2uQYsyZ8a mvcEmXxlsFWO+dQ0MIBTYi2bf0F0JzgUQ/o6tR7CoMTlvlU31sGoB4bgXuOipejdzu6+Q4Y/r7Uw /3HHQqfeplX2t064mO+ljqxPiXTWviEqxXu9nsjup+bYfVGN6iosGsVTmudl6YlodXwh+5DX8GBK 2+FCvMRX/exKBeIM9UHslcVUQPXc7RxsFltixw8oz/erkNo121abqNyKx6Lru3bykS72vwCCDvHj mF3eoMP3I2Gsa2ZAWndDSAOBnfqwBI6gCq9pd8FuwF4MX4ZQHWBBwjF3lw6xMU+SO3TC0l5A2Plz ZcQn76/OwEscq0QMF99VlWOZVo1sbhkkbsVDjSgV5CF/KKTa/AElCN4KhLp9/AG1in5FZWZj2q5J mj+ZLzF4zBDb0bNcgUTHNCd0JmbqROuof5+bHLNCgb4217NirEYyqwqMBGrw8ELiqFRUPWaWJ63q BD/7hHGCrg6Z3JKVmi72ocgY5kMQSjs7nxlDOs6qMAREe7im38hrrEMbpEF3kpqh7rbNKrK3sPFD DTOZFLH5hMfjyaE0GFy3PBx49OFdmcpM4r1ByaBdDZYbb5hsJgP8lv28IZ5edQSnRfHnajQxc6x3 cUXEa2CPw7Yhb4Kit1L9FxRd8cL4pJgGyH8lmQ2eYZRMFrEIwJO9xAKP0UvPX7YTxC7iIk5W67mG XhPcpnBt29kUjAO58E+Q2RM21QI4rfCQB4piHuj8PzWuJxrqdnZneuKmUvTdZuM7jUXIESohoO51 xWmU8ZHaQ6ZNVHH8a5JP5xGJ2AkchRwBNNjV272S9TYbWIic2PgsF42qAMMI6CURENPcSsZKIzeX iZb4H6tpztUZHQbeNHk15VolAGHS5rCXQKDywofSUk/dJDceXQAfRCkwEiRgDMxx2Flqv7V0NJeZ aB864pShjzZrFIvgBBqKOWVdT0sPdfk4WeMVTJuAdW8PYw== X-Report-Abuse-To: spam@quarantine2.antispamcloud.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3202 Lines: 105 On 01-12-17 16:42, Sebastian Reichel wrote: > Hi, > > On Thu, Nov 23, 2017 at 03:41:05PM +0100, Mike Looijmans wrote: >> 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 >> --- > > Thanks, queued. I wonder if you need a second patch to also disable > the monitoring for suspend (and re-enable on resume)? For now, yes, that would probably make sense. The gauge also has "alert" functionality, once that is enabled in the driver, the monitoring shouldn't be disabled and the device would even be able to wake the system. But that's no concern yet, so just stopping it on suspend would be better for now. > > -- Sebastian > >> 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); >> -- >> 1.9.1 >> -- Mike Looijmans Kind regards, Mike Looijmans System Expert TOPIC Products Materiaalweg 4, NL-5681 RJ Best Postbus 440, NL-5680 AK Best Telefoon: +31 (0) 499 33 69 79 E-mail: mike.looijmans@topicproducts.com Website: www.topicproducts.com Please consider the environment before printing this e-mail