Received: by 2002:a4a:301c:0:0:0:0:0 with SMTP id q28-v6csp470687oof; Mon, 24 Sep 2018 23:54:40 -0700 (PDT) X-Google-Smtp-Source: ACcGV61CdDZh7QG8sk3HcDXs0lnmtzlKlZixuKPgk+Q48lbQs0dAJg2KcpfqMt/OpOetsc0jgg43 X-Received: by 2002:a17:902:b115:: with SMTP id q21-v6mr2111412plr.333.1537858480819; Mon, 24 Sep 2018 23:54:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537858480; cv=none; d=google.com; s=arc-20160816; b=kyGICqNoMkh5MEJUagh5emH/NVs17nA1Yn9UU06wCp1buNR6YtvMZyAcM71zbPQYzE tgJ1GVTWuVtHC5MMTDh1xbGP3tef2Wu+ebkYm1rEhN/aFVh/WqLjd9kxZS8vIERy3lqe A9mJ1+9Xo2W2R7NRabLDFYqawN0rgEg9NEQwT9d7cMy2ejgcrfePGJrxWaoG75pUu9oA uYuKIeDyt5dtvkgBeQPDH8nTtUrV7vEeDrHb8KbQXDANECReFhanEfIAz1CQXZFkqFgZ 8PEXFoPFJVwui1TH6NgoYq5yld7+NrdicrNr51x8GwNXRW5mQQY5EICuyWR9AmCBY0dL 6jXw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=pO+VORE+4WBXA2qx18sV3UlDDXnubOuzAMTmokh8+GE=; b=WawEINmTHbsA2nr4TYIoXsb6BcszJgxCcSdvBRUp1mxfqh8tkpJu3IY5H5FCxdPfzR bhHkmqXIQzqO5fuUCsHNazqIgbDbMf/H08NCaAotTYKSTDHZqWrJZb7D43/lewuhic2l N2aoVeVNQ+F0Fa45dJ6VT0059vpPF02X4CJmAxAaBDc2+s1vk0I8qvpfHjLmOSJoNpor lgknFk1Zan1LRxIaxQlVCv85+n0yFexjWYpKhTFL+TEKDIY0dRPcxeVgiJ3yRfkPGev0 PLX1GduzrEr7mMscw47X/SFx5NOW49lejxVmoIkyIZDME7tO+KgClgh9NdQiWAfoCM6J tnHw== 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 m19-v6si1594970pgj.155.2018.09.24.23.54.25; Mon, 24 Sep 2018 23:54:40 -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 S1727159AbeIYNAY (ORCPT + 99 others); Tue, 25 Sep 2018 09:00:24 -0400 Received: from esa6.microchip.iphmx.com ([216.71.154.253]:23487 "EHLO esa6.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726030AbeIYNAY (ORCPT ); Tue, 25 Sep 2018 09:00:24 -0400 X-IronPort-AV: E=Sophos;i="5.54,301,1534834800"; d="scan'208";a="17716566" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 24 Sep 2018 23:54:18 -0700 Received: from [10.145.6.126] (10.10.76.4) by chn-sv-exch04.mchp-main.com (10.10.76.105) with Microsoft SMTP Server id 14.3.352.0; Mon, 24 Sep 2018 23:54:17 -0700 Subject: Re: [PATCH 1/2] iio: adc: at91: fix acking DRDY irq on simple conversions To: Jonathan Cameron CC: , , , , , Maxime Ripard , References: <1537447238-18674-1-git-send-email-eugen.hristev@microchip.com> <20180922113123.2c8da044@archlinux> <9846e106-8baf-b491-29ca-8306be9527ee@microchip.com> <20180924210056.2cae9439@archlinux> <20180924212701.400e21f7@archlinux> From: Eugen Hristev Message-ID: <5ee8253a-5b07-94ce-a86d-b453911fce0a@microchip.com> Date: Tue, 25 Sep 2018 09:50:24 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180924212701.400e21f7@archlinux> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24.09.2018 23:27, Jonathan Cameron wrote: > On Mon, 24 Sep 2018 21:00:56 +0100 > Jonathan Cameron wrote: > >> 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'm talking rubbish here. Please ignore! > >> >>> >>>> >>>> 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! For what it's worth a small explanation: The status in the ISR (interrupt status) is updated regardless of whether the IRQ is enabled in the IER (interrupt enable) or not. Actually "enabling DRDY" makes the hardware start raising the interrupt line on DRDY event if it's the case. but DRDY bit is still being asserted in the ISR. It works like this because someone might want to write some simple driver without IRQ, just poll the ISR for the status. One other thing, in my driver, at91-sama5d2_adc, I had the same issue, and I am reading the DRDY in the EOC part after waking up from the wait. This makes the IRQ handler shorter by a few hundred cycles : read LCDR in the userspace-called read_raw. Do you want me to have a patch at some point to move the LCDR read in the IRQ handler for at91-sama5d2_adc as well ? Eugen >> >> Jonathan >>> >>> >>>> >>>> Jonathan >>>> >>>>> >>>>> st->last_value = 0; >>>>> st->done = false; >>>> >> > >