Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2924313ybz; Mon, 27 Apr 2020 07:03:57 -0700 (PDT) X-Google-Smtp-Source: APiQypLZWwtk7eZ27xz3xuooR4F/CFjrFz9uvsAU8QGczAhqNjsa005bgAtBTEM9BbgEnHObjHBV X-Received: by 2002:a05:6402:356:: with SMTP id r22mr19651698edw.3.1587996236909; Mon, 27 Apr 2020 07:03:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587996236; cv=none; d=google.com; s=arc-20160816; b=aUYO2Jl+IBL7tNGKqnojUNWwHY7x3TQ+2SWP0d6KKkbWlEWWVSPvQ7ciSFRfjOdCOl bG0iezvtMtC8DZOLjBixm+7mu58RSvS7gBB7yCpP8Pjwys3UpOqGYpSwVZwgwgLIG2d3 S2ODB9VTD69hU9qp0E2ZCp3IRtDkTcfnIvXPO1K3xdRTVaXjJcSt2mfpH/D47P2+ghbW DrGYFkzDTtgpkBZOPcPQew2CiNtsroAOn3+rbNW6C9mh9xlsJ33KOo1zPtptBg68T4zB fjyKLNzY88yvaI9Eh3aTAYKWpQMovQnF5Wv2ZQSigZQX1Jqqxyb1BJYa3ma/wbQyzQqW zMMQ== 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=7zWSMLtI9lX/N/RWgbMYs3DP7d0ictgqemSWics9l08=; b=Iv+IP75i/eLxwdQtGmFrgcdCxUWhOVs7KR+u/1FcrYC+phK4zZjiAdCO4wWe4NyS4D wbdLVY/w2+xBN/2S2kfRFW9VY5thllRIv7578kyH7rKjX8Abm+aWLBMzBBi3+C1eVk5F e8QOriUCkuKFp/zeGCLdVNvPdajbzTjUFM2GCmlGxBjyH4Z5HHfTmfdeW3v55QGKdL8S WaRu8MLEW5mQWCxrrAg+5LNd1XxaViso6XtPNI2nOQct9HUtB92kV4VJwp08XM4E5Obn lPbty9+BY4d0RVjcO56g1XmFvHljNgyjl/Q9bMOoCu+L1ioK2vpQuEnO8a2/LGsj3mW2 wf5Q== 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 u1si8606541ejt.47.2020.04.27.07.03.18; Mon, 27 Apr 2020 07:03:56 -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 S1727969AbgD0OA7 (ORCPT + 99 others); Mon, 27 Apr 2020 10:00:59 -0400 Received: from mout.kundenserver.de ([212.227.126.133]:37709 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727824AbgD0OAw (ORCPT ); Mon, 27 Apr 2020 10:00:52 -0400 Received: from localhost ([109.41.194.26]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N6sON-1j7g1g0Aed-018Lsx; Mon, 27 Apr 2020 16:00:23 +0200 Date: Mon, 27 Apr 2020 16:00:19 +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] iio: bmp280: fix compensation of humidity Message-ID: <20200427140017.GA25402@arbad> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-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S58LE1xlf6cVMSdZWIf4/8hdJSbPcVpHqGPeD88euZHwk hsgpcBnRKgH2aPcLcU/Vb1yC2YEm+rOaBZkoMvVc6u89yzMbhY/ZbgpyhA6J2U87LY3dKHx 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. Signed-off-by: Andreas Klinger --- drivers/iio/pressure/bmp280-core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 29c209cc1108..ac9ef1b63b07 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -271,6 +271,9 @@ 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 = var < 0 ? 0 : var; + var = var > 419430400 ? 419430400 : var; + return var >> 12; }; -- 2.20.1