Return-Path: Received: from mail-dm3nam03on0096.outbound.protection.outlook.com ([104.47.41.96]:30671 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S966216AbeCSQI1 (ORCPT ); Mon, 19 Mar 2018 12:08:27 -0400 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Nikita Yushchenko , Jonathan Cameron , Sasha Levin Subject: [PATCH AUTOSEL for 4.4 056/167] iio: hi8435: avoid garbage event at first enable Date: Mon, 19 Mar 2018 16:06:30 +0000 Message-ID: <20180319160513.16384-56-alexander.levin@microsoft.com> References: <20180319160513.16384-1-alexander.levin@microsoft.com> In-Reply-To: <20180319160513.16384-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Nikita Yushchenko [ Upstream commit ee19ac340c5fdfd89c6348be4563453c61ab54a9 ] Currently, driver generates events for channels if new reading differs from previous one. This "previous value" is initialized to zero, which results into event if value is constant-one. Fix that by initializing "previous value" by reading at event enable time. This provides reliable sequence for userspace: - enable event, - AFTER THAT read current value, - AFTER THAT each event will correspond to change. Signed-off-by: Nikita Yushchenko Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- drivers/iio/adc/hi8435.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/hi8435.c b/drivers/iio/adc/hi8435.c index c73c6c62a6ac..ba9e8fc747b8 100644 --- a/drivers/iio/adc/hi8435.c +++ b/drivers/iio/adc/hi8435.c @@ -121,10 +121,21 @@ static int hi8435_write_event_config(struct iio_dev *= idev, enum iio_event_direction dir, int state) { struct hi8435_priv *priv =3D iio_priv(idev); + int ret; + u32 tmp; + + if (state) { + ret =3D hi8435_readl(priv, HI8435_SO31_0_REG, &tmp); + if (ret < 0) + return ret; + if (tmp & BIT(chan->channel)) + priv->event_prev_val |=3D BIT(chan->channel); + else + priv->event_prev_val &=3D ~BIT(chan->channel); =20 - priv->event_scan_mask &=3D ~BIT(chan->channel); - if (state) priv->event_scan_mask |=3D BIT(chan->channel); + } else + priv->event_scan_mask &=3D ~BIT(chan->channel); =20 return 0; } --=20 2.14.1