From: Nuno Sa <nuno.sa@analog.com>
To: <linux-iio@vger.kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
Jonathan Cameron <jic23@kernel.org>
Subject: [PATCH 1/9] iio: imu: adis_buffer: split trigger handling
Date: Tue, 18 Jun 2024 15:32:04 +0200 [thread overview]
Message-ID: <20240618-dev-iio-adis-cleanup-v1-1-bd93ce7845c7@analog.com> (raw)
In-Reply-To: <20240618-dev-iio-adis-cleanup-v1-0-bd93ce7845c7@analog.com>
Split trigger handling for devices that have paging and need to
select the correct page to get the data. Although this actually
introduces more LOC, it makes the code and the locking clear. It will
also make the following move to the cleanup magic cleaner.
Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
drivers/iio/imu/adis_buffer.c | 56 ++++++++++++++++++++++++-------------------
1 file changed, 31 insertions(+), 25 deletions(-)
diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c
index 871b78b225e2..d1d1e4f512b9 100644
--- a/drivers/iio/imu/adis_buffer.c
+++ b/drivers/iio/imu/adis_buffer.c
@@ -126,6 +126,30 @@ int adis_update_scan_mode(struct iio_dev *indio_dev,
}
EXPORT_SYMBOL_NS_GPL(adis_update_scan_mode, IIO_ADISLIB);
+static int adis_paging_trigger_handler(struct adis *adis)
+{
+ int ret;
+
+ mutex_lock(&adis->state_lock);
+ if (adis->current_page != 0) {
+ adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID);
+ adis->tx[1] = 0;
+ ret = spi_write(adis->spi, adis->tx, 2);
+ if (ret) {
+ dev_err(&adis->spi->dev, "Failed to change device page: %d\n", ret);
+ mutex_unlock(&adis->state_lock);
+ return ret;
+ }
+
+ adis->current_page = 0;
+ }
+
+ ret = spi_sync(adis->spi, &adis->msg);
+ mutex_unlock(&adis->state_lock);
+
+ return ret;
+}
+
static irqreturn_t adis_trigger_handler(int irq, void *p)
{
struct iio_poll_func *pf = p;
@@ -133,34 +157,16 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
struct adis *adis = iio_device_get_drvdata(indio_dev);
int ret;
- if (adis->data->has_paging) {
- mutex_lock(&adis->state_lock);
- if (adis->current_page != 0) {
- adis->tx[0] = ADIS_WRITE_REG(ADIS_REG_PAGE_ID);
- adis->tx[1] = 0;
- ret = spi_write(adis->spi, adis->tx, 2);
- if (ret) {
- dev_err(&adis->spi->dev, "Failed to change device page: %d\n", ret);
- mutex_unlock(&adis->state_lock);
- goto irq_done;
- }
-
- adis->current_page = 0;
- }
- }
-
- ret = spi_sync(adis->spi, &adis->msg);
if (adis->data->has_paging)
- mutex_unlock(&adis->state_lock);
- if (ret) {
+ ret = adis_paging_trigger_handler(adis);
+ else
+ ret = spi_sync(adis->spi, &adis->msg);
+ if (ret)
dev_err(&adis->spi->dev, "Failed to read data: %d", ret);
- goto irq_done;
- }
+ else
+ iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer,
+ pf->timestamp);
- iio_push_to_buffers_with_timestamp(indio_dev, adis->buffer,
- pf->timestamp);
-
-irq_done:
iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED;
--
2.45.2
next prev parent reply other threads:[~2024-06-18 13:28 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-18 13:32 [PATCH 0/9] iio: imu: adis: make use the cleanup.h magic Nuno Sa
2024-06-18 13:32 ` Nuno Sa [this message]
2024-06-23 16:03 ` [PATCH 1/9] iio: imu: adis_buffer: split trigger handling Jonathan Cameron
2024-06-23 16:15 ` Jonathan Cameron
2024-06-18 13:32 ` [PATCH 2/9] iio: imu: adis: move to the cleanup magic Nuno Sa
2024-06-18 13:32 ` [PATCH 3/9] iio: imu: adis: add cleanup based lock helpers Nuno Sa
2024-06-18 13:32 ` [PATCH 4/9] iio: gyro: adis16260: make use of the new " Nuno Sa
2024-06-18 13:32 ` [PATCH 5/9] " Nuno Sa
2024-06-18 13:32 ` [PATCH 6/9] iio: imu: adis16400: " Nuno Sa
2024-06-18 13:32 ` [PATCH 7/9] iio: imu: adis16480: " Nuno Sa
2024-06-18 13:32 ` [PATCH 8/9] iio: imu: adis16475: " Nuno Sa
2024-06-23 16:16 ` Jonathan Cameron
2024-06-18 13:32 ` [PATCH 9/9] iio: imu: adis: remove legacy " Nuno Sa
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=20240618-dev-iio-adis-cleanup-v1-1-bd93ce7845c7@analog.com \
--to=nuno.sa@analog.com \
--cc=Michael.Hennerich@analog.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).