[PATCH 2/4] iio: pressure: Add scale value for channels

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

 



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@xxxxxxxxx>
---
 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:
-- 
2.25.1





[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