Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3485608pxb; Mon, 30 Aug 2021 03:33:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfU6uRfW2Jfi3SyLXdJcCB/i3A9PhMiOb/ZHXTE4aJoRl7MObozIULWfBN/IOqupfXXX88 X-Received: by 2002:a05:6402:3ce:: with SMTP id t14mr22603698edw.191.1630319607996; Mon, 30 Aug 2021 03:33:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630319607; cv=none; d=google.com; s=arc-20160816; b=hvkQWPzoaZAHHZOTZKiHe3CkQ4gKw/F8/PWBrB45sFQ/7odKoHupn46rwX2As/4peN /1jlyF4K0SomLbWKTM99DF3mhJdG4MM0EbJgEDN8v1gzuOQ9eZPsolBtXkyDK3vTD1NA 3E6PgEbeDLeKCQ1uQaXS+61AG47ctQPoaIMbsLvDIpiibPmBBgoaodDDl+UlfhG767zE w0yNB8PKZFX6XtLn5FuSebjLhmGpXayqRhJLJ55FParuFaN8LCElOnGGW4trKTICN/uh vJGeNxNdF/RjWutTx/5dR3AELeT8TAZQtpIAnwXbnLEywIRNtni4acs2lKK4tO1YpvRp 9L+A== 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:subject:cc:to:from:date; bh=PxgB7us+m559AbegVnrf4gSxOw2wlWvDHp2uq4Yy4C0=; b=mi7yCHYfNsbkt44vESQSqxm+NdhfMoNUA+X3FihXS4klcsEwG5xz4SAZSosSGIG4Ph GMX0GkFvSFGEePx0ogvjdLnqJarIDpYysgXl+gyXOBlFahHfeYqRECJ1+EAfbwBgBvPu SacCzLfsBB+sfbtgWOpsBqMF3pr6HLTLRFolStAJGQO4SUHUedR1ioY1zpFw9NF61BM2 kQBTjs/TaY7f35L3ZRAPMqay/H3KSa1F1OAFtsROF3FPMNFigfUoBQZUHn2QA6AQ+2NE CgQ1wMVirY/qz39rnxd3x+v+TBU9ftzK7Ro6EyR3316f3QpgFXnXnSTw1NyS0zveO8WB E2OA== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c26si4161416ejj.291.2021.08.30.03.33.04; Mon, 30 Aug 2021 03:33:27 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236312AbhH3Kcm (ORCPT + 99 others); Mon, 30 Aug 2021 06:32:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:36404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236269AbhH3Kcl (ORCPT ); Mon, 30 Aug 2021 06:32:41 -0400 Received: from jic23-huawei (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (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 40E6C610C7; Mon, 30 Aug 2021 10:31:46 +0000 (UTC) Date: Mon, 30 Aug 2021 11:34:57 +0100 From: Jonathan Cameron To: Miquel Raynal Cc: Lars-Peter Clausen , Thomas Petazzoni , linux-iio@vger.kernel.org, Subject: Re: [PATCH 12/16] iio: adc: max1027: Introduce an end of conversion helper Message-ID: <20210830113457.4acf12e2@jic23-huawei> In-Reply-To: <20210818111139.330636-13-miquel.raynal@bootlin.com> References: <20210818111139.330636-1-miquel.raynal@bootlin.com> <20210818111139.330636-13-miquel.raynal@bootlin.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 18 Aug 2021 13:11:35 +0200 Miquel Raynal wrote: > 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); Why here? This had me confused when I couldn't find it being introduced in the later patch that uses it. More comments in that patch. > + > +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);