diff mbox series

[6/9] ASoC: SOF: imx8: make imx8_ops_init() an util function

Message ID 20250203171808.4108-7-laurentiumihalcea111@gmail.com (mailing list archive)
State New
Headers show
Series Refactor imx drivers and introduce support for imx95 | expand

Commit Message

Laurentiu Mihalcea Feb. 3, 2025, 5:18 p.m. UTC
From: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>

The definition for the ops_init() operation is similar among the imx8
chips (namely: imx8, imx8x, imx8m, and imx8ulp). The only difference is
the name of the 'struct snd_soc_dai_driver' array used to fill the SOF
ops structure.

As such, 'imx8_ops_init()' can be made into an utility function that takes
the 'struct snd_soc_dai_driver' array and its size as parameters and fills
the SOF ops structure fields accordingly. This will allow us to reuse this
function when the other drivers (imx8m, imx8ulp) are merged into this one.

Since the definition of the function is changed, it can no longer be
used directly by the SOF core. Therefore, also introduce a wrapper:
'imx_ops_init()' that will call 'imx8_ops_init()' with the right
parameters based on the chip.

Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: Iuliana Prodan <iuliana.prodan@nxp.com>
---
 sound/soc/sof/imx/imx8.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/sound/soc/sof/imx/imx8.c b/sound/soc/sof/imx/imx8.c
index 1efdb169cf07..3ad20df351c2 100644
--- a/sound/soc/sof/imx/imx8.c
+++ b/sound/soc/sof/imx/imx8.c
@@ -19,7 +19,7 @@  static struct snd_soc_dai_driver imx8_dai[] = {
 
 static struct snd_sof_dsp_ops sof_imx8_ops;
 
-static int imx8_ops_init(struct snd_sof_dev *sdev)
+static void imx8_ops_init(struct snd_soc_dai_driver *dai_drv, uint32_t num_drv)
 {
 	/* first copy from template */
 	memcpy(&sof_imx8_ops, &sof_imx_ops, sizeof(sof_imx_ops));
@@ -31,8 +31,18 @@  static int imx8_ops_init(struct snd_sof_dev *sdev)
 		snd_sof_debugfs_add_region_item_iomem;
 
 	/* ... and finally set DAI driver */
-	sof_imx8_ops.drv = imx8_dai;
-	sof_imx8_ops.num_drv = ARRAY_SIZE(imx8_dai);
+	sof_imx8_ops.drv = dai_drv;
+	sof_imx8_ops.num_drv = num_drv;
+}
+
+static int imx_ops_init(struct snd_sof_dev *sdev)
+{
+	if (of_device_is_compatible(sdev->dev->of_node, "fsl,imx8qm-dsp") ||
+	    of_device_is_compatible(sdev->dev->of_node, "fsl,imx8qxp-dsp")) {
+		imx8_ops_init(imx8_dai, ARRAY_SIZE(imx8_dai));
+	} else {
+		return -EINVAL;
+	}
 
 	return 0;
 }
@@ -186,8 +196,8 @@  static struct snd_sof_of_mach sof_imx8_machs[] = {
 	{}
 };
 
-IMX_SOF_DEV_DESC(imx8, sof_imx8_machs, &imx8_chip_info, &sof_imx8_ops, imx8_ops_init);
-IMX_SOF_DEV_DESC(imx8x, sof_imx8_machs, &imx8x_chip_info, &sof_imx8_ops, imx8_ops_init);
+IMX_SOF_DEV_DESC(imx8, sof_imx8_machs, &imx8_chip_info, &sof_imx8_ops, imx_ops_init);
+IMX_SOF_DEV_DESC(imx8x, sof_imx8_machs, &imx8x_chip_info, &sof_imx8_ops, imx_ops_init);
 
 static const struct of_device_id sof_of_imx8_ids[] = {
 	{