lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f383264b0704161433v1bcba3d1v46c0838fa93a79a5@mail.gmail.com>
Date:	Mon, 16 Apr 2007 14:33:24 -0700
From:	"Matt Reimer" <mattjreimer@...il.com>
To:	cbou@...l.ru
Cc:	"Pavel Machek" <pavel@....cz>, linux-kernel@...r.kernel.org,
	kernel-discuss@...dhelds.org, dwmw2@...radead.org
Subject: Re: [PATCH 6/7] [RFC] ds2760 battery driver

On 4/16/07, Anton Vorontsov <cbou@...l.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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ