All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Akshay Jindal <akshayaj.lkd@gmail.com>
Cc: anshulusr@gmail.com, jic23@kernel.org, dlechner@baylibre.com,
	nuno.sa@analog.com, andy@kernel.org, shuah@kernel.org,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4] iio: light: ltr390: Implement runtime PM support
Date: Tue, 2 Sep 2025 15:57:24 +0300	[thread overview]
Message-ID: <aLbptFRh9ZvAVfLn@smile.fi.intel.com> (raw)
In-Reply-To: <20250901184238.34335-1-akshayaj.lkd@gmail.com>

On Tue, Sep 02, 2025 at 12:12:36AM +0530, Akshay Jindal wrote:
> Implement runtime power management for the LTR390 sensor. The device
> autosuspends after 1s of idle time, reducing current consumption from
> 100 µA in active mode to 1 µA in standby mode as per the datasheet.
> 
> Ensure that interrupts continue to be delivered with runtime PM.
> Since the LTR390 cannot be used as a wakeup source during runtime
> suspend, therefore increment the runtime PM refcount when enabling
> events and decrement it when disabling events or powering down.
> This prevents event loss while still allowing power savings when IRQs
> are unused.

...

> -static int ltr390_read_raw(struct iio_dev *iio_device,
> -			   struct iio_chan_spec const *chan, int *val,
> -			   int *val2, long mask)
> +
> +static int __ltr390_read_raw(struct iio_dev *iio_device,
> +			struct iio_chan_spec const *chan, int *val,
> +			int *val2, long mask)

Can we avoid using leading __ (double underscore)? Better name is
ltr390_read_raw_no_pm(). But you may find even better one.

...

> -static int ltr390_write_event_config(struct iio_dev *indio_dev,
> +static int __ltr390_write_event_config(struct iio_dev *indio_dev,

Ditto.

...

> +static int ltr390_write_event_config(struct iio_dev *indio_dev,
> +				const struct iio_chan_spec *chan,
> +				enum iio_event_type type,
> +				enum iio_event_direction dir,
> +				bool state)
> +{
> +	int ret;
> +	struct ltr390_data *data = iio_priv(indio_dev);
> +	struct device *dev = &data->client->dev;

^^^ (1) for the reference below.

> +	guard(mutex)(&data->lock);
> +
> +	if (state && !data->irq_enabled) {
> +		ret = pm_runtime_resume_and_get(dev);
> +		if (ret < 0) {
> +			dev_err(dev, "runtime PM failed to resume: %d\n", ret);
> +			return ret;
> +		}
> +		data->irq_enabled = true;
> +	}
> +
> +	ret = __ltr390_write_event_config(indio_dev, chan, type, dir, state);
> +
> +	if (!state && data->irq_enabled) {
> +		data->irq_enabled = false;
> +		pm_runtime_put_autosuspend(dev);
> +	}
> +
> +	return ret;
> +}

...

>  	/* Ensure that power off and interrupts are disabled */
> -	if (regmap_clear_bits(data->regmap, LTR390_INT_CFG,
> -				LTR390_LS_INT_EN) < 0)
> -		dev_err(&data->client->dev, "failed to disable interrupts\n");
> +	if (data->irq_enabled) {
> +		if (regmap_clear_bits(data->regmap, LTR390_INT_CFG,
> +					LTR390_LS_INT_EN) < 0)

Wrong indentation, hard to read line, either one line, or do better. Actually
why not assign it to ret? The above not only simple style issue, but also makes
readability much harder as the semantics of '0' is completely hidden. This style
is discouraged.

> +			dev_err(&data->client->dev,
> +					"failed to disable interrupts\n");

Why not doing (1) here as well and with that

			dev_err(dev, "failed to disable interrupts\n");

besides the fact of wrong indentation.

> +		data->irq_enabled = false;
> +
> +		pm_runtime_put_autosuspend(&data->client->dev);
> +	}

...

> +static int ltr390_pm_init(struct ltr390_data *data)
> +{
> +	int ret;
> +	struct device *dev = &data->client->dev;
> +
> +	ret = devm_pm_runtime_set_active_enabled(dev);
> +	if (ret)
> +		return dev_err_probe(dev, ret,
> +					"failed to enable runtime PM\n");

Something wrong with your editor or so, please check and make proper
indentation _everywhere_ (in your changes).

> +	pm_runtime_set_autosuspend_delay(dev, 1000);
> +	pm_runtime_use_autosuspend(dev);
> +	return 0;
> +}

...

> +static int ltr390_runtime_suspend(struct device *dev)
> +{
> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +	struct ltr390_data *data = iio_priv(indio_dev);
> +
> +	return regmap_clear_bits(data->regmap, LTR390_MAIN_CTRL,
> +				LTR390_SENSOR_ENABLE);

I would make it one line despite being 87 character long.

> +}
> +
> +static int ltr390_runtime_resume(struct device *dev)
> +{
> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +	struct ltr390_data *data = iio_priv(indio_dev);
> +
> +	return regmap_set_bits(data->regmap, LTR390_MAIN_CTRL,
> +				LTR390_SENSOR_ENABLE);

Ditto. (Here it's even shorter)

> +}

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2025-09-02 12:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-01 18:42 [PATCH v4] iio: light: ltr390: Implement runtime PM support Akshay Jindal
2025-09-02 12:57 ` Andy Shevchenko [this message]
2025-09-02 12:59   ` Andy Shevchenko
2025-09-03  3:45   ` Akshay Jindal
2025-09-03 10:37     ` Andy Shevchenko
2025-09-03 11:27       ` Akshay Jindal

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=aLbptFRh9ZvAVfLn@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=akshayaj.lkd@gmail.com \
    --cc=andy@kernel.org \
    --cc=anshulusr@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=shuah@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.