Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2959261imm; Mon, 24 Sep 2018 13:01:23 -0700 (PDT) X-Google-Smtp-Source: ACcGV6325dInMs433pPEpcaTyVuPIJ3KWccuWGvFxaXCHq7pystZ6SMHpDCNdaXUyVo2dQcG46PM X-Received: by 2002:a17:902:788e:: with SMTP id q14-v6mr313869pll.49.1537819283929; Mon, 24 Sep 2018 13:01:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537819283; cv=none; d=google.com; s=arc-20160816; b=KwM2arkaJM9spdKNNoHfmr6XMZ1ARKkchkDJEqEzWQlNBMiAYnHlIUZj23UrMKezIE 5TttVNUlQRHvWan8yuwOBVk8HxJHvCzPpoCpoy+t6BJf/dLVMB9X+OGmBZN3ed7bve8u hl1DP5TicjEOHNXwYSrwlM643JEQZz+BseCy3FAaJBHWU7CLU1snFjU3q4GPglapaKNd g9XHGW6Ahpvt7NCCztmjEG83ButhZmanTB2k2Zif2HogSTWPVgr0/IZ/hhtYzsFYYvu+ CiMTSc3d2SZvp8y3uEvvu4wq2z1A6KaWj0z1Nzns3DgAuK7waMqyPpHQry4S+KFNjKGj YEOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=vQZftV4ay3TaiLkdzhYzsz6xjfEtBabKkW40zGI9Sak=; b=V5yIYgXM+BruhPf2DM4ZOZ3Z/v/NtCnYNZwwxSJU5doAHnqcplGHDxM3A5B/C6h5KQ I072xUwlKzEkL/vAECdOtzbwYIFO2tRzCLJ7wWUA8RTYwLvmbc9PwR/GOJ+l5IlUAQoH TUMgIr858Ot5QyhogvljW20m8USwUWyxB5yU/hkKhmCZTeR6wjXaJN8hqj1XPP8BlYhl RSBSsV6dZVrNknNOMcSXVEB3vhPKJZZjYl/7Nb9IOh9+rsEJYUdHY8rCzip8uxPbsM02 5bR45G87VU5x2wdCur+m7fnS67crElVSVUVjT0SbopHXNTwUqjHfTJ3yNCD0uvk2PjAq QYhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LbkORAp5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m24-v6si143524pfk.56.2018.09.24.13.01.07; Mon, 24 Sep 2018 13:01:23 -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; dkim=pass header.i=@kernel.org header.s=default header.b=LbkORAp5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727086AbeIYCEw (ORCPT + 99 others); Mon, 24 Sep 2018 22:04:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:48676 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726265AbeIYCEv (ORCPT ); Mon, 24 Sep 2018 22:04:51 -0400 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0D5DA20C0A; Mon, 24 Sep 2018 20:00:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1537819259; bh=6N2QS3Qkbz8RZL0tANYJUmUe653BAdA/qRn1gZU63O8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=LbkORAp5yr/MlNtqMqId4uTNjbiIhJ3EtHGJ6HUDlRAX5vQ3lvWJvT61cRwYvNLn0 NJYcjn7e+jQWEFaPi+xDT2n7oXHmmy8aNVM0ErZUMwZ8yV/DH7nCHHlYg4WvU90ebE 754wDme9M7r9Xg/7xhBqOSIWKlXxnXuGo/i9flmk= Date: Mon, 24 Sep 2018 21:00:56 +0100 From: Jonathan Cameron To: Eugen Hristev Cc: , , , , , Maxime Ripard , Subject: Re: [PATCH 1/2] iio: adc: at91: fix acking DRDY irq on simple conversions Message-ID: <20180924210056.2cae9439@archlinux> In-Reply-To: <9846e106-8baf-b491-29ca-8306be9527ee@microchip.com> References: <1537447238-18674-1-git-send-email-eugen.hristev@microchip.com> <20180922113123.2c8da044@archlinux> <9846e106-8baf-b491-29ca-8306be9527ee@microchip.com> X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 24 Sep 2018 09:19:43 +0300 Eugen Hristev wrote: > On 22.09.2018 13:31, Jonathan Cameron wrote: > > On Thu, 20 Sep 2018 15:40:37 +0300 > > Eugen Hristev wrote: > > > >> When doing simple conversions, the driver did not acknowledge the DRDY irq. > >> If this irq is not acked, it will be left pending, and as soon as a trigger > >> is enabled, the irq handler will be called, it doesn't know why this irq > >> has occurred because no channel is pending, and then we will have irq loop > >> and board will hang. > >> > >> Fixes 0e589d5fb ("ARM: AT91: IIO: Add AT91 ADC driver.") > >> Cc: Maxime Ripard > >> Cc: > >> Signed-off-by: Eugen Hristev > >> --- > >> drivers/iio/adc/at91_adc.c | 5 +++++ > >> 1 file changed, 5 insertions(+) > >> > >> diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c > >> index 44b5168..e85f859 100644 > >> --- a/drivers/iio/adc/at91_adc.c > >> +++ b/drivers/iio/adc/at91_adc.c > >> @@ -712,6 +712,11 @@ static int at91_adc_read_raw(struct iio_dev *idev, > >> at91_adc_writel(st, AT91_ADC_CHDR, > >> AT91_ADC_CH(chan->channel)); > >> at91_adc_writel(st, AT91_ADC_IDR, BIT(chan->channel)); > >> + /* > >> + * we need to ack the DRDY irq, otherwise it will be > >> + * left pending and irq handler will be confused > >> + */ > >> + at91_adc_readl(st, AT91_ADC_LCDR); > > > > I'm curious as to how things were working before. Does this only occur > > if we do a raw_read whilst the buffer is enabled? > > No. The situation is that the read raw does not properly cleans itself > up after it's done. > The DRDY bit is cleared only when LCDR (last converted data ) is being read. > Even if we read the per channel conversion data, the LCDR still needs to > be read to clear this irq status. > The driver does not use the DRDY irq but this irq status is still being > set in the status register. Hmm. That is somewhat nasty if it results in false interrupts when you then enable them. > > > > > I would have assumed when it's not enabled, the irq would be masked and > > never generated in the first place... > > > > It may be that what we actually need to do is to prevent read_raw accesses > > when the buffer is enabled (like lots of other drivers do precisely to > > avoid this sort of condition). The problem there comes if we have > > existing applications doing this combination as we are then breaking > > userspace. If that's the case we'll need to be a bit more clever. > > > > Hammering down an irq state in a non irq handling path isn't a good > > solution. > > Ok, I will move the clearing of the DRDY (LCDR read) in the irq path > then, and send a v2. If that can be done cleanly, let us go with that approach. If not what you have here with the addition of a comments saying that the interrupt status is not masked, merely the interrupt and as a result needs clearing for when you later enabled the interrupt, is fine. This definitely sounds like one of those bits of hardware that you can write software to use safely but they certainly didn't make it easy to do so! Jonathan > > > > > > Jonathan > > > >> > >> st->last_value = 0; > >> st->done = false; > >