On 4/16/07, Anton Vorontsov <[email protected]> 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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]