ASoC: mediatek: mt8195: add headset codec rt5682s support
authorTrevor Wu <trevor.wu@mediatek.com>
Mon, 29 Nov 2021 14:10:54 +0000 (22:10 +0800)
committerMark Brown <broonie@kernel.org>
Mon, 6 Dec 2021 13:49:20 +0000 (13:49 +0000)
mt8195 machine driver adds rt5682s support in this patch.
Card name can be specified from dts by model property, and driver makes
use of the name to distinguish which headset codec is on the board.

Signed-off-by: Trevor Wu <trevor.wu@mediatek.com>
Link: https://lore.kernel.org/r/20211129141057.12422-2-trevor.wu@mediatek.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/mediatek/Kconfig
sound/soc/mediatek/mt8195/mt8195-mt6359-rt1011-rt5682.c
sound/soc/mediatek/mt8195/mt8195-mt6359-rt1019-rt5682.c

index 3b1ddea26a9eff345916fb02605b724c00640bcb..9306b7ca2644248a547fec5d31e593de8384a375 100644 (file)
@@ -205,6 +205,7 @@ config SND_SOC_MT8195_MT6359_RT1019_RT5682
        select SND_SOC_MT6359
        select SND_SOC_RT1015P
        select SND_SOC_RT5682_I2C
+       select SND_SOC_RT5682S
        select SND_SOC_DMIC
        select SND_SOC_HDMI_CODEC
        help
@@ -220,6 +221,7 @@ config SND_SOC_MT8195_MT6359_RT1011_RT5682
        select SND_SOC_MT6359
        select SND_SOC_RT1011
        select SND_SOC_RT5682_I2C
+       select SND_SOC_RT5682S
        select SND_SOC_DMIC
        select SND_SOC_HDMI_CODEC
        help
index 9e6b54e19c232f7920616b5b181cc42bf5a74beb..cca1c739e690b71250217e3a2b7b72643878c24c 100644 (file)
@@ -27,6 +27,9 @@
 #define RT5682_CODEC_DAI       "rt5682-aif1"
 #define RT5682_DEV0_NAME       "rt5682.2-001a"
 
+#define RT5682S_CODEC_DAI      "rt5682s-aif1"
+#define RT5682S_DEV0_NAME      "rt5682s.2-001a"
+
 struct mt8195_mt6359_rt1011_rt5682_priv {
        struct device_node *platform_node;
        struct device_node *hdmi_node;
@@ -691,14 +694,12 @@ SND_SOC_DAILINK_DEFS(ETDM1_IN_BE,
 
 SND_SOC_DAILINK_DEFS(ETDM2_IN_BE,
                     DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_IN")),
-                    DAILINK_COMP_ARRAY(COMP_CODEC(RT5682_DEV0_NAME,
-                                                  RT5682_CODEC_DAI)),
+                    DAILINK_COMP_ARRAY(COMP_DUMMY()),
                     DAILINK_COMP_ARRAY(COMP_EMPTY()));
 
 SND_SOC_DAILINK_DEFS(ETDM1_OUT_BE,
                     DAILINK_COMP_ARRAY(COMP_CPU("ETDM1_OUT")),
-                    DAILINK_COMP_ARRAY(COMP_CODEC(RT5682_DEV0_NAME,
-                                                  RT5682_CODEC_DAI)),
+                    DAILINK_COMP_ARRAY(COMP_DUMMY()),
                     DAILINK_COMP_ARRAY(COMP_EMPTY()));
 
 SND_SOC_DAILINK_DEFS(ETDM2_OUT_BE,
@@ -1046,9 +1047,19 @@ static int mt8195_mt6359_rt1011_rt5682_dev_probe(struct platform_device *pdev)
        struct snd_soc_card *card = &mt8195_mt6359_rt1011_rt5682_soc_card;
        struct snd_soc_dai_link *dai_link;
        struct mt8195_mt6359_rt1011_rt5682_priv *priv;
+       int is5682s = 0;
        int ret, i;
 
        card->dev = &pdev->dev;
+       ret = snd_soc_of_parse_card_name(card, "model");
+       if (ret) {
+               dev_err(&pdev->dev, "%s new card name parsing error %d\n",
+                       __func__, ret);
+               return ret;
+       }
+
+       if (strstr(card->name, "_5682s"))
+               is5682s = 1;
 
        priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
        if (!priv)
@@ -1078,9 +1089,7 @@ static int mt8195_mt6359_rt1011_rt5682_dev_probe(struct platform_device *pdev)
                                dai_link->codecs->dai_name = "i2s-hifi";
                                dai_link->init = mt8195_dptx_codec_init;
                        }
-               }
-
-               if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) {
+               } else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) {
                        priv->hdmi_node =
                                of_parse_phandle(pdev->dev.of_node,
                                                 "mediatek,hdmi-codec", 0);
@@ -1092,6 +1101,12 @@ static int mt8195_mt6359_rt1011_rt5682_dev_probe(struct platform_device *pdev)
                                dai_link->codecs->dai_name = "i2s-hifi";
                                dai_link->init = mt8195_hdmi_codec_init;
                        }
+               } else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0 ||
+                          strcmp(dai_link->name, "ETDM2_IN_BE") == 0) {
+                       dai_link->codecs->name =
+                               is5682s ? RT5682S_DEV0_NAME : RT5682_DEV0_NAME;
+                       dai_link->codecs->dai_name =
+                               is5682s ? RT5682S_CODEC_DAI : RT5682_CODEC_DAI;
                }
        }
 
index e22e5fd4098464a663da715ebecce8649f0490c8..c33b69b4f8e783ffd567acca9b76ba9a3d09fb21 100644 (file)
@@ -25,6 +25,9 @@
 #define RT5682_CODEC_DAI       "rt5682-aif1"
 #define RT5682_DEV0_NAME       "rt5682.2-001a"
 
+#define RT5682S_CODEC_DAI      "rt5682s-aif1"
+#define RT5682S_DEV0_NAME      "rt5682s.2-001a"
+
 struct mt8195_mt6359_rt1019_rt5682_priv {
        struct device_node *platform_node;
        struct device_node *hdmi_node;
@@ -661,14 +664,12 @@ SND_SOC_DAILINK_DEFS(ETDM1_IN_BE,
 
 SND_SOC_DAILINK_DEFS(ETDM2_IN_BE,
                     DAILINK_COMP_ARRAY(COMP_CPU("ETDM2_IN")),
-                    DAILINK_COMP_ARRAY(COMP_CODEC(RT5682_DEV0_NAME,
-                                                  RT5682_CODEC_DAI)),
+                    DAILINK_COMP_ARRAY(COMP_DUMMY()),
                     DAILINK_COMP_ARRAY(COMP_EMPTY()));
 
 SND_SOC_DAILINK_DEFS(ETDM1_OUT_BE,
                     DAILINK_COMP_ARRAY(COMP_CPU("ETDM1_OUT")),
-                    DAILINK_COMP_ARRAY(COMP_CODEC(RT5682_DEV0_NAME,
-                                                  RT5682_CODEC_DAI)),
+                    DAILINK_COMP_ARRAY(COMP_DUMMY()),
                     DAILINK_COMP_ARRAY(COMP_EMPTY()));
 
 SND_SOC_DAILINK_DEFS(ETDM2_OUT_BE,
@@ -999,10 +1000,21 @@ static int mt8195_mt6359_rt1019_rt5682_dev_probe(struct platform_device *pdev)
        struct snd_soc_card *card = &mt8195_mt6359_rt1019_rt5682_soc_card;
        struct snd_soc_dai_link *dai_link;
        struct mt8195_mt6359_rt1019_rt5682_priv *priv;
+       int is5682s = 0;
        int ret, i;
 
        card->dev = &pdev->dev;
 
+       ret = snd_soc_of_parse_card_name(card, "model");
+       if (ret) {
+               dev_err(&pdev->dev, "%s new card name parsing error %d\n",
+                       __func__, ret);
+               return ret;
+       }
+
+       if (strstr(card->name, "_5682s"))
+               is5682s = 1;
+
        priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
        if (!priv)
                return -ENOMEM;
@@ -1031,9 +1043,7 @@ static int mt8195_mt6359_rt1019_rt5682_dev_probe(struct platform_device *pdev)
                                dai_link->codecs->dai_name = "i2s-hifi";
                                dai_link->init = mt8195_dptx_codec_init;
                        }
-               }
-
-               if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) {
+               } else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) {
                        priv->hdmi_node =
                                of_parse_phandle(pdev->dev.of_node,
                                                 "mediatek,hdmi-codec", 0);
@@ -1045,6 +1055,12 @@ static int mt8195_mt6359_rt1019_rt5682_dev_probe(struct platform_device *pdev)
                                dai_link->codecs->dai_name = "i2s-hifi";
                                dai_link->init = mt8195_hdmi_codec_init;
                        }
+               } else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0 ||
+                          strcmp(dai_link->name, "ETDM2_IN_BE") == 0) {
+                       dai_link->codecs->name =
+                               is5682s ? RT5682S_DEV0_NAME : RT5682_DEV0_NAME;
+                       dai_link->codecs->dai_name =
+                               is5682s ? RT5682S_CODEC_DAI : RT5682_CODEC_DAI;
                }
        }