lkml.org 
[lkml]   [2024]   [Apr]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 4/4] iio: pressure: dps310: simplify scale factor reading
Date
Both functions `dps310_get_pres_precision` and
`dps310_get_temp_precision` provide the oversampling rate by calling the
`BIT()` macro. However, to look up the corresponding scale factor, we
need the register value itself. Currently, this is achieved by undoing
the calculation of the oversampling rate with `ilog2()`.

Simplify the two functions for getting the scale factor and directly
use the register content for the lookup.

Signed-off-by: Thomas Haemmerle <thomas.haemmerle@leica-geosystems.com>
---
drivers/iio/pressure/dps310.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 4abce7e40715..320e34ff9381 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -382,11 +382,11 @@ static int dps310_get_pres_k(struct dps310_data *data, int *val)
{
int reg_val, rc;

- rc = dps310_get_pres_precision(data, &reg_val);
- if (rc)
+ rc = regmap_read(data->regmap, DPS310_PRS_CFG, &reg_val);
+ if (rc < 0)
return rc;

- *val = scale_factors[ilog2(reg_val)];
+ *val = scale_factors[reg_val & GENMASK(2, 0)];

return 0;
}
@@ -395,11 +395,11 @@ static int dps310_get_temp_k(struct dps310_data *data, int *val)
{
int reg_val, rc;

- rc = dps310_get_temp_precision(data, &reg_val);
- if (rc)
+ rc = regmap_read(data->regmap, DPS310_TMP_CFG, &reg_val);
+ if (rc < 0)
return rc;

- *val = scale_factors[ilog2(reg_val)];
+ *val = scale_factors[reg_val & GENMASK(2, 0)];

return 0;
}
--
2.34.1

\
 
 \ /
  Last update: 2024-05-27 16:32    [W:0.082 / U:0.116 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site