Lines Matching +full:temperature +full:- +full:offset +full:- +full:millicelsius

1 // SPDX-License-Identifier: GPL-2.0+
4 * The DPS310 is a barometric pressure and temperature sensor.
5 * Currently only reading a single temperature is supported by
10 * Temperature calculation:
14 * - Optionally support the FIFO
119 rc = regmap_bulk_read(data->regmap, DPS310_COEF_BASE, coef, in dps310_get_coefs()
125 * Calculate temperature calibration coefficients c0 and c1. The in dps310_get_coefs()
126 * numbers are 12-bit 2's complement numbers. in dps310_get_coefs()
129 data->c0 = sign_extend32(c0, 11); in dps310_get_coefs()
132 data->c1 = sign_extend32(c1, 11); in dps310_get_coefs()
140 data->c00 = sign_extend32(c00, 19); in dps310_get_coefs()
143 data->c10 = sign_extend32(c10, 19); in dps310_get_coefs()
146 data->c01 = sign_extend32(c01, 15); in dps310_get_coefs()
149 data->c11 = sign_extend32(c11, 15); in dps310_get_coefs()
152 data->c20 = sign_extend32(c20, 15); in dps310_get_coefs()
155 data->c21 = sign_extend32(c21, 15); in dps310_get_coefs()
158 data->c30 = sign_extend32(c30, 15); in dps310_get_coefs()
173 rc = regmap_read(data->regmap, 0x32, &reg); in dps310_temp_workaround()
184 rc = regmap_write(data->regmap, 0x0e, 0xA5); in dps310_temp_workaround()
188 rc = regmap_write(data->regmap, 0x0f, 0x96); in dps310_temp_workaround()
192 rc = regmap_write(data->regmap, 0x62, 0x02); in dps310_temp_workaround()
196 rc = regmap_write(data->regmap, 0x0e, 0x00); in dps310_temp_workaround()
200 return regmap_write(data->regmap, 0x0f, 0x00); in dps310_temp_workaround()
212 rc = regmap_write(data->regmap, DPS310_PRS_CFG, 0); in dps310_startup()
217 * Set up external (MEMS) temperature sensor in single sample, one in dps310_startup()
220 rc = regmap_write(data->regmap, DPS310_TMP_CFG, DPS310_TMP_EXT); in dps310_startup()
225 rc = regmap_write_bits(data->regmap, DPS310_CFG_REG, in dps310_startup()
231 rc = regmap_write_bits(data->regmap, DPS310_MEAS_CFG, in dps310_startup()
236 /* Turn on temperature and pressure measurement in the background */ in dps310_startup()
237 rc = regmap_write_bits(data->regmap, DPS310_MEAS_CFG, in dps310_startup()
244 * Calibration coefficients required for reporting temperature. in dps310_startup()
247 rc = regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, ready, in dps310_startup()
263 rc = regmap_read(data->regmap, DPS310_PRS_CFG, &reg_val); in dps310_get_pres_precision()
276 rc = regmap_read(data->regmap, DPS310_TMP_CFG, &reg_val); in dps310_get_temp_precision()
296 return -EINVAL; in dps310_set_pres_precision()
299 rc = regmap_write_bits(data->regmap, DPS310_CFG_REG, in dps310_set_pres_precision()
304 return regmap_update_bits(data->regmap, DPS310_PRS_CFG, in dps310_set_pres_precision()
315 return -EINVAL; in dps310_set_temp_precision()
318 rc = regmap_write_bits(data->regmap, DPS310_CFG_REG, in dps310_set_temp_precision()
323 return regmap_update_bits(data->regmap, DPS310_TMP_CFG, in dps310_set_temp_precision()
333 return -EINVAL; in dps310_set_pres_samp_freq()
337 return regmap_update_bits(data->regmap, DPS310_PRS_CFG, in dps310_set_pres_samp_freq()
347 return -EINVAL; in dps310_set_temp_samp_freq()
351 return regmap_update_bits(data->regmap, DPS310_TMP_CFG, in dps310_set_temp_samp_freq()
359 rc = regmap_read(data->regmap, DPS310_PRS_CFG, &reg_val); in dps310_get_pres_samp_freq()
372 rc = regmap_read(data->regmap, DPS310_TMP_CFG, &reg_val); in dps310_get_temp_samp_freq()
385 rc = regmap_read(data->regmap, DPS310_PRS_CFG, &reg_val); in dps310_get_pres_k()
398 rc = regmap_read(data->regmap, DPS310_TMP_CFG, &reg_val); in dps310_get_temp_k()
411 rc = regmap_write(data->regmap, DPS310_RESET, DPS310_RESET_MAGIC); in dps310_reset_wait()
436 return regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, ready, ready & ready_bit, in dps310_ready_status()
446 if (rc == -ETIMEDOUT && !data->timeout_recovery_failed) { in dps310_ready()
449 data->timeout_recovery_failed = true; in dps310_ready()
453 data->timeout_recovery_failed = true; in dps310_ready()
462 data->timeout_recovery_failed = false; in dps310_ready()
474 if (mutex_lock_interruptible(&data->lock)) in dps310_read_pres_raw()
475 return -EINTR; in dps310_read_pres_raw()
488 rc = regmap_bulk_read(data->regmap, DPS310_PRS_BASE, val, sizeof(val)); in dps310_read_pres_raw()
493 data->pressure_raw = sign_extend32(raw, 23); in dps310_read_pres_raw()
496 mutex_unlock(&data->lock); in dps310_read_pres_raw()
507 rc = regmap_bulk_read(data->regmap, DPS310_TMP_BASE, val, sizeof(val)); in dps310_read_temp_ready()
512 data->temp_raw = sign_extend32(raw, 23); in dps310_read_temp_ready()
523 if (mutex_lock_interruptible(&data->lock)) in dps310_read_temp_raw()
524 return -EINTR; in dps310_read_temp_raw()
540 mutex_unlock(&data->lock); in dps310_read_temp_raw()
586 if (mutex_lock_interruptible(&data->lock)) in dps310_write_raw()
587 return -EINTR; in dps310_write_raw()
591 switch (chan->type) { in dps310_write_raw()
601 rc = -EINVAL; in dps310_write_raw()
607 switch (chan->type) { in dps310_write_raw()
617 rc = -EINVAL; in dps310_write_raw()
623 rc = -EINVAL; in dps310_write_raw()
627 mutex_unlock(&data->lock); in dps310_write_raw()
660 if (mutex_trylock(&data->lock)) { in dps310_calculate_pressure()
661 rc = regmap_read(data->regmap, DPS310_MEAS_CFG, &t_ready); in dps310_calculate_pressure()
665 mutex_unlock(&data->lock); in dps310_calculate_pressure()
668 p = (s64)data->pressure_raw; in dps310_calculate_pressure()
669 t = (s64)data->temp_raw; in dps310_calculate_pressure()
672 nums[0] = (s64)data->c00; in dps310_calculate_pressure()
674 nums[1] = p * (s64)data->c10; in dps310_calculate_pressure()
676 nums[2] = p * p * (s64)data->c20; in dps310_calculate_pressure()
678 nums[3] = p * p * p * (s64)data->c30; in dps310_calculate_pressure()
680 nums[4] = t * (s64)data->c01; in dps310_calculate_pressure()
682 nums[5] = t * p * (s64)data->c11; in dps310_calculate_pressure()
684 nums[6] = t * p * p * (s64)data->c21; in dps310_calculate_pressure()
692 pressure -= div64_u64_rem(-nums[i], denoms[i], &irem); in dps310_calculate_pressure()
693 rems[i] = -irem; in dps310_calculate_pressure()
706 return -ERANGE; in dps310_calculate_pressure()
745 return -EINVAL; in dps310_read_pressure()
759 /* Obtain inverse-scaled offset */ in dps310_calculate_temp()
760 c0 = div_s64((s64)kt * (s64)data->c0, 2); in dps310_calculate_temp()
762 /* Add the offset to the unscaled temperature */ in dps310_calculate_temp()
763 t = c0 + ((s64)data->temp_raw * (s64)data->c1); in dps310_calculate_temp()
765 /* Convert to milliCelsius and scale the temperature */ in dps310_calculate_temp()
803 return -EINVAL; in dps310_read_temp()
813 switch (chan->type) { in dps310_read_raw()
821 return -EINVAL; in dps310_read_raw()
853 iio = devm_iio_device_alloc(&client->dev, sizeof(*data)); in dps310_probe()
855 return -ENOMEM; in dps310_probe()
858 data->client = client; in dps310_probe()
859 mutex_init(&data->lock); in dps310_probe()
861 iio->name = id->name; in dps310_probe()
862 iio->channels = dps310_channels; in dps310_probe()
863 iio->num_channels = ARRAY_SIZE(dps310_channels); in dps310_probe()
864 iio->info = &dps310_info; in dps310_probe()
865 iio->modes = INDIO_DIRECT_MODE; in dps310_probe()
867 data->regmap = devm_regmap_init_i2c(client, &dps310_regmap_config); in dps310_probe()
868 if (IS_ERR(data->regmap)) in dps310_probe()
869 return PTR_ERR(data->regmap); in dps310_probe()
872 rc = devm_add_action_or_reset(&client->dev, dps310_reset, data); in dps310_probe()
880 rc = devm_iio_device_register(&client->dev, iio); in dps310_probe()
912 MODULE_DESCRIPTION("Infineon DPS310 pressure and temperature sensor");