From: "Nuno Sá" <nuno.sa@analog.com>
To: <linux-iio@vger.kernel.org>, <devicetree@vger.kernel.org>
Cc: Jonathan Cameron <jic23@kernel.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexandru Ardelean <alexandru.Ardelean@analog.com>,
Michael Hennerich <Michael.Hennerich@analog.com>
Subject: [PATCH v5 2/6] iio: imu: adis: Add irq flag variable
Date: Mon, 13 Apr 2020 10:24:41 +0200 [thread overview]
Message-ID: <20200413082445.17324-3-nuno.sa@analog.com> (raw)
In-Reply-To: <20200413082445.17324-1-nuno.sa@analog.com>
There are some ADIS devices that can configure the data ready pin
polarity. Hence, we cannot hardcode our IRQ mask as IRQF_TRIGGER_RISING
since we might want to have it as IRQF_TRIGGER_FALLING.
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
---
Changes in v2:
* Add kernel doc-string for `irq-mask`.
Changes in v3:
* Removed unnecessary inline;
* Renamed `__adis_validate_irq_mask` to `adis_validate_irq_mask` to keep lib consistency;
* Cosmetics in logs.
Changes in v4:
* Use flag suffix instead of mask;
* Add comments to `adis_validate_irq_flag`.
Changes in v5:
* Change commit subject to irq flag instead of mask.
drivers/iio/imu/adis_trigger.c | 33 +++++++++++++++++++++++++++++++--
include/linux/iio/imu/adis.h | 2 ++
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/imu/adis_trigger.c b/drivers/iio/imu/adis_trigger.c
index a36810e0b1ab..8afe71947c00 100644
--- a/drivers/iio/imu/adis_trigger.c
+++ b/drivers/iio/imu/adis_trigger.c
@@ -34,6 +34,27 @@ static void adis_trigger_setup(struct adis *adis)
iio_trigger_set_drvdata(adis->trig, adis);
}
+static int adis_validate_irq_flag(struct adis *adis)
+{
+ /*
+ * Typically this devices have data ready either on the rising edge or
+ * on the falling edge of the data ready pin. This checks enforces that
+ * one of those is set in the drivers... It defaults to
+ * IRQF_TRIGGER_RISING for backward compatibility wiht devices that
+ * don't support changing the pin polarity.
+ */
+ if (!adis->irq_flag) {
+ adis->irq_flag = IRQF_TRIGGER_RISING;
+ return 0;
+ } else if (adis->irq_flag != IRQF_TRIGGER_RISING &&
+ adis->irq_flag != IRQF_TRIGGER_FALLING) {
+ dev_err(&adis->spi->dev, "Invalid IRQ mask: %08lx\n",
+ adis->irq_flag);
+ return -EINVAL;
+ }
+
+ return 0;
+}
/**
* adis_probe_trigger() - Sets up trigger for a adis device
* @adis: The adis device
@@ -54,9 +75,13 @@ int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
adis_trigger_setup(adis);
+ ret = adis_validate_irq_flag(adis);
+ if (ret)
+ return ret;
+
ret = request_irq(adis->spi->irq,
&iio_trigger_generic_data_rdy_poll,
- IRQF_TRIGGER_RISING,
+ adis->irq_flag,
indio_dev->name,
adis->trig);
if (ret)
@@ -96,9 +121,13 @@ int devm_adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
adis_trigger_setup(adis);
+ ret = adis_validate_irq_flag(adis);
+ if (ret)
+ return ret;
+
ret = devm_request_irq(&adis->spi->dev, adis->spi->irq,
&iio_trigger_generic_data_rdy_poll,
- IRQF_TRIGGER_RISING,
+ adis->irq_flag,
indio_dev->name,
adis->trig);
if (ret)
diff --git a/include/linux/iio/imu/adis.h b/include/linux/iio/imu/adis.h
index e70814d96e1c..70e4d1d262f5 100644
--- a/include/linux/iio/imu/adis.h
+++ b/include/linux/iio/imu/adis.h
@@ -87,6 +87,7 @@ struct adis_data {
* @msg: SPI message object
* @xfer: SPI transfer objects to be used for a @msg
* @current_page: Some ADIS devices have registers, this selects current page
+ * @irq_flag: IRQ handling flags as passed to request_irq()
* @buffer: Data buffer for information read from the device
* @tx: DMA safe TX buffer for SPI transfers
* @rx: DMA safe RX buffer for SPI transfers
@@ -113,6 +114,7 @@ struct adis {
struct spi_message msg;
struct spi_transfer *xfer;
unsigned int current_page;
+ unsigned long irq_flag;
void *buffer;
uint8_t tx[10] ____cacheline_aligned;
--
2.17.1
next prev parent reply other threads:[~2020-04-13 8:36 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-13 8:24 [PATCH v5 0/6] Support ADIS16475 and similar IMUs Nuno Sá
2020-04-13 8:24 ` [PATCH v5 1/6] iio: imu: adis: Add Managed device functions Nuno Sá
2020-04-13 8:24 ` Nuno Sá [this message]
2020-04-13 8:24 ` [PATCH v5 3/6] iio: adis: Add adis_update_bits() APIs Nuno Sá
2020-04-13 8:24 ` [PATCH v5 4/6] iio: adis: Support different burst sizes Nuno Sá
2020-04-13 8:24 ` [PATCH v5 5/6] iio: imu: Add support for adis16475 Nuno Sá
2020-04-27 18:06 ` Lars-Peter Clausen
2020-05-02 17:40 ` Jonathan Cameron
2020-05-02 18:01 ` Lars-Peter Clausen
2020-05-02 19:52 ` Nuno Sá
2020-05-03 8:47 ` Jonathan Cameron
2020-05-03 9:07 ` Lars-Peter Clausen
2020-05-03 9:12 ` Lars-Peter Clausen
2020-05-17 16:15 ` Jonathan Cameron
2020-05-17 19:07 ` Lars-Peter Clausen
2020-05-18 16:29 ` Jonathan Cameron
2020-05-03 11:07 ` Nuno Sá
2020-05-03 11:29 ` Jonathan Cameron
2020-05-03 17:19 ` Jonathan Cameron
2020-05-03 17:55 ` Nuno Sá
2020-04-13 8:24 ` [PATCH v5 6/6] dt-bindings: iio: Add adis16475 documentation Nuno Sá
2020-04-20 19:17 ` Rob Herring
2020-04-13 16:27 ` [PATCH v5 0/6] Support ADIS16475 and similar IMUs Jonathan Cameron
2020-04-25 15:18 ` 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=20200413082445.17324-3-nuno.sa@analog.com \
--to=nuno.sa@analog.com \
--cc=Michael.Hennerich@analog.com \
--cc=alexandru.Ardelean@analog.com \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=pmeerw@pmeerw.net \
--cc=robh+dt@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).