2020-01-06 11:00:02

by Alexandru Tachici

[permalink] [raw]
Subject: [PATCH] iio: ad_sigma_delta: Add custom irq flags

The data-sheet of AD7124, from the Sigma-Delta ADC family,
recommends that the falling edge of the DOUT line should be used for
an interrupt.

The ad_sigma_delta implementation hardcodes the irq trigger type
to low, assuming that all Sigma-Delta ADCs have the same interrupt-type.
This causes unwanted behaviour. If DOUT line is already low, the
interrupt will fire once, when enabled and the irq handler will send a
read request to the device. At this time the device has not yet finished
the previous conversion and will give a bad reading.

This patch allows drivers using the ad_sigma_delta layer to set the
irq trigger type to the one specified in the corresponding data-sheet.

Signed-off-by: Alexandru Tachici <[email protected]>
---
drivers/iio/adc/ad_sigma_delta.c | 9 ++++++++-
include/linux/iio/adc/ad_sigma_delta.h | 2 ++
2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index d10bd0c97233..0007df8d50fb 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -454,7 +454,7 @@ static int ad_sd_probe_trigger(struct iio_dev *indio_dev)

ret = request_irq(sigma_delta->spi->irq,
ad_sd_data_rdy_trig_poll,
- IRQF_TRIGGER_LOW,
+ sigma_delta->irq_flags,
indio_dev->name,
sigma_delta);
if (ret)
@@ -540,8 +540,15 @@ EXPORT_SYMBOL_GPL(ad_sd_cleanup_buffer_and_trigger);
int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev,
struct spi_device *spi, const struct ad_sigma_delta_info *info)
{
+ unsigned long set_trigger_flags;
+
sigma_delta->spi = spi;
sigma_delta->info = info;
+
+ set_trigger_flags = sigma_delta->irq_flags & IRQF_TRIGGER_MASK;
+ if (set_trigger_flags == IRQF_TRIGGER_NONE)
+ sigma_delta->irq_flags |= IRQF_TRIGGER_LOW;
+
iio_device_set_drvdata(indio_dev, sigma_delta);

return 0;
diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
index 5ba430cc9a87..94a91731c8e8 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -53,6 +53,7 @@ struct ad_sigma_delta_info {
* struct ad_sigma_delta - Sigma Delta device struct
* @spi: The spi device associated with the Sigma Delta device.
* @trig: The IIO trigger associated with the Sigma Delta device.
+ * @irq_flags: flags for the interrupt used by the triggered buffer
*
* Most of the fields are private to the sigma delta library code and should not
* be accessed by individual drivers.
@@ -60,6 +61,7 @@ struct ad_sigma_delta_info {
struct ad_sigma_delta {
struct spi_device *spi;
struct iio_trigger *trig;
+ unsigned long irq_flags;

/* private: */
struct completion completion;
--
2.20.1


2020-01-07 08:42:47

by Alexandru Tachici

[permalink] [raw]
Subject: Re: [PATCH] iio: ad_sigma_delta: Add custom irq flags

On Mon, 2020-01-06 at 12:57 +0200, Alexandru Tachici wrote:
> The data-sheet of AD7124, from the Sigma-Delta ADC family,
> recommends that the falling edge of the DOUT line should be used for
> an interrupt.
>
> The ad_sigma_delta implementation hardcodes the irq trigger type
> to low, assuming that all Sigma-Delta ADCs have the same interrupt-
> type.
> This causes unwanted behaviour. If DOUT line is already low, the
> interrupt will fire once, when enabled and the irq handler will send
> a
> read request to the device. At this time the device has not yet
> finished
> the previous conversion and will give a bad reading.
>
> This patch allows drivers using the ad_sigma_delta layer to set the
> irq trigger type to the one specified in the corresponding data-
> sheet.
>

Please disregard this will send a propper V2.

> Signed-off-by: Alexandru Tachici <[email protected]>
> ---
> drivers/iio/adc/ad_sigma_delta.c | 9 ++++++++-
> include/linux/iio/adc/ad_sigma_delta.h | 2 ++
> 2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/ad_sigma_delta.c
> b/drivers/iio/adc/ad_sigma_delta.c
> index d10bd0c97233..0007df8d50fb 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -454,7 +454,7 @@ static int ad_sd_probe_trigger(struct iio_dev
> *indio_dev)
>
> ret = request_irq(sigma_delta->spi->irq,
> ad_sd_data_rdy_trig_poll,
> - IRQF_TRIGGER_LOW,
> + sigma_delta->irq_flags,
> indio_dev->name,
> sigma_delta);
> if (ret)
> @@ -540,8 +540,15 @@
> EXPORT_SYMBOL_GPL(ad_sd_cleanup_buffer_and_trigger);
> int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev
> *indio_dev,
> struct spi_device *spi, const struct ad_sigma_delta_info *info)
> {
> + unsigned long set_trigger_flags;
> +
> sigma_delta->spi = spi;
> sigma_delta->info = info;
> +
> + set_trigger_flags = sigma_delta->irq_flags & IRQF_TRIGGER_MASK;
> + if (set_trigger_flags == IRQF_TRIGGER_NONE)
> + sigma_delta->irq_flags |= IRQF_TRIGGER_LOW;
> +
> iio_device_set_drvdata(indio_dev, sigma_delta);
>
> return 0;
> diff --git a/include/linux/iio/adc/ad_sigma_delta.h
> b/include/linux/iio/adc/ad_sigma_delta.h
> index 5ba430cc9a87..94a91731c8e8 100644
> --- a/include/linux/iio/adc/ad_sigma_delta.h
> +++ b/include/linux/iio/adc/ad_sigma_delta.h
> @@ -53,6 +53,7 @@ struct ad_sigma_delta_info {
> * struct ad_sigma_delta - Sigma Delta device struct
> * @spi: The spi device associated with the Sigma Delta device.
> * @trig: The IIO trigger associated with the Sigma Delta device.
> + * @irq_flags: flags for the interrupt used by the triggered buffer
> *
> * Most of the fields are private to the sigma delta library code
> and should not
> * be accessed by individual drivers.
> @@ -60,6 +61,7 @@ struct ad_sigma_delta_info {
> struct ad_sigma_delta {
> struct spi_device *spi;
> struct iio_trigger *trig;
> + unsigned long irq_flags;
>
> /* private: */
> struct completion completion;

2020-01-07 11:07:50

by Alexandru Tachici

[permalink] [raw]
Subject: [PATCH V2] iio: ad_sigma_delta: Add custom irq flags

The data-sheet of AD7124, from the Sigma-Delta ADC family,
recommends that the falling edge of the DOUT line should be used for
an interrupt.

The ad_sigma_delta implementation hardcodes the irq trigger type
to low, assuming that all Sigma-Delta ADCs have the same interrupt-type.
This causes unwanted behaviour. If DOUT line is already low, the
interrupt will fire once, when enabled and the irq handler will send a
read request to the device. At this time the device has not yet finished
the previous conversion and will give a bad reading.

This patch allows drivers using the ad_sigma_delta layer to set the
irq trigger type to the one specified in the corresponding data-sheet.

Signed-off-by: Alexandru Tachici <[email protected]>
---
Changelog V1-V2:
- added a V2 tag

drivers/iio/adc/ad_sigma_delta.c | 9 ++++++++-
include/linux/iio/adc/ad_sigma_delta.h | 2 ++
2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index d10bd0c97233..0007df8d50fb 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -454,7 +454,7 @@ static int ad_sd_probe_trigger(struct iio_dev *indio_dev)

ret = request_irq(sigma_delta->spi->irq,
ad_sd_data_rdy_trig_poll,
- IRQF_TRIGGER_LOW,
+ sigma_delta->irq_flags,
indio_dev->name,
sigma_delta);
if (ret)
@@ -540,8 +540,15 @@ EXPORT_SYMBOL_GPL(ad_sd_cleanup_buffer_and_trigger);
int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev,
struct spi_device *spi, const struct ad_sigma_delta_info *info)
{
+ unsigned long set_trigger_flags;
+
sigma_delta->spi = spi;
sigma_delta->info = info;
+
+ set_trigger_flags = sigma_delta->irq_flags & IRQF_TRIGGER_MASK;
+ if (set_trigger_flags == IRQF_TRIGGER_NONE)
+ sigma_delta->irq_flags |= IRQF_TRIGGER_LOW;
+
iio_device_set_drvdata(indio_dev, sigma_delta);

return 0;
diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
index 5ba430cc9a87..94a91731c8e8 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -53,6 +53,7 @@ struct ad_sigma_delta_info {
* struct ad_sigma_delta - Sigma Delta device struct
* @spi: The spi device associated with the Sigma Delta device.
* @trig: The IIO trigger associated with the Sigma Delta device.
+ * @irq_flags: flags for the interrupt used by the triggered buffer
*
* Most of the fields are private to the sigma delta library code and should not
* be accessed by individual drivers.
@@ -60,6 +61,7 @@ struct ad_sigma_delta_info {
struct ad_sigma_delta {
struct spi_device *spi;
struct iio_trigger *trig;
+ unsigned long irq_flags;

/* private: */
struct completion completion;
--
2.20.1

2020-01-11 11:24:36

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH V2] iio: ad_sigma_delta: Add custom irq flags

On Tue, 7 Jan 2020 13:06:36 +0200
Alexandru Tachici <[email protected]> wrote:

> The data-sheet of AD7124, from the Sigma-Delta ADC family,
> recommends that the falling edge of the DOUT line should be used for
> an interrupt.
>
> The ad_sigma_delta implementation hardcodes the irq trigger type
> to low, assuming that all Sigma-Delta ADCs have the same interrupt-type.
> This causes unwanted behaviour. If DOUT line is already low, the
> interrupt will fire once, when enabled and the irq handler will send a
> read request to the device. At this time the device has not yet finished
> the previous conversion and will give a bad reading.
>
> This patch allows drivers using the ad_sigma_delta layer to set the
> irq trigger type to the one specified in the corresponding data-sheet.
>
> Signed-off-by: Alexandru Tachici <[email protected]>

Hi Alexandru.

Patch is fine, but I'd expect to see it in a series with the change
for the ad7124 driver. I'm never keen to merge new features without
a user. So send a v3, with the change to that driver (which I'm guessing
is pretty trivial!)

Thanks,

Jonathan

> ---
> Changelog V1-V2:
> - added a V2 tag
>
> drivers/iio/adc/ad_sigma_delta.c | 9 ++++++++-
> include/linux/iio/adc/ad_sigma_delta.h | 2 ++
> 2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index d10bd0c97233..0007df8d50fb 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -454,7 +454,7 @@ static int ad_sd_probe_trigger(struct iio_dev *indio_dev)
>
> ret = request_irq(sigma_delta->spi->irq,
> ad_sd_data_rdy_trig_poll,
> - IRQF_TRIGGER_LOW,
> + sigma_delta->irq_flags,
> indio_dev->name,
> sigma_delta);
> if (ret)
> @@ -540,8 +540,15 @@ EXPORT_SYMBOL_GPL(ad_sd_cleanup_buffer_and_trigger);
> int ad_sd_init(struct ad_sigma_delta *sigma_delta, struct iio_dev *indio_dev,
> struct spi_device *spi, const struct ad_sigma_delta_info *info)
> {
> + unsigned long set_trigger_flags;
> +
> sigma_delta->spi = spi;
> sigma_delta->info = info;
> +
> + set_trigger_flags = sigma_delta->irq_flags & IRQF_TRIGGER_MASK;
> + if (set_trigger_flags == IRQF_TRIGGER_NONE)
> + sigma_delta->irq_flags |= IRQF_TRIGGER_LOW;
> +
> iio_device_set_drvdata(indio_dev, sigma_delta);
>
> return 0;
> diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
> index 5ba430cc9a87..94a91731c8e8 100644
> --- a/include/linux/iio/adc/ad_sigma_delta.h
> +++ b/include/linux/iio/adc/ad_sigma_delta.h
> @@ -53,6 +53,7 @@ struct ad_sigma_delta_info {
> * struct ad_sigma_delta - Sigma Delta device struct
> * @spi: The spi device associated with the Sigma Delta device.
> * @trig: The IIO trigger associated with the Sigma Delta device.
> + * @irq_flags: flags for the interrupt used by the triggered buffer
> *
> * Most of the fields are private to the sigma delta library code and should not
> * be accessed by individual drivers.
> @@ -60,6 +61,7 @@ struct ad_sigma_delta_info {
> struct ad_sigma_delta {
> struct spi_device *spi;
> struct iio_trigger *trig;
> + unsigned long irq_flags;
>
> /* private: */
> struct completion completion;

2020-01-13 10:28:30

by Alexandru Tachici

[permalink] [raw]
Subject: [PATCH 0/2 V3] iio: adc: ad7124 fix wrong irq flag

Before these patches the ad7124 driver used a wrong irq flag
because it is using the ad-sigma-delta layer which hardcoded
the used irq flag. This caused an early read of the
data register when ad7124 was set on continous mode giving
a bad conversion.

This V3 series fixes the above explained unwanted behaviour.

1. Allow drivers to set their own irq flag for the iio
triggered buffer.

2. Set the right irq flag in the ad_sigma_delta_info
in ad7124 driver.

Alexandru Tachici (2):
iio: adc: ad-sigma-delta: Allow custom IRQ flags
iio: adc: ad7124: Set IRQ type to falling

drivers/iio/adc/ad7124.c | 2 ++
drivers/iio/adc/ad7780.c | 1 +
drivers/iio/adc/ad7791.c | 1 +
drivers/iio/adc/ad7793.c | 1 +
drivers/iio/adc/ad_sigma_delta.c | 2 +-
include/linux/iio/adc/ad_sigma_delta.h | 2 ++
6 files changed, 8 insertions(+), 1 deletion(-)

--
2.20.1

2020-01-13 10:28:32

by Alexandru Tachici

[permalink] [raw]
Subject: [PATCH 1/2 V3] iio: adc: ad-sigma-delta: Allow custom IRQ flags

Before this patch the ad_sigma_delta implementation hardcoded
the irq trigger type to low, assuming that all Sigma-Delta ADCs
have the same interrupt-type.

This patch allows all drivers using the ad_sigma_delta layer to set the
irq trigger type to the one specified in the datasheet.

Signed-off-by: Alexandru Tachici <[email protected]>
---
drivers/iio/adc/ad7124.c | 2 ++
drivers/iio/adc/ad7780.c | 1 +
drivers/iio/adc/ad7791.c | 1 +
drivers/iio/adc/ad7793.c | 1 +
drivers/iio/adc/ad_sigma_delta.c | 2 +-
include/linux/iio/adc/ad_sigma_delta.h | 2 ++
6 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index edc6f1cc90b2..9531d8a6cb27 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -9,6 +9,7 @@
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/err.h>
+#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/regulator/consumer.h>
@@ -222,6 +223,7 @@ static const struct ad_sigma_delta_info ad7124_sigma_delta_info = {
.addr_shift = 0,
.read_mask = BIT(6),
.data_reg = AD7124_DATA,
+ .irq_flags = IRQF_TRIGGER_LOW,
};

static int ad7124_set_channel_odr(struct ad7124_state *st,
diff --git a/drivers/iio/adc/ad7780.c b/drivers/iio/adc/ad7780.c
index 217a5a5c3c6d..291c1a898129 100644
--- a/drivers/iio/adc/ad7780.c
+++ b/drivers/iio/adc/ad7780.c
@@ -203,6 +203,7 @@ static const struct ad_sigma_delta_info ad7780_sigma_delta_info = {
.set_mode = ad7780_set_mode,
.postprocess_sample = ad7780_postprocess_sample,
.has_registers = false,
+ .irq_flags = IRQF_TRIGGER_LOW,
};

#define AD7780_CHANNEL(bits, wordsize) \
diff --git a/drivers/iio/adc/ad7791.c b/drivers/iio/adc/ad7791.c
index 54025ea10239..abb239392631 100644
--- a/drivers/iio/adc/ad7791.c
+++ b/drivers/iio/adc/ad7791.c
@@ -205,6 +205,7 @@ static const struct ad_sigma_delta_info ad7791_sigma_delta_info = {
.has_registers = true,
.addr_shift = 4,
.read_mask = BIT(3),
+ .irq_flags = IRQF_TRIGGER_LOW,
};

static int ad7791_read_raw(struct iio_dev *indio_dev,
diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
index bbc41ecf0d2f..b747db97f78a 100644
--- a/drivers/iio/adc/ad7793.c
+++ b/drivers/iio/adc/ad7793.c
@@ -206,6 +206,7 @@ static const struct ad_sigma_delta_info ad7793_sigma_delta_info = {
.has_registers = true,
.addr_shift = 3,
.read_mask = BIT(6),
+ .irq_flags = IRQF_TRIGGER_LOW,
};

static const struct ad_sd_calib_data ad7793_calib_arr[6] = {
diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
index 8ba90486c787..8115b6de1d6c 100644
--- a/drivers/iio/adc/ad_sigma_delta.c
+++ b/drivers/iio/adc/ad_sigma_delta.c
@@ -500,7 +500,7 @@ static int ad_sd_probe_trigger(struct iio_dev *indio_dev)

ret = request_irq(sigma_delta->spi->irq,
ad_sd_data_rdy_trig_poll,
- IRQF_TRIGGER_LOW,
+ sigma_delta->info->irq_flags,
indio_dev->name,
sigma_delta);
if (ret)
diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
index 8a4e25a7080c..5a127c0ed200 100644
--- a/include/linux/iio/adc/ad_sigma_delta.h
+++ b/include/linux/iio/adc/ad_sigma_delta.h
@@ -40,6 +40,7 @@ struct iio_dev;
* @read_mask: Mask for the communications register having the read bit set.
* @data_reg: Address of the data register, if 0 the default address of 0x3 will
* be used.
+ * @irq_flags: flags for the interrupt used by the triggered buffer
*/
struct ad_sigma_delta_info {
int (*set_channel)(struct ad_sigma_delta *, unsigned int channel);
@@ -49,6 +50,7 @@ struct ad_sigma_delta_info {
unsigned int addr_shift;
unsigned int read_mask;
unsigned int data_reg;
+ unsigned long irq_flags;
};

/**
--
2.20.1

2020-01-13 10:28:33

by Alexandru Tachici

[permalink] [raw]
Subject: [PATCH 2/2 V3] iio: adc: ad7124: Set IRQ type to falling

Ad7124 data-sheet specifies that the falling edge
of the DOUT line should be used for an interrupt.
The current irq flag (IRQF_TRIGGER_LOW) used will
cause unwanted behaviour. When enabling the interrupt
it will fire once because the DOUT line is already low.
This will make the driver to read an unfinished conversion
from the chip.

This patch sets the irq type to the one specified in
the data-sheet.

Signed-off-by: Alexandru Tachici <[email protected]>
---
drivers/iio/adc/ad7124.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index 9531d8a6cb27..9113f6d36ad4 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -223,7 +223,7 @@ static const struct ad_sigma_delta_info ad7124_sigma_delta_info = {
.addr_shift = 0,
.read_mask = BIT(6),
.data_reg = AD7124_DATA,
- .irq_flags = IRQF_TRIGGER_LOW,
+ .irq_flags = IRQF_TRIGGER_FALLING,
};

static int ad7124_set_channel_odr(struct ad7124_state *st,
--
2.20.1

2020-01-18 11:19:26

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 1/2 V3] iio: adc: ad-sigma-delta: Allow custom IRQ flags

On Mon, 13 Jan 2020 12:26:52 +0200
Alexandru Tachici <[email protected]> wrote:

> Before this patch the ad_sigma_delta implementation hardcoded
> the irq trigger type to low, assuming that all Sigma-Delta ADCs
> have the same interrupt-type.
>
> This patch allows all drivers using the ad_sigma_delta layer to set the
> irq trigger type to the one specified in the datasheet.
>
> Signed-off-by: Alexandru Tachici <[email protected]>

Now, as neither of these has a fixes tag, I've taken them in the
togreg branch of iio.git. If you want them backported to stable,
one they are in Linus's tree you can send a specific message to
request they are applied.

Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan

> ---
> drivers/iio/adc/ad7124.c | 2 ++
> drivers/iio/adc/ad7780.c | 1 +
> drivers/iio/adc/ad7791.c | 1 +
> drivers/iio/adc/ad7793.c | 1 +
> drivers/iio/adc/ad_sigma_delta.c | 2 +-
> include/linux/iio/adc/ad_sigma_delta.h | 2 ++
> 6 files changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
> index edc6f1cc90b2..9531d8a6cb27 100644
> --- a/drivers/iio/adc/ad7124.c
> +++ b/drivers/iio/adc/ad7124.c
> @@ -9,6 +9,7 @@
> #include <linux/delay.h>
> #include <linux/device.h>
> #include <linux/err.h>
> +#include <linux/interrupt.h>
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/regulator/consumer.h>
> @@ -222,6 +223,7 @@ static const struct ad_sigma_delta_info ad7124_sigma_delta_info = {
> .addr_shift = 0,
> .read_mask = BIT(6),
> .data_reg = AD7124_DATA,
> + .irq_flags = IRQF_TRIGGER_LOW,
> };
>
> static int ad7124_set_channel_odr(struct ad7124_state *st,
> diff --git a/drivers/iio/adc/ad7780.c b/drivers/iio/adc/ad7780.c
> index 217a5a5c3c6d..291c1a898129 100644
> --- a/drivers/iio/adc/ad7780.c
> +++ b/drivers/iio/adc/ad7780.c
> @@ -203,6 +203,7 @@ static const struct ad_sigma_delta_info ad7780_sigma_delta_info = {
> .set_mode = ad7780_set_mode,
> .postprocess_sample = ad7780_postprocess_sample,
> .has_registers = false,
> + .irq_flags = IRQF_TRIGGER_LOW,
> };
>
> #define AD7780_CHANNEL(bits, wordsize) \
> diff --git a/drivers/iio/adc/ad7791.c b/drivers/iio/adc/ad7791.c
> index 54025ea10239..abb239392631 100644
> --- a/drivers/iio/adc/ad7791.c
> +++ b/drivers/iio/adc/ad7791.c
> @@ -205,6 +205,7 @@ static const struct ad_sigma_delta_info ad7791_sigma_delta_info = {
> .has_registers = true,
> .addr_shift = 4,
> .read_mask = BIT(3),
> + .irq_flags = IRQF_TRIGGER_LOW,
> };
>
> static int ad7791_read_raw(struct iio_dev *indio_dev,
> diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
> index bbc41ecf0d2f..b747db97f78a 100644
> --- a/drivers/iio/adc/ad7793.c
> +++ b/drivers/iio/adc/ad7793.c
> @@ -206,6 +206,7 @@ static const struct ad_sigma_delta_info ad7793_sigma_delta_info = {
> .has_registers = true,
> .addr_shift = 3,
> .read_mask = BIT(6),
> + .irq_flags = IRQF_TRIGGER_LOW,
> };
>
> static const struct ad_sd_calib_data ad7793_calib_arr[6] = {
> diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
> index 8ba90486c787..8115b6de1d6c 100644
> --- a/drivers/iio/adc/ad_sigma_delta.c
> +++ b/drivers/iio/adc/ad_sigma_delta.c
> @@ -500,7 +500,7 @@ static int ad_sd_probe_trigger(struct iio_dev *indio_dev)
>
> ret = request_irq(sigma_delta->spi->irq,
> ad_sd_data_rdy_trig_poll,
> - IRQF_TRIGGER_LOW,
> + sigma_delta->info->irq_flags,
> indio_dev->name,
> sigma_delta);
> if (ret)
> diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
> index 8a4e25a7080c..5a127c0ed200 100644
> --- a/include/linux/iio/adc/ad_sigma_delta.h
> +++ b/include/linux/iio/adc/ad_sigma_delta.h
> @@ -40,6 +40,7 @@ struct iio_dev;
> * @read_mask: Mask for the communications register having the read bit set.
> * @data_reg: Address of the data register, if 0 the default address of 0x3 will
> * be used.
> + * @irq_flags: flags for the interrupt used by the triggered buffer
> */
> struct ad_sigma_delta_info {
> int (*set_channel)(struct ad_sigma_delta *, unsigned int channel);
> @@ -49,6 +50,7 @@ struct ad_sigma_delta_info {
> unsigned int addr_shift;
> unsigned int read_mask;
> unsigned int data_reg;
> + unsigned long irq_flags;
> };
>
> /**

2020-01-18 11:21:18

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 2/2 V3] iio: adc: ad7124: Set IRQ type to falling

On Mon, 13 Jan 2020 12:26:53 +0200
Alexandru Tachici <[email protected]> wrote:

> Ad7124 data-sheet specifies that the falling edge
> of the DOUT line should be used for an interrupt.
> The current irq flag (IRQF_TRIGGER_LOW) used will
> cause unwanted behaviour. When enabling the interrupt
> it will fire once because the DOUT line is already low.
> This will make the driver to read an unfinished conversion
> from the chip.
>
> This patch sets the irq type to the one specified in
> the data-sheet.
>
> Signed-off-by: Alexandru Tachici <[email protected]>
Applied to the togreg branch of iio.git and pushed out as testing for the
autobuilders to play with it.

Thanks,

Jonathan

> ---
> drivers/iio/adc/ad7124.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
> index 9531d8a6cb27..9113f6d36ad4 100644
> --- a/drivers/iio/adc/ad7124.c
> +++ b/drivers/iio/adc/ad7124.c
> @@ -223,7 +223,7 @@ static const struct ad_sigma_delta_info ad7124_sigma_delta_info = {
> .addr_shift = 0,
> .read_mask = BIT(6),
> .data_reg = AD7124_DATA,
> - .irq_flags = IRQF_TRIGGER_LOW,
> + .irq_flags = IRQF_TRIGGER_FALLING,
> };
>
> static int ad7124_set_channel_odr(struct ad7124_state *st,