Received: by 10.223.164.221 with SMTP id h29csp2314036wrb; Mon, 9 Oct 2017 02:30:27 -0700 (PDT) X-Google-Smtp-Source: AOwi7QC+hv3lUWWCxCnzo63/ElZ8P/3+YA0OWZm3gn/XYBWMzwcrUUYkUVFPP4BjI+F3RX68rcXe X-Received: by 10.159.216.143 with SMTP id s15mr8644858plp.201.1507541427246; Mon, 09 Oct 2017 02:30:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507541427; cv=none; d=google.com; s=arc-20160816; b=TU5+coWpw9M4F3GBrQbnpHN4tUalGbZjd9WLKGJXx2x2pqGnoeo567uCK5kinJJFd3 j1S++g252IA4r3TV42G9oc/NrLlaucWQ3cZfZf+l7p04p+CSp0WQ/dAhk9+r2mSESEaa M9XPSY5NGLraNpNldwq5JimfIJU2qmuvGCDEidV/k/Xzw7Lp2psGcB2o5OO4wDOW86UV +3fIxm4pq9eEkuD9olegeDahBB4d/C9qc8HGcNWof1SQ1WoodFCNLXRIQxtX7TwkMX9f WVm6MZD+XYo9H3J5oktTe4Ap7phHOEnS1y5o8diWb8CTOtVosMoNnXMTIijLn6uGFYPf M8Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type :content-transfer-encoding:content-language:in-reply-to:user-agent :date:message-id:from:cc:to:subject:mime-version :arc-authentication-results; bh=8VPLf+Ozg7fAMEfAeji0CtZUygp7nFYg+KjasQYjOy8=; b=XvsIupCo2cM1wSsNeT994yopd9/TsaErpefpbTJUDXAwxRj8hyngWenMyJ2ZsaRm25 PXQvLUt12RvRdTirj/Z5VVBVr668scHV1+DCgWQMog4ErpqKyXi9MCrFqdzUzjelTMvS a8mDcbGNj6gVBEp4I5KoUtYqFsyNTe+NwE7GTxC1sEoeSZu3eMf2+C9HUrychGzSlcTi LtuGIXabiQXmvFiDjAE7007GufxPrMJ68W/dG7gTaVIMCEi5PhBjSoUBeh5jIsZJfmHT LgMvAIr/lesvyd8tUgA/vA0JTqBTUpOcjKYLDCuoIznEmaIfOuKmrYybJFTuDmJEgPiB AU/Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v9si6436708plz.833.2017.10.09.02.30.13; Mon, 09 Oct 2017 02:30:27 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753977AbdJIJ3v (ORCPT + 99 others); Mon, 9 Oct 2017 05:29:51 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:47978 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751401AbdJIJ3s (ORCPT ); Mon, 9 Oct 2017 05:29:48 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20171009092946euoutp0195f93c51d9f977551fd4a8061d0aa1ea~r3OdN6Fe-2830228302euoutp01d; Mon, 9 Oct 2017 09:29:46 +0000 (GMT) Received: from eusmges3.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20171009092945eucas1p29771f5437d7cd1f8371857f639bd0c8a~r3Oci4ow51639216392eucas1p2S; Mon, 9 Oct 2017 09:29:45 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3.samsung.com (EUCPMTA) with SMTP id 83.C1.12867.9814BD95; Mon, 9 Oct 2017 10:29:45 +0100 (BST) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20171009092944eucas1p18b2e66a4a07db309551a7e945c2611ec~r3Ob3BK_D0400204002eucas1p14; Mon, 9 Oct 2017 09:29:44 +0000 (GMT) X-AuditID: cbfec7f2-f793b6d000003243-95-59db41890e36 Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 95.A9.20118.8814BD95; Mon, 9 Oct 2017 10:29:44 +0100 (BST) MIME-version: 1.0 Content-type: text/plain; charset="utf-8"; format="flowed" Received: from [106.120.51.25] by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OXJ005TVUDKKL10@eusync3.samsung.com>; Mon, 09 Oct 2017 10:29:44 +0100 (BST) Subject: Re: [2/3] iio: adc: ina2xx: Adhere to documented ABI, use Ohm instead of uOhm To: =?UTF-8?Q?Stefan_Br=c3=bcns?= , linux-iio@vger.kernel.org Cc: Peter Meerwald-Stadler , linux-kernel@vger.kernel.org, "Andrew F . Davis" , Javier Martinez Canillas , Lars-Peter Clausen , Jonathan Cameron , Hartmut Knaack From: Maciej Purski Message-id: <6144c719-5310-7358-bd57-f778ab481788@samsung.com> Date: Mon, 09 Oct 2017 11:29:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 In-reply-to: <7ee955b2-a58f-45e0-985d-1f7508d41ae7@rwthex-w2-a.rwth-ad.de> Content-language: en-US Content-transfer-encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrCKsWRmVeSWpSXmKPExsWy7djP87qdjrcjDXY/FrJ4f2oiu8Wbt2uY LB40rWKy2PX/DbPFksnzWS3mHXnHYnF51xw2i9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5k1wARxSXTUpqTmZZapG+XQJXxt7pr9gK9itXvL19 mq2BcZZMFyMnh4SAicS9UxtYIGwxiQv31rN1MXJxCAksYZT49m4uG0iCV0BQ4sfke2BFzAJm El9eHmaFKHrGKDH3xXx2kISwQITE/o+vwYpEBGIl3qxaAlbELDCVSWL36u9MXYwcQB2eEldv qoOYbAJaEmva4yHm20msa50NtotFQFXi77X7LCAlokAjN2zkBwlzCnhJHGmaBXWCuERz600o W17i4JXnLBMYBWchuXQWkktnIWmZhaRlASPLKkaR1NLi3PTcYiO94sTc4tK8dL3k/NxNjMAI 2nbs55YdjF3vgg8xCnAwKvHwNky7FSnEmlhWXJl7iFGCg1lJhHeZ+e1IId6UxMqq1KL8+KLS nNTiQ4zSHCxK4ry9e1ZHCgmkJ5akZqemFqQWwWSZODilGhi3T7+6IWD5tKVMbdcrG3TTNE93 aeyWub/w7nqmE/o9eqe9ehX+lZhm8mzYLiR9/OdsZrfHGcsu7mKM1Y0J3qN25ebt2YcaWyxc OQ/eejwxv8Myoz73w1StmMi58+rtnr8+/EPe5K+nxt9v/CuqjkYlrHm03U/ax+Tt9wyVo19f hXP8533rcc1YiaU4I9FQi7moOBEAk0uUlZwCAAA= X-CMS-MailID: 20171009092944eucas1p18b2e66a4a07db309551a7e945c2611ec X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?UTF-8?B?TWFjaWVqIFB1cnNraRtTZWN1cml0eSAoVFApG1NhbXN1bmcg?= =?UTF-8?B?RWxlY3Ryb25pY3MbVHJhaW5lZSAoKQ==?= X-Global-Sender: =?UTF-8?B?TWFjaWVqIFB1cnNraRtTZWN1cml0eSAoVFApG1NhbXN1bmcg?= =?UTF-8?B?RWxlY3Ryb25pY3MbVHJhaW5lZSAoKQ==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTU=?= CMS-TYPE: 201P X-CMS-RootMailID: 20171009092944eucas1p18b2e66a4a07db309551a7e945c2611ec X-RootMTR: 20171009092944eucas1p18b2e66a4a07db309551a7e945c2611ec References: <7ee955b2-a58f-45e0-985d-1f7508d41ae7@rwthex-w2-a.rwth-ad.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > Signed-off-by: Stefan Brüns > --- > > drivers/iio/adc/ina2xx-adc.c | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c > index 361fb4e459d5..1930f853e8c5 100644 > --- a/drivers/iio/adc/ina2xx-adc.c > +++ b/drivers/iio/adc/ina2xx-adc.c > @@ -127,7 +127,7 @@ struct ina2xx_chip_info { > struct task_struct *task; > const struct ina2xx_config *config; > struct mutex state_lock; > - unsigned int shunt_resistor; > + unsigned int shunt_resistor_uohm; > int avg; > int int_time_vbus; /* Bus voltage integration time uS */ > int int_time_vshunt; /* Shunt voltage integration time uS */ > @@ -444,7 +444,7 @@ static ssize_t ina2xx_allow_async_readout_store(struct device *dev, > /* > * Set current LSB to 1mA, shunt is in uOhms > * (equation 13 in datasheet). We hardcode a Current_LSB > - * of 1.0 x10-6. The only remaining parameter is RShunt. > + * of 1.0 x10-3. The only remaining parameter is RShunt. > * There is no need to expose the CALIBRATION register > * to the user for now. But we need to reset this register > * if the user updates RShunt after driver init, e.g upon > @@ -453,7 +453,7 @@ static ssize_t ina2xx_allow_async_readout_store(struct device *dev, > static int ina2xx_set_calibration(struct ina2xx_chip_info *chip) > { > u16 regval = DIV_ROUND_CLOSEST(chip->config->calibration_factor, > - chip->shunt_resistor); > + chip->shunt_resistor_uohm); > > return regmap_write(chip->regmap, INA2XX_CALIBRATION, regval); > } > @@ -463,7 +463,7 @@ static int set_shunt_resistor(struct ina2xx_chip_info *chip, unsigned int val) > if (val <= 0 || val > chip->config->calibration_factor) > return -EINVAL; > > - chip->shunt_resistor = val; > + chip->shunt_resistor_uohm = val; > > return 0; > } > @@ -473,8 +473,9 @@ static ssize_t ina2xx_shunt_resistor_show(struct device *dev, > char *buf) > { > struct ina2xx_chip_info *chip = iio_priv(dev_to_iio_dev(dev)); > + int vals[2] = { chip->shunt_resistor_uohm, 1000000 }; > > - return sprintf(buf, "%d\n", chip->shunt_resistor); > + return iio_format_value(buf, IIO_VAL_FRACTIONAL, 1, vals); > } > > static ssize_t ina2xx_shunt_resistor_store(struct device *dev, > @@ -482,14 +483,13 @@ static ssize_t ina2xx_shunt_resistor_store(struct device *dev, > const char *buf, size_t len) > { > struct ina2xx_chip_info *chip = iio_priv(dev_to_iio_dev(dev)); > - unsigned long val; > - int ret; > + int val, val_fract, ret; > > - ret = kstrtoul((const char *) buf, 10, &val); > + ret = iio_str_to_fixpoint(buf, 100000, &val, &val_fract); > if (ret) > return ret; > > - ret = set_shunt_resistor(chip, val); > + ret = set_shunt_resistor(chip, val * 1000000 + val_fract); > if (ret) > return ret; > > From 1580683259409547218@xxx Sun Oct 08 10:03:46 +0000 2017 X-GM-THRID: 1580086010895794021 X-Gmail-Labels: Inbox,Category Forums