Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Stepan Ionichev <sozdayvek@gmail.com>
Cc: arthur.becker@sentec.com, dlechner@baylibre.com,
	nuno.sa@analog.com, andy@kernel.org, gregkh@linuxfoundation.org,
	hcazarim@yahoo.com, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: light: veml6040: add suspend/resume support
Date: Wed, 13 May 2026 15:15:39 +0100	[thread overview]
Message-ID: <20260513151539.48b0207c@jic23-huawei> (raw)
In-Reply-To: <20260513094536.8038-1-sozdayvek@gmail.com>

On Wed, 13 May 2026 14:45:36 +0500
Stepan Ionichev <sozdayvek@gmail.com> wrote:

> The VEML6040 RGBW light sensor stays in auto-measurement mode at all
> times once probed, drawing its full active current (~200 uA per
> Vishay VEML6040 datasheet, Doc# 84276 Rev. 1.7). On system suspend
> there is no need to keep the sensor running.
> 
> Add system sleep PM callbacks that toggle the SD (shutdown) bit in
> CONF register 00H to put the chip into shutdown on suspend and back
> into normal operation on resume. The bit semantics are documented in
> the datasheet Tables 2-1 and 2-2.
> 
> The existing veml6040_shutdown_action() is unchanged; it still runs
> on module unload to leave the chip shut down.
> 
> Signed-off-by: Stepan Ionichev <sozdayvek@gmail.com>
Hi Stepan

Suspend / resume tend to be a little non trivial to add and datasheets
are sometimes less than perfect in describing powerdown modes, so can
I confirm: Do you have one of these that you are testing this with?

Thanks,

Jonathan

> ---
>  drivers/iio/light/veml6040.c | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
> 
> diff --git a/drivers/iio/light/veml6040.c b/drivers/iio/light/veml6040.c
> index f563f9f0e..ffd0a2a70 100644
> --- a/drivers/iio/light/veml6040.c
> +++ b/drivers/iio/light/veml6040.c
> @@ -13,6 +13,7 @@
>  #include <linux/iio/iio.h>
>  #include <linux/iio/sysfs.h>
>  #include <linux/module.h>
> +#include <linux/pm.h>
>  #include <linux/regmap.h>
>  
>  /* VEML6040 Configuration Registers
> @@ -201,6 +202,32 @@ static void veml6040_shutdown_action(void *data)
>  			   VEML6040_CONF_SD_MSK, VEML6040_CONF_SD_MSK);
>  }
>  
> +/*
> + * Per Vishay VEML6040 datasheet (Doc# 84276 Rev. 1.7), Table 2-1 and
> + * Table 2-2, the SD bit in CONF register 00H controls chip shutdown:
> + * SD = 1 disables the color sensor, SD = 0 re-enables it.
> + */
> +static int veml6040_suspend(struct device *dev)
> +{
> +	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> +	struct veml6040_data *data = iio_priv(indio_dev);
> +
> +	return regmap_update_bits(data->regmap, VEML6040_CONF_REG,
> +				  VEML6040_CONF_SD_MSK, VEML6040_CONF_SD_MSK);
> +}
> +
> +static int veml6040_resume(struct device *dev)
> +{
> +	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));

dev_get_drvdata() rather than going in circles.  It's get of 'implicit'
knowledge that works for i2c sequences like this so most instances of what
you have here got ripped out years ago.  I've never really like the missbalance
and would love to get rid of i2c_set_clientdata() but such is life!


> +	struct veml6040_data *data = iio_priv(indio_dev);
> +
> +	return regmap_update_bits(data->regmap, VEML6040_CONF_REG,
> +				  VEML6040_CONF_SD_MSK, 0);
Andy pointed out regmap_clear_bits() is handy here and set_bits above.

> +}
> +
> +static DEFINE_SIMPLE_DEV_PM_OPS(veml6040_pm_ops, veml6040_suspend,
> +				veml6040_resume);
> +
>  static int veml6040_probe(struct i2c_client *client)
>  {
>  	struct device *dev = &client->dev;
> @@ -271,6 +298,7 @@ static struct i2c_driver veml6040_driver = {
>  	.driver = {
>  		.name = "veml6040",
>  		.of_match_table = veml6040_of_match,
> +		.pm = pm_sleep_ptr(&veml6040_pm_ops),
>  	},
>  };
>  module_i2c_driver(veml6040_driver);


  parent reply	other threads:[~2026-05-13 14:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13  9:45 [PATCH] iio: light: veml6040: add suspend/resume support Stepan Ionichev
2026-05-13  9:50 ` Andy Shevchenko
2026-05-13 14:15 ` Jonathan Cameron [this message]
2026-05-13 14:26 ` Stepan Ionichev
2026-05-13 15:54   ` 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=20260513151539.48b0207c@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=arthur.becker@sentec.com \
    --cc=dlechner@baylibre.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hcazarim@yahoo.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=sozdayvek@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox