]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: pressure: mprls0025pa: fix pressure calculation
authorPetre Rodan <petre.rodan@subdimension.ro>
Wed, 14 Jan 2026 16:55:34 +0000 (18:55 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Fri, 16 Jan 2026 17:40:40 +0000 (17:40 +0000)
A sign change is needed for proper calculation of the pressure.

This is a minor fix since it only affects users that might have custom
silicon from Honeywell that has honeywell,pmin-pascal != 0.

Also due to the fact that raw pressure values can not be lower
than output_min (400k-3.3M) there is no need to calculate a decimal for
the offset.

Fixes: 713337d9143e ("iio: pressure: Honeywell mprls0025pa pressure sensor")
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/pressure/mprls0025pa.c
drivers/iio/pressure/mprls0025pa.h

index 6ba45d4c16b301e57c6a7bded9f513e14c7a6651..d4133fef91fac4e57193c96818a3de41cde5074e 100644 (file)
@@ -59,7 +59,7 @@
  *
  * Values given to the userspace in sysfs interface:
  * * raw       - press_cnt
- * * offset    - (-1 * outputmin) - pmin / scale
+ * * offset    - (-1 * outputmin) + pmin / scale
  *                note: With all sensors from the datasheet pmin = 0
  *                which reduces the offset to (-1 * outputmin)
  */
@@ -313,8 +313,7 @@ static int mpr_read_raw(struct iio_dev *indio_dev,
                return IIO_VAL_INT_PLUS_NANO;
        case IIO_CHAN_INFO_OFFSET:
                *val = data->offset;
-               *val2 = data->offset2;
-               return IIO_VAL_INT_PLUS_NANO;
+               return IIO_VAL_INT;
        default:
                return -EINVAL;
        }
@@ -330,8 +329,9 @@ int mpr_common_probe(struct device *dev, const struct mpr_ops *ops, int irq)
        struct mpr_data *data;
        struct iio_dev *indio_dev;
        const char *triplet;
-       s64 scale, offset;
+       s64 odelta, pdelta;
        u32 func;
+       s32 tmp;
 
        indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
        if (!indio_dev)
@@ -405,17 +405,13 @@ int mpr_common_probe(struct device *dev, const struct mpr_ops *ops, int irq)
        data->outmin = mpr_func_spec[data->function].output_min;
        data->outmax = mpr_func_spec[data->function].output_max;
 
-       /* use 64 bit calculation for preserving a reasonable precision */
-       scale = div_s64(((s64)(data->pmax - data->pmin)) * NANO,
-                       data->outmax - data->outmin);
-       data->scale = div_s64_rem(scale, NANO, &data->scale2);
-       /*
-        * multiply with NANO before dividing by scale and later divide by NANO
-        * again.
-        */
-       offset = ((-1LL) * (s64)data->outmin) * NANO -
-                 div_s64(div_s64((s64)data->pmin * NANO, scale), NANO);
-       data->offset = div_s64_rem(offset, NANO, &data->offset2);
+       odelta = data->outmax - data->outmin;
+       pdelta = data->pmax - data->pmin;
+
+       data->scale = div_s64_rem(div_s64(pdelta * NANO, odelta), NANO, &tmp);
+       data->scale2 = tmp;
+
+       data->offset = div_s64(odelta * data->pmin, pdelta) - data->outmin;
 
        if (data->irq > 0) {
                ret = devm_request_irq(dev, data->irq, mpr_eoc_handler, 0,
index d62a018eaff32bdd0dab046057fcd9d60befa3ac..b6944b30512677e388ca325e8e6791ac3f84d764 100644 (file)
@@ -53,7 +53,6 @@ enum mpr_func_id {
  * @scale: pressure scale
  * @scale2: pressure scale, decimal number
  * @offset: pressure offset
- * @offset2: pressure offset, decimal number
  * @gpiod_reset: reset
  * @irq: end of conversion irq. used to distinguish between irq mode and
  *       reading in a loop until data is ready
@@ -75,7 +74,6 @@ struct mpr_data {
        int                     scale;
        int                     scale2;
        int                     offset;
-       int                     offset2;
        struct gpio_desc        *gpiod_reset;
        int                     irq;
        struct completion       completion;