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 B335CC27C4F for ; Wed, 26 Jun 2024 08:55:42 +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:MIME-Version: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Date:Cc:To:From :Subject:Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=UuJKZ5dvfnd3VwIG1aD3aPBKZXM0rYW+LOmM/rqRb7g=; b=I/AQ4SoHNQpxKlWiRQD5lNAhHv dRR+4vzwHw5WmRbKtSQCwm1j4M82oe/rj0DOFXz0tSFwhN2K2mh3ywKk9oprG8+NdEB3ovaRnGDfy hJCdREsCtSEc1KKNJ6KihxfazQMrQbi0ZGcHFRTs3xxiu2VKiikDT+iX3fFUd9QjVOUf7J++06U9U 2rJgBkT7uTJR09T0iAsrFIGvjZ1P6uYzu7RBb79bALnUn6Iqeho41Nv0fh3jBP1u0DGmgUuehrU6k E6lZ9vOT/4SjV0x1t20bQg2ms0EplvUft3iHsQEjEbfr+eJhrIrldc2RuDM/KbgSISblmn6SsNPvI XOAN8kDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMOR1-000000060Zc-3BI9; Wed, 26 Jun 2024 08:55:23 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMOQu-000000060Y8-42HH for linux-arm-kernel@lists.infradead.org; Wed, 26 Jun 2024 08:55:18 +0000 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-52cd8897c73so5286512e87.2 for ; Wed, 26 Jun 2024 01:55:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719392114; x=1719996914; darn=lists.infradead.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=UuJKZ5dvfnd3VwIG1aD3aPBKZXM0rYW+LOmM/rqRb7g=; b=IVWjnw0XFYjYtvVDA3yA/o9FhPpEpMGTpeHIhGCcGIV7gJ9oQuBWayQhuRkT+1J7J1 Xo/F8J/wcOASmwfZFKEFOWdl0A1+6As9j0YhBGZ9POrAUylzsi+MM/qYPAg1UMHSoklP +KcgvpuPLNLTRtb6Bbf1iIIetM/EvTAHg0BR2bvEPzquM4zx0jl8VvD2C3zDonb9zTPx itK4PhkNBYjBYFeXEcP7FWkGdx4nDJdHRTo+EOKg6eEE9uQz8KivQ8q4ry+d755ASTJT BjNH6fenvwd7oDNY34VBOnJ+zWkT1hqnHmgWoYFRka9K+kat797o+RSRzBkHQr1g7m4f 19zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719392114; x=1719996914; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=UuJKZ5dvfnd3VwIG1aD3aPBKZXM0rYW+LOmM/rqRb7g=; b=ktIXdNc5Np6i/k+thnolsPSrhk61o7J1NFk64KiKaTN0FDC2OH/5KpGYqoMFWEpPf0 +sx7V+QkcmbzBD4jFlvgGK4CDDHCAiZupbxFq/CfIBjI5STU/KphTcWJoQnV4Z5NVDdM HR//H5r5Ri0YOjJh7iabplI0cWCpFDbVYuZTQ856j4yfp93bVooNUHjWLbTPdpKRuxni gFOvZNgiPutnE7OE5hTrH/pSGuQOIbMd45uroXx+MMyPqKn1EhKMnYnY1gSZTPZ2fUFK BYkG9PGfhaF2xvdx0sOL3r1vR5AJkvC459HchhfIgu9/PKFIaUejFDxmJMHRBP1Yt41n i+4A== X-Forwarded-Encrypted: i=1; AJvYcCUNx/szuRelkzssFHXiY8LoIGycQAPKKQwMG1CAmIQB9d7elBc2kv0d2bTHIxdFVb/JZ/sTtShT85KkCPMb/zatgoboe8oqHNrYKYgZvcuy7ftu1V4= X-Gm-Message-State: AOJu0YxouOocSu8CxuorcodcaMEx64oHMgvzFNSaHyxzOZYAwOzAok5y uEQQ8rj0vqpjJt5OyvlILnXtfa6RUXBOtCL2NA+fqugkT6YpaABx X-Google-Smtp-Source: AGHT+IFuNqURBw9MrG0Gl9cJcVUawr+D9J6cKvNgIaK256nGX0K2iZmbGttOuH5LhAzrPbtCRpZWxA== X-Received: by 2002:a05:6512:138e:b0:52c:e08c:a0dc with SMTP id 2adb3069b0e04-52ce185f753mr7582925e87.51.1719392113740; Wed, 26 Jun 2024 01:55:13 -0700 (PDT) Received: from ?IPv6:2003:f6:ef1c:c500:ee59:d953:f148:40ba? (p200300f6ef1cc500ee59d953f14840ba.dip0.t-ipconnect.de. [2003:f6:ef1c:c500:ee59:d953:f148:40ba]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-424c8468613sm17302035e9.39.2024.06.26.01.55.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jun 2024 01:55:13 -0700 (PDT) Message-ID: Subject: Re: [PATCH v2 8/8] iio: adc: stm32-dfsdm: add scaling support to dfsdm From: Nuno =?ISO-8859-1?Q?S=E1?= To: Olivier Moysan , fabrice.gasnier@foss.st.com, Jonathan Cameron , Lars-Peter Clausen , Maxime Coquelin , Alexandre Torgue Cc: Nuno Sa , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Date: Wed, 26 Jun 2024 10:59:05 +0200 In-Reply-To: <20240625150717.1038212-9-olivier.moysan@foss.st.com> References: <20240625150717.1038212-1-olivier.moysan@foss.st.com> <20240625150717.1038212-9-olivier.moysan@foss.st.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240626_015517_087578_DD0A2E50 X-CRM114-Status: GOOD ( 18.71 ) 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 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. >=20 > When used in an analog context, a DFSDM filter typically converts the dat= a > 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. >=20 > With the new binding based on IIO backend framework, the sigma delta > modulators are defined as backends providing scaling information. >=20 > The scaling is not supported with legacy binding. >=20 > Signed-off-by: Olivier Moysan > Acked-by: Nuno Sa > --- >=20 ... > + > + 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 =3D realbits - 1. > + * This leads to underestimating the input voltage. > + * To compensate this deviation, the voltage reference can be > + * corrected with a factor =3D 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 handl= ing as iio_backend_read_raw() can return an error. > + *val =3D div_u64((u64)*val * (u64)BIT(DFSDM_DATA_RES - > 1), max); > + *val2 =3D chan->scan_type.realbits; > + if (chan->differential) > + *val *=3D 2; > + } > + return IIO_VAL_FRACTIONAL_LOG2; > + > + case IIO_CHAN_INFO_OFFSET: > + /* > + * DFSDM output data are in the range [-2^n, 2^n], > + * with n =3D 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 =3D 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=C3=A1