On Tue, Aug 25, 2020 at 4:11 PM Nishant Malpani <nish.malpani25@xxxxxxxxx> wrote: > > Provide a way for continuous data capture by setting up buffer support. The > data ready signal exposed at the SYNC pin of the ADXRS290 is exploited as > a hardware interrupt which triggers to fill the buffer. > > Triggered buffer setup was tested with both hardware trigger (DATA_RDY) and > software triggers (sysfs-trig & hrtimer). ... > +static int adxrs290_set_mode(struct iio_dev *indio_dev, enum adxrs290_mode mode) > +{ > + struct adxrs290_state *st = iio_priv(indio_dev); > + int val, ret; > + > + mutex_lock(&st->lock); > + > + if (st->mode == mode) { > + ret = 0; Can be done outside of mutex. > + goto done; > + } > + > + val = spi_w8r8(st->spi, ADXRS290_READ_REG(ADXRS290_REG_POWER_CTL)); > + if (val < 0) { > + ret = val; > + goto done; > + } Consider other way around ret = ... ... val = ret; > + switch (mode) { > + case ADXRS290_MODE_STANDBY: > + val &= ~ADXRS290_MEASUREMENT; > + break; > + case ADXRS290_MODE_MEASUREMENT: > + val |= ADXRS290_MEASUREMENT; > + break; > + default: > + ret = -EINVAL; > + goto done; > + } > + > + ret = adxrs290_spi_write_reg(st->spi, > + ADXRS290_REG_POWER_CTL, > + val); > + if (ret < 0) { > + dev_err(&st->spi->dev, "unable to set mode: %d\n", ret); > + goto done; > + } > + > + /* update cached mode */ > + st->mode = mode; > + > +done: > + mutex_unlock(&st->lock); > + return ret; > +} ... > + goto err_release; > > - return IIO_VAL_INT; > + ret = IIO_VAL_INT; > + break; > default: > - return -EINVAL; > + ret = -EINVAL; > + break; > } > +err_release: I didn't get the purpose of this. Wasn't the break statement enough? > + iio_device_release_direct_mode(indio_dev); > + return ret; > case IIO_CHAN_INFO_SCALE: > switch (chan->type) { > case IIO_ANGL_VEL: ... > + goto err_release; Ditto. > + } > + > /* caching the updated state of the high-pass filter */ > st->hpf_3db_freq_idx = hpf_idx; > /* retrieving the current state of the low-pass filter */ > lpf_idx = st->lpf_3db_freq_idx; > - return adxrs290_set_filter_freq(indio_dev, lpf_idx, hpf_idx); > + ret = adxrs290_set_filter_freq(indio_dev, lpf_idx, hpf_idx); > + break; > + > + default: > + ret = -EINVAL; > + break; > } > > - return -EINVAL; > +err_release: > + iio_device_release_direct_mode(indio_dev); > + return ret; > } ... > + val = (state ? ADXRS290_SYNC(ADXRS290_DATA_RDY_OUT) : 0); Purpose of outer parentheses? ... > +static int adxrs290_probe_trigger(struct iio_dev *indio_dev) > +{ > + struct adxrs290_state *st = iio_priv(indio_dev); > + int ret; > + > + if (!st->spi->irq) { > + dev_info(&st->spi->dev, "no irq, using polling\n"); > + return 0; > + } > + > + st->dready_trig = devm_iio_trigger_alloc(&st->spi->dev, > + "%s-dev%d", > + indio_dev->name, > + indio_dev->id); > + if (!st->dready_trig) > + return -ENOMEM; > + > + st->dready_trig->dev.parent = &st->spi->dev; > + st->dready_trig->ops = &adxrs290_trigger_ops; > + iio_trigger_set_drvdata(st->dready_trig, indio_dev); > + > + ret = devm_request_irq(&st->spi->dev, st->spi->irq, > + &iio_trigger_generic_data_rdy_poll, > + IRQF_ONESHOT, > + "adxrs290_irq", st->dready_trig); > + if (ret < 0) { > + dev_err(&st->spi->dev, "request irq %d failed\n", st->spi->irq); > + return ret; return dev_err_probe(...); > + } > + > + ret = devm_iio_trigger_register(&st->spi->dev, st->dready_trig); > + if (ret) { > + dev_err(&st->spi->dev, "iio trigger register failed\n"); > + return ret; return dev_err_probe(...); > + } > + > + indio_dev->trig = iio_trigger_get(st->dready_trig); > + > + return 0; > +} ... > + ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, > + &iio_pollfunc_store_time, > + &adxrs290_trigger_handler, NULL); > + if (ret < 0) { > + dev_err(&spi->dev, "iio triggered buffer setup failed\n"); > + return ret; return dev_err_probe(...); > + } -- With Best Regards, Andy Shevchenko