Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp362100pxb; Wed, 18 Aug 2021 04:17:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3E6oxYPH9xrOUtW9MgafysL9J6YJl5J/a07axsBEsKojSEXvXYOhI9e05M1AD8yPVbb3T X-Received: by 2002:a17:907:2b09:: with SMTP id gc9mr9383608ejc.49.1629285473565; Wed, 18 Aug 2021 04:17:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629285473; cv=none; d=google.com; s=arc-20160816; b=RAjys8lacf0JOKqHYQxxsm2uhIPNLZMkAVfGyAR9+Agb0KgT391Ssx2ei+eDv8Ja/K QBOcuLCMj5QcJkGDNdlZSUkmAOh5BHuNbRX7LRG4zR5ktbMiru46/R3xPEfUDtjJ3coH TdZLDBMqpPJzzoQIoVNSxk8DFFVt4TnmDHx4e5vLOMrLmTtHtWcFg/xnTT77A5xNfk2X kRAn+sR+PgiLevqxMyXQrVOLgwhzXTErfVTgOInPxNlKta3vU/qHfNq9eCJbzGKrpnVe NEzKC8M5NGiy1Va02KtZBS/d7fo9EI6S6iJWGSwgmGtslZ4VfgGU3ozGum5vsRkYlD9L 4ggQ== 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=cwJh+xepUjC9X3ng4tMBTP1880lYxGh9oHdsfWlCO4k=; b=X3YqPhgfJMyMonnaydaE1pM2GOlp1kws3k3zsZ5wo1zbchhe4PLsy4uyO43Iu+oUJZ dMGcEZ2dM6qA2SlYNvpgIHlG3hgLlZGqA3Ra7lCzouPlnFn5mdt5AW+eY16qQeE0A1uO yFPVp5z0PjIM4tjbtPsROIcU2M2B4jWif/l6zr46Q5zJsMGXznk+aPTy+aGeYbQFUWHR o7rFyautyPm1POUfmBbQIhCjPHb2uof5SoBs8LPQKluJYa8wRskd3AV+MiXD854eBjIR QQZ8v/6AiTl5l2Haw0CePA4fb/hkfFSwx/7i+vXzG1TVSBRx3jWJ3ZCA0eGw8aPvRSUW q5Vg== 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 ee28si5158432edb.265.2021.08.18.04.17.31; Wed, 18 Aug 2021 04:17:53 -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 S236514AbhHRLNq (ORCPT + 99 others); Wed, 18 Aug 2021 07:13:46 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:60351 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235551AbhHRLMX (ORCPT ); Wed, 18 Aug 2021 07:12:23 -0400 Received: (Authenticated sender: miquel.raynal@bootlin.com) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 0CE8260012; Wed, 18 Aug 2021 11:11:47 +0000 (UTC) From: Miquel Raynal To: Jonathan Cameron , Lars-Peter Clausen Cc: Thomas Petazzoni , linux-iio@vger.kernel.org, , Miquel Raynal Subject: [PATCH 12/16] iio: adc: max1027: Introduce an end of conversion helper Date: Wed, 18 Aug 2021 13:11:35 +0200 Message-Id: <20210818111139.330636-13-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 For now this helper only waits for the maximum duration of a conversion, but it will soon be improved to properly handle the end of conversion interrupt. Signed-off-by: Miquel Raynal --- drivers/iio/adc/max1027.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/max1027.c b/drivers/iio/adc/max1027.c index afc3ce69f7ea..2d6485591761 100644 --- a/drivers/iio/adc/max1027.c +++ b/drivers/iio/adc/max1027.c @@ -60,6 +60,9 @@ #define MAX1027_NAVG_32 (0x03 << 2) #define MAX1027_AVG_EN BIT(4) +/* Device can achieve 300ksps so we assume a 3.33us conversion delay */ +#define MAX1027_CONVERSION_UDELAY 4 + enum max1027_id { max1027, max1029, @@ -236,6 +239,20 @@ struct max1027_state { u8 reg ____cacheline_aligned; }; +static DECLARE_WAIT_QUEUE_HEAD(max1027_queue); + +static int max1027_wait_eoc(struct iio_dev *indio_dev) +{ + unsigned int conversion_time = MAX1027_CONVERSION_UDELAY; + + if (indio_dev->active_scan_mask) + conversion_time *= hweight32(*indio_dev->active_scan_mask); + + usleep_range(conversion_time, conversion_time * 2); + + return 0; +} + /* Scan from 0 to the highest requested channel */ static int max1027_configure_chans_to_scan(struct iio_dev *indio_dev) { @@ -310,9 +327,11 @@ static int max1027_read_single_value(struct iio_dev *indio_dev, /* * For an unknown reason, when we use the mode "10" (write * conversion register), the interrupt doesn't occur every time. - * So we just wait 1 ms. + * So we just wait the maximum conversion time and deliver the value. */ - mdelay(1); + ret = max1027_wait_eoc(indio_dev); + if (ret) + return ret; /* Read result */ ret = spi_read(st->spi, st->buffer, (chan->type == IIO_TEMP) ? 4 : 2); -- 2.27.0