From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DAD1C55185 for ; Sat, 25 Apr 2020 14:52:58 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6288F20714 for ; Sat, 25 Apr 2020 14:52:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="mqlNjyLT"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="OulI3xUd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6288F20714 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zVDnkqpHBlTrd9d43A1bPNwQZ0tooT6f9wM8Pl2oIhE=; b=mqlNjyLTqZvjBS krgNPRjutXl+7wjOCxX8wIAoshgiGxGgW2m45kqWHaXJfwbmdOW+YDbisaHB3Aoe0P4R4wAiwbkwD xuyVVxd3n8zSDr98MDPa0OVDWYAJsNWgBZKro4H8q7Le8X+Bdo4VrkbgQy3mrO+bnnDo70xECzEH+ P7zhD4ZOATsFtWoOLQgc3tMQxBPJaRhv2FqG4+MwcHcBnaBl+fM7uVDau3wqpf3BW1SKhCbhUH6kd xqTye7GuZUO9unMt9kyDQQ+FL/rS6AXIJCns0qHJGJ0/bz0+GlS0DzPsDAc1PtWV7xwlcRNYTpn7u mpLXCeEupdsb6BhQB1jg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jSMAr-0006hi-Hh; Sat, 25 Apr 2020 14:52:57 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jSMAo-0006hA-9Z for linux-arm-kernel@lists.infradead.org; Sat, 25 Apr 2020 14:52:55 +0000 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (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 5F3D720714; Sat, 25 Apr 2020 14:52:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587826373; bh=+13CHPNmfmCKf+0SVFYF37GqQiMCAaZRQBxv+QtM87o=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=OulI3xUdPjn50jbNzvZ8tMsNtjmM9jrKFZ+7nIv5avHBRDKjJg553M1LtNyHlYByI ITdynEsnKVHySeySGiFrmI0Wf0B105B8OhH1eQjh9LABM8joxhNK6yaYpiti3Sd2Pe TQ7Km1tat6aYfVrW2QxsyXgqmD2kTu/3+FgVeXkc= Date: Sat, 25 Apr 2020 15:52:49 +0100 From: Jonathan Cameron To: Subject: Re: [PATCH v3 2/3] iio: adc: at91-sama5d2_adc: handle unfinished conversions Message-ID: <20200425155249.15fb855f@archlinux> In-Reply-To: <1580216189-27418-3-git-send-email-eugen.hristev@microchip.com> References: <1580216189-27418-1-git-send-email-eugen.hristev@microchip.com> <1580216189-27418-3-git-send-email-eugen.hristev@microchip.com> X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200425_075254_375638_CB4DAF2C X-CRM114-Status: GOOD ( 28.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-iio@vger.kernel.org, Ludovic.Desroches@microchip.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, alexandru.ardelean@analog.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 28 Jan 2020 12:57:40 +0000 wrote: > From: Eugen Hristev > > It can happen that on IRQ trigger, not all conversions are done if > we are enabling multiple channels. > The IRQ is triggered on first EOC (end of channel), but it can happen > that not all channels are done. This leads into erroneous reports to > userspace (zero values or previous values). > To solve this, in trigger handler, check if the mask of done channels > is the same as the mask of active scan channels. > If it's the same, proceed and push to buffers. Otherwise, use usleep > to sleep until the conversion is done or we timeout. > Normally, it should happen that in a short time fashion, all channels are > ready, since the first IRQ triggered. > If a hardware fault happens (for example the clock suddently dissappears), > the handler will not be completed, in which case we do not report anything to > userspace anymore. > Also, change from using the EOC interrupts to DRDY interrupt. > This helps with the fact that not 'n' interrupt statuses are enabled, > each being able to trigger an interrupt, and instead only data ready > interrupt can wake up the CPU. Like this, when data is ready, check in > handler which and how many channels are done. While the DRDY is raised, > other IRQs cannot occur. Once the channel data is being read, we ack the > IRQ and finish the conversion. > > Signed-off-by: Eugen Hristev Applied this and patch 3 to the togreg branch of iio.git and pushed out as testing. Thanks for reminding me about these. Were still in the queue but I might have forgotten to check this far back! Jonathan > --- > Changes in v3: > - rewrite some code as suggested by Jonathan (w.r.t. state and dma enabled in > configure_trigger > - move back enable_irq in reenable_trigger : looks like it was a leftover, > thanks Jonathan > > Changes in v2: > - move start of conversion to threaded irq, removed specific at91 pollfunc > - add timeout to channel mask readiness check in trigger handler > - use DRDY irq instead of EOC irqs. > - move enable irq after DRDY has been acked in reenable_trigger > > drivers/iio/adc/at91-sama5d2_adc.c | 62 +++++++++++++++++++++++++++++--------- > 1 file changed, 48 insertions(+), 14 deletions(-) > > diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c > index 2a6950a..49c2b9d 100644 > --- a/drivers/iio/adc/at91-sama5d2_adc.c > +++ b/drivers/iio/adc/at91-sama5d2_adc.c > @@ -8,6 +8,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -100,6 +101,8 @@ > #define AT91_SAMA5D2_IER_YRDY BIT(21) > /* Interrupt Enable Register - TS pressure measurement ready */ > #define AT91_SAMA5D2_IER_PRDY BIT(22) > +/* Interrupt Enable Register - Data ready */ > +#define AT91_SAMA5D2_IER_DRDY BIT(24) > /* Interrupt Enable Register - general overrun error */ > #define AT91_SAMA5D2_IER_GOVRE BIT(25) > /* Interrupt Enable Register - Pen detect */ > @@ -486,6 +489,21 @@ static inline int at91_adc_of_xlate(struct iio_dev *indio_dev, > return at91_adc_chan_xlate(indio_dev, iiospec->args[0]); > } > > +static unsigned int at91_adc_active_scan_mask_to_reg(struct iio_dev *indio_dev) > +{ > + u32 mask = 0; > + u8 bit; > + > + for_each_set_bit(bit, indio_dev->active_scan_mask, > + indio_dev->num_channels) { > + struct iio_chan_spec const *chan = > + at91_adc_chan_get(indio_dev, bit); > + mask |= BIT(chan->channel); > + } > + > + return mask & GENMASK(11, 0); > +} > + > static void at91_adc_config_emr(struct at91_adc_state *st) > { > /* configure the extended mode register */ > @@ -746,25 +764,23 @@ static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state) > at91_adc_writel(st, AT91_SAMA5D2_COR, cor); > } > > - if (state) { > + if (state) > at91_adc_writel(st, AT91_SAMA5D2_CHER, > BIT(chan->channel)); > - /* enable irq only if not using DMA */ > - if (!st->dma_st.dma_chan) { > - at91_adc_writel(st, AT91_SAMA5D2_IER, > - BIT(chan->channel)); > - } > - } else { > - /* disable irq only if not using DMA */ > - if (!st->dma_st.dma_chan) { > - at91_adc_writel(st, AT91_SAMA5D2_IDR, > - BIT(chan->channel)); > - } > + else > at91_adc_writel(st, AT91_SAMA5D2_CHDR, > BIT(chan->channel)); > - } > } > > + /* Nothing to do if using DMA */ > + if (st->dma_st.dma_chan) > + return 0; > + > + if (state) > + at91_adc_writel(st, AT91_SAMA5D2_IER, AT91_SAMA5D2_IER_DRDY); > + else > + at91_adc_writel(st, AT91_SAMA5D2_IDR, AT91_SAMA5D2_IER_DRDY); > + > return 0; > } > > @@ -781,6 +797,7 @@ static int at91_adc_reenable_trigger(struct iio_trigger *trig) > > /* Needed to ACK the DRDY interruption */ > at91_adc_readl(st, AT91_SAMA5D2_LCDR); > + > return 0; > } > > @@ -1015,6 +1032,22 @@ static void at91_adc_trigger_handler_nodma(struct iio_dev *indio_dev, > int i = 0; > int val; > u8 bit; > + u32 mask = at91_adc_active_scan_mask_to_reg(indio_dev); > + unsigned int timeout = 50; > + > + /* > + * Check if the conversion is ready. If not, wait a little bit, and > + * in case of timeout exit with an error. > + */ > + while ((at91_adc_readl(st, AT91_SAMA5D2_ISR) & mask) != mask && > + timeout) { > + usleep_range(50, 100); > + timeout--; > + } > + > + /* Cannot read data, not ready. Continue without reporting data */ > + if (!timeout) > + return; > > for_each_set_bit(bit, indio_dev->active_scan_mask, > indio_dev->num_channels) { > @@ -1281,7 +1314,8 @@ static irqreturn_t at91_adc_interrupt(int irq, void *private) > status = at91_adc_readl(st, AT91_SAMA5D2_XPOSR); > status = at91_adc_readl(st, AT91_SAMA5D2_YPOSR); > status = at91_adc_readl(st, AT91_SAMA5D2_PRESSR); > - } else if (iio_buffer_enabled(indio) && !st->dma_st.dma_chan) { > + } else if (iio_buffer_enabled(indio) && > + (status & AT91_SAMA5D2_IER_DRDY)) { > /* triggered buffer without DMA */ > disable_irq_nosync(irq); > iio_trigger_poll(indio->trig); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel