Lines Matching full:data

312 static int bmp280_read_calib(struct bmp280_data *data)  in bmp280_read_calib()  argument
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()
327 /* Toss calibration data into the entropy pool */ 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()
358 static int bme280_read_calib(struct bmp280_data *data) in bme280_read_calib() argument
360 struct bmp280_calib *calib = &data->calib.bmp280; in bme280_read_calib()
361 struct device *dev = data->dev; in bme280_read_calib()
367 ret = bmp280_read_calib(data); in bme280_read_calib()
371 ret = regmap_read(data->regmap, BME280_REG_COMP_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()
393 tmp_3 = get_unaligned_le16(&data->bme280_humid_cal_buf[H5]); in bme280_read_calib()
395 calib->H6 = data->bme280_humid_cal_buf[H6]; in bme280_read_calib()
400 static int bme280_read_humid_adc(struct bmp280_data *data, u16 *adc_humidity) in bme280_read_humid_adc() argument
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()
428 static u32 bme280_compensate_humidity(struct bmp280_data *data, in bme280_compensate_humidity() argument
431 struct bmp280_calib *calib = &data->calib.bmp280; in bme280_compensate_humidity()
446 static int bmp280_read_temp_adc(struct bmp280_data *data, u32 *adc_temp) in bmp280_read_temp_adc() argument
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()
475 static s32 bmp280_calc_t_fine(struct bmp280_data *data, u32 adc_temp) in bmp280_calc_t_fine() argument
477 struct bmp280_calib *calib = &data->calib.bmp280; in bmp280_calc_t_fine()
488 static int bmp280_get_t_fine(struct bmp280_data *data, s32 *t_fine) in bmp280_get_t_fine() argument
493 ret = bmp280_read_temp_adc(data, &adc_temp); in bmp280_get_t_fine()
497 *t_fine = bmp280_calc_t_fine(data, adc_temp); in bmp280_get_t_fine()
502 static s32 bmp280_compensate_temp(struct bmp280_data *data, u32 adc_temp) in bmp280_compensate_temp() argument
504 return (bmp280_calc_t_fine(data, adc_temp) * 5 + 128) / 256; in bmp280_compensate_temp()
507 static int bmp280_read_press_adc(struct bmp280_data *data, u32 *adc_press) in bmp280_read_press_adc() argument
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()
536 static u32 bmp280_compensate_press(struct bmp280_data *data, in bmp280_compensate_press() argument
539 struct bmp280_calib *calib = &data->calib.bmp280; in bmp280_compensate_press()
562 static int bmp280_read_temp(struct bmp280_data *data, s32 *comp_temp) in bmp280_read_temp() argument
567 ret = bmp280_read_temp_adc(data, &adc_temp); in bmp280_read_temp()
571 *comp_temp = bmp280_compensate_temp(data, adc_temp); in bmp280_read_temp()
576 static int bmp280_read_press(struct bmp280_data *data, u32 *comp_press) in bmp280_read_press() argument
582 ret = bmp280_get_t_fine(data, &t_fine); in bmp280_read_press()
586 ret = bmp280_read_press_adc(data, &adc_press); in bmp280_read_press()
590 *comp_press = bmp280_compensate_press(data, adc_press, t_fine); in bmp280_read_press()
595 static int bme280_read_humid(struct bmp280_data *data, u32 *comp_humidity) in bme280_read_humid() argument
601 ret = bmp280_get_t_fine(data, &t_fine); in bme280_read_humid()
605 ret = bme280_read_humid_adc(data, &adc_humidity); in bme280_read_humid()
609 *comp_humidity = bme280_compensate_humidity(data, adc_humidity, t_fine); in bme280_read_humid()
618 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_read_raw_impl() local
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()
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()
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()
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()
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()
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()
728 if (!data->chip_info->sampling_freq_avail) 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()
738 *val = (1 << data->iir_filter_coeff) - 1; in bmp280_read_raw_impl()
749 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_read_raw() local
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()
760 static int bme280_write_oversampling_ratio_humid(struct bmp280_data *data, in bme280_write_oversampling_ratio_humid() argument
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()
785 static int bmp280_write_oversampling_ratio_temp(struct bmp280_data *data, in bmp280_write_oversampling_ratio_temp() argument
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()
810 static int bmp280_write_oversampling_ratio_press(struct bmp280_data *data, in bmp280_write_oversampling_ratio_press() argument
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()
835 static int bmp280_write_sampling_frequency(struct bmp280_data *data, in bmp280_write_sampling_frequency() argument
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()
860 static int bmp280_write_iir_filter_coeffs(struct bmp280_data *data, int val) in bmp280_write_iir_filter_coeffs() argument
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()
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()
889 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_write_raw_impl() local
891 guard(mutex)(&data->lock); in bmp280_write_raw_impl()
903 return bme280_write_oversampling_ratio_humid(data, val); in bmp280_write_raw_impl()
905 return bmp280_write_oversampling_ratio_press(data, val); in bmp280_write_raw_impl()
907 return bmp280_write_oversampling_ratio_temp(data, val); in bmp280_write_raw_impl()
912 return bmp280_write_sampling_frequency(data, val, val2); in bmp280_write_raw_impl()
914 return bmp280_write_iir_filter_coeffs(data, val); in bmp280_write_raw_impl()
924 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_write_raw() local
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()
940 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_read_avail() local
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()
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()
990 static int bmp280_preinit(struct bmp280_data *data) in bmp280_preinit() argument
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()
1005 fsleep(data->start_up_time); in bmp280_preinit()
1007 ret = regmap_read(data->regmap, BMP280_REG_STATUS, &reg); in bmp280_preinit()
1023 static int bmp280_set_mode(struct bmp280_data *data, enum bmp280_op_mode mode) in bmp280_set_mode() argument
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()
1039 static int bmp280_wait_conv(struct bmp280_data *data) in bmp280_wait_conv() argument
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, &reg); 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()
1076 static int bmp280_chip_config(struct bmp280_data *data) in bmp280_chip_config() argument
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()
1107 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_trigger_handler() local
1110 s32 *chans = (s32 *)data->sensor_data; in bmp280_trigger_handler()
1113 guard(mutex)(&data->lock); in bmp280_trigger_handler()
1115 /* Burst read data registers */ 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()
1130 comp_temp = bmp280_compensate_temp(data, adc_temp); 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()
1139 t_fine = bmp280_calc_t_fine(data, adc_temp); in bmp280_trigger_handler()
1140 comp_press = bmp280_compensate_press(data, adc_press, t_fine); in bmp280_trigger_handler()
1145 iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data, in bmp280_trigger_handler()
1204 static int bme280_chip_config(struct bmp280_data *data) in bme280_chip_config() argument
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()
1220 return bmp280_chip_config(data); in bme280_chip_config()
1227 struct bmp280_data *data = iio_priv(indio_dev); in bme280_trigger_handler() local
1230 s32 *chans = (s32 *)data->sensor_data; in bme280_trigger_handler()
1233 guard(mutex)(&data->lock); in bme280_trigger_handler()
1235 /* Burst read data registers */ 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()
1250 comp_temp = bmp280_compensate_temp(data, adc_temp); 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()
1259 t_fine = bmp280_calc_t_fine(data, adc_temp); in bme280_trigger_handler()
1260 comp_press = bmp280_compensate_press(data, adc_press, t_fine); 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()
1270 comp_humidity = bme280_compensate_humidity(data, adc_humidity, t_fine); in bme280_trigger_handler()
1276 iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data, in bme280_trigger_handler()
1287 int (*int_pin_config)(struct bmp280_data *data), in __bmp280_trigger_probe() argument
1290 struct bmp280_data *data = iio_priv(indio_dev); in __bmp280_trigger_probe() local
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()
1311 data->trig_open_drain = in __bmp280_trigger_probe()
1314 ret = int_pin_config(data); in __bmp280_trigger_probe()
1318 data->trig = devm_iio_trigger_alloc(data->dev, "%s-dev%d", in __bmp280_trigger_probe()
1321 if (!data->trig) 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()
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()
1394 static int bmp380_cmd(struct bmp280_data *data, u8 cmd) in bmp380_cmd() argument
1400 ret = regmap_read(data->regmap, BMP380_REG_STATUS, &reg); 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()
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, &reg); 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()
1432 static int bmp380_read_temp_adc(struct bmp280_data *data, u32 *adc_temp) in bmp380_read_temp_adc() argument
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()
1461 static s32 bmp380_calc_t_fine(struct bmp280_data *data, u32 adc_temp) in bmp380_calc_t_fine() argument
1464 struct bmp380_calib *calib = &data->calib.bmp380; in bmp380_calc_t_fine()
1475 static int bmp380_get_t_fine(struct bmp280_data *data, s32 *t_fine) in bmp380_get_t_fine() argument
1480 ret = bmp380_read_temp_adc(data, &adc_temp); in bmp380_get_t_fine()
1484 *t_fine = bmp380_calc_t_fine(data, adc_temp); in bmp380_get_t_fine()
1489 static int bmp380_compensate_temp(struct bmp280_data *data, u32 adc_temp) in bmp380_compensate_temp() argument
1494 var6 = bmp380_calc_t_fine(data, adc_temp); in bmp380_compensate_temp()
1501 static int bmp380_read_press_adc(struct bmp280_data *data, u32 *adc_press) in bmp380_read_press_adc() argument
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()
1530 static u32 bmp380_compensate_press(struct bmp280_data *data, in bmp380_compensate_press() argument
1534 struct bmp380_calib *calib = &data->calib.bmp380; in bmp380_compensate_press()
1571 static int bmp380_read_temp(struct bmp280_data *data, s32 *comp_temp) in bmp380_read_temp() argument
1576 ret = bmp380_read_temp_adc(data, &adc_temp); in bmp380_read_temp()
1580 *comp_temp = bmp380_compensate_temp(data, adc_temp); in bmp380_read_temp()
1585 static int bmp380_read_press(struct bmp280_data *data, u32 *comp_press) in bmp380_read_press() argument
1590 ret = bmp380_get_t_fine(data, &t_fine); in bmp380_read_press()
1594 ret = bmp380_read_press_adc(data, &adc_press); in bmp380_read_press()
1598 *comp_press = bmp380_compensate_press(data, adc_press, t_fine); in bmp380_read_press()
1603 static int bmp380_read_calib(struct bmp280_data *data) in bmp380_read_calib() argument
1605 struct bmp380_calib *calib = &data->calib.bmp380; in bmp380_read_calib()
1608 /* Read temperature and pressure calibration data */ 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()
1618 /* Toss the temperature calibration data into the entropy pool */ 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()
1662 static int bmp380_preinit(struct bmp280_data *data) in bmp380_preinit() argument
1665 return bmp380_cmd(data, BMP380_CMD_SOFT_RESET); in bmp380_preinit()
1674 static int bmp380_set_mode(struct bmp280_data *data, enum bmp280_op_mode mode) in bmp380_set_mode() argument
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()
1692 static int bmp380_wait_conv(struct bmp280_data *data) in bmp380_wait_conv() argument
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, &reg); 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()
1726 static int bmp380_chip_config(struct bmp280_data *data) in bmp380_chip_config() argument
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()
1758 /* Configure output data rate */ 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()
1768 /* Set filter data */ 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()
1786 ret = bmp380_set_mode(data, BMP280_SLEEP); in bmp380_chip_config()
1788 dev_err(data->dev, "failed to set sleep mode\n"); in bmp380_chip_config()
1798 ret = bmp380_set_mode(data, BMP280_NORMAL); 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()
1824 /* Dummy read to empty data registers. */ in bmp380_chip_config()
1825 ret = bmp380_read_press(data, &tmp); in bmp380_chip_config()
1829 ret = bmp380_set_mode(data, BMP280_SLEEP); in bmp380_chip_config()
1831 dev_err(data->dev, "failed to set sleep mode.\n"); in bmp380_chip_config()
1839 struct bmp280_data *data = iio_trigger_get_drvdata(trig); in bmp380_data_rdy_trigger_set_state() local
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()
1857 static int bmp380_int_pin_config(struct bmp280_data *data) in bmp380_int_pin_config() argument
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()
1876 struct bmp280_data *data = iio_priv(indio_dev); in bmp380_irq_thread_handler() local
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()
1901 struct bmp280_data *data = iio_priv(indio_dev); in bmp380_trigger_handler() local
1904 s32 *chans = (s32 *)data->sensor_data; in bmp380_trigger_handler()
1907 guard(mutex)(&data->lock); in bmp380_trigger_handler()
1909 /* Burst read data registers */ 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()
1924 comp_temp = bmp380_compensate_temp(data, adc_temp); 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()
1933 t_fine = bmp380_calc_t_fine(data, adc_temp); in bmp380_trigger_handler()
1934 comp_press = bmp380_compensate_press(data, adc_press, t_fine); in bmp380_trigger_handler()
1939 iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data, in bmp380_trigger_handler()
1999 static int bmp580_soft_reset(struct bmp280_data *data) in bmp580_soft_reset() argument
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, &reg); 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, &reg); 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()
2033 * @data: sensor data struct
2036 static int bmp580_nvm_operation(struct bmp280_data *data, bool is_write) in bmp580_nvm_operation() argument
2043 ret = regmap_read(data->regmap, BMP580_REG_STATUS, &reg); 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()
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()
2107 * We are only required to read the register raw data and adapt the ranges
2111 static int bmp580_read_temp(struct bmp280_data *data, s32 *raw_temp) in bmp580_read_temp() argument
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()
2133 static int bmp580_read_press(struct bmp280_data *data, u32 *raw_press) in bmp580_read_press() argument
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()
2195 struct bmp280_data *data = priv; in bmp580_nvmem_read_impl() local
2199 guard(mutex)(&data->lock); 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()
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()
2223 ret = bmp580_nvm_operation(data, false); 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()
2240 data->chip_info->chip_config(data); in bmp580_nvmem_read_impl()
2247 struct bmp280_data *data = priv; in bmp580_nvmem_read() local
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()
2261 struct bmp280_data *data = priv; in bmp580_nvmem_write_impl() local
2265 guard(mutex)(&data->lock); 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()
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()
2298 ret = bmp580_nvm_operation(data, true); 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()
2315 data->chip_info->chip_config(data); in bmp580_nvmem_write_impl()
2322 struct bmp280_data *data = priv; in bmp580_nvmem_write() local
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()
2333 static int bmp580_preinit(struct bmp280_data *data) in bmp580_preinit() argument
2336 .dev = data->dev, in bmp580_preinit()
2337 .priv = data, in bmp580_preinit()
2349 ret = bmp580_soft_reset(data); in bmp580_preinit()
2354 ret = regmap_read(data->regmap, BMP580_REG_CHIP_ID, &reg); 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, &reg); 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()
2386 static int bmp580_set_mode(struct bmp280_data *data, enum bmp280_op_mode mode) in bmp580_set_mode() argument
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()
2414 static int bmp580_wait_conv(struct bmp280_data *data) in bmp580_wait_conv() argument
2431 time_conv_temp[data->oversampling_temp] + in bmp580_wait_conv()
2432 time_conv_press[data->oversampling_press]; in bmp580_wait_conv()
2444 static int bmp580_chip_config(struct bmp280_data *data) in bmp580_chip_config() argument
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()
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()
2492 /* Configure output data rate */ 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()
2502 /* Set filter data */ 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()
2527 /* Set current OSR settings from data on effective OSR */ 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()
2540 struct bmp280_data *data = iio_trigger_get_drvdata(trig); in bmp580_data_rdy_trigger_set_state() local
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()
2558 static int bmp580_int_pin_config(struct bmp280_data *data) in bmp580_int_pin_config() argument
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()
2584 struct bmp280_data *data = iio_priv(indio_dev); in bmp580_irq_thread_handler() local
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()
2609 struct bmp280_data *data = iio_priv(indio_dev); in bmp580_trigger_handler() local
2612 guard(mutex)(&data->lock); in bmp580_trigger_handler()
2614 /* Burst read data registers */ 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()
2690 static int bmp180_wait_for_eoc(struct bmp280_data *data, u8 ctrl_meas) in bmp180_wait_for_eoc() argument
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()
2741 static int bmp180_read_temp_adc(struct bmp280_data *data, u32 *adc_temp) in bmp180_read_temp_adc() argument
2745 ret = bmp180_wait_for_eoc(data, in bmp180_read_temp_adc()
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()
2763 static int bmp180_read_calib(struct bmp280_data *data) in bmp180_read_calib() argument
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()
2783 /* Toss the calibration data into the entropy pool */ 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()
2809 static s32 bmp180_calc_t_fine(struct bmp280_data *data, u32 adc_temp) in bmp180_calc_t_fine() argument
2811 struct bmp180_calib *calib = &data->calib.bmp180; in bmp180_calc_t_fine()
2819 static int bmp180_get_t_fine(struct bmp280_data *data, s32 *t_fine) in bmp180_get_t_fine() argument
2824 ret = bmp180_read_temp_adc(data, &adc_temp); in bmp180_get_t_fine()
2828 *t_fine = bmp180_calc_t_fine(data, adc_temp); in bmp180_get_t_fine()
2833 static s32 bmp180_compensate_temp(struct bmp280_data *data, u32 adc_temp) in bmp180_compensate_temp() argument
2835 return (bmp180_calc_t_fine(data, adc_temp) + 8) / 16; in bmp180_compensate_temp()
2838 static int bmp180_read_temp(struct bmp280_data *data, s32 *comp_temp) in bmp180_read_temp() argument
2843 ret = bmp180_read_temp_adc(data, &adc_temp); in bmp180_read_temp()
2847 *comp_temp = bmp180_compensate_temp(data, adc_temp); in bmp180_read_temp()
2852 static int bmp180_read_press_adc(struct bmp280_data *data, u32 *adc_press) in bmp180_read_press_adc() argument
2854 u8 oss = data->oversampling_press; in bmp180_read_press_adc()
2857 ret = bmp180_wait_for_eoc(data, 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()
2881 static u32 bmp180_compensate_press(struct bmp280_data *data, u32 adc_press, in bmp180_compensate_press() argument
2884 struct bmp180_calib *calib = &data->calib.bmp180; in bmp180_compensate_press()
2885 s32 oss = data->oversampling_press; in bmp180_compensate_press()
2912 static int bmp180_read_press(struct bmp280_data *data, u32 *comp_press) in bmp180_read_press() argument
2918 ret = bmp180_get_t_fine(data, &t_fine); in bmp180_read_press()
2922 ret = bmp180_read_press_adc(data, &adc_press); in bmp180_read_press()
2926 *comp_press = bmp180_compensate_press(data, adc_press, t_fine); in bmp180_read_press()
2932 static int bmp180_set_mode(struct bmp280_data *data, enum bmp280_op_mode mode) in bmp180_set_mode() argument
2938 static int bmp180_wait_conv(struct bmp280_data *data) in bmp180_wait_conv() argument
2944 static int bmp180_chip_config(struct bmp280_data *data) in bmp180_chip_config() argument
2953 struct bmp280_data *data = iio_priv(indio_dev); in bmp180_trigger_handler() local
2955 s32 *chans = (s32 *)data->sensor_data; in bmp180_trigger_handler()
2957 guard(mutex)(&data->lock); in bmp180_trigger_handler()
2959 ret = bmp180_read_temp(data, &comp_temp); in bmp180_trigger_handler()
2964 ret = bmp180_read_press(data, &comp_press); in bmp180_trigger_handler()
2971 iio_push_to_buffers_with_timestamp(indio_dev, data->sensor_data, in bmp180_trigger_handler()
3024 struct bmp280_data *data = d; in bmp085_eoc_irq() local
3026 complete(&data->done); in bmp085_eoc_irq()
3033 struct bmp280_data *data = iio_priv(indio_dev); in bmp085_trigger_probe() local
3034 struct device *dev = data->dev; 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()
3103 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_buffer_preenable() local
3105 pm_runtime_get_sync(data->dev); in bmp280_buffer_preenable()
3106 data->chip_info->set_mode(data, BMP280_NORMAL); in bmp280_buffer_preenable()
3113 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_buffer_postdisable() local
3115 pm_runtime_mark_last_busy(data->dev); in bmp280_buffer_postdisable()
3116 pm_runtime_put_autosuspend(data->dev); in bmp280_buffer_postdisable()
3126 static void bmp280_pm_disable(void *data) in bmp280_pm_disable() argument
3128 struct device *dev = data; in bmp280_pm_disable()
3135 static void bmp280_regulators_disable(void *data) in bmp280_regulators_disable() argument
3137 struct regulator_bulk_data *supplies = data; in bmp280_regulators_disable()
3149 struct bmp280_data *data; in bmp280_common_probe() local
3155 indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); in bmp280_common_probe()
3159 data = iio_priv(indio_dev); in bmp280_common_probe()
3160 mutex_init(&data->lock); in bmp280_common_probe()
3161 data->dev = dev; in bmp280_common_probe()
3167 data->chip_info = chip_info; 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()
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()
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()
3290 pm_runtime_set_autosuspend_delay(dev, data->start_up_time / 10); in bmp280_common_probe()
3305 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_runtime_suspend() local
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()
3316 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_runtime_resume() local
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()