From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Olivier Moysan <olivier.moysan@foss.st.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
"Philipp Zabel" <p.zabel@pengutronix.de>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Philipp Stanner" <phasta@kernel.org>,
"Arnaud Pouliquen" <arnaud.pouliquen@foss.st.com>,
"Liam Girdwood" <lgirdwood@gmail.com>,
"Mark Brown" <broonie@kernel.org>,
"Jaroslav Kysela" <perex@perex.cz>,
"Takashi Iwai" <tiwai@suse.com>,
"Fabrice Gasnier" <fabrice.gasnier@foss.st.com>,
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
Date: Thu, 19 Nov 2026 11:44:45 +0200 [thread overview]
Message-ID: <av7FDVDUH9EvNJmQ@ashevche-desk.local> (raw)
In-Reply-To: <20261118-upstream_mdf_v2-v2-2-7939d3c3720a@foss.st.com>
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 <olivier.moysan@foss.st.com>.
> + */
...
> +#include <linux/cleanup.h>
> +#include <linux/clk.h>
> +#include <linux/device.h>
> +#include <linux/list.h>
> +#include <linux/module.h>
> +#include <linux/of_address.h>
> +#include <linux/of_device.h>
> +#include <linux/of_platform.h>
Oh, really all of them are required?
> +#include <linux/pinctrl/consumer.h>
> +#include <linux/pm_runtime.h>
> +#include <linux/platform_device.h>
> +#include <linux/regmap.h>
> +#include <linux/reset.h>
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
next prev parent reply other threads:[~2026-11-19 9:45 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 15:17 [PATCH v2 00/11] iio: adc: stm32: add mdf support for stm32mp2 Olivier Moysan
2026-11-18 15:17 ` [PATCH v2 01/11] dt-bindings: iio: adc: add stm32mp2 mdf filter Olivier Moysan
2026-11-18 15:17 ` [PATCH v2 02/11] iio: adc: stm32-mdf: add core registration Olivier Moysan
2026-11-18 15:45 ` sashiko-bot
2026-11-19 9:44 ` Andy Shevchenko [this message]
2026-11-20 21:17 ` kernel test robot
2026-11-18 15:17 ` [PATCH v2 03/11] iio: adc: stm32-mdf: add cck clocks provider Olivier Moysan
2026-11-18 15:50 ` sashiko-bot
2026-11-18 15:17 ` [PATCH v2 04/11] iio: adc: stm32-mdf: add serial interfaces support Olivier Moysan
2026-11-18 15:42 ` sashiko-bot
2026-11-18 15:17 ` [PATCH v2 05/11] iio: adc: stm32-mdf: add digital filter device support Olivier Moysan
2026-11-18 15:40 ` sashiko-bot
2026-11-18 15:17 ` [PATCH v2 06/11] iio: adc: stm32-mdf: configure cic filters and sample rates Olivier Moysan
2026-11-18 15:34 ` sashiko-bot
2026-11-18 15:17 ` [PATCH v2 07/11] iio: adc: stm32-mdf: add direct iio conversion support Olivier Moysan
2026-11-18 15:51 ` sashiko-bot
2026-11-18 15:17 ` [PATCH v2 08/11] iio: adc: stm32-mdf: add dma buffered acquisition support Olivier Moysan
2026-11-18 15:55 ` sashiko-bot
2026-11-18 15:17 ` [PATCH v2 09/11] iio: adc: stm32-mdf: add external timer trigger support Olivier Moysan
2026-11-18 15:37 ` sashiko-bot
2026-11-18 15:17 ` [PATCH v2 10/11] iio: adc: stm32-mdf: add dmic audio filter support Olivier Moysan
2026-11-18 16:06 ` sashiko-bot
2026-11-18 15:17 ` [PATCH v2 11/11] ASoC: stm32: add mdf dai support Olivier Moysan
2026-11-18 16:08 ` sashiko-bot
2026-11-19 18:37 ` [PATCH v2 00/11] iio: adc: stm32: add mdf support for stm32mp2 Conor Dooley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=av7FDVDUH9EvNJmQ@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andy@kernel.org \
--cc=arnaud.pouliquen@foss.st.com \
--cc=broonie@kernel.org \
--cc=christian.koenig@amd.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=fabrice.gasnier@foss.st.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=nuno.sa@analog.com \
--cc=olivier.moysan@foss.st.com \
--cc=p.zabel@pengutronix.de \
--cc=perex@perex.cz \
--cc=phasta@kernel.org \
--cc=robh@kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.