Skip to content

Commit

Permalink
iio: imu: st_lsm6dsx: fix edge-trigger interrupts
Browse files Browse the repository at this point in the history
commit 3f9bce7 upstream.

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: 89ca88a ("iio: imu: st_lsm6dsx: support active-low interrupts")
Fixes: 290a6ce ("iio: imu: add support to lsm6dsx driver")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Link: https://lore.kernel.org/r/5e93cda7dc1e665f5685c53ad8e9ea71dbae782d.1605378871.git.lorenzo@kernel.org
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
LorenzoBianconi authored and gregkh committed Dec 30, 2020
1 parent 160ec8a commit 6e94b83
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
Expand Up @@ -2255,19 +2255,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)
Expand Down

0 comments on commit 6e94b83

Please sign in to comment.