[PATCH] drivers: iio: pressure: dps310: Fix failure to read negative numbers
Paul Menzel
pmenzel at molgen.mpg.de
Thu Feb 1 19:32:53 AEDT 2024
Dear George,
Thank you for your patch.
Am 01.02.24 um 09:25 schrieb George Liu:
> The dps310 chip driver fails to read the temperature when the
> temperature reaches below zero.
Stating, how you fixed this would also be nice.
How did you test this?
> Signed-off-by: George Liu <liuxiwei at ieisystem.com>
> ---
> drivers/iio/pressure/dps310.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
> index 1ff091b2f764..fcbfdc5e85b7 100644
> --- a/drivers/iio/pressure/dps310.c
> +++ b/drivers/iio/pressure/dps310.c
> @@ -730,7 +730,7 @@ static int dps310_read_pressure(struct dps310_data *data, int *val, int *val2,
> }
> }
>
> -static int dps310_calculate_temp(struct dps310_data *data)
> +static int dps310_calculate_temp(struct dps310_data *data, int *val)
> {
> s64 c0;
> s64 t;
> @@ -746,7 +746,9 @@ static int dps310_calculate_temp(struct dps310_data *data)
> t = c0 + ((s64)data->temp_raw * (s64)data->c1);
>
> /* Convert to milliCelsius and scale the temperature */
> - return (int)div_s64(t * 1000LL, kt);
> + *val = (int)div_s64(t * 1000LL, kt);
> +
> + return 0;
> }
This works, because `dps310_get_temp_k` returns the temperature in
Kelvin which cannot be negative?
static int dps310_get_temp_k(struct dps310_data *data)
{
int rc = dps310_get_temp_precision(data);
if (rc < 0)
return rc;
return scale_factors[ilog2(rc)];
}
Kind regards,
Paul
> static int dps310_read_temp(struct dps310_data *data, int *val, int *val2,
> @@ -768,11 +770,10 @@ static int dps310_read_temp(struct dps310_data *data, int *val, int *val2,
> if (rc)
> return rc;
>
> - rc = dps310_calculate_temp(data);
> + rc = dps310_calculate_temp(data, val);
> if (rc < 0)
> return rc;
>
> - *val = rc;
> return IIO_VAL_INT;
>
> case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
More information about the openbmc
mailing list