From: Jonathan Cameron <jic23@kernel.org>
To: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: lorenzo.bianconi@redhat.com, linux-iio@vger.kernel.org
Subject: Re: [PATCH v3] iio: imu: st_lsm6dsx: fix edge-trigger interrupts
Date: Sat, 21 Nov 2020 16:33:54 +0000 [thread overview]
Message-ID: <20201121163354.64af2edd@archlinux> (raw)
In-Reply-To: <5e93cda7dc1e665f5685c53ad8e9ea71dbae782d.1605378871.git.lorenzo@kernel.org>
On Sat, 14 Nov 2020 19:39:05 +0100
Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> If we are using edge IRQs, new samples can arrive while processing
> current interrupt since there are no hw guarantees the irq line
> stays "low" long enough to properly detect the new interrupt.
> In this case the new sample will be missed.
> Polling FIFO status register in st_lsm6dsx_handler_thread routine
> allow us to read new samples even if the interrupt arrives while
> processing previous data and the timeslot where the line is "low"
> is too short to be properly detected.
>
> Fixes: 89ca88a7cdf2 ("iio: imu: st_lsm6dsx: support active-low interrupts")
> Fixes: 290a6ce11d93 ("iio: imu: add support to lsm6dsx driver")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Applied to the fixes-togreg branch of iio.git and marked for stable.
Thanks,
Jonathan
> ---
> Changes since v2:
> - improve comments/commit log
>
> Changes since v1:
> - add missing fixes tags
> - keep IRQF_ONESHOT even for edge-interrupts
> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 26 ++++++++++++++++----
> 1 file changed, 21 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 5e584c6026f1..da91f5e7e86d 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -2460,19 +2460,35 @@ st_lsm6dsx_report_motion_event(struct st_lsm6dsx_hw *hw)
> static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
> {
> struct st_lsm6dsx_hw *hw = private;
> + int fifo_len = 0, len;
> bool event;
> - int count;
>
> event = st_lsm6dsx_report_motion_event(hw);
>
> if (!hw->settings->fifo_ops.read_fifo)
> return event ? IRQ_HANDLED : IRQ_NONE;
>
> - mutex_lock(&hw->fifo_lock);
> - count = hw->settings->fifo_ops.read_fifo(hw);
> - mutex_unlock(&hw->fifo_lock);
> + /*
> + * If we are using edge IRQs, new samples can arrive while
> + * processing current interrupt since there are no hw
> + * guarantees the irq line stays "low" long enough to properly
> + * detect the new interrupt. In this case the new sample will
> + * be missed.
> + * Polling FIFO status register allow us to read new
> + * samples even if the interrupt arrives while processing
> + * previous data and the timeslot where the line is "low" is
> + * too short to be properly detected.
> + */
> + do {
> + mutex_lock(&hw->fifo_lock);
> + len = hw->settings->fifo_ops.read_fifo(hw);
> + mutex_unlock(&hw->fifo_lock);
> +
> + if (len > 0)
> + fifo_len += len;
> + } while (len > 0);
>
> - return count || event ? IRQ_HANDLED : IRQ_NONE;
> + return fifo_len || event ? IRQ_HANDLED : IRQ_NONE;
> }
>
> static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
prev parent reply other threads:[~2020-11-21 16:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-14 18:39 [PATCH v3] iio: imu: st_lsm6dsx: fix edge-trigger interrupts Lorenzo Bianconi
2020-11-21 16:33 ` Jonathan Cameron [this message]
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=20201121163354.64af2edd@archlinux \
--to=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=lorenzo.bianconi@redhat.com \
--cc=lorenzo@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).