Message ID | 20240303165300.468011-3-vassilisamir@gmail.com (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
Series | Series to add triggered buffer support to BMP280 driver | expand |
On Sun, Mar 03, 2024 at 05:52:58PM +0100, Vasileios Amoiridis wrote: > Add extra IIO_CHAN_INFO_SCALE in order to be able to have the scales > for the values in userspace. Can be used for triggered buffers. ... > + case IIO_CHAN_INFO_SCALE: > + switch (chan->type) { > + case IIO_HUMIDITYRELATIVE: > + if (!strcmp(indio_dev->name, "bme280")) { > + *val = 1000; > + *val2 = 1024; > + ret = IIO_VAL_FRACTIONAL; > + } else { > + ret = -EINVAL; > + } No, just make these int arrays part of chip_info, then case IIO_HUMIDITYRELATIVE: if (chip_info->hrel) { *val = chip_info->hrel[0]; *val2 = chip_info->hrel[1]; ret = IIO_VAL_FRACTIONAL; } else { ret = -EINVAL; } > + break; > + case IIO_PRESSURE: > + if ((!strcmp(indio_dev->name, "bmp085")) || > + (!strcmp(indio_dev->name, "bmp180")) || > + (!strcmp(indio_dev->name, "bmp181"))) { > + *val = 1; > + *val2 = 1000; > + ret = IIO_VAL_FRACTIONAL; > + } else if ((!strcmp(indio_dev->name, "bmp280")) || > + (!strcmp(indio_dev->name, "bme280"))) { > + *val = 1; > + *val2 = 256000; > + ret = IIO_VAL_FRACTIONAL; > + } else if (!strcmp(indio_dev->name, "bmp380")) { > + *val = 1; > + *val2 = 100000; > + ret = IIO_VAL_FRACTIONAL; > + } else if (!strcmp(indio_dev->name, "bmp580")) { > + *val = 1; > + *val2 = 64000; > + ret = IIO_VAL_FRACTIONAL; > + } else { > + ret = -EINVAL; > + } > + break; Ditto. > + case IIO_TEMP: > + if ((!strcmp(indio_dev->name, "bmp085")) || > + (!strcmp(indio_dev->name, "bmp180")) || > + (!strcmp(indio_dev->name, "bmp181"))) { > + *val = 100; > + *val2 = 1; > + ret = IIO_VAL_FRACTIONAL; > + } else if ((!strcmp(indio_dev->name, "bmp280")) || > + (!strcmp(indio_dev->name, "bme280"))) { > + *val = 10; > + *val2 = 1; > + ret = IIO_VAL_FRACTIONAL; > + } else if (!strcmp(indio_dev->name, "bmp380")) { > + *val = 10; > + *val2 = 1; > + ret = IIO_VAL_FRACTIONAL; > + } else if (!strcmp(indio_dev->name, "bmp580")) { > + *val = 1000; > + *val2 = 16; > + ret = IIO_VAL_FRACTIONAL_LOG2; > + } else { > + ret = -EINVAL; > + } > + break; Ditto. > + default: > + ret = -EINVAL; > + break; > + } > + break;
On Sun, 3 Mar 2024 17:52:58 +0100 Vasileios Amoiridis <vassilisamir@gmail.com> wrote: > Add extra IIO_CHAN_INFO_SCALE in order to be able to have the scales > for the values in userspace. Can be used for triggered buffers. > > Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com> So providing scale and processed is a mess. With hindsight this should have always provided raw + scale, but too late :( This retrofitting buffered code onto a drive that does processed channels is one of the few reasons I'll let through channels that do both processed and raw. So add raw as well. Hopefully raw * scale always equals processed. The reason is that for a channel doing processed only - assumption is normally that the buffer is processed as well. We can't remove processed as that would be ABI breakage, but we can add raw. Jonathan > --- > drivers/iio/pressure/bmp280-core.c | 70 ++++++++++++++++++++++++++++++ > 1 file changed, 70 insertions(+) > > diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c > index 29a8b7195076..acdf6138d317 100644 > --- a/drivers/iio/pressure/bmp280-core.c > +++ b/drivers/iio/pressure/bmp280-core.c > @@ -138,16 +138,19 @@ static const struct iio_chan_spec bmp280_channels[] = { > { > .type = IIO_PRESSURE, > .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | > + BIT(IIO_CHAN_INFO_SCALE) | > BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), > }, > { > .type = IIO_TEMP, > .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | > + BIT(IIO_CHAN_INFO_SCALE) | > BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), > }, > { > .type = IIO_HUMIDITYRELATIVE, > .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | > + BIT(IIO_CHAN_INFO_SCALE) | > BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), > }, > }; > @@ -156,6 +159,7 @@ static const struct iio_chan_spec bmp380_channels[] = { > { > .type = IIO_PRESSURE, > .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | > + BIT(IIO_CHAN_INFO_SCALE) | > BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), > .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | > BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), > @@ -163,6 +167,7 @@ static const struct iio_chan_spec bmp380_channels[] = { > { > .type = IIO_TEMP, > .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | > + BIT(IIO_CHAN_INFO_SCALE) | > BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), > .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | > BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), > @@ -170,6 +175,7 @@ static const struct iio_chan_spec bmp380_channels[] = { > { > .type = IIO_HUMIDITYRELATIVE, > .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | > + BIT(IIO_CHAN_INFO_SCALE) | > BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), > .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | > BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), > @@ -487,6 +493,70 @@ static int bmp280_read_raw(struct iio_dev *indio_dev, > break; > } > break; > + case IIO_CHAN_INFO_SCALE: > + switch (chan->type) { > + case IIO_HUMIDITYRELATIVE: > + if (!strcmp(indio_dev->name, "bme280")) { > + *val = 1000; > + *val2 = 1024; > + ret = IIO_VAL_FRACTIONAL; > + } else { > + ret = -EINVAL; > + } > + break; > + case IIO_PRESSURE: > + if ((!strcmp(indio_dev->name, "bmp085")) || > + (!strcmp(indio_dev->name, "bmp180")) || > + (!strcmp(indio_dev->name, "bmp181"))) { > + *val = 1; > + *val2 = 1000; > + ret = IIO_VAL_FRACTIONAL; > + } else if ((!strcmp(indio_dev->name, "bmp280")) || > + (!strcmp(indio_dev->name, "bme280"))) { > + *val = 1; > + *val2 = 256000; > + ret = IIO_VAL_FRACTIONAL; > + } else if (!strcmp(indio_dev->name, "bmp380")) { > + *val = 1; > + *val2 = 100000; > + ret = IIO_VAL_FRACTIONAL; > + } else if (!strcmp(indio_dev->name, "bmp580")) { > + *val = 1; > + *val2 = 64000; > + ret = IIO_VAL_FRACTIONAL; > + } else { > + ret = -EINVAL; > + } > + break; > + case IIO_TEMP: > + if ((!strcmp(indio_dev->name, "bmp085")) || > + (!strcmp(indio_dev->name, "bmp180")) || > + (!strcmp(indio_dev->name, "bmp181"))) { > + *val = 100; > + *val2 = 1; > + ret = IIO_VAL_FRACTIONAL; > + } else if ((!strcmp(indio_dev->name, "bmp280")) || > + (!strcmp(indio_dev->name, "bme280"))) { > + *val = 10; > + *val2 = 1; > + ret = IIO_VAL_FRACTIONAL; > + } else if (!strcmp(indio_dev->name, "bmp380")) { > + *val = 10; > + *val2 = 1; > + ret = IIO_VAL_FRACTIONAL; > + } else if (!strcmp(indio_dev->name, "bmp580")) { > + *val = 1000; > + *val2 = 16; > + ret = IIO_VAL_FRACTIONAL_LOG2; > + } else { > + ret = -EINVAL; > + } > + break; > + default: > + ret = -EINVAL; > + break; > + } > + break; > case IIO_CHAN_INFO_OVERSAMPLING_RATIO: > switch (chan->type) { > case IIO_HUMIDITYRELATIVE:
diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 29a8b7195076..acdf6138d317 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -138,16 +138,19 @@ static const struct iio_chan_spec bmp280_channels[] = { { .type = IIO_PRESSURE, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), }, { .type = IIO_TEMP, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), }, { .type = IIO_HUMIDITYRELATIVE, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), }, }; @@ -156,6 +159,7 @@ static const struct iio_chan_spec bmp380_channels[] = { { .type = IIO_PRESSURE, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), @@ -163,6 +167,7 @@ static const struct iio_chan_spec bmp380_channels[] = { { .type = IIO_TEMP, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), @@ -170,6 +175,7 @@ static const struct iio_chan_spec bmp380_channels[] = { { .type = IIO_HUMIDITYRELATIVE, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), @@ -487,6 +493,70 @@ static int bmp280_read_raw(struct iio_dev *indio_dev, break; } break; + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_HUMIDITYRELATIVE: + if (!strcmp(indio_dev->name, "bme280")) { + *val = 1000; + *val2 = 1024; + ret = IIO_VAL_FRACTIONAL; + } else { + ret = -EINVAL; + } + break; + case IIO_PRESSURE: + if ((!strcmp(indio_dev->name, "bmp085")) || + (!strcmp(indio_dev->name, "bmp180")) || + (!strcmp(indio_dev->name, "bmp181"))) { + *val = 1; + *val2 = 1000; + ret = IIO_VAL_FRACTIONAL; + } else if ((!strcmp(indio_dev->name, "bmp280")) || + (!strcmp(indio_dev->name, "bme280"))) { + *val = 1; + *val2 = 256000; + ret = IIO_VAL_FRACTIONAL; + } else if (!strcmp(indio_dev->name, "bmp380")) { + *val = 1; + *val2 = 100000; + ret = IIO_VAL_FRACTIONAL; + } else if (!strcmp(indio_dev->name, "bmp580")) { + *val = 1; + *val2 = 64000; + ret = IIO_VAL_FRACTIONAL; + } else { + ret = -EINVAL; + } + break; + case IIO_TEMP: + if ((!strcmp(indio_dev->name, "bmp085")) || + (!strcmp(indio_dev->name, "bmp180")) || + (!strcmp(indio_dev->name, "bmp181"))) { + *val = 100; + *val2 = 1; + ret = IIO_VAL_FRACTIONAL; + } else if ((!strcmp(indio_dev->name, "bmp280")) || + (!strcmp(indio_dev->name, "bme280"))) { + *val = 10; + *val2 = 1; + ret = IIO_VAL_FRACTIONAL; + } else if (!strcmp(indio_dev->name, "bmp380")) { + *val = 10; + *val2 = 1; + ret = IIO_VAL_FRACTIONAL; + } else if (!strcmp(indio_dev->name, "bmp580")) { + *val = 1000; + *val2 = 16; + ret = IIO_VAL_FRACTIONAL_LOG2; + } else { + ret = -EINVAL; + } + break; + default: + ret = -EINVAL; + break; + } + break; case IIO_CHAN_INFO_OVERSAMPLING_RATIO: switch (chan->type) { case IIO_HUMIDITYRELATIVE:
Add extra IIO_CHAN_INFO_SCALE in order to be able to have the scales for the values in userspace. Can be used for triggered buffers. Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com> --- drivers/iio/pressure/bmp280-core.c | 70 ++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+)