public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Anton Vorontsov <cbouatmailru@gmail.com>
To: rklein@nvidia.com
Cc: olof@lixom.net, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] power: bq20z75: add support for POWER_NOW
Date: Tue, 1 Mar 2011 22:39:09 +0300	[thread overview]
Message-ID: <20110301193909.GB5649@oksana.dev.rtsoft.ru> (raw)
In-Reply-To: <1298940931-17552-4-git-send-email-rklein@nvidia.com>

On Mon, Feb 28, 2011 at 04:55:30PM -0800, rklein@nvidia.com wrote:
[...]
> +static int bq20z75_get_power_now(struct i2c_client *client,
> +	union power_supply_propval *val)
> +{
> +	int voltage_now = 0;
> +	int current_now = 0;
> +
> +	voltage_now = bq20z75_read_word_data(client,
> +		bq20z75_data[REG_VOLTAGE].addr);
> +	if (voltage_now < 0)
> +		return voltage_now;
> +
> +	current_now = bq20z75_read_word_data(client,
> +		bq20z75_data[REG_CURRENT].addr);
> +	if (current_now < 0)
> +		return current_now;
> +
> +	/* returned values are 16 bit */
> +	current_now = (s16)current_now;
> +	/* need to ensure it is positive */
> +	current_now = abs(current_now);
> +
> +	val->intval = voltage_now * current_now;

Nope, we don't do this in the drivers. It's a derived property, and
driver should not bother with these.

Documentation/power/power_supply_class.txt says:
- - - -
Q: Suppose, my battery monitoring chip/firmware does not provides capacity
   in percents, but provides charge_{now,full,empty}. Should I calculate
   percentage capacity manually, inside the driver, and register CAPACITY
   attribute? The same question about time_to_empty/time_to_full.
A: Most likely, no. This class is designed to export properties which are
   directly measurable by the specific hardware available.

   Inferring not available properties using some heuristics or mathematical
   model is not subject of work for a battery driver. Such functionality
   should be factored out, and in fact, apm_power, the driver to serve
   legacy APM API on top of power supply class, uses a simple heuristic of
   approximating remaining battery capacity based on its charge, current,
   voltage and so on. But full-fledged battery model is likely not subject
   for kernel at all, as it would require floating point calculation to deal
   with things like differential equations and Kalman filters. This is
   better be handled by batteryd/libbattery, yet to be written.
- - - -

There were some ideas to write a kernel module that would provide
such "derived" properties for all the drivers. But drivers themselves
should not duplicate the generic logic.

Thanks,

-- 
Anton Vorontsov
Email: cbouatmailru@gmail.com

  reply	other threads:[~2011-03-01 19:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-01  0:55 [PATCH 0/4] power: bq20z75: update support rklein
2011-03-01  0:55 ` [PATCH 1/4] power: bq20z75: add optional battery detect gpio rklein
2011-03-01  0:55 ` [PATCH 2/4] power: bq20z75: add i2c retry mechanism rklein
2011-03-01  0:55 ` [PATCH 3/4] power: bq20z75: add support for POWER_NOW rklein
2011-03-01 19:39   ` Anton Vorontsov [this message]
2011-03-01  0:55 ` [PATCH 4/4] power_supply: update power_supply_is_watt_property rklein
2011-03-01 19:41 ` [PATCH 0/4] power: bq20z75: update support Anton Vorontsov

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=20110301193909.GB5649@oksana.dev.rtsoft.ru \
    --to=cbouatmailru@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olof@lixom.net \
    --cc=rklein@nvidia.com \
    /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