All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Sean Nyekjaer <sean@geanix.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-iio <linux-iio@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] iio: accel: fxls8962af: add wake on event
Date: Tue, 24 Aug 2021 15:40:18 +0300	[thread overview]
Message-ID: <CAHp75VdzUuMogq7u5hd2ajw+rzEtaWuybrTkQ2ykossy1T2iUg@mail.gmail.com> (raw)
In-Reply-To: <20210824113709.1834195-2-sean@geanix.com>

On Tue, Aug 24, 2021 at 2:39 PM Sean Nyekjaer <sean@geanix.com> wrote:
>
> This adds ways for the SoC to wake from accelerometer wake events.
>
> In the suspend function we skip disabling the sensor if wakeup-source
> and events are activated.
>
> If buffered reads are enabled they will be deactivated before suspend.
> As the onboard buffer is only holding up to 32 12-bit X/Y/Z data
> triplets.

Assuming it works, the code looks good to me
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

One niy-pick below, though.

> Signed-off-by: Sean Nyekjaer <sean@geanix.com>
> ---
> Changes since v1:
>  - Fixed comments fron Andy (Thanks)
>
>  drivers/iio/accel/fxls8962af-core.c | 47 +++++++++++++++++++++++++++--
>  1 file changed, 45 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/accel/fxls8962af-core.c b/drivers/iio/accel/fxls8962af-core.c
> index fd35f8685e62..ecd138f595d4 100644
> --- a/drivers/iio/accel/fxls8962af-core.c
> +++ b/drivers/iio/accel/fxls8962af-core.c
> @@ -160,6 +160,7 @@ struct fxls8962af_data {
>         } scan;
>         int64_t timestamp, old_timestamp;       /* Only used in hw fifo mode. */
>         struct iio_mount_matrix orientation;
> +       int irq;
>         u8 watermark;
>         u8 enable_event;
>         u16 lower_thres;
> @@ -1121,6 +1122,7 @@ int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq)
>         data = iio_priv(indio_dev);
>         dev_set_drvdata(dev, indio_dev);
>         data->regmap = regmap;
> +       data->irq = irq;
>
>         ret = iio_read_mount_matrix(dev, &data->orientation);
>         if (ret)
> @@ -1190,6 +1192,9 @@ int fxls8962af_core_probe(struct device *dev, struct regmap *regmap, int irq)
>         if (ret)
>                 return ret;
>
> +       if (device_property_read_bool(dev, "wakeup-source"))
> +               device_init_wakeup(dev, true);
> +
>         return devm_iio_device_register(dev, indio_dev);
>  }
>  EXPORT_SYMBOL_GPL(fxls8962af_core_probe);
> @@ -1215,9 +1220,47 @@ static int __maybe_unused fxls8962af_runtime_resume(struct device *dev)
>         return fxls8962af_active(data);
>  }
>
> +static int __maybe_unused fxls8962af_suspend(struct device *dev)
> +{
> +       struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +       struct fxls8962af_data *data = iio_priv(indio_dev);
> +
> +       if (device_may_wakeup(dev) && data->enable_event) {
> +               enable_irq_wake(data->irq);
> +
> +               /*
> +                * Disable buffer, as the buffer is so small the device will wake
> +                * almost immediately.
> +                */
> +               if (iio_buffer_enabled(indio_dev))
> +                       fxls8962af_buffer_predisable(indio_dev);
> +       } else {
> +               fxls8962af_runtime_suspend(dev);
> +       }
> +
> +       return 0;
> +}
> +
> +static int __maybe_unused fxls8962af_resume(struct device *dev)
> +{
> +       struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +       struct fxls8962af_data *data = iio_priv(indio_dev);
> +
> +       if (device_may_wakeup(dev) && data->enable_event) {
> +               disable_irq_wake(data->irq);
> +
> +               if (iio_buffer_enabled(indio_dev))
> +                       fxls8962af_buffer_postenable(indio_dev);
> +       } else {
> +               fxls8962af_runtime_resume(dev);
> +       }
> +
> +       return 0;
> +}
> +
>  const struct dev_pm_ops fxls8962af_pm_ops = {
> -       SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
> -                               pm_runtime_force_resume)

> +       SET_SYSTEM_SLEEP_PM_OPS(fxls8962af_suspend,
> +                               fxls8962af_resume)

Now one line?

>         SET_RUNTIME_PM_OPS(fxls8962af_runtime_suspend,
>                            fxls8962af_runtime_resume, NULL)
>  };

-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2021-08-24 12:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-24 11:37 [PATCH v2 1/2] iio: accel: fxls8962af: add threshold event handling Sean Nyekjaer
2021-08-24 11:37 ` [PATCH v2 2/2] iio: accel: fxls8962af: add wake on event Sean Nyekjaer
2021-08-24 12:40   ` Andy Shevchenko [this message]
2021-08-24 12:15 ` [PATCH v2 1/2] iio: accel: fxls8962af: add threshold event handling Andy Shevchenko
2021-08-24 12:32   ` Sean Nyekjaer
2021-08-24 12:42     ` Andy Shevchenko
2021-08-24 12:59       ` Sean Nyekjaer

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=CAHp75VdzUuMogq7u5hd2ajw+rzEtaWuybrTkQ2ykossy1T2iUg@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=sean@geanix.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.