/** * ad7606_poll_bh_to_ring() bh of trigger launched polling to ring buffer * @work_s: the work struct through which this was scheduled * * Currently there is no option in this driver to disable the saving of * timestamps within the ring. * I think the one copy of this at a time was to avoid problems if the * trigger was set far too high and the reads then locked up the computer. **/ static void ad7606_poll_bh_to_ring(struct work_struct *work_s) { struct ad7606_state *st = container_of(work_s, struct ad7606_state, poll_work); struct iio_dev *indio_dev = iio_priv_to_dev(st); struct iio_buffer *ring = indio_dev->buffer; s64 time_ns; __u8 *buf; int ret; buf = kzalloc(ring->access->get_bytes_per_datum(ring), GFP_KERNEL); if (buf == NULL) return; if (gpio_is_valid(st->pdata->gpio_frstdata)) { ret = st->bops->read_block(st->dev, 1, buf); if (ret) goto done; if (!gpio_get_value(st->pdata->gpio_frstdata)) { /* This should never happen. However * some signal glitch caused by bad PCB desgin or * electrostatic discharge, could cause an extra read * or clock. This allows recovery. */ ad7606_reset(st); goto done; } ret = st->bops->read_block(st->dev, st->chip_info->num_channels - 1, buf + 2); if (ret) goto done; } else { ret = st->bops->read_block(st->dev, st->chip_info->num_channels, buf); if (ret) goto done; } time_ns = iio_get_time_ns(); if (ring->scan_timestamp) *((s64 *)(buf + ring->access->get_bytes_per_datum(ring) - sizeof(s64))) = time_ns; ring->access->store_to(indio_dev->buffer, buf, time_ns); done: gpio_set_value(st->pdata->gpio_convst, 0); iio_trigger_notify_done(indio_dev->trig); kfree(buf); }
static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned ch) { struct ad7606_state *st = iio_priv(indio_dev); int ret; st->done = false; gpio_set_value(st->pdata->gpio_convst, 1); ret = wait_event_interruptible(st->wq_data_avail, st->done); if (ret) goto error_ret; if (gpio_is_valid(st->pdata->gpio_frstdata)) { ret = st->bops->read_block(st->dev, 1, st->data); if (ret) goto error_ret; if (!gpio_get_value(st->pdata->gpio_frstdata)) { /* This should never happen */ ad7606_reset(st); ret = -EIO; goto error_ret; } ret = st->bops->read_block(st->dev, st->chip_info->num_channels - 1, &st->data[1]); if (ret) goto error_ret; } else { ret = st->bops->read_block(st->dev, st->chip_info->num_channels, st->data); if (ret) goto error_ret; } ret = st->data[ch]; error_ret: gpio_set_value(st->pdata->gpio_convst, 0); return ret; }