From: Antoni Pokusinski Date: Thu, 2 Oct 2025 20:02:03 +0000 (+0200) Subject: iio: mpl3115: add separate function for triggered buffer data collection X-Git-Tag: v6.19-rc1~65^2~58^2~126 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f692f0bfdf471b6afad0aa759ce215cb087c9b81;p=thirdparty%2Flinux.git iio: mpl3115: add separate function for triggered buffer data collection Factor out the code responsible for collecting data for the triggered buffer from the trigger handler into a separate function. Signed-off-by: Antoni Pokusinski Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c index 579da60ef4414..1da78081ca7eb 100644 --- a/drivers/iio/pressure/mpl3115.c +++ b/drivers/iio/pressure/mpl3115.c @@ -148,47 +148,53 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev, return -EINVAL; } -static irqreturn_t mpl3115_trigger_handler(int irq, void *p) +static int mpl3115_fill_trig_buffer(struct iio_dev *indio_dev, u8 *buffer) { - struct iio_poll_func *pf = p; - struct iio_dev *indio_dev = pf->indio_dev; struct mpl3115_data *data = iio_priv(indio_dev); - /* - * 32-bit channel + 16-bit channel + padding + ts - * Note that it is possible for only one of the first 2 - * channels to be enabled. If that happens, the first element - * of the buffer may be either 16 or 32-bits. As such we cannot - * use a simple structure definition to express this data layout. - */ - u8 buffer[16] __aligned(8) = { }; int ret, pos = 0; - mutex_lock(&data->lock); ret = mpl3115_request(data); - if (ret < 0) { - mutex_unlock(&data->lock); - goto done; - } + if (ret < 0) + return ret; if (test_bit(0, indio_dev->active_scan_mask)) { ret = i2c_smbus_read_i2c_block_data(data->client, MPL3115_OUT_PRESS, 3, &buffer[pos]); - if (ret < 0) { - mutex_unlock(&data->lock); - goto done; - } + if (ret < 0) + return ret; pos += 4; } if (test_bit(1, indio_dev->active_scan_mask)) { ret = i2c_smbus_read_i2c_block_data(data->client, MPL3115_OUT_TEMP, 2, &buffer[pos]); - if (ret < 0) { - mutex_unlock(&data->lock); - goto done; - } + if (ret < 0) + return ret; } + + return 0; +} + +static irqreturn_t mpl3115_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct mpl3115_data *data = iio_priv(indio_dev); + /* + * 32-bit channel + 16-bit channel + padding + ts + * Note that it is possible for only one of the first 2 + * channels to be enabled. If that happens, the first element + * of the buffer may be either 16 or 32-bits. As such we cannot + * use a simple structure definition to express this data layout. + */ + u8 buffer[16] __aligned(8) = { }; + int ret; + + mutex_lock(&data->lock); + ret = mpl3115_fill_trig_buffer(indio_dev, buffer); mutex_unlock(&data->lock); + if (ret) + goto done; iio_push_to_buffers_with_ts(indio_dev, buffer, sizeof(buffer), iio_get_time_ns(indio_dev));