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 triggered buffer support

BMP2xx, BME280, BMP3xx, and BMP5xx use continuous buffers for their
temperature, pressure and humidity readings. This facilitates the
use of burst/bulk reads in order to acquire data faster. The
approach is different from the one used in oneshot captures.

BMP085 & BMP1xx devices use a completely different measurement
process that is well defined and is used in their buffer_handler().

Suggested-by: Angel Iglesias <ang.iglesiasg@gmail.com>
Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
Link: https://lore.kernel.org/r/20240512230524.53990-6-vassilisamir@gmail.com
Link: https://patch.msgid.link/20240628171726.124852-4-vassilisamir@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Vasileios Amoiridis and committed by
Jonathan Cameron
80cd23f4 479e67ac

+405 -19
+2
drivers/iio/pressure/Kconfig
··· 31 31 select REGMAP 32 32 select BMP280_I2C if (I2C) 33 33 select BMP280_SPI if (SPI_MASTER) 34 + select IIO_BUFFER 35 + select IIO_TRIGGERED_BUFFER 34 36 help 35 37 Say yes here to build support for Bosch Sensortec BMP180, BMP280, BMP380 36 38 and BMP580 pressure and temperature sensors. Also supports the BME280 with
+381 -12
drivers/iio/pressure/bmp280-core.c
··· 41 41 #include <linux/regmap.h> 42 42 #include <linux/regulator/consumer.h> 43 43 44 + #include <linux/iio/buffer.h> 44 45 #include <linux/iio/iio.h> 46 + #include <linux/iio/trigger_consumer.h> 47 + #include <linux/iio/triggered_buffer.h> 45 48 46 49 #include <asm/unaligned.h> 47 50 ··· 137 134 BMP380_P11 = 20, 138 135 }; 139 136 137 + enum bmp280_scan { 138 + BMP280_PRESS, 139 + BMP280_TEMP, 140 + BME280_HUMID, 141 + }; 142 + 140 143 static const struct iio_chan_spec bmp280_channels[] = { 141 144 { 142 145 .type = IIO_PRESSURE, ··· 151 142 BIT(IIO_CHAN_INFO_RAW) | 152 143 BIT(IIO_CHAN_INFO_SCALE) | 153 144 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 145 + .scan_index = 0, 146 + .scan_type = { 147 + .sign = 'u', 148 + .realbits = 32, 149 + .storagebits = 32, 150 + .endianness = IIO_CPU, 151 + }, 154 152 }, 155 153 { 156 154 .type = IIO_TEMP, ··· 166 150 BIT(IIO_CHAN_INFO_RAW) | 167 151 BIT(IIO_CHAN_INFO_SCALE) | 168 152 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 153 + .scan_index = 1, 154 + .scan_type = { 155 + .sign = 's', 156 + .realbits = 32, 157 + .storagebits = 32, 158 + .endianness = IIO_CPU, 159 + }, 169 160 }, 161 + IIO_CHAN_SOFT_TIMESTAMP(2), 170 162 }; 171 163 172 164 static const struct iio_chan_spec bme280_channels[] = { ··· 185 161 BIT(IIO_CHAN_INFO_RAW) | 186 162 BIT(IIO_CHAN_INFO_SCALE) | 187 163 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 164 + .scan_index = 0, 165 + .scan_type = { 166 + .sign = 'u', 167 + .realbits = 32, 168 + .storagebits = 32, 169 + .endianness = IIO_CPU, 170 + }, 188 171 }, 189 172 { 190 173 .type = IIO_TEMP, ··· 200 169 BIT(IIO_CHAN_INFO_RAW) | 201 170 BIT(IIO_CHAN_INFO_SCALE) | 202 171 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 172 + .scan_index = 1, 173 + .scan_type = { 174 + .sign = 's', 175 + .realbits = 32, 176 + .storagebits = 32, 177 + .endianness = IIO_CPU, 178 + }, 203 179 }, 204 180 { 205 181 .type = IIO_HUMIDITYRELATIVE, ··· 215 177 BIT(IIO_CHAN_INFO_RAW) | 216 178 BIT(IIO_CHAN_INFO_SCALE) | 217 179 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 180 + .scan_index = 2, 181 + .scan_type = { 182 + .sign = 'u', 183 + .realbits = 32, 184 + .storagebits = 32, 185 + .endianness = IIO_CPU, 186 + }, 218 187 }, 188 + IIO_CHAN_SOFT_TIMESTAMP(3), 219 189 }; 220 190 221 191 static const struct iio_chan_spec bmp380_channels[] = { ··· 236 190 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 237 191 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | 238 192 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), 193 + .scan_index = 0, 194 + .scan_type = { 195 + .sign = 'u', 196 + .realbits = 32, 197 + .storagebits = 32, 198 + .endianness = IIO_CPU, 199 + }, 239 200 }, 240 201 { 241 202 .type = IIO_TEMP, ··· 253 200 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 254 201 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | 255 202 BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), 203 + .scan_index = 1, 204 + .scan_type = { 205 + .sign = 's', 206 + .realbits = 32, 207 + .storagebits = 32, 208 + .endianness = IIO_CPU, 209 + }, 256 210 }, 211 + IIO_CHAN_SOFT_TIMESTAMP(2), 212 + }; 213 + 214 + static const struct iio_chan_spec bmp580_channels[] = { 215 + { 216 + .type = IIO_PRESSURE, 217 + /* PROCESSED maintained for ABI backwards compatibility */ 218 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 219 + BIT(IIO_CHAN_INFO_RAW) | 220 + BIT(IIO_CHAN_INFO_SCALE) | 221 + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 222 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | 223 + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), 224 + .scan_index = 0, 225 + .scan_type = { 226 + .sign = 'u', 227 + .realbits = 24, 228 + .storagebits = 32, 229 + .endianness = IIO_LE, 230 + }, 231 + }, 232 + { 233 + .type = IIO_TEMP, 234 + /* PROCESSED maintained for ABI backwards compatibility */ 235 + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 236 + BIT(IIO_CHAN_INFO_RAW) | 237 + BIT(IIO_CHAN_INFO_SCALE) | 238 + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 239 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ) | 240 + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY), 241 + .scan_index = 1, 242 + .scan_type = { 243 + .sign = 's', 244 + .realbits = 24, 245 + .storagebits = 32, 246 + .endianness = IIO_LE, 247 + }, 248 + }, 249 + IIO_CHAN_SOFT_TIMESTAMP(2), 257 250 }; 258 251 259 252 static int bmp280_read_calib(struct bmp280_data *data) ··· 415 316 int ret; 416 317 417 318 ret = regmap_bulk_read(data->regmap, BME280_REG_HUMIDITY_MSB, 418 - &data->be16, sizeof(data->be16)); 319 + &data->be16, BME280_NUM_HUMIDITY_BYTES); 419 320 if (ret) { 420 321 dev_err(data->dev, "failed to read humidity\n"); 421 322 return ret; ··· 461 362 int ret; 462 363 463 364 ret = regmap_bulk_read(data->regmap, BMP280_REG_TEMP_MSB, 464 - data->buf, sizeof(data->buf)); 365 + data->buf, BMP280_NUM_TEMP_BYTES); 465 366 if (ret) { 466 367 dev_err(data->dev, "failed to read temperature\n"); 467 368 return ret; ··· 522 423 int ret; 523 424 524 425 ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, 525 - data->buf, sizeof(data->buf)); 426 + data->buf, BMP280_NUM_PRESS_BYTES); 526 427 if (ret) { 527 428 dev_err(data->dev, "failed to read pressure\n"); 528 429 return ret; ··· 973 874 .write_raw = &bmp280_write_raw, 974 875 }; 975 876 877 + static const unsigned long bmp280_avail_scan_masks[] = { 878 + BIT(BMP280_TEMP) | BIT(BMP280_PRESS), 879 + 0 880 + }; 881 + 882 + static const unsigned long bme280_avail_scan_masks[] = { 883 + BIT(BME280_HUMID) | BIT(BMP280_TEMP) | BIT(BMP280_PRESS), 884 + 0 885 + }; 886 + 976 887 static int bmp280_chip_config(struct bmp280_data *data) 977 888 { 978 889 u8 osrs = FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1) | ··· 1010 901 return ret; 1011 902 } 1012 903 904 + static irqreturn_t bmp280_trigger_handler(int irq, void *p) 905 + { 906 + struct iio_poll_func *pf = p; 907 + struct iio_dev *indio_dev = pf->indio_dev; 908 + struct bmp280_data *data = iio_priv(indio_dev); 909 + s32 adc_temp, adc_press, t_fine; 910 + int ret; 911 + 912 + guard(mutex)(&data->lock); 913 + 914 + /* Burst read data registers */ 915 + ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, 916 + data->buf, BMP280_BURST_READ_BYTES); 917 + if (ret) { 918 + dev_err(data->dev, "failed to burst read sensor data\n"); 919 + goto out; 920 + } 921 + 922 + /* Temperature calculations */ 923 + adc_temp = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[3])); 924 + if (adc_temp == BMP280_TEMP_SKIPPED) { 925 + dev_err(data->dev, "reading temperature skipped\n"); 926 + goto out; 927 + } 928 + 929 + data->sensor_data[1] = bmp280_compensate_temp(data, adc_temp); 930 + 931 + /* Pressure calculations */ 932 + adc_press = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[0])); 933 + if (adc_press == BMP280_PRESS_SKIPPED) { 934 + dev_err(data->dev, "reading pressure skipped\n"); 935 + goto out; 936 + } 937 + 938 + t_fine = bmp280_calc_t_fine(data, adc_temp); 939 + 940 + data->sensor_data[0] = bmp280_compensate_press(data, adc_press, t_fine); 941 + 942 + iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, 943 + iio_get_time_ns(indio_dev)); 944 + 945 + out: 946 + iio_trigger_notify_done(indio_dev->trig); 947 + 948 + return IRQ_HANDLED; 949 + } 950 + 1013 951 static const int bmp280_oversampling_avail[] = { 1, 2, 4, 8, 16 }; 1014 952 static const u8 bmp280_chip_ids[] = { BMP280_CHIP_ID }; 1015 953 static const int bmp280_temp_coeffs[] = { 10, 1 }; ··· 1070 914 .start_up_time = 2000, 1071 915 .channels = bmp280_channels, 1072 916 .num_channels = ARRAY_SIZE(bmp280_channels), 917 + .avail_scan_masks = bmp280_avail_scan_masks, 1073 918 1074 919 .oversampling_temp_avail = bmp280_oversampling_avail, 1075 920 .num_oversampling_temp_avail = ARRAY_SIZE(bmp280_oversampling_avail), ··· 1099 942 .read_temp = bmp280_read_temp, 1100 943 .read_press = bmp280_read_press, 1101 944 .read_calib = bmp280_read_calib, 945 + 946 + .trigger_handler = bmp280_trigger_handler, 1102 947 }; 1103 948 EXPORT_SYMBOL_NS(bmp280_chip_info, IIO_BMP280); 1104 949 ··· 1123 964 return bmp280_chip_config(data); 1124 965 } 1125 966 967 + static irqreturn_t bme280_trigger_handler(int irq, void *p) 968 + { 969 + struct iio_poll_func *pf = p; 970 + struct iio_dev *indio_dev = pf->indio_dev; 971 + struct bmp280_data *data = iio_priv(indio_dev); 972 + s32 adc_temp, adc_press, adc_humidity, t_fine; 973 + int ret; 974 + 975 + guard(mutex)(&data->lock); 976 + 977 + /* Burst read data registers */ 978 + ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, 979 + data->buf, BME280_BURST_READ_BYTES); 980 + if (ret) { 981 + dev_err(data->dev, "failed to burst read sensor data\n"); 982 + goto out; 983 + } 984 + 985 + /* Temperature calculations */ 986 + adc_temp = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[3])); 987 + if (adc_temp == BMP280_TEMP_SKIPPED) { 988 + dev_err(data->dev, "reading temperature skipped\n"); 989 + goto out; 990 + } 991 + 992 + data->sensor_data[1] = bmp280_compensate_temp(data, adc_temp); 993 + 994 + /* Pressure calculations */ 995 + adc_press = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[0])); 996 + if (adc_press == BMP280_PRESS_SKIPPED) { 997 + dev_err(data->dev, "reading pressure skipped\n"); 998 + goto out; 999 + } 1000 + 1001 + t_fine = bmp280_calc_t_fine(data, adc_temp); 1002 + 1003 + data->sensor_data[0] = bmp280_compensate_press(data, adc_press, t_fine); 1004 + 1005 + /* Humidity calculations */ 1006 + adc_humidity = get_unaligned_be16(&data->buf[6]); 1007 + 1008 + if (adc_humidity == BMP280_HUMIDITY_SKIPPED) { 1009 + dev_err(data->dev, "reading humidity skipped\n"); 1010 + goto out; 1011 + } 1012 + data->sensor_data[2] = bme280_compensate_humidity(data, adc_humidity, t_fine); 1013 + 1014 + iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, 1015 + iio_get_time_ns(indio_dev)); 1016 + 1017 + out: 1018 + iio_trigger_notify_done(indio_dev->trig); 1019 + 1020 + return IRQ_HANDLED; 1021 + } 1022 + 1126 1023 static const u8 bme280_chip_ids[] = { BME280_CHIP_ID }; 1127 1024 static const int bme280_humid_coeffs[] = { 1000, 1024 }; 1128 1025 ··· 1190 975 .start_up_time = 2000, 1191 976 .channels = bme280_channels, 1192 977 .num_channels = ARRAY_SIZE(bme280_channels), 978 + .avail_scan_masks = bme280_avail_scan_masks, 1193 979 1194 980 .oversampling_temp_avail = bmp280_oversampling_avail, 1195 981 .num_oversampling_temp_avail = ARRAY_SIZE(bmp280_oversampling_avail), ··· 1216 1000 .read_press = bmp280_read_press, 1217 1001 .read_humid = bme280_read_humid, 1218 1002 .read_calib = bme280_read_calib, 1003 + 1004 + .trigger_handler = bme280_trigger_handler, 1219 1005 }; 1220 1006 EXPORT_SYMBOL_NS(bme280_chip_info, IIO_BMP280); 1221 1007 ··· 1272 1054 int ret; 1273 1055 1274 1056 ret = regmap_bulk_read(data->regmap, BMP380_REG_TEMP_XLSB, 1275 - data->buf, sizeof(data->buf)); 1057 + data->buf, BMP280_NUM_TEMP_BYTES); 1276 1058 if (ret) { 1277 1059 dev_err(data->dev, "failed to read temperature\n"); 1278 1060 return ret; ··· 1341 1123 int ret; 1342 1124 1343 1125 ret = regmap_bulk_read(data->regmap, BMP380_REG_PRESS_XLSB, 1344 - data->buf, sizeof(data->buf)); 1126 + data->buf, BMP280_NUM_PRESS_BYTES); 1345 1127 if (ret) { 1346 1128 dev_err(data->dev, "failed to read pressure\n"); 1347 1129 return ret; ··· 1602 1384 return 0; 1603 1385 } 1604 1386 1387 + static irqreturn_t bmp380_trigger_handler(int irq, void *p) 1388 + { 1389 + struct iio_poll_func *pf = p; 1390 + struct iio_dev *indio_dev = pf->indio_dev; 1391 + struct bmp280_data *data = iio_priv(indio_dev); 1392 + s32 adc_temp, adc_press, t_fine; 1393 + int ret; 1394 + 1395 + guard(mutex)(&data->lock); 1396 + 1397 + /* Burst read data registers */ 1398 + ret = regmap_bulk_read(data->regmap, BMP380_REG_PRESS_XLSB, 1399 + data->buf, BMP280_BURST_READ_BYTES); 1400 + if (ret) { 1401 + dev_err(data->dev, "failed to burst read sensor data\n"); 1402 + goto out; 1403 + } 1404 + 1405 + /* Temperature calculations */ 1406 + adc_temp = get_unaligned_le24(&data->buf[3]); 1407 + if (adc_temp == BMP380_TEMP_SKIPPED) { 1408 + dev_err(data->dev, "reading temperature skipped\n"); 1409 + goto out; 1410 + } 1411 + 1412 + data->sensor_data[1] = bmp380_compensate_temp(data, adc_temp); 1413 + 1414 + /* Pressure calculations */ 1415 + adc_press = get_unaligned_le24(&data->buf[0]); 1416 + if (adc_press == BMP380_PRESS_SKIPPED) { 1417 + dev_err(data->dev, "reading pressure skipped\n"); 1418 + goto out; 1419 + } 1420 + 1421 + t_fine = bmp380_calc_t_fine(data, adc_temp); 1422 + 1423 + data->sensor_data[0] = bmp380_compensate_press(data, adc_press, t_fine); 1424 + 1425 + iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, 1426 + iio_get_time_ns(indio_dev)); 1427 + 1428 + out: 1429 + iio_trigger_notify_done(indio_dev->trig); 1430 + 1431 + return IRQ_HANDLED; 1432 + } 1433 + 1605 1434 static const int bmp380_oversampling_avail[] = { 1, 2, 4, 8, 16, 32 }; 1606 1435 static const int bmp380_iir_filter_coeffs_avail[] = { 1, 2, 4, 8, 16, 32, 64, 128}; 1607 1436 static const u8 bmp380_chip_ids[] = { BMP380_CHIP_ID, BMP390_CHIP_ID }; ··· 1664 1399 .start_up_time = 2000, 1665 1400 .channels = bmp380_channels, 1666 1401 .num_channels = ARRAY_SIZE(bmp380_channels), 1402 + .avail_scan_masks = bmp280_avail_scan_masks, 1667 1403 1668 1404 .oversampling_temp_avail = bmp380_oversampling_avail, 1669 1405 .num_oversampling_temp_avail = ARRAY_SIZE(bmp380_oversampling_avail), ··· 1692 1426 .read_press = bmp380_read_press, 1693 1427 .read_calib = bmp380_read_calib, 1694 1428 .preinit = bmp380_preinit, 1429 + 1430 + .trigger_handler = bmp380_trigger_handler, 1695 1431 }; 1696 1432 EXPORT_SYMBOL_NS(bmp380_chip_info, IIO_BMP280); 1697 1433 ··· 1814 1546 s32 value_temp; 1815 1547 int ret; 1816 1548 1817 - ret = regmap_bulk_read(data->regmap, BMP580_REG_TEMP_XLSB, data->buf, 1818 - sizeof(data->buf)); 1549 + ret = regmap_bulk_read(data->regmap, BMP580_REG_TEMP_XLSB, 1550 + data->buf, BMP280_NUM_TEMP_BYTES); 1819 1551 if (ret) { 1820 1552 dev_err(data->dev, "failed to read temperature\n"); 1821 1553 return ret; ··· 1836 1568 u32 value_press; 1837 1569 int ret; 1838 1570 1839 - ret = regmap_bulk_read(data->regmap, BMP580_REG_PRESS_XLSB, data->buf, 1840 - sizeof(data->buf)); 1571 + ret = regmap_bulk_read(data->regmap, BMP580_REG_PRESS_XLSB, 1572 + data->buf, BMP280_NUM_PRESS_BYTES); 1841 1573 if (ret) { 1842 1574 dev_err(data->dev, "failed to read pressure\n"); 1843 1575 return ret; ··· 2184 1916 return 0; 2185 1917 } 2186 1918 1919 + static irqreturn_t bmp580_trigger_handler(int irq, void *p) 1920 + { 1921 + struct iio_poll_func *pf = p; 1922 + struct iio_dev *indio_dev = pf->indio_dev; 1923 + struct bmp280_data *data = iio_priv(indio_dev); 1924 + int ret; 1925 + 1926 + guard(mutex)(&data->lock); 1927 + 1928 + /* Burst read data registers */ 1929 + ret = regmap_bulk_read(data->regmap, BMP580_REG_TEMP_XLSB, 1930 + data->buf, BMP280_BURST_READ_BYTES); 1931 + if (ret) { 1932 + dev_err(data->dev, "failed to burst read sensor data\n"); 1933 + goto out; 1934 + } 1935 + 1936 + /* Temperature calculations */ 1937 + memcpy(&data->sensor_data[1], &data->buf[0], 3); 1938 + 1939 + /* Pressure calculations */ 1940 + memcpy(&data->sensor_data[0], &data->buf[3], 3); 1941 + 1942 + iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, 1943 + iio_get_time_ns(indio_dev)); 1944 + 1945 + out: 1946 + iio_trigger_notify_done(indio_dev->trig); 1947 + 1948 + return IRQ_HANDLED; 1949 + } 1950 + 2187 1951 static const int bmp580_oversampling_avail[] = { 1, 2, 4, 8, 16, 32, 64, 128 }; 2188 1952 static const u8 bmp580_chip_ids[] = { BMP580_CHIP_ID, BMP580_CHIP_ID_ALT }; 2189 1953 /* Instead of { 1000, 16 } we do this, to avoid overflow issues */ ··· 2228 1928 .num_chip_id = ARRAY_SIZE(bmp580_chip_ids), 2229 1929 .regmap_config = &bmp580_regmap_config, 2230 1930 .start_up_time = 2000, 2231 - .channels = bmp380_channels, 2232 - .num_channels = ARRAY_SIZE(bmp380_channels), 1931 + .channels = bmp580_channels, 1932 + .num_channels = ARRAY_SIZE(bmp580_channels), 1933 + .avail_scan_masks = bmp280_avail_scan_masks, 2233 1934 2234 1935 .oversampling_temp_avail = bmp580_oversampling_avail, 2235 1936 .num_oversampling_temp_avail = ARRAY_SIZE(bmp580_oversampling_avail), ··· 2257 1956 .read_temp = bmp580_read_temp, 2258 1957 .read_press = bmp580_read_press, 2259 1958 .preinit = bmp580_preinit, 1959 + 1960 + .trigger_handler = bmp580_trigger_handler, 2260 1961 }; 2261 1962 EXPORT_SYMBOL_NS(bmp580_chip_info, IIO_BMP280); 2262 1963 ··· 2437 2134 return ret; 2438 2135 2439 2136 ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, 2440 - data->buf, sizeof(data->buf)); 2137 + data->buf, BMP280_NUM_PRESS_BYTES); 2441 2138 if (ret) { 2442 2139 dev_err(data->dev, "failed to read pressure\n"); 2443 2140 return ret; ··· 2508 2205 return 0; 2509 2206 } 2510 2207 2208 + static irqreturn_t bmp180_trigger_handler(int irq, void *p) 2209 + { 2210 + struct iio_poll_func *pf = p; 2211 + struct iio_dev *indio_dev = pf->indio_dev; 2212 + struct bmp280_data *data = iio_priv(indio_dev); 2213 + int ret, chan_value; 2214 + 2215 + guard(mutex)(&data->lock); 2216 + 2217 + ret = bmp180_read_temp(data, &chan_value); 2218 + if (ret) 2219 + goto out; 2220 + 2221 + data->sensor_data[1] = chan_value; 2222 + 2223 + ret = bmp180_read_press(data, &chan_value); 2224 + if (ret) 2225 + goto out; 2226 + 2227 + data->sensor_data[0] = chan_value; 2228 + 2229 + iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, 2230 + iio_get_time_ns(indio_dev)); 2231 + 2232 + out: 2233 + iio_trigger_notify_done(indio_dev->trig); 2234 + 2235 + return IRQ_HANDLED; 2236 + } 2237 + 2511 2238 static const int bmp180_oversampling_temp_avail[] = { 1 }; 2512 2239 static const int bmp180_oversampling_press_avail[] = { 1, 2, 4, 8 }; 2513 2240 static const u8 bmp180_chip_ids[] = { BMP180_CHIP_ID }; ··· 2552 2219 .start_up_time = 2000, 2553 2220 .channels = bmp280_channels, 2554 2221 .num_channels = ARRAY_SIZE(bmp280_channels), 2222 + .avail_scan_masks = bmp280_avail_scan_masks, 2555 2223 2556 2224 .oversampling_temp_avail = bmp180_oversampling_temp_avail, 2557 2225 .num_oversampling_temp_avail = ··· 2573 2239 .read_temp = bmp180_read_temp, 2574 2240 .read_press = bmp180_read_press, 2575 2241 .read_calib = bmp180_read_calib, 2242 + 2243 + .trigger_handler = bmp180_trigger_handler, 2576 2244 }; 2577 2245 EXPORT_SYMBOL_NS(bmp180_chip_info, IIO_BMP280); 2578 2246 ··· 2619 2283 data->use_eoc = true; 2620 2284 return 0; 2621 2285 } 2286 + 2287 + static int bmp280_buffer_preenable(struct iio_dev *indio_dev) 2288 + { 2289 + struct bmp280_data *data = iio_priv(indio_dev); 2290 + 2291 + pm_runtime_get_sync(data->dev); 2292 + 2293 + return 0; 2294 + } 2295 + 2296 + static int bmp280_buffer_postdisable(struct iio_dev *indio_dev) 2297 + { 2298 + struct bmp280_data *data = iio_priv(indio_dev); 2299 + 2300 + pm_runtime_mark_last_busy(data->dev); 2301 + pm_runtime_put_autosuspend(data->dev); 2302 + 2303 + return 0; 2304 + } 2305 + 2306 + static const struct iio_buffer_setup_ops bmp280_buffer_setup_ops = { 2307 + .preenable = bmp280_buffer_preenable, 2308 + .postdisable = bmp280_buffer_postdisable, 2309 + }; 2622 2310 2623 2311 static void bmp280_pm_disable(void *data) 2624 2312 { ··· 2690 2330 /* Apply initial values from chip info structure */ 2691 2331 indio_dev->channels = chip_info->channels; 2692 2332 indio_dev->num_channels = chip_info->num_channels; 2333 + indio_dev->available_scan_masks = chip_info->avail_scan_masks; 2693 2334 data->oversampling_press = chip_info->oversampling_press_default; 2694 2335 data->oversampling_humid = chip_info->oversampling_humid_default; 2695 2336 data->oversampling_temp = chip_info->oversampling_temp_default; ··· 2775 2414 return dev_err_probe(data->dev, ret, 2776 2415 "failed to read calibration coefficients\n"); 2777 2416 } 2417 + 2418 + ret = devm_iio_triggered_buffer_setup(data->dev, indio_dev, 2419 + iio_pollfunc_store_time, 2420 + data->chip_info->trigger_handler, 2421 + &bmp280_buffer_setup_ops); 2422 + if (ret) 2423 + return dev_err_probe(data->dev, ret, 2424 + "iio triggered buffer setup failed\n"); 2778 2425 2779 2426 /* 2780 2427 * Attempt to grab an optional EOC IRQ - only the BMP085 has this
+2 -6
drivers/iio/pressure/bmp280-spi.c
··· 40 40 size_t reg_size, void *val, size_t val_size) 41 41 { 42 42 struct spi_device *spi = to_spi_device(context); 43 - u8 rx_buf[4]; 43 + u8 rx_buf[BME280_BURST_READ_BYTES + 1]; 44 44 ssize_t status; 45 45 46 - /* 47 - * Maximum number of consecutive bytes read for a temperature or 48 - * pressure measurement is 3. 49 - */ 50 - if (val_size > 3) 46 + if (val_size > BME280_BURST_READ_BYTES) 51 47 return -EINVAL; 52 48 53 49 /*
+20 -1
drivers/iio/pressure/bmp280.h
··· 304 304 #define BMP280_PRESS_SKIPPED 0x80000 305 305 #define BMP280_HUMIDITY_SKIPPED 0x8000 306 306 307 + /* Number of bytes for each value */ 308 + #define BMP280_NUM_PRESS_BYTES 3 309 + #define BMP280_NUM_TEMP_BYTES 3 310 + #define BME280_NUM_HUMIDITY_BYTES 2 311 + #define BMP280_BURST_READ_BYTES (BMP280_NUM_PRESS_BYTES + \ 312 + BMP280_NUM_TEMP_BYTES) 313 + #define BME280_BURST_READ_BYTES (BMP280_NUM_PRESS_BYTES + \ 314 + BMP280_NUM_TEMP_BYTES + \ 315 + BME280_NUM_HUMIDITY_BYTES) 316 + 307 317 /* Core exported structs */ 308 318 309 319 static const char *const bmp280_supply_names[] = { ··· 408 398 int sampling_freq; 409 399 410 400 /* 401 + * Data to push to userspace triggered buffer. Up to 3 channels and 402 + * s64 timestamp, aligned. 403 + */ 404 + s32 sensor_data[6] __aligned(8); 405 + 406 + /* 411 407 * DMA (thus cache coherency maintenance) may require the 412 408 * transfer buffers to live in their own cache lines. 413 409 */ 414 410 union { 415 411 /* Sensor data buffer */ 416 - u8 buf[3]; 412 + u8 buf[BME280_BURST_READ_BYTES]; 417 413 /* Calibration data buffers */ 418 414 __le16 bmp280_cal_buf[BMP280_CONTIGUOUS_CALIB_REGS / 2]; 419 415 __be16 bmp180_cal_buf[BMP180_REG_CALIB_COUNT / 2]; ··· 441 425 const struct iio_chan_spec *channels; 442 426 int num_channels; 443 427 unsigned int start_up_time; 428 + const unsigned long *avail_scan_masks; 444 429 445 430 const int *oversampling_temp_avail; 446 431 int num_oversampling_temp_avail; ··· 476 459 int (*read_humid)(struct bmp280_data *data, u32 *adc_humidity); 477 460 int (*read_calib)(struct bmp280_data *data); 478 461 int (*preinit)(struct bmp280_data *data); 462 + 463 + irqreturn_t (*trigger_handler)(int irq, void *p); 479 464 }; 480 465 481 466 /* Chip infos for each variant */