public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@ucw.cz>
To: Anton Vorontsov <cbou@mail.ru>
Cc: linux-kernel@vger.kernel.org, kernel-discuss@handhelds.org,
	dwmw2@infradead.org
Subject: Re: [PATCH 6/7] [RFC] ds2760 battery driver
Date: Sun, 15 Apr 2007 19:40:01 +0000	[thread overview]
Message-ID: <20070415194001.GF10097@ucw.cz> (raw)
In-Reply-To: <20070411232522.GF20095@zarina>

Hi!

> This is driver for batteries with ds2760 chip inside. Such batteries
> used in almost every HP iPaq and HTC PDAs/phones.

Looks nice to me. It even knows about dependency between temperature
and remaining power :-).


> +	di->update_time = jiffies;
> +
> +	/* DS2760 reports voltage in units of 4.88mV, but the battery class
> +	 * reports in units of mV, so convert by multiplying by 4.875.
> +	 * We approximate because integer math is cheap, and close enough. */
> +	di->voltage_raw = (di->raw[DS2760_VOLTAGE_MSB] << 3) |
> +	                  (di->raw[DS2760_VOLTAGE_LSB] >> 5);
> +	di->voltage_mV = (di->voltage_raw * 5) - (di->voltage_raw / 8);

Hmm, not sure if such tricks re really worth it... should not compiler
be doing this?


> +	/* Calculate the empty level at the present temperature. */
> +	scale[4] = di->raw[DS2760_ACTIVE_EMPTY + 4];
> +	for (i = 3; i >= 0; i--)
> +		scale[i] = scale[i + 1] + di->raw[DS2760_ACTIVE_EMPTY + i];
> +
> +	di->empty_mAh = battery_interpolate(scale, di->temp_C / 10);

Wow.

> +static struct platform_driver ds2760_battery_driver = {
> +	.driver = {
> +		.name = "ds2760-battery",
> +	},
> +	.probe	  = ds2760_battery_probe,
> +	.remove   = ds2760_battery_remove,
> +	#ifdef CONFIG_PM
> +	.suspend  = ds2760_battery_suspend,
> +	.resume	  = ds2760_battery_resume,
> +	#endif

I thought ifdefs need to be at column 0?

							Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

  parent reply	other threads:[~2007-04-15 19:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-11 23:25 [PATCH 6/7] [RFC] ds2760 battery driver Anton Vorontsov
2007-04-13 13:49 ` Anton Vorontsov
2007-04-15 19:40 ` Pavel Machek [this message]
2007-04-16 19:14   ` Matt Reimer
2007-04-16 19:35     ` Anton Vorontsov
2007-04-16 21:33       ` Matt Reimer
2007-04-17  8:17     ` Pavel Machek

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=20070415194001.GF10097@ucw.cz \
    --to=pavel@ucw.cz \
    --cc=cbou@mail.ru \
    --cc=dwmw2@infradead.org \
    --cc=kernel-discuss@handhelds.org \
    --cc=linux-kernel@vger.kernel.org \
    /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