mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Matt Reimer" <mattjreimer@gmail.com>
To: cbou@mail.ru
Cc: "Pavel Machek" <pavel@ucw.cz>,
	linux-kernel@vger.kernel.org, kernel-discuss@handhelds.org,
	dwmw2@infradead.org
Subject: Re: [PATCH 6/7] [RFC] ds2760 battery driver
Date: Mon, 16 Apr 2007 14:33:24 -0700	[thread overview]
Message-ID: <f383264b0704161433v1bcba3d1v46c0838fa93a79a5@mail.gmail.com> (raw)
In-Reply-To: <20070416193518.GA3580@zarina>

On 4/16/07, Anton Vorontsov <cbou@mail.ru> wrote:
> On Mon, Apr 16, 2007 at 12:14:27PM -0700, Matt Reimer wrote:
> >  The shifts (<< 3 and >> 5) are just to get the bits reassembled in the
> >  right positions. The multiplication by 5 and subtracting 1/8 is
> >  because (AFAIK) we can't do floating point multiplication in the
> >  kernel. I'm open to suggestions.
>
> Because we are in micro world now, divisions already replaced by
> multiplication. I.e.
>
>         /* DS2760 reports voltage in units of 4.88mV, but the battery class
>          * reports in units of uV, so convert by multiplying by 4880. */
>         di->voltage_raw = (di->raw[DS2760_VOLTAGE_MSB] << 3) |
>                           (di->raw[DS2760_VOLTAGE_LSB] >> 5);
>         di->voltage_uV = di->voltage_raw * 4880;
>
> As a side effect, now we're not losing any precision. :-)

That's a good way to solve the problem. :-)

> By the way. Matt, you're more familiar with ds2760 specs, could you
> enlighten me about "* 4" in this snippet?
>
> >       acr[0] = (di->full_active_mAh * 4) >> 8;
>                                       ^^^
> >       acr[1] = (di->full_active_mAh * 4) & 0xff;
>                                       ^^^
> >       if (w1_ds2760_write(di->w1_dev, acr,
> >                           DS2760_CURRENT_ACCUM_MSB, 2) < 2)
> >              printk(KERN_ERR "ACR reset failed\n");

The accumulated current register (acr) value is in units of 0.25 mAh,
so we have to multiply by 4 to convert from units of 1 mAh to 0.25
mAh.

Thanks for all your work on this Anton.

Matt

  reply	other threads:[~2007-04-16 21:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-11 23:25 Anton Vorontsov
2007-04-13 13:49 ` Anton Vorontsov
2007-04-15 19:40 ` Pavel Machek
2007-04-16 19:14   ` Matt Reimer
2007-04-16 19:35     ` Anton Vorontsov
2007-04-16 21:33       ` Matt Reimer [this message]
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=f383264b0704161433v1bcba3d1v46c0838fa93a79a5@mail.gmail.com \
    --to=mattjreimer@gmail.com \
    --cc=cbou@mail.ru \
    --cc=dwmw2@infradead.org \
    --cc=kernel-discuss@handhelds.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /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®