Lines Matching +full:vref +full:- +full:n +full:- +full:supply
1 // SPDX-License-Identifier: GPL-2.0-only
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
121 * @vref: Power / voltage reference.
122 * @vdd: Power supply.
133 struct regulator *vref; member
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
304 iio_priv(indio_dev))->regmap, 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()
342 goto vref; in zpa2326_power_on()
359 regulator_disable(private->vdd); in zpa2326_power_on()
360 vref: 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()
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()
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.
591 if (test_bit(0, indio_dev->active_scan_mask)) { in zpa2326_fill_sample_buffer()
601 if (test_bit(1, indio_dev->active_scan_mask)) { in zpa2326_fill_sample_buffer()
603 err = regmap_bulk_read(private->regmap, ZPA2326_TEMP_OUT_L_REG, in zpa2326_fill_sample_buffer()
614 * - by hardware interrupt handler if interrupt is available: see in zpa2326_fill_sample_buffer()
616 * - or oneshot completion polling machinery : see in zpa2326_fill_sample_buffer()
622 private->timestamp); in zpa2326_fill_sample_buffer()
634 return -EAGAIN; in zpa2326_runtime_suspend()
657 * zpa2326_resume() - Request the PM layer to power supply the device.
661 * < 0 - a negative error code meaning failure ;
662 * 0 - success, device has just been powered up ;
663 * 1 - success, device was already powered.
669 err = pm_runtime_get_sync(indio_dev->dev.parent); in zpa2326_resume()
671 pm_runtime_put(indio_dev->dev.parent); in zpa2326_resume()
689 * zpa2326_suspend() - Schedule a power down using autosuspend feature of PM
698 struct device *parent = indio_dev->dev.parent; in zpa2326_suspend()
740 * zpa2326_handle_irq() - Process hardware interrupts.
756 iio_priv(indio_dev))->timestamp = iio_get_time_ns(indio_dev); in zpa2326_handle_irq()
763 * zpa2326_handle_threaded_irq() - Interrupt bottom-half handler.
778 * configured in one-shot mode either by an external trigger or the IIO read_raw
785 * %IRQ_NONE - no consistent interrupt happened ;
786 * %IRQ_HANDLED - there was new samples available.
805 * status de-asserts interrupt line. in zpa2326_handle_threaded_irq()
807 priv->result = regmap_read(priv->regmap, ZPA2326_INT_SOURCE_REG, &val); in zpa2326_handle_threaded_irq()
808 if (priv->result < 0) { in zpa2326_handle_threaded_irq()
829 priv->result = -ENODATA; in zpa2326_handle_threaded_irq()
834 iio_trigger_poll_nested(priv->trigger); in zpa2326_handle_threaded_irq()
850 complete(&priv->data_ready); in zpa2326_handle_threaded_irq()
856 * zpa2326_wait_oneshot_completion() - Wait for oneshot data ready interrupt.
871 &private->data_ready, ZPA2326_CONVERSION_JIFFIES); in zpa2326_wait_oneshot_completion()
877 return private->result; in zpa2326_wait_oneshot_completion()
880 regmap_read(private->regmap, ZPA2326_INT_SOURCE_REG, &val); in zpa2326_wait_oneshot_completion()
886 return -ETIME; in zpa2326_wait_oneshot_completion()
890 return -ERESTARTSYS; in zpa2326_wait_oneshot_completion()
900 private->irq = irq; in zpa2326_init_managed_irq()
911 init_completion(&private->data_ready); in zpa2326_init_managed_irq()
930 * zpa2326_poll_oneshot_completion() - Actively poll for one shot data ready.
942 iio_priv(indio_dev))->regmap; in zpa2326_poll_oneshot_completion()
949 * At least, 100 ms is needed for the device to complete its one-shot in zpa2326_poll_oneshot_completion()
953 return -ERESTARTSYS; in zpa2326_poll_oneshot_completion()
962 /* One-shot bit self clears at conversion end. */ in zpa2326_poll_oneshot_completion()
967 err = -ETIME; in zpa2326_poll_oneshot_completion()
985 err = -ENODATA; in zpa2326_poll_oneshot_completion()
998 * zpa2326_fetch_raw_sample() - Retrieve a raw sample and convert it to CPU
1011 iio_priv(indio_dev))->regmap; in zpa2326_fetch_raw_sample()
1040 /* Temperature is a 16 bits wide little-endian signed int. */ in zpa2326_fetch_raw_sample()
1046 return -EINVAL; in zpa2326_fetch_raw_sample()
1051 * zpa2326_sample_oneshot() - Perform a complete one shot sampling cycle.
1098 ret = zpa2326_config_oneshot(indio_dev, priv->irq); in zpa2326_sample_oneshot()
1109 if (priv->irq > 0) in zpa2326_sample_oneshot()
1129 * zpa2326_trigger_handler() - Perform an IIO buffered sampling round in one
1135 * Bottom-half handler called by the IIO trigger to which our device is
1152 * %IRQ_NONE - no consistent interrupt happened ;
1153 * %IRQ_HANDLED - there was new samples available.
1158 data)->indio_dev; in zpa2326_trigger_handler()
1175 if (priv->irq <= 0) { in zpa2326_trigger_handler()
1181 priv->timestamp = iio_get_time_ns(indio_dev); in zpa2326_trigger_handler()
1198 iio_trigger_notify_done(indio_dev->trig); in zpa2326_trigger_handler()
1204 * zpa2326_preenable_buffer() - Prepare device for configuring triggered
1223 iio_priv(indio_dev))->waken = iio_priv(indio_dev); in zpa2326_preenable_buffer()
1229 * zpa2326_postenable_buffer() - Configure device for triggered sampling.
1232 * Basically setup one-shot mode if plugging external trigger.
1249 if (!priv->waken) { in zpa2326_postenable_buffer()
1262 if (!iio_trigger_using_own(indio_dev) && priv->waken) { in zpa2326_postenable_buffer()
1265 * powered up: reconfigure one-shot mode. in zpa2326_postenable_buffer()
1267 err = zpa2326_config_oneshot(indio_dev, priv->irq); in zpa2326_postenable_buffer()
1292 * zpa2326_set_trigger_state() - Start / stop continuous sampling.
1306 trig->dev.parent); in zpa2326_set_trigger_state()
1325 disable_irq(priv->irq); in zpa2326_set_trigger_state()
1331 err = regmap_write(priv->regmap, ZPA2326_CTRL_REG3_REG, in zpa2326_set_trigger_state()
1332 zpa2326_highest_frequency()->odr); in zpa2326_set_trigger_state()
1341 err = regmap_read(priv->regmap, ZPA2326_INT_SOURCE_REG, &val); in zpa2326_set_trigger_state()
1346 * Re-enable interrupts only if we can guarantee the device will in zpa2326_set_trigger_state()
1350 enable_irq(priv->irq); in zpa2326_set_trigger_state()
1359 if (priv->waken) { in zpa2326_set_trigger_state()
1361 err = regmap_write(priv->regmap, ZPA2326_CTRL_REG1_REG, in zpa2326_set_trigger_state()
1369 err = regmap_write(priv->regmap, ZPA2326_CTRL_REG3_REG, in zpa2326_set_trigger_state()
1371 priv->frequency->odr); in zpa2326_set_trigger_state()
1376 priv->frequency->hz); in zpa2326_set_trigger_state()
1387 * zpa2326_init_managed_trigger() - Create interrupt driven / hardware trigger
1412 trigger = devm_iio_trigger_alloc(parent, "%s-dev%d", in zpa2326_init_managed_trigger()
1413 indio_dev->name, in zpa2326_init_managed_trigger()
1416 return -ENOMEM; in zpa2326_init_managed_trigger()
1419 trigger->ops = &zpa2326_trigger_ops; in zpa2326_init_managed_trigger()
1421 private->trigger = trigger; in zpa2326_init_managed_trigger()
1434 return ((struct zpa2326_private *)iio_priv(indio_dev))->frequency->hz; in zpa2326_get_frequency()
1448 return -EINVAL; in zpa2326_set_frequency()
1455 priv->frequency = &zpa2326_sampling_frequencies[freq]; in zpa2326_set_frequency()
1482 return zpa2326_sample_oneshot(indio_dev, chan->type, val); in zpa2326_read_raw()
1485 switch (chan->type) { in zpa2326_read_raw()
1498 * Temp[degC] = Tempcode * 0.00649 - 176.83 in zpa2326_read_raw()
1502 * Hence, to produce a temperature in milli-degrees in zpa2326_read_raw()
1507 * Offset = -176.83 / 0.00649 in zpa2326_read_raw()
1515 return -EINVAL; in zpa2326_read_raw()
1519 switch (chan->type) { in zpa2326_read_raw()
1521 *val = -17683000; in zpa2326_read_raw()
1526 return -EINVAL; in zpa2326_read_raw()
1534 return -EINVAL; in zpa2326_read_raw()
1545 return -EINVAL; in zpa2326_write_raw()
1600 indio_dev->modes = INDIO_DIRECT_MODE; in zpa2326_create_managed_iiodev()
1601 indio_dev->channels = zpa2326_channels; in zpa2326_create_managed_iiodev()
1602 indio_dev->num_channels = ARRAY_SIZE(zpa2326_channels); in zpa2326_create_managed_iiodev()
1603 indio_dev->name = name; in zpa2326_create_managed_iiodev()
1604 indio_dev->info = &zpa2326_info; in zpa2326_create_managed_iiodev()
1622 return -ENOMEM; in zpa2326_probe()
1626 priv->vref = devm_regulator_get(parent, "vref"); in zpa2326_probe()
1627 if (IS_ERR(priv->vref)) in zpa2326_probe()
1628 return PTR_ERR(priv->vref); in zpa2326_probe()
1630 priv->vdd = devm_regulator_get(parent, "vdd"); in zpa2326_probe()
1631 if (IS_ERR(priv->vdd)) in zpa2326_probe()
1632 return PTR_ERR(priv->vdd); in zpa2326_probe()
1635 priv->frequency = zpa2326_highest_frequency(); in zpa2326_probe()
1642 priv->regmap = regmap; in zpa2326_probe()
1670 err = -ENODEV; in zpa2326_probe()
1710 zpa2326_fini_runtime(indio_dev->dev.parent); in zpa2326_remove()