Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1918419lql; Wed, 13 Mar 2024 11:48:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVJW53Ff5g4CVpJ9nRRpjt9ICXwiSLPG6UCPrXU+XTd2XcI1Qz8qTk/vNppLcSMBNFdlCC++pns8y9OKS5WbDDMWy+zM102RVGMQxKQNw== X-Google-Smtp-Source: AGHT+IGEiC79Sors1jfi1xD9s/+nLQmZGvExuMLK8WaT5w2V/DLhKVuY0q5hhmbCrZCeFEB648Lp X-Received: by 2002:a25:aa91:0:b0:dcc:a61b:1a72 with SMTP id t17-20020a25aa91000000b00dcca61b1a72mr3203263ybi.47.1710355725476; Wed, 13 Mar 2024 11:48:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710355725; cv=pass; d=google.com; s=arc-20160816; b=f0GODHLjCvhC7H7fQqNTKK3KnZyYJRlAksIPB5nLeuya1dhkYyB32KLd1P9GOOWL72 pLGIlv8wvTD1174wLEoq/mE2RJRRY75p8iAs++6K009jkKdGpcwuMdQmdESiqgQzeE3G nbkBpOEUnXaH4uSYcWr8xr0WNRiJCnjyNzpCo0OGSVwKw0VYXi7zge2lWhc0X9D8yCae lk2sBlCRP6z0oIBDI5cCrAhHikLqG/zLOAZI5ygAUhSlKq5HOkjhPtE48rD0bvibL3Nc kjREuqiNxc8UYqYs7v2FhdTwBti3gsSd5/T+RRlr5oSGKbSJhr2ULR1rVlVoSXUgO3My 2lJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=myKz1FVxkkY2My67LEfKvneqOReMkZwpEuPPL7ER9GA=; fh=6hf3N2ZclmkQyGc9PA+LqhdoJfc1W2asn1710LBXYg4=; b=lunQmhT7w35s3pdsT7FyZc3hM7uruVeeINA0XJOl2LN/+qEX2JolfO/U5wXhDrWpVZ Sf6sC4GjAn93rbz42MkbnELENkpasGZRfNLlKOCZDKjvcuCUn9YqTt3MxaKV+R0+3gzk 5V1RoHcOjzWaY3Xt7uWXcmHm8JST0i/pTYb0+Pvdsyao4S2a5VCf9JaMgWT2cDocqMqG v1rSl226+v/Sz0nYE5rMvEZJQHpSJ38XqexLU+o3KxrTwgMzTUuzyM73tPmdW/BosBAE Fe0lvhvMc0C6sKrh37aZMYRlpdFNW8rVl6szeF3HV4xTfqZqOk0o1iSG3MqY4s93S1gj KQWg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=avYasxa4; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-102287-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102287-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id i8-20020ac85e48000000b0042eefd04772si10009228qtx.553.2024.03.13.11.48.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 11:48:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-102287-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=avYasxa4; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-102287-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102287-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 881251C25A33 for ; Wed, 13 Mar 2024 18:46:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 251D9131E5C; Wed, 13 Mar 2024 17:40:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="avYasxa4" Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B06012FF9D; Wed, 13 Mar 2024 17:40:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710351625; cv=none; b=tXqSw+GaDGkopPE8auhdETyujp1VnpwzUMFJ4Zkg37rCDDaQDCZenpBU5glaGPSs6e5MbuFJ4ZkeFALy/4CwL1OGUng+hlh5vP7l+W+9zmrthtuyoMVVVzmGukCwNAKFAan6RRGudf43NYsuqish9DEOip5n3hTs8PlqbeZW25g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710351625; c=relaxed/simple; bh=S9zF1Lvby+c7nTni5s4hL/8l9Ch+C18fqZYolOwShGk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rTC6/ODZ5Ms3t2a5p9w/6EIf9JgszHDSDn40lkFl36d280I846kFy0mMc/Ga7G0tgWDtn9/huS3S30hHcdwcxuPpecD+dpIwanvwn3xNkAhNA03h67GiQn8sKaIQaTxb0Z9SLwMGV/TS2KqFlQIPSdZtNfk5hmOtJVOWVo9R7/s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=avYasxa4; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a446b5a08f0so25025366b.1; Wed, 13 Mar 2024 10:40:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710351621; x=1710956421; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=myKz1FVxkkY2My67LEfKvneqOReMkZwpEuPPL7ER9GA=; b=avYasxa4L4gFpsLxajxqWhM+GrtpoA72+qmArUpdjEHsbXifU3qvLlYo1TS0Gkg7Fz JuxWzwoFligD1aWt6bE6qo8fgQyLC9yUOdgO+7MoyQePvw8aQl7BJr1SHc5Z0jQ3Vo3a DT/oT8rkbcFcQIHzlkSqO+X54xTBVpRZEvFsZK1OTCE6UmNx3Ty6UDoCAlUJzeLcKgZf 15eI+e2+zt1nkifgAsw7txU7KpVyy0T8C3L49KfQIx1Nrx5n+yL6wpVkpWZuFL0BtsQY hbkm3HxVdGxtyHMQja2ojdD0d0NxzBLdxd/Ae+gYEbe/gUqjyuTeX8wkFMwJ9rs0h3df Pr/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710351621; x=1710956421; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=myKz1FVxkkY2My67LEfKvneqOReMkZwpEuPPL7ER9GA=; b=wsZ7mX+Ll2jJQqKUy+ybiEnGl9FkfPng3tj/FugNPKsvTP6jyS2WEnb0TNdM7ZMTfw NfOpz0OR7YA+6Mp2INjgbewmALaA+OqjonVYVe5WnsT7rzRsnpQou/RLz4rHRjn4kLMV L0DDUS+gijLNSjS2cYisqBWIqZ5tklaw/bl8toStiLvdNBVjzAQp04hqW4w1jFqYN1qt ir5h0yLN/JMZQ02DLyLEvvmglZFMFcKgGAUCp1jEfmGbfD5K6qoBWrBVsjWCWv9pXcdZ x8XXprFR/V+7qOCdTKsRYgG9Lvt0LSKrOyNVs3Jlv1NitQCB0nX7+TaF65iknzmEKBN2 Y3FA== X-Forwarded-Encrypted: i=1; AJvYcCUy9UA33MRobzhP7x5jd1uP75B5AhM5PODvQy/aKeHNNI+buraY23Pa7gXJVsiuTTdtVKOw0WEU8aAPkzotx07phwhwq0C3Esf7MT+ou/gAre2pRjSBzYJTUpjc2098R85B/YvcTMS1 X-Gm-Message-State: AOJu0YzKbxlhov17ShyPdAmleTqocxrlwcYK/OZUhSN5aT5lPtizttnt YnOw3z+Vw1Qu60RQ7S0u2bLoMpMm8SCulp3iVpDG0Z3BrAlYwLGP X-Received: by 2002:a17:906:4f01:b0:a46:605d:697c with SMTP id t1-20020a1709064f0100b00a46605d697cmr1546466eju.4.1710351621511; Wed, 13 Mar 2024 10:40:21 -0700 (PDT) Received: from localhost.localdomain ([2a04:ee41:82:7577:fa35:157e:1a40:3463]) by smtp.gmail.com with ESMTPSA id m17-20020a1709061ed100b00a449076d0dbsm5028215ejj.53.2024.03.13.10.40.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:40:21 -0700 (PDT) From: Vasileios Amoiridis To: jic23@kernel.org Cc: lars@metafoo.de, andriy.shevchenko@linux.intel.com, ang.iglesiasg@gmail.com, mazziesaccount@gmail.com, ak@it-klinger.de, petre.rodan@subdimension.ro, linus.walleij@linaro.org, phil@raspberrypi.com, 579lpy@gmail.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Vasileios Amoiridis Subject: [PATCH v2 4/6] iio: pressure: Simplify and make more clear temperature readings Date: Wed, 13 Mar 2024 18:40:05 +0100 Message-Id: <20240313174007.1934983-5-vassilisamir@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240313174007.1934983-1-vassilisamir@gmail.com> References: <20240313174007.1934983-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The read_press/read_humid functions need the updated t_fine value in order to calculate the current pressure/humidity. Temperature reads should be removed from the read_press/read_humid functions and should be placed in the oneshot captures before the pressure and humidity reads. This makes the code more intuitive. Signed-off-by: Vasileios Amoiridis --- drivers/iio/pressure/bmp280-core.c | 38 ++++++++++++++---------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 6d7734f867bc..377e90d9e5a2 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -404,11 +404,6 @@ static u32 bmp280_read_press(struct bmp280_data *data) s32 adc_press; int ret; - /* Read and compensate temperature so we get a reading of t_fine. */ - ret = bmp280_read_temp(data); - if (ret < 0) - return ret; - ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, data->buf, sizeof(data->buf)); if (ret < 0) { @@ -433,11 +428,6 @@ static u32 bmp280_read_humid(struct bmp280_data *data) s32 adc_humidity; int ret; - /* Read and compensate temperature so we get a reading of t_fine. */ - ret = bmp280_read_temp(data); - if (ret < 0) - return ret; - ret = regmap_bulk_read(data->regmap, BMP280_REG_HUMIDITY_MSB, &data->be16, sizeof(data->be16)); if (ret < 0) { @@ -470,12 +460,21 @@ static int bmp280_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_PROCESSED: switch (chan->type) { case IIO_HUMIDITYRELATIVE: + /* Read temperature to update the t_fine value */ + data->chip_info->read_temp(data); ret = data->chip_info->read_humid(data); *val = data->chip_info->humid_coeffs[0] * ret; *val2 = data->chip_info->humid_coeffs[1]; ret = IIO_VAL_FRACTIONAL; break; case IIO_PRESSURE: + /* + * Read temperature to update the t_fine value. + * BMP5xx devices do this in hardware, so skip it. + */ + if (strcmp(indio_dev->name, "bmp580")) + data->chip_info->read_temp(data); + ret = data->chip_info->read_press(data); *val = data->chip_info->press_coeffs[0] * ret; *val2 = data->chip_info->press_coeffs[1]; @@ -500,10 +499,19 @@ static int bmp280_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_RAW: switch (chan->type) { case IIO_HUMIDITYRELATIVE: + /* Read temperature to update the t_fine value */ + data->chip_info->read_temp(data); *val = data->chip_info->read_humid(data); ret = IIO_VAL_INT; break; case IIO_PRESSURE: + /* + * Read temperature to update the t_fine value. + * BMP5xx devices do this in hardware, so skip it. + */ + if (strcmp(indio_dev->name, "bmp580")) + data->chip_info->read_temp(data); + *val = data->chip_info->read_press(data); ret = IIO_VAL_INT; break; @@ -1092,11 +1100,6 @@ static u32 bmp380_read_press(struct bmp280_data *data) s32 adc_press; int ret; - /* Read and compensate for temperature so we get a reading of t_fine */ - ret = bmp380_read_temp(data); - if (ret) - return ret; - ret = regmap_bulk_read(data->regmap, BMP380_REG_PRESS_XLSB, data->buf, sizeof(data->buf)); if (ret) { @@ -2009,11 +2012,6 @@ static u32 bmp180_read_press(struct bmp280_data *data) s32 adc_press; int ret; - /* Read and compensate temperature so we get a reading of t_fine. */ - ret = bmp180_read_temp(data); - if (ret) - return ret; - ret = bmp180_read_adc_press(data, &adc_press); if (ret) return ret; -- 2.25.1