Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9097391pxu; Mon, 28 Dec 2020 06:34:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4PDxt2Rv6cZBG9U7RFnkcPkRYFa+KneR9dAkmf0jHYQuU4x8x7OCvhedggAdeNsmenhhn X-Received: by 2002:aa7:da8f:: with SMTP id q15mr42175605eds.239.1609166070287; Mon, 28 Dec 2020 06:34:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609166070; cv=none; d=google.com; s=arc-20160816; b=ntV+UtzWkXZq26FOLRYwm6OTBrsOdy1Lae4TliyjrmehLUKKHWDqjBB3SPuqB24BsP BoHu+9A9sCWH4sbFSZbwA7/Ok0a+JDckT+RDOUD9tpl32rMi1phrdIypBA/cIhj+z8VM bEcXbyRrdi3LldBMWCUOcDfEqaBLRJ8GYmUjZpKo0nVC/LO1I0/VwjBzrXpmHAzlPFoN gnNuhLqtD4F9Yug1emVkLQte8fgRfwbinNCvC3+Z5tkHdD7Eg8jghPxfBCV60XnKS9qp NJ9rkCwu68fVC5kgWSx7NyJ8QtHOmavERBG6drKjxLp9fnpLq6lbr2e7xAuxG3V4sFh1 LAow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qI/el50APEeRKOmDyOhHQoWO+Tm6em9ZV7/8+qwj0C8=; b=u0Lofk9QdBQ73sRYsVxXG+19kXpIYS+Z1GJXzPFZWe4Lqp2rL412gULgxOZI3vXglS 9paXACqSKuFsUn1qRFhdcM5lSScuTH48wfUG4wXyqLnlPQAtpbDw6BJs5k8ZG133lWk5 oNj70LnEmR1WhZUA+mQbcPhmi1IR0ORN+3I1KJuhhDJK97kcvdaar0PPHtQhL7jmblL3 v/+jJxzi9Bapl8jFYDgQ8ui4a8MN/EiiNKaA+g4xRvirndtYanh9K3egOWWMfUStGvl8 ePIYFUlOF+qeL0WnOYBln/+OdQspl7FhyhLK5cbOnVF4lL8gckjcAD7dOHvrF/g5EGLx UK9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qYbNfi9n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y13si18678685ejw.564.2020.12.28.06.34.07; Mon, 28 Dec 2020 06:34:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qYbNfi9n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2504647AbgL1OcW (ORCPT + 99 others); Mon, 28 Dec 2020 09:32:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:38964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2504401AbgL1ObY (ORCPT ); Mon, 28 Dec 2020 09:31:24 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A24ED207B2; Mon, 28 Dec 2020 14:31:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165869; bh=W7pSCyKOlJXrAxmKWRx59qwpgcKSPHu8XN2FiSUblOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qYbNfi9nuik6GZ5HXiwI1QN3TnDFP7046TdSWH5NnNXsXy8Pfyn/xM/7HE42ayuP+ t80F5I89mCR5Uh4GUAvQFZ4/q5uA/t4VeeAFBi6g7IBRVrPE2d/n+UFHMlFoNNotEE jULyiS/AmaG4xV3xf/F6JAikMKWAZ3TBYwFzZTp0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lorenzo Bianconi , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 5.10 676/717] iio: imu: st_lsm6dsx: fix edge-trigger interrupts Date: Mon, 28 Dec 2020 13:51:14 +0100 Message-Id: <20201228125053.370159550@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lorenzo Bianconi commit 3f9bce7a22a3f8ac9d885c9d75bc45569f24ac8b 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: 89ca88a7cdf2 ("iio: imu: st_lsm6dsx: support active-low interrupts") Fixes: 290a6ce11d93 ("iio: imu: add support to lsm6dsx driver") Signed-off-by: Lorenzo Bianconi Link: https://lore.kernel.org/r/5e93cda7dc1e665f5685c53ad8e9ea71dbae782d.1605378871.git.lorenzo@kernel.org Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c @@ -2255,19 +2255,35 @@ st_lsm6dsx_report_motion_event(struct st 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); - return count || event ? IRQ_HANDLED : IRQ_NONE; + if (len > 0) + fifo_len += len; + } while (len > 0); + + return fifo_len || event ? IRQ_HANDLED : IRQ_NONE; } static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)