diff mbox series

[1/2] ASoC: SOF: mediatek: add mt8188 audio support

Message ID 20230515052540.9037-2-trevor.wu@mediatek.com (mailing list archive)
State New, archived
Headers show
Series ASoC: SOF: add mt8188 audio support | expand

Commit Message

Trevor Wu (吳文良) May 15, 2023, 5:25 a.m. UTC
Add mt8188 dai driver and specify of_machine to support mt8188 audio.

Signed-off-by: Trevor Wu <trevor.wu@mediatek.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Yaochun Hung <yc.hung@mediatek.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
---
 sound/soc/sof/mediatek/mt8186/mt8186.c | 61 +++++++++++++++++++++++++-
 1 file changed, 60 insertions(+), 1 deletion(-)

Comments

AngeloGioacchino Del Regno May 15, 2023, 11:25 a.m. UTC | #1
Il 15/05/23 07:25, Trevor Wu ha scritto:
> Add mt8188 dai driver and specify of_machine to support mt8188 audio.
> 
> Signed-off-by: Trevor Wu <trevor.wu@mediatek.com>
> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
> Reviewed-by: Yaochun Hung <yc.hung@mediatek.com>
> Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
> ---
>   sound/soc/sof/mediatek/mt8186/mt8186.c | 61 +++++++++++++++++++++++++-
>   1 file changed, 60 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/soc/sof/mediatek/mt8186/mt8186.c b/sound/soc/sof/mediatek/mt8186/mt8186.c
> index 419913c8474d..3a9c81418c1f 100644
> --- a/sound/soc/sof/mediatek/mt8186/mt8186.c
> +++ b/sound/soc/sof/mediatek/mt8186/mt8186.c
> @@ -594,7 +594,65 @@ static const struct sof_dev_desc sof_of_mt8186_desc = {
>   	.ops = &sof_mt8186_ops,
>   };
>   
> +/*
> + * DL2, DL3, UL4, UL5 are registered as SOF FE, so creating the corresponding
> + * SOF BE to complete the pipeline.
> + */
> +static struct snd_soc_dai_driver mt8188_dai[] = {
> +{
> +	.name = "SOF_DL2",
> +	.playback = {
> +		.channels_min = 1,
> +		.channels_max = 2,
> +	},
> +},
> +{
> +	.name = "SOF_DL3",
> +	.playback = {
> +		.channels_min = 1,
> +		.channels_max = 2,
> +	},
> +},
> +{
> +	.name = "SOF_UL4",
> +	.capture = {
> +		.channels_min = 1,
> +		.channels_max = 2,
> +	},
> +},
> +{
> +	.name = "SOF_UL5",
> +	.capture = {
> +		.channels_min = 1,
> +		.channels_max = 2,
> +	},
> +},
> +};
> +
> +/* mt8188 ops */
> +static struct snd_sof_dsp_ops sof_mt8188_ops;
> +
> +static int sof_mt8188_ops_init(struct snd_sof_dev *sdev)
> +{
> +	/* common defaults */
> +	memcpy(&sof_mt8188_ops, &sof_mt8186_ops, sizeof(struct snd_sof_dsp_ops));

Never use sizeof(type), always use destination var size! Anyway, there's more.

I don't think we need to perform this memcpy: we'll never see an instance of
both mt8186 and mt8188 drivers on the same machine, so you can safely just use
sof_mt8186_ops for mt8188...

> +
> +	sof_mt8188_ops.drv = mt8188_dai;

...which obviously means that this becomes

	sof_mt8186_ops.drv = mt8188_dai;

and....

> +	sof_mt8186_ops.num_drv = ARRAY_SIZE(mt8188_dai);
> +
> +	return 0;
> +}
> +
> +static struct snd_sof_of_mach sof_mt8188_machs[] = {
> +	{
> +		.compatible = "mediatek,mt8188",
> +		.sof_tplg_filename = "sof-mt8188.tplg",
> +	},
> +	{}
> +};
> +
>   static const struct sof_dev_desc sof_of_mt8188_desc = {
> +	.of_machines = sof_mt8188_machs,
>   	.ipc_supported_mask	= BIT(SOF_IPC),
>   	.ipc_default		= SOF_IPC,
>   	.default_fw_path = {
> @@ -607,7 +665,8 @@ static const struct sof_dev_desc sof_of_mt8188_desc = {
>   		[SOF_IPC] = "sof-mt8188.ri",
>   	},
>   	.nocodec_tplg_filename = "sof-mt8188-nocodec.tplg",
> -	.ops = &sof_mt8186_ops,
> +	.ops = &sof_mt8188_ops,

...this keeps being sof_mt8186_ops as well.

> +	.ops_init = sof_mt8188_ops_init,
>   };
>   
>   static const struct of_device_id sof_of_mt8186_ids[] = {

Regards,
Angelo
Mark Brown May 15, 2023, 3:05 p.m. UTC | #2
On Mon, May 15, 2023 at 01:25:44PM +0200, AngeloGioacchino Del Regno wrote:
> Il 15/05/23 07:25, Trevor Wu ha scritto:

> > +{
> > +	/* common defaults */
> > +	memcpy(&sof_mt8188_ops, &sof_mt8186_ops, sizeof(struct snd_sof_dsp_ops));

> Never use sizeof(type), always use destination var size! Anyway, there's more.
> 
> I don't think we need to perform this memcpy: we'll never see an instance of
> both mt8186 and mt8188 drivers on the same machine, so you can safely just use
> sof_mt8186_ops for mt8188...

> > +	sof_mt8188_ops.drv = mt8188_dai;

> ...which obviously means that this becomes

> 	sof_mt8186_ops.drv = mt8188_dai;

This does have the issue that it then means the ops struct isn't const
which isn't ideal.  It's also not the end of the world though so I don't
have super strong feelings.
Pierre-Louis Bossart May 15, 2023, 3:28 p.m. UTC | #3
On 5/15/23 10:05, Mark Brown wrote:
> On Mon, May 15, 2023 at 01:25:44PM +0200, AngeloGioacchino Del Regno wrote:
>> Il 15/05/23 07:25, Trevor Wu ha scritto:
> 
>>> +{
>>> +	/* common defaults */
>>> +	memcpy(&sof_mt8188_ops, &sof_mt8186_ops, sizeof(struct snd_sof_dsp_ops));
> 
>> Never use sizeof(type), always use destination var size! Anyway, there's more.
>>
>> I don't think we need to perform this memcpy: we'll never see an instance of
>> both mt8186 and mt8188 drivers on the same machine, so you can safely just use
>> sof_mt8186_ops for mt8188...
> 
>>> +	sof_mt8188_ops.drv = mt8188_dai;
> 
>> ...which obviously means that this becomes
> 
>> 	sof_mt8186_ops.drv = mt8188_dai;
> 
> This does have the issue that it then means the ops struct isn't const
> which isn't ideal.  It's also not the end of the world though so I don't
> have super strong feelings.

We do the same for Intel devices, we have a common structure which is
copied and only the members that differ in specific SOCs are updated.
You're right that it's not constant, but it avoids copy-paste of a
rather large structure just to change a couple of lines.
Trevor Wu (吳文良) May 16, 2023, 3:34 a.m. UTC | #4
On Mon, 2023-05-15 at 10:28 -0500, Pierre-Louis Bossart wrote:
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
> 
> 
> On 5/15/23 10:05, Mark Brown wrote:
> > On Mon, May 15, 2023 at 01:25:44PM +0200, AngeloGioacchino Del
> > Regno wrote:
> > > Il 15/05/23 07:25, Trevor Wu ha scritto:
> > > > +{
> > > > +   /* common defaults */
> > > > +   memcpy(&sof_mt8188_ops, &sof_mt8186_ops, sizeof(struct
> > > > snd_sof_dsp_ops));
> > > 
> > > Never use sizeof(type), always use destination var size! Anyway,
> > > there's more.

OK, I will use sizeof(sof_mt8188_ops) instead.

> > > 
> > > I don't think we need to perform this memcpy: we'll never see an
> > > instance of
> > > both mt8186 and mt8188 drivers on the same machine, so you can
> > > safely just use
> > > sof_mt8186_ops for mt8188...
> > > > +   sof_mt8188_ops.drv = mt8188_dai;
> > > 
> > > ...which obviously means that this becomes
> > >      sof_mt8186_ops.drv = mt8188_dai;
> > 
> > This does have the issue that it then means the ops struct isn't
> > const
> > which isn't ideal.  It's also not the end of the world though so I
> > don't
> > have super strong feelings.
> 
> We do the same for Intel devices, we have a common structure which is
> copied and only the members that differ in specific SOCs are updated.
> You're right that it's not constant, but it avoids copy-paste of a
> rather large structure just to change a couple of lines.

Currently, I prefer to follow the same implementation as Intel devices.
It's easier to see a different ops exists for mt8188 in
sof_of_mt8188_desc and it really avoids copy-paste of a large
structure.


Additionally, I found a typo in the next line.

sof_mt8186_ops.num_drv = ARRAY_SIZE(mt8188_dai);
	^
This should be sof_mt8188_ops. I will correct it in V2.

Thanks,
Trevor
Trevor Wu (吳文良) June 1, 2023, 1:38 a.m. UTC | #5
On Mon, 2023-05-15 at 10:28 -0500, Pierre-Louis Bossart wrote:
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
> 
> 
> On 5/15/23 10:05, Mark Brown wrote:
> > On Mon, May 15, 2023 at 01:25:44PM +0200, AngeloGioacchino Del
> > Regno wrote:
> > > Il 15/05/23 07:25, Trevor Wu ha scritto:
> > > > +{
> > > > +   /* common defaults */
> > > > +   memcpy(&sof_mt8188_ops, &sof_mt8186_ops, sizeof(struct
> > > > snd_sof_dsp_ops));
> > > Never use sizeof(type), always use destination var size! Anyway,
> > > there's more.

OK, I will use sizeof(sof_mt8188_ops) instead.

> > > 
> > > I don't think we need to perform this memcpy: we'll never see an
> > > instance of
> > > both mt8186 and mt8188 drivers on the same machine, so you can
> > > safely just use
> > > sof_mt8186_ops for mt8188...
> > > > +   sof_mt8188_ops.drv = mt8188_dai;
> > > ...which obviously means that this becomes
> > >      sof_mt8186_ops.drv = mt8188_dai;
> > 
> > This does have the issue that it then means the ops struct isn't
> > const
> > which isn't ideal.  It's also not the end of the world though so I
> > don't
> > have super strong feelings.
> 
> We do the same for Intel devices, we have a common structure which is
> copied and only the members that differ in specific SOCs are updated.
> You're right that it's not constant, but it avoids copy-paste of a
> rather large structure just to change a couple of lines.

Currently, I prefer to follow the same implementation as Intel devices.
It's easier to see a different ops exists for mt8188 in
sof_of_mt8188_desc and it really avoids copy-paste of a large
structure.


Additionally, I found a typo in the next line.

sof_mt8186_ops.num_drv = ARRAY_SIZE(mt8188_dai);
	^
This should be sof_mt8188_ops. I will correct it in V2.

Thanks,
Trevor
diff mbox series

Patch

diff --git a/sound/soc/sof/mediatek/mt8186/mt8186.c b/sound/soc/sof/mediatek/mt8186/mt8186.c
index 419913c8474d..3a9c81418c1f 100644
--- a/sound/soc/sof/mediatek/mt8186/mt8186.c
+++ b/sound/soc/sof/mediatek/mt8186/mt8186.c
@@ -594,7 +594,65 @@  static const struct sof_dev_desc sof_of_mt8186_desc = {
 	.ops = &sof_mt8186_ops,
 };
 
+/*
+ * DL2, DL3, UL4, UL5 are registered as SOF FE, so creating the corresponding
+ * SOF BE to complete the pipeline.
+ */
+static struct snd_soc_dai_driver mt8188_dai[] = {
+{
+	.name = "SOF_DL2",
+	.playback = {
+		.channels_min = 1,
+		.channels_max = 2,
+	},
+},
+{
+	.name = "SOF_DL3",
+	.playback = {
+		.channels_min = 1,
+		.channels_max = 2,
+	},
+},
+{
+	.name = "SOF_UL4",
+	.capture = {
+		.channels_min = 1,
+		.channels_max = 2,
+	},
+},
+{
+	.name = "SOF_UL5",
+	.capture = {
+		.channels_min = 1,
+		.channels_max = 2,
+	},
+},
+};
+
+/* mt8188 ops */
+static struct snd_sof_dsp_ops sof_mt8188_ops;
+
+static int sof_mt8188_ops_init(struct snd_sof_dev *sdev)
+{
+	/* common defaults */
+	memcpy(&sof_mt8188_ops, &sof_mt8186_ops, sizeof(struct snd_sof_dsp_ops));
+
+	sof_mt8188_ops.drv = mt8188_dai;
+	sof_mt8186_ops.num_drv = ARRAY_SIZE(mt8188_dai);
+
+	return 0;
+}
+
+static struct snd_sof_of_mach sof_mt8188_machs[] = {
+	{
+		.compatible = "mediatek,mt8188",
+		.sof_tplg_filename = "sof-mt8188.tplg",
+	},
+	{}
+};
+
 static const struct sof_dev_desc sof_of_mt8188_desc = {
+	.of_machines = sof_mt8188_machs,
 	.ipc_supported_mask	= BIT(SOF_IPC),
 	.ipc_default		= SOF_IPC,
 	.default_fw_path = {
@@ -607,7 +665,8 @@  static const struct sof_dev_desc sof_of_mt8188_desc = {
 		[SOF_IPC] = "sof-mt8188.ri",
 	},
 	.nocodec_tplg_filename = "sof-mt8188-nocodec.tplg",
-	.ops = &sof_mt8186_ops,
+	.ops = &sof_mt8188_ops,
+	.ops_init = sof_mt8188_ops_init,
 };
 
 static const struct of_device_id sof_of_mt8186_ids[] = {