Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp360172pxb; Wed, 18 Aug 2021 04:15:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcgT5Rfja4D7hQHqno5Grj1v6HI06nYuvbroRWSJBtcujSoTpxTKm7uk8VrViRVJKQhsLL X-Received: by 2002:a17:906:b74f:: with SMTP id fx15mr6294967ejb.95.1629285305281; Wed, 18 Aug 2021 04:15:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629285305; cv=none; d=google.com; s=arc-20160816; b=ygeiWc4cEV/KsaA4ShFQhZEtUhJaK+hyK2C2/DUDPgiPtI5Mu9L6E4h6UdQ/fvckW6 SgPqc/0Orkij4Bmz/2xAbrzjREfqFSKJSOMmPYfck/cD2J/AzMP/wCgq2TIWsQRlbajj g9vVFbRX1o4T1WREc+V8Ii99P27aJVCbbuxZ+VpPEjWp8OJq0qGWKL71qAsd2mIKxHEU FjG3IoSetWGmuh6B0fHsM4wB0Kf3VUIcVBAcAuGD7C5IXpWsJciFZu6cGoJmIHvGr2M+ Q53cPcbneAW3UcwJW0WKNjFvPQ9/HzBFdnMPN1RPQHz8lMp/dZynrKcNmG2aN5cRmP+2 u7Ow== 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=bJPS56iMSKuq/GW8pfox6410P9o5ZxM1k5RbczdNI6Q=; b=LKUBNKOsUoXWxdRnrAi/mq3yj0xmTyNfSe5flroiuzvwL6gFI9y6SCSLT5dw7ApTni uZR+DXiauq1fXGzpzOH9QQFvUR0tvxRkvluu0XB0/jHRWLf5UGe5i9bIyPuNjo7koCfS XiFeYSYBZzn8hu1HHr89vR1dwD1F0alfLw0CJxYHTX+1AQU2zwf4J8bknW4ejMSp2w7V 56tOKfwRDl2w3ywgIu79TS75jCEOQarzRN27mfYp25Mj9kWkwNGwnC/nPHToC4T9HaEB m2TkJEWArld4V2+PmSCnDT8zk+XcVSd8wXZSZtMQjRVnN4spC8KVlncVY+4sOw27BcvB 8dSQ== 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 w19si5132795edc.537.2021.08.18.04.14.42; Wed, 18 Aug 2021 04:15:05 -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 S236104AbhHRLNZ (ORCPT + 99 others); Wed, 18 Aug 2021 07:13:25 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:50709 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235328AbhHRLMV (ORCPT ); Wed, 18 Aug 2021 07:12:21 -0400 Received: (Authenticated sender: miquel.raynal@bootlin.com) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 0A6256000F; Wed, 18 Aug 2021 11:11:45 +0000 (UTC) From: Miquel Raynal To: Jonathan Cameron , Lars-Peter Clausen Cc: Thomas Petazzoni , linux-iio@vger.kernel.org, , Miquel Raynal Subject: [PATCH 09/16] iio: adc: max1027: Create a helper to configure the channels to scan Date: Wed, 18 Aug 2021 13:11:32 +0200 Message-Id: <20210818111139.330636-10-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 These bits are meant to be reused for triggered buffers setup. Signed-off-by: Miquel Raynal --- drivers/iio/adc/max1027.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/iio/adc/max1027.c b/drivers/iio/adc/max1027.c index 4a78c9cbc339..223c9e4abd86 100644 --- a/drivers/iio/adc/max1027.c +++ b/drivers/iio/adc/max1027.c @@ -236,6 +236,22 @@ struct max1027_state { u8 reg ____cacheline_aligned; }; +/* Scan from 0 to the highest requested channel */ +static int max1027_configure_chans_to_scan(struct iio_dev *indio_dev) +{ + struct max1027_state *st = iio_priv(indio_dev); + int ret; + + /* 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; + + return 0; +} + static int max1027_configure_trigger(struct iio_dev *indio_dev) { struct max1027_state *st = iio_priv(indio_dev); @@ -391,14 +407,8 @@ static int max1027_set_cnvst_trigger_state(struct iio_trigger *trig, bool state) if (ret) return ret; - /* - * 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) + ret = max1027_configure_chans_to_scan(indio_dev); + if (ret) return ret; } else { /* -- 2.27.0