public inbox for devicetree@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,
	anshulusr@gmail.com, gustavograzs@gmail.com,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 3/7] iio: chemical: bme680: Add triggered buffer support
Date: Sat, 2 Nov 2024 15:24:52 +0000	[thread overview]
Message-ID: <20241102152452.062ff2c4@jic23-huawei> (raw)
In-Reply-To: <20241102131311.36210-4-vassilisamir@gmail.com>

On Sat,  2 Nov 2024 14:13:07 +0100
Vasileios Amoiridis <vassilisamir@gmail.com> wrote:

> Add triggered buffer and soft timestamp support. The available scan mask
> enables all the channels of the sensor in order to follow the operation of
> the sensor. The sensor basically starts to capture from all channels
> as long as it enters into FORCED mode.
> 
> The bulk read, reads a total of 15 registers from the sensor, 0x1D..0x2B.
> Even though some of those registers are not reported in the register map
> of the device, this is how the BME680 Sensor API [1] proposes to do it.
> This allows to have one bulk read instead of multiple ones.
> 
> Link: https://github.com/boschsensortec/BME68x_SensorAPI/blob/v4.4.8/bme68x.c#L1200
> Signed-off-by: Vasileios Amoiridis <vassilisamir@gmail.com>
Applied with a couple of (to me) superfluous comments dropped.
> +static irqreturn_t bme680_trigger_handler(int irq, void *p)
> +{
> +	struct iio_poll_func *pf = p;
> +	struct iio_dev *indio_dev = pf->indio_dev;
> +	struct bme680_data *data = iio_priv(indio_dev);
> +	struct device *dev = regmap_get_device(data->regmap);
> +	u32 adc_temp, adc_press, adc_humid;
> +	u16 adc_gas_res, gas_regs_val;
> +	u8 gas_range;
> +	s32 t_fine;
> +	int ret;
> +
> +	guard(mutex)(&data->lock);
> +
> +	ret = bme680_set_mode(data, BME680_MODE_FORCED);
> +	if (ret < 0)
> +		goto out;
> +
> +	ret = bme680_wait_for_eoc(data);
> +	if (ret)
> +		goto out;
> +
> +	/* Burst read data regs */
This one dropped as kind of obvious from the code.
> +	ret = regmap_bulk_read(data->regmap, BME680_REG_MEAS_STAT_0,
> +			       data->buf, sizeof(data->buf));
> +	if (ret) {
> +		dev_err(dev, "failed to burst read sensor data\n");
> +		goto out;
> +	}
> +	if (data->buf[0] & BME680_GAS_MEAS_BIT) {
> +		dev_err(dev, "gas measurement incomplete\n");
> +		goto out;
> +	}
> +
> +	/* Temperature calculations */
> +	adc_temp = FIELD_GET(BME680_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[5]));
> +	if (adc_temp == BME680_MEAS_SKIPPED) {
> +		dev_err(dev, "reading temperature skipped\n");
> +		goto out;
> +	}
> +	data->scan.chan[0] = bme680_compensate_temp(data, adc_temp);
> +	t_fine = bme680_calc_t_fine(data, adc_temp);
> +
> +	/* Pressure calculations */
> +	adc_press = FIELD_GET(BME680_MEAS_TRIM_MASK, get_unaligned_be24(&data->buf[2]));
> +	if (adc_press == BME680_MEAS_SKIPPED) {
> +		dev_err(dev, "reading pressure skipped\n");
> +		goto out;
> +	}
> +	data->scan.chan[1] = bme680_compensate_press(data, adc_press, t_fine);
> +
> +	/* Humidity calculations */
> +	adc_humid = get_unaligned_be16(&data->buf[8]);
> +	if (adc_humid == BME680_MEAS_SKIPPED) {
> +		dev_err(dev, "reading humidity skipped\n");
> +		goto out;
> +	}
> +	data->scan.chan[2] = bme680_compensate_humid(data, adc_humid, t_fine);
> +
> +	/* Gas calculations */
> +	gas_regs_val = get_unaligned_be16(&data->buf[13]);
> +	adc_gas_res = FIELD_GET(BME680_ADC_GAS_RES, gas_regs_val);
> +	if ((gas_regs_val & BME680_GAS_STAB_BIT) == 0) {
> +		dev_err(dev, "heater failed to reach the target temperature\n");
> +		goto out;
> +	}
> +	gas_range = FIELD_GET(BME680_GAS_RANGE_MASK, gas_regs_val);
> +	data->scan.chan[3] = bme680_compensate_gas(data, adc_gas_res, gas_range);
> +
> +	/* Push to buffer */
This one is extremely obvious so dropped.

> +	iio_push_to_buffers_with_timestamp(indio_dev, &data->scan,
> +					   iio_get_time_ns(indio_dev));
> +out:
> +	iio_trigger_notify_done(indio_dev->trig);
> +	return IRQ_HANDLED;
> +}
> +

  reply	other threads:[~2024-11-02 15:25 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-02 13:13 [PATCH v3 0/7]: iio: chemical: bme680: 2nd round of cleanup Vasileios Amoiridis
2024-11-02 13:13 ` [PATCH v3 1/7] iio: chemical: bme680: refactorize set_mode() mode Vasileios Amoiridis
2024-11-02 15:21   ` Jonathan Cameron
2024-11-02 13:13 ` [PATCH v3 2/7] iio: chemical: bme680: Add SCALE and RAW channels Vasileios Amoiridis
2024-11-02 15:21   ` Jonathan Cameron
2024-11-02 13:13 ` [PATCH v3 3/7] iio: chemical: bme680: Add triggered buffer support Vasileios Amoiridis
2024-11-02 15:24   ` Jonathan Cameron [this message]
2024-11-02 13:13 ` [PATCH v3 4/7] iio: chemical: bme680: Add support for preheat current Vasileios Amoiridis
2024-11-02 15:26   ` Jonathan Cameron
2024-11-02 13:13 ` [PATCH v3 5/7] dt-bindings: iio: bosch,bme680: Add supply properties Vasileios Amoiridis
2024-11-02 15:33   ` Jonathan Cameron
2024-11-03  9:46     ` Krzysztof Kozlowski
2024-11-04 16:10       ` Rob Herring
2024-11-11 18:48         ` Vasileios Amoiridis
2024-11-19 14:04           ` Rob Herring
2024-11-02 13:13 ` [PATCH v3 6/7] iio: chemical: bme680: add regulators Vasileios Amoiridis
2024-11-02 13:13 ` [PATCH v3 7/7] iio: chemical: bme680: add power management Vasileios Amoiridis
2024-11-02 15:35   ` Jonathan Cameron
2024-11-03 14:57     ` 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=20241102152452.062ff2c4@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=anshulusr@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gustavograzs@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@kernel.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