Lines Matching refs:data
305 static int bmp280_read_calib(struct bmp280_data *data) in bmp280_read_calib() argument
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()
343 static int bme280_read_calib(struct bmp280_data *data) in bme280_read_calib() argument
345 struct bmp280_calib *calib = &data->calib.bmp280; in bme280_read_calib()
346 struct device *dev = data->dev; in bme280_read_calib()
351 ret = bmp280_read_calib(data); in bme280_read_calib()
363 ret = regmap_read(data->regmap, BME280_REG_COMP_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()
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()
412 static int bme280_read_humid_adc(struct bmp280_data *data, u16 *adc_humidity) in bme280_read_humid_adc() argument
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()
440 static u32 bme280_compensate_humidity(struct bmp280_data *data, in bme280_compensate_humidity() argument
443 struct bmp280_calib *calib = &data->calib.bmp280; in bme280_compensate_humidity()
458 static int bmp280_read_temp_adc(struct bmp280_data *data, u32 *adc_temp) in bmp280_read_temp_adc() argument
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()
487 static s32 bmp280_calc_t_fine(struct bmp280_data *data, u32 adc_temp) in bmp280_calc_t_fine() argument
489 struct bmp280_calib *calib = &data->calib.bmp280; in bmp280_calc_t_fine()
500 static int bmp280_get_t_fine(struct bmp280_data *data, s32 *t_fine) in bmp280_get_t_fine() argument
505 ret = bmp280_read_temp_adc(data, &adc_temp); in bmp280_get_t_fine()
509 *t_fine = bmp280_calc_t_fine(data, adc_temp); in bmp280_get_t_fine()
514 static s32 bmp280_compensate_temp(struct bmp280_data *data, u32 adc_temp) in bmp280_compensate_temp() argument
516 return (bmp280_calc_t_fine(data, adc_temp) * 5 + 128) / 256; in bmp280_compensate_temp()
519 static int bmp280_read_press_adc(struct bmp280_data *data, u32 *adc_press) in bmp280_read_press_adc() argument
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()
548 static u32 bmp280_compensate_press(struct bmp280_data *data, in bmp280_compensate_press() argument
551 struct bmp280_calib *calib = &data->calib.bmp280; in bmp280_compensate_press()
574 static int bmp280_read_temp(struct bmp280_data *data, s32 *comp_temp) in bmp280_read_temp() argument
579 ret = bmp280_read_temp_adc(data, &adc_temp); in bmp280_read_temp()
583 *comp_temp = bmp280_compensate_temp(data, adc_temp); in bmp280_read_temp()
588 static int bmp280_read_press(struct bmp280_data *data, u32 *comp_press) in bmp280_read_press() argument
594 ret = bmp280_get_t_fine(data, &t_fine); in bmp280_read_press()
598 ret = bmp280_read_press_adc(data, &adc_press); in bmp280_read_press()
602 *comp_press = bmp280_compensate_press(data, adc_press, t_fine); in bmp280_read_press()
607 static int bme280_read_humid(struct bmp280_data *data, u32 *comp_humidity) in bme280_read_humid() argument
613 ret = bmp280_get_t_fine(data, &t_fine); in bme280_read_humid()
617 ret = bme280_read_humid_adc(data, &adc_humidity); in bme280_read_humid()
621 *comp_humidity = bme280_compensate_humidity(data, adc_humidity, t_fine); in bme280_read_humid()
630 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_read_raw_impl() local
634 guard(mutex)(&data->lock); 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()
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()
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()
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()
724 if (!data->chip_info->sampling_freq_avail) 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()
734 *val = (1 << data->iir_filter_coeff) - 1; in bmp280_read_raw_impl()
745 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_read_raw() local
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()
756 static int bme280_write_oversampling_ratio_humid(struct bmp280_data *data, in bme280_write_oversampling_ratio_humid() argument
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()
781 static int bmp280_write_oversampling_ratio_temp(struct bmp280_data *data, in bmp280_write_oversampling_ratio_temp() argument
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()
806 static int bmp280_write_oversampling_ratio_press(struct bmp280_data *data, in bmp280_write_oversampling_ratio_press() argument
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()
831 static int bmp280_write_sampling_frequency(struct bmp280_data *data, in bmp280_write_sampling_frequency() argument
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()
856 static int bmp280_write_iir_filter_coeffs(struct bmp280_data *data, int val) in bmp280_write_iir_filter_coeffs() argument
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()
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()
885 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_write_raw_impl() local
887 guard(mutex)(&data->lock); in bmp280_write_raw_impl()
899 return bme280_write_oversampling_ratio_humid(data, val); in bmp280_write_raw_impl()
901 return bmp280_write_oversampling_ratio_press(data, val); in bmp280_write_raw_impl()
903 return bmp280_write_oversampling_ratio_temp(data, val); in bmp280_write_raw_impl()
908 return bmp280_write_sampling_frequency(data, val, val2); in bmp280_write_raw_impl()
910 return bmp280_write_iir_filter_coeffs(data, val); in bmp280_write_raw_impl()
920 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_write_raw() local
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()
936 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_read_avail() local
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()
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()
986 static int bmp280_chip_config(struct bmp280_data *data) in bmp280_chip_config() argument
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()
1017 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_trigger_handler() local
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()
1047 t_fine = bmp280_calc_t_fine(data, adc_temp); 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()
1107 static int bme280_chip_config(struct bmp280_data *data) in bme280_chip_config() argument
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()
1123 return bmp280_chip_config(data); in bme280_chip_config()
1130 struct bmp280_data *data = iio_priv(indio_dev); in bme280_trigger_handler() local
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()
1160 t_fine = bmp280_calc_t_fine(data, adc_temp); 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()
1231 static int bmp380_cmd(struct bmp280_data *data, u8 cmd) in bmp380_cmd() argument
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()
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()
1269 static int bmp380_read_temp_adc(struct bmp280_data *data, u32 *adc_temp) in bmp380_read_temp_adc() argument
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()
1298 static s32 bmp380_calc_t_fine(struct bmp280_data *data, u32 adc_temp) in bmp380_calc_t_fine() argument
1301 struct bmp380_calib *calib = &data->calib.bmp380; in bmp380_calc_t_fine()
1312 static int bmp380_get_t_fine(struct bmp280_data *data, s32 *t_fine) in bmp380_get_t_fine() argument
1317 ret = bmp380_read_temp_adc(data, &adc_temp); in bmp380_get_t_fine()
1321 *t_fine = bmp380_calc_t_fine(data, adc_temp); in bmp380_get_t_fine()
1326 static int bmp380_compensate_temp(struct bmp280_data *data, u32 adc_temp) in bmp380_compensate_temp() argument
1331 var6 = bmp380_calc_t_fine(data, adc_temp); in bmp380_compensate_temp()
1338 static int bmp380_read_press_adc(struct bmp280_data *data, u32 *adc_press) in bmp380_read_press_adc() argument
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()
1367 static u32 bmp380_compensate_press(struct bmp280_data *data, in bmp380_compensate_press() argument
1371 struct bmp380_calib *calib = &data->calib.bmp380; in bmp380_compensate_press()
1408 static int bmp380_read_temp(struct bmp280_data *data, s32 *comp_temp) in bmp380_read_temp() argument
1413 ret = bmp380_read_temp_adc(data, &adc_temp); in bmp380_read_temp()
1417 *comp_temp = bmp380_compensate_temp(data, adc_temp); in bmp380_read_temp()
1422 static int bmp380_read_press(struct bmp280_data *data, u32 *comp_press) in bmp380_read_press() argument
1427 ret = bmp380_get_t_fine(data, &t_fine); in bmp380_read_press()
1431 ret = bmp380_read_press_adc(data, &adc_press); in bmp380_read_press()
1435 *comp_press = bmp380_compensate_press(data, adc_press, t_fine); in bmp380_read_press()
1440 static int bmp380_read_calib(struct bmp280_data *data) in bmp380_read_calib() argument
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()
1499 static int bmp380_preinit(struct bmp280_data *data) in bmp380_preinit() argument
1502 return bmp380_cmd(data, BMP380_CMD_SOFT_RESET); in bmp380_preinit()
1505 static int bmp380_chip_config(struct bmp280_data *data) in bmp380_chip_config() argument
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()
1532 dev_err(data->dev, "failed to write oversampling register\n"); 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()
1542 dev_err(data->dev, "failed to write ODR selection register\n"); 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()
1552 dev_err(data->dev, "failed to write config register\n"); 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()
1610 struct bmp280_data *data = iio_priv(indio_dev); in bmp380_trigger_handler() local
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()
1640 t_fine = bmp380_calc_t_fine(data, adc_temp); 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()
1701 static int bmp580_soft_reset(struct bmp280_data *data) in bmp580_soft_reset() argument
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()
1738 static int bmp580_nvm_operation(struct bmp280_data *data, bool is_write) in bmp580_nvm_operation() argument
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()
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()
1813 static int bmp580_read_temp(struct bmp280_data *data, s32 *raw_temp) in bmp580_read_temp() argument
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()
1835 static int bmp580_read_press(struct bmp280_data *data, u32 *raw_press) in bmp580_read_press() argument
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()
1897 struct bmp280_data *data = priv; in bmp580_nvmem_read_impl() local
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()
1925 ret = bmp580_nvm_operation(data, false); 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()
1942 data->chip_info->chip_config(data); in bmp580_nvmem_read_impl()
1949 struct bmp280_data *data = priv; in bmp580_nvmem_read() local
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()
1963 struct bmp280_data *data = priv; in bmp580_nvmem_write_impl() local
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()
2000 ret = bmp580_nvm_operation(data, true); 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()
2017 data->chip_info->chip_config(data); in bmp580_nvmem_write_impl()
2024 struct bmp280_data *data = priv; in bmp580_nvmem_write() local
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()
2035 static int bmp580_preinit(struct bmp280_data *data) in bmp580_preinit() argument
2038 .dev = data->dev, in bmp580_preinit()
2039 .priv = data, in bmp580_preinit()
2051 ret = bmp580_soft_reset(data); 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()
2082 static int bmp580_chip_config(struct bmp280_data *data) in bmp580_chip_config() argument
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()
2125 dev_err(data->dev, "failed to write oversampling register\n"); 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()
2135 dev_err(data->dev, "failed to write ODR configuration register\n"); 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()
2149 dev_err(data->dev, "failed to write config register\n"); 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()
2192 struct bmp280_data *data = iio_priv(indio_dev); in bmp580_trigger_handler() local
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()
2266 static int bmp180_wait_for_eoc(struct bmp280_data *data, u8 ctrl_meas) in bmp180_wait_for_eoc() argument
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()
2317 static int bmp180_read_temp_adc(struct bmp280_data *data, u32 *adc_temp) in bmp180_read_temp_adc() argument
2321 ret = bmp180_wait_for_eoc(data, in bmp180_read_temp_adc()
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()
2339 static int bmp180_read_calib(struct bmp280_data *data) in bmp180_read_calib() argument
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()
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()
2385 static s32 bmp180_calc_t_fine(struct bmp280_data *data, u32 adc_temp) in bmp180_calc_t_fine() argument
2387 struct bmp180_calib *calib = &data->calib.bmp180; in bmp180_calc_t_fine()
2395 static int bmp180_get_t_fine(struct bmp280_data *data, s32 *t_fine) in bmp180_get_t_fine() argument
2400 ret = bmp180_read_temp_adc(data, &adc_temp); in bmp180_get_t_fine()
2404 *t_fine = bmp180_calc_t_fine(data, adc_temp); in bmp180_get_t_fine()
2409 static s32 bmp180_compensate_temp(struct bmp280_data *data, u32 adc_temp) in bmp180_compensate_temp() argument
2411 return (bmp180_calc_t_fine(data, adc_temp) + 8) / 16; in bmp180_compensate_temp()
2414 static int bmp180_read_temp(struct bmp280_data *data, s32 *comp_temp) in bmp180_read_temp() argument
2419 ret = bmp180_read_temp_adc(data, &adc_temp); in bmp180_read_temp()
2423 *comp_temp = bmp180_compensate_temp(data, adc_temp); in bmp180_read_temp()
2428 static int bmp180_read_press_adc(struct bmp280_data *data, u32 *adc_press) in bmp180_read_press_adc() argument
2430 u8 oss = data->oversampling_press; in bmp180_read_press_adc()
2433 ret = bmp180_wait_for_eoc(data, 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()
2457 static u32 bmp180_compensate_press(struct bmp280_data *data, u32 adc_press, in bmp180_compensate_press() argument
2460 struct bmp180_calib *calib = &data->calib.bmp180; in bmp180_compensate_press()
2461 s32 oss = data->oversampling_press; in bmp180_compensate_press()
2488 static int bmp180_read_press(struct bmp280_data *data, u32 *comp_press) in bmp180_read_press() argument
2494 ret = bmp180_get_t_fine(data, &t_fine); in bmp180_read_press()
2498 ret = bmp180_read_press_adc(data, &adc_press); in bmp180_read_press()
2502 *comp_press = bmp180_compensate_press(data, adc_press, t_fine); in bmp180_read_press()
2507 static int bmp180_chip_config(struct bmp280_data *data) in bmp180_chip_config() argument
2516 struct bmp280_data *data = iio_priv(indio_dev); in bmp180_trigger_handler() local
2519 guard(mutex)(&data->lock); in bmp180_trigger_handler()
2521 ret = bmp180_read_temp(data, &chan_value); in bmp180_trigger_handler()
2525 data->sensor_data[1] = chan_value; in bmp180_trigger_handler()
2527 ret = bmp180_read_press(data, &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()
2584 struct bmp280_data *data = d; in bmp085_eoc_irq() local
2586 complete(&data->done); in bmp085_eoc_irq()
2594 struct bmp280_data *data) in bmp085_fetch_eoc_irq() argument
2605 init_completion(&data->done); in bmp085_fetch_eoc_irq()
2613 data); in bmp085_fetch_eoc_irq()
2620 data->use_eoc = true; in bmp085_fetch_eoc_irq()
2626 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_buffer_preenable() local
2628 pm_runtime_get_sync(data->dev); in bmp280_buffer_preenable()
2635 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_buffer_postdisable() local
2637 pm_runtime_mark_last_busy(data->dev); in bmp280_buffer_postdisable()
2638 pm_runtime_put_autosuspend(data->dev); in bmp280_buffer_postdisable()
2648 static void bmp280_pm_disable(void *data) in bmp280_pm_disable() argument
2650 struct device *dev = data; in bmp280_pm_disable()
2657 static void bmp280_regulators_disable(void *data) in bmp280_regulators_disable() argument
2659 struct regulator_bulk_data *supplies = data; in bmp280_regulators_disable()
2671 struct bmp280_data *data; in bmp280_common_probe() local
2677 indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); in bmp280_common_probe()
2681 data = iio_priv(indio_dev); in bmp280_common_probe()
2682 mutex_init(&data->lock); in bmp280_common_probe()
2683 data->dev = dev; in bmp280_common_probe()
2689 data->chip_info = chip_info; 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()
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()
2794 ret = bmp085_fetch_eoc_irq(dev, name, irq, data); in bmp280_common_probe()
2807 pm_runtime_set_autosuspend_delay(dev, data->start_up_time / 10); in bmp280_common_probe()
2822 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_runtime_suspend() local
2824 return regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies); in bmp280_runtime_suspend()
2830 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_runtime_resume() local
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()