Received: by 10.223.164.221 with SMTP id h29csp637788wrb; Sun, 1 Oct 2017 12:50:46 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDJ2P63rAj8XVnpgVI36w59XiCOnfanmoLsVucCrDPzefeNYaRHhYRYmtLFfjlYHjB02Z4I X-Received: by 10.159.197.66 with SMTP id d2mr12405673plo.130.1506887446364; Sun, 01 Oct 2017 12:50:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506887446; cv=none; d=google.com; s=arc-20160816; b=bPUTW5DU2QF8ZSY6xXl2PUM3S/9a41o7rTqtrUYc1XmOy807gGEQhDjhgOIglPutwb oA2qahH+AR4srJVo8VEKJlHF24yFdxKvKq/BZxUX2TBYrwqk7yNbiZktA5n1tR3TNBJk bjrkNnOytNh0m3VxTIvRjv6/Nm6GkILeW7Dwm/gqdN8tPVNe1jkrH8oHOtrA58DXY2lO nUx8VC31tMo18H/BreMhTswPHXvEISdlmDHHcq7/FyyXaGLbu7nCE1ZC2nQZ0rQlgBgl 11mGadsZB0GNpXQP0J8DcCPIAQJZ3Ya9hdcfEHFc/r3OL+n8keM5gxE5cQKTqn57HZRo WPtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:subject:cc:to:from :arc-authentication-results; bh=gH1Zt0F0yLyNg/FUr7mDeDQ84wZBIs6byZp2ZofIDY8=; b=ySUkgj66f5NcuV09ELheJg8gUoD+Qpr5BDhm8vLH2IctQQO1SIfrgVsp9IMPP1WHZ9 eT8Ht6WkD72zzIjD0MV5N/CW6/jEpahy+ThujCSZNOU2rci14H01c6bTkwgSCUCYHron QAucnZW82kFibkInx7SVVZOptOISGHucPOKETzGImqTJrKqo0qqXXUzoLoseUbSv4kHp UxXq/zjU6FR0T1CIihGoaMp5CGoBFx0F99N/PWqi9d5p/2sbtYIqWS0Oey8KCrQ6hcOl nWaybNCYYIfaT6TDc46aIzLLuKdUZ+womOU7LOhvOh5rCTALXOoIMqvVtTS/P46xZ/Nu 9n9g== 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 k91si2920048pld.78.2017.10.01.12.50.28; Sun, 01 Oct 2017 12:50:46 -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 S1752405AbdJATsn (ORCPT + 99 others); Sun, 1 Oct 2017 15:48:43 -0400 Received: from mail-out-1.itc.rwth-aachen.de ([134.130.5.46]:31185 "EHLO mail-out-1.itc.rwth-aachen.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751761AbdJATsh (ORCPT ); Sun, 1 Oct 2017 15:48:37 -0400 X-IronPort-AV: E=Sophos;i="5.42,465,1500933600"; d="scan'208";a="16169957" Received: from rwthex-w2-a.rwth-ad.de ([134.130.26.158]) by mail-in-1.itc.rwth-aachen.de with ESMTP; 01 Oct 2017 21:48:35 +0200 Received: from pebbles.fritz.box (78.48.224.164) 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; Sun, 1 Oct 2017 21:48:29 +0200 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= To: CC: Peter Meerwald-Stadler , =?UTF-8?q?Stefan=20Br=C3=BCns?= , , "Andrew F . Davis" , "Javier Martinez Canillas" , Lars-Peter Clausen , Jonathan Cameron , Hartmut Knaack Subject: [PATCH 2/3] iio: adc: ina2xx: Adhere to documented ABI, use Ohm instead of uOhm Date: Sun, 1 Oct 2017 21:48:17 +0200 X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171001194818.26017-1-stefan.bruens@rwth-aachen.de> References: <20171001194818.26017-1-stefan.bruens@rwth-aachen.de> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [78.48.224.164] X-ClientProxiedBy: rwthex-s3-a.rwth-ad.de (2002:8682:1aa0::8682:1aa0) To rwthex-w2-a.rwth-ad.de (2002:8682:1a9e::8682:1a9e) Message-ID: <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 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. 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; -- 2.14.1 From 1586841024986900596@xxx Fri Dec 15 09:18:49 +0000 2017 X-GM-THRID: 1584468874825650605 X-Gmail-Labels: Inbox,Category Forums