Lines Matching +full:one +full:- +full:shot

1 // SPDX-License-Identifier: GPL-2.0-only
18 * ZPA2326 hardware supports 2 sampling mode: one shot and continuous.
20 * A complete one shot sampling cycle gets device out of low power mode,
34 * - get device out of low power mode,
35 * - setup hardware sampling period,
36 * - at end of period, upon data ready interrupt: pop pressure samples out of
38 * - when no longer needed, stop sampling process by putting device into
70 /* 200 ms should be enough for the longest conversion time in one-shot mode. */
78 * struct zpa2326_frequency - Hardware sampling frequency descriptor
102 ARRAY_SIZE(zpa2326_sampling_frequencies) - 1]; in zpa2326_highest_frequency()
106 * struct zpa2326_private - Per-device internal private state
138 dev_err(idev->dev.parent, fmt "\n", ##__VA_ARGS__)
141 dev_warn(idev->dev.parent, fmt "\n", ##__VA_ARGS__)
144 dev_dbg(idev->dev.parent, fmt "\n", ##__VA_ARGS__)
210 * zpa2326_enable_device() - Enable device, i.e. get out of low power mode.
223 iio_priv(indio_dev))->regmap, in zpa2326_enable_device()
236 * zpa2326_sleep() - Disable device, i.e. switch to low power mode.
249 iio_priv(indio_dev))->regmap, in zpa2326_sleep()
262 * zpa2326_reset_device() - Reset device to default hardware state.
275 iio_priv(indio_dev))->regmap, in zpa2326_reset_device()
290 * zpa2326_start_oneshot() - Start a single sampling cycle, i.e. in one shot
294 * Device must have been previously enabled and configured for one shot mode.
304 iio_priv(indio_dev))->regmap, in zpa2326_start_oneshot()
309 zpa2326_err(indio_dev, "failed to start one shot cycle (%d)", in zpa2326_start_oneshot()
314 zpa2326_dbg(indio_dev, "one shot cycle started"); in zpa2326_start_oneshot()
320 * zpa2326_power_on() - Power on device to allow subsequent configuration.
336 err = regulator_enable(private->vref); in zpa2326_power_on()
340 err = regulator_enable(private->vdd); in zpa2326_power_on()
359 regulator_disable(private->vdd); in zpa2326_power_on()
361 regulator_disable(private->vref); in zpa2326_power_on()
369 * zpa2326_power_off() - Power off device, i.e. disable attached power
379 regulator_disable(private->vdd); in zpa2326_power_off()
380 regulator_disable(private->vref); in zpa2326_power_off()
386 * zpa2326_config_oneshot() - Setup device for one shot / on demand mode.
406 iio_priv(indio_dev))->regmap; in zpa2326_config_oneshot()
410 /* Setup highest available Output Data Rate for one shot mode. */ in zpa2326_config_oneshot()
411 err = regmap_write(regs, ZPA2326_CTRL_REG3_REG, freq->odr); in zpa2326_config_oneshot()
421 dev_err(indio_dev->dev.parent, in zpa2326_config_oneshot()
422 "failed to setup one shot mode (%d)", err); in zpa2326_config_oneshot()
427 zpa2326_dbg(indio_dev, "one shot mode setup @%dHz", freq->hz); in zpa2326_config_oneshot()
433 * zpa2326_clear_fifo() - Clear remaining entries in hardware FIFO.
448 iio_priv(indio_dev))->regmap; in zpa2326_clear_fifo()
482 min_count--; in zpa2326_clear_fifo()
503 * zpa2326_dequeue_pressure() - Retrieve the most recent pressure sample from
516 iio_priv(indio_dev))->regmap; in zpa2326_dequeue_pressure()
519 int cleared = -1; in zpa2326_dequeue_pressure()
541 return zpa2326_clear_fifo(indio_dev, ZPA2326_FIFO_DEPTH - 1); in zpa2326_dequeue_pressure()
573 * zpa2326_fill_sample_buffer() - Enqueue new channel samples to IIO buffer.
589 if (test_bit(0, indio_dev->active_scan_mask)) { in zpa2326_fill_sample_buffer()
599 if (test_bit(1, indio_dev->active_scan_mask)) { in zpa2326_fill_sample_buffer()
601 err = regmap_bulk_read(private->regmap, ZPA2326_TEMP_OUT_L_REG, in zpa2326_fill_sample_buffer()
612 * - by hardware interrupt handler if interrupt is available: see in zpa2326_fill_sample_buffer()
614 * - or oneshot completion polling machinery : see in zpa2326_fill_sample_buffer()
620 private->timestamp); in zpa2326_fill_sample_buffer()
632 return -EAGAIN; in zpa2326_runtime_suspend()
655 * zpa2326_resume() - Request the PM layer to power supply the device.
659 * < 0 - a negative error code meaning failure ;
660 * 0 - success, device has just been powered up ;
661 * 1 - success, device was already powered.
667 err = pm_runtime_get_sync(indio_dev->dev.parent); in zpa2326_resume()
669 pm_runtime_put(indio_dev->dev.parent); in zpa2326_resume()
687 * zpa2326_suspend() - Schedule a power down using autosuspend feature of PM
692 * attached regulator is a "dummy" one.
696 struct device *parent = indio_dev->dev.parent; in zpa2326_suspend()
738 * zpa2326_handle_irq() - Process hardware interrupts.
754 iio_priv(indio_dev))->timestamp = iio_get_time_ns(indio_dev); in zpa2326_handle_irq()
761 * zpa2326_handle_threaded_irq() - Interrupt bottom-half handler.
776 * configured in one-shot mode either by an external trigger or the IIO read_raw
777 * hook. This means one of the latter is currently waiting for sampling
783 * %IRQ_NONE - no consistent interrupt happened ;
784 * %IRQ_HANDLED - there was new samples available.
803 * status de-asserts interrupt line. in zpa2326_handle_threaded_irq()
805 priv->result = regmap_read(priv->regmap, ZPA2326_INT_SOURCE_REG, &val); in zpa2326_handle_threaded_irq()
806 if (priv->result < 0) { in zpa2326_handle_threaded_irq()
827 priv->result = -ENODATA; in zpa2326_handle_threaded_irq()
832 iio_trigger_poll_nested(priv->trigger); in zpa2326_handle_threaded_irq()
848 complete(&priv->data_ready); in zpa2326_handle_threaded_irq()
854 * zpa2326_wait_oneshot_completion() - Wait for oneshot data ready interrupt.
866 zpa2326_dbg(indio_dev, "waiting for one shot completion interrupt"); in zpa2326_wait_oneshot_completion()
869 &private->data_ready, ZPA2326_CONVERSION_JIFFIES); in zpa2326_wait_oneshot_completion()
875 return private->result; in zpa2326_wait_oneshot_completion()
878 regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val); in zpa2326_wait_oneshot_completion()
882 zpa2326_warn(indio_dev, "no one shot interrupt occurred (%ld)", in zpa2326_wait_oneshot_completion()
884 return -ETIME; in zpa2326_wait_oneshot_completion()
887 zpa2326_warn(indio_dev, "wait for one shot interrupt cancelled"); in zpa2326_wait_oneshot_completion()
888 return -ERESTARTSYS; in zpa2326_wait_oneshot_completion()
898 private->irq = irq; in zpa2326_init_managed_irq()
909 init_completion(&private->data_ready); in zpa2326_init_managed_irq()
928 * zpa2326_poll_oneshot_completion() - Actively poll for one shot data ready.
940 iio_priv(indio_dev))->regmap; in zpa2326_poll_oneshot_completion()
944 zpa2326_dbg(indio_dev, "polling for one shot completion"); in zpa2326_poll_oneshot_completion()
947 * At least, 100 ms is needed for the device to complete its one-shot in zpa2326_poll_oneshot_completion()
951 return -ERESTARTSYS; in zpa2326_poll_oneshot_completion()
960 /* One-shot bit self clears at conversion end. */ in zpa2326_poll_oneshot_completion()
965 err = -ETIME; in zpa2326_poll_oneshot_completion()
983 err = -ENODATA; in zpa2326_poll_oneshot_completion()
990 zpa2326_warn(indio_dev, "failed to poll one shot completion (%d)", err); in zpa2326_poll_oneshot_completion()
996 * zpa2326_fetch_raw_sample() - Retrieve a raw sample and convert it to CPU
1009 iio_priv(indio_dev))->regmap; in zpa2326_fetch_raw_sample()
1038 /* Temperature is a 16 bits wide little-endian signed int. */ in zpa2326_fetch_raw_sample()
1044 return -EINVAL; in zpa2326_fetch_raw_sample()
1049 * zpa2326_sample_oneshot() - Perform a complete one shot sampling cycle.
1096 ret = zpa2326_config_oneshot(indio_dev, priv->irq); in zpa2326_sample_oneshot()
1107 if (priv->irq > 0) in zpa2326_sample_oneshot()
1127 * zpa2326_trigger_handler() - Perform an IIO buffered sampling round in one
1128 * shot mode.
1133 * Bottom-half handler called by the IIO trigger to which our device is
1150 * %IRQ_NONE - no consistent interrupt happened ;
1151 * %IRQ_HANDLED - there was new samples available.
1156 data)->indio_dev; in zpa2326_trigger_handler()
1168 /* On demand sampling : start a one shot cycle. */ in zpa2326_trigger_handler()
1173 if (priv->irq <= 0) { in zpa2326_trigger_handler()
1179 priv->timestamp = iio_get_time_ns(indio_dev); in zpa2326_trigger_handler()
1196 iio_trigger_notify_done(indio_dev->trig); in zpa2326_trigger_handler()
1202 * zpa2326_preenable_buffer() - Prepare device for configuring triggered
1221 iio_priv(indio_dev))->waken = iio_priv(indio_dev); in zpa2326_preenable_buffer()
1227 * zpa2326_postenable_buffer() - Configure device for triggered sampling.
1230 * Basically setup one-shot mode if plugging external trigger.
1247 if (!priv->waken) { in zpa2326_postenable_buffer()
1260 if (!iio_trigger_using_own(indio_dev) && priv->waken) { in zpa2326_postenable_buffer()
1263 * powered up: reconfigure one-shot mode. in zpa2326_postenable_buffer()
1265 err = zpa2326_config_oneshot(indio_dev, priv->irq); in zpa2326_postenable_buffer()
1290 * zpa2326_set_trigger_state() - Start / stop continuous sampling.
1304 trig->dev.parent); in zpa2326_set_trigger_state()
1321 * required to, i.e. by restoring back to default one shot mode. in zpa2326_set_trigger_state()
1323 disable_irq(priv->irq); in zpa2326_set_trigger_state()
1327 * one shot / direct sampling operations. in zpa2326_set_trigger_state()
1329 err = regmap_write(priv->regmap, ZPA2326_CTRL_REG3_REG, in zpa2326_set_trigger_state()
1330 zpa2326_highest_frequency()->odr); in zpa2326_set_trigger_state()
1339 err = regmap_read(priv->regmap, ZPA2326_INT_SOURCE_REG, &val); in zpa2326_set_trigger_state()
1344 * Re-enable interrupts only if we can guarantee the device will in zpa2326_set_trigger_state()
1348 enable_irq(priv->irq); in zpa2326_set_trigger_state()
1357 if (priv->waken) { in zpa2326_set_trigger_state()
1359 err = regmap_write(priv->regmap, ZPA2326_CTRL_REG1_REG, in zpa2326_set_trigger_state()
1367 err = regmap_write(priv->regmap, ZPA2326_CTRL_REG3_REG, in zpa2326_set_trigger_state()
1369 priv->frequency->odr); in zpa2326_set_trigger_state()
1374 priv->frequency->hz); in zpa2326_set_trigger_state()
1385 * zpa2326_init_managed_trigger() - Create interrupt driven / hardware trigger
1410 trigger = devm_iio_trigger_alloc(parent, "%s-dev%d", in zpa2326_init_managed_trigger()
1411 indio_dev->name, in zpa2326_init_managed_trigger()
1414 return -ENOMEM; in zpa2326_init_managed_trigger()
1417 trigger->ops = &zpa2326_trigger_ops; in zpa2326_init_managed_trigger()
1419 private->trigger = trigger; in zpa2326_init_managed_trigger()
1432 return ((struct zpa2326_private *)iio_priv(indio_dev))->frequency->hz; in zpa2326_get_frequency()
1446 return -EINVAL; in zpa2326_set_frequency()
1453 priv->frequency = &zpa2326_sampling_frequencies[freq]; in zpa2326_set_frequency()
1480 return zpa2326_sample_oneshot(indio_dev, chan->type, val); in zpa2326_read_raw()
1483 switch (chan->type) { in zpa2326_read_raw()
1496 * Temp[degC] = Tempcode * 0.00649 - 176.83 in zpa2326_read_raw()
1500 * Hence, to produce a temperature in milli-degrees in zpa2326_read_raw()
1505 * Offset = -176.83 / 0.00649 in zpa2326_read_raw()
1513 return -EINVAL; in zpa2326_read_raw()
1517 switch (chan->type) { in zpa2326_read_raw()
1519 *val = -17683000; in zpa2326_read_raw()
1524 return -EINVAL; in zpa2326_read_raw()
1532 return -EINVAL; in zpa2326_read_raw()
1543 return -EINVAL; in zpa2326_write_raw()
1598 indio_dev->modes = INDIO_DIRECT_MODE; in zpa2326_create_managed_iiodev()
1599 indio_dev->channels = zpa2326_channels; in zpa2326_create_managed_iiodev()
1600 indio_dev->num_channels = ARRAY_SIZE(zpa2326_channels); in zpa2326_create_managed_iiodev()
1601 indio_dev->name = name; in zpa2326_create_managed_iiodev()
1602 indio_dev->info = &zpa2326_info; in zpa2326_create_managed_iiodev()
1620 return -ENOMEM; in zpa2326_probe()
1624 priv->vref = devm_regulator_get(parent, "vref"); in zpa2326_probe()
1625 if (IS_ERR(priv->vref)) in zpa2326_probe()
1626 return PTR_ERR(priv->vref); in zpa2326_probe()
1628 priv->vdd = devm_regulator_get(parent, "vdd"); in zpa2326_probe()
1629 if (IS_ERR(priv->vdd)) in zpa2326_probe()
1630 return PTR_ERR(priv->vdd); in zpa2326_probe()
1633 priv->frequency = zpa2326_highest_frequency(); in zpa2326_probe()
1640 priv->regmap = regmap; in zpa2326_probe()
1668 err = -ENODEV; in zpa2326_probe()
1708 zpa2326_fini_runtime(indio_dev->dev.parent); in zpa2326_remove()