From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 475EF606A325 for ; Thu, 19 Nov 2026 09:45:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=TvOfjsY7; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=EvV7duoT 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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=YqeiPLfNjKXmPyvzUWMnk9Cqa9JDVTCN0McxrwDNA9g=; b=TvOfjsY7zZSC2f7/IWwBq0iirp yggzJVASp6FGczpahufT85mHx9wwjMHB9XjPXGG3C1Va13/z86xKq2zm9TD6/Mpq3JQPGiaoY90yy 3YL/+1thewtvESRwyBJ9xZNwJVL500bWfRBc8/b9w0ti+mWRUw34ZxpIoaGayP4wL/QwmDKU2u2ub cJ5lmRKC68bNDrL5zZ7LAe2s105rN8DJTzGblZm92kebxON33kNGj9LSva7FaoUUiK8dXs7lhqEaY fw2j61JOvWa53Cz7mwVwc3w+3w5Wbqwl7C3D21whM7Aj0pMp2pOLVuULChvY5H8IklXPLBfRt6RGb NDq0MFTw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xTyhS-0000000BR1p-0fYL; Thu, 19 Nov 2026 09:45:02 +0000 Received: from mgamail.intel.com ([192.198.163.12]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xTyhN-0000000BR0t-3IOY for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2026 09:45:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1795081498; x=1826617498; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=GrxUehPYuAdZ9/RKMpHXF+LGSfBV45QK6OO7c7G2neU=; b=EvV7duoTSpCF2EYDVBraUTAGtYjZBDy3+oMP7jUincYQ1n/pDjZg4pcp mliOjgW7gBX01G4n6Mld9QNGl6rR3i292PPrWLjHdn1oJ6JJjYe2O2zg8 pjEYFzusyqSljX1DzRdmg2s5+MUWn2qUcSjHvweaRFeh9hHevhJ+zYLYS k890mwGFG0Van+J2eEwHWIKF350C2cTKC4onAzwqW4ZdnqGK0cJ4eK5TJ 57ICZH30DeWdzekAB+3rM2eOI1TdASWNDqI4rLYFRPEAxlz/Q1U0CA6// hrzEmo7GT2E/+eLk0/s4Q1i/rPItAiGNM52tq2yQZUlWj8PdumOgnUAEL A==; X-CSE-ConnectionGUID: 7nEcEmI3RQ2GX1mYPOioWg== X-CSE-MsgGUID: gDsisPDpTEmV0cnoDMSO3g== X-IronPort-AV: E=McAfee;i="6800,10657,11970"; a="3815570" X-IronPort-AV: E=Sophos;i="6.27,220,1787036400"; d="scan'208";a="3815570" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Nov 2026 01:44:54 -0800 X-CSE-ConnectionGUID: KydEFDI0RQGTZj/DOyvsjA== X-CSE-MsgGUID: Sh455h9HQyyJ4OnK67pEcg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,220,1787036400"; d="scan'208";a="10196106" Received: from klitkey1-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.245.61]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Nov 2026 01:44:47 -0800 Date: Thu, 19 Nov 2026 11:44:45 +0200 From: Andy Shevchenko To: Olivier Moysan Cc: Jonathan Cameron , David Lechner , Nuno =?iso-8859-1?Q?S=E1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Maxime Coquelin , Alexandre Torgue , Philipp Zabel , Sumit Semwal , Christian =?iso-8859-1?Q?K=F6nig?= , Philipp Stanner , Arnaud Pouliquen , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Fabrice Gasnier , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-sound@vger.kernel.org Subject: Re: [PATCH v2 02/11] iio: adc: stm32-mdf: add core registration Message-ID: References: <20261118-upstream_mdf_v2-v2-0-7939d3c3720a@foss.st.com> <20261118-upstream_mdf_v2-v2-2-7939d3c3720a@foss.st.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261118-upstream_mdf_v2-v2-2-7939d3c3720a@foss.st.com> Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261119_014458_237891_2530D388 X-CRM114-Status: GOOD ( 34.87 ) X-Spam-Score: -4.4 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-5.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Wed, Nov 18, 2026 at 04:17:47PM +0100, Olivier Moysan wrote: > The STM32 multifunction digital filter (MDF) shares its register bank, > kernel clock and power resources between serial interfaces and digital > filters. Add a core driver to manage these common resources on STM32MP2. > > Check the number of filter actually supported from identification > registers. ... > +config STM32_MDF_CORE > + tristate "STMicroelectronics STM32 MDF core" > + depends on (ARCH_STM32 && OF) || COMPILE_TEST Why OF? > + depends on COMMON_CLK > + select REGMAP Redundant. > + select REGMAP_MMIO > + help > + Select this option to enable the driver for STMicroelectronics > + STM32 Multi-function Digital Filter for sigma delta converter. > + > + This driver can also be built as a module. If so, the module > + will be called stm32-mdf. Broken indentation in the last line. ... > +/* > + * This file is part of STM32 MDF driver Better to be more explicit. "This is the core part of ..." > + * Copyright (C) 2023-2026, STMicroelectronics - All Rights Reserved > + * Author: Olivier Moysan . > + */ ... > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include Oh, really all of them are required? > +#include > +#include > +#include > +#include > +#include Missing types.h at least. Please follow IWYU principle. > +#include "stm32-mdf.h" ... > +static bool stm32_mdf_core_volatile_reg(struct device *dev, unsigned int reg) > +{ > + /* > + * In MDF_CKGCR_REG register only CKGACTIVE bit is volatile. MDF_CKGCR_REG is not marked > + * as volatible to ease the suspend/resume case, and benefit from the regcache API. > + * Access to CKGACTIVE bit is managed specifically instead. > + */ Why file is using 80 limit and comments 100? Be consistent! > + return false; > +} ... > +static const struct regmap_config stm32_mdf_regmap_cfg = { > + .reg_bits = 32, > + .val_bits = 32, > + .reg_stride = sizeof(u32), > + .max_register = MDF_SIDR_REG, > + .readable_reg = stm32_mdf_core_readable_reg, > + .volatile_reg = stm32_mdf_core_volatile_reg, > + .writeable_reg = stm32_mdf_core_writeable_reg, > + .num_reg_defaults_raw = MDF_SIDR_REG / sizeof(u32) + 1, ARRAY_SIZE()? > + .fast_io = true, > + .cache_type = REGCACHE_FLAT, > +}; ... > +struct stm32_mdf_priv { > + struct stm32_mdf mdf; > + struct platform_device *pdev; Why?! > + struct regmap *regmap; > + struct clk *kclk; > + void __iomem *base; > + phys_addr_t phys_base; > + atomic_t n_active_ch; > + spinlock_t lock; /* Manage common resources race conditions */ > + unsigned long kclk_rate; Units? _Hz? Why not group it with kclk above? > + bool exclusive_flg; > +}; ... > +static inline struct stm32_mdf_priv *to_stm32_mdf_priv(struct stm32_mdf *mdf) > +{ > + return container_of(mdf, struct stm32_mdf_priv, mdf); + container_of.h > +} ... > +int stm32_mdf_core_start_mdf(struct stm32_mdf *mdf) > +{ > + struct stm32_mdf_priv *priv = to_stm32_mdf_priv(mdf); > + struct device *dev = &priv->pdev->dev; > + int ret; > + u32 val; regmap uses unsigned int. > + > + if (atomic_inc_return(&priv->n_active_ch) == 1) { > + ret = pm_runtime_resume_and_get(dev); > + if (ret < 0) > + goto err; > + > + /* Enable PROCDIV and CCKDIV clock dividers */ > + ret = regmap_set_bits(priv->regmap, MDF_CKGCR_REG, MDF_CKG_CKGDEN); > + if (ret < 0) > + goto pm_put; > + > + /* Check clock status. Bypass cache to access volatile CKGACTIVE active bit */ > + regcache_cache_bypass(priv->regmap, true); > + regmap_read(priv->regmap, MDF_CKGCR_REG, &val); > + regcache_cache_bypass(priv->regmap, false); > + if (!(val & MDF_CKG_ACTIVE)) { > + ret = -EINVAL; > + dev_err(dev, "MDF clock not active\n"); > + goto pm_put; > + } > + > + if (!priv->exclusive_flg) { > + clk_rate_exclusive_get(priv->kclk); > + priv->exclusive_flg = true; > + } > + } > + > + return 0; > + > +pm_put: > + pm_runtime_put_sync(dev); > +err: > + atomic_dec(&priv->n_active_ch); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(stm32_mdf_core_start_mdf); No namespace? ... > +int stm32_mdf_core_trigger(struct stm32_mdf *mdf) > +{ > + struct stm32_mdf_priv *priv = to_stm32_mdf_priv(mdf); > + int ret; > + u32 val; As per above. > + guard(spinlock)(&priv->lock); > + > + /* Bypass cache to access TRGO volatile bit */ > + regcache_cache_bypass(priv->regmap, true); > + > + ret = regmap_read(priv->regmap, MDF_GCR_REG, &val); > + if (ret < 0) Why ' < 0' ? > + goto err; > + > + if (val & MDF_GCR_TRGO) { > + ret = -EBUSY; > + goto err; > + } > + > + ret = regmap_set_bits(priv->regmap, MDF_GCR_REG, MDF_GCR_TRGO); > + > +err: > + regcache_cache_bypass(priv->regmap, false); > + > + return ret; > +} ... > +int stm32_mdf_core_stop_mdf(struct stm32_mdf *mdf) > +{ > + struct stm32_mdf_priv *priv = to_stm32_mdf_priv(mdf); > + int ret = 0; Top assignments like this one is harder to maintain. And they might lead to subtle errors. > + if (atomic_dec_and_test(&priv->n_active_ch)) { > + if (priv->exclusive_flg) { > + clk_rate_exclusive_put(priv->kclk); > + priv->exclusive_flg = false; > + } > + > + ret = regmap_clear_bits(priv->regmap, MDF_CKGCR_REG, MDF_CKG_CKGDEN); > + > + pm_runtime_put_sync(&priv->pdev->dev); return ret; > + } > + > + return ret; return 0; > +} ... > +static int stm32_mdf_core_parse_of(struct platform_device *pdev, struct stm32_mdf_priv *priv) Oh my... In the name _of_ is present, in the code device property API is used, the inclusion block includes set of rarely required of_*.h! Please, fix this mess. > +{ > + struct device_node *node = pdev->dev.of_node; Why?! > + struct reset_control *rst; > + struct device *dev = &pdev->dev; > + u32 count; > + int ret; > + if (!node) > + return -EINVAL; Do we really need this (or at least why here?)? > + rst = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL); > + if (IS_ERR(rst)) > + return dev_err_probe(dev, PTR_ERR(rst), "Failed to get reset controller\n"); > + > + ret = reset_control_reset(rst); > + if (ret) > + return dev_err_probe(dev, ret, "Failed to reset MDF\n"); > + > + ret = stm32_mdf_core_parse_clocks(pdev, priv); > + if (ret < 0) > + return ret; > + > + if (device_property_present(&pdev->dev, "st,interleave")) { > + ret = device_property_read_u32(dev, "st,interleave", &count); > + if (ret) > + return dev_err_probe(dev, ret, > + "Failed to read interleaved filter count\n"); > + > + if (count < 2 || count > 8 || count > priv->mdf.nbf) > + return dev_err_probe(dev, -EINVAL, > + "Invalid interleaved filter count [%u]\n", count); > + > + priv->mdf.nb_interleave = count; > + > + /* Configure GCR */ > + ret = regmap_update_bits(priv->regmap, MDF_GCR_REG, > + MDF_GCR_ILVNB_MASK, > + FIELD_PREP(MDF_GCR_ILVNB_MASK, count - 1)); > + } > + return ret; This is unusual. Just make return early and return 0 on success. > +} ... > +static const struct of_device_id stm32_mdf_of_match[] = { > + { .compatible = "st,stm32mp23-mdf", .data = (void *)STM32_MDF_MP23_FILTER_NB }, > + { .compatible = "st,stm32mp25-mdf" }, Make both provide chip_info and not some constant. > + {} Follow the common style (space inside). > +}; ... > +static int stm32_mdf_core_identification(struct platform_device *pdev, struct stm32_mdf_priv *priv) > +{ > + struct stm32_mdf *mdf = &priv->mdf; > + u32 val; > + int ret; > + > + /* If filter number is explicitly defined, don't check identification registers */ > + mdf->nbf = ((unsigned long)device_get_match_data(&pdev->dev)); Outer parentheses make no sense at all. > + if (mdf->nbf) > + return 0; No, return -ENODATA and make sure you provide chip_info for all of the components. > + ret = regmap_read(priv->regmap, MDF_IPIDR_REG, &val); > + if (ret) > + return ret; > + > + if (val == STM32MP25_MDF_IPIDR_NUMBER) { > + ret = regmap_read(priv->regmap, MDF_HWCFGR_REG, &val); > + if (ret) > + return ret; > + > + mdf->nbf = FIELD_GET(MDF_HWCFGR_NBF_MASK, val); > + > + ret = regmap_read(priv->regmap, MDF_VERR_REG, &val); This ret is not used? > + dev_dbg(&pdev->dev, "MDF version: %lu.%lu\n", FIELD_GET(MDF_VERR_MAJREV_MASK, val), > + FIELD_GET(MDF_VERR_MINREV_MASK, val)); > + } else { > + dev_err(&pdev->dev, "Unexpected ID number: 0x%x\n", val); > + return -EINVAL; > + } > + > + return 0; > +} ... > +static int stm32_mdf_core_probe(struct platform_device *pdev) > +{ struct device *dev = &pdev->dev; > + struct stm32_mdf_priv *priv; > + struct resource *res; > + int ret; > + > + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); > + if (!priv) > + return -ENOMEM; > + priv->pdev = pdev; > + spin_lock_init(&priv->lock); > + > + priv->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); > + if (IS_ERR(priv->base)) > + return PTR_ERR(priv->base); > + priv->phys_base = res->start; > + > + priv->kclk = devm_clk_get(&pdev->dev, NULL); > + if (IS_ERR(priv->kclk)) > + return dev_err_probe(&pdev->dev, PTR_ERR(priv->kclk), > + "Failed to get kernel clock\n"); > + priv->mdf.kclk = priv->kclk; > + > + priv->regmap = stm32_mdf_regmap_init(&pdev->dev, priv->kclk, priv->base, > + &stm32_mdf_regmap_cfg); > + if (IS_ERR(priv->regmap)) > + return dev_err_probe(&pdev->dev, PTR_ERR(priv->regmap), > + "Regmap init error\n"); > + > + ret = stm32_mdf_core_identification(pdev, priv); > + if (ret < 0) > + return ret; > + > + ret = stm32_mdf_core_parse_of(pdev, priv); > + if (ret < 0) > + return ret; > + > + INIT_LIST_HEAD(&priv->mdf.filter_list); > + > + platform_set_drvdata(pdev, priv); > + > + pm_runtime_get_noresume(&pdev->dev); > + pm_runtime_set_active(&pdev->dev); > + pm_runtime_enable(&pdev->dev); > + ret = of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev); dev_of_node(dev) > + if (ret) > + goto pm_put; Yeah, if needed, this is the only thing that needs of.h and of_platform.h IIUC. > + pm_runtime_put(&pdev->dev); > + > + return 0; > + > +pm_put: > + pm_runtime_disable(&pdev->dev); > + pm_runtime_set_suspended(&pdev->dev); > + pm_runtime_put_noidle(&pdev->dev); > + > + return ret; > +} ... > +static const struct dev_pm_ops stm32_mdf_core_pm_ops = { > + SET_SYSTEM_SLEEP_PM_OPS(stm32_mdf_core_suspend, stm32_mdf_core_resume) > + SET_RUNTIME_PM_OPS(stm32_mdf_core_runtime_suspend, stm32_mdf_core_runtime_resume, NULL) > +}; Use modern way of representing PM callbacks. ... > +static struct platform_driver stm32_mdf_driver = { > + .probe = stm32_mdf_core_probe, > + .remove = stm32_mdf_core_remove, > + .driver = { > + .name = "stm32-mdf", > + .of_match_table = stm32_mdf_of_match, > + .pm = &stm32_mdf_core_pm_ops, > + }, > +}; > + Drop this blank line. > +module_platform_driver(stm32_mdf_driver); ... I stopped here, this series need much more work, please study existing drivers in IIO for the modern style and APIs they are using. Also make code be consistent. -- With Best Regards, Andy Shevchenko