linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nishant Malpani <nish.malpani25@gmail.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	"Bogdan, Dragos" <dragos.bogdan@analog.com>,
	darius.berghe@analog.com,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-iio <linux-iio@vger.kernel.org>,
	devicetree <devicetree@vger.kernel.org>
Subject: Re: [PATCH 1/3] iio: gyro: adxrs290: Add triggered buffer support
Date: Wed, 2 Sep 2020 16:01:37 +0530	[thread overview]
Message-ID: <d103b760-5871-de55-af3a-b6b7e5378666@gmail.com> (raw)
In-Reply-To: <CAHp75VfHFo41S=Bhs2MB6Te6VAn+yCteys6XcYgciNZu9VppJg@mail.gmail.com>

Hello,

Thanks for the review, Andy. Comments inline...

On 26/08/20 9:40 pm, Andy Shevchenko wrote:
> On Tue, Aug 25, 2020 at 4:11 PM Nishant Malpani
> <nish.malpani25@gmail.com> 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.
> 
Yep, makes sense.
>> +               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;
> 
I suppose that does make things consistent; will do so in v2.

>> +       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?
> 
It is indeed; I just thought the labeling was a preferred way to jump to 
error handling paths. Will use just the 'break' in v2.

>> +               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.
> 
Got it.

>> +               }
>> +
>>                  /* 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?
> I personally find that more readable but I think I'm violating the 
coding style in the kernel; will remove the parentheses in v2.

> ...
> 
>> +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(...);
> 
Nice, wasn't aware of this. Thanks. Will use 'dev_err_probe()' in v2 
wherever pointed.

With regards,
Nishant Malpani

>> +       }
>> +
>> +       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(...);
> 
>> +       }
> 

  reply	other threads:[~2020-09-02 10:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-25 12:47 [PATCH 0/3] iio: gyro: adxrs290: Add triggered buffer & debugfs support Nishant Malpani
2020-08-25 12:47 ` [PATCH 1/3] iio: gyro: adxrs290: Add triggered buffer support Nishant Malpani
2020-08-26 16:10   ` Andy Shevchenko
2020-09-02 10:31     ` Nishant Malpani [this message]
2020-08-29 16:46   ` Jonathan Cameron
2020-09-03 12:37     ` Nishant Malpani
2020-09-06 14:51       ` Jonathan Cameron
2020-08-25 12:47 ` [PATCH 2/3] dt-bindings: iio: gyro: adxrs290: Add required interrupts property Nishant Malpani
2020-08-29 16:48   ` Jonathan Cameron
2020-09-03 12:46     ` Nishant Malpani
2020-08-25 12:47 ` [PATCH 3/3] iio: gyro: adxrs290: Add debugfs register access support Nishant Malpani
2020-08-29 16:51   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d103b760-5871-de55-af3a-b6b7e5378666@gmail.com \
    --to=nish.malpani25@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=darius.berghe@analog.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dragos.bogdan@analog.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).