Lines Matching +full:iio +full:- +full:aux
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
21 * - Changed document referral from ANP015 to BST-MPS-AN004-00 on page 26
22 * - Updated equation for B3 param on section 3.5 to ((((long)AC1 * 4 + X3) << oss) + 2) / 4
23 * - Updated RoHS directive to 2011/65/EU effective 8 June 2011 on page 26
38 #include <linux/nvmem-provider.h>
44 #include <linux/iio/buffer.h>
45 #include <linux/iio/iio.h>
46 #include <linux/iio/trigger_consumer.h>
47 #include <linux/iio/triggered_buffer.h>
307 struct bmp280_calib *calib = &data->calib.bmp280; in bmp280_read_calib()
311 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_TEMP_START, in bmp280_read_calib()
312 data->bmp280_cal_buf, in bmp280_read_calib()
313 sizeof(data->bmp280_cal_buf)); in bmp280_read_calib()
315 dev_err(data->dev, in bmp280_read_calib()
321 add_device_randomness(data->bmp280_cal_buf, in bmp280_read_calib()
322 sizeof(data->bmp280_cal_buf)); in bmp280_read_calib()
325 calib->T1 = le16_to_cpu(data->bmp280_cal_buf[T1]); in bmp280_read_calib()
326 calib->T2 = le16_to_cpu(data->bmp280_cal_buf[T2]); in bmp280_read_calib()
327 calib->T3 = le16_to_cpu(data->bmp280_cal_buf[T3]); in bmp280_read_calib()
330 calib->P1 = le16_to_cpu(data->bmp280_cal_buf[P1]); in bmp280_read_calib()
331 calib->P2 = le16_to_cpu(data->bmp280_cal_buf[P2]); in bmp280_read_calib()
332 calib->P3 = le16_to_cpu(data->bmp280_cal_buf[P3]); in bmp280_read_calib()
333 calib->P4 = le16_to_cpu(data->bmp280_cal_buf[P4]); in bmp280_read_calib()
334 calib->P5 = le16_to_cpu(data->bmp280_cal_buf[P5]); in bmp280_read_calib()
335 calib->P6 = le16_to_cpu(data->bmp280_cal_buf[P6]); in bmp280_read_calib()
336 calib->P7 = le16_to_cpu(data->bmp280_cal_buf[P7]); in bmp280_read_calib()
337 calib->P8 = le16_to_cpu(data->bmp280_cal_buf[P8]); in bmp280_read_calib()
338 calib->P9 = le16_to_cpu(data->bmp280_cal_buf[P9]); in bmp280_read_calib()
345 struct bmp280_calib *calib = &data->calib.bmp280; in bme280_read_calib()
346 struct device *dev = data->dev; in bme280_read_calib()
363 ret = regmap_read(data->regmap, BME280_REG_COMP_H1, &tmp); in bme280_read_calib()
368 calib->H1 = tmp; in bme280_read_calib()
370 ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H2, in bme280_read_calib()
371 &data->le16, sizeof(data->le16)); in bme280_read_calib()
376 calib->H2 = sign_extend32(le16_to_cpu(data->le16), 15); in bme280_read_calib()
378 ret = regmap_read(data->regmap, BME280_REG_COMP_H3, &tmp); in bme280_read_calib()
383 calib->H3 = tmp; in bme280_read_calib()
385 ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H4, in bme280_read_calib()
386 &data->be16, sizeof(data->be16)); in bme280_read_calib()
391 calib->H4 = sign_extend32(((be16_to_cpu(data->be16) >> 4) & 0xff0) | in bme280_read_calib()
392 (be16_to_cpu(data->be16) & 0xf), 11); in bme280_read_calib()
394 ret = regmap_bulk_read(data->regmap, BME280_REG_COMP_H5, in bme280_read_calib()
395 &data->le16, sizeof(data->le16)); in bme280_read_calib()
400 calib->H5 = sign_extend32(FIELD_GET(BME280_COMP_H5_MASK, le16_to_cpu(data->le16)), 11); in bme280_read_calib()
402 ret = regmap_read(data->regmap, BME280_REG_COMP_H6, &tmp); in bme280_read_calib()
407 calib->H6 = sign_extend32(tmp, 7); in bme280_read_calib()
417 ret = regmap_bulk_read(data->regmap, BME280_REG_HUMIDITY_MSB, in bme280_read_humid_adc()
418 &data->be16, BME280_NUM_HUMIDITY_BYTES); in bme280_read_humid_adc()
420 dev_err(data->dev, "failed to read humidity\n"); in bme280_read_humid_adc()
424 value_humidity = be16_to_cpu(data->be16); in bme280_read_humid_adc()
426 dev_err(data->dev, "reading humidity skipped\n"); in bme280_read_humid_adc()
427 return -EIO; in bme280_read_humid_adc()
443 struct bmp280_calib *calib = &data->calib.bmp280; in bme280_compensate_humidity()
446 var = t_fine - (s32)76800; in bme280_compensate_humidity()
447 var = (((((s32)adc_humidity << 14) - (calib->H4 << 20) - (calib->H5 * var)) in bme280_compensate_humidity()
448 + (s32)16384) >> 15) * (((((((var * calib->H6) >> 10) in bme280_compensate_humidity()
449 * (((var * (s32)calib->H3) >> 11) + (s32)32768)) >> 10) in bme280_compensate_humidity()
450 + (s32)2097152) * calib->H2 + 8192) >> 14); in bme280_compensate_humidity()
451 var -= ((((var >> 15) * (var >> 15)) >> 7) * (s32)calib->H1) >> 4; in bme280_compensate_humidity()
463 ret = regmap_bulk_read(data->regmap, BMP280_REG_TEMP_MSB, in bmp280_read_temp_adc()
464 data->buf, BMP280_NUM_TEMP_BYTES); in bmp280_read_temp_adc()
466 dev_err(data->dev, "failed to read temperature\n"); in bmp280_read_temp_adc()
470 value_temp = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(data->buf)); in bmp280_read_temp_adc()
472 dev_err(data->dev, "reading temperature skipped\n"); in bmp280_read_temp_adc()
473 return -EIO; in bmp280_read_temp_adc()
489 struct bmp280_calib *calib = &data->calib.bmp280; in bmp280_calc_t_fine()
492 var1 = (((((s32)adc_temp) >> 3) - ((s32)calib->T1 << 1)) * in bmp280_calc_t_fine()
493 ((s32)calib->T2)) >> 11; in bmp280_calc_t_fine()
494 var2 = (((((((s32)adc_temp) >> 4) - ((s32)calib->T1)) * in bmp280_calc_t_fine()
495 ((((s32)adc_temp >> 4) - ((s32)calib->T1))) >> 12) * in bmp280_calc_t_fine()
496 ((s32)calib->T3))) >> 14; in bmp280_calc_t_fine()
524 ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, in bmp280_read_press_adc()
525 data->buf, BMP280_NUM_PRESS_BYTES); in bmp280_read_press_adc()
527 dev_err(data->dev, "failed to read pressure\n"); in bmp280_read_press_adc()
531 value_press = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(data->buf)); in bmp280_read_press_adc()
533 dev_err(data->dev, "reading pressure skipped\n"); in bmp280_read_press_adc()
534 return -EIO; in bmp280_read_press_adc()
551 struct bmp280_calib *calib = &data->calib.bmp280; in bmp280_compensate_press()
554 var1 = ((s64)t_fine) - 128000; in bmp280_compensate_press()
555 var2 = var1 * var1 * (s64)calib->P6; in bmp280_compensate_press()
556 var2 += (var1 * (s64)calib->P5) << 17; in bmp280_compensate_press()
557 var2 += ((s64)calib->P4) << 35; in bmp280_compensate_press()
558 var1 = ((var1 * var1 * (s64)calib->P3) >> 8) + in bmp280_compensate_press()
559 ((var1 * (s64)calib->P2) << 12); in bmp280_compensate_press()
560 var1 = ((((s64)1) << 47) + var1) * ((s64)calib->P1) >> 33; in bmp280_compensate_press()
565 p = ((((s64)1048576 - (s32)adc_press) << 31) - var2) * 3125; in bmp280_compensate_press()
567 var1 = (((s64)calib->P9) * (p >> 13) * (p >> 13)) >> 25; in bmp280_compensate_press()
568 var2 = ((s64)(calib->P8) * p) >> 19; in bmp280_compensate_press()
569 p = ((p + var1 + var2) >> 8) + (((s64)calib->P7) << 4); in bmp280_compensate_press()
634 guard(mutex)(&data->lock); in bmp280_read_raw_impl()
638 switch (chan->type) { in bmp280_read_raw_impl()
640 ret = data->chip_info->read_humid(data, &chan_value); in bmp280_read_raw_impl()
644 *val = data->chip_info->humid_coeffs[0] * chan_value; in bmp280_read_raw_impl()
645 *val2 = data->chip_info->humid_coeffs[1]; in bmp280_read_raw_impl()
646 return data->chip_info->humid_coeffs_type; in bmp280_read_raw_impl()
648 ret = data->chip_info->read_press(data, &chan_value); in bmp280_read_raw_impl()
652 *val = data->chip_info->press_coeffs[0] * chan_value; in bmp280_read_raw_impl()
653 *val2 = data->chip_info->press_coeffs[1]; in bmp280_read_raw_impl()
654 return data->chip_info->press_coeffs_type; in bmp280_read_raw_impl()
656 ret = data->chip_info->read_temp(data, &chan_value); in bmp280_read_raw_impl()
660 *val = data->chip_info->temp_coeffs[0] * chan_value; in bmp280_read_raw_impl()
661 *val2 = data->chip_info->temp_coeffs[1]; in bmp280_read_raw_impl()
662 return data->chip_info->temp_coeffs_type; in bmp280_read_raw_impl()
664 return -EINVAL; in bmp280_read_raw_impl()
667 switch (chan->type) { in bmp280_read_raw_impl()
669 ret = data->chip_info->read_humid(data, &chan_value); in bmp280_read_raw_impl()
676 ret = data->chip_info->read_press(data, &chan_value); in bmp280_read_raw_impl()
683 ret = data->chip_info->read_temp(data, &chan_value); in bmp280_read_raw_impl()
690 return -EINVAL; in bmp280_read_raw_impl()
693 switch (chan->type) { in bmp280_read_raw_impl()
695 *val = data->chip_info->humid_coeffs[0]; in bmp280_read_raw_impl()
696 *val2 = data->chip_info->humid_coeffs[1]; in bmp280_read_raw_impl()
697 return data->chip_info->humid_coeffs_type; in bmp280_read_raw_impl()
699 *val = data->chip_info->press_coeffs[0]; in bmp280_read_raw_impl()
700 *val2 = data->chip_info->press_coeffs[1]; in bmp280_read_raw_impl()
701 return data->chip_info->press_coeffs_type; in bmp280_read_raw_impl()
703 *val = data->chip_info->temp_coeffs[0]; in bmp280_read_raw_impl()
704 *val2 = data->chip_info->temp_coeffs[1]; in bmp280_read_raw_impl()
705 return data->chip_info->temp_coeffs_type; in bmp280_read_raw_impl()
707 return -EINVAL; in bmp280_read_raw_impl()
710 switch (chan->type) { in bmp280_read_raw_impl()
712 *val = 1 << data->oversampling_humid; in bmp280_read_raw_impl()
715 *val = 1 << data->oversampling_press; in bmp280_read_raw_impl()
718 *val = 1 << data->oversampling_temp; in bmp280_read_raw_impl()
721 return -EINVAL; in bmp280_read_raw_impl()
724 if (!data->chip_info->sampling_freq_avail) in bmp280_read_raw_impl()
725 return -EINVAL; in bmp280_read_raw_impl()
727 *val = data->chip_info->sampling_freq_avail[data->sampling_freq][0]; in bmp280_read_raw_impl()
728 *val2 = data->chip_info->sampling_freq_avail[data->sampling_freq][1]; in bmp280_read_raw_impl()
731 if (!data->chip_info->iir_filter_coeffs_avail) in bmp280_read_raw_impl()
732 return -EINVAL; in bmp280_read_raw_impl()
734 *val = (1 << data->iir_filter_coeff) - 1; in bmp280_read_raw_impl()
737 return -EINVAL; in bmp280_read_raw_impl()
748 pm_runtime_get_sync(data->dev); in bmp280_read_raw()
750 pm_runtime_mark_last_busy(data->dev); in bmp280_read_raw()
751 pm_runtime_put_autosuspend(data->dev); in bmp280_read_raw()
759 const int *avail = data->chip_info->oversampling_humid_avail; in bme280_write_oversampling_ratio_humid()
760 const int n = data->chip_info->num_oversampling_humid_avail; in bme280_write_oversampling_ratio_humid()
766 prev = data->oversampling_humid; in bme280_write_oversampling_ratio_humid()
767 data->oversampling_humid = ilog2(val); in bme280_write_oversampling_ratio_humid()
769 ret = data->chip_info->chip_config(data); in bme280_write_oversampling_ratio_humid()
771 data->oversampling_humid = prev; in bme280_write_oversampling_ratio_humid()
772 data->chip_info->chip_config(data); in bme280_write_oversampling_ratio_humid()
778 return -EINVAL; in bme280_write_oversampling_ratio_humid()
784 const int *avail = data->chip_info->oversampling_temp_avail; in bmp280_write_oversampling_ratio_temp()
785 const int n = data->chip_info->num_oversampling_temp_avail; in bmp280_write_oversampling_ratio_temp()
791 prev = data->oversampling_temp; in bmp280_write_oversampling_ratio_temp()
792 data->oversampling_temp = ilog2(val); in bmp280_write_oversampling_ratio_temp()
794 ret = data->chip_info->chip_config(data); in bmp280_write_oversampling_ratio_temp()
796 data->oversampling_temp = prev; in bmp280_write_oversampling_ratio_temp()
797 data->chip_info->chip_config(data); in bmp280_write_oversampling_ratio_temp()
803 return -EINVAL; in bmp280_write_oversampling_ratio_temp()
809 const int *avail = data->chip_info->oversampling_press_avail; in bmp280_write_oversampling_ratio_press()
810 const int n = data->chip_info->num_oversampling_press_avail; in bmp280_write_oversampling_ratio_press()
816 prev = data->oversampling_press; in bmp280_write_oversampling_ratio_press()
817 data->oversampling_press = ilog2(val); in bmp280_write_oversampling_ratio_press()
819 ret = data->chip_info->chip_config(data); in bmp280_write_oversampling_ratio_press()
821 data->oversampling_press = prev; in bmp280_write_oversampling_ratio_press()
822 data->chip_info->chip_config(data); in bmp280_write_oversampling_ratio_press()
828 return -EINVAL; in bmp280_write_oversampling_ratio_press()
834 const int (*avail)[2] = data->chip_info->sampling_freq_avail; in bmp280_write_sampling_frequency()
835 const int n = data->chip_info->num_sampling_freq_avail; in bmp280_write_sampling_frequency()
841 prev = data->sampling_freq; in bmp280_write_sampling_frequency()
842 data->sampling_freq = i; in bmp280_write_sampling_frequency()
844 ret = data->chip_info->chip_config(data); in bmp280_write_sampling_frequency()
846 data->sampling_freq = prev; in bmp280_write_sampling_frequency()
847 data->chip_info->chip_config(data); in bmp280_write_sampling_frequency()
853 return -EINVAL; in bmp280_write_sampling_frequency()
858 const int *avail = data->chip_info->iir_filter_coeffs_avail; in bmp280_write_iir_filter_coeffs()
859 const int n = data->chip_info->num_iir_filter_coeffs_avail; in bmp280_write_iir_filter_coeffs()
864 if (avail[i] - 1 == val) { in bmp280_write_iir_filter_coeffs()
865 prev = data->iir_filter_coeff; in bmp280_write_iir_filter_coeffs()
866 data->iir_filter_coeff = i; in bmp280_write_iir_filter_coeffs()
868 ret = data->chip_info->chip_config(data); in bmp280_write_iir_filter_coeffs()
870 data->iir_filter_coeff = prev; in bmp280_write_iir_filter_coeffs()
871 data->chip_info->chip_config(data); in bmp280_write_iir_filter_coeffs()
878 return -EINVAL; in bmp280_write_iir_filter_coeffs()
887 guard(mutex)(&data->lock); in bmp280_write_raw_impl()
897 switch (chan->type) { in bmp280_write_raw_impl()
905 return -EINVAL; in bmp280_write_raw_impl()
912 return -EINVAL; in bmp280_write_raw_impl()
923 pm_runtime_get_sync(data->dev); in bmp280_write_raw()
925 pm_runtime_mark_last_busy(data->dev); in bmp280_write_raw()
926 pm_runtime_put_autosuspend(data->dev); in bmp280_write_raw()
940 switch (chan->type) { in bmp280_read_avail()
942 *vals = data->chip_info->oversampling_press_avail; in bmp280_read_avail()
943 *length = data->chip_info->num_oversampling_press_avail; in bmp280_read_avail()
946 *vals = data->chip_info->oversampling_temp_avail; in bmp280_read_avail()
947 *length = data->chip_info->num_oversampling_temp_avail; in bmp280_read_avail()
950 return -EINVAL; in bmp280_read_avail()
955 *vals = (const int *)data->chip_info->sampling_freq_avail; in bmp280_read_avail()
958 *length = data->chip_info->num_sampling_freq_avail; in bmp280_read_avail()
961 *vals = data->chip_info->iir_filter_coeffs_avail; in bmp280_read_avail()
963 *length = data->chip_info->num_iir_filter_coeffs_avail; in bmp280_read_avail()
966 return -EINVAL; in bmp280_read_avail()
988 u8 osrs = FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1) | in bmp280_chip_config()
989 FIELD_PREP(BMP280_OSRS_PRESS_MASK, data->oversampling_press + 1); in bmp280_chip_config()
992 ret = regmap_write_bits(data->regmap, BMP280_REG_CTRL_MEAS, in bmp280_chip_config()
998 dev_err(data->dev, "failed to write ctrl_meas register\n"); in bmp280_chip_config()
1002 ret = regmap_update_bits(data->regmap, BMP280_REG_CONFIG, in bmp280_chip_config()
1006 dev_err(data->dev, "failed to write config register\n"); in bmp280_chip_config()
1016 struct iio_dev *indio_dev = pf->indio_dev; in bmp280_trigger_handler()
1021 guard(mutex)(&data->lock); in bmp280_trigger_handler()
1024 ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, in bmp280_trigger_handler()
1025 data->buf, BMP280_BURST_READ_BYTES); in bmp280_trigger_handler()
1027 dev_err(data->dev, "failed to burst read sensor data\n"); in bmp280_trigger_handler()
1032 adc_temp = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[3])); in bmp280_trigger_handler()
1034 dev_err(data->dev, "reading temperature skipped\n"); in bmp280_trigger_handler()
1038 data->sensor_data[1] = bmp280_compensate_temp(data, adc_temp); in bmp280_trigger_handler()
1041 adc_press = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[0])); in bmp280_trigger_handler()
1043 dev_err(data->dev, "reading pressure skipped\n"); in bmp280_trigger_handler()
1049 data->sensor_data[0] = bmp280_compensate_press(data, adc_press, t_fine); in bmp280_trigger_handler()
1051 iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, in bmp280_trigger_handler()
1055 iio_trigger_notify_done(indio_dev->trig); in bmp280_trigger_handler()
1087 .oversampling_temp_default = BMP280_OSRS_TEMP_2X - 1,
1091 .oversampling_press_default = BMP280_OSRS_PRESS_16X - 1,
1109 u8 osrs = FIELD_PREP(BME280_OSRS_HUMIDITY_MASK, data->oversampling_humid + 1); in bme280_chip_config()
1116 ret = regmap_update_bits(data->regmap, BME280_REG_CTRL_HUMIDITY, in bme280_chip_config()
1119 dev_err(data->dev, "failed to set humidity oversampling"); in bme280_chip_config()
1129 struct iio_dev *indio_dev = pf->indio_dev; in bme280_trigger_handler()
1134 guard(mutex)(&data->lock); in bme280_trigger_handler()
1137 ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, in bme280_trigger_handler()
1138 data->buf, BME280_BURST_READ_BYTES); in bme280_trigger_handler()
1140 dev_err(data->dev, "failed to burst read sensor data\n"); in bme280_trigger_handler()
1145 adc_temp = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[3])); in bme280_trigger_handler()
1147 dev_err(data->dev, "reading temperature skipped\n"); in bme280_trigger_handler()
1151 data->sensor_data[1] = bmp280_compensate_temp(data, adc_temp); in bme280_trigger_handler()
1154 adc_press = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[0])); in bme280_trigger_handler()
1156 dev_err(data->dev, "reading pressure skipped\n"); in bme280_trigger_handler()
1162 data->sensor_data[0] = bmp280_compensate_press(data, adc_press, t_fine); in bme280_trigger_handler()
1165 adc_humidity = get_unaligned_be16(&data->buf[6]); in bme280_trigger_handler()
1168 dev_err(data->dev, "reading humidity skipped\n"); in bme280_trigger_handler()
1171 data->sensor_data[2] = bme280_compensate_humidity(data, adc_humidity, t_fine); in bme280_trigger_handler()
1173 iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, in bme280_trigger_handler()
1177 iio_trigger_notify_done(indio_dev->trig); in bme280_trigger_handler()
1197 .oversampling_temp_default = BMP280_OSRS_TEMP_2X - 1,
1201 .oversampling_press_default = BMP280_OSRS_PRESS_16X - 1,
1205 .oversampling_humid_default = BME280_OSRS_HUMIDITY_16X - 1,
1237 ret = regmap_read(data->regmap, BMP380_REG_STATUS, ®); in bmp380_cmd()
1239 dev_err(data->dev, "failed to read error register\n"); in bmp380_cmd()
1243 dev_err(data->dev, "device is not ready to accept commands\n"); in bmp380_cmd()
1244 return -EBUSY; in bmp380_cmd()
1248 ret = regmap_write(data->regmap, BMP380_REG_CMD, cmd); in bmp380_cmd()
1250 dev_err(data->dev, "failed to send command to device\n"); in bmp380_cmd()
1254 usleep_range(data->start_up_time, data->start_up_time + 100); in bmp380_cmd()
1256 ret = regmap_read(data->regmap, BMP380_REG_ERROR, ®); in bmp380_cmd()
1258 dev_err(data->dev, "error reading ERROR reg\n"); in bmp380_cmd()
1262 dev_err(data->dev, "error processing command 0x%X\n", cmd); in bmp380_cmd()
1263 return -EINVAL; in bmp380_cmd()
1274 ret = regmap_bulk_read(data->regmap, BMP380_REG_TEMP_XLSB, in bmp380_read_temp_adc()
1275 data->buf, BMP280_NUM_TEMP_BYTES); in bmp380_read_temp_adc()
1277 dev_err(data->dev, "failed to read temperature\n"); in bmp380_read_temp_adc()
1281 value_temp = get_unaligned_le24(data->buf); in bmp380_read_temp_adc()
1283 dev_err(data->dev, "reading temperature skipped\n"); in bmp380_read_temp_adc()
1284 return -EIO; in bmp380_read_temp_adc()
1296 * https://github.com/BoschSensortec/BMP3-Sensor-API.
1301 struct bmp380_calib *calib = &data->calib.bmp380; in bmp380_calc_t_fine()
1303 var1 = ((s64) adc_temp) - (((s64) calib->T1) << 8); in bmp380_calc_t_fine()
1304 var2 = var1 * ((s64) calib->T2); in bmp380_calc_t_fine()
1306 var4 = var3 * ((s64) calib->T3); in bmp380_calc_t_fine()
1343 ret = regmap_bulk_read(data->regmap, BMP380_REG_PRESS_XLSB, in bmp380_read_press_adc()
1344 data->buf, BMP280_NUM_PRESS_BYTES); in bmp380_read_press_adc()
1346 dev_err(data->dev, "failed to read pressure\n"); in bmp380_read_press_adc()
1350 value_press = get_unaligned_le24(data->buf); in bmp380_read_press_adc()
1352 dev_err(data->dev, "reading pressure skipped\n"); in bmp380_read_press_adc()
1353 return -EIO; in bmp380_read_press_adc()
1365 * https://github.com/BoschSensortec/BMP3-Sensor-API.
1371 struct bmp380_calib *calib = &data->calib.bmp380; in bmp380_compensate_press()
1377 var4 = ((s64)calib->P8 * var3) >> 5; in bmp380_compensate_press()
1378 var5 = ((s64)calib->P7 * var1) << 4; in bmp380_compensate_press()
1379 var6 = ((s64)calib->P6 * (s64)t_fine) << 22; in bmp380_compensate_press()
1380 offset = ((s64)calib->P5 << 47) + var4 + var5 + var6; in bmp380_compensate_press()
1381 var2 = ((s64)calib->P4 * var3) >> 5; in bmp380_compensate_press()
1382 var4 = ((s64)calib->P3 * var1) << 2; in bmp380_compensate_press()
1383 var5 = ((s64)calib->P2 - ((s64)1 << 14)) * in bmp380_compensate_press()
1385 sensitivity = (((s64) calib->P1 - ((s64) 1 << 14)) << 46) + in bmp380_compensate_press()
1388 var2 = (s64)calib->P10 * (s64)t_fine; in bmp380_compensate_press()
1389 var3 = var2 + ((s64)calib->P9 << 16); in bmp380_compensate_press()
1394 * possible overflow caused by (uncomp_data->pressure * partial_data4). in bmp380_compensate_press()
1399 var2 = ((s64)calib->P11 * var6) >> 16; in bmp380_compensate_press()
1442 struct bmp380_calib *calib = &data->calib.bmp380; in bmp380_read_calib()
1446 ret = regmap_bulk_read(data->regmap, BMP380_REG_CALIB_TEMP_START, in bmp380_read_calib()
1447 data->bmp380_cal_buf, in bmp380_read_calib()
1448 sizeof(data->bmp380_cal_buf)); in bmp380_read_calib()
1450 dev_err(data->dev, in bmp380_read_calib()
1456 add_device_randomness(data->bmp380_cal_buf, in bmp380_read_calib()
1457 sizeof(data->bmp380_cal_buf)); in bmp380_read_calib()
1460 calib->T1 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_T1]); in bmp380_read_calib()
1461 calib->T2 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_T2]); in bmp380_read_calib()
1462 calib->T3 = data->bmp380_cal_buf[BMP380_T3]; in bmp380_read_calib()
1463 calib->P1 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_P1]); in bmp380_read_calib()
1464 calib->P2 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_P2]); in bmp380_read_calib()
1465 calib->P3 = data->bmp380_cal_buf[BMP380_P3]; in bmp380_read_calib()
1466 calib->P4 = data->bmp380_cal_buf[BMP380_P4]; in bmp380_read_calib()
1467 calib->P5 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_P5]); in bmp380_read_calib()
1468 calib->P6 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_P6]); in bmp380_read_calib()
1469 calib->P7 = data->bmp380_cal_buf[BMP380_P7]; in bmp380_read_calib()
1470 calib->P8 = data->bmp380_cal_buf[BMP380_P8]; in bmp380_read_calib()
1471 calib->P9 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_P9]); in bmp380_read_calib()
1472 calib->P10 = data->bmp380_cal_buf[BMP380_P10]; in bmp380_read_calib()
1473 calib->P11 = data->bmp380_cal_buf[BMP380_P11]; in bmp380_read_calib()
1501 /* BMP3xx requires soft-reset as part of initialization */ in bmp380_preinit()
1507 bool change = false, aux; in bmp380_chip_config() local
1513 ret = regmap_update_bits(data->regmap, BMP380_REG_POWER_CONTROL, in bmp380_chip_config()
1518 dev_err(data->dev, in bmp380_chip_config()
1524 osrs = FIELD_PREP(BMP380_OSRS_TEMP_MASK, data->oversampling_temp) | in bmp380_chip_config()
1525 FIELD_PREP(BMP380_OSRS_PRESS_MASK, data->oversampling_press); in bmp380_chip_config()
1527 ret = regmap_update_bits_check(data->regmap, BMP380_REG_OSR, in bmp380_chip_config()
1530 osrs, &aux); in bmp380_chip_config()
1532 dev_err(data->dev, "failed to write oversampling register\n"); in bmp380_chip_config()
1535 change = change || aux; in bmp380_chip_config()
1538 ret = regmap_update_bits_check(data->regmap, BMP380_REG_ODR, in bmp380_chip_config()
1539 BMP380_ODRS_MASK, data->sampling_freq, in bmp380_chip_config()
1540 &aux); in bmp380_chip_config()
1542 dev_err(data->dev, "failed to write ODR selection register\n"); in bmp380_chip_config()
1545 change = change || aux; in bmp380_chip_config()
1548 ret = regmap_update_bits_check(data->regmap, BMP380_REG_CONFIG, BMP380_FILTER_MASK, in bmp380_chip_config()
1549 FIELD_PREP(BMP380_FILTER_MASK, data->iir_filter_coeff), in bmp380_chip_config()
1550 &aux); in bmp380_chip_config()
1552 dev_err(data->dev, "failed to write config register\n"); in bmp380_chip_config()
1555 change = change || aux; in bmp380_chip_config()
1567 ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, in bmp380_chip_config()
1571 dev_err(data->dev, "failed to set sleep mode\n"); in bmp380_chip_config()
1575 ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, in bmp380_chip_config()
1579 dev_err(data->dev, "failed to set normal mode\n"); in bmp380_chip_config()
1591 ret = regmap_read(data->regmap, BMP380_REG_ERROR, &tmp); in bmp380_chip_config()
1593 dev_err(data->dev, "failed to read error register\n"); in bmp380_chip_config()
1597 dev_warn(data->dev, in bmp380_chip_config()
1599 return -EINVAL; in bmp380_chip_config()
1609 struct iio_dev *indio_dev = pf->indio_dev; in bmp380_trigger_handler()
1614 guard(mutex)(&data->lock); in bmp380_trigger_handler()
1617 ret = regmap_bulk_read(data->regmap, BMP380_REG_PRESS_XLSB, in bmp380_trigger_handler()
1618 data->buf, BMP280_BURST_READ_BYTES); in bmp380_trigger_handler()
1620 dev_err(data->dev, "failed to burst read sensor data\n"); in bmp380_trigger_handler()
1625 adc_temp = get_unaligned_le24(&data->buf[3]); in bmp380_trigger_handler()
1627 dev_err(data->dev, "reading temperature skipped\n"); in bmp380_trigger_handler()
1631 data->sensor_data[1] = bmp380_compensate_temp(data, adc_temp); in bmp380_trigger_handler()
1634 adc_press = get_unaligned_le24(&data->buf[0]); in bmp380_trigger_handler()
1636 dev_err(data->dev, "reading pressure skipped\n"); in bmp380_trigger_handler()
1642 data->sensor_data[0] = bmp380_compensate_press(data, adc_press, t_fine); in bmp380_trigger_handler()
1644 iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, in bmp380_trigger_handler()
1648 iio_trigger_notify_done(indio_dev->trig); in bmp380_trigger_handler()
1706 ret = regmap_write(data->regmap, BMP580_REG_CMD, BMP580_CMD_SOFT_RESET); in bmp580_soft_reset()
1708 dev_err(data->dev, "failed to send reset command to device\n"); in bmp580_soft_reset()
1714 ret = regmap_read(data->regmap, BMP580_REG_CHIP_ID, ®); in bmp580_soft_reset()
1716 dev_err(data->dev, "failed to reestablish comms after reset\n"); in bmp580_soft_reset()
1720 ret = regmap_read(data->regmap, BMP580_REG_INT_STATUS, ®); in bmp580_soft_reset()
1722 dev_err(data->dev, "error reading interrupt status register\n"); in bmp580_soft_reset()
1726 dev_err(data->dev, "error resetting sensor\n"); in bmp580_soft_reset()
1727 return -EINVAL; in bmp580_soft_reset()
1734 * bmp580_nvm_operation() - Helper function to commit NVM memory operations
1745 ret = regmap_read(data->regmap, BMP580_REG_STATUS, ®); in bmp580_nvm_operation()
1747 dev_err(data->dev, "failed to check nvm status\n"); in bmp580_nvm_operation()
1751 dev_err(data->dev, "sensor's nvm is not ready\n"); in bmp580_nvm_operation()
1752 return -EIO; in bmp580_nvm_operation()
1756 ret = regmap_write(data->regmap, BMP580_REG_CMD, in bmp580_nvm_operation()
1759 dev_err(data->dev, in bmp580_nvm_operation()
1765 ret = regmap_write(data->regmap, BMP580_REG_CMD, in bmp580_nvm_operation()
1768 dev_err(data->dev, in bmp580_nvm_operation()
1777 ret = regmap_write(data->regmap, BMP580_REG_CMD, in bmp580_nvm_operation()
1780 dev_err(data->dev, in bmp580_nvm_operation()
1790 ret = regmap_read_poll_timeout(data->regmap, BMP580_REG_STATUS, reg, in bmp580_nvm_operation()
1794 dev_err(data->dev, "error checking nvm operation status\n"); in bmp580_nvm_operation()
1800 dev_err(data->dev, "error processing nvm operation\n"); in bmp580_nvm_operation()
1801 return -EIO; in bmp580_nvm_operation()
1810 * for what is expected on IIO ABI.
1818 ret = regmap_bulk_read(data->regmap, BMP580_REG_TEMP_XLSB, in bmp580_read_temp()
1819 data->buf, BMP280_NUM_TEMP_BYTES); in bmp580_read_temp()
1821 dev_err(data->dev, "failed to read temperature\n"); in bmp580_read_temp()
1825 value_temp = get_unaligned_le24(data->buf); in bmp580_read_temp()
1827 dev_err(data->dev, "reading temperature skipped\n"); in bmp580_read_temp()
1828 return -EIO; in bmp580_read_temp()
1840 ret = regmap_bulk_read(data->regmap, BMP580_REG_PRESS_XLSB, in bmp580_read_press()
1841 data->buf, BMP280_NUM_PRESS_BYTES); in bmp580_read_press()
1843 dev_err(data->dev, "failed to read pressure\n"); in bmp580_read_press()
1847 value_press = get_unaligned_le24(data->buf); in bmp580_read_press()
1849 dev_err(data->dev, "reading pressure skipped\n"); in bmp580_read_press()
1850 return -EIO; in bmp580_read_press()
1901 guard(mutex)(&data->lock); in bmp580_nvmem_read_impl()
1904 ret = regmap_update_bits(data->regmap, BMP580_REG_ODR_CONFIG, in bmp580_nvmem_read_impl()
1909 dev_err(data->dev, "failed to change sensor to standby mode\n"); in bmp580_nvmem_read_impl()
1918 ret = regmap_write(data->regmap, BMP580_REG_NVM_ADDR, in bmp580_nvmem_read_impl()
1921 dev_err(data->dev, "error writing nvm address\n"); in bmp580_nvmem_read_impl()
1929 ret = regmap_bulk_read(data->regmap, BMP580_REG_NVM_DATA_LSB, in bmp580_nvmem_read_impl()
1930 &data->le16, sizeof(data->le16)); in bmp580_nvmem_read_impl()
1932 dev_err(data->dev, "error reading nvm data regs\n"); in bmp580_nvmem_read_impl()
1936 *dst++ = le16_to_cpu(data->le16); in bmp580_nvmem_read_impl()
1937 bytes -= sizeof(*dst); in bmp580_nvmem_read_impl()
1942 data->chip_info->chip_config(data); in bmp580_nvmem_read_impl()
1952 pm_runtime_get_sync(data->dev); in bmp580_nvmem_read()
1954 pm_runtime_mark_last_busy(data->dev); in bmp580_nvmem_read()
1955 pm_runtime_put_autosuspend(data->dev); in bmp580_nvmem_read()
1967 guard(mutex)(&data->lock); in bmp580_nvmem_write_impl()
1970 ret = regmap_update_bits(data->regmap, BMP580_REG_ODR_CONFIG, in bmp580_nvmem_write_impl()
1975 dev_err(data->dev, "failed to change sensor to standby mode\n"); in bmp580_nvmem_write_impl()
1984 ret = regmap_write(data->regmap, BMP580_REG_NVM_ADDR, in bmp580_nvmem_write_impl()
1988 dev_err(data->dev, "error writing nvm address\n"); in bmp580_nvmem_write_impl()
1991 data->le16 = cpu_to_le16(*buf++); in bmp580_nvmem_write_impl()
1993 ret = regmap_bulk_write(data->regmap, BMP580_REG_NVM_DATA_LSB, in bmp580_nvmem_write_impl()
1994 &data->le16, sizeof(data->le16)); in bmp580_nvmem_write_impl()
1996 dev_err(data->dev, "error writing LSB NVM data regs\n"); in bmp580_nvmem_write_impl()
2005 ret = regmap_clear_bits(data->regmap, BMP580_REG_NVM_ADDR, in bmp580_nvmem_write_impl()
2008 dev_err(data->dev, "error resetting nvm write\n"); in bmp580_nvmem_write_impl()
2012 bytes -= sizeof(*buf); in bmp580_nvmem_write_impl()
2017 data->chip_info->chip_config(data); in bmp580_nvmem_write_impl()
2027 pm_runtime_get_sync(data->dev); in bmp580_nvmem_write()
2029 pm_runtime_mark_last_busy(data->dev); in bmp580_nvmem_write()
2030 pm_runtime_put_autosuspend(data->dev); in bmp580_nvmem_write()
2038 .dev = data->dev, in bmp580_preinit()
2050 /* Issue soft-reset command */ in bmp580_preinit()
2056 ret = regmap_read(data->regmap, BMP580_REG_CHIP_ID, ®); in bmp580_preinit()
2058 dev_err(data->dev, "failed to establish comms with the chip\n"); in bmp580_preinit()
2064 dev_warn(data->dev, "unexpected chip_id\n"); in bmp580_preinit()
2066 ret = regmap_read(data->regmap, BMP580_REG_STATUS, ®); in bmp580_preinit()
2068 dev_err(data->dev, "failed to read nvm status\n"); in bmp580_preinit()
2074 dev_err(data->dev, "nvm error on powerup sequence\n"); in bmp580_preinit()
2075 return -EIO; in bmp580_preinit()
2084 bool change = false, aux; in bmp580_chip_config() local
2090 ret = regmap_update_bits(data->regmap, BMP580_REG_ODR_CONFIG, in bmp580_chip_config()
2095 dev_err(data->dev, "failed to change sensor to standby mode\n"); in bmp580_chip_config()
2105 ret = regmap_update_bits(data->regmap, BMP580_REG_DSP_CONFIG, in bmp580_chip_config()
2110 dev_err(data->dev, "failed to change DSP mode settings\n"); in bmp580_chip_config()
2115 reg_val = FIELD_PREP(BMP580_OSR_TEMP_MASK, data->oversampling_temp) | in bmp580_chip_config()
2116 FIELD_PREP(BMP580_OSR_PRESS_MASK, data->oversampling_press) | in bmp580_chip_config()
2119 ret = regmap_update_bits_check(data->regmap, BMP580_REG_OSR_CONFIG, in bmp580_chip_config()
2123 reg_val, &aux); in bmp580_chip_config()
2125 dev_err(data->dev, "failed to write oversampling register\n"); in bmp580_chip_config()
2128 change = change || aux; in bmp580_chip_config()
2131 ret = regmap_update_bits_check(data->regmap, BMP580_REG_ODR_CONFIG, BMP580_ODR_MASK, in bmp580_chip_config()
2132 FIELD_PREP(BMP580_ODR_MASK, data->sampling_freq), in bmp580_chip_config()
2133 &aux); in bmp580_chip_config()
2135 dev_err(data->dev, "failed to write ODR configuration register\n"); in bmp580_chip_config()
2138 change = change || aux; in bmp580_chip_config()
2141 reg_val = FIELD_PREP(BMP580_DSP_IIR_PRESS_MASK, data->iir_filter_coeff) | in bmp580_chip_config()
2142 FIELD_PREP(BMP580_DSP_IIR_TEMP_MASK, data->iir_filter_coeff); in bmp580_chip_config()
2144 ret = regmap_update_bits_check(data->regmap, BMP580_REG_DSP_IIR, in bmp580_chip_config()
2147 reg_val, &aux); in bmp580_chip_config()
2149 dev_err(data->dev, "failed to write config register\n"); in bmp580_chip_config()
2152 change = change || aux; in bmp580_chip_config()
2155 ret = regmap_write_bits(data->regmap, BMP580_REG_ODR_CONFIG, in bmp580_chip_config()
2159 dev_err(data->dev, "failed to set normal mode\n"); in bmp580_chip_config()
2170 ret = regmap_read(data->regmap, BMP580_REG_EFF_OSR, &tmp); in bmp580_chip_config()
2172 dev_err(data->dev, in bmp580_chip_config()
2177 dev_warn(data->dev, "OSR and ODR incompatible settings detected\n"); in bmp580_chip_config()
2179 data->oversampling_temp = FIELD_GET(BMP580_EFF_OSR_TEMP_MASK, tmp); in bmp580_chip_config()
2180 data->oversampling_press = FIELD_GET(BMP580_EFF_OSR_PRESS_MASK, tmp); in bmp580_chip_config()
2181 return -EINVAL; in bmp580_chip_config()
2191 struct iio_dev *indio_dev = pf->indio_dev; in bmp580_trigger_handler()
2195 guard(mutex)(&data->lock); in bmp580_trigger_handler()
2198 ret = regmap_bulk_read(data->regmap, BMP580_REG_TEMP_XLSB, in bmp580_trigger_handler()
2199 data->buf, BMP280_BURST_READ_BYTES); in bmp580_trigger_handler()
2201 dev_err(data->dev, "failed to burst read sensor data\n"); in bmp580_trigger_handler()
2206 memcpy(&data->sensor_data[1], &data->buf[0], 3); in bmp580_trigger_handler()
2209 memcpy(&data->sensor_data[0], &data->buf[3], 3); in bmp580_trigger_handler()
2211 iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, in bmp580_trigger_handler()
2215 iio_trigger_notify_done(indio_dev->trig); in bmp580_trigger_handler()
2273 if (data->use_eoc) in bmp180_wait_for_eoc()
2274 reinit_completion(&data->done); in bmp180_wait_for_eoc()
2276 ret = regmap_write(data->regmap, BMP280_REG_CTRL_MEAS, ctrl_meas); in bmp180_wait_for_eoc()
2278 dev_err(data->dev, "failed to write crtl_meas register\n"); in bmp180_wait_for_eoc()
2282 if (data->use_eoc) { in bmp180_wait_for_eoc()
2288 ret = wait_for_completion_timeout(&data->done, in bmp180_wait_for_eoc()
2291 dev_err(data->dev, "timeout waiting for completion\n"); in bmp180_wait_for_eoc()
2297 conversion_time_max[data->oversampling_press]; in bmp180_wait_for_eoc()
2302 ret = regmap_read(data->regmap, BMP280_REG_CTRL_MEAS, &ctrl); in bmp180_wait_for_eoc()
2304 dev_err(data->dev, "failed to read ctrl_meas register\n"); in bmp180_wait_for_eoc()
2310 dev_err(data->dev, "conversion didn't complete\n"); in bmp180_wait_for_eoc()
2311 return -EIO; in bmp180_wait_for_eoc()
2327 ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, in bmp180_read_temp_adc()
2328 &data->be16, sizeof(data->be16)); in bmp180_read_temp_adc()
2330 dev_err(data->dev, "failed to read temperature\n"); in bmp180_read_temp_adc()
2334 *adc_temp = be16_to_cpu(data->be16); in bmp180_read_temp_adc()
2341 struct bmp180_calib *calib = &data->calib.bmp180; in bmp180_read_calib()
2345 ret = regmap_bulk_read(data->regmap, BMP180_REG_CALIB_START, in bmp180_read_calib()
2346 data->bmp180_cal_buf, sizeof(data->bmp180_cal_buf)); in bmp180_read_calib()
2348 dev_err(data->dev, "failed to read calibration parameters\n"); in bmp180_read_calib()
2353 for (i = 0; i < ARRAY_SIZE(data->bmp180_cal_buf); i++) { in bmp180_read_calib()
2354 if (data->bmp180_cal_buf[i] == cpu_to_be16(0) || in bmp180_read_calib()
2355 data->bmp180_cal_buf[i] == cpu_to_be16(0xffff)) in bmp180_read_calib()
2356 return -EIO; in bmp180_read_calib()
2360 add_device_randomness(data->bmp180_cal_buf, in bmp180_read_calib()
2361 sizeof(data->bmp180_cal_buf)); in bmp180_read_calib()
2363 calib->AC1 = be16_to_cpu(data->bmp180_cal_buf[AC1]); in bmp180_read_calib()
2364 calib->AC2 = be16_to_cpu(data->bmp180_cal_buf[AC2]); in bmp180_read_calib()
2365 calib->AC3 = be16_to_cpu(data->bmp180_cal_buf[AC3]); in bmp180_read_calib()
2366 calib->AC4 = be16_to_cpu(data->bmp180_cal_buf[AC4]); in bmp180_read_calib()
2367 calib->AC5 = be16_to_cpu(data->bmp180_cal_buf[AC5]); in bmp180_read_calib()
2368 calib->AC6 = be16_to_cpu(data->bmp180_cal_buf[AC6]); in bmp180_read_calib()
2369 calib->B1 = be16_to_cpu(data->bmp180_cal_buf[B1]); in bmp180_read_calib()
2370 calib->B2 = be16_to_cpu(data->bmp180_cal_buf[B2]); in bmp180_read_calib()
2371 calib->MB = be16_to_cpu(data->bmp180_cal_buf[MB]); in bmp180_read_calib()
2372 calib->MC = be16_to_cpu(data->bmp180_cal_buf[MC]); in bmp180_read_calib()
2373 calib->MD = be16_to_cpu(data->bmp180_cal_buf[MD]); in bmp180_read_calib()
2387 struct bmp180_calib *calib = &data->calib.bmp180; in bmp180_calc_t_fine()
2390 x1 = ((((s32)adc_temp) - calib->AC6) * calib->AC5) >> 15; in bmp180_calc_t_fine()
2391 x2 = (calib->MC << 11) / (x1 + calib->MD); in bmp180_calc_t_fine()
2430 u8 oss = data->oversampling_press; in bmp180_read_press_adc()
2440 ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, in bmp180_read_press_adc()
2441 data->buf, BMP280_NUM_PRESS_BYTES); in bmp180_read_press_adc()
2443 dev_err(data->dev, "failed to read pressure\n"); in bmp180_read_press_adc()
2447 *adc_press = get_unaligned_be24(data->buf) >> (8 - oss); in bmp180_read_press_adc()
2460 struct bmp180_calib *calib = &data->calib.bmp180; in bmp180_compensate_press()
2461 s32 oss = data->oversampling_press; in bmp180_compensate_press()
2466 b6 = t_fine - 4000; in bmp180_compensate_press()
2467 x1 = (calib->B2 * (b6 * b6 >> 12)) >> 11; in bmp180_compensate_press()
2468 x2 = calib->AC2 * b6 >> 11; in bmp180_compensate_press()
2470 b3 = ((((s32)calib->AC1 * 4 + x3) << oss) + 2) / 4; in bmp180_compensate_press()
2471 x1 = calib->AC3 * b6 >> 13; in bmp180_compensate_press()
2472 x2 = (calib->B1 * ((b6 * b6) >> 12)) >> 16; in bmp180_compensate_press()
2474 b4 = calib->AC4 * (u32)(x3 + 32768) >> 15; in bmp180_compensate_press()
2475 b7 = (adc_press - b3) * (50000 >> oss); in bmp180_compensate_press()
2483 x2 = (-7357 * p) >> 16; in bmp180_compensate_press()
2515 struct iio_dev *indio_dev = pf->indio_dev; in bmp180_trigger_handler()
2519 guard(mutex)(&data->lock); in bmp180_trigger_handler()
2525 data->sensor_data[1] = chan_value; in bmp180_trigger_handler()
2531 data->sensor_data[0] = chan_value; in bmp180_trigger_handler()
2533 iio_push_to_buffers_with_timestamp(indio_dev, &data->sensor_data, in bmp180_trigger_handler()
2537 iio_trigger_notify_done(indio_dev->trig); in bmp180_trigger_handler()
2586 complete(&data->done); in bmp085_eoc_irq()
2601 dev_err(dev, "non-rising trigger given for EOC interrupt, trying to enforce it\n"); in bmp085_fetch_eoc_irq()
2605 init_completion(&data->done); in bmp085_fetch_eoc_irq()
2620 data->use_eoc = true; in bmp085_fetch_eoc_irq()
2628 pm_runtime_get_sync(data->dev); in bmp280_buffer_preenable()
2637 pm_runtime_mark_last_busy(data->dev); in bmp280_buffer_postdisable()
2638 pm_runtime_put_autosuspend(data->dev); in bmp280_buffer_postdisable()
2679 return -ENOMEM; in bmp280_common_probe()
2682 mutex_init(&data->lock); in bmp280_common_probe()
2683 data->dev = dev; in bmp280_common_probe()
2685 indio_dev->name = name; in bmp280_common_probe()
2686 indio_dev->info = &bmp280_info; in bmp280_common_probe()
2687 indio_dev->modes = INDIO_DIRECT_MODE; in bmp280_common_probe()
2689 data->chip_info = chip_info; in bmp280_common_probe()
2692 indio_dev->channels = chip_info->channels; in bmp280_common_probe()
2693 indio_dev->num_channels = chip_info->num_channels; in bmp280_common_probe()
2694 indio_dev->available_scan_masks = chip_info->avail_scan_masks; in bmp280_common_probe()
2695 data->oversampling_press = chip_info->oversampling_press_default; in bmp280_common_probe()
2696 data->oversampling_humid = chip_info->oversampling_humid_default; in bmp280_common_probe()
2697 data->oversampling_temp = chip_info->oversampling_temp_default; in bmp280_common_probe()
2698 data->iir_filter_coeff = chip_info->iir_filter_coeff_default; in bmp280_common_probe()
2699 data->sampling_freq = chip_info->sampling_freq_default; in bmp280_common_probe()
2700 data->start_up_time = chip_info->start_up_time; in bmp280_common_probe()
2703 regulator_bulk_set_supply_names(data->supplies, in bmp280_common_probe()
2708 BMP280_NUM_SUPPLIES, data->supplies); in bmp280_common_probe()
2714 ret = regulator_bulk_enable(BMP280_NUM_SUPPLIES, data->supplies); in bmp280_common_probe()
2721 data->supplies); in bmp280_common_probe()
2726 usleep_range(data->start_up_time, data->start_up_time + 100); in bmp280_common_probe()
2736 data->regmap = regmap; in bmp280_common_probe()
2738 ret = regmap_read(regmap, data->chip_info->id_reg, &chip_id); in bmp280_common_probe()
2740 dev_err(data->dev, "failed to read chip id\n"); in bmp280_common_probe()
2744 for (i = 0; i < data->chip_info->num_chip_id; i++) { in bmp280_common_probe()
2745 if (chip_id == data->chip_info->chip_id[i]) { in bmp280_common_probe()
2751 if (i == data->chip_info->num_chip_id) in bmp280_common_probe()
2754 if (data->chip_info->preinit) { in bmp280_common_probe()
2755 ret = data->chip_info->preinit(data); in bmp280_common_probe()
2757 return dev_err_probe(data->dev, ret, in bmp280_common_probe()
2761 ret = data->chip_info->chip_config(data); in bmp280_common_probe()
2769 * non-volatile memory during production". Let's read them out at probe in bmp280_common_probe()
2773 if (data->chip_info->read_calib) { in bmp280_common_probe()
2774 ret = data->chip_info->read_calib(data); in bmp280_common_probe()
2776 return dev_err_probe(data->dev, ret, in bmp280_common_probe()
2780 ret = devm_iio_triggered_buffer_setup(data->dev, indio_dev, in bmp280_common_probe()
2782 data->chip_info->trigger_handler, in bmp280_common_probe()
2785 return dev_err_probe(data->dev, ret, in bmp280_common_probe()
2786 "iio triggered buffer setup failed\n"); in bmp280_common_probe()
2789 * Attempt to grab an optional EOC IRQ - only the BMP085 has this in bmp280_common_probe()
2805 * start-up time. in bmp280_common_probe()
2807 pm_runtime_set_autosuspend_delay(dev, data->start_up_time / 10); in bmp280_common_probe()
2824 return regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies); in bmp280_runtime_suspend()
2833 ret = regulator_bulk_enable(BMP280_NUM_SUPPLIES, data->supplies); in bmp280_runtime_resume()
2837 usleep_range(data->start_up_time, data->start_up_time + 100); in bmp280_runtime_resume()
2838 return data->chip_info->chip_config(data); in bmp280_runtime_resume()