Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp361664pxb; Wed, 18 Aug 2021 04:17:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZPCF3lxReV5i6gC6/Gxopc482zasA1qo/ha/n+rMlShil0uYgk6YZCL5zkzEsN74tzshG X-Received: by 2002:a17:906:369a:: with SMTP id a26mr9119988ejc.539.1629285438001; Wed, 18 Aug 2021 04:17:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629285437; cv=none; d=google.com; s=arc-20160816; b=ZewOQ4naMzOQ56LsHZDBCWOtO5Cn3tE1SpltmfuVPDEFqD2r4QRyLQyOWCT29wlnpW SJLfy2vU1IjHMogqW9BbwNOrzJL+UykxTF0hdPkck9dqmo+FHm0mHOdwuHWqSPns/76+ 7Y1U/6cKUcnX+LPXyAHM41Sgm7PvWOMmhY3WiPVQ1KElKX7CerAIyIoUhb1hcrTabMWV zsfaZNhdof1TZRY7hJBxrc9RSOaPsciYRUx6S0EMnFWstEjwSa0OLmdPVPT53pEn1ePe XW7+1C6ZKVBYpn6kT1WzSV0QC2Ib6z0UbGLV4Da6YvJDO2jv541+GaQwO36XJ2D8dL26 1H9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=yt8gEaTy1MkMPHvhCJBQIWWdPxIh/aTMz9albHQBVYQ=; b=Zgtigel9VbmjatrcDbuVseruFsCBZ+PHGKA0P8or2hkEB0V91Yqz5umDV7WMyiKa4D EsJcE5E1riJSFC0fp1EKV8tWSB1XTgdhQ2Mwbji24iIYqPLXLPMLeUEVvX3ImIXD1mze F6Ndq5fikn4MgFZRapBiBhSJmtUs/9iu8xTUmhr+Ho2zovqUjXR5LS7IKIWIQh4PNeY9 B1nCnoMOux0OLv67TtMq7GkGb1I/zjVl4tb6VIq35Zi4jBJALqufBUmRAVgufMaRmaRk 4DBntiaZGVIMG/l5fAFM4hv6STS0f0PZhcvXTggqHtNngeUrFSMxT+prRiRJkElMvtiL 8GEQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nd33si5121559ejc.139.2021.08.18.04.16.54; Wed, 18 Aug 2021 04:17:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235440AbhHRLNw (ORCPT + 99 others); Wed, 18 Aug 2021 07:13:52 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:57119 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235612AbhHRLMZ (ORCPT ); Wed, 18 Aug 2021 07:12:25 -0400 Received: (Authenticated sender: miquel.raynal@bootlin.com) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 5D7C160014; Wed, 18 Aug 2021 11:11:49 +0000 (UTC) From: Miquel Raynal To: Jonathan Cameron , Lars-Peter Clausen Cc: Thomas Petazzoni , linux-iio@vger.kernel.org, , Miquel Raynal Subject: [PATCH 14/16] iio: adc: max1027: Consolidate the end of conversion helper Date: Wed, 18 Aug 2021 13:11:37 +0200 Message-Id: <20210818111139.330636-15-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210818111139.330636-1-miquel.raynal@bootlin.com> References: <20210818111139.330636-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we have a dedicated handler for End Of Conversion interrupts, let's create a second path: - Situation 1: we are using the external hardware trigger, a conversion has been triggered and the ADC pushed the data to its FIFO, we need to retrieve the data and push it to the IIO buffers. - Situation 2: we are not using the external hardware trigger, hence we are likely waiting in a blocked thread waiting for this interrupt to happen: in this case we just wake up the waiting thread. Signed-off-by: Miquel Raynal --- drivers/iio/adc/max1027.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/max1027.c b/drivers/iio/adc/max1027.c index 8d86e77fb5db..8c5995ae59f2 100644 --- a/drivers/iio/adc/max1027.c +++ b/drivers/iio/adc/max1027.c @@ -235,6 +235,7 @@ struct max1027_state { struct iio_trigger *trig; __be16 *buffer; struct mutex lock; + bool data_rdy; bool cnvst_trigger; u8 reg ____cacheline_aligned; }; @@ -243,12 +244,22 @@ static DECLARE_WAIT_QUEUE_HEAD(max1027_queue); static int max1027_wait_eoc(struct iio_dev *indio_dev) { + struct max1027_state *st = iio_priv(indio_dev); unsigned int conversion_time = MAX1027_CONVERSION_UDELAY; + int ret; - if (indio_dev->active_scan_mask) - conversion_time *= hweight32(*indio_dev->active_scan_mask); + if (st->spi->irq) { + ret = wait_event_interruptible_timeout(max1027_queue, + st->data_rdy, HZ / 1000); + st->data_rdy = false; + if (ret == -ERESTARTSYS) + return ret; + } else { + if (indio_dev->active_scan_mask) + conversion_time *= hweight32(*indio_dev->active_scan_mask); - usleep_range(conversion_time, conversion_time * 2); + usleep_range(conversion_time, conversion_time * 2); + } return 0; } @@ -481,6 +492,9 @@ static irqreturn_t max1027_eoc_irq_handler(int irq, void *private) if (st->cnvst_trigger) { ret = max1027_read_scan(indio_dev); iio_trigger_notify_done(indio_dev->trig); + } else { + st->data_rdy = true; + wake_up(&max1027_queue); } if (ret) -- 2.27.0