mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
To: Mike Looijmans <mike.looijmans@topic.nl>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	ladis@linux-mips.org, Dragos.Bogdan@analog.com
Subject: Re: [PATCH] power: ltc2941-battery-gauge: Disable continuous monitoring on shutdown
Date: Fri, 1 Dec 2017 16:42:10 +0100	[thread overview]
Message-ID: <20171201154210.l5wrmqipb5eeamzc@earth> (raw)
In-Reply-To: <1511448065-2727-1-git-send-email-mike.looijmans@topic.nl>

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

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 <mike.looijmans@topic.nl>
> ---

Thanks, queued. I wonder if you need a second patch to also disable
the monitoring for suspend (and re-enable on resume)?

-- 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
> 

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

  reply	other threads:[~2017-12-01 15:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-23 14:41 Mike Looijmans
2017-12-01 15:42 ` Sebastian Reichel [this message]
2017-12-05  7:10   ` Mike Looijmans
2017-12-05  9:08     ` Ladislav Michl
2017-12-05 10:29       ` Mike Looijmans

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=20171201154210.l5wrmqipb5eeamzc@earth \
    --to=sebastian.reichel@collabora.co.uk \
    --cc=Dragos.Bogdan@analog.com \
    --cc=ladis@linux-mips.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mike.looijmans@topic.nl \
    /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

all inboxes | Powered by JetHome®