Received: by 10.192.165.156 with SMTP id m28csp1136868imm; Wed, 11 Apr 2018 13:07:34 -0700 (PDT) X-Google-Smtp-Source: AIpwx4++wmRJiAp75H6mVGoisrSc4LitQffHiVaZ2vOrp+1WhJYa+J/qCSRmy8T/5toc8tAt8Qqv X-Received: by 10.98.159.129 with SMTP id v1mr5075364pfk.25.1523477254267; Wed, 11 Apr 2018 13:07:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523477254; cv=none; d=google.com; s=arc-20160816; b=uusJKiVHWnhmQOdvvZXyPIltG1c6G8xhpCVuR6BacmIQW5xAnd605cXwmWYhfB6bSM eFu5Jmg90Mi/Qp7V+N3YyZUnB7Km0Baw7FEbGmfdMZXLTQfGvm+mfkIjlftKhYUpVnF4 2/sKZtbLu4S/lbZbG9vYV8wrp7AIze1Z+qNs0agdN4o0kvXA9sZsaXeLk3z7ngwfLaO8 aphVfcpF7wL/6nsy+PR6I1OMNSEdzaCkuEokh5CSiskwZkbDuesijV96J3KGb7mY2oV+ 8L1uUTEL1vZW/S9gYg7wadbyxBddgZxVNNztyztGLspAVonfjPxzGs9fj0RhihALhTxi 4qgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=HaMUst45gU0zOxaBWBDhIsMg2B7s5MLL4krP/ttyKh0=; b=VNYK6VKFOayTtmElISqwZRP1YYRoUaYyvdeMoQVRKyAIBt3rjIIf25DdyGuQbAXx1L iXQP1Ls7R4KT+PyOigmzTt3O1gt7XjBgqfMT6Z5fzqmfZo+yQb8RO7kZGfWH+zWWf9lm RvGRzx6XZbxf4e5Oq4Z/iktZqUdzaQ7nNy3xqPzoVPgjje0jHq4urKzTxzZkayEi3gn3 AXbpIDPRETAWf4ZBfW3t1pMLI2C+4D/v/xlJ3oo5q04pSdwAOvhg2M1xztMXxi+xeBsm 030Coye4DC9mla4UMOPY82QXgqjF02sehzlhQMm2lfyzJx9DVfHjBXXoi5gRNx2GFo5a 7/kA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d70si1308612pfl.219.2018.04.11.13.06.57; Wed, 11 Apr 2018 13:07:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757024AbeDKUCk (ORCPT + 99 others); Wed, 11 Apr 2018 16:02:40 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:35690 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933189AbeDKS4L (ORCPT ); Wed, 11 Apr 2018 14:56:11 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 19DE8D20; Wed, 11 Apr 2018 18:56:09 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikita Yushchenko , Jonathan Cameron , Sasha Levin Subject: [PATCH 4.9 083/310] iio: hi8435: avoid garbage event at first enable Date: Wed, 11 Apr 2018 20:33:42 +0200 Message-Id: <20180411183625.855924714@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183622.305902791@linuxfoundation.org> References: <20180411183622.305902791@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- drivers/iio/adc/hi8435.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- a/drivers/iio/adc/hi8435.c +++ b/drivers/iio/adc/hi8435.c @@ -121,10 +121,21 @@ static int hi8435_write_event_config(str enum iio_event_direction dir, int state) { struct hi8435_priv *priv = iio_priv(idev); + int ret; + u32 tmp; + + if (state) { + ret = hi8435_readl(priv, HI8435_SO31_0_REG, &tmp); + if (ret < 0) + return ret; + if (tmp & BIT(chan->channel)) + priv->event_prev_val |= BIT(chan->channel); + else + priv->event_prev_val &= ~BIT(chan->channel); - priv->event_scan_mask &= ~BIT(chan->channel); - if (state) priv->event_scan_mask |= BIT(chan->channel); + } else + priv->event_scan_mask &= ~BIT(chan->channel); return 0; }