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]
Date:   Wed, 26 Aug 2020 23:59:50 +0200
From:   Sebastian Reichel <sebastian.reichel@...labora.com>
To:     Andreas Kemnade <andreas@...nade.info>
Cc:     lee.jones@...aro.org, linux-kernel@...r.kernel.org,
        linux-pm@...r.kernel.org, b.galvani@...il.com, phh@....me,
        letux-kernel@...nphoenux.org
Subject: Re: [PATCH 1/2] power: supply: Add support for RN5T618/RC5T619
 charger and fuel gauge

Hi,

On Wed, Aug 26, 2020 at 08:28:34PM +0200, Andreas Kemnade wrote:
> On Wed, 26 Aug 2020 19:48:17 +0200
> Sebastian Reichel <sebastian.reichel@...labora.com> wrote:
> > On Sat, Aug 15, 2020 at 06:56:09PM +0200, Andreas Kemnade wrote:
> > > [...]
> > > +static int rn5t618_battery_current_now(struct rn5t618_power_info *info,
> > > +				       union power_supply_propval *val)
> > > +{
> > > +	u16 res;
> > > +	int ret;
> > > +
> > > +	ret = rn5t618_battery_read_doublereg(info, RN5T618_CC_AVEREG1, &res);
> > > +	if (ret)
> > > +		return ret;
> > > +
> > > +	val->intval = res;
> > > +	/* 2's complement */
> > > +	if (val->intval & (1 << 13))
> > > +		val->intval = val->intval - (1 << 14);

Btw. I think sign_extend32() can be used here?

> > > +	/* negate current to be positive when discharging */
> > > +	val->intval *= -1000;  
> > 
> > mh, the sign is not documented (which should be fixed). At least
> > sbs-battery does it the other way around (negative current when
> > discharging, positive otherwise). Some drivers do not support
> > signed current and always report positive values (e.g. ACPI driver).
> > 
> > What did you use as reference for swapping the sign?
> > 
> Well, I have searched for documentation, found nothing and used the
> bq27xxx driver as reference  which I am used to from the GTA04/GTA02,
> so things behave equal. That are the devices where a was most
> intensively looking at those values.
> I thought that there would be some unwritten rule about that.

The mess is mostly due to lacking reviewing from my side
(and possibly my predecessors). I just went through a dozen of
drivers and it looks like most either do not support signed current
(and use negative values as error code :() or use negative current
for discharge. I could not find any other driver using negative
numbers for charging. I think it's best to negative = discharge as
official correct value and will send an update patch for the
documentation later.

-- Sebastian

Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ