Re: [PATCH v8 5/8] Loongson: YeeLoong: add hardware monitoring driver

Wu Zhangjin <[email protected]> Mon, 07 Dec 2009 08:54:58 +0800
Newsgroups org.kernel.vger.linux-laptop,org.kernel.vger.linux-kernel,org.kernel.vger.linux-mips
Message-ID <[email protected]>
On Sun, 2009-12-06 at 09:47 +0100, Pavel Machek wrote: 
> Hi!
> 
> > +static int get_battery_current(void)
> > +{
> > +	s16 value;
> > +
> > +	value = (ec_read(REG_BAT_CURRENT_HIGH) << 8) |
> > +		(ec_read(REG_BAT_CURRENT_LOW));
> > +
> > +	if (value < 0)
> > +		value = ~value + 1;
> > +
> > +	return value;
> > +}
> 
> What is going on here? I thought the value is already in two's
> complement... Is the above equivalent of
> 
> 	      if (value < 0)
> 	      	 value = -value; 
> 
> ? If so, why? If not, can you add a comment?

Right, then, will use this instead:

static int get_battery_current(void)
{ 
	s16 value;

	value = (ec_read(REG_BAT_CURRENT_HIGH) << 8) |
		(ec_read(REG_BAT_CURRENT_LOW));

	return abs(value);
}

Thanks & Best Regards,
	Wu Zhangjin