Lines Matching +full:adc +full:- +full:use +full:- +full:external +full:- +full:triggers
1 // SPDX-License-Identifier: GPL-2.0-only
3 * iio/adc/max1027.c
182 * ->available_scan_masks, the core will select the most appropriate
183 * ->active_scan_mask and the "minimum" number of channels will be
188 * filter out the unneeded samples based on the ->active_scan_mask that has
195 GENMASK(1, 1 - (temp)), GENMASK(2, 1 - (temp)), \
196 GENMASK(3, 1 - (temp)), GENMASK(4, 1 - (temp)), \
197 GENMASK(5, 1 - (temp)), GENMASK(6, 1 - (temp)), \
198 GENMASK(7, 1 - (temp)), GENMASK(8, 1 - (temp))
202 GENMASK(9, 1 - (temp)), GENMASK(10, 1 - (temp)), \
203 GENMASK(11, 1 - (temp)), GENMASK(12, 1 - (temp))
207 GENMASK(13, 1 - (temp)), GENMASK(14, 1 - (temp)), \
208 GENMASK(15, 1 - (temp)), GENMASK(16, 1 - (temp))
284 if (st->spi->irq) { in max1027_wait_eoc()
285 ret = wait_for_completion_timeout(&st->complete, in max1027_wait_eoc()
287 reinit_completion(&st->complete); in max1027_wait_eoc()
289 return -ETIMEDOUT; in max1027_wait_eoc()
291 if (indio_dev->active_scan_mask) in max1027_wait_eoc()
292 conversion_time *= hweight32(*indio_dev->active_scan_mask); in max1027_wait_eoc()
305 st->reg = MAX1027_CONV_REG | MAX1027_SCAN_0_N; in max1027_configure_chans_and_start()
306 st->reg |= MAX1027_CHAN(fls(*indio_dev->active_scan_mask) - 2); in max1027_configure_chans_and_start()
307 if (*indio_dev->active_scan_mask & MAX1X27_SCAN_MASK_TEMP) in max1027_configure_chans_and_start()
308 st->reg |= MAX1027_TEMP; in max1027_configure_chans_and_start()
310 return spi_write(st->spi, &st->reg, 1); in max1027_configure_chans_and_start()
317 st->reg = MAX1027_SETUP_REG | MAX1027_REF_MODE2; in max1027_enable_trigger()
321 * MODE0: external hardware trigger wired to the cnvst input pin in max1027_enable_trigger()
325 st->reg |= MAX1027_CKS_MODE0; in max1027_enable_trigger()
327 st->reg |= MAX1027_CKS_MODE2; in max1027_enable_trigger()
329 return spi_write(st->spi, &st->reg, 1); in max1027_enable_trigger()
344 st->reg = MAX1027_CONV_REG | MAX1027_CHAN(chan->channel) | in max1027_read_single_value()
346 if (chan->type == IIO_TEMP) in max1027_read_single_value()
347 st->reg |= MAX1027_TEMP; in max1027_read_single_value()
348 ret = spi_write(st->spi, &st->reg, 1); in max1027_read_single_value()
350 dev_err(&indio_dev->dev, in max1027_read_single_value()
356 * For an unknown reason, when we use the mode "10" (write in max1027_read_single_value()
365 ret = spi_read(st->spi, st->buffer, (chan->type == IIO_TEMP) ? 4 : 2); in max1027_read_single_value()
373 *val = be16_to_cpu(st->buffer[0]); in max1027_read_single_value()
385 mutex_lock(&st->lock); in max1027_read_raw()
392 switch (chan->type) { in max1027_read_raw()
400 *val2 = chan->scan_type.realbits; in max1027_read_raw()
404 ret = -EINVAL; in max1027_read_raw()
409 ret = -EINVAL; in max1027_read_raw()
413 mutex_unlock(&st->lock); in max1027_read_raw()
423 u8 *val = (u8 *)st->buffer; in max1027_debugfs_reg_access()
426 int ret = spi_read(st->spi, val, 2); in max1027_debugfs_reg_access()
427 *readval = be16_to_cpu(st->buffer[0]); in max1027_debugfs_reg_access()
432 return spi_write(st->spi, val, 1); in max1027_debugfs_reg_access()
444 * the external hardware trigger. in max1027_set_cnvst_trigger_state()
465 scanned_chans = fls(*indio_dev->active_scan_mask) - 1; in max1027_read_scan()
466 if (*indio_dev->active_scan_mask & MAX1X27_SCAN_MASK_TEMP) in max1027_read_scan()
470 ret = spi_read(st->spi, st->buffer, scanned_chans * 2); in max1027_read_scan()
474 iio_push_to_buffers(indio_dev, st->buffer); in max1027_read_scan()
485 * If buffers are disabled (raw read) or when using external triggers, in max1027_handler()
488 * When using the internal trigger, we must hand-off the choice of the in max1027_handler()
496 complete(&st->complete); in max1027_handler()
498 iio_trigger_poll(indio_dev->trig); in max1027_handler()
506 struct iio_dev *indio_dev = pf->indio_dev; in max1027_trigger_handler()
523 dev_err(&indio_dev->dev, in max1027_trigger_handler()
526 iio_trigger_notify_done(indio_dev->trig); in max1027_trigger_handler()
547 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); in max1027_probe()
550 return -ENOMEM; in max1027_probe()
554 st->spi = spi; in max1027_probe()
555 st->info = &max1027_chip_info_tbl[spi_get_device_id(spi)->driver_data]; in max1027_probe()
557 mutex_init(&st->lock); in max1027_probe()
558 init_completion(&st->complete); in max1027_probe()
560 indio_dev->name = spi_get_device_id(spi)->name; in max1027_probe()
561 indio_dev->info = &max1027_info; in max1027_probe()
562 indio_dev->modes = INDIO_DIRECT_MODE; in max1027_probe()
563 indio_dev->channels = st->info->channels; in max1027_probe()
564 indio_dev->num_channels = st->info->num_channels; in max1027_probe()
565 indio_dev->available_scan_masks = st->info->available_scan_masks; in max1027_probe()
567 st->buffer = devm_kmalloc_array(&indio_dev->dev, in max1027_probe()
568 indio_dev->num_channels, 2, in max1027_probe()
570 if (!st->buffer) in max1027_probe()
571 return -ENOMEM; in max1027_probe()
574 ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, in max1027_probe()
579 dev_err(&indio_dev->dev, "Failed to setup buffer\n"); in max1027_probe()
584 if (spi->irq) { in max1027_probe()
585 st->trig = devm_iio_trigger_alloc(&spi->dev, "%s-trigger", in max1027_probe()
586 indio_dev->name); in max1027_probe()
587 if (!st->trig) { in max1027_probe()
588 ret = -ENOMEM; in max1027_probe()
589 dev_err(&indio_dev->dev, in max1027_probe()
594 st->trig->ops = &max1027_trigger_ops; in max1027_probe()
595 iio_trigger_set_drvdata(st->trig, indio_dev); in max1027_probe()
596 ret = devm_iio_trigger_register(&indio_dev->dev, in max1027_probe()
597 st->trig); in max1027_probe()
599 dev_err(&indio_dev->dev, in max1027_probe()
604 ret = devm_request_irq(&spi->dev, spi->irq, max1027_handler, in max1027_probe()
606 spi->dev.driver->name, indio_dev); in max1027_probe()
608 dev_err(&indio_dev->dev, "Failed to allocate IRQ.\n"); in max1027_probe()
614 st->reg = MAX1027_RST_REG; in max1027_probe()
615 ret = spi_write(st->spi, &st->reg, 1); in max1027_probe()
617 dev_err(&indio_dev->dev, "Failed to reset the ADC\n"); in max1027_probe()
622 st->reg = MAX1027_AVG_REG; in max1027_probe()
623 ret = spi_write(st->spi, &st->reg, 1); in max1027_probe()
625 dev_err(&indio_dev->dev, "Failed to configure averaging register\n"); in max1027_probe()
634 return devm_iio_device_register(&spi->dev, indio_dev); in max1027_probe()
648 MODULE_DESCRIPTION("MAX1X27/MAX1X29/MAX1X31 ADC");