Lines Matching refs:data
178 static int bmp280_read_calib(struct bmp280_data *data) in bmp280_read_calib() argument
180 struct bmp280_calib *calib = &data->calib.bmp280; in bmp280_read_calib()
185 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_TEMP_START, in bmp280_read_calib()
186 data->bmp280_cal_buf, sizeof(data->bmp280_cal_buf)); in bmp280_read_calib()
188 dev_err(data->dev, in bmp280_read_calib()
194 add_device_randomness(data->bmp280_cal_buf, sizeof(data->bmp280_cal_buf)); in bmp280_read_calib()
197 calib->T1 = le16_to_cpu(data->bmp280_cal_buf[T1]); in bmp280_read_calib()
198 calib->T2 = le16_to_cpu(data->bmp280_cal_buf[T2]); in bmp280_read_calib()
199 calib->T3 = le16_to_cpu(data->bmp280_cal_buf[T3]); in bmp280_read_calib()
202 calib->P1 = le16_to_cpu(data->bmp280_cal_buf[P1]); in bmp280_read_calib()
203 calib->P2 = le16_to_cpu(data->bmp280_cal_buf[P2]); in bmp280_read_calib()
204 calib->P3 = le16_to_cpu(data->bmp280_cal_buf[P3]); in bmp280_read_calib()
205 calib->P4 = le16_to_cpu(data->bmp280_cal_buf[P4]); in bmp280_read_calib()
206 calib->P5 = le16_to_cpu(data->bmp280_cal_buf[P5]); in bmp280_read_calib()
207 calib->P6 = le16_to_cpu(data->bmp280_cal_buf[P6]); in bmp280_read_calib()
208 calib->P7 = le16_to_cpu(data->bmp280_cal_buf[P7]); in bmp280_read_calib()
209 calib->P8 = le16_to_cpu(data->bmp280_cal_buf[P8]); in bmp280_read_calib()
210 calib->P9 = le16_to_cpu(data->bmp280_cal_buf[P9]); in bmp280_read_calib()
215 static int bme280_read_calib(struct bmp280_data *data) in bme280_read_calib() argument
217 struct bmp280_calib *calib = &data->calib.bmp280; in bme280_read_calib()
218 struct device *dev = data->dev; in bme280_read_calib()
223 ret = bmp280_read_calib(data); in bme280_read_calib()
237 ret = regmap_read(data->regmap, BMP280_REG_COMP_H1, &tmp); in bme280_read_calib()
244 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H2, in bme280_read_calib()
245 &data->le16, sizeof(data->le16)); in bme280_read_calib()
250 calib->H2 = sign_extend32(le16_to_cpu(data->le16), 15); in bme280_read_calib()
252 ret = regmap_read(data->regmap, BMP280_REG_COMP_H3, &tmp); in bme280_read_calib()
259 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H4, in bme280_read_calib()
260 &data->be16, sizeof(data->be16)); in bme280_read_calib()
265 calib->H4 = sign_extend32(((be16_to_cpu(data->be16) >> 4) & 0xff0) | in bme280_read_calib()
266 (be16_to_cpu(data->be16) & 0xf), 11); in bme280_read_calib()
268 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H5, in bme280_read_calib()
269 &data->le16, sizeof(data->le16)); in bme280_read_calib()
274 calib->H5 = sign_extend32(FIELD_GET(BMP280_COMP_H5_MASK, le16_to_cpu(data->le16)), 11); in bme280_read_calib()
276 ret = regmap_read(data->regmap, BMP280_REG_COMP_H6, &tmp); in bme280_read_calib()
291 static u32 bmp280_compensate_humidity(struct bmp280_data *data, in bmp280_compensate_humidity() argument
294 struct bmp280_calib *calib = &data->calib.bmp280; in bmp280_compensate_humidity()
297 var = ((s32)data->t_fine) - (s32)76800; in bmp280_compensate_humidity()
316 static s32 bmp280_compensate_temp(struct bmp280_data *data, in bmp280_compensate_temp() argument
319 struct bmp280_calib *calib = &data->calib.bmp280; in bmp280_compensate_temp()
327 data->t_fine = var1 + var2; in bmp280_compensate_temp()
329 return (data->t_fine * 5 + 128) >> 8; in bmp280_compensate_temp()
339 static u32 bmp280_compensate_press(struct bmp280_data *data, in bmp280_compensate_press() argument
342 struct bmp280_calib *calib = &data->calib.bmp280; in bmp280_compensate_press()
345 var1 = ((s64)data->t_fine) - 128000; in bmp280_compensate_press()
365 static int bmp280_read_temp(struct bmp280_data *data, in bmp280_read_temp() argument
371 ret = regmap_bulk_read(data->regmap, BMP280_REG_TEMP_MSB, in bmp280_read_temp()
372 data->buf, sizeof(data->buf)); in bmp280_read_temp()
374 dev_err(data->dev, "failed to read temperature\n"); in bmp280_read_temp()
378 adc_temp = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(data->buf)); in bmp280_read_temp()
381 dev_err(data->dev, "reading temperature skipped\n"); in bmp280_read_temp()
384 comp_temp = bmp280_compensate_temp(data, adc_temp); in bmp280_read_temp()
398 static int bmp280_read_press(struct bmp280_data *data, in bmp280_read_press() argument
406 ret = bmp280_read_temp(data, NULL, NULL); in bmp280_read_press()
410 ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB, in bmp280_read_press()
411 data->buf, sizeof(data->buf)); in bmp280_read_press()
413 dev_err(data->dev, "failed to read pressure\n"); in bmp280_read_press()
417 adc_press = FIELD_GET(BMP280_MEAS_TRIM_MASK, get_unaligned_be24(data->buf)); in bmp280_read_press()
420 dev_err(data->dev, "reading pressure skipped\n"); in bmp280_read_press()
423 comp_press = bmp280_compensate_press(data, adc_press); in bmp280_read_press()
431 static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2) in bmp280_read_humid() argument
438 ret = bmp280_read_temp(data, NULL, NULL); in bmp280_read_humid()
442 ret = regmap_bulk_read(data->regmap, BMP280_REG_HUMIDITY_MSB, in bmp280_read_humid()
443 &data->be16, sizeof(data->be16)); in bmp280_read_humid()
445 dev_err(data->dev, "failed to read humidity\n"); in bmp280_read_humid()
449 adc_humidity = be16_to_cpu(data->be16); in bmp280_read_humid()
452 dev_err(data->dev, "reading humidity skipped\n"); in bmp280_read_humid()
455 comp_humidity = bmp280_compensate_humidity(data, adc_humidity); in bmp280_read_humid()
466 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_read_raw() local
469 pm_runtime_get_sync(data->dev); in bmp280_read_raw()
470 mutex_lock(&data->lock); in bmp280_read_raw()
476 ret = data->chip_info->read_humid(data, val, val2); in bmp280_read_raw()
479 ret = data->chip_info->read_press(data, val, val2); in bmp280_read_raw()
482 ret = data->chip_info->read_temp(data, val, val2); in bmp280_read_raw()
492 *val = 1 << data->oversampling_humid; in bmp280_read_raw()
496 *val = 1 << data->oversampling_press; in bmp280_read_raw()
500 *val = 1 << data->oversampling_temp; in bmp280_read_raw()
509 if (!data->chip_info->sampling_freq_avail) { in bmp280_read_raw()
514 *val = data->chip_info->sampling_freq_avail[data->sampling_freq][0]; in bmp280_read_raw()
515 *val2 = data->chip_info->sampling_freq_avail[data->sampling_freq][1]; in bmp280_read_raw()
519 if (!data->chip_info->iir_filter_coeffs_avail) { in bmp280_read_raw()
524 *val = (1 << data->iir_filter_coeff) - 1; in bmp280_read_raw()
532 mutex_unlock(&data->lock); in bmp280_read_raw()
533 pm_runtime_mark_last_busy(data->dev); in bmp280_read_raw()
534 pm_runtime_put_autosuspend(data->dev); in bmp280_read_raw()
539 static int bmp280_write_oversampling_ratio_humid(struct bmp280_data *data, in bmp280_write_oversampling_ratio_humid() argument
542 const int *avail = data->chip_info->oversampling_humid_avail; in bmp280_write_oversampling_ratio_humid()
543 const int n = data->chip_info->num_oversampling_humid_avail; in bmp280_write_oversampling_ratio_humid()
549 prev = data->oversampling_humid; in bmp280_write_oversampling_ratio_humid()
550 data->oversampling_humid = ilog2(val); in bmp280_write_oversampling_ratio_humid()
552 ret = data->chip_info->chip_config(data); in bmp280_write_oversampling_ratio_humid()
554 data->oversampling_humid = prev; in bmp280_write_oversampling_ratio_humid()
555 data->chip_info->chip_config(data); in bmp280_write_oversampling_ratio_humid()
564 static int bmp280_write_oversampling_ratio_temp(struct bmp280_data *data, in bmp280_write_oversampling_ratio_temp() argument
567 const int *avail = data->chip_info->oversampling_temp_avail; in bmp280_write_oversampling_ratio_temp()
568 const int n = data->chip_info->num_oversampling_temp_avail; in bmp280_write_oversampling_ratio_temp()
574 prev = data->oversampling_temp; in bmp280_write_oversampling_ratio_temp()
575 data->oversampling_temp = ilog2(val); in bmp280_write_oversampling_ratio_temp()
577 ret = data->chip_info->chip_config(data); in bmp280_write_oversampling_ratio_temp()
579 data->oversampling_temp = prev; in bmp280_write_oversampling_ratio_temp()
580 data->chip_info->chip_config(data); in bmp280_write_oversampling_ratio_temp()
589 static int bmp280_write_oversampling_ratio_press(struct bmp280_data *data, in bmp280_write_oversampling_ratio_press() argument
592 const int *avail = data->chip_info->oversampling_press_avail; in bmp280_write_oversampling_ratio_press()
593 const int n = data->chip_info->num_oversampling_press_avail; in bmp280_write_oversampling_ratio_press()
599 prev = data->oversampling_press; in bmp280_write_oversampling_ratio_press()
600 data->oversampling_press = ilog2(val); in bmp280_write_oversampling_ratio_press()
602 ret = data->chip_info->chip_config(data); in bmp280_write_oversampling_ratio_press()
604 data->oversampling_press = prev; in bmp280_write_oversampling_ratio_press()
605 data->chip_info->chip_config(data); in bmp280_write_oversampling_ratio_press()
614 static int bmp280_write_sampling_frequency(struct bmp280_data *data, in bmp280_write_sampling_frequency() argument
617 const int (*avail)[2] = data->chip_info->sampling_freq_avail; in bmp280_write_sampling_frequency()
618 const int n = data->chip_info->num_sampling_freq_avail; in bmp280_write_sampling_frequency()
624 prev = data->sampling_freq; in bmp280_write_sampling_frequency()
625 data->sampling_freq = i; in bmp280_write_sampling_frequency()
627 ret = data->chip_info->chip_config(data); in bmp280_write_sampling_frequency()
629 data->sampling_freq = prev; in bmp280_write_sampling_frequency()
630 data->chip_info->chip_config(data); in bmp280_write_sampling_frequency()
639 static int bmp280_write_iir_filter_coeffs(struct bmp280_data *data, int val) in bmp280_write_iir_filter_coeffs() argument
641 const int *avail = data->chip_info->iir_filter_coeffs_avail; in bmp280_write_iir_filter_coeffs()
642 const int n = data->chip_info->num_iir_filter_coeffs_avail; in bmp280_write_iir_filter_coeffs()
648 prev = data->iir_filter_coeff; in bmp280_write_iir_filter_coeffs()
649 data->iir_filter_coeff = i; in bmp280_write_iir_filter_coeffs()
651 ret = data->chip_info->chip_config(data); in bmp280_write_iir_filter_coeffs()
653 data->iir_filter_coeff = prev; in bmp280_write_iir_filter_coeffs()
654 data->chip_info->chip_config(data); in bmp280_write_iir_filter_coeffs()
668 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_write_raw() local
679 pm_runtime_get_sync(data->dev); in bmp280_write_raw()
680 mutex_lock(&data->lock); in bmp280_write_raw()
683 ret = bmp280_write_oversampling_ratio_humid(data, val); in bmp280_write_raw()
686 ret = bmp280_write_oversampling_ratio_press(data, val); in bmp280_write_raw()
689 ret = bmp280_write_oversampling_ratio_temp(data, val); in bmp280_write_raw()
695 mutex_unlock(&data->lock); in bmp280_write_raw()
696 pm_runtime_mark_last_busy(data->dev); in bmp280_write_raw()
697 pm_runtime_put_autosuspend(data->dev); in bmp280_write_raw()
700 pm_runtime_get_sync(data->dev); in bmp280_write_raw()
701 mutex_lock(&data->lock); in bmp280_write_raw()
702 ret = bmp280_write_sampling_frequency(data, val, val2); in bmp280_write_raw()
703 mutex_unlock(&data->lock); in bmp280_write_raw()
704 pm_runtime_mark_last_busy(data->dev); in bmp280_write_raw()
705 pm_runtime_put_autosuspend(data->dev); in bmp280_write_raw()
708 pm_runtime_get_sync(data->dev); in bmp280_write_raw()
709 mutex_lock(&data->lock); in bmp280_write_raw()
710 ret = bmp280_write_iir_filter_coeffs(data, val); in bmp280_write_raw()
711 mutex_unlock(&data->lock); in bmp280_write_raw()
712 pm_runtime_mark_last_busy(data->dev); in bmp280_write_raw()
713 pm_runtime_put_autosuspend(data->dev); in bmp280_write_raw()
727 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_read_avail() local
733 *vals = data->chip_info->oversampling_press_avail; in bmp280_read_avail()
734 *length = data->chip_info->num_oversampling_press_avail; in bmp280_read_avail()
737 *vals = data->chip_info->oversampling_temp_avail; in bmp280_read_avail()
738 *length = data->chip_info->num_oversampling_temp_avail; in bmp280_read_avail()
746 *vals = (const int *)data->chip_info->sampling_freq_avail; in bmp280_read_avail()
749 *length = data->chip_info->num_sampling_freq_avail; in bmp280_read_avail()
752 *vals = data->chip_info->iir_filter_coeffs_avail; in bmp280_read_avail()
754 *length = data->chip_info->num_iir_filter_coeffs_avail; in bmp280_read_avail()
767 static int bmp280_chip_config(struct bmp280_data *data) in bmp280_chip_config() argument
769 u8 osrs = FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1) | in bmp280_chip_config()
770 FIELD_PREP(BMP280_OSRS_PRESS_MASK, data->oversampling_press + 1); in bmp280_chip_config()
773 ret = regmap_write_bits(data->regmap, BMP280_REG_CTRL_MEAS, in bmp280_chip_config()
779 dev_err(data->dev, in bmp280_chip_config()
784 ret = regmap_update_bits(data->regmap, BMP280_REG_CONFIG, in bmp280_chip_config()
788 dev_err(data->dev, in bmp280_chip_config()
831 static int bme280_chip_config(struct bmp280_data *data) in bme280_chip_config() argument
833 u8 osrs = FIELD_PREP(BMP280_OSRS_HUMIDITY_MASK, data->oversampling_humid + 1); in bme280_chip_config()
840 ret = regmap_update_bits(data->regmap, BMP280_REG_CTRL_HUMIDITY, in bme280_chip_config()
846 return bmp280_chip_config(data); in bme280_chip_config()
884 static int bmp380_cmd(struct bmp280_data *data, u8 cmd) in bmp380_cmd() argument
890 ret = regmap_read(data->regmap, BMP380_REG_STATUS, ®); in bmp380_cmd()
892 dev_err(data->dev, "failed to read error register\n"); in bmp380_cmd()
896 dev_err(data->dev, "device is not ready to accept commands\n"); in bmp380_cmd()
901 ret = regmap_write(data->regmap, BMP380_REG_CMD, cmd); in bmp380_cmd()
903 dev_err(data->dev, "failed to send command to device\n"); in bmp380_cmd()
907 usleep_range(data->start_up_time, data->start_up_time + 100); in bmp380_cmd()
909 ret = regmap_read(data->regmap, BMP380_REG_ERROR, ®); in bmp380_cmd()
911 dev_err(data->dev, "error reading ERROR reg\n"); in bmp380_cmd()
915 dev_err(data->dev, "error processing command 0x%X\n", cmd); in bmp380_cmd()
929 static s32 bmp380_compensate_temp(struct bmp280_data *data, u32 adc_temp) in bmp380_compensate_temp() argument
932 struct bmp380_calib *calib = &data->calib.bmp380; in bmp380_compensate_temp()
940 data->t_fine = (s32) var6; in bmp380_compensate_temp()
954 static u32 bmp380_compensate_press(struct bmp280_data *data, u32 adc_press) in bmp380_compensate_press() argument
957 struct bmp380_calib *calib = &data->calib.bmp380; in bmp380_compensate_press()
960 var1 = (s64)data->t_fine * (s64)data->t_fine; in bmp380_compensate_press()
962 var3 = (var2 * ((s64) data->t_fine)) >> 8; in bmp380_compensate_press()
965 var6 = ((s64)calib->P6 * (s64)data->t_fine) << 22; in bmp380_compensate_press()
970 ((s64)data->t_fine << 21); in bmp380_compensate_press()
974 var2 = (s64)calib->P10 * (s64)data->t_fine; in bmp380_compensate_press()
994 static int bmp380_read_temp(struct bmp280_data *data, int *val, int *val2) in bmp380_read_temp() argument
1000 ret = regmap_bulk_read(data->regmap, BMP380_REG_TEMP_XLSB, in bmp380_read_temp()
1001 data->buf, sizeof(data->buf)); in bmp380_read_temp()
1003 dev_err(data->dev, "failed to read temperature\n"); in bmp380_read_temp()
1007 adc_temp = get_unaligned_le24(data->buf); in bmp380_read_temp()
1009 dev_err(data->dev, "reading temperature skipped\n"); in bmp380_read_temp()
1012 comp_temp = bmp380_compensate_temp(data, adc_temp); in bmp380_read_temp()
1027 static int bmp380_read_press(struct bmp280_data *data, int *val, int *val2) in bmp380_read_press() argument
1034 ret = bmp380_read_temp(data, NULL, NULL); in bmp380_read_press()
1038 ret = regmap_bulk_read(data->regmap, BMP380_REG_PRESS_XLSB, in bmp380_read_press()
1039 data->buf, sizeof(data->buf)); in bmp380_read_press()
1041 dev_err(data->dev, "failed to read pressure\n"); in bmp380_read_press()
1045 adc_press = get_unaligned_le24(data->buf); in bmp380_read_press()
1047 dev_err(data->dev, "reading pressure skipped\n"); in bmp380_read_press()
1050 comp_press = bmp380_compensate_press(data, adc_press); in bmp380_read_press()
1059 static int bmp380_read_calib(struct bmp280_data *data) in bmp380_read_calib() argument
1061 struct bmp380_calib *calib = &data->calib.bmp380; in bmp380_read_calib()
1065 ret = regmap_bulk_read(data->regmap, BMP380_REG_CALIB_TEMP_START, in bmp380_read_calib()
1066 data->bmp380_cal_buf, sizeof(data->bmp380_cal_buf)); in bmp380_read_calib()
1068 dev_err(data->dev, in bmp380_read_calib()
1074 add_device_randomness(data->bmp380_cal_buf, sizeof(data->bmp380_cal_buf)); in bmp380_read_calib()
1077 calib->T1 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_T1]); in bmp380_read_calib()
1078 calib->T2 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_T2]); in bmp380_read_calib()
1079 calib->T3 = data->bmp380_cal_buf[BMP380_T3]; in bmp380_read_calib()
1080 calib->P1 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_P1]); in bmp380_read_calib()
1081 calib->P2 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_P2]); in bmp380_read_calib()
1082 calib->P3 = data->bmp380_cal_buf[BMP380_P3]; in bmp380_read_calib()
1083 calib->P4 = data->bmp380_cal_buf[BMP380_P4]; in bmp380_read_calib()
1084 calib->P5 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_P5]); in bmp380_read_calib()
1085 calib->P6 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_P6]); in bmp380_read_calib()
1086 calib->P7 = data->bmp380_cal_buf[BMP380_P7]; in bmp380_read_calib()
1087 calib->P8 = data->bmp380_cal_buf[BMP380_P8]; in bmp380_read_calib()
1088 calib->P9 = get_unaligned_le16(&data->bmp380_cal_buf[BMP380_P9]); in bmp380_read_calib()
1089 calib->P10 = data->bmp380_cal_buf[BMP380_P10]; in bmp380_read_calib()
1090 calib->P11 = data->bmp380_cal_buf[BMP380_P11]; in bmp380_read_calib()
1116 static int bmp380_preinit(struct bmp280_data *data) in bmp380_preinit() argument
1119 return bmp380_cmd(data, BMP380_CMD_SOFT_RESET); in bmp380_preinit()
1122 static int bmp380_chip_config(struct bmp280_data *data) in bmp380_chip_config() argument
1130 ret = regmap_update_bits(data->regmap, BMP380_REG_POWER_CONTROL, in bmp380_chip_config()
1135 dev_err(data->dev, in bmp380_chip_config()
1141 osrs = FIELD_PREP(BMP380_OSRS_TEMP_MASK, data->oversampling_temp) | in bmp380_chip_config()
1142 FIELD_PREP(BMP380_OSRS_PRESS_MASK, data->oversampling_press); in bmp380_chip_config()
1144 ret = regmap_update_bits_check(data->regmap, BMP380_REG_OSR, in bmp380_chip_config()
1149 dev_err(data->dev, "failed to write oversampling register\n"); in bmp380_chip_config()
1155 ret = regmap_update_bits_check(data->regmap, BMP380_REG_ODR, in bmp380_chip_config()
1156 BMP380_ODRS_MASK, data->sampling_freq, &aux); in bmp380_chip_config()
1158 dev_err(data->dev, "failed to write ODR selection register\n"); in bmp380_chip_config()
1164 ret = regmap_update_bits_check(data->regmap, BMP380_REG_CONFIG, BMP380_FILTER_MASK, in bmp380_chip_config()
1165 FIELD_PREP(BMP380_FILTER_MASK, data->iir_filter_coeff), in bmp380_chip_config()
1168 dev_err(data->dev, "failed to write config register\n"); in bmp380_chip_config()
1182 ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, in bmp380_chip_config()
1186 dev_err(data->dev, "failed to set sleep mode\n"); in bmp380_chip_config()
1190 ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL, in bmp380_chip_config()
1194 dev_err(data->dev, "failed to set normal mode\n"); in bmp380_chip_config()
1205 ret = regmap_read(data->regmap, BMP380_REG_ERROR, &tmp); in bmp380_chip_config()
1207 dev_err(data->dev, in bmp380_chip_config()
1212 dev_warn(data->dev, in bmp380_chip_config()
1256 static int bmp580_soft_reset(struct bmp280_data *data) in bmp580_soft_reset() argument
1261 ret = regmap_write(data->regmap, BMP580_REG_CMD, BMP580_CMD_SOFT_RESET); in bmp580_soft_reset()
1263 dev_err(data->dev, "failed to send reset command to device\n"); in bmp580_soft_reset()
1269 ret = regmap_read(data->regmap, BMP580_REG_CHIP_ID, ®); in bmp580_soft_reset()
1271 dev_err(data->dev, "failed to reestablish comms after reset\n"); in bmp580_soft_reset()
1275 ret = regmap_read(data->regmap, BMP580_REG_INT_STATUS, ®); in bmp580_soft_reset()
1277 dev_err(data->dev, "error reading interrupt status register\n"); in bmp580_soft_reset()
1281 dev_err(data->dev, "error resetting sensor\n"); in bmp580_soft_reset()
1293 static int bmp580_nvm_operation(struct bmp280_data *data, bool is_write) in bmp580_nvm_operation() argument
1300 ret = regmap_read(data->regmap, BMP580_REG_STATUS, ®); in bmp580_nvm_operation()
1302 dev_err(data->dev, "failed to check nvm status\n"); in bmp580_nvm_operation()
1306 dev_err(data->dev, "sensor's nvm is not ready\n"); in bmp580_nvm_operation()
1311 ret = regmap_write(data->regmap, BMP580_REG_CMD, BMP580_CMD_NVM_OP_SEQ_0); in bmp580_nvm_operation()
1313 dev_err(data->dev, "failed to send nvm operation's first sequence\n"); in bmp580_nvm_operation()
1318 ret = regmap_write(data->regmap, BMP580_REG_CMD, in bmp580_nvm_operation()
1321 dev_err(data->dev, "failed to send nvm write sequence\n"); in bmp580_nvm_operation()
1329 ret = regmap_write(data->regmap, BMP580_REG_CMD, in bmp580_nvm_operation()
1332 dev_err(data->dev, "failed to send nvm read sequence\n"); in bmp580_nvm_operation()
1340 dev_err(data->dev, "failed to write command sequence\n"); in bmp580_nvm_operation()
1345 ret = regmap_read_poll_timeout(data->regmap, BMP580_REG_STATUS, reg, in bmp580_nvm_operation()
1349 dev_err(data->dev, "error checking nvm operation status\n"); in bmp580_nvm_operation()
1355 dev_err(data->dev, "error processing nvm operation\n"); in bmp580_nvm_operation()
1368 static int bmp580_read_temp(struct bmp280_data *data, int *val, int *val2) in bmp580_read_temp() argument
1373 ret = regmap_bulk_read(data->regmap, BMP580_REG_TEMP_XLSB, data->buf, in bmp580_read_temp()
1374 sizeof(data->buf)); in bmp580_read_temp()
1376 dev_err(data->dev, "failed to read temperature\n"); in bmp580_read_temp()
1380 raw_temp = get_unaligned_le24(data->buf); in bmp580_read_temp()
1382 dev_err(data->dev, "reading temperature skipped\n"); in bmp580_read_temp()
1396 static int bmp580_read_press(struct bmp280_data *data, int *val, int *val2) in bmp580_read_press() argument
1401 ret = regmap_bulk_read(data->regmap, BMP580_REG_PRESS_XLSB, data->buf, in bmp580_read_press()
1402 sizeof(data->buf)); in bmp580_read_press()
1404 dev_err(data->dev, "failed to read pressure\n"); in bmp580_read_press()
1408 raw_press = get_unaligned_le24(data->buf); in bmp580_read_press()
1410 dev_err(data->dev, "reading pressure skipped\n"); in bmp580_read_press()
1462 struct bmp280_data *data = priv; in bmp580_nvmem_read() local
1466 pm_runtime_get_sync(data->dev); in bmp580_nvmem_read()
1467 mutex_lock(&data->lock); in bmp580_nvmem_read()
1470 ret = regmap_update_bits(data->regmap, BMP580_REG_ODR_CONFIG, in bmp580_nvmem_read()
1475 dev_err(data->dev, "failed to change sensor to standby mode\n"); in bmp580_nvmem_read()
1484 ret = regmap_write(data->regmap, BMP580_REG_NVM_ADDR, in bmp580_nvmem_read()
1487 dev_err(data->dev, "error writing nvm address\n"); in bmp580_nvmem_read()
1491 ret = bmp580_nvm_operation(data, false); in bmp580_nvmem_read()
1495 ret = regmap_bulk_read(data->regmap, BMP580_REG_NVM_DATA_LSB, &data->le16, in bmp580_nvmem_read()
1496 sizeof(data->le16)); in bmp580_nvmem_read()
1498 dev_err(data->dev, "error reading nvm data regs\n"); in bmp580_nvmem_read()
1502 *dst++ = le16_to_cpu(data->le16); in bmp580_nvmem_read()
1508 data->chip_info->chip_config(data); in bmp580_nvmem_read()
1509 mutex_unlock(&data->lock); in bmp580_nvmem_read()
1510 pm_runtime_mark_last_busy(data->dev); in bmp580_nvmem_read()
1511 pm_runtime_put_autosuspend(data->dev); in bmp580_nvmem_read()
1518 struct bmp280_data *data = priv; in bmp580_nvmem_write() local
1522 pm_runtime_get_sync(data->dev); in bmp580_nvmem_write()
1523 mutex_lock(&data->lock); in bmp580_nvmem_write()
1526 ret = regmap_update_bits(data->regmap, BMP580_REG_ODR_CONFIG, in bmp580_nvmem_write()
1531 dev_err(data->dev, "failed to change sensor to standby mode\n"); in bmp580_nvmem_write()
1540 ret = regmap_write(data->regmap, BMP580_REG_NVM_ADDR, BMP580_NVM_PROG_EN | in bmp580_nvmem_write()
1543 dev_err(data->dev, "error writing nvm address\n"); in bmp580_nvmem_write()
1546 data->le16 = cpu_to_le16(*buf++); in bmp580_nvmem_write()
1548 ret = regmap_bulk_write(data->regmap, BMP580_REG_NVM_DATA_LSB, &data->le16, in bmp580_nvmem_write()
1549 sizeof(data->le16)); in bmp580_nvmem_write()
1551 dev_err(data->dev, "error writing LSB NVM data regs\n"); in bmp580_nvmem_write()
1555 ret = bmp580_nvm_operation(data, true); in bmp580_nvmem_write()
1560 ret = regmap_update_bits(data->regmap, BMP580_REG_NVM_ADDR, in bmp580_nvmem_write()
1563 dev_err(data->dev, "error resetting nvm write\n"); in bmp580_nvmem_write()
1572 data->chip_info->chip_config(data); in bmp580_nvmem_write()
1573 mutex_unlock(&data->lock); in bmp580_nvmem_write()
1574 pm_runtime_mark_last_busy(data->dev); in bmp580_nvmem_write()
1575 pm_runtime_put_autosuspend(data->dev); in bmp580_nvmem_write()
1579 static int bmp580_preinit(struct bmp280_data *data) in bmp580_preinit() argument
1582 .dev = data->dev, in bmp580_preinit()
1583 .priv = data, in bmp580_preinit()
1595 ret = bmp580_soft_reset(data); in bmp580_preinit()
1600 ret = regmap_read(data->regmap, BMP580_REG_CHIP_ID, ®); in bmp580_preinit()
1606 dev_warn(data->dev, "preinit: unexpected chip_id\n"); in bmp580_preinit()
1608 ret = regmap_read(data->regmap, BMP580_REG_STATUS, ®); in bmp580_preinit()
1614 dev_err(data->dev, "preinit: nvm error on powerup sequence\n"); in bmp580_preinit()
1622 static int bmp580_chip_config(struct bmp280_data *data) in bmp580_chip_config() argument
1630 ret = regmap_update_bits(data->regmap, BMP580_REG_ODR_CONFIG, in bmp580_chip_config()
1635 dev_err(data->dev, "failed to change sensor to standby mode\n"); in bmp580_chip_config()
1645 ret = regmap_update_bits(data->regmap, BMP580_REG_DSP_CONFIG, in bmp580_chip_config()
1651 reg_val = FIELD_PREP(BMP580_OSR_TEMP_MASK, data->oversampling_temp) | in bmp580_chip_config()
1652 FIELD_PREP(BMP580_OSR_PRESS_MASK, data->oversampling_press) | in bmp580_chip_config()
1655 ret = regmap_update_bits_check(data->regmap, BMP580_REG_OSR_CONFIG, in bmp580_chip_config()
1660 dev_err(data->dev, "failed to write oversampling register\n"); in bmp580_chip_config()
1666 ret = regmap_update_bits_check(data->regmap, BMP580_REG_ODR_CONFIG, BMP580_ODR_MASK, in bmp580_chip_config()
1667 FIELD_PREP(BMP580_ODR_MASK, data->sampling_freq), in bmp580_chip_config()
1670 dev_err(data->dev, "failed to write ODR configuration register\n"); in bmp580_chip_config()
1676 reg_val = FIELD_PREP(BMP580_DSP_IIR_PRESS_MASK, data->iir_filter_coeff) | in bmp580_chip_config()
1677 FIELD_PREP(BMP580_DSP_IIR_TEMP_MASK, data->iir_filter_coeff); in bmp580_chip_config()
1679 ret = regmap_update_bits_check(data->regmap, BMP580_REG_DSP_IIR, in bmp580_chip_config()
1684 dev_err(data->dev, "failed to write config register\n"); in bmp580_chip_config()
1690 ret = regmap_write_bits(data->regmap, BMP580_REG_ODR_CONFIG, in bmp580_chip_config()
1694 dev_err(data->dev, "failed to set normal mode\n"); in bmp580_chip_config()
1705 ret = regmap_read(data->regmap, BMP580_REG_EFF_OSR, &tmp); in bmp580_chip_config()
1707 dev_err(data->dev, "error reading effective OSR register\n"); in bmp580_chip_config()
1711 dev_warn(data->dev, "OSR and ODR incompatible settings detected\n"); in bmp580_chip_config()
1713 data->oversampling_temp = FIELD_GET(BMP580_EFF_OSR_TEMP_MASK, tmp); in bmp580_chip_config()
1714 data->oversampling_press = FIELD_GET(BMP580_EFF_OSR_PRESS_MASK, tmp); in bmp580_chip_config()
1755 static int bmp180_measure(struct bmp280_data *data, u8 ctrl_meas) in bmp180_measure() argument
1762 if (data->use_eoc) in bmp180_measure()
1763 reinit_completion(&data->done); in bmp180_measure()
1765 ret = regmap_write(data->regmap, BMP280_REG_CTRL_MEAS, ctrl_meas); in bmp180_measure()
1769 if (data->use_eoc) { in bmp180_measure()
1775 ret = wait_for_completion_timeout(&data->done, in bmp180_measure()
1778 dev_err(data->dev, "timeout waiting for completion\n"); in bmp180_measure()
1784 conversion_time_max[data->oversampling_press]; in bmp180_measure()
1789 ret = regmap_read(data->regmap, BMP280_REG_CTRL_MEAS, &ctrl); in bmp180_measure()
1800 static int bmp180_read_adc_temp(struct bmp280_data *data, int *val) in bmp180_read_adc_temp() argument
1804 ret = bmp180_measure(data, in bmp180_read_adc_temp()
1810 ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, in bmp180_read_adc_temp()
1811 &data->be16, sizeof(data->be16)); in bmp180_read_adc_temp()
1815 *val = be16_to_cpu(data->be16); in bmp180_read_adc_temp()
1820 static int bmp180_read_calib(struct bmp280_data *data) in bmp180_read_calib() argument
1822 struct bmp180_calib *calib = &data->calib.bmp180; in bmp180_read_calib()
1826 ret = regmap_bulk_read(data->regmap, BMP180_REG_CALIB_START, in bmp180_read_calib()
1827 data->bmp180_cal_buf, sizeof(data->bmp180_cal_buf)); in bmp180_read_calib()
1833 for (i = 0; i < ARRAY_SIZE(data->bmp180_cal_buf); i++) { in bmp180_read_calib()
1834 if (data->bmp180_cal_buf[i] == cpu_to_be16(0) || in bmp180_read_calib()
1835 data->bmp180_cal_buf[i] == cpu_to_be16(0xffff)) in bmp180_read_calib()
1840 add_device_randomness(data->bmp180_cal_buf, sizeof(data->bmp180_cal_buf)); in bmp180_read_calib()
1842 calib->AC1 = be16_to_cpu(data->bmp180_cal_buf[AC1]); in bmp180_read_calib()
1843 calib->AC2 = be16_to_cpu(data->bmp180_cal_buf[AC2]); in bmp180_read_calib()
1844 calib->AC3 = be16_to_cpu(data->bmp180_cal_buf[AC3]); in bmp180_read_calib()
1845 calib->AC4 = be16_to_cpu(data->bmp180_cal_buf[AC4]); in bmp180_read_calib()
1846 calib->AC5 = be16_to_cpu(data->bmp180_cal_buf[AC5]); in bmp180_read_calib()
1847 calib->AC6 = be16_to_cpu(data->bmp180_cal_buf[AC6]); in bmp180_read_calib()
1848 calib->B1 = be16_to_cpu(data->bmp180_cal_buf[B1]); in bmp180_read_calib()
1849 calib->B2 = be16_to_cpu(data->bmp180_cal_buf[B2]); in bmp180_read_calib()
1850 calib->MB = be16_to_cpu(data->bmp180_cal_buf[MB]); in bmp180_read_calib()
1851 calib->MC = be16_to_cpu(data->bmp180_cal_buf[MC]); in bmp180_read_calib()
1852 calib->MD = be16_to_cpu(data->bmp180_cal_buf[MD]); in bmp180_read_calib()
1863 static s32 bmp180_compensate_temp(struct bmp280_data *data, s32 adc_temp) in bmp180_compensate_temp() argument
1865 struct bmp180_calib *calib = &data->calib.bmp180; in bmp180_compensate_temp()
1870 data->t_fine = x1 + x2; in bmp180_compensate_temp()
1872 return (data->t_fine + 8) >> 4; in bmp180_compensate_temp()
1875 static int bmp180_read_temp(struct bmp280_data *data, int *val, int *val2) in bmp180_read_temp() argument
1880 ret = bmp180_read_adc_temp(data, &adc_temp); in bmp180_read_temp()
1884 comp_temp = bmp180_compensate_temp(data, adc_temp); in bmp180_read_temp()
1898 static int bmp180_read_adc_press(struct bmp280_data *data, int *val) in bmp180_read_adc_press() argument
1900 u8 oss = data->oversampling_press; in bmp180_read_adc_press()
1903 ret = bmp180_measure(data, in bmp180_read_adc_press()
1910 ret = regmap_bulk_read(data->regmap, BMP180_REG_OUT_MSB, in bmp180_read_adc_press()
1911 data->buf, sizeof(data->buf)); in bmp180_read_adc_press()
1915 *val = get_unaligned_be24(data->buf) >> (8 - oss); in bmp180_read_adc_press()
1925 static u32 bmp180_compensate_press(struct bmp280_data *data, s32 adc_press) in bmp180_compensate_press() argument
1927 struct bmp180_calib *calib = &data->calib.bmp180; in bmp180_compensate_press()
1928 s32 oss = data->oversampling_press; in bmp180_compensate_press()
1933 b6 = data->t_fine - 4000; in bmp180_compensate_press()
1955 static int bmp180_read_press(struct bmp280_data *data, in bmp180_read_press() argument
1963 ret = bmp180_read_temp(data, NULL, NULL); in bmp180_read_press()
1967 ret = bmp180_read_adc_press(data, &adc_press); in bmp180_read_press()
1971 comp_press = bmp180_compensate_press(data, adc_press); in bmp180_read_press()
1979 static int bmp180_chip_config(struct bmp280_data *data) in bmp180_chip_config() argument
2014 struct bmp280_data *data = d; in bmp085_eoc_irq() local
2016 complete(&data->done); in bmp085_eoc_irq()
2024 struct bmp280_data *data) in bmp085_fetch_eoc_irq() argument
2035 init_completion(&data->done); in bmp085_fetch_eoc_irq()
2043 data); in bmp085_fetch_eoc_irq()
2050 data->use_eoc = true; in bmp085_fetch_eoc_irq()
2054 static void bmp280_pm_disable(void *data) in bmp280_pm_disable() argument
2056 struct device *dev = data; in bmp280_pm_disable()
2063 static void bmp280_regulators_disable(void *data) in bmp280_regulators_disable() argument
2065 struct regulator_bulk_data *supplies = data; in bmp280_regulators_disable()
2077 struct bmp280_data *data; in bmp280_common_probe() local
2082 indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); in bmp280_common_probe()
2086 data = iio_priv(indio_dev); in bmp280_common_probe()
2087 mutex_init(&data->lock); in bmp280_common_probe()
2088 data->dev = dev; in bmp280_common_probe()
2094 data->chip_info = chip_info; in bmp280_common_probe()
2099 data->oversampling_press = chip_info->oversampling_press_default; in bmp280_common_probe()
2100 data->oversampling_humid = chip_info->oversampling_humid_default; in bmp280_common_probe()
2101 data->oversampling_temp = chip_info->oversampling_temp_default; in bmp280_common_probe()
2102 data->iir_filter_coeff = chip_info->iir_filter_coeff_default; in bmp280_common_probe()
2103 data->sampling_freq = chip_info->sampling_freq_default; in bmp280_common_probe()
2104 data->start_up_time = chip_info->start_up_time; in bmp280_common_probe()
2107 regulator_bulk_set_supply_names(data->supplies, in bmp280_common_probe()
2112 BMP280_NUM_SUPPLIES, data->supplies); in bmp280_common_probe()
2118 ret = regulator_bulk_enable(BMP280_NUM_SUPPLIES, data->supplies); in bmp280_common_probe()
2125 data->supplies); in bmp280_common_probe()
2130 usleep_range(data->start_up_time, data->start_up_time + 100); in bmp280_common_probe()
2140 data->regmap = regmap; in bmp280_common_probe()
2142 ret = regmap_read(regmap, data->chip_info->id_reg, &chip_id); in bmp280_common_probe()
2145 if (chip_id != data->chip_info->chip_id) { in bmp280_common_probe()
2147 data->chip_info->chip_id, chip_id); in bmp280_common_probe()
2151 if (data->chip_info->preinit) { in bmp280_common_probe()
2152 ret = data->chip_info->preinit(data); in bmp280_common_probe()
2154 return dev_err_probe(data->dev, ret, in bmp280_common_probe()
2158 ret = data->chip_info->chip_config(data); in bmp280_common_probe()
2170 if (data->chip_info->read_calib) { in bmp280_common_probe()
2171 ret = data->chip_info->read_calib(data); in bmp280_common_probe()
2173 return dev_err_probe(data->dev, ret, in bmp280_common_probe()
2183 ret = bmp085_fetch_eoc_irq(dev, name, irq, data); in bmp280_common_probe()
2196 pm_runtime_set_autosuspend_delay(dev, data->start_up_time / 10); in bmp280_common_probe()
2211 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_runtime_suspend() local
2213 return regulator_bulk_disable(BMP280_NUM_SUPPLIES, data->supplies); in bmp280_runtime_suspend()
2219 struct bmp280_data *data = iio_priv(indio_dev); in bmp280_runtime_resume() local
2222 ret = regulator_bulk_enable(BMP280_NUM_SUPPLIES, data->supplies); in bmp280_runtime_resume()
2225 usleep_range(data->start_up_time, data->start_up_time + 100); in bmp280_runtime_resume()
2226 return data->chip_info->chip_config(data); in bmp280_runtime_resume()