Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp1283pxa; Wed, 26 Aug 2020 15:02:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuZTZLkF493Urfzr9Dxa3W0aPOyyGd7Uw4IqjMLaw6m3G9XMvblM2MF04laPZfYQrfxsWA X-Received: by 2002:a17:906:1c59:: with SMTP id l25mr18500890ejg.182.1598479332356; Wed, 26 Aug 2020 15:02:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598479332; cv=none; d=google.com; s=arc-20160816; b=Z+m3t8kdhC4/AvAc/+6r/J9/j6DyhoOQll6i1+P7wCThJPtEcK0V44Y7o/EIp0kkzw VIGNM6S0wXWKHuhIIHKhHubMZcoqMSsq8uiwgUIIr1pULOVJCPNkC8Ro9J5rdv9de082 HoAw9oMXB9B6sYhFUrNkjfRMOHcZVSR2BILH3Hf7ttkYC97Tb9qQaUSd5Oq5cM4OTZLJ C2YOoiUcp1l1g9cN2D4TH0LQtf85Wd97vcdEsvH5DPiDlkKILponcpzavUy3jQ8FTaqW nrJxFe2jVd5WJ4At7cgvt8X32cV9ZZaGXT/ZWdmO3T1DcQ2oT+scBUg7qmLpLjOk2FoP cPRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=Y1IWxmpwHbhlJnFO8uSheBDSrtQ+pb6WGqicp9tsro4=; b=HQgF+CEj/VvAfEmVECT4IZS0Fh3l+OEXCsrEGEds/8O2kbGnk29ziLycvle8+UN9pv aBTK07w/HNZ2UedSkMc61q6yMBJkTGsIskv3gs4vR+WZuGIZIOjHGepOtOFQwCdtijCC PEniSyH/63vMlVexCgkV4U3xMEoQBCDMOdKd8jwStqBKyz6k5Z1NaOBErUWbLAUkfCKM ZQXtqL+JKGoyOeWeC3lDLW2HwU19X7xQXe3WQFMxzTYliJ1LZWMNehfaU49+TvFT561m EyaJ0lHMdizx6xMZ7H6xZCWzr6ck0tJHyFd1z/Vw+xEPpoPUj4cxOJ6w+J2AaeFvloH0 0AnA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a62si196959edf.186.2020.08.26.15.01.48; Wed, 26 Aug 2020 15:02:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726939AbgHZV74 (ORCPT + 99 others); Wed, 26 Aug 2020 17:59:56 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:47262 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726753AbgHZV7z (ORCPT ); Wed, 26 Aug 2020 17:59:55 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: sre) with ESMTPSA id 42A8329946E Received: by earth.universe (Postfix, from userid 1000) id E7C103C0C82; Wed, 26 Aug 2020 23:59:50 +0200 (CEST) Date: Wed, 26 Aug 2020 23:59:50 +0200 From: Sebastian Reichel To: Andreas Kemnade Cc: lee.jones@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, b.galvani@gmail.com, phh@phh.me, letux-kernel@openphoenux.org Subject: Re: [PATCH 1/2] power: supply: Add support for RN5T618/RC5T619 charger and fuel gauge Message-ID: <20200826215950.bkzk76lwax7l6arz@earth.universe> References: <20200815165610.10647-1-andreas@kemnade.info> <20200815165610.10647-2-andreas@kemnade.info> <20200826174817.vhus3j4i4t7u7jc4@earth.universe> <20200826202834.42b1673f@aktux> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="pa4o3hd67cmcjsut" Content-Disposition: inline In-Reply-To: <20200826202834.42b1673f@aktux> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --pa4o3hd67cmcjsut Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 wrote: > > On Sat, Aug 15, 2020 at 06:56:09PM +0200, Andreas Kemnade wrote: > > > [...] > > > +static int rn5t618_battery_current_now(struct rn5t618_power_info *in= fo, > > > + union power_supply_propval *val) > > > +{ > > > + u16 res; > > > + int ret; > > > + > > > + ret =3D rn5t618_battery_read_doublereg(info, RN5T618_CC_AVEREG1, &r= es); > > > + if (ret) > > > + return ret; > > > + > > > + val->intval =3D res; > > > + /* 2's complement */ > > > + if (val->intval & (1 << 13)) > > > + val->intval =3D val->intval - (1 << 14); Btw. I think sign_extend32() can be used here? > > > + /* negate current to be positive when discharging */ > > > + val->intval *=3D -1000; =20 > >=20 > > 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). > >=20 > > What did you use as reference for swapping the sign? > >=20 > 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 =3D discharge as official correct value and will send an update patch for the documentation later. -- Sebastian --pa4o3hd67cmcjsut Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAl9G204ACgkQ2O7X88g7 +poT0hAAo9qt3MJtmVC4Jo5cRFg8HtHcMV/QonFv94AU1H1EF/yXqztd2Q2GpQJo Q91b0E0d6fBYsVhofss7D2Oq2dqEeSQlAUs1UohcXQlySBfsIPI4UYm+hxdkVegA 9Qaj5q6oFEZrHvN0O4hq86iH4dtelG0SgYbxWwpfnaehk+uTHdazVzwoBACw9q+s j+5HRlqs0aelpVP2y8Sab0XQQHlt14Fl6r17vxuIxM4p0K7ks1+yElJtx1fyNrjO Pvx72OyR40mEfGtMJErLpHEWDNAY7MZYUbb1VwWQ3uYOtmvI3RNcnP2ffXMR6j0t J14Ll3Aui93Ka9GvM+hDivWw4/pehfDrajMs4xlpu2mtAwFmvZpUtxhGB5pRd54Q MO2oaOaOmrWS5Klrpw57PN5PMHdODglZL8URpPD7x4bznVbEge9ekB6UowrJIsyp 7DQsb2VlVYkHGt3pY17XW0h80Lbc/IYLUlUgnkmrxBHkbI8vGWwJKsCT0Kx82ZwL m+0NWKdVVfb/sQGTeWS4kAh82y4/llJlmZx4/QzzM57EKk0V4ZuUHNBAA+f8QgU1 0/S6jmXiv9/uU6aTqQXLHKDX3dInXMZS289aibvWYQAFcXeDF95qHDhbQoIzGWUk WANu3gcDoWSzW2pdGlKtWjKvQtbGeyY4crVsIzomPQfqVe+tZng= =ozPK -----END PGP SIGNATURE----- --pa4o3hd67cmcjsut--