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. :-)
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");