iio: pressure: dps310: simplify scale factor reading
authorThomas Haemmerle <thomas.haemmerle@leica-geosystems.com>
Mon, 15 Apr 2024 10:50:30 +0000 (12:50 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 20 Apr 2024 13:53:02 +0000 (14:53 +0100)
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>
Link: https://lore.kernel.org/r/20240415105030.1161770-5-thomas.haemmerle@leica-geosystems.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/pressure/dps310.c

index c30623d96f0e483a87f53befff9638420c660103..7d882e15e5564a805045ec1fd283d674ac3d8a39 100644 (file)
@@ -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;
 }