From: Olivier Moysan <olivier.moysan@foss.st.com>
To: "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>
Cc: <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>,
"Olivier Moysan" <olivier.moysan@foss.st.com>
Subject: [PATCH v2 10/11] iio: adc: stm32-mdf: add dmic audio filter support
Date: Wed, 18 Nov 2026 16:17:55 +0100 [thread overview]
Message-ID: <20261118-upstream_mdf_v2-v2-10-7939d3c3720a@foss.st.com> (raw)
In-Reply-To: <20261118-upstream_mdf_v2-v2-0-7939d3c3720a@foss.st.com>
Extend the MDF filter driver to support digital microphones and provide
the interface required by an audio consumer.
Signed-off-by: Olivier Moysan <olivier.moysan@foss.st.com>
---
drivers/iio/adc/stm32-mdf-adc.c | 164 +++++++++++++++++++++++++++++++++-
include/linux/iio/adc/stm32-mdf-adc.h | 19 ++++
2 files changed, 182 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/stm32-mdf-adc.c b/drivers/iio/adc/stm32-mdf-adc.c
index 97099b4adffc..27c47bef71a4 100644
--- a/drivers/iio/adc/stm32-mdf-adc.c
+++ b/drivers/iio/adc/stm32-mdf-adc.c
@@ -9,6 +9,7 @@
#include <linux/clk-provider.h>
#include <linux/dmaengine.h>
#include <linux/dma-mapping.h>
+#include <linux/iio/adc/stm32-mdf-adc.h>
#include <linux/iio/backend.h>
#include <linux/iio/buffer.h>
#include <linux/iio/hw-consumer.h>
@@ -1128,6 +1129,42 @@ static const struct iio_buffer_setup_ops stm32_mdf_buffer_setup_ops = {
.predisable = &stm32_mdf_adc_predisable,
};
+/**
+ * stm32_mdf_get_sub_channels_nb() - Get the number of MDF sub-channels
+ * @indio_dev: MDF IIO device
+ *
+ * Return: 0 on success, or a negative error code on failure.
+ */
+unsigned int stm32_mdf_get_sub_channels_nb(struct iio_dev *indio_dev)
+{
+ struct stm32_mdf_adc *adc = iio_priv(indio_dev);
+
+ if (MDF_IS_FILTER0(adc) && adc->mdf->nb_interleave)
+ return adc->mdf->nb_interleave;
+
+ return 1;
+}
+EXPORT_SYMBOL_GPL(stm32_mdf_get_sub_channels_nb);
+
+static ssize_t stm32_mdf_adc_audio_get_channels(struct iio_dev *indio_dev, uintptr_t priv,
+ const struct iio_chan_spec *chan, char *buf)
+{
+ return sysfs_emit(buf, "%u\n", stm32_mdf_get_sub_channels_nb(indio_dev));
+}
+
+/*
+ * IIO channel extended info used by the audio device IIO channel consumer.
+ * sub_channels_nb: provides the number of audio channels associated to the IIO channel.
+ */
+static const struct iio_chan_spec_ext_info stm32_mdf_adc_audio_ext_info[] = {
+ {
+ .name = "sub_channels_nb",
+ .shared = IIO_SHARED_BY_TYPE,
+ .read = stm32_mdf_adc_audio_get_channels,
+ },
+ {},
+};
+
static void stm32_mdf_dma_release(struct iio_dev *indio_dev)
{
struct stm32_mdf_adc *adc = iio_priv(indio_dev);
@@ -1240,6 +1277,9 @@ static int stm32_mdf_adc_chan_init_one(struct iio_dev *indio_dev, struct fwnode_
ch->scan_type.shift = 8;
}
+ if (adc->dev_data->type == STM32_MDF_AUDIO)
+ ch->ext_info = stm32_mdf_adc_audio_ext_info;
+
ch->info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ);
ch->scan_type.sign = 's';
ch->scan_type.realbits = STM32_MDF_DATA_RES;
@@ -1474,6 +1514,13 @@ static int stm32_mdf_adc_read_label(struct iio_dev *indio_dev, const struct iio_
return sysfs_emit(label, "%s\n", name);
}
+static const struct iio_info stm32_mdf_info_audio = {
+ .hwfifo_set_watermark = stm32_mdf_set_watermark,
+ .write_raw = stm32_mdf_adc_write_raw,
+ .read_raw = stm32_mdf_adc_read_raw,
+ .read_label = stm32_mdf_adc_read_label,
+};
+
static const struct iio_info stm32_mdf_info_adc = {
.hwfifo_set_watermark = stm32_mdf_set_watermark,
.write_raw = stm32_mdf_adc_write_raw,
@@ -1530,6 +1577,38 @@ static irqreturn_t stm32_mdf_irq(int irq, void *arg)
return IRQ_HANDLED;
}
+static int stm32_mdf_audio_init(struct device *dev, struct iio_dev *indio_dev)
+{
+ struct stm32_mdf_adc *adc = iio_priv(indio_dev);
+ struct iio_chan_spec *ch;
+ int ret;
+
+ ch = devm_kzalloc(&indio_dev->dev, sizeof(*ch), GFP_KERNEL);
+ if (!ch)
+ return -ENOMEM;
+
+ adc->channels = devm_kzalloc(&indio_dev->dev, sizeof(*adc->channels), GFP_KERNEL);
+ if (!adc->channels)
+ return -ENOMEM;
+
+ ret = stm32_mdf_adc_chan_init(indio_dev, ch);
+ if (ret < 0)
+ return dev_err_probe(dev, ret, "Channels init failed\n");
+
+ indio_dev->num_channels = 1;
+ indio_dev->channels = ch;
+
+ ret = stm32_mdf_dma_request(dev, indio_dev);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to get DMA\n");
+
+ ret = stm32_mdf_adc_filter_set_mode(adc, true);
+ if (ret)
+ stm32_mdf_dma_release(indio_dev);
+
+ return ret;
+}
+
static int stm32_mdf_adc_init(struct device *dev, struct iio_dev *indio_dev)
{
struct stm32_mdf_adc *adc = iio_priv(indio_dev);
@@ -1599,11 +1678,77 @@ static const struct stm32_mdf_dev_data stm32h7_mdf_adc_data = {
.init = stm32_mdf_adc_init,
};
+static const struct stm32_mdf_dev_data stm32_mdf_audio_data = {
+ .type = STM32_MDF_AUDIO,
+ .init = stm32_mdf_audio_init,
+};
+
+/**
+ * stm32_mdf_get_buff_cb() - register a callback that will be called when
+ * DMA transfer period is achieved.
+ *
+ * @iio_dev: Handle to IIO device.
+ * @cb: Pointer to callback function:
+ * - data: pointer to data buffer
+ * - size: size in byte of the data buffer
+ * - private: pointer to consumer private structure.
+ * @private: Pointer to consumer private structure.
+ *
+ * Return: 0 on success, or a negative error code on failure.
+ */
+int stm32_mdf_get_buff_cb(struct iio_dev *iio_dev,
+ int (*cb)(const void *data, size_t size, void *private), void *private)
+{
+ struct stm32_mdf_adc *adc;
+
+ if (!iio_dev)
+ return -EINVAL;
+ adc = iio_priv(iio_dev);
+
+ if (!adc)
+ return -EINVAL;
+
+ adc->cb = cb;
+ adc->cb_priv = private;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(stm32_mdf_get_buff_cb);
+
+/**
+ * stm32_mdf_release_buff_cb() - Unregister the buffer callback
+ *
+ * @iio_dev: Handle to IIO device.
+ *
+ * Return: 0 on success, or a negative error code on failure.
+ */
+int stm32_mdf_release_buff_cb(struct iio_dev *iio_dev)
+{
+ struct stm32_mdf_adc *adc;
+
+ if (!iio_dev)
+ return -EINVAL;
+ adc = iio_priv(iio_dev);
+
+ if (!adc)
+ return -EINVAL;
+
+ adc->cb = NULL;
+ adc->cb_priv = NULL;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(stm32_mdf_release_buff_cb);
+
static const struct of_device_id stm32_mdf_adc_match[] = {
{
.compatible = "st,stm32mp25-mdf-adc",
.data = &stm32h7_mdf_adc_data,
},
+ {
+ .compatible = "st,stm32mp25-mdf-dmic",
+ .data = &stm32_mdf_audio_data,
+ },
{}
};
MODULE_DEVICE_TABLE(of, stm32_mdf_adc_match);
@@ -1788,6 +1933,7 @@ static int stm32_mdf_adc_parse_of(struct platform_device *pdev, struct stm32_mdf
static int stm32_mdf_adc_probe(struct platform_device *pdev)
{
+ struct device_node *node = pdev->dev.of_node;
struct device *dev = &pdev->dev;
struct stm32_mdf_adc *adc;
const struct stm32_mdf_dev_data *dev_data;
@@ -1830,7 +1976,10 @@ static int stm32_mdf_adc_probe(struct platform_device *pdev)
if (ret < 0)
return ret;
- iio->info = &stm32_mdf_info_adc;
+ if (dev_data->type == STM32_MDF_AUDIO)
+ iio->info = &stm32_mdf_info_audio;
+ else
+ iio->info = &stm32_mdf_info_adc;
iio->name = dev_name(&pdev->dev);
adc->dev = dev;
@@ -1847,8 +1996,19 @@ static int stm32_mdf_adc_probe(struct platform_device *pdev)
}
}
+ if (dev_data->type == STM32_MDF_AUDIO) {
+ ret = of_platform_populate(node, NULL, NULL, dev);
+ if (ret < 0) {
+ dev_err_probe(dev, ret, "Failed to find an audio DAI\n");
+ goto err_unregister;
+ }
+ }
+
return 0;
+err_unregister:
+ if (!MDF_IS_INTERLEAVED_FILT_NOT_0(adc))
+ iio_device_unregister(iio);
err_cleanup:
stm32_mdf_dma_release(iio);
err_clean_list:
@@ -1862,6 +2022,8 @@ static void stm32_mdf_adc_remove(struct platform_device *pdev)
struct iio_dev *indio_dev = platform_get_drvdata(pdev);
struct stm32_mdf_adc *adc = iio_priv(indio_dev);
+ if (adc->dev_data->type == STM32_MDF_AUDIO)
+ of_platform_depopulate(&pdev->dev);
if (!MDF_IS_INTERLEAVED_FILT_NOT_0(adc))
iio_device_unregister(indio_dev);
stm32_mdf_dma_release(indio_dev);
diff --git a/include/linux/iio/adc/stm32-mdf-adc.h b/include/linux/iio/adc/stm32-mdf-adc.h
new file mode 100644
index 000000000000..95e3f4afdb78
--- /dev/null
+++ b/include/linux/iio/adc/stm32-mdf-adc.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * This file describe the STM32 MDF IIO driver API for audio part
+ *
+ * Copyright (C) 2023, STMicroelectronics.
+ * Author(s): Olivier Moysan <olivier.moysan@foss.st.com>.
+ */
+
+#ifndef STM32_MDF_ADC_H
+#define STM32_MDF_ADC_H
+
+#include <linux/iio/iio.h>
+
+int stm32_mdf_get_buff_cb(struct iio_dev *iio_dev,
+ int (*cb)(const void *data, size_t size, void *private), void *private);
+int stm32_mdf_release_buff_cb(struct iio_dev *iio_dev);
+unsigned int stm32_mdf_get_sub_channels_nb(struct iio_dev *iio_dev);
+
+#endif
--
2.43.0
next prev parent reply other threads:[~2026-11-18 15:18 UTC|newest]
Thread overview: 12+ 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:17 ` [PATCH v2 03/11] iio: adc: stm32-mdf: add cck clocks provider Olivier Moysan
2026-11-18 15:17 ` [PATCH v2 04/11] iio: adc: stm32-mdf: add serial interfaces support Olivier Moysan
2026-11-18 15:17 ` [PATCH v2 05/11] iio: adc: stm32-mdf: add digital filter device support Olivier Moysan
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:17 ` [PATCH v2 07/11] iio: adc: stm32-mdf: add direct iio conversion support Olivier Moysan
2026-11-18 15:17 ` [PATCH v2 08/11] iio: adc: stm32-mdf: add dma buffered acquisition support Olivier Moysan
2026-11-18 15:17 ` [PATCH v2 09/11] iio: adc: stm32-mdf: add external timer trigger support Olivier Moysan
2026-11-18 15:17 ` Olivier Moysan [this message]
2026-11-18 15:17 ` [PATCH v2 11/11] ASoC: stm32: add mdf dai support Olivier Moysan
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=20261118-upstream_mdf_v2-v2-10-7939d3c3720a@foss.st.com \
--to=olivier.moysan@foss.st.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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®