All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandru Ardelean <aardelean@deviqon.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: linux-iio <linux-iio@vger.kernel.org>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: Re: [PATCH 2/5] iio: accel: mma9551/mma9553: Simplify pm logic
Date: Mon, 24 May 2021 10:33:58 +0300	[thread overview]
Message-ID: <CAASAkoY+eRTAA8AO4hA1B2W+t+rs_zv7yoT2O3zJERVG6mb+Dg@mail.gmail.com> (raw)
In-Reply-To: <20210523162315.1965869-3-jic23@kernel.org>

On Sun, 23 May 2021 at 19:24, Jonathan Cameron <jic23@kernel.org> wrote:
>
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
>
> I can't see why we shouldn't sleep in the system resume path to allow
> the device firmware to fully wakeup.  Having done that, the runtime
> system functions are identical (down to an error print) so use
> pm_runtime_force_suspend() and pm_runtime_force_resume() to reduce
> repitition.
>
> General preference in IIO is now to mark these functions __maybe_unused
> instead of using ifdefs as it is easy to get them wrong.
> Here they appear correct, but provide a less than desirable example
> to copy into other drivers.
>

Reviewed-by: Alexandru Ardelean <aardelean@deviqon.com>

> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/iio/accel/mma9551.c | 37 ++++--------------------------------
>  drivers/iio/accel/mma9553.c | 38 ++++---------------------------------
>  2 files changed, 8 insertions(+), 67 deletions(-)
>
> diff --git a/drivers/iio/accel/mma9551.c b/drivers/iio/accel/mma9551.c
> index 2b74f67536a3..1b4a8b27f14a 100644
> --- a/drivers/iio/accel/mma9551.c
> +++ b/drivers/iio/accel/mma9551.c
> @@ -510,8 +510,7 @@ static int mma9551_remove(struct i2c_client *client)
>         return 0;
>  }
>
> -#ifdef CONFIG_PM
> -static int mma9551_runtime_suspend(struct device *dev)
> +static __maybe_unused int mma9551_runtime_suspend(struct device *dev)
>  {
>         struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>         struct mma9551_data *data = iio_priv(indio_dev);
> @@ -522,13 +521,13 @@ static int mma9551_runtime_suspend(struct device *dev)
>         mutex_unlock(&data->mutex);
>         if (ret < 0) {
>                 dev_err(&data->client->dev, "powering off device failed\n");
> -               return -EAGAIN;
> +               return ret;
>         }
>
>         return 0;
>  }
>
> -static int mma9551_runtime_resume(struct device *dev)
> +static __maybe_unused int mma9551_runtime_resume(struct device *dev)
>  {
>         struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>         struct mma9551_data *data = iio_priv(indio_dev);
> @@ -542,38 +541,10 @@ static int mma9551_runtime_resume(struct device *dev)
>
>         return 0;
>  }
> -#endif
> -
> -#ifdef CONFIG_PM_SLEEP
> -static int mma9551_suspend(struct device *dev)
> -{
> -       struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> -       struct mma9551_data *data = iio_priv(indio_dev);
> -       int ret;
> -
> -       mutex_lock(&data->mutex);
> -       ret = mma9551_set_device_state(data->client, false);
> -       mutex_unlock(&data->mutex);
> -
> -       return ret;
> -}
> -
> -static int mma9551_resume(struct device *dev)
> -{
> -       struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> -       struct mma9551_data *data = iio_priv(indio_dev);
> -       int ret;
>
> -       mutex_lock(&data->mutex);
> -       ret = mma9551_set_device_state(data->client, true);
> -       mutex_unlock(&data->mutex);
> -
> -       return ret;
> -}
> -#endif
>
>  static const struct dev_pm_ops mma9551_pm_ops = {
> -       SET_SYSTEM_SLEEP_PM_OPS(mma9551_suspend, mma9551_resume)
> +       SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
>         SET_RUNTIME_PM_OPS(mma9551_runtime_suspend,
>                            mma9551_runtime_resume, NULL)
>  };
> diff --git a/drivers/iio/accel/mma9553.c b/drivers/iio/accel/mma9553.c
> index 32c9a79ebfec..dc2a3316c1a3 100644
> --- a/drivers/iio/accel/mma9553.c
> +++ b/drivers/iio/accel/mma9553.c
> @@ -1149,8 +1149,7 @@ static int mma9553_remove(struct i2c_client *client)
>         return 0;
>  }
>
> -#ifdef CONFIG_PM
> -static int mma9553_runtime_suspend(struct device *dev)
> +static __maybe_unused int mma9553_runtime_suspend(struct device *dev)
>  {
>         struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>         struct mma9553_data *data = iio_priv(indio_dev);
> @@ -1161,13 +1160,13 @@ static int mma9553_runtime_suspend(struct device *dev)
>         mutex_unlock(&data->mutex);
>         if (ret < 0) {
>                 dev_err(&data->client->dev, "powering off device failed\n");
> -               return -EAGAIN;
> +               return ret;
>         }
>
>         return 0;
>  }
>
> -static int mma9553_runtime_resume(struct device *dev)
> +static __maybe_unused int mma9553_runtime_resume(struct device *dev)
>  {
>         struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>         struct mma9553_data *data = iio_priv(indio_dev);
> @@ -1181,38 +1180,9 @@ static int mma9553_runtime_resume(struct device *dev)
>
>         return 0;
>  }
> -#endif
> -
> -#ifdef CONFIG_PM_SLEEP
> -static int mma9553_suspend(struct device *dev)
> -{
> -       struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> -       struct mma9553_data *data = iio_priv(indio_dev);
> -       int ret;
> -
> -       mutex_lock(&data->mutex);
> -       ret = mma9551_set_device_state(data->client, false);
> -       mutex_unlock(&data->mutex);
> -
> -       return ret;
> -}
> -
> -static int mma9553_resume(struct device *dev)
> -{
> -       struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> -       struct mma9553_data *data = iio_priv(indio_dev);
> -       int ret;
> -
> -       mutex_lock(&data->mutex);
> -       ret = mma9551_set_device_state(data->client, true);
> -       mutex_unlock(&data->mutex);
> -
> -       return ret;
> -}
> -#endif
>
>  static const struct dev_pm_ops mma9553_pm_ops = {
> -       SET_SYSTEM_SLEEP_PM_OPS(mma9553_suspend, mma9553_resume)
> +       SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
>         SET_RUNTIME_PM_OPS(mma9553_runtime_suspend,
>                            mma9553_runtime_resume, NULL)
>  };
> --
> 2.31.1
>

  reply	other threads:[~2021-05-24  7:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-23 16:23 [PATCH 0/5] iio: accel: mma9551/mma9553 Cleanup and update Jonathan Cameron
2021-05-23 16:23 ` [PATCH 1/5] iio: accel: mma9551/mma9553: Drop explicit ACPI match support Jonathan Cameron
2021-05-23 19:17   ` Andy Shevchenko
2021-05-24  7:28   ` Alexandru Ardelean
2021-05-23 16:23 ` [PATCH 2/5] iio: accel: mma9551/mma9553: Simplify pm logic Jonathan Cameron
2021-05-24  7:33   ` Alexandru Ardelean [this message]
2021-05-23 16:23 ` [PATCH 3/5] iio: accel: mma9551: Add support to get irqs directly from fwnode Jonathan Cameron
2021-05-24  6:13   ` Andy Shevchenko
2021-05-24  9:27     ` Jonathan Cameron
2021-06-03 18:40       ` Jonathan Cameron
2021-05-24  8:16   ` Alexandru Ardelean
2021-05-23 16:23 ` [PATCH 4/5] iio: accel: mma9551: Use devm managed functions to tidy up probe() Jonathan Cameron
2021-05-24  8:13   ` Alexandru Ardelean
2021-05-23 16:23 ` [PATCH 5/5] iio: accel: mma9553: " Jonathan Cameron
2021-05-24  8:15   ` Alexandru Ardelean

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=CAASAkoY+eRTAA8AO4hA1B2W+t+rs_zv7yoT2O3zJERVG6mb+Dg@mail.gmail.com \
    --to=aardelean@deviqon.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.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 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.