From: Vasileios Amoiridis <vassilisamir@gmail.com>
To: jic23@kernel.org
Cc: dpfrey@gmail.com, himanshujha199640@gmail.com, lars@metafoo.de,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
mike.looijmans@topic.nl, vassilisamir@gmail.com
Subject: [PATCH v3 06/15] iio: chemical: bme680: Remove duplicate register read
Date: Mon, 10 Jun 2024 01:38:17 +0200 [thread overview]
Message-ID: <20240609233826.330516-7-vassilisamir@gmail.com> (raw)
In-Reply-To: <20240609233826.330516-1-vassilisamir@gmail.com>
The LSB of the gas register was read first to check if the following
check was correct and then the MSB+LSB were read together. Simplify this
by reading together the MSB+LSB immediately.
Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
---
drivers/iio/chemical/bme680.h | 2 +-
drivers/iio/chemical/bme680_core.c | 21 ++++++++-------------
2 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h
index c51bf2bdf504..b5f16ca81e70 100644
--- a/drivers/iio/chemical/bme680.h
+++ b/drivers/iio/chemical/bme680.h
@@ -46,7 +46,7 @@
#define BME680_RSERROR_MASK GENMASK(7, 4)
#define BME680_REG_RES_HEAT_0 0x5A
#define BME680_REG_GAS_WAIT_0 0x64
-#define BME680_ADC_GAS_RES_SHIFT 6
+#define BME680_ADC_GAS_RES GENMASK(15, 6)
#define BME680_AMB_TEMP 25
#define BME680_REG_CTRL_GAS_1 0x71
diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c
index 72bd5445b6c0..9660ec3854a1 100644
--- a/drivers/iio/chemical/bme680_core.c
+++ b/drivers/iio/chemical/bme680_core.c
@@ -767,7 +767,7 @@ static int bme680_read_gas(struct bme680_data *data,
int ret;
__be16 tmp = 0;
unsigned int check;
- u16 adc_gas_res;
+ u16 adc_gas_res, gas_regs_val;
u8 gas_range;
/* Set heater settings */
@@ -792,11 +792,14 @@ static int bme680_read_gas(struct bme680_data *data,
return -EBUSY;
}
- ret = regmap_read(data->regmap, BME680_REG_GAS_R_LSB, &check);
+ ret = regmap_bulk_read(data->regmap, BME680_REG_GAS_MSB,
+ &tmp, sizeof(tmp));
if (ret < 0) {
- dev_err(dev, "failed to read gas_r_lsb register\n");
+ dev_err(dev, "failed to read gas resistance\n");
return ret;
}
+ gas_regs_val = be16_to_cpu(tmp);
+ adc_gas_res = FIELD_GET(BME680_ADC_GAS_RES, gas_regs_val);
/*
* occurs if either the gas heating duration was insuffient
@@ -804,20 +807,12 @@ static int bme680_read_gas(struct bme680_data *data,
* heater temperature was too high for the heater sink to
* reach.
*/
- if ((check & BME680_GAS_STAB_BIT) == 0) {
+ if ((gas_regs_val & BME680_GAS_STAB_BIT) == 0) {
dev_err(dev, "heater failed to reach the target temperature\n");
return -EINVAL;
}
- ret = regmap_bulk_read(data->regmap, BME680_REG_GAS_MSB,
- &tmp, sizeof(tmp));
- if (ret < 0) {
- dev_err(dev, "failed to read gas resistance\n");
- return ret;
- }
-
- gas_range = check & BME680_GAS_RANGE_MASK;
- adc_gas_res = be16_to_cpu(tmp) >> BME680_ADC_GAS_RES_SHIFT;
+ gas_range = FIELD_GET(BME680_GAS_RANGE_MASK, gas_regs_val);
*val = bme680_compensate_gas(data, adc_gas_res, gas_range);
return IIO_VAL_INT;
--
2.25.1
next prev parent reply other threads:[~2024-06-09 23:38 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-09 23:38 [PATCH v3 00/15] iio: chemical: bme680: Driver cleanup Vasileios Amoiridis
2024-06-09 23:38 ` [PATCH v3 01/15] iio: chemical: bme680: Fix read/write ops to device by adding mutexes Vasileios Amoiridis
2024-06-09 23:38 ` [PATCH v3 02/15] iio: chemical: bme680: Fix typo in define Vasileios Amoiridis
2024-06-09 23:38 ` [PATCH v3 03/15] iio: chemical: bme680: Drop unnecessary casts and correct adc data types Vasileios Amoiridis
2024-06-09 23:38 ` [PATCH v3 04/15] iio: chemical: bme680: Remove remaining ACPI-only stuff Vasileios Amoiridis
2024-06-09 23:38 ` [PATCH v3 05/15] iio: chemical: bme680: Sort headers alphabetically Vasileios Amoiridis
2024-06-09 23:38 ` Vasileios Amoiridis [this message]
2024-06-09 23:38 ` [PATCH v3 07/15] iio: chemical: bme680: Use bulk reads for calibration data Vasileios Amoiridis
2024-06-09 23:38 ` [PATCH v3 08/15] iio: chemical: bme680: Allocate IIO device before chip initialization Vasileios Amoiridis
2024-06-09 23:38 ` [PATCH v3 09/15] iio: chemical: bme680: Add read buffers in read/write buffer union Vasileios Amoiridis
2024-06-09 23:38 ` [PATCH v3 10/15] iio: chemical: bme680: Make error checks consistent Vasileios Amoiridis
2024-06-09 23:38 ` [PATCH v3 11/15] iio: chemical: bme680: Modify startup procedure Vasileios Amoiridis
2024-06-09 23:38 ` [PATCH v3 12/15] iio: chemical: bme680: Move probe errors to dev_err_probe() Vasileios Amoiridis
2024-06-09 23:38 ` [PATCH v3 13/15] iio: chemical: bme680: Remove redundant gas configuration Vasileios Amoiridis
2024-06-09 23:38 ` [PATCH v3 14/15] iio: chemical: bme680: Move forced mode setup in ->read_raw() Vasileios Amoiridis
2024-06-09 23:38 ` [PATCH v3 15/15] iio: chemical: bme680: Refactorize reading functions Vasileios Amoiridis
2024-06-30 20:26 ` [PATCH v3 00/15] iio: chemical: bme680: Driver cleanup Vasileios Amoiridis
2024-07-01 12:44 ` Jonathan Cameron
2024-07-01 17:00 ` Vasileios Amoiridis
2024-07-07 16:41 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240609233826.330516-7-vassilisamir@gmail.com \
--to=vassilisamir@gmail.com \
--cc=dpfrey@gmail.com \
--cc=himanshujha199640@gmail.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mike.looijmans@topic.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox