Lines Matching +full:poll +full:- +full:rate +full:- +full:ms
1 // SPDX-License-Identifier: GPL-2.0+
14 * - Optionally support the FIFO
60 /* Make sure sleep time is <= 20ms for usleep_range */
62 /* Silently handle error in rate value here */
118 rc = regmap_bulk_read(data->regmap, DPS310_COEF_BASE, coef, in dps310_get_coefs()
125 * numbers are 12-bit 2's complement numbers. in dps310_get_coefs()
128 data->c0 = sign_extend32(c0, 11); in dps310_get_coefs()
131 data->c1 = sign_extend32(c1, 11); in dps310_get_coefs()
139 data->c00 = sign_extend32(c00, 19); in dps310_get_coefs()
142 data->c10 = sign_extend32(c10, 19); in dps310_get_coefs()
145 data->c01 = sign_extend32(c01, 15); in dps310_get_coefs()
148 data->c11 = sign_extend32(c11, 15); in dps310_get_coefs()
151 data->c20 = sign_extend32(c20, 15); in dps310_get_coefs()
154 data->c21 = sign_extend32(c21, 15); in dps310_get_coefs()
157 data->c30 = sign_extend32(c30, 15); in dps310_get_coefs()
167 rc = regmap_read(data->regmap, DPS310_PRS_CFG, &val); in dps310_get_pres_precision()
179 rc = regmap_read(data->regmap, DPS310_TMP_CFG, &val); in dps310_get_temp_precision()
197 return -EINVAL; in dps310_set_pres_precision()
200 rc = regmap_write_bits(data->regmap, DPS310_CFG_REG, in dps310_set_pres_precision()
205 return regmap_update_bits(data->regmap, DPS310_PRS_CFG, in dps310_set_pres_precision()
216 return -EINVAL; in dps310_set_temp_precision()
219 rc = regmap_write_bits(data->regmap, DPS310_CFG_REG, in dps310_set_temp_precision()
224 return regmap_update_bits(data->regmap, DPS310_TMP_CFG, in dps310_set_temp_precision()
234 return -EINVAL; in dps310_set_pres_samp_freq()
238 return regmap_update_bits(data->regmap, DPS310_PRS_CFG, in dps310_set_pres_samp_freq()
248 return -EINVAL; in dps310_set_temp_samp_freq()
252 return regmap_update_bits(data->regmap, DPS310_TMP_CFG, in dps310_set_temp_samp_freq()
261 rc = regmap_read(data->regmap, DPS310_PRS_CFG, &val); in dps310_get_pres_samp_freq()
273 rc = regmap_read(data->regmap, DPS310_TMP_CFG, &val); in dps310_get_temp_samp_freq()
303 int rate; in dps310_read_pres_raw() local
309 if (mutex_lock_interruptible(&data->lock)) in dps310_read_pres_raw()
310 return -EINTR; in dps310_read_pres_raw()
312 rate = dps310_get_pres_samp_freq(data); in dps310_read_pres_raw()
313 timeout = DPS310_POLL_TIMEOUT_US(rate); in dps310_read_pres_raw()
315 /* Poll for sensor readiness; base the timeout upon the sample rate. */ in dps310_read_pres_raw()
316 rc = regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, ready, in dps310_read_pres_raw()
322 rc = regmap_bulk_read(data->regmap, DPS310_PRS_BASE, val, sizeof(val)); in dps310_read_pres_raw()
327 data->pressure_raw = sign_extend32(raw, 23); in dps310_read_pres_raw()
330 mutex_unlock(&data->lock); in dps310_read_pres_raw()
341 rc = regmap_bulk_read(data->regmap, DPS310_TMP_BASE, val, sizeof(val)); in dps310_read_temp_ready()
346 data->temp_raw = sign_extend32(raw, 23); in dps310_read_temp_ready()
354 int rate; in dps310_read_temp_raw() local
358 if (mutex_lock_interruptible(&data->lock)) in dps310_read_temp_raw()
359 return -EINTR; in dps310_read_temp_raw()
361 rate = dps310_get_temp_samp_freq(data); in dps310_read_temp_raw()
362 timeout = DPS310_POLL_TIMEOUT_US(rate); in dps310_read_temp_raw()
364 /* Poll for sensor readiness; base the timeout upon the sample rate. */ in dps310_read_temp_raw()
365 rc = regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, ready, in dps310_read_temp_raw()
374 mutex_unlock(&data->lock); in dps310_read_temp_raw()
420 if (mutex_lock_interruptible(&data->lock)) in dps310_write_raw()
421 return -EINTR; in dps310_write_raw()
425 switch (chan->type) { in dps310_write_raw()
435 rc = -EINVAL; in dps310_write_raw()
441 switch (chan->type) { in dps310_write_raw()
451 rc = -EINVAL; in dps310_write_raw()
457 rc = -EINVAL; in dps310_write_raw()
461 mutex_unlock(&data->lock); in dps310_write_raw()
492 if (mutex_trylock(&data->lock)) { in dps310_calculate_pressure()
493 rc = regmap_read(data->regmap, DPS310_MEAS_CFG, &t_ready); in dps310_calculate_pressure()
497 mutex_unlock(&data->lock); in dps310_calculate_pressure()
500 p = (s64)data->pressure_raw; in dps310_calculate_pressure()
501 t = (s64)data->temp_raw; in dps310_calculate_pressure()
504 nums[0] = (s64)data->c00; in dps310_calculate_pressure()
506 nums[1] = p * (s64)data->c10; in dps310_calculate_pressure()
508 nums[2] = p * p * (s64)data->c20; in dps310_calculate_pressure()
510 nums[3] = p * p * p * (s64)data->c30; in dps310_calculate_pressure()
512 nums[4] = t * (s64)data->c01; in dps310_calculate_pressure()
514 nums[5] = t * p * (s64)data->c11; in dps310_calculate_pressure()
516 nums[6] = t * p * p * (s64)data->c21; in dps310_calculate_pressure()
524 pressure -= div64_u64_rem(-nums[i], denoms[i], &irem); in dps310_calculate_pressure()
525 rems[i] = -irem; in dps310_calculate_pressure()
538 return -ERANGE; in dps310_calculate_pressure()
579 return -EINVAL; in dps310_read_pressure()
592 /* Obtain inverse-scaled offset */ in dps310_calculate_temp()
593 c0 = div_s64((s64)kt * (s64)data->c0, 2); in dps310_calculate_temp()
596 t = c0 + ((s64)data->temp_raw * (s64)data->c1); in dps310_calculate_temp()
637 return -EINVAL; in dps310_read_temp()
647 switch (chan->type) { in dps310_read_raw()
655 return -EINVAL; in dps310_read_raw()
663 regmap_write(data->regmap, DPS310_RESET, DPS310_RESET_MAGIC); in dps310_reset()
690 rc = regmap_read(data->regmap, 0x32, ®); in dps310_temp_workaround()
701 rc = regmap_write(data->regmap, 0x0e, 0xA5); in dps310_temp_workaround()
705 rc = regmap_write(data->regmap, 0x0f, 0x96); in dps310_temp_workaround()
709 rc = regmap_write(data->regmap, 0x62, 0x02); in dps310_temp_workaround()
713 rc = regmap_write(data->regmap, 0x0e, 0x00); in dps310_temp_workaround()
717 return regmap_write(data->regmap, 0x0f, 0x00); in dps310_temp_workaround()
727 iio = devm_iio_device_alloc(&client->dev, sizeof(*data)); in dps310_probe()
729 return -ENOMEM; in dps310_probe()
732 data->client = client; in dps310_probe()
733 mutex_init(&data->lock); in dps310_probe()
735 iio->name = id->name; in dps310_probe()
736 iio->channels = dps310_channels; in dps310_probe()
737 iio->num_channels = ARRAY_SIZE(dps310_channels); in dps310_probe()
738 iio->info = &dps310_info; in dps310_probe()
739 iio->modes = INDIO_DIRECT_MODE; in dps310_probe()
741 data->regmap = devm_regmap_init_i2c(client, &dps310_regmap_config); in dps310_probe()
742 if (IS_ERR(data->regmap)) in dps310_probe()
743 return PTR_ERR(data->regmap); in dps310_probe()
746 rc = devm_add_action_or_reset(&client->dev, dps310_reset, data); in dps310_probe()
754 rc = regmap_write(data->regmap, DPS310_PRS_CFG, 0); in dps310_probe()
760 rc = regmap_write(data->regmap, DPS310_TMP_CFG, DPS310_TMP_EXT); in dps310_probe()
765 rc = regmap_write_bits(data->regmap, DPS310_CFG_REG, in dps310_probe()
771 rc = regmap_write_bits(data->regmap, DPS310_MEAS_CFG, in dps310_probe()
777 rc = regmap_write_bits(data->regmap, DPS310_MEAS_CFG, in dps310_probe()
785 * They are available 40ms after the device has started in dps310_probe()
787 rc = regmap_read_poll_timeout(data->regmap, DPS310_MEAS_CFG, ready, in dps310_probe()
800 rc = devm_iio_device_register(&client->dev, iio); in dps310_probe()