[PATCH v5 2/3] ASoC: mediatek: mt8188-mt6359: add es8326 support

AngeloGioacchino Del Regno angelogioacchino.delregno at collabora.com
Wed Nov 15 01:15:33 PST 2023


Il 15/11/23 10:09, Rui Zhou ha scritto:
> To use ES8326 as the codec, add a new sound card
> named mt8186_es8326.
> 
> Signed-off-by: Rui Zhou <zhourui at huaqin.corp-partner.google.com>
> ---
>   sound/soc/mediatek/Kconfig                |   1 +
>   sound/soc/mediatek/mt8188/mt8188-mt6359.c | 100 +++++++++++++++++++++-
>   2 files changed, 100 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/soc/mediatek/Kconfig b/sound/soc/mediatek/Kconfig
> index b93d455744ab..296b434caf81 100644
> --- a/sound/soc/mediatek/Kconfig
> +++ b/sound/soc/mediatek/Kconfig
> @@ -252,6 +252,7 @@ config SND_SOC_MT8188_MT6359
>   	select SND_SOC_NAU8315
>   	select SND_SOC_NAU8825
>   	select SND_SOC_RT5682S
> +	select SND_SOC_ES8326
>   	help
>   	  This adds support for ASoC machine driver for MediaTek MT8188
>   	  boards with the MT6359 and other I2S audio codecs.
> diff --git a/sound/soc/mediatek/mt8188/mt8188-mt6359.c b/sound/soc/mediatek/mt8188/mt8188-mt6359.c
> index 33d477cc2e54..0421debe3ce4 100644
> --- a/sound/soc/mediatek/mt8188/mt8188-mt6359.c
> +++ b/sound/soc/mediatek/mt8188/mt8188-mt6359.c
> @@ -34,6 +34,8 @@
>   
>   #define NAU8825_HS_PRESENT	BIT(0)
>   #define RT5682S_HS_PRESENT	BIT(1)
> +#define ES8326_HS_PRESENT	BIT(2)
> +#define MAX98390_TWO_AMP	BIT(3)
>   /*
>    * Maxim MAX98390
>    */
> @@ -48,6 +50,11 @@
>    */
>   #define NAU8825_CODEC_DAI  "nau8825-hifi"
>   
> +/*
> + * ES8326
> + */
> +#define ES8326_CODEC_DAI  "es8326-hifi"
> +
>   #define SOF_DMA_DL2 "SOF_DMA_DL2"
>   #define SOF_DMA_DL3 "SOF_DMA_DL3"
>   #define SOF_DMA_UL4 "SOF_DMA_UL4"
> @@ -261,6 +268,17 @@ static struct snd_soc_jack_pin nau8825_jack_pins[] = {
>   	},
>   };
>   
> +static struct snd_soc_jack_pin es8326_jack_pins[] = {

This is practically the same as nau8825_jack_pins, can we please avoid duplication?

> +	{
> +		.pin    = "Headphone",
> +		.mask   = SND_JACK_HEADPHONE,
> +	},
> +	{
> +		.pin    = "Headset Mic",
> +		.mask   = SND_JACK_MICROPHONE,
> +	},
> +};
> +
>   struct mt8188_card_data {
>   	const char *name;
>   	unsigned long quirk;
> @@ -943,6 +961,71 @@ static const struct snd_soc_ops mt8188_sof_be_ops = {
>   	.hw_params = mt8188_sof_be_hw_params,
>   };
>   
> +static int mt8188_es8326_codec_init(struct snd_soc_pcm_runtime *rtd)
> +{
> +	struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card);
> +	struct mt8188_mt6359_priv *priv = soc_card_data->mach_priv;
> +	struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
> +	struct snd_soc_jack *jack = &priv->headset_jack;
> +	int ret;
> +
> +	ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
> +					 SND_JACK_HEADSET | SND_JACK_BTN_0 |
> +					 SND_JACK_BTN_1 | SND_JACK_BTN_2 |
> +					 SND_JACK_BTN_3,
> +					 jack,
> +					 es8326_jack_pins,
> +					 ARRAY_SIZE(es8326_jack_pins));
> +	if (ret) {
> +		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
> +		return ret;
> +	}
> +
> +	snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
> +	snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
> +	snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
> +	snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
> +	ret = snd_soc_component_set_jack(component, jack, NULL);
> +
> +	if (ret) {
> +		dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
> +		return ret;
> +	}
> +

This exact code pattern is repeated already twice: once for RT5682s and once for
NAU8825. Can we please commonize it?

> +	return ret;
> +};
> +
> +static void mt8188_es8326_codec_exit(struct snd_soc_pcm_runtime *rtd)
> +{

Same for this one.

> +	struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
> +
> +	snd_soc_component_set_jack(component, NULL, NULL);
> +}
> +

Regards,
Angelo




More information about the Linux-mediatek mailing list