Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: pressure: bmp280: Add SCALE, RAW values in channels and refactorize them

Add extra IIO_CHAN_INFO_SCALE and IIO_CHAN_INFO_RAW channels in order
to be able to calculate the processed value with standard userspace
IIO tools. Can be used for triggered buffers as well.

Even though it is not a good design choice to have SCALE, RAW and
PROCESSED together, the PROCESSED channel is kept for ABI compatibility.

While at it, separate BMPxxx and BMExxx device channels since BME
supports also humidity measurements.

Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
Link: https://lore.kernel.org/r/20240512230524.53990-5-vassilisamir@gmail.com
Link: https://patch.msgid.link/20240628171726.124852-3-vassilisamir@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Vasileios Amoiridis and committed by
Jonathan Cameron
479e67ac 74353ceb

+83 -13
+83 -13
drivers/iio/pressure/bmp280-core.c
··· 137 137 static const struct iio_chan_spec bmp280_channels[] = { 138 138 { 139 139 .type = IIO_PRESSURE, 140 + /* PROCESSED maintained for ABI backwards compatibility */ 140 141 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 142 + BIT(IIO_CHAN_INFO_RAW) | 143 + BIT(IIO_CHAN_INFO_SCALE) | 141 144 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 142 145 }, 143 146 { 144 147 .type = IIO_TEMP, 148 + /* PROCESSED maintained for ABI backwards compatibility */ 145 149 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 150 + BIT(IIO_CHAN_INFO_RAW) | 151 + BIT(IIO_CHAN_INFO_SCALE) | 152 + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 153 + }, 154 + }; 155 + 156 + static const struct iio_chan_spec bme280_channels[] = { 157 + { 158 + .type = IIO_PRESSURE, 159 + /* PROCESSED maintained for ABI backwards compatibility */ 160 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 161 + BIT(IIO_CHAN_INFO_RAW) | 162 + BIT(IIO_CHAN_INFO_SCALE) | 163 + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 164 + }, 165 + { 166 + .type = IIO_TEMP, 167 + /* PROCESSED maintained for ABI backwards compatibility */ 168 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 169 + BIT(IIO_CHAN_INFO_RAW) | 170 + BIT(IIO_CHAN_INFO_SCALE) | 146 171 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 147 172 }, 148 173 { 149 174 .type = IIO_HUMIDITYRELATIVE, 175 + /* PROCESSED maintained for ABI backwards compatibility */ 150 176 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 177 + BIT(IIO_CHAN_INFO_RAW) | 178 + BIT(IIO_CHAN_INFO_SCALE) | 151 179 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 152 180 }, 153 181 }; ··· 183 155 static const struct iio_chan_spec bmp380_channels[] = { 184 156 { 185 157 .type = IIO_PRESSURE, 158 + /* PROCESSED maintained for ABI backwards compatibility */ 186 159 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 160 + BIT(IIO_CHAN_INFO_RAW) | 161 + BIT(IIO_CHAN_INFO_SCALE) | 187 162 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 188 163 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | 189 164 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), 190 165 }, 191 166 { 192 167 .type = IIO_TEMP, 168 + /* PROCESSED maintained for ABI backwards compatibility */ 193 169 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 194 - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 195 - .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | 196 - BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), 197 - }, 198 - { 199 - .type = IIO_HUMIDITYRELATIVE, 200 - .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 170 + BIT(IIO_CHAN_INFO_RAW) | 171 + BIT(IIO_CHAN_INFO_SCALE) | 201 172 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 202 173 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | 203 174 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), ··· 564 537 default: 565 538 return -EINVAL; 566 539 } 540 + case IIO_CHAN_INFO_RAW: 541 + switch (chan->type) { 542 + case IIO_HUMIDITYRELATIVE: 543 + ret = data->chip_info->read_humid(data, &chan_value); 544 + if (ret) 545 + return ret; 546 + 547 + *val = chan_value; 548 + return IIO_VAL_INT; 549 + case IIO_PRESSURE: 550 + ret = data->chip_info->read_press(data, &chan_value); 551 + if (ret) 552 + return ret; 553 + 554 + *val = chan_value; 555 + return IIO_VAL_INT; 556 + case IIO_TEMP: 557 + ret = data->chip_info->read_temp(data, &chan_value); 558 + if (ret) 559 + return ret; 560 + 561 + *val = chan_value; 562 + return IIO_VAL_INT; 563 + default: 564 + return -EINVAL; 565 + } 566 + case IIO_CHAN_INFO_SCALE: 567 + switch (chan->type) { 568 + case IIO_HUMIDITYRELATIVE: 569 + *val = data->chip_info->humid_coeffs[0]; 570 + *val2 = data->chip_info->humid_coeffs[1]; 571 + return data->chip_info->humid_coeffs_type; 572 + case IIO_PRESSURE: 573 + *val = data->chip_info->press_coeffs[0]; 574 + *val2 = data->chip_info->press_coeffs[1]; 575 + return data->chip_info->press_coeffs_type; 576 + case IIO_TEMP: 577 + *val = data->chip_info->temp_coeffs[0]; 578 + *val2 = data->chip_info->temp_coeffs[1]; 579 + return data->chip_info->temp_coeffs_type; 580 + default: 581 + return -EINVAL; 582 + } 567 583 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 568 584 switch (chan->type) { 569 585 case IIO_HUMIDITYRELATIVE: ··· 913 843 .regmap_config = &bmp280_regmap_config, 914 844 .start_up_time = 2000, 915 845 .channels = bmp280_channels, 916 - .num_channels = 2, 846 + .num_channels = ARRAY_SIZE(bmp280_channels), 917 847 918 848 .oversampling_temp_avail = bmp280_oversampling_avail, 919 849 .num_oversampling_temp_avail = ARRAY_SIZE(bmp280_oversampling_avail), ··· 973 903 .num_chip_id = ARRAY_SIZE(bme280_chip_ids), 974 904 .regmap_config = &bmp280_regmap_config, 975 905 .start_up_time = 2000, 976 - .channels = bmp280_channels, 977 - .num_channels = 3, 906 + .channels = bme280_channels, 907 + .num_channels = ARRAY_SIZE(bme280_channels), 978 908 979 909 .oversampling_temp_avail = bmp280_oversampling_avail, 980 910 .num_oversampling_temp_avail = ARRAY_SIZE(bmp280_oversampling_avail), ··· 1398 1328 .spi_read_extra_byte = true, 1399 1329 .start_up_time = 2000, 1400 1330 .channels = bmp380_channels, 1401 - .num_channels = 2, 1331 + .num_channels = ARRAY_SIZE(bmp380_channels), 1402 1332 1403 1333 .oversampling_temp_avail = bmp380_oversampling_avail, 1404 1334 .num_oversampling_temp_avail = ARRAY_SIZE(bmp380_oversampling_avail), ··· 1929 1859 .regmap_config = &bmp580_regmap_config, 1930 1860 .start_up_time = 2000, 1931 1861 .channels = bmp380_channels, 1932 - .num_channels = 2, 1862 + .num_channels = ARRAY_SIZE(bmp380_channels), 1933 1863 1934 1864 .oversampling_temp_avail = bmp580_oversampling_avail, 1935 1865 .num_oversampling_temp_avail = ARRAY_SIZE(bmp580_oversampling_avail), ··· 2218 2148 .regmap_config = &bmp180_regmap_config, 2219 2149 .start_up_time = 2000, 2220 2150 .channels = bmp280_channels, 2221 - .num_channels = 2, 2151 + .num_channels = ARRAY_SIZE(bmp280_channels), 2222 2152 2223 2153 .oversampling_temp_avail = bmp180_oversampling_temp_avail, 2224 2154 .num_oversampling_temp_avail =