Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3003606ybz; Mon, 27 Apr 2020 08:19:19 -0700 (PDT) X-Google-Smtp-Source: APiQypJYmryt5PP86MMUlXR2wcSeipOxBETWplBxvqtnIaUv3O2LBMk9TYXtsks2nuDB2VF+SoG1 X-Received: by 2002:a17:906:7804:: with SMTP id u4mr20761561ejm.328.1588000759336; Mon, 27 Apr 2020 08:19:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588000759; cv=none; d=google.com; s=arc-20160816; b=aYX6d0gMjwXd1Y4u6Bp1ip0BDdGV6+/aWS/gBf9GNrWOv3/CKkJgReFOTICfvhicbZ Rdanh3o1lQ6FtnxQen7E05yc+zTEitr7AjPPLroZtNMxA3jZASSFPRn8l48K7ydm6OPN rHgFwhTfZ5CRjnbdDSsLy5YcHoc5IOx7KRdQtO7FzUZI9ijePxEHJEV4GtWvLv7vgj6h Mxv3WuJK9x8DNE+YwhbCY6YSewR4cbzjRU2lUIohVAnQMYhJnaOHUayT1DLPXRueVfvf zkhoAWTKlrL4TlMjPsChsbOUM00p56kmkDB7YWZJTlTe9dQ60bYOLJW/MbvEeM1iL9kk vo4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=GRpMbtnWp6aIJAJuIqE9d6J18G5G+cNkj0GHG/hOjqU=; b=OBtHmp2ugRPRtkeiP5s+YnwsmeoHui6RxVThG8brJtHS2ZouD1Mas3nxD8/K33rCd8 Febi3R/89gflSZG9l/+8gCzVa+E0sSul8hQO/z5KpE1t4L2kSBGdVPMV3EtCcOlVEZGE QqvXAVwu+rH4UpsZOFvy9ILcM7qantvWybW2FUFBAkEjjZs+4mhQJn60ifhK8XgP79xx t3oVEFgZKciPWU4seAhamdp7X7Ah/rCNdiOsCYkhSuYappvWkUKU1HjTk5eIA/0pd1k2 UgrEHJcSeMTTaXPClUx97lJDCMQwxY5zPwi+ujXPt01898lLa+TnOPJDRBexCMurecmb zAKA== 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 me3si8915025ejb.250.2020.04.27.08.18.55; Mon, 27 Apr 2020 08:19:19 -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 S1728215AbgD0PNs (ORCPT + 99 others); Mon, 27 Apr 2020 11:13:48 -0400 Received: from smtpout1.mo528.mail-out.ovh.net ([46.105.34.251]:44301 "EHLO smtpout1.mo528.mail-out.ovh.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728203AbgD0PNq (ORCPT ); Mon, 27 Apr 2020 11:13:46 -0400 Received: from pro2.mail.ovh.net (unknown [10.108.16.2]) by mo528.mail-out.ovh.net (Postfix) with ESMTPS id 1A4BA5B0A4CF; Mon, 27 Apr 2020 17:13:43 +0200 (CEST) Received: from localhost (89.70.31.203) by DAG2EX1.emp2.local (172.16.2.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1847.3; Mon, 27 Apr 2020 17:13:42 +0200 Date: Mon, 27 Apr 2020 17:12:14 +0200 From: Tomasz Duszynski To: Andreas Klinger CC: , , , , , , , , , Subject: Re: [PATCH] iio: bmp280: fix compensation of humidity Message-ID: <20200427151214.GA6389@arch> References: <20200427140017.GA25402@arbad> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline In-Reply-To: <20200427140017.GA25402@arbad> X-Originating-IP: [89.70.31.203] X-ClientProxiedBy: DAG3EX2.emp2.local (172.16.2.22) To DAG2EX1.emp2.local (172.16.2.11) X-Ovh-Tracer-Id: 17773174454577880249 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduhedrheelgdekgecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpeffhffvuffkfhggtggujghisehttdertddttdejnecuhfhrohhmpefvohhmrghsiicuffhushiihihnshhkihcuoehtohhmrghsiidrughushiihihnshhkihesohgtthgrkhhonhdrtghomheqnecukfhppedtrddtrddtrddtpdekledrjedtrdefuddrvddtfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhhouggvpehsmhhtphdqohhuthdphhgvlhhopehprhhovddrmhgrihhlrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpehtohhmrghsiidrughushiihihnshhkihesohgtthgrkhhonhdrtghomhdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrgh Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 27, 2020 at 04:00:19PM +0200, Andreas Klinger wrote: > 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; > + Looks that clamp_val() might come in handy here. > return var >> 12; > }; > > -- > 2.20.1