Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp359473pxb; Wed, 18 Aug 2021 04:14:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPTsoJyL+Zcgn64hwILgmSz2zcF/stkZphlRvFhu4UckMWp0VYbKbU7JXhbsHZnAEfYUR8 X-Received: by 2002:a17:907:7895:: with SMTP id ku21mr9322643ejc.361.1629285254081; Wed, 18 Aug 2021 04:14:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629285254; cv=none; d=google.com; s=arc-20160816; b=uop/GI0iXVt8ykj3Y4MYkOZ0Fxw+qs3VV3Rs6svAzRONTGlIHJ1mFDTXg46uLZIjAT 2tjJ4jaMM/8Zqs6adnZGNn4ELF29hjC58dN68m6zUqwg1cf40gaSHGekdjla3irEFJ2/ 1QdHBioIs2scx5md9x4nIK00faxJGxNKVaOchQPP+VCAAQpk6nhIWnU0luo1CElhbQC2 YDn/Hdlzh4VpZGhI6blmBKOiol8gulISLvKa1Y2z1aWQuIT+aluex4zWL1gP+5r9dKaA wvjYa9AdqB8p7ufp6ZtNjfqHK+Hsg43H9Jm2LuCs8pP+m4xrOnk24ubfOyxJrfMcwQIQ gQ7w== 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=K9AB48nNEluP6n2n860tsW3Z3Igwrq0Nt3sQS8YW0iU=; b=dNA1LcTb3qwJiejd6t6Q9Z3i9vYPmE7LX2TcUj6VFZWex1AUOTlYL6DBrpxuphsQ9k 29eAGfOf9YtgDrTG3Wk00seg6juIlMKn/MNWuuoYQzIgSC1TscojGjg/lxphW/abVYpn pawS//5poKAjDiKthpd0axn4sFg85kInKL+mf8UwKRcv4V7OclWGoo2174jEsGV756mT uXSifNBPJsY84OLUM/4kcfsddOftSX2lLFXgNpBcUXGDzftPTnLsB4Tg2sQ1gtRbOsz+ WtLNxQnYUlNOKPMvuEZNoVZo/36PibnbIBFa13kvimie/OrYIER8NYS0PzcvNK8LBay7 crSQ== 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 z15si5309793edb.227.2021.08.18.04.13.50; Wed, 18 Aug 2021 04:14:14 -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 S235660AbhHRLMc (ORCPT + 99 others); Wed, 18 Aug 2021 07:12:32 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:51527 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233798AbhHRLMR (ORCPT ); Wed, 18 Aug 2021 07:12:17 -0400 Received: (Authenticated sender: miquel.raynal@bootlin.com) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id EEA666000E; Wed, 18 Aug 2021 11:11:41 +0000 (UTC) From: Miquel Raynal To: Jonathan Cameron , Lars-Peter Clausen Cc: Thomas Petazzoni , linux-iio@vger.kernel.org, , Miquel Raynal Subject: [PATCH 03/16] iio: adc: max1027: Push only the requested samples Date: Wed, 18 Aug 2021 13:11:26 +0200 Message-Id: <20210818111139.330636-4-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 When a triggered scan occurs, the identity of the desired channels is known in indio_dev->active_scan_mask. Instead of reading and pushing to the IIO buffers all channels each time, scan the minimum amount of channels (0 to maximum requested chan, to be exact) and only provide the samples requested by the user. For example, if the user wants channels 1, 4 and 5, all channels from 0 to 5 will be scanned but only the desired channels will be pushed to the IIO buffers. Signed-off-by: Miquel Raynal --- drivers/iio/adc/max1027.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/iio/adc/max1027.c b/drivers/iio/adc/max1027.c index b753658bb41e..8ab660f596b5 100644 --- a/drivers/iio/adc/max1027.c +++ b/drivers/iio/adc/max1027.c @@ -360,6 +360,9 @@ static int max1027_set_trigger_state(struct iio_trigger *trig, bool state) struct max1027_state *st = iio_priv(indio_dev); int ret; + if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) + return -EINVAL; + if (state) { /* Start acquisition on cnvst */ st->reg = MAX1027_SETUP_REG | MAX1027_CKS_MODE0 | @@ -368,9 +371,12 @@ static int max1027_set_trigger_state(struct iio_trigger *trig, bool state) if (ret < 0) return ret; - /* Scan from 0 to max */ - st->reg = MAX1027_CONV_REG | MAX1027_CHAN(0) | - MAX1027_SCAN_N_M | MAX1027_TEMP; + /* + * Scan from 0 to the highest requested channel. The temperature + * could be avoided but it simplifies a bit the logic. + */ + st->reg = MAX1027_CONV_REG | MAX1027_SCAN_0_N | MAX1027_TEMP; + st->reg |= MAX1027_CHAN(fls(*indio_dev->active_scan_mask) - 2); ret = spi_write(st->spi, &st->reg, 1); if (ret < 0) return ret; @@ -391,11 +397,22 @@ static irqreturn_t max1027_trigger_handler(int irq, void *private) struct iio_poll_func *pf = private; struct iio_dev *indio_dev = pf->indio_dev; struct max1027_state *st = iio_priv(indio_dev); + unsigned int scanned_chans = fls(*indio_dev->active_scan_mask); + u16 *buf = st->buffer; + unsigned int bit; pr_debug("%s(irq=%d, private=0x%p)\n", __func__, irq, private); /* fill buffer with all channel */ - spi_read(st->spi, st->buffer, indio_dev->masklength * 2); + spi_read(st->spi, st->buffer, scanned_chans * 2); + + /* Only keep the channels selected by the user */ + for_each_set_bit(bit, indio_dev->active_scan_mask, + indio_dev->masklength) { + if (buf[0] != st->buffer[bit]) + buf[0] = st->buffer[bit]; + buf++; + } iio_push_to_buffers(indio_dev, st->buffer); -- 2.27.0