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 DCCA1C27C4F for ; Wed, 26 Jun 2024 16:16:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:CC:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=0K6g4n5PAuZsVsxr2X9hg3rFa4+lIJuxNGEgIloS7DY=; b=HQIefqBkMKzCif1+4527N7rNbN HxplQqycfFSJYRx6ttIB9RiaREqXIytFdWIazFKmuVtGwP1FKcGhCK01w5cRKjyDEcfDoqxw9Y8hf aoil6u+irKkwXxMWKc9MljEedY7TinQ/m1gc2OgSXVmUk/pzV/0vi7uUF/I/Kr4f5EIkhvrbxaxfL eXr+qP0ZmhvCPgtZkcjTPHiO6ivVs6ry7KDF9NzZHxCp78dXm99jCCt1J+GS+1a0FfweIv44fMrmv RVeiRczu4YPbizNyyotOLqOUsjdUjjF4MM7EhyyhzLZpDX/ExkGES9lqReZ9mScQQE5rQCxxXYr1K SK0H51Aw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMVJq-00000007Yp7-1a77; Wed, 26 Jun 2024 16:16:26 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMVJg-00000007YkW-367N for linux-arm-kernel@lists.infradead.org; Wed, 26 Jun 2024 16:16:19 +0000 Received: from pps.filterd (m0369457.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45QBLI8W023451; Wed, 26 Jun 2024 18:16:04 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=selector1; bh= 0K6g4n5PAuZsVsxr2X9hg3rFa4+lIJuxNGEgIloS7DY=; b=EyU3L10newAuzHTN t+Bk/jwsZdFiq35Ki6JMbOWT/srmka8vs5v3dGLrPN1f2vgDh4bARIsJwKAPl1gD +byra0tGSKKY0YEIASQBi+4YhVB9fmx/YkP8zE+xfV7M8Z5bcfVz5uhbydJKwNO0 rbJ1sc5LkcLyXL+c3laPCTd6jAS3TriBJPUqCt8U7llRbUxwJ71BQEXE9F1zLV3b EQ9IToEVMJJZjz25/NPeAq6ipKdJnU28mUh+eX8EORs/xWvYhPBYPm7fBxhpCI1p 2gr1f701xzjpdKcazRMsEoUX/RcHq6s35/AB543kKUFoZsUxQ7nkCLe6VSvxfyM/ myhAmw== Received: from beta.dmz-ap.st.com (beta.dmz-ap.st.com [138.198.100.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3yx9jjest7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Jun 2024 18:16:03 +0200 (MEST) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 633E340044; Wed, 26 Jun 2024 18:15:54 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id C59B62291CA; Wed, 26 Jun 2024 18:15:16 +0200 (CEST) Received: from [10.252.26.2] (10.252.26.2) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 26 Jun 2024 18:15:16 +0200 Message-ID: <7125491f-880c-486e-b417-8fc1e0c20c88@foss.st.com> Date: Wed, 26 Jun 2024 18:15:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 8/8] iio: adc: stm32-dfsdm: add scaling support to dfsdm To: =?UTF-8?Q?Nuno_S=C3=A1?= , , Jonathan Cameron , Lars-Peter Clausen , Maxime Coquelin , Alexandre Torgue CC: Nuno Sa , , , , References: <20240625150717.1038212-1-olivier.moysan@foss.st.com> <20240625150717.1038212-9-olivier.moysan@foss.st.com> Content-Language: en-US From: Olivier MOYSAN In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.252.26.2] X-ClientProxiedBy: SHFCAS1NODE1.st.com (10.75.129.72) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-26_07,2024-06-25_01,2024-05-17_01 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240626_091617_784894_7AEAE9F3 X-CRM114-Status: GOOD ( 18.00 ) 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 Hi Nuno, On 6/26/24 10:59, Nuno Sá wrote: > Hi Olivier, > > One thing that I just noticed... > > On Tue, 2024-06-25 at 17:07 +0200, Olivier Moysan wrote: >> Add scaling support to STM32 DFSDM. >> >> When used in an analog context, a DFSDM filter typically converts the data >> from a sigma delta modulator. The IIO device associated to the DFSDM >> filter provides these data as raw data. >> The IIO device can provide scaling information (voltage and offset) to >> allow conversion of raw data into physical values. >> >> With the new binding based on IIO backend framework, the sigma delta >> modulators are defined as backends providing scaling information. >> >> The scaling is not supported with legacy binding. >> >> Signed-off-by: Olivier Moysan >> Acked-by: Nuno Sa >> --- >> > > ... > >> + >> + case IIO_CHAN_INFO_SCALE: >> + /* >> + * Scale is expressed in mV. >> + * When fast mode is disabled, actual resolution may be lower >> + * than 2^n, where n = realbits - 1. >> + * This leads to underestimating the input voltage. >> + * To compensate this deviation, the voltage reference can be >> + * corrected with a factor = realbits resolution / actual max >> + */ >> + if (adc->backend[idx]) { >> + iio_backend_read_raw(adc->backend[idx], chan, val, >> val2, mask); > > Eve if it does not matter for your usecase, you should still do error handling > as iio_backend_read_raw() can return an error. > Ack. On the same occasion, I will switch to a dedicated API. Olivier >> + *val = div_u64((u64)*val * (u64)BIT(DFSDM_DATA_RES - >> 1), max); >> + *val2 = chan->scan_type.realbits; >> + if (chan->differential) >> + *val *= 2; >> + } >> + return IIO_VAL_FRACTIONAL_LOG2; >> + >> + case IIO_CHAN_INFO_OFFSET: >> + /* >> + * DFSDM output data are in the range [-2^n, 2^n], >> + * with n = realbits - 1. >> + * - Differential modulator: >> + * Offset correspond to SD modulator offset. >> + * - Single ended modulator: >> + * Input is in [0V, Vref] range, >> + * where 0V corresponds to -2^n, and Vref to 2^n. >> + * Add 2^n to offset. (i.e. middle of input range) >> + * offset = offset(sd) * vref / res(sd) * max / vref. >> + */ >> + if (adc->backend[idx]) { >> + iio_backend_read_raw(adc->backend[idx], chan, val, >> val2, mask); > > Same... > > - Nuno Sá