Lines Matching +full:co2 +full:- +full:sensor

1 // SPDX-License-Identifier: GPL-2.0
3 * Sensirion SCD30 carbon dioxide sensor core driver
53 return state->command(state, cmd, arg, NULL, 0); in scd30_command_write()
61 ret = state->command(state, cmd, 0, &tmp, sizeof(tmp)); in scd30_command_read()
76 /* sensor boots up within 2 secs */ in scd30_reset()
79 * Power-on-reset causes sensor to produce some glitch on i2c bus and in scd30_reset()
93 sign = (float32 & BIT(31)) ? -1 : 1, in scd30_float_to_fp()
100 exp -= 127; in scd30_float_to_fp()
102 exp = -exp; in scd30_float_to_fp()
108 shift = 23 - exp; in scd30_float_to_fp()
110 fraction = mantissa & GENMASK(shift - 1, 0); in scd30_float_to_fp()
119 ret = state->command(state, CMD_READ_MEAS, 0, state->meas, sizeof(state->meas)); in scd30_read_meas()
123 be32_to_cpu_array(state->meas, (__be32 *)state->meas, ARRAY_SIZE(state->meas)); in scd30_read_meas()
125 for (i = 0; i < ARRAY_SIZE(state->meas); i++) in scd30_read_meas()
126 state->meas[i] = scd30_float_to_fp(state->meas[i]); in scd30_read_meas()
129 * co2 is left unprocessed while temperature and humidity are scaled in scd30_read_meas()
132 state->meas[SCD30_TEMP] *= 10; in scd30_read_meas()
133 state->meas[SCD30_HR] *= 10; in scd30_read_meas()
142 reinit_completion(&state->meas_ready); in scd30_wait_meas_irq()
143 enable_irq(state->irq); in scd30_wait_meas_irq()
144 timeout = msecs_to_jiffies(state->meas_interval * (1000 + SCD30_EXTRA_TIMEOUT_PER_S)); in scd30_wait_meas_irq()
145 ret = wait_for_completion_interruptible_timeout(&state->meas_ready, timeout); in scd30_wait_meas_irq()
149 ret = -ETIMEDOUT; in scd30_wait_meas_irq()
151 disable_irq(state->irq); in scd30_wait_meas_irq()
158 int timeout = state->meas_interval * SCD30_EXTRA_TIMEOUT_PER_S, tries = 5; in scd30_wait_meas_poll()
166 return -EIO; in scd30_wait_meas_poll()
173 } while (--tries); in scd30_wait_meas_poll()
175 return tries ? 0 : -ETIMEDOUT; in scd30_wait_meas_poll()
191 if (state->irq > 0) in scd30_read()
201 int ret = -EINVAL; in scd30_read_raw()
204 mutex_lock(&state->lock); in scd30_read_raw()
208 if (chan->output) { in scd30_read_raw()
209 *val = state->pressure_comp; in scd30_read_raw()
224 *val = state->meas[chan->address]; in scd30_read_raw()
251 mutex_unlock(&state->lock); in scd30_read_raw()
260 int ret = -EINVAL; in scd30_write_raw()
262 mutex_lock(&state->lock); in scd30_write_raw()
276 state->meas_interval = val; in scd30_write_raw()
279 switch (chan->type) { in scd30_write_raw()
289 state->pressure_comp = val; in scd30_write_raw()
304 mutex_unlock(&state->lock); in scd30_write_raw()
320 return -EINVAL; in scd30_write_raw_get_fmt()
347 return -EINVAL; in scd30_read_avail()
366 buf[len - 1] = '\n'; in sampling_frequency_available_show()
379 mutex_lock(&state->lock); in calibration_auto_enable_show()
381 mutex_unlock(&state->lock); in calibration_auto_enable_show()
398 mutex_lock(&state->lock); in calibration_auto_enable_store()
400 mutex_unlock(&state->lock); in calibration_auto_enable_store()
413 mutex_lock(&state->lock); in calibration_forced_value_show()
415 mutex_unlock(&state->lock); in calibration_forced_value_show()
433 return -EINVAL; in calibration_forced_value_store()
435 mutex_lock(&state->lock); in calibration_forced_value_store()
437 mutex_unlock(&state->lock); in calibration_forced_value_store()
476 * sensor is able to change measurement chamber pressure but in
483 .scan_index = -1,
530 return regulator_disable(state->vdd); in scd30_suspend()
539 ret = regulator_enable(state->vdd); in scd30_resume()
543 return scd30_command_write(state, CMD_START_MEAS, state->pressure_comp); in scd30_resume()
559 regulator_disable(state->vdd); in scd30_disable_regulator()
567 iio_trigger_poll(indio_dev->trig); in scd30_irq_handler()
585 complete_all(&state->meas_ready); in scd30_irq_thread_handler()
593 struct iio_dev *indio_dev = pf->indio_dev; in scd30_trigger_handler()
601 mutex_lock(&state->lock); in scd30_trigger_handler()
607 memcpy(scan.data, state->meas, sizeof(state->meas)); in scd30_trigger_handler()
608 mutex_unlock(&state->lock); in scd30_trigger_handler()
614 iio_trigger_notify_done(indio_dev->trig); in scd30_trigger_handler()
624 enable_irq(st->irq); in scd30_set_trigger_state()
626 disable_irq(st->irq); in scd30_set_trigger_state()
639 struct device *dev = indio_dev->dev.parent; in scd30_setup_trigger()
643 trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name, in scd30_setup_trigger()
646 return dev_err_probe(dev, -ENOMEM, "failed to allocate trigger\n"); in scd30_setup_trigger()
648 trig->ops = &scd30_trigger_ops; in scd30_setup_trigger()
655 indio_dev->trig = iio_trigger_get(trig); in scd30_setup_trigger()
662 ret = devm_request_threaded_irq(dev, state->irq, scd30_irq_handler, in scd30_setup_trigger()
666 indio_dev->name, indio_dev); in scd30_setup_trigger()
684 return -ENOMEM; in scd30_probe()
687 state->dev = dev; in scd30_probe()
688 state->priv = priv; in scd30_probe()
689 state->irq = irq; in scd30_probe()
690 state->pressure_comp = SCD30_PRESSURE_COMP_DEFAULT; in scd30_probe()
691 state->meas_interval = SCD30_MEAS_INTERVAL_DEFAULT; in scd30_probe()
692 state->command = command; in scd30_probe()
693 mutex_init(&state->lock); in scd30_probe()
694 init_completion(&state->meas_ready); in scd30_probe()
698 indio_dev->info = &scd30_info; in scd30_probe()
699 indio_dev->name = name; in scd30_probe()
700 indio_dev->channels = scd30_channels; in scd30_probe()
701 indio_dev->num_channels = ARRAY_SIZE(scd30_channels); in scd30_probe()
702 indio_dev->modes = INDIO_DIRECT_MODE; in scd30_probe()
703 indio_dev->available_scan_masks = scd30_scan_masks; in scd30_probe()
705 state->vdd = devm_regulator_get(dev, "vdd"); in scd30_probe()
706 if (IS_ERR(state->vdd)) in scd30_probe()
707 return dev_err_probe(dev, PTR_ERR(state->vdd), "failed to get regulator\n"); in scd30_probe()
709 ret = regulator_enable(state->vdd); in scd30_probe()
721 if (state->irq > 0) { in scd30_probe()
736 ret = scd30_command_write(state, CMD_MEAS_INTERVAL, state->meas_interval); in scd30_probe()
740 ret = scd30_command_write(state, CMD_START_MEAS, state->pressure_comp); in scd30_probe()
753 MODULE_DESCRIPTION("Sensirion SCD30 carbon dioxide sensor core driver");