Received: by 10.223.164.221 with SMTP id h29csp2056755wrb; Sat, 14 Oct 2017 11:27:42 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RQpJLovYX6o5v9GvKywCUonIX8xqj9SEc38VVQon5DhvLQ0yW6yx8QL63hvzlGnbrjeZGx X-Received: by 10.99.97.132 with SMTP id v126mr353291pgb.179.1508005662508; Sat, 14 Oct 2017 11:27:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508005662; cv=none; d=google.com; s=arc-20160816; b=AzyJP8NR1iIw4uGW5Xor7KwwnTkg4qRbRLu2+ISADJxJhS2ruLdEzqIFfmxzzhKxB3 S4YYM+EgsW81rQjzDEAl+Edz0hmc+4jNKgAOJkQ0Bzg0KanzkZrb+HLIwSeEuJqKdNa9 Kq/WZ0jjc8o7f7dn7T0Tc3C1CLlmjjny0XSpJYPJZR44RoTevahpH+vW7x0cq/m4gfIp oyrneXL5Tk0e+MtP+Hk3KROo6e4OxeZ46c0wLNCvf1qa8RyqGWWSGknAkcO5V/z5T1nD OEA5Oh56jKwmUkGOY5VhsYuHIgQUa5Oc0jJqSx4zW/SLc8NFSrSOMGFp8dnZJgplz7nv I7Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=dLN1Rv1ggud+AK+r1dI5RiFxUruZA9rTU19lVQuD/7s=; b=0QrY43o/3+Gnlio8raSeth99PZyPkmcs9r8BzfZr0SPAj82qOjY4+/H+9uZBtFoRPA UDUxMYP+crDAdtRhIyelW5nBvisYHUX6XdFk4kLukXkmqenA1zaJgJlTzqAoirbUcpTO 3VwhG7O9ok51fSpnXgNPTml1FWaCwKqoWeRRe4FRHeRUJCPaPvOA6+04G28njN9XKboo VnOUXIPkjXYqvfBVt5Fj8hVsmN8EAySAE3t1vkSWzsS/mSyS3wA5LjIwECpMuiAg88Vb iBX03FVj9YoLPzt5uZ5rTinMOmof5n15KiTCxS3/M2PbcWWoA7hJNeS/SGt+2IG5E3KF OS0A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 62si2271549ply.467.2017.10.14.11.27.28; Sat, 14 Oct 2017 11:27:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751571AbdJNS1G convert rfc822-to-8bit (ORCPT + 99 others); Sat, 14 Oct 2017 14:27:06 -0400 Received: from mail-out-2.itc.rwth-aachen.de ([134.130.5.47]:8645 "EHLO mail-out-2.itc.rwth-aachen.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750907AbdJNS1F (ORCPT ); Sat, 14 Oct 2017 14:27:05 -0400 X-IronPort-AV: E=Sophos;i="5.43,377,1503352800"; d="scan'208";a="18568951" Received: from rwthex-w2-a.rwth-ad.de ([134.130.26.158]) by mail-in-2.itc.rwth-aachen.de with ESMTP; 14 Oct 2017 20:27:03 +0200 Received: from pebbles.site (78.49.54.107) by rwthex-w2-a.rwth-ad.de (2002:8682:1a9e::8682:1a9e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1034.26; Sat, 14 Oct 2017 20:27:02 +0200 From: Stefan Bruens To: Maciej Purski CC: , Peter Meerwald-Stadler , , "Andrew F . Davis" , "Javier Martinez Canillas" , Lars-Peter Clausen , Jonathan Cameron , Hartmut Knaack Subject: Re: [2/3] iio: adc: ina2xx: Adhere to documented ABI, use Ohm instead of uOhm Date: Sat, 14 Oct 2017 20:27:01 +0200 Message-ID: <2075928.pSFUuclJ1z@pebbles.site> In-Reply-To: <6144c719-5310-7358-bd57-f778ab481788@samsung.com> References: <7ee955b2-a58f-45e0-985d-1f7508d41ae7@rwthex-w2-a.rwth-ad.de> <6144c719-5310-7358-bd57-f778ab481788@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset="iso-8859-1" X-Originating-IP: [78.49.54.107] X-ClientProxiedBy: rwthex-s1-b.rwth-ad.de (2002:8682:1a99::8682:1a99) To rwthex-w2-a.rwth-ad.de (2002:8682:1a9e::8682:1a9e) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Montag, 9. Oktober 2017 11:29:43 CEST Maciej Purski wrote: > On 10/01/2017 09:48 PM, Stefan Br�ns wrote: > > According to the ABI documentation, the shunt resistor value should be > > specificied in Ohm. As this is also used/documented for the MAX9611, > > use the same for the INA2xx driver. > > > > This poses an ABI break for anyone actually altering the shunt value > > through the sysfs interface, it does not alter the default value nor > > a value set from the devicetree. > > > > Minor change: Fix comment, 1mA is 10^-3A. > > I have just a minor issue. There could be an inconsistency with units as in > my patch I make current_lsb adjustable and I need it to be in uA (it used > to be hardcoded as 1 mA so to achieve better precision we need smaller > units). So in order to keep calibration register properly scaled, I convert > uOhms to mOhms on each set_calibration(). So if both my changes and your > changes were applied, on each shunt_resistore_store we would be performing > multiplication by 10^6 and then in set_calibration() division by 10^3 which > seems odd to me. > > I guess we could keep it as shunt_resistor_ohms instead of > shunt_resistor_uohm. We could avoid performing division on each > shunt_resistor_show() and perform multiplication by 10^3 only once in > set_calibration() on each > shunt_resistore_store(). We could then change the default value and perform > division only on probing, when reading the shunt_resistance from device > tree. > > There are many other options. It's not a major issue so maybe we could leave > it as it is or you could suggest some changes in my patch. Sorry it took me so long to answer ... The current fixed current_lsb of 1mA is indeed a bad choice for everything but a shunt resistor value of 10mOhm, as it truncates the current value. So what is a *good* choice? One important point is the current register is merely more than a convenience register. At least for the INA219/220, it provides nothing not achievable in software, and for the INA226 family it only has added value if the current is varying faster than the readout frequency and the averaging is used. The precision of the current register is limited by the precision of the shunt voltage register, and may be reduced by the applied scaling/calibration factor. The precision of the shunt voltage register is fixed at 10uV (INA219) resp. 2.5uV (INA226). Changing conversion time (both) and PGA (219) affects the noise and offset, but the lsb value is still fixed. If one wants to carry over the shunt voltage register precision into the current register, its important no (or hardly any) truncation happens. The terms therefor are given in the manual, formulas 8.5.1 (4) resp 7.5.1 (3): INA219: current = shunt_voltage * cal_register / 4096 INA226: current = shunt_voltage * cal_register / 2048 So any cal value smaller than 4096 (2048) will introduce truncation errors, larger values may introduce overflows, if the full input range is used. Now, would it not be wise to always use 4096 (2048) for the calibration value? The raw values from the IIO subsystem are meaningless without their accompanying scale factor. Instead of changing the calibration value, why not just change the reported scale factor? More opinions are very welcome. Kind regards, Stefan -- Stefan Br�ns / Bergstra�e 21 / 52062 Aachen home: +49 241 53809034 mobile: +49 151 50412019 From 1580771759759789878@xxx Mon Oct 09 09:30:27 +0000 2017 X-GM-THRID: 1580086010895794021 X-Gmail-Labels: Inbox,Category Forums