Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp925867ybz; Wed, 29 Apr 2020 11:51:24 -0700 (PDT) X-Google-Smtp-Source: APiQypJTr4EWEgbLsZ9nnbA4djjxUIZ3bTWDLoD/FWDOIHFSb+PVqjEBGLDnOD7x97Rc+9s5NyZ0 X-Received: by 2002:a17:906:72c8:: with SMTP id m8mr4151009ejl.318.1588186283867; Wed, 29 Apr 2020 11:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588186283; cv=none; d=google.com; s=arc-20160816; b=j3mqoLytyjLmF4B4U1aJPb6pwQiliRWzRuawevllPKYzAs8awXWWizOkTMxbctqoGJ RxNjZxN0ebvLPu9qViDbGP+61CRGyxqDGHDAqKtIm11V9+o9XcILKOpiErHiVVusHANU q6p2cAdw5RFhnuqgrfmTRsQpbFZzT8hlfLS9X3q9VEMq15DBQ3GL43DsRoFu8TRjg+ro vaWiSG15WqAga3D83QGJ27S1lqG7BRP02NX5rIXhOlC5CWXWdR+s0EEpn2YbNJ17sqwv +g7pCZ903iHnkA+pSXzFbsvpskmULVHyOheTEA9j4uKfaGOaqR/BTBEdD8l9hjtHO6NC 3WzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=vKlGL6o5uhVzk2ObtSI1uWz1W1Arqu1PJiYOY/YzS7Y=; b=k4SUvzM0BPWLNNELcFCTVg/NXgSzbZYMOvUvIhrLV4cvQAW3JFYOHb8T+X8H3Jm5N9 h8EfduOqRbgDRqzuDyoXfgnw37GVU/2YA4BLyx9hvtFdDQVMz4gdifgosMMkD3O0ZL2z 4Eeiwuglg+hEmzfDxrrPSNjUBXuDoZQoDJujWTarsQ1dx+qS7RJLOShhT2oqc/GTbU7F V6TgQUWOghLsFB4o2+QkcPB5/k6O1J9dETIrAn4Y9ZGVJnf2oW5iZHvp8obG6pridnkV TKtu2l537qgEXmy9fguyX4CvWuuirh7FujJrRUCZB9AhqwDC0cwm/5g8I4EV3KY5q9FO 9aIQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w10si4451344ejn.246.2020.04.29.11.51.00; Wed, 29 Apr 2020 11:51:23 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726844AbgD2StW (ORCPT + 99 others); Wed, 29 Apr 2020 14:49:22 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:45853 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726423AbgD2StW (ORCPT ); Wed, 29 Apr 2020 14:49:22 -0400 Received: from localhost ([109.41.192.52]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MAgMY-1jItPe1mtU-00B39G; Wed, 29 Apr 2020 20:48:58 +0200 Date: Wed, 29 Apr 2020 20:48:54 +0200 From: Andreas Klinger To: jic23@kernel.org Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, bgolaszewski@baylibre.com, linus.walleij@linaro.org, tglx@linutronix.de, allison@lohutok.net, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] iio: bmp280: fix compensation of humidity Message-ID: <20200429184852.GA17547@arbad> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13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Z4SnKPwC5y+BkIXu8HiatV8Ott81zbb1wUS+6rglMBUwOXxSSLoq4 xJI70s9JAEUbBrsfGvAIWkKwYpImzLsB1QBAco42Plk8iOtnN6U23TulG7J3z5hr6iEkdsW Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Output of humidity compensation is limited to the range between 0 and 100 percent. Add this to the compensation formula as described in the datasheet chapter 4.2.3. Change to v1: Thanks to Tomasz for suggesting the easier to use function clamp_val() which is now used. Signed-off-by: Andreas Klinger --- drivers/iio/pressure/bmp280-core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 29c209cc1108..297ee2205bf6 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -271,6 +271,8 @@ static u32 bmp280_compensate_humidity(struct bmp280_data *data, + (s32)2097152) * calib->H2 + 8192) >> 14); var -= ((((var >> 15) * (var >> 15)) >> 7) * (s32)calib->H1) >> 4; + var = clamp_val(var, 0, 419430400); + return var >> 12; }; -- 2.20.1