From patchwork Thu Jun 9 08:32:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 12875006 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 51681C43334 for ; Thu, 9 Jun 2022 08:34:38 +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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kNq7dVFOPsnLFid8hgAmNpxi28VGMKQiOWDTB3P9FCY=; b=u+ZFCKmqDlIg6l IR0x+Xr2+HeiCR/j9i9/0DYjUjsk5nD6Dx/rixoCPg6BXljsqLlPrB1zM4BfyWt0ZVbEmMG5cANXr UMzrB5yBTs1zDYCD2qSXDbvImmZaXa3IpFxOSsbPDsiEK3hbyeqLqCC4yTkOONUXIIUKVa1LiVf8Y Ijhk3Xq3+9axA3PgbquAELeft69Y1hADxSwdR1Klkonp7oeOqRkHE6eBhZ1dauSfBKKTnFZxfNSvi xYQnaRSGLkbpL3zA+bkNAWvG08YhBJNQ0Rz2AhvsWYkld6ph47J1Gz49g8brDHD25HySVHwbnfiCI lnlWz6vPX/o1nUD7e9QQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzDbX-000Gnv-0C; Thu, 09 Jun 2022 08:33:23 +0000 Received: from esa.microchip.iphmx.com ([68.232.154.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzDYc-000FR3-0m for linux-arm-kernel@lists.infradead.org; Thu, 09 Jun 2022 08:30:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1654763422; x=1686299422; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=77ZWqA+4UaqVdZ24io5cE1ntvgewfYNdW+CZyfcvoQY=; b=E2FuYSIaqgEDNATfNCYVvJis4TH9ibzblumsYPDM7k8VaP3V/xHuxurF KsoUmkyZMstgLTGTRgpZRVxyHJrxrfp28AxsElsI7uU4601ppGLLnha5e MRkyfGhjcMSrkKlOvJNDY88MzgdOLIk0wVuigFqxqpZ1xqvM0kQ8g68/T P3dKq2GDjnIkTUOFfzw6asHmMPemcvr1eqEA5hnuAgIE7Sfz/ZK2xHqZy S7R8A+ijr2TBI9Gx3u5BwRig4DxZtz0l6nBwN1Wd2KUXDW6GLwSTTw/gv TSydKaPSXIs1jo8P/ipzUqWpMfnT5eI6lPcDyiDlyiHEo1j42e1Wk1OZ6 Q==; X-IronPort-AV: E=Sophos;i="5.91,287,1647327600"; d="scan'208";a="99259938" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 09 Jun 2022 01:30:20 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.87.72) by chn-vm-ex02.mchp-main.com (10.10.87.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Thu, 9 Jun 2022 01:30:14 -0700 Received: from localhost.localdomain (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Thu, 9 Jun 2022 01:30:11 -0700 From: Claudiu Beznea To: , , , , , , , CC: , , , , Claudiu Beznea Subject: [PATCH 06/16] iio: adc: at91-sama5d2_adc: add 64 and 256 oversampling ratio Date: Thu, 9 Jun 2022 11:32:03 +0300 Message-ID: <20220609083213.1795019-7-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220609083213.1795019-1-claudiu.beznea@microchip.com> References: <20220609083213.1795019-1-claudiu.beznea@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220609_013022_379579_0F6706C6 X-CRM114-Status: GOOD ( 12.69 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 #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)) 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)); static struct attribute *at91_adc_attributes[] = { &iio_const_attr_oversampling_ratio_available.dev_attr.attr,