Received: by 10.192.165.156 with SMTP id m28csp1173187imm; Wed, 11 Apr 2018 13:53:17 -0700 (PDT) X-Google-Smtp-Source: AIpwx49oyki7sC9puok5hsKKwPsK78Hiuf7g79c9Cw8X/+ktJpN6T4EIMu8GyHBcNTs0J+bbpYie X-Received: by 2002:a17:902:70c4:: with SMTP id l4-v6mr6694256plt.382.1523479997745; Wed, 11 Apr 2018 13:53:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523479997; cv=none; d=google.com; s=arc-20160816; b=q3a72bga+GltTrv7B7LzgTiDWVRSjFmyTMaT+gH+NNAmUVgtVxkd2J261zXH8cWIyD R/sgJ89RPVCMQiFEdgiiiZceXFTpeQEu5XNOlUivDa/M85j8lK5OGRYSbK8LpqcgLdsZ uIZcQJ6R46Vur3Uq0/MqsRJbzHZEutZwJf+j1cHhRcBEcGgJr5SoiLf6D9sQkUtRiKYx Ki79RVABR5/+ucr/w8KZu2STEjHi6vrnZ/dci6IYzL6WUBED4FaW1aZGho0jvp+fMyME SRvq/A+fmw7hrMbtV0jK9Dl7X+fu67Dyo+PUXjlal2DmDHr2LLjWbOWVsOoJaSBA8GJ3 5LuA== 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=icEpjjEKdOYYZ5KHGQyAxHf4sgFbS+qSvOUQaTqYMH4=; b=eocPRZYVUVMYCovbuICquJSsznDJlAJKQzp8Dcp9gmoQbeZpl7USle0LwtaeUR8S7T i/oNZaqrr1rSL0LHxR4LhH0Ibdj8P0GpfyfJinAB/Y/Wcyx/IADfVKFhpbvUJ9EoNobS sZ4cTfpJblHsB/t5KeDWuFlFeq7a9Yi5LJEXPSm8BMesgfddvACk12gPvekfFKFw2eJu HfSG972JrX1VsOsdDNNKKV0X3N0RTqGORA+z6q5n7dRfnXpg1cAbJwRBD/VjxrsRydoH aGmts8kbDet48z+RrrRjHdjpnB0YZrMbH5hnyQpuz9qpivfqDVpL1x+8nyU+oKKAE8UG 7Xqg== 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 s24-v6si1764941plp.564.2018.04.11.13.52.41; Wed, 11 Apr 2018 13:53:17 -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 S1755663AbeDKSqA (ORCPT + 99 others); Wed, 11 Apr 2018 14:46:00 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58736 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755631AbeDKSpx (ORCPT ); Wed, 11 Apr 2018 14:45:53 -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 B0A37CE3; Wed, 11 Apr 2018 18:45:52 +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.4 055/190] iio: hi8435: avoid garbage event at first enable Date: Wed, 11 Apr 2018 20:35:01 +0200 Message-Id: <20180411183553.570751720@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183550.114495991@linuxfoundation.org> References: <20180411183550.114495991@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.4-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; }