public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Vasileios Amoiridis <vassilisamir@gmail.com>
Cc: lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, andriy.shevchenko@linux.intel.com,
	ang.iglesiasg@gmail.com, linus.walleij@linaro.org,
	biju.das.jz@bp.renesas.com, javier.carrasco.cruz@gmail.com,
	semen.protsenko@linaro.org, 579lpy@gmail.com, ak@it-klinger.de,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, christophe.jaillet@wanadoo.fr
Subject: Re: [PATCH v8 1/4] iio: pressure: bmp280: Use sleep and forced mode for oneshot captures
Date: Sat, 12 Oct 2024 17:03:33 +0100	[thread overview]
Message-ID: <20241012170333.37059686@jic23-huawei> (raw)
In-Reply-To: <20241007194945.66192-2-vassilisamir@gmail.com>

On Mon,  7 Oct 2024 21:49:42 +0200
Vasileios Amoiridis <vassilisamir@gmail.com> wrote:

> Add forced mode support in sensors BMP28x, BME28x, BMP3xx and BMP58x.
> Sensors BMP18x and BMP085 are old and do not support this feature so
> their operation is not affected at all.
> 
> Essentially, up to now, the rest of the sensors were used in normal mode
> all the time. This means that they are continuously doing measurements
> even though these measurements are not used. Even though the sensor does
> provide PM support, to cover all the possible use cases, the sensor needs
> to go into sleep mode and wake up whenever necessary.
> 
> The idea is that the sensor is by default in sleep mode, wakes up in
> forced mode when a oneshot capture is requested, or in normal mode
> when the buffer is enabled. The difference lays in the fact that in
> forced mode, the sensor does only one conversion and goes back to sleep
> while in normal mode, the sensor does continuous measurements with the
> frequency that was set in the ODR registers.
> 
> The bmpX_chip_config() functions which are responsible for applying
> the requested configuration to the sensor, are modified accordingly
> in order to set the sensor by default in sleep mode.
> 
> DEEP STANDBY, Low Power NORMAL and CONTINUOUS modes, supported only by
> the BMP58x version, are not added.
> 
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
Hi Vasilieos

Given it looks like you'll be doing a v9 anyway, a few comments inline
on some minor simplifications and potential readability improvements.

Thanks,

Jonathan


> ---
>  drivers/iio/pressure/bmp280-core.c | 296 +++++++++++++++++++++++++++--
>  drivers/iio/pressure/bmp280.h      |  21 ++
>  2 files changed, 296 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
> index 6811619c6f11..9ad29cf4c2ac 100644
> --- a/drivers/iio/pressure/bmp280-core.c
> +++ b/drivers/iio/pressure/bmp280-core.c
> @@ -16,6 +16,11 @@


> @@ -1522,6 +1610,71 @@ static int bmp380_preinit(struct bmp280_data *data)
>  	return bmp380_cmd(data, BMP380_CMD_SOFT_RESET);
>  }
>  
> +static const u8 bmp380_operation_mode[] = {
> +	BMP380_MODE_SLEEP, BMP380_MODE_FORCED, BMP380_MODE_NORMAL,
> +};

As below - I'd assign these to specific entries to make the fairly obvious association
even more obvious!

> +
> +static int bmp380_set_mode(struct bmp280_data *data, enum bmp280_op_mode mode)
> +{
> +	int ret;
> +
> +	switch (mode) {
> +	case BMP280_SLEEP:
> +	case BMP280_FORCED:
> +	case BMP280_NORMAL:
> +		break;
> +	default:
> +		return -EINVAL;

Currently there aren't others. So the compiler should shout if you try to pass
something else. Hence this check shouldn't be needed.

> +	}
> +
> +	ret = regmap_write_bits(data->regmap, BMP380_REG_POWER_CONTROL,
> +				BMP380_MODE_MASK,
> +				FIELD_PREP(BMP380_MODE_MASK,
> +					   bmp380_operation_mode[mode]));
> +	if (ret) {
> +		dev_err(data->dev, "failed to  write power control register.\n");
> +		return ret;
> +	}
> +
> +	data->op_mode = mode;
> +
> +	return 0;
> +}
>

>  	return PTR_ERR_OR_ZERO(devm_nvmem_register(config.dev, &config));
>  }
>  
> +static const u8 bmp580_operation_mode[] = {
> +	BMP580_MODE_SLEEP, BMP580_MODE_FORCED, BMP580_MODE_NORMAL,

For these, explicit setting will make it more obvious.
	[BMP280_SLEEP] = BMP580_MODE_SLEEP,
etc

> +};
> +
> +static int bmp580_set_mode(struct bmp280_data *data, enum bmp280_op_mode mode)
> +{
> +	struct device *dev = data->dev;
> +	int ret;
> +
> +	switch (mode) {
> +	case BMP280_SLEEP:
> +	case BMP280_NORMAL:
> +		break;
> +	case BMP280_FORCED:
> +		ret = regmap_set_bits(data->regmap, BMP580_REG_DSP_CONFIG,
> +				      BMP580_DSP_IIR_FORCED_FLUSH);
> +		if (ret) {
> +			dev_err(dev, "Could not flush IIR filter constants.\n");
> +			return ret;
> +		}
> +		break;
> +	default:
There are only the values above, and we should hopefully be able to rely
on compiler warnings to shout at us if a future modification adds more.

So should be able to drop the default here.

> +		return -EINVAL;
> +	}
> +
> +	ret = regmap_write_bits(data->regmap, BMP580_REG_ODR_CONFIG,
> +				BMP580_MODE_MASK,
> +				FIELD_PREP(BMP580_MODE_MASK,
> +					   bmp580_operation_mode[mode]));
> +	if (ret) {
> +		dev_err(dev, "failed to  write power control register.\n");
> +		return ret;
> +	}
> +
> +	data->op_mode = mode;
> +
> +	return 0;
> +}


  parent reply	other threads:[~2024-10-12 16:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-07 19:49 [PATCH v8 0/4] pressure: bmp280: Minor cleanup and interrupt support Vasileios Amoiridis
2024-10-07 19:49 ` [PATCH v8 1/4] iio: pressure: bmp280: Use sleep and forced mode for oneshot captures Vasileios Amoiridis
2024-10-11  4:32   ` kernel test robot
2024-10-11 10:53     ` Andy Shevchenko
2024-10-11 17:35       ` Vasileios Aoiridis
2024-10-12 16:03   ` Jonathan Cameron [this message]
2024-10-14 19:50     ` Vasileios Amoiridis
2024-10-07 19:49 ` [PATCH v8 2/4] dt-bindings: iio: pressure: bmp085: Add interrupts for BMP3xx and BMP5xx devices Vasileios Amoiridis
2024-10-07 19:49 ` [PATCH v8 3/4] iio: pressure: bmp280: Add data ready trigger support Vasileios Amoiridis
2024-10-12 16:08   ` Jonathan Cameron
2024-10-14 20:10     ` Vasileios Amoiridis
2024-10-07 19:49 ` [PATCH v8 4/4] iio: pressure: bmp280: Move bmp085 interrupt to new configuration Vasileios Amoiridis

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=20241012170333.37059686@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=579lpy@gmail.com \
    --cc=ak@it-klinger.de \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=ang.iglesiasg@gmail.com \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=semen.protsenko@linaro.org \
    --cc=vassilisamir@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