Lines Matching +full:dsp +full:- +full:standby
1 // SPDX-License-Identifier: GPL-2.0-only
12 * https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf
13 * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp280-ds001.pdf
14 * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme280-ds002.pdf
15 * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp388-ds001.pdf
16 * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp390-ds002.pdf
17 * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp581-ds004.pdf
26 * - Changed document referral from ANP015 to BST-MPS-AN004-00 on page 26
27 * - Updated equation for B3 param on section 3.5 to ((((long)AC1 * 4 + X3) << oss) + 2) / 4
28 * - Updated RoHS directive to 2011/65/EU effective 8 June 2011 on page 26
43 #include <linux/nvmem-provider.h>
314 struct bmp280_calib *calib = &data->calib.bmp280; in bmp280_read_calib()
318 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_TEMP_START, in bmp280_read_calib()
319 data->bmp280_cal_buf, in bmp280_read_calib()
320 sizeof(data->bmp280_cal_buf)); in bmp280_read_calib()
322 dev_err(data->dev, in bmp280_read_calib()
328 add_device_randomness(data->bmp280_cal_buf, in bmp280_read_calib()
329 sizeof(data->bmp280_cal_buf)); in bmp280_read_calib()
332 calib->T1 = le16_to_cpu(data->bmp280_cal_buf[T1]); in bmp280_read_calib()
333 calib->T2 = le16_to_cpu(data->bmp280_cal_buf[T2]); in bmp280_read_calib()
334 calib->T3 = le16_to_cpu(data->bmp280_cal_buf[T3]); in bmp280_read_calib()
337 calib->P1 = le16_to_cpu(data->bmp280_cal_buf[P1]); in bmp280_read_calib()
338 calib->P2 = le16_to_cpu(data->bmp280_cal_buf[P2]); in bmp280_read_calib()
339 calib->P3 = le16_to_cpu(data->bmp280_cal_buf[P3]); in bmp280_read_calib()
340 calib->P4 = le16_to_cpu(data->bmp280_cal_buf[P4]); in bmp280_read_calib()
341 calib->P5 = le16_to_cpu(data->bmp280_cal_buf[P5]); in bmp280_read_calib()
342 calib->P6 = le16_to_cpu(data->bmp280_cal_buf[P6]); in bmp280_read_calib()
343 calib->P7 = le16_to_cpu(data->bmp280_cal_buf[P7]); in bmp280_read_calib()
344 calib->P8 = le16_to_cpu(data->bmp280_cal_buf[P8]); in bmp280_read_calib()
345 calib->P9 = le16_to_cpu(data->bmp280_cal_buf[P9]); in bmp280_read_calib()
352 * for BME280. Due to some weird indexing, unaligned BE/LE accesses co-exist in
360 struct bmp280_calib *calib = &data->calib.bmp280; in bme280_read_calib()
361 struct device *dev = data->dev; in bme280_read_calib()
371 ret = regmap_read(data->regmap, BME280_REG_COMP_H1, &tmp); in bme280_read_calib()
376 calib->H1 = tmp; in bme280_read_calib()
378 ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H2, in bme280_read_calib()
379 data->bme280_humid_cal_buf, in bme280_read_calib()
380 sizeof(data->bme280_humid_cal_buf)); in bme280_read_calib()
386 calib->H2 = get_unaligned_le16(&data->bme280_humid_cal_buf[H2]); in bme280_read_calib()
387 calib->H3 = data->bme280_humid_cal_buf[H3]; in bme280_read_calib()
388 tmp_1 = get_unaligned_be16(&data->bme280_humid_cal_buf[H4]); in bme280_read_calib()
392 calib->H4 = sign_extend32(h4_upper | h4_lower, 11); in bme280_read_calib()
393 tmp_3 = get_unaligned_le16(&data->bme280_humid_cal_buf[H5]); in bme280_read_calib()
394 calib->H5 = sign_extend32(FIELD_GET(BME280_COMP_H5_MASK, tmp_3), 11); in bme280_read_calib()
395 calib->H6 = data->bme280_humid_cal_buf[H6]; in bme280_read_calib()
405 ret = regmap_bulk_read(data->regmap, BME280_REG_HUMIDITY_MSB, in bme280_read_humid_adc()
406 &data->be16, BME280_NUM_HUMIDITY_BYTES); in bme280_read_humid_adc()
408 dev_err(data->dev, "failed to read humidity\n"); in bme280_read_humid_adc()
412 value_humidity = be16_to_cpu(data->be16); in bme280_read_humid_adc()
414 dev_err(data->dev, "reading humidity skipped\n"); in bme280_read_humid_adc()
415 return -EIO; in bme280_read_humid_adc()
431 struct bmp280_calib *calib = &data->calib.bmp280; in bme280_compensate_humidity()
434 var = t_fine - (s32)76800; in bme280_compensate_humidity()
435 var = (((((s32)adc_humidity << 14) - (calib->H4 << 20) - (calib->H5 * var)) in bme280_compensate_humidity()
436 + (s32)16384) >> 15) * (((((((var * calib->H6) >> 10) in bme280_compensate_humidity()
437 * (((var * (s32)calib->H3) >> 11) + (s32)32768)) >> 10) in bme280_compensate_humidity()
438 + (s32)2097152) * calib->H2 + 8192) >> 14); in bme280_compensate_humidity()
439 var -= ((((var >> 15) * (var >> 15)) >> 7) * (s32)calib->H1) >> 4; in bme280_compensate_humidity()
451 ret = regmap_bulk_read(data->regmap, BMP280_REG_TEMP_MSB, in bmp280_read_temp_adc()
452 data->buf, BMP280_NUM_TEMP_BYTES); in bmp280_read_temp_adc()
454 dev_err(data->dev, "failed to read temperature\n"); in bmp280_read_temp_adc()
458 value_temp = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(data->buf)); in bmp280_read_temp_adc()
460 dev_err(data->dev, "reading temperature skipped\n"); in bmp280_read_temp_adc()
461 return -EIO; in bmp280_read_temp_adc()
477 struct bmp280_calib *calib = &data->calib.bmp280; in bmp280_calc_t_fine()
480 var1 = (((((s32)adc_temp) >> 3) - ((s32)calib->T1 << 1)) * in bmp280_calc_t_fine()
481 ((s32)calib->T2)) >> 11; in bmp280_calc_t_fine()
482 var2 = (((((((s32)adc_temp) >> 4) - ((s32)calib->T1)) * in bmp280_calc_t_fine()
483 ((((s32)adc_temp >> 4) - ((s32)calib->T1))) >> 12) * in bmp280_calc_t_fine()
484 ((s32)calib->T3))) >> 14; in bmp280_calc_t_fine()
512 ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, in bmp280_read_press_adc()
513 data->buf, BMP280_NUM_PRESS_BYTES); in bmp280_read_press_adc()
515 dev_err(data->dev, "failed to read pressure\n"); in bmp280_read_press_adc()
519 value_press = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(data->buf)); in bmp280_read_press_adc()
521 dev_err(data->dev, "reading pressure skipped\n"); in bmp280_read_press_adc()
522 return -EIO; in bmp280_read_press_adc()
539 struct bmp280_calib *calib = &data->calib.bmp280; in bmp280_compensate_press()
542 var1 = ((s64)t_fine) - 128000; in bmp280_compensate_press()
543 var2 = var1 * var1 * (s64)calib->P6; in bmp280_compensate_press()
544 var2 += (var1 * (s64)calib->P5) << 17; in bmp280_compensate_press()
545 var2 += ((s64)calib->P4) << 35; in bmp280_compensate_press()
546 var1 = ((var1 * var1 * (s64)calib->P3) >> 8) + in bmp280_compensate_press()
547 ((var1 * (s64)calib->P2) << 12); in bmp280_compensate_press()
548 var1 = ((((s64)1) << 47) + var1) * ((s64)calib->P1) >> 33; in bmp280_compensate_press()
553 p = ((((s64)1048576 - (s32)adc_press) << 31) - var2) * 3125; in bmp280_compensate_press()
555 var1 = (((s64)calib->P9) * (p >> 13) * (p >> 13)) >> 25; in bmp280_compensate_press()
556 var2 = ((s64)(calib->P8) * p) >> 19; in bmp280_compensate_press()
557 p = ((p + var1 + var2) >> 8) + (((s64)calib->P7) << 4); in bmp280_compensate_press()
622 guard(mutex)(&data->lock); in bmp280_read_raw_impl()
626 ret = data->chip_info->set_mode(data, BMP280_FORCED); in bmp280_read_raw_impl()
630 ret = data->chip_info->wait_conv(data); in bmp280_read_raw_impl()
634 switch (chan->type) { in bmp280_read_raw_impl()
636 ret = data->chip_info->read_humid(data, &chan_value); in bmp280_read_raw_impl()
640 *val = data->chip_info->humid_coeffs[0] * chan_value; in bmp280_read_raw_impl()
641 *val2 = data->chip_info->humid_coeffs[1]; in bmp280_read_raw_impl()
642 return data->chip_info->humid_coeffs_type; in bmp280_read_raw_impl()
644 ret = data->chip_info->read_press(data, &chan_value); in bmp280_read_raw_impl()
648 *val = data->chip_info->press_coeffs[0] * chan_value; in bmp280_read_raw_impl()
649 *val2 = data->chip_info->press_coeffs[1]; in bmp280_read_raw_impl()
650 return data->chip_info->press_coeffs_type; in bmp280_read_raw_impl()
652 ret = data->chip_info->read_temp(data, &chan_value); in bmp280_read_raw_impl()
656 *val = data->chip_info->temp_coeffs[0] * chan_value; in bmp280_read_raw_impl()
657 *val2 = data->chip_info->temp_coeffs[1]; in bmp280_read_raw_impl()
658 return data->chip_info->temp_coeffs_type; in bmp280_read_raw_impl()
660 return -EINVAL; in bmp280_read_raw_impl()
663 ret = data->chip_info->set_mode(data, BMP280_FORCED); in bmp280_read_raw_impl()
667 ret = data->chip_info->wait_conv(data); in bmp280_read_raw_impl()
671 switch (chan->type) { in bmp280_read_raw_impl()
673 ret = data->chip_info->read_humid(data, &chan_value); in bmp280_read_raw_impl()
680 ret = data->chip_info->read_press(data, &chan_value); in bmp280_read_raw_impl()
687 ret = data->chip_info->read_temp(data, &chan_value); in bmp280_read_raw_impl()
694 return -EINVAL; in bmp280_read_raw_impl()
697 switch (chan->type) { in bmp280_read_raw_impl()
699 *val = data->chip_info->humid_coeffs[0]; in bmp280_read_raw_impl()
700 *val2 = data->chip_info->humid_coeffs[1]; in bmp280_read_raw_impl()
701 return data->chip_info->humid_coeffs_type; in bmp280_read_raw_impl()
703 *val = data->chip_info->press_coeffs[0]; in bmp280_read_raw_impl()
704 *val2 = data->chip_info->press_coeffs[1]; in bmp280_read_raw_impl()
705 return data->chip_info->press_coeffs_type; in bmp280_read_raw_impl()
707 *val = data->chip_info->temp_coeffs[0]; in bmp280_read_raw_impl()
708 *val2 = data->chip_info->temp_coeffs[1]; in bmp280_read_raw_impl()
709 return data->chip_info->temp_coeffs_type; in bmp280_read_raw_impl()
711 return -EINVAL; in bmp280_read_raw_impl()
714 switch (chan->type) { in bmp280_read_raw_impl()
716 *val = 1 << data->oversampling_humid; in bmp280_read_raw_impl()
719 *val = 1 << data->oversampling_press; in bmp280_read_raw_impl()
722 *val = 1 << data->oversampling_temp; in bmp280_read_raw_impl()
725 return -EINVAL; in bmp280_read_raw_impl()
728 if (!data->chip_info->sampling_freq_avail) in bmp280_read_raw_impl()
729 return -EINVAL; in bmp280_read_raw_impl()
731 *val = data->chip_info->sampling_freq_avail[data->sampling_freq][0]; in bmp280_read_raw_impl()
732 *val2 = data->chip_info->sampling_freq_avail[data->sampling_freq][1]; in bmp280_read_raw_impl()
735 if (!data->chip_info->iir_filter_coeffs_avail) in bmp280_read_raw_impl()
736 return -EINVAL; in bmp280_read_raw_impl()
738 *val = (1 << data->iir_filter_coeff) - 1; in bmp280_read_raw_impl()
741 return -EINVAL; in bmp280_read_raw_impl()
752 pm_runtime_get_sync(data->dev); in bmp280_read_raw()
754 pm_runtime_mark_last_busy(data->dev); in bmp280_read_raw()
755 pm_runtime_put_autosuspend(data->dev); in bmp280_read_raw()
763 const int *avail = data->chip_info->oversampling_humid_avail; in bme280_write_oversampling_ratio_humid()
764 const int n = data->chip_info->num_oversampling_humid_avail; in bme280_write_oversampling_ratio_humid()
770 prev = data->oversampling_humid; in bme280_write_oversampling_ratio_humid()
771 data->oversampling_humid = ilog2(val); in bme280_write_oversampling_ratio_humid()
773 ret = data->chip_info->chip_config(data); in bme280_write_oversampling_ratio_humid()
775 data->oversampling_humid = prev; in bme280_write_oversampling_ratio_humid()
776 data->chip_info->chip_config(data); in bme280_write_oversampling_ratio_humid()
782 return -EINVAL; in bme280_write_oversampling_ratio_humid()
788 const int *avail = data->chip_info->oversampling_temp_avail; in bmp280_write_oversampling_ratio_temp()
789 const int n = data->chip_info->num_oversampling_temp_avail; in bmp280_write_oversampling_ratio_temp()
795 prev = data->oversampling_temp; in bmp280_write_oversampling_ratio_temp()
796 data->oversampling_temp = ilog2(val); in bmp280_write_oversampling_ratio_temp()
798 ret = data->chip_info->chip_config(data); in bmp280_write_oversampling_ratio_temp()
800 data->oversampling_temp = prev; in bmp280_write_oversampling_ratio_temp()
801 data->chip_info->chip_config(data); in bmp280_write_oversampling_ratio_temp()
807 return -EINVAL; in bmp280_write_oversampling_ratio_temp()
813 const int *avail = data->chip_info->oversampling_press_avail; in bmp280_write_oversampling_ratio_press()
814 const int n = data->chip_info->num_oversampling_press_avail; in bmp280_write_oversampling_ratio_press()
820 prev = data->oversampling_press; in bmp280_write_oversampling_ratio_press()
821 data->oversampling_press = ilog2(val); in bmp280_write_oversampling_ratio_press()
823 ret = data->chip_info->chip_config(data); in bmp280_write_oversampling_ratio_press()
825 data->oversampling_press = prev; in bmp280_write_oversampling_ratio_press()
826 data->chip_info->chip_config(data); in bmp280_write_oversampling_ratio_press()
832 return -EINVAL; in bmp280_write_oversampling_ratio_press()
838 const int (*avail)[2] = data->chip_info->sampling_freq_avail; in bmp280_write_sampling_frequency()
839 const int n = data->chip_info->num_sampling_freq_avail; in bmp280_write_sampling_frequency()
845 prev = data->sampling_freq; in bmp280_write_sampling_frequency()
846 data->sampling_freq = i; in bmp280_write_sampling_frequency()
848 ret = data->chip_info->chip_config(data); in bmp280_write_sampling_frequency()
850 data->sampling_freq = prev; in bmp280_write_sampling_frequency()
851 data->chip_info->chip_config(data); in bmp280_write_sampling_frequency()
857 return -EINVAL; in bmp280_write_sampling_frequency()
862 const int *avail = data->chip_info->iir_filter_coeffs_avail; in bmp280_write_iir_filter_coeffs()
863 const int n = data->chip_info->num_iir_filter_coeffs_avail; in bmp280_write_iir_filter_coeffs()
868 if (avail[i] - 1 == val) { in bmp280_write_iir_filter_coeffs()
869 prev = data->iir_filter_coeff; in bmp280_write_iir_filter_coeffs()
870 data->iir_filter_coeff = i; in bmp280_write_iir_filter_coeffs()
872 ret = data->chip_info->chip_config(data); in bmp280_write_iir_filter_coeffs()
874 data->iir_filter_coeff = prev; in bmp280_write_iir_filter_coeffs()
875 data->chip_info->chip_config(data); in bmp280_write_iir_filter_coeffs()
882 return -EINVAL; in bmp280_write_iir_filter_coeffs()
891 guard(mutex)(&data->lock); in bmp280_write_raw_impl()
901 switch (chan->type) { in bmp280_write_raw_impl()
909 return -EINVAL; in bmp280_write_raw_impl()
916 return -EINVAL; in bmp280_write_raw_impl()
927 pm_runtime_get_sync(data->dev); in bmp280_write_raw()
929 pm_runtime_mark_last_busy(data->dev); in bmp280_write_raw()
930 pm_runtime_put_autosuspend(data->dev); in bmp280_write_raw()
944 switch (chan->type) { in bmp280_read_avail()
946 *vals = data->chip_info->oversampling_press_avail; in bmp280_read_avail()
947 *length = data->chip_info->num_oversampling_press_avail; in bmp280_read_avail()
950 *vals = data->chip_info->oversampling_temp_avail; in bmp280_read_avail()
951 *length = data->chip_info->num_oversampling_temp_avail; in bmp280_read_avail()
954 return -EINVAL; in bmp280_read_avail()
959 *vals = (const int *)data->chip_info->sampling_freq_avail; in bmp280_read_avail()
962 *length = data->chip_info->num_sampling_freq_avail; in bmp280_read_avail()
965 *vals = data->chip_info->iir_filter_coeffs_avail; in bmp280_read_avail()
967 *length = data->chip_info->num_iir_filter_coeffs_avail; in bmp280_read_avail()
970 return -EINVAL; in bmp280_read_avail()
992 struct device *dev = data->dev; in bmp280_preinit()
996 ret = regmap_write(data->regmap, BMP280_REG_RESET, BMP280_RST_SOFT_CMD); in bmp280_preinit()
1002 * after resetting, the device uses the complete power-on sequence so in bmp280_preinit()
1003 * it needs to wait for the defined start-up time. in bmp280_preinit()
1005 fsleep(data->start_up_time); in bmp280_preinit()
1007 ret = regmap_read(data->regmap, BMP280_REG_STATUS, ®); in bmp280_preinit()
1012 return dev_err_probe(dev, -EIO, "Failed to copy NVM contents.\n"); in bmp280_preinit()
1027 ret = regmap_write_bits(data->regmap, BMP280_REG_CTRL_MEAS, in bmp280_set_mode()
1030 dev_err(data->dev, "failed to write ctrl_meas register.\n"); in bmp280_set_mode()
1034 data->op_mode = mode; in bmp280_set_mode()
1045 if (data->oversampling_humid) in bmp280_wait_conv()
1047 BIT(data->oversampling_humid) * BMP280_MEAS_DUR; in bmp280_wait_conv()
1054 BIT(data->oversampling_press) * BMP280_MEAS_DUR; in bmp280_wait_conv()
1057 meas_time_us += BIT(data->oversampling_temp) * BMP280_MEAS_DUR; in bmp280_wait_conv()
1062 ret = regmap_read(data->regmap, BMP280_REG_STATUS, ®); in bmp280_wait_conv()
1064 dev_err(data->dev, "failed to read status register.\n"); in bmp280_wait_conv()
1069 dev_err(data->dev, "Measurement cycle didn't complete.\n"); in bmp280_wait_conv()
1070 return -EBUSY; in bmp280_wait_conv()
1078 u8 osrs = FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1) | in bmp280_chip_config()
1079 FIELD_PREP(BMP280_OSRS_PRESS_MASK, data->oversampling_press + 1); in bmp280_chip_config()
1082 ret = regmap_write_bits(data->regmap, BMP280_REG_CTRL_MEAS, in bmp280_chip_config()
1088 dev_err(data->dev, "failed to write ctrl_meas register\n"); in bmp280_chip_config()
1092 ret = regmap_update_bits(data->regmap, BMP280_REG_CONFIG, in bmp280_chip_config()
1096 dev_err(data->dev, "failed to write config register\n"); in bmp280_chip_config()
1106 struct iio_dev *indio_dev = pf->indio_dev; in bmp280_trigger_handler()
1110 s32 *chans = (s32 *)data->sensor_data; in bmp280_trigger_handler()
1113 guard(mutex)(&data->lock); in bmp280_trigger_handler()
1116 ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, in bmp280_trigger_handler()
1117 data->buf, BMP280_BURST_READ_BYTES); in bmp280_trigger_handler()
1119 dev_err(data->dev, "failed to burst read sensor data\n"); in bmp280_trigger_handler()
1124 adc_temp = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[3])); in bmp280_trigger_handler()
1126 dev_err(data->dev, "reading temperature skipped\n"); in bmp280_trigger_handler()
1133 adc_press = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[0])); in bmp280_trigger_handler()
1135 dev_err(data->dev, "reading pressure skipped\n"); in bmp280_trigger_handler()
1145 iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data, in bmp280_trigger_handler()
1149 iio_trigger_notify_done(indio_dev->trig); in bmp280_trigger_handler()
1181 .oversampling_temp_default = BMP280_OSRS_TEMP_2X - 1,
1185 .oversampling_press_default = BMP280_OSRS_PRESS_16X - 1,
1206 u8 osrs = FIELD_PREP(BME280_OSRS_HUMIDITY_MASK, data->oversampling_humid + 1); in bme280_chip_config()
1213 ret = regmap_update_bits(data->regmap, BME280_REG_CTRL_HUMIDITY, in bme280_chip_config()
1216 dev_err(data->dev, "failed to set humidity oversampling"); in bme280_chip_config()
1226 struct iio_dev *indio_dev = pf->indio_dev; in bme280_trigger_handler()
1230 s32 *chans = (s32 *)data->sensor_data; in bme280_trigger_handler()
1233 guard(mutex)(&data->lock); in bme280_trigger_handler()
1236 ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, in bme280_trigger_handler()
1237 data->buf, BME280_BURST_READ_BYTES); in bme280_trigger_handler()
1239 dev_err(data->dev, "failed to burst read sensor data\n"); in bme280_trigger_handler()
1244 adc_temp = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[3])); in bme280_trigger_handler()
1246 dev_err(data->dev, "reading temperature skipped\n"); in bme280_trigger_handler()
1253 adc_press = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[0])); in bme280_trigger_handler()
1255 dev_err(data->dev, "reading pressure skipped\n"); in bme280_trigger_handler()
1263 adc_humidity = get_unaligned_be16(&data->buf[6]); in bme280_trigger_handler()
1266 dev_err(data->dev, "reading humidity skipped\n"); in bme280_trigger_handler()
1276 iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data, in bme280_trigger_handler()
1280 iio_trigger_notify_done(indio_dev->trig); in bme280_trigger_handler()
1291 struct device *dev = data->dev; in __bmp280_trigger_probe()
1302 data->trig_active_high = true; in __bmp280_trigger_probe()
1305 data->trig_active_high = false; in __bmp280_trigger_probe()
1308 return dev_err_probe(dev, -EINVAL, "Invalid interrupt type specified.\n"); in __bmp280_trigger_probe()
1311 data->trig_open_drain = in __bmp280_trigger_probe()
1312 fwnode_property_read_bool(dev_fwnode(dev), "int-open-drain"); in __bmp280_trigger_probe()
1318 data->trig = devm_iio_trigger_alloc(data->dev, "%s-dev%d", in __bmp280_trigger_probe()
1319 indio_dev->name, in __bmp280_trigger_probe()
1321 if (!data->trig) in __bmp280_trigger_probe()
1322 return -ENOMEM; in __bmp280_trigger_probe()
1324 data->trig->ops = trigger_ops; in __bmp280_trigger_probe()
1325 iio_trigger_set_drvdata(data->trig, data); in __bmp280_trigger_probe()
1327 ret = devm_request_threaded_irq(data->dev, irq, NULL, in __bmp280_trigger_probe()
1329 indio_dev->name, indio_dev); in __bmp280_trigger_probe()
1333 ret = devm_iio_trigger_register(data->dev, data->trig); in __bmp280_trigger_probe()
1337 indio_dev->trig = iio_trigger_get(data->trig); in __bmp280_trigger_probe()
1357 .oversampling_temp_default = BMP280_OSRS_TEMP_2X - 1,
1361 .oversampling_press_default = BMP280_OSRS_PRESS_16X - 1,
1365 .oversampling_humid_default = BME280_OSRS_HUMIDITY_16X - 1,
1400 ret = regmap_read(data->regmap, BMP380_REG_STATUS, ®); in bmp380_cmd()
1402 dev_err(data->dev, "failed to read error register\n"); in bmp380_cmd()
1406 dev_err(data->dev, "device is not ready to accept commands\n"); in bmp380_cmd()
1407 return -EBUSY; in bmp380_cmd()
1411 ret = regmap_write(data->regmap, BMP380_REG_CMD, cmd); in bmp380_cmd()
1413 dev_err(data->dev, "failed to send command to device\n"); in bmp380_cmd()
1417 usleep_range(data->start_up_time, data->start_up_time + 100); in bmp380_cmd()
1419 ret = regmap_read(data->regmap, BMP380_REG_ERROR, ®); in bmp380_cmd()
1421 dev_err(data->dev, "error reading ERROR reg\n"); in bmp380_cmd()
1425 dev_err(data->dev, "error processing command 0x%X\n", cmd); in bmp380_cmd()
1426 return -EINVAL; in bmp380_cmd()
1437 ret = regmap_bulk_read(data->regmap, BMP380_REG_TEMP_XLSB, in bmp380_read_temp_adc()
1438 data->buf, BMP280_NUM_TEMP_BYTES); in bmp380_read_temp_adc()
1440 dev_err(data->dev, "failed to read temperature\n"); in bmp380_read_temp_adc()
1444 value_temp = get_unaligned_le24(data->buf); in bmp380_read_temp_adc()
1446 dev_err(data->dev, "reading temperature skipped\n"); in bmp380_read_temp_adc()
1447 return -EIO; in bmp380_read_temp_adc()
1459 * https://github.com/BoschSensortec/BMP3-Sensor-API.
1464 struct bmp380_calib *calib = &data->calib.bmp380; in bmp380_calc_t_fine()
1466 var1 = ((s64) adc_temp) - (((s64) calib->T1) << 8); in bmp380_calc_t_fine()
1467 var2 = var1 * ((s64) calib->T2); in bmp380_calc_t_fine()
1469 var4 = var3 * ((s64) calib->T3); in bmp380_calc_t_fine()
1506 ret = regmap_bulk_read(data->regmap, BMP380_REG_PRESS_XLSB, in bmp380_read_press_adc()
1507 data->buf, BMP280_NUM_PRESS_BYTES); in bmp380_read_press_adc()
1509 dev_err(data->dev, "failed to read pressure\n"); in bmp380_read_press_adc()
1513 value_press = get_unaligned_le24(data->buf); in bmp380_read_press_adc()
1515 dev_err(data->dev, "reading pressure skipped\n"); in bmp380_read_press_adc()
1516 return -EIO; in bmp380_read_press_adc()
1528 * https://github.com/BoschSensortec/BMP3-Sensor-API.
1534 struct bmp380_calib *calib = &data->calib.bmp380; in bmp380_compensate_press()
1540 var4 = ((s64)calib->P8 * var3) >> 5; in bmp380_compensate_press()
1541 var5 = ((s64)calib->P7 * var1) << 4; in bmp380_compensate_press()
1542 var6 = ((s64)calib->P6 * (s64)t_fine) << 22; in bmp380_compensate_press()
1543 offset = ((s64)calib->P5 << 47) + var4 + var5 + var6; in bmp380_compensate_press()
1544 var2 = ((s64)calib->P4 * var3) >> 5; in bmp380_compensate_press()
1545 var4 = ((s64)calib->P3 * var1) << 2; in bmp380_compensate_press()
1546 var5 = ((s64)calib->P2 - ((s64)1 << 14)) * in bmp380_compensate_press()
1548 sensitivity = (((s64) calib->P1 - ((s64) 1 << 14)) << 46) + in bmp380_compensate_press()
1551 var2 = (s64)calib->P10 * (s64)t_fine; in bmp380_compensate_press()
1552 var3 = var2 + ((s64)calib->P9 << 16); in bmp380_compensate_press()
1557 * possible overflow caused by (uncomp_data->pressure * partial_data4). in bmp380_compensate_press()
1562 var2 = ((s64)calib->P11 * var6) >> 16; in bmp380_compensate_press()
1605 struct bmp380_calib *calib = &data->calib.bmp380; in bmp380_read_calib()
1609 ret = regmap_bulk_read(data->regmap, BMP380_REG_CALIB_TEMP_START, in bmp380_read_calib()
1610 data->bmp380_cal_buf, in bmp380_read_calib()
1611 sizeof(data->bmp380_cal_buf)); in bmp380_read_calib()
1613 dev_err(data->dev, in bmp380_read_calib()
1619 add_device_randomness(data->bmp380_cal_buf, in bmp380_read_calib()
1620 sizeof(data->bmp380_cal_buf)); in bmp380_read_calib()
1623 calib->T1 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_T1]); in bmp380_read_calib()
1624 calib->T2 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_T2]); in bmp380_read_calib()
1625 calib->T3 = data->bmp380_cal_buf[BMP380_T3]; in bmp380_read_calib()
1626 calib->P1 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_P1]); in bmp380_read_calib()
1627 calib->P2 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_P2]); in bmp380_read_calib()
1628 calib->P3 = data->bmp380_cal_buf[BMP380_P3]; in bmp380_read_calib()
1629 calib->P4 = data->bmp380_cal_buf[BMP380_P4]; in bmp380_read_calib()
1630 calib->P5 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_P5]); in bmp380_read_calib()
1631 calib->P6 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_P6]); in bmp380_read_calib()
1632 calib->P7 = data->bmp380_cal_buf[BMP380_P7]; in bmp380_read_calib()
1633 calib->P8 = data->bmp380_cal_buf[BMP380_P8]; in bmp380_read_calib()
1634 calib->P9 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_P9]); in bmp380_read_calib()
1635 calib->P10 = data->bmp380_cal_buf[BMP380_P10]; in bmp380_read_calib()
1636 calib->P11 = data->bmp380_cal_buf[BMP380_P11]; in bmp380_read_calib()
1664 /* BMP3xx requires soft-reset as part of initialization */ in bmp380_preinit()
1678 ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, in bmp380_set_mode()
1683 dev_err(data->dev, "failed to write power control register.\n"); in bmp380_set_mode()
1687 data->op_mode = mode; in bmp380_set_mode()
1702 BIT(data->oversampling_press) * BMP380_MEAS_DUR; in bmp380_wait_conv()
1706 BIT(data->oversampling_temp) * BMP380_MEAS_DUR; in bmp380_wait_conv()
1711 ret = regmap_read(data->regmap, BMP380_REG_STATUS, ®); in bmp380_wait_conv()
1713 dev_err(data->dev, "failed to read status register.\n"); in bmp380_wait_conv()
1719 dev_err(data->dev, "Measurement cycle didn't complete.\n"); in bmp380_wait_conv()
1720 return -EBUSY; in bmp380_wait_conv()
1734 ret = regmap_update_bits(data->regmap, BMP380_REG_POWER_CONTROL, in bmp380_chip_config()
1739 dev_err(data->dev, in bmp380_chip_config()
1745 osrs = FIELD_PREP(BMP380_OSRS_TEMP_MASK, data->oversampling_temp) | in bmp380_chip_config()
1746 FIELD_PREP(BMP380_OSRS_PRESS_MASK, data->oversampling_press); in bmp380_chip_config()
1748 ret = regmap_update_bits_check(data->regmap, BMP380_REG_OSR, in bmp380_chip_config()
1753 dev_err(data->dev, "failed to write oversampling register\n"); in bmp380_chip_config()
1759 ret = regmap_update_bits_check(data->regmap, BMP380_REG_ODR, in bmp380_chip_config()
1760 BMP380_ODRS_MASK, data->sampling_freq, in bmp380_chip_config()
1763 dev_err(data->dev, "failed to write ODR selection register\n"); in bmp380_chip_config()
1769 ret = regmap_update_bits(data->regmap, BMP380_REG_CONFIG, BMP380_FILTER_MASK, in bmp380_chip_config()
1770 FIELD_PREP(BMP380_FILTER_MASK, data->iir_filter_coeff)); in bmp380_chip_config()
1772 dev_err(data->dev, "failed to write config register\n"); in bmp380_chip_config()
1788 dev_err(data->dev, "failed to set sleep mode\n"); in bmp380_chip_config()
1800 dev_err(data->dev, "failed to set normal mode\n"); in bmp380_chip_config()
1812 ret = regmap_read(data->regmap, BMP380_REG_ERROR, &tmp); in bmp380_chip_config()
1814 dev_err(data->dev, "failed to read error register\n"); in bmp380_chip_config()
1818 dev_warn(data->dev, in bmp380_chip_config()
1820 return -EINVAL; in bmp380_chip_config()
1831 dev_err(data->dev, "failed to set sleep mode.\n"); in bmp380_chip_config()
1842 guard(mutex)(&data->lock); in bmp380_data_rdy_trigger_set_state()
1844 ret = regmap_update_bits(data->regmap, BMP380_REG_INT_CONTROL, in bmp380_data_rdy_trigger_set_state()
1848 dev_err(data->dev, in bmp380_data_rdy_trigger_set_state()
1860 data->trig_open_drain); in bmp380_int_pin_config()
1862 data->trig_active_high); in bmp380_int_pin_config()
1865 ret = regmap_update_bits(data->regmap, BMP380_REG_INT_CONTROL, in bmp380_int_pin_config()
1868 dev_err(data->dev, "Could not set interrupt settings.\n"); in bmp380_int_pin_config()
1880 ret = regmap_read(data->regmap, BMP380_REG_INT_STATUS, &int_ctrl); in bmp380_irq_thread_handler()
1885 iio_trigger_poll_nested(data->trig); in bmp380_irq_thread_handler()
1900 struct iio_dev *indio_dev = pf->indio_dev; in bmp380_trigger_handler()
1904 s32 *chans = (s32 *)data->sensor_data; in bmp380_trigger_handler()
1907 guard(mutex)(&data->lock); in bmp380_trigger_handler()
1910 ret = regmap_bulk_read(data->regmap, BMP380_REG_PRESS_XLSB, in bmp380_trigger_handler()
1911 data->buf, BMP280_BURST_READ_BYTES); in bmp380_trigger_handler()
1913 dev_err(data->dev, "failed to burst read sensor data\n"); in bmp380_trigger_handler()
1918 adc_temp = get_unaligned_le24(&data->buf[3]); in bmp380_trigger_handler()
1920 dev_err(data->dev, "reading temperature skipped\n"); in bmp380_trigger_handler()
1927 adc_press = get_unaligned_le24(&data->buf[0]); in bmp380_trigger_handler()
1929 dev_err(data->dev, "reading pressure skipped\n"); in bmp380_trigger_handler()
1939 iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data, in bmp380_trigger_handler()
1943 iio_trigger_notify_done(indio_dev->trig); in bmp380_trigger_handler()
2004 ret = regmap_write(data->regmap, BMP580_REG_CMD, BMP580_CMD_SOFT_RESET); in bmp580_soft_reset()
2006 dev_err(data->dev, "failed to send reset command to device\n"); in bmp580_soft_reset()
2012 ret = regmap_read(data->regmap, BMP580_REG_CHIP_ID, ®); in bmp580_soft_reset()
2014 dev_err(data->dev, "failed to reestablish comms after reset\n"); in bmp580_soft_reset()
2018 ret = regmap_read(data->regmap, BMP580_REG_INT_STATUS, ®); in bmp580_soft_reset()
2020 dev_err(data->dev, "error reading interrupt status register\n"); in bmp580_soft_reset()
2024 dev_err(data->dev, "error resetting sensor\n"); in bmp580_soft_reset()
2025 return -EINVAL; in bmp580_soft_reset()
2032 * bmp580_nvm_operation() - Helper function to commit NVM memory operations
2043 ret = regmap_read(data->regmap, BMP580_REG_STATUS, ®); in bmp580_nvm_operation()
2045 dev_err(data->dev, "failed to check nvm status\n"); in bmp580_nvm_operation()
2049 dev_err(data->dev, "sensor's nvm is not ready\n"); in bmp580_nvm_operation()
2050 return -EIO; in bmp580_nvm_operation()
2054 ret = regmap_write(data->regmap, BMP580_REG_CMD, in bmp580_nvm_operation()
2057 dev_err(data->dev, in bmp580_nvm_operation()
2063 ret = regmap_write(data->regmap, BMP580_REG_CMD, in bmp580_nvm_operation()
2066 dev_err(data->dev, in bmp580_nvm_operation()
2075 ret = regmap_write(data->regmap, BMP580_REG_CMD, in bmp580_nvm_operation()
2078 dev_err(data->dev, in bmp580_nvm_operation()
2088 ret = regmap_read_poll_timeout(data->regmap, BMP580_REG_STATUS, reg, in bmp580_nvm_operation()
2092 dev_err(data->dev, "error checking nvm operation status\n"); in bmp580_nvm_operation()
2098 dev_err(data->dev, "error processing nvm operation\n"); in bmp580_nvm_operation()
2099 return -EIO; in bmp580_nvm_operation()
2116 ret = regmap_bulk_read(data->regmap, BMP580_REG_TEMP_XLSB, in bmp580_read_temp()
2117 data->buf, BMP280_NUM_TEMP_BYTES); in bmp580_read_temp()
2119 dev_err(data->dev, "failed to read temperature\n"); in bmp580_read_temp()
2123 value_temp = get_unaligned_le24(data->buf); in bmp580_read_temp()
2125 dev_err(data->dev, "reading temperature skipped\n"); in bmp580_read_temp()
2126 return -EIO; in bmp580_read_temp()
2138 ret = regmap_bulk_read(data->regmap, BMP580_REG_PRESS_XLSB, in bmp580_read_press()
2139 data->buf, BMP280_NUM_PRESS_BYTES); in bmp580_read_press()
2141 dev_err(data->dev, "failed to read pressure\n"); in bmp580_read_press()
2145 value_press = get_unaligned_le24(data->buf); in bmp580_read_press()
2147 dev_err(data->dev, "reading pressure skipped\n"); in bmp580_read_press()
2148 return -EIO; in bmp580_read_press()
2199 guard(mutex)(&data->lock); in bmp580_nvmem_read_impl()
2201 /* Set sensor in standby mode */ in bmp580_nvmem_read_impl()
2202 ret = regmap_update_bits(data->regmap, BMP580_REG_ODR_CONFIG, in bmp580_nvmem_read_impl()
2207 dev_err(data->dev, "failed to change sensor to standby mode\n"); in bmp580_nvmem_read_impl()
2210 /* Wait standby transition time */ in bmp580_nvmem_read_impl()
2216 ret = regmap_write(data->regmap, BMP580_REG_NVM_ADDR, in bmp580_nvmem_read_impl()
2219 dev_err(data->dev, "error writing nvm address\n"); in bmp580_nvmem_read_impl()
2227 ret = regmap_bulk_read(data->regmap, BMP580_REG_NVM_DATA_LSB, in bmp580_nvmem_read_impl()
2228 &data->le16, sizeof(data->le16)); in bmp580_nvmem_read_impl()
2230 dev_err(data->dev, "error reading nvm data regs\n"); in bmp580_nvmem_read_impl()
2234 *dst++ = le16_to_cpu(data->le16); in bmp580_nvmem_read_impl()
2235 bytes -= sizeof(*dst); in bmp580_nvmem_read_impl()
2240 data->chip_info->chip_config(data); in bmp580_nvmem_read_impl()
2250 pm_runtime_get_sync(data->dev); in bmp580_nvmem_read()
2252 pm_runtime_mark_last_busy(data->dev); in bmp580_nvmem_read()
2253 pm_runtime_put_autosuspend(data->dev); in bmp580_nvmem_read()
2265 guard(mutex)(&data->lock); in bmp580_nvmem_write_impl()
2267 /* Set sensor in standby mode */ in bmp580_nvmem_write_impl()
2268 ret = regmap_update_bits(data->regmap, BMP580_REG_ODR_CONFIG, in bmp580_nvmem_write_impl()
2273 dev_err(data->dev, "failed to change sensor to standby mode\n"); in bmp580_nvmem_write_impl()
2276 /* Wait standby transition time */ in bmp580_nvmem_write_impl()
2282 ret = regmap_write(data->regmap, BMP580_REG_NVM_ADDR, in bmp580_nvmem_write_impl()
2286 dev_err(data->dev, "error writing nvm address\n"); in bmp580_nvmem_write_impl()
2289 data->le16 = cpu_to_le16(*buf++); in bmp580_nvmem_write_impl()
2291 ret = regmap_bulk_write(data->regmap, BMP580_REG_NVM_DATA_LSB, in bmp580_nvmem_write_impl()
2292 &data->le16, sizeof(data->le16)); in bmp580_nvmem_write_impl()
2294 dev_err(data->dev, "error writing LSB NVM data regs\n"); in bmp580_nvmem_write_impl()
2303 ret = regmap_clear_bits(data->regmap, BMP580_REG_NVM_ADDR, in bmp580_nvmem_write_impl()
2306 dev_err(data->dev, "error resetting nvm write\n"); in bmp580_nvmem_write_impl()
2310 bytes -= sizeof(*buf); in bmp580_nvmem_write_impl()
2315 data->chip_info->chip_config(data); in bmp580_nvmem_write_impl()
2325 pm_runtime_get_sync(data->dev); in bmp580_nvmem_write()
2327 pm_runtime_mark_last_busy(data->dev); in bmp580_nvmem_write()
2328 pm_runtime_put_autosuspend(data->dev); in bmp580_nvmem_write()
2336 .dev = data->dev, in bmp580_preinit()
2348 /* Issue soft-reset command */ in bmp580_preinit()
2354 ret = regmap_read(data->regmap, BMP580_REG_CHIP_ID, ®); in bmp580_preinit()
2356 dev_err(data->dev, "failed to establish comms with the chip\n"); in bmp580_preinit()
2362 dev_warn(data->dev, "unexpected chip_id\n"); in bmp580_preinit()
2364 ret = regmap_read(data->regmap, BMP580_REG_STATUS, ®); in bmp580_preinit()
2366 dev_err(data->dev, "failed to read nvm status\n"); in bmp580_preinit()
2372 dev_err(data->dev, "nvm error on powerup sequence\n"); in bmp580_preinit()
2373 return -EIO; in bmp580_preinit()
2388 struct device *dev = data->dev; in bmp580_set_mode()
2392 ret = regmap_set_bits(data->regmap, BMP580_REG_DSP_CONFIG, in bmp580_set_mode()
2400 ret = regmap_write_bits(data->regmap, BMP580_REG_ODR_CONFIG, in bmp580_set_mode()
2409 data->op_mode = mode; in bmp580_set_mode()
2431 time_conv_temp[data->oversampling_temp] + in bmp580_wait_conv()
2432 time_conv_press[data->oversampling_press]; in bmp580_wait_conv()
2451 /* Sets sensor in standby mode */ in bmp580_chip_config()
2452 ret = regmap_update_bits(data->regmap, BMP580_REG_ODR_CONFIG, in bmp580_chip_config()
2457 dev_err(data->dev, "failed to change sensor to standby mode\n"); in bmp580_chip_config()
2463 /* Set default DSP mode settings */ in bmp580_chip_config()
2467 ret = regmap_update_bits(data->regmap, BMP580_REG_DSP_CONFIG, in bmp580_chip_config()
2472 dev_err(data->dev, "failed to change DSP mode settings\n"); in bmp580_chip_config()
2477 reg_val = FIELD_PREP(BMP580_OSR_TEMP_MASK, data->oversampling_temp) | in bmp580_chip_config()
2478 FIELD_PREP(BMP580_OSR_PRESS_MASK, data->oversampling_press) | in bmp580_chip_config()
2481 ret = regmap_update_bits_check(data->regmap, BMP580_REG_OSR_CONFIG, in bmp580_chip_config()
2487 dev_err(data->dev, "failed to write oversampling register\n"); in bmp580_chip_config()
2493 ret = regmap_update_bits_check(data->regmap, BMP580_REG_ODR_CONFIG, BMP580_ODR_MASK, in bmp580_chip_config()
2494 FIELD_PREP(BMP580_ODR_MASK, data->sampling_freq), in bmp580_chip_config()
2497 dev_err(data->dev, "failed to write ODR configuration register\n"); in bmp580_chip_config()
2503 reg_val = FIELD_PREP(BMP580_DSP_IIR_PRESS_MASK, data->iir_filter_coeff) | in bmp580_chip_config()
2504 FIELD_PREP(BMP580_DSP_IIR_TEMP_MASK, data->iir_filter_coeff); in bmp580_chip_config()
2506 ret = regmap_update_bits(data->regmap, BMP580_REG_DSP_IIR, in bmp580_chip_config()
2510 dev_err(data->dev, "failed to write config register\n"); in bmp580_chip_config()
2519 ret = regmap_read(data->regmap, BMP580_REG_EFF_OSR, &tmp); in bmp580_chip_config()
2521 dev_err(data->dev, in bmp580_chip_config()
2526 dev_warn(data->dev, "OSR and ODR incompatible settings detected\n"); in bmp580_chip_config()
2528 data->oversampling_temp = FIELD_GET(BMP580_EFF_OSR_TEMP_MASK, tmp); in bmp580_chip_config()
2529 data->oversampling_press = FIELD_GET(BMP580_EFF_OSR_PRESS_MASK, tmp); in bmp580_chip_config()
2530 return -EINVAL; in bmp580_chip_config()
2543 guard(mutex)(&data->lock); in bmp580_data_rdy_trigger_set_state()
2545 ret = regmap_update_bits(data->regmap, BMP580_REG_INT_CONFIG, in bmp580_data_rdy_trigger_set_state()
2549 dev_err(data->dev, in bmp580_data_rdy_trigger_set_state()
2561 data->trig_open_drain); in bmp580_int_pin_config()
2563 data->trig_active_high); in bmp580_int_pin_config()
2566 ret = regmap_update_bits(data->regmap, BMP580_REG_INT_CONFIG, in bmp580_int_pin_config()
2569 dev_err(data->dev, "Could not set interrupt settings.\n"); in bmp580_int_pin_config()
2573 ret = regmap_set_bits(data->regmap, BMP580_REG_INT_SOURCE, in bmp580_int_pin_config()
2576 dev_err(data->dev, "Could not set interrupt source.\n"); in bmp580_int_pin_config()
2588 ret = regmap_read(data->regmap, BMP580_REG_INT_STATUS, &int_ctrl); in bmp580_irq_thread_handler()
2593 iio_trigger_poll_nested(data->trig); in bmp580_irq_thread_handler()
2608 struct iio_dev *indio_dev = pf->indio_dev; in bmp580_trigger_handler()
2612 guard(mutex)(&data->lock); in bmp580_trigger_handler()
2615 ret = regmap_bulk_read(data->regmap, BMP580_REG_TEMP_XLSB, in bmp580_trigger_handler()
2616 data->buf, BMP280_BURST_READ_BYTES); in bmp580_trigger_handler()
2618 dev_err(data->dev, "failed to burst read sensor data\n"); in bmp580_trigger_handler()
2625 memcpy(&data->sensor_data[offset], &data->buf[3], 3); in bmp580_trigger_handler()
2630 memcpy(&data->sensor_data[offset], &data->buf[0], 3); in bmp580_trigger_handler()
2632 iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data, in bmp580_trigger_handler()
2636 iio_trigger_notify_done(indio_dev->trig); in bmp580_trigger_handler()
2697 if (data->use_eoc) in bmp180_wait_for_eoc()
2698 reinit_completion(&data->done); in bmp180_wait_for_eoc()
2700 ret = regmap_write(data->regmap, BMP280_REG_CTRL_MEAS, ctrl_meas); in bmp180_wait_for_eoc()
2702 dev_err(data->dev, "failed to write crtl_meas register\n"); in bmp180_wait_for_eoc()
2706 if (data->use_eoc) { in bmp180_wait_for_eoc()
2712 ret = wait_for_completion_timeout(&data->done, in bmp180_wait_for_eoc()
2715 dev_err(data->dev, "timeout waiting for completion\n"); in bmp180_wait_for_eoc()
2721 conversion_time_max[data->oversampling_press]; in bmp180_wait_for_eoc()
2726 ret = regmap_read(data->regmap, BMP280_REG_CTRL_MEAS, &ctrl); in bmp180_wait_for_eoc()
2728 dev_err(data->dev, "failed to read ctrl_meas register\n"); in bmp180_wait_for_eoc()
2734 dev_err(data->dev, "conversion didn't complete\n"); in bmp180_wait_for_eoc()
2735 return -EIO; in bmp180_wait_for_eoc()
2751 ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, in bmp180_read_temp_adc()
2752 &data->be16, sizeof(data->be16)); in bmp180_read_temp_adc()
2754 dev_err(data->dev, "failed to read temperature\n"); in bmp180_read_temp_adc()
2758 *adc_temp = be16_to_cpu(data->be16); in bmp180_read_temp_adc()
2765 struct bmp180_calib *calib = &data->calib.bmp180; in bmp180_read_calib()
2769 ret = regmap_bulk_read(data->regmap, BMP180_REG_CALIB_START, in bmp180_read_calib()
2770 data->bmp180_cal_buf, sizeof(data->bmp180_cal_buf)); in bmp180_read_calib()
2772 dev_err(data->dev, "failed to read calibration parameters\n"); in bmp180_read_calib()
2777 for (i = 0; i < ARRAY_SIZE(data->bmp180_cal_buf); i++) { in bmp180_read_calib()
2778 if (data->bmp180_cal_buf[i] == cpu_to_be16(0) || in bmp180_read_calib()
2779 data->bmp180_cal_buf[i] == cpu_to_be16(0xffff)) in bmp180_read_calib()
2780 return -EIO; in bmp180_read_calib()
2784 add_device_randomness(data->bmp180_cal_buf, in bmp180_read_calib()
2785 sizeof(data->bmp180_cal_buf)); in bmp180_read_calib()
2787 calib->AC1 = be16_to_cpu(data->bmp180_cal_buf[AC1]); in bmp180_read_calib()
2788 calib->AC2 = be16_to_cpu(data->bmp180_cal_buf[AC2]); in bmp180_read_calib()
2789 calib->AC3 = be16_to_cpu(data->bmp180_cal_buf[AC3]); in bmp180_read_calib()
2790 calib->AC4 = be16_to_cpu(data->bmp180_cal_buf[AC4]); in bmp180_read_calib()
2791 calib->AC5 = be16_to_cpu(data->bmp180_cal_buf[AC5]); in bmp180_read_calib()
2792 calib->AC6 = be16_to_cpu(data->bmp180_cal_buf[AC6]); in bmp180_read_calib()
2793 calib->B1 = be16_to_cpu(data->bmp180_cal_buf[B1]); in bmp180_read_calib()
2794 calib->B2 = be16_to_cpu(data->bmp180_cal_buf[B2]); in bmp180_read_calib()
2795 calib->MB = be16_to_cpu(data->bmp180_cal_buf[MB]); in bmp180_read_calib()
2796 calib->MC = be16_to_cpu(data->bmp180_cal_buf[MC]); in bmp180_read_calib()
2797 calib->MD = be16_to_cpu(data->bmp180_cal_buf[MD]); in bmp180_read_calib()
2811 struct bmp180_calib *calib = &data->calib.bmp180; in bmp180_calc_t_fine()
2814 x1 = ((((s32)adc_temp) - calib->AC6) * calib->AC5) >> 15; in bmp180_calc_t_fine()
2815 x2 = (calib->MC << 11) / (x1 + calib->MD); in bmp180_calc_t_fine()
2854 u8 oss = data->oversampling_press; in bmp180_read_press_adc()
2864 ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, in bmp180_read_press_adc()
2865 data->buf, BMP280_NUM_PRESS_BYTES); in bmp180_read_press_adc()
2867 dev_err(data->dev, "failed to read pressure\n"); in bmp180_read_press_adc()
2871 *adc_press = get_unaligned_be24(data->buf) >> (8 - oss); in bmp180_read_press_adc()
2884 struct bmp180_calib *calib = &data->calib.bmp180; in bmp180_compensate_press()
2885 s32 oss = data->oversampling_press; in bmp180_compensate_press()
2890 b6 = t_fine - 4000; in bmp180_compensate_press()
2891 x1 = (calib->B2 * (b6 * b6 >> 12)) >> 11; in bmp180_compensate_press()
2892 x2 = calib->AC2 * b6 >> 11; in bmp180_compensate_press()
2894 b3 = ((((s32)calib->AC1 * 4 + x3) << oss) + 2) / 4; in bmp180_compensate_press()
2895 x1 = calib->AC3 * b6 >> 13; in bmp180_compensate_press()
2896 x2 = (calib->B1 * ((b6 * b6) >> 12)) >> 16; in bmp180_compensate_press()
2898 b4 = calib->AC4 * (u32)(x3 + 32768) >> 15; in bmp180_compensate_press()
2899 b7 = (adc_press - b3) * (50000 >> oss); in bmp180_compensate_press()
2907 x2 = (-7357 * p) >> 16; in bmp180_compensate_press()
2952 struct iio_dev *indio_dev = pf->indio_dev; in bmp180_trigger_handler()
2955 s32 *chans = (s32 *)data->sensor_data; in bmp180_trigger_handler()
2957 guard(mutex)(&data->lock); in bmp180_trigger_handler()
2971 iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data, in bmp180_trigger_handler()
2975 iio_trigger_notify_done(indio_dev->trig); in bmp180_trigger_handler()
3026 complete(&data->done); in bmp085_eoc_irq()
3034 struct device *dev = data->dev; in bmp085_trigger_probe()
3044 dev_err(dev, "non-rising trigger given for EOC interrupt, trying to enforce it\n"); in bmp085_trigger_probe()
3048 init_completion(&data->done); in bmp085_trigger_probe()
3051 indio_dev->name, data); in bmp085_trigger_probe()
3058 data->use_eoc = true; in bmp085_trigger_probe()
3105 pm_runtime_get_sync(data->dev); in bmp280_buffer_preenable()
3106 data->chip_info->set_mode(data, BMP280_NORMAL); in bmp280_buffer_preenable()
3115 pm_runtime_mark_last_busy(data->dev); in bmp280_buffer_postdisable()
3116 pm_runtime_put_autosuspend(data->dev); in bmp280_buffer_postdisable()
3157 return -ENOMEM; in bmp280_common_probe()
3160 mutex_init(&data->lock); in bmp280_common_probe()
3161 data->dev = dev; in bmp280_common_probe()
3163 indio_dev->name = name; in bmp280_common_probe()
3164 indio_dev->info = &bmp280_info; in bmp280_common_probe()
3165 indio_dev->modes = INDIO_DIRECT_MODE; in bmp280_common_probe()
3167 data->chip_info = chip_info; in bmp280_common_probe()
3170 indio_dev->channels = chip_info->channels; in bmp280_common_probe()
3171 indio_dev->num_channels = chip_info->num_channels; in bmp280_common_probe()
3172 indio_dev->available_scan_masks = chip_info->avail_scan_masks; in bmp280_common_probe()
3173 data->oversampling_press = chip_info->oversampling_press_default; in bmp280_common_probe()
3174 data->oversampling_humid = chip_info->oversampling_humid_default; in bmp280_common_probe()
3175 data->oversampling_temp = chip_info->oversampling_temp_default; in bmp280_common_probe()
3176 data->iir_filter_coeff = chip_info->iir_filter_coeff_default; in bmp280_common_probe()
3177 data->sampling_freq = chip_info->sampling_freq_default; in bmp280_common_probe()
3178 data->start_up_time = chip_info->start_up_time; in bmp280_common_probe()
3181 regulator_bulk_set_supply_names(data->supplies, in bmp280_common_probe()
3186 BMP280_NUM_SUPPLIES, data->supplies); in bmp280_common_probe()
3192 ret = regulator_bulk_enable(BMP280_NUM_SUPPLIES, data->supplies); in bmp280_common_probe()
3199 data->supplies); in bmp280_common_probe()
3204 usleep_range(data->start_up_time, data->start_up_time + 100); in bmp280_common_probe()
3214 data->regmap = regmap; in bmp280_common_probe()
3216 ret = regmap_read(regmap, data->chip_info->id_reg, &chip_id); in bmp280_common_probe()
3218 dev_err(data->dev, "failed to read chip id\n"); in bmp280_common_probe()
3222 for (i = 0; i < data->chip_info->num_chip_id; i++) { in bmp280_common_probe()
3223 if (chip_id == data->chip_info->chip_id[i]) { in bmp280_common_probe()
3229 if (i == data->chip_info->num_chip_id) in bmp280_common_probe()
3232 if (data->chip_info->preinit) { in bmp280_common_probe()
3233 ret = data->chip_info->preinit(data); in bmp280_common_probe()
3235 return dev_err_probe(data->dev, ret, in bmp280_common_probe()
3239 ret = data->chip_info->chip_config(data); in bmp280_common_probe()
3247 * non-volatile memory during production". Let's read them out at probe in bmp280_common_probe()
3251 if (data->chip_info->read_calib) { in bmp280_common_probe()
3252 ret = data->chip_info->read_calib(data); in bmp280_common_probe()
3254 return dev_err_probe(data->dev, ret, in bmp280_common_probe()
3258 ret = devm_iio_triggered_buffer_setup(data->dev, indio_dev, in bmp280_common_probe()
3260 data->chip_info->trigger_handler, in bmp280_common_probe()
3263 return dev_err_probe(data->dev, ret, in bmp280_common_probe()
3267 * Attempt to grab an optional EOC IRQ - only the BMP085 has this in bmp280_common_probe()
3272 if (data->chip_info->trigger_probe) in bmp280_common_probe()
3273 ret = data->chip_info->trigger_probe(indio_dev); in bmp280_common_probe()
3278 ret = data->chip_info->set_mode(data, BMP280_SLEEP); in bmp280_common_probe()
3288 * start-up time. in bmp280_common_probe()
3290 pm_runtime_set_autosuspend_delay(dev, data->start_up_time / 10); in bmp280_common_probe()
3307 data->chip_info->set_mode(data, BMP280_SLEEP); in bmp280_runtime_suspend()
3309 fsleep(data->start_up_time); in bmp280_runtime_suspend()
3310 return regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies); in bmp280_runtime_suspend()
3319 ret = regulator_bulk_enable(BMP280_NUM_SUPPLIES, data->supplies); in bmp280_runtime_resume()
3323 usleep_range(data->start_up_time, data->start_up_time + 100); in bmp280_runtime_resume()
3325 ret = data->chip_info->chip_config(data); in bmp280_runtime_resume()
3329 return data->chip_info->set_mode(data, data->op_mode); in bmp280_runtime_resume()