From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7EC58C433EF for ; Sat, 11 Jun 2022 17:39:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VdXNAEEFIjFOBzWxE1AAhLZSJ5Gc3xG+Wkur9YQ6m90=; b=GKs6D9zkjD3/KM cdBcIa7//6d0ybsHIF2wjsrXe/sxWTn2DPjnr92yIjhHywqDG7VtMraBbFSN5Nx3NXYOOd8hFyyjg jT6Cj/TVFSA9G47Tc2EzZ+zic0pnYCzu/zbqM0NRbtcNVteRu8cSGIX0VT2K7O+NPEfSxuJmWM9+k zWWF4fF2Uy00Y26O33mDIDYXpTrEXPd3mVPFPBqe8vAat+kEQ5s6DYpHaxVjZxf62I7IZfeCu72RA 0AKzXGnhZoYEUFvyOLDx0EagxPJXvj3AT3Wx8/0UctFQKFo60CIBSh6UytYWbvHdV4j2sTLCIOSNF 041Jau8XPxlT34Me+utQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o0549-00Dzds-LN; Sat, 11 Jun 2022 17:38:29 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o0546-00Dzcx-C5 for linux-arm-kernel@lists.infradead.org; Sat, 11 Jun 2022 17:38:28 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 12443B8068B; Sat, 11 Jun 2022 17:38:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EBADC3411C; Sat, 11 Jun 2022 17:38:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654969102; bh=2nO9YYrpb7HdXkesn/oDuP7eCP+sVOf/Q2uUIIPkQRM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=b3Ntjx/NxB8hmCkkd5ZaM1YnLRX5te7+JM3KNvP7zyAy6TXaEOYS8rnH2qdGZmL38 uL2RUbKeBe6D8byjYNnVqIjWNnmz5Db+dbvfBXViJmTqvFC4LeA/IFfN/0Ae5/xD91 kMrBV0BAVIAaOPS586Y09/jrqG8qLzRx3z7R7Dtfxxs7zykUlO3s/9lkpT2M/eJmi6 q7bvFRrrTVaYg6f+UcfuEHmUwTgFsjyhMT1tjT+7BW0H7VKrOVnEbWUUxpdUmhq7ZA 7rgF6djw/xmmCKTddxMh+7y/NOd6m7hq5vrTinj4GWkbuSpvy1g3RZyeatbQhgf2Hh gkTdZni0wNXFg== Date: Sat, 11 Jun 2022 18:47:31 +0100 From: Jonathan Cameron To: Claudiu Beznea Subject: Re: [PATCH 06/16] iio: adc: at91-sama5d2_adc: add 64 and 256 oversampling ratio Message-ID: <20220611184731.7c100a08@jic23-huawei> In-Reply-To: <20220609083213.1795019-7-claudiu.beznea@microchip.com> References: <20220609083213.1795019-1-claudiu.beznea@microchip.com> <20220609083213.1795019-7-claudiu.beznea@microchip.com> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220611_103826_767805_B5BB4AC2 X-CRM114-Status: GOOD ( 26.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, alexandre.belloni@bootlin.com, lars@metafoo.de, ludovic.desroches@atmel.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, eugen.hristev@microchip.com, krzk+dt@kernel.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 9 Jun 2022 11:32:03 +0300 Claudiu Beznea wrote: > Add 64 and 256 oversampling ratio support. It is necessary for temperature > sensor. > > Signed-off-by: Claudiu Beznea > --- > drivers/iio/adc/at91-sama5d2_adc.c | 31 +++++++++++++++++++++++++++--- > 1 file changed, 28 insertions(+), 3 deletions(-) > > diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c > index 7321a4b519af..b52f1020feaf 100644 > --- a/drivers/iio/adc/at91-sama5d2_adc.c > +++ b/drivers/iio/adc/at91-sama5d2_adc.c > @@ -142,6 +142,8 @@ struct at91_adc_reg_layout { > #define AT91_SAMA5D2_EMR_OSR_1SAMPLES 0 > #define AT91_SAMA5D2_EMR_OSR_4SAMPLES 1 > #define AT91_SAMA5D2_EMR_OSR_16SAMPLES 2 > +#define AT91_SAMA5D2_EMR_OSR_64SAMPLES 3 > +#define AT91_SAMA5D2_EMR_OSR_256SAMPLES 4 > > /* Extended Mode Register - Averaging on single trigger event */ > #define AT91_SAMA5D2_EMR_ASTE(V) ((V) << 20) > @@ -308,6 +310,8 @@ static const struct at91_adc_reg_layout sama7g5_layout = { > #define AT91_OSR_1SAMPLES 1 > #define AT91_OSR_4SAMPLES 4 > #define AT91_OSR_16SAMPLES 16 > +#define AT91_OSR_64SAMPLES 64 > +#define AT91_OSR_256SAMPLES 256 These defines seems a bit silly. Better to use the values inline than to have these. > > #define AT91_SAMA5D2_CHAN_SINGLE(index, num, addr) \ > { \ > @@ -640,7 +644,9 @@ static const struct at91_adc_platform sama7g5_platform = { > .osr_mask = GENMASK(18, 16), > .osr_vals = BIT(AT91_SAMA5D2_EMR_OSR_1SAMPLES) | > BIT(AT91_SAMA5D2_EMR_OSR_4SAMPLES) | > - BIT(AT91_SAMA5D2_EMR_OSR_16SAMPLES), > + BIT(AT91_SAMA5D2_EMR_OSR_16SAMPLES) | > + BIT(AT91_SAMA5D2_EMR_OSR_64SAMPLES) | > + BIT(AT91_SAMA5D2_EMR_OSR_256SAMPLES), > .chan_realbits = 16, > }; > > @@ -774,6 +780,18 @@ static int at91_adc_config_emr(struct at91_adc_state *st, > emr |= AT91_SAMA5D2_EMR_OSR(AT91_SAMA5D2_EMR_OSR_16SAMPLES, > osr_mask); > break; > + case AT91_OSR_64SAMPLES: > + if (!(osr_vals & BIT(AT91_SAMA5D2_EMR_OSR_64SAMPLES))) > + return -EINVAL; > + emr |= AT91_SAMA5D2_EMR_OSR(AT91_SAMA5D2_EMR_OSR_64SAMPLES, > + osr_mask); > + break; > + case AT91_OSR_256SAMPLES: > + if (!(osr_vals & BIT(AT91_SAMA5D2_EMR_OSR_256SAMPLES))) > + return -EINVAL; > + emr |= AT91_SAMA5D2_EMR_OSR(AT91_SAMA5D2_EMR_OSR_256SAMPLES, > + osr_mask); > + break; > } > > at91_adc_writel(st, EMR, emr); > @@ -791,6 +809,10 @@ static int at91_adc_adjust_val_osr(struct at91_adc_state *st, int *val) > nbits = 13; > else if (st->oversampling_ratio == AT91_OSR_16SAMPLES) > nbits = 14; > + else if (st->oversampling_ratio == AT91_OSR_64SAMPLES) > + nbits = 15; > + else if (st->oversampling_ratio == AT91_OSR_256SAMPLES) > + nbits = 16; > > /* > * We have nbits of real data and channel is registered as > @@ -1679,7 +1701,8 @@ static int at91_adc_write_raw(struct iio_dev *indio_dev, > switch (mask) { > case IIO_CHAN_INFO_OVERSAMPLING_RATIO: > if ((val != AT91_OSR_1SAMPLES) && (val != AT91_OSR_4SAMPLES) && > - (val != AT91_OSR_16SAMPLES)) > + (val != AT91_OSR_16SAMPLES) && (val != AT91_OSR_64SAMPLES) && > + (val != AT91_OSR_256SAMPLES)) Dropping this partial validity check and moving into a default in the switch statement in config_emr() would be nice cleanup (I also replied to earlier patch based on what is visible here). > return -EINVAL; > /* if no change, optimize out */ > mutex_lock(&st->lock); > @@ -1897,7 +1920,9 @@ static IIO_CONST_ATTR(hwfifo_watermark_max, AT91_HWFIFO_MAX_SIZE_STR); > static IIO_CONST_ATTR(oversampling_ratio_available, > __stringify(AT91_OSR_1SAMPLES) " " > __stringify(AT91_OSR_4SAMPLES) " " > - __stringify(AT91_OSR_16SAMPLES)); > + __stringify(AT91_OSR_16SAMPLES) " " > + __stringify(AT91_OSR_64SAMPLES) " " > + __stringify(AT91_OSR_256SAMPLES)); At somepoint it would be good to move this over to the read_avail() callback rather than hand rolling it. We are slowly working through doing this for all the IIO drivers but it will take a long time yet! > > static struct attribute *at91_adc_attributes[] = { > &iio_const_attr_oversampling_ratio_available.dev_attr.attr, _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel