Re: [PATCH 3/4] staging:iio:ad5933: Report temperature as raw value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Sep 23, 2014 at 9:04 PM, Lars-Peter Clausen <lars@xxxxxxxxxx> wrote:
> We shouldn't be doing the unit conversion in kernel space. Just report the
> raw value for the property and the scale. Userspace can do the conversion if
> necessary.
>
> Signed-off-by: Lars-Peter Clausen <lars@xxxxxxxxxx>
> ---
>  drivers/staging/iio/impedance-analyzer/ad5933.c | 17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
> index b6bd609..ebff637 100644
> --- a/drivers/staging/iio/impedance-analyzer/ad5933.c
> +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
> @@ -113,7 +113,8 @@ static const struct iio_chan_spec ad5933_channels[] = {
>                 .type = IIO_TEMP,
>                 .indexed = 1,
>                 .channel = 0,
> -               .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> +               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> +                       BIT(IIO_CHAN_INFO_SCALE),
>                 .address = AD5933_REG_TEMP_DATA,
>                 .scan_index = -1,
>                 .scan_type = {
> @@ -522,10 +523,9 @@ static int ad5933_read_raw(struct iio_dev *indio_dev,
>         __be16 dat;
>         int ret = -EINVAL;
>
> -       mutex_lock(&indio_dev->mlock);
>         switch (m) {
>         case IIO_CHAN_INFO_RAW:
> -       case IIO_CHAN_INFO_PROCESSED:
> +               mutex_lock(&indio_dev->mlock);
>                 if (iio_buffer_enabled(indio_dev)) {
>                         ret = -EBUSY;
>                         goto out;
> @@ -543,14 +543,13 @@ static int ad5933_read_raw(struct iio_dev *indio_dev,
>                 if (ret < 0)
>                         goto out;
>                 mutex_unlock(&indio_dev->mlock);
> -               ret = be16_to_cpu(dat);
> -               /* Temp in Milli degrees Celsius */
> -               if (ret < 8192)
> -                       *val = ret * 1000 / 32;
> -               else
> -                       *val = (ret - 16384) * 1000 / 32;
> +               *val = sign_extend32(be16_to_cpu(dat), 13);
>
>                 return IIO_VAL_INT;
> +       case IIO_CHAN_INFO_SCALE:
> +               *val = 1000;
> +               *val2 = 5;
> +               return IIO_VAL_FRACTIONAL_LOG2;
>         }
>
>  out:

Is it possible to reach this line with mutex not acquired?

out:
      mutex_unlock(&indio_dev->mlock);
      return ret;

Daniel.
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux