From patchwork Fri Apr 17 14:51:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ivan T. Ivanov" X-Patchwork-Id: 47292 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8A56020553 for ; Fri, 17 Apr 2015 14:51:30 +0000 (UTC) Received: by wixv7 with SMTP id v7sf4832219wix.0 for ; Fri, 17 Apr 2015 07:51:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=E5N2az0ttT+W+lSLSWx8+KJQzbneguOiRDSuGFHNvag=; b=ASr75ec25qloNFI3xa/Le4Z6Iecqz02vng+PNTIoHHglyA535ps91rhGlF2wctag9g zd1sKJDVAeiZF9R9jFlH1GD6dy2wpSYxyouIQHTZtOyEGxKfHCSbyK9GGa3VMaEWLozw RMLuhcgJCMGcJO3ajFygwCqbgYPn/DtnXaK+PP4b1ch3G2mlBZGT6ZL5JyID8FDh3L1v iQ5Rg1YWfoKPxwX7itKknejndll2dY6AGSbaRv9uJWXUN2HSepez7DPsA3p6BLeuX5s5 oXNG1NiQsH2oc8Pfl1oUZEGVEo7r9nzgfaktsRrp1g3SBPENxyjRZlRj7NBXcUgDweCa 1zdw== X-Gm-Message-State: ALoCoQkl6H/5w9nFGulgaXxxXKXDvuWtFAMJuKNcgVJZzeqkvXpr63vHpTRhV1PCF0NuLHXMqhJA X-Received: by 10.152.3.70 with SMTP id a6mr293255laa.0.1429282289859; Fri, 17 Apr 2015 07:51:29 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.194 with SMTP id v2ls608138lag.59.gmail; Fri, 17 Apr 2015 07:51:29 -0700 (PDT) X-Received: by 10.152.239.135 with SMTP id vs7mr4369624lac.104.1429282289665; Fri, 17 Apr 2015 07:51:29 -0700 (PDT) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id uf6si8921160lac.168.2015.04.17.07.51.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Apr 2015 07:51:29 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by lbbzk7 with SMTP id zk7so84986988lbb.0 for ; Fri, 17 Apr 2015 07:51:29 -0700 (PDT) X-Received: by 10.152.5.72 with SMTP id q8mr4304550laq.73.1429282289576; Fri, 17 Apr 2015 07:51:29 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.67.65 with SMTP id l1csp30601lbt; Fri, 17 Apr 2015 07:51:28 -0700 (PDT) X-Received: by 10.66.90.134 with SMTP id bw6mr6029534pab.131.1429282286149; Fri, 17 Apr 2015 07:51:26 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id kw1si17044452pab.127.2015.04.17.07.51.25; Fri, 17 Apr 2015 07:51:26 -0700 (PDT) Received-SPF: none (google.com: linux-arm-msm-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965047AbbDQOvS (ORCPT + 5 others); Fri, 17 Apr 2015 10:51:18 -0400 Received: from mail-wi0-f171.google.com ([209.85.212.171]:33980 "EHLO mail-wi0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965424AbbDQOvP (ORCPT ); Fri, 17 Apr 2015 10:51:15 -0400 Received: by widjs5 with SMTP id js5so35669411wid.1 for ; Fri, 17 Apr 2015 07:51:14 -0700 (PDT) X-Received: by 10.194.143.20 with SMTP id sa20mr6570453wjb.16.1429282274743; Fri, 17 Apr 2015 07:51:14 -0700 (PDT) Received: from localhost.localdomain ([37.157.136.206]) by mx.google.com with ESMTPSA id az2sm14982425wjb.4.2015.04.17.07.51.13 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 17 Apr 2015 07:51:14 -0700 (PDT) From: "Ivan T. Ivanov" To: Jonathan Cameron Cc: Stanimir Varbanov , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: [PATCH] iio: adc: spmi-vadc: Fix overflow in output value normalization Date: Fri, 17 Apr 2015 17:51:08 +0300 Message-Id: <1429282268-30501-1-git-send-email-ivan.ivanov@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ivan.ivanov@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , With 'dx' equal to 0.625V and 15 bit ADC, calculations overflow when difference against GND is ~20% of the ADC range. Fix this. Signed-off-by: Ivan T. Ivanov --- drivers/iio/adc/qcom-spmi-vadc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/iio/adc/qcom-spmi-vadc.c b/drivers/iio/adc/qcom-spmi-vadc.c index 3211729..0c4618b 100644 --- a/drivers/iio/adc/qcom-spmi-vadc.c +++ b/drivers/iio/adc/qcom-spmi-vadc.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -471,11 +472,11 @@ static s32 vadc_calibrate(struct vadc_priv *vadc, const struct vadc_channel_prop *prop, u16 adc_code) { const struct vadc_prescale_ratio *prescale; - s32 voltage; + s64 voltage; voltage = adc_code - vadc->graph[prop->calibration].gnd; voltage *= vadc->graph[prop->calibration].dx; - voltage = voltage / vadc->graph[prop->calibration].dy; + voltage = div64_s64(voltage, vadc->graph[prop->calibration].dy); if (prop->calibration == VADC_CALIB_ABSOLUTE) voltage += vadc->graph[prop->calibration].dx; @@ -487,7 +488,7 @@ static s32 vadc_calibrate(struct vadc_priv *vadc, voltage = voltage * prescale->den; - return voltage / prescale->num; + return div64_s64(voltage, prescale->num); } static int vadc_decimation_from_dt(u32 value)