From patchwork Fri Jun 23 14:09:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Moysan X-Patchwork-Id: 13290664 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 ACD83EB64D7 for ; Fri, 23 Jun 2023 14:12:17 +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: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:In-Reply-To:References: List-Owner; bh=zll69kMS5B6tr2IRDAxMojL3AfNjn83oIP/dvJ2b+C8=; b=GH0eLWk3aUZ1gU mgzbfKQGEcK5DxPpemvSMQi8mzY+kgv4pzMCy2dLzuVHsFzf/EN/ADkEmYGSxabikib9+sgu+3j97 RYQeZjQaq6RrGaaeq6rz9HkfLibTa32CuWT52zQBk+MVrj4MFAoSMSG4g9uTZg167Kc1kF6yvToZN ZvKlU0W4hoCoixMBiX1fK8vQho+1ykiN3ApLJO/0XB9uTGjIEWfMqYv/hUk3PktZF/MSx/FOEOaOq ctJ2wIZguFFZ+eRPjgTKoUQ6vct7MCihkWQnc2lJmkcaXysrzDS0WUOv94PZdeDj4ELWYsA082tHy BYjUjy8mfRCaYLxmmjuA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qChVn-003ioV-2Z; Fri, 23 Jun 2023 14:11:43 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qChVj-003inV-2O for linux-arm-kernel@lists.infradead.org; Fri, 23 Jun 2023 14:11:41 +0000 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35NDEZCt004204; Fri, 23 Jun 2023 16:11:27 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=selector1; bh=zLkUeXmL+Ow+eXO/4Kk5UPFmY47fOCK359xSbjwsIEE=; b=Qdu1MOMXtdPoz1WyVmRnGhYiRajVMKK2eslEUyO/ReiXGux03z/2GGzN3/JDCRRexU1y 83rTc+q/qijDOsaLFHWkH2LkSraGiCGIfRJw6TFPXPDByFxiT8YgaBLhBm4+6Dh2liT9 Xkzn4Szdf7jnfwMlwzLyolY2DZE0+0k+XHitFhcor2bMXcix3W8G7W890BeBoHbECXc2 9g9iFqf7tOBmOCGE02uT/AKsquR1hvQHjX0blJ82xmnmLCNmnQABETIFm4hdBkqoVPaF +a9F+53jfxfykTE/AR2PmtJjPOK/KAADLGp8r0aPK8s7lP4EMHl1kxngDO9faO559ivu 4Q== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3rdc3w0ddf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 23 Jun 2023 16:11:27 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 51C9A10002A; Fri, 23 Jun 2023 16:11:25 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 472DD22AFEC; Fri, 23 Jun 2023 16:11:25 +0200 (CEST) Received: from localhost (10.252.5.198) 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.21; Fri, 23 Jun 2023 16:11:25 +0200 From: Olivier Moysan To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Maxime Coquelin , Alexandre Torgue , Jonathan Cameron , Lars-Peter Clausen , Frank Rowand , Liam Girdwood , Mark Brown CC: Olivier Moysan , , , , , Subject: [RFC PATCH 0/7] iio: add iio backend device type Date: Fri, 23 Jun 2023 16:09:36 +0200 Message-ID: <20230623140944.2613002-1-olivier.moysan@foss.st.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.252.5.198] X-ClientProxiedBy: EQNCAS1NODE4.st.com (10.75.129.82) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-23_08,2023-06-22_02,2023-05-22_02 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230623_071140_373149_69E58D62 X-CRM114-Status: GOOD ( 20.07 ) 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 This RFC re-opens an old discussion regarding channel scaling management in STM32 DFSDM driver [1] The DFSDM is a peripheral provided by the STM32MP1x SoC family. One objective is also to prepare the introduction of its successor in the STM32MP12x SoC family: the MDF (Multi-function Digital Filter). The MDF driver will have the same requirements as the DFSDM regarding channel scaling management. So, the solution proposed here will apply also for the future MDF driver. [1] https://patchwork.kernel.org/project/linux-iio/patch/20200204101008.11411-5-olivier.moysan@st.com/ As a short reminder of our previous discussion, the two main options emerging were the following ones: - Option1: Use the DFSDM as an hardware accelerator and expose the scaled channels on SD modulator side. Drawbak: this solution is leading to an very complex datapath, especially for scan mode. - Option2: Introduce a new IIO device type (so-called backend) Retrieve scaling information from SD modulator scaling to expose a single IIO device on DFSDM side. This solution is derivated from rcar-gyroadc example, but with a more standard approach. This was discussed in https://lore.kernel.org/lkml/20210919191414.09270f4e@jic23-huawei/ The patchset proposed in this RFC implements option2 (backend) solution. These patches provide a minimal API implemented as a template. The intented use of this API is illustrated through the DFSDM channel scaling support basic implementation. For sake of simplicity I did not include the related DT binding in this serie. Below are some use case examples. * DFSDM with SD modulator backend: ------------------------------- This use case corresponds to the example implemented in this RFC. The channel attributes are retrieved from backend by the dfsdm, and the resulting scaling is exposed through DFSDM IIO device sysfs - Single channel: +-------------+ ch attr +--------+ sysfs (compound scaling) | sd0 backend | ---------> | dfsdm0 | --------------------------> +-------------+ +--------+ - Scan mode: +-------------+ ch attr +-------------+ sysfs (compound scaling) | sd1 backend | ---------> | dfsdm1 | --------------------------> +-------------+ +-------------+ ^ | +-------------+ ch attr | | sd2 backend |--------------+ +-------------+ * Voltage divider in front of an adc: ---------------------------------- By way of example, here is a comparison on scaling management with a iio-rescale device, and how it could be managed with a backend device. - iio-rescale implementation Scaling is exposed both on ADC and iio-rescale IIO devices. On iio-rescale device we get the compound scaling +---------------------------+ ch attr +------+ sysfs | iio-rescale (div) | <--------- | adc0 | -------> +---------------------------+ +------+ | | sysfs (compound scaling) v - Backend implementation: Compound scaling is exposed on ADC IIO device. No scaling exposed on backend device +---------------+ ch attr +------+ sysfs (compound scaling) | backend (div) | ---------> | adc0 | --------------------------> +---------------+ +------+ * Cascaded backends: ----------------- Backends may be cascaded to allow computation of the whole chain scaling This is not part of this RFC, but it is identified as a potential future use case. +---------------+ attr +-------------+ attr +--------+ sysfs | backend (div) | ------> | sd0 backend | ------> | dfsdm0 | -------> +---------------+ +-------------+ +--------+ Olivier Moysan (7): iio: introduce iio backend device of: property: add device link support for io-backends iio: adc: stm32-dfsdm: manage dfsdm as a channel provider iio: adc: stm32-dfsdm: adopt generic channel bindings iio: adc: sd_adc_modulator: change to iio backend device iio: adc: stm32-dfsdm: add scaling support to dfsdm ARM: dts: stm32: add dfsdm iio suppport arch/arm/boot/dts/stm32mp157c-ev1.dts | 62 +++++++++ drivers/iio/Makefile | 2 + drivers/iio/adc/sd_adc_modulator.c | 92 +++++++++++--- drivers/iio/adc/stm32-dfsdm-adc.c | 176 ++++++++++++++++---------- drivers/iio/industrialio-backend.c | 59 +++++++++ drivers/of/property.c | 2 + include/linux/iio/backend.h | 29 +++++ 7 files changed, 336 insertions(+), 86 deletions(-) create mode 100644 drivers/iio/industrialio-backend.c create mode 100644 include/linux/iio/backend.h