ASoC: Intel: nau8825/rt5682: move speaker widget to common modules
authorBrent Lu <brent.lu@intel.com>
Fri, 26 Apr 2024 15:25:07 +0000 (10:25 -0500)
committerMark Brown <broonie@kernel.org>
Mon, 29 Apr 2024 14:49:02 +0000 (23:49 +0900)
Two machine drivers sof_rt5682 and sof_nau8825 always register two
speaker widgets 'Left Spk' and 'Right Spk' regardless the actual
number of speakers. Move the widget registration to speaker common
modules to avoid useless speaker widgets for 1 or 4 speaker boards.

Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Signed-off-by: Brent Lu <brent.lu@intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20240426152529.38345-2-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/intel/boards/sof_maxim_common.c
sound/soc/intel/boards/sof_nau8825.c
sound/soc/intel/boards/sof_realtek_common.c
sound/soc/intel/boards/sof_rt5682.c

index cf29747182716c500447b3e8b36dc12cfdcee000..53c7392bf3ddc59e3db356b1339b69b3c0804c3a 100644 (file)
 #include <uapi/sound/asound.h>
 #include "sof_maxim_common.h"
 
+/*
+ * Common structures and functions
+ */
+static const struct snd_kcontrol_new maxim_2spk_kcontrols[] = {
+       SOC_DAPM_PIN_SWITCH("Left Spk"),
+       SOC_DAPM_PIN_SWITCH("Right Spk"),
+
+};
+
+static const struct snd_soc_dapm_widget maxim_2spk_widgets[] = {
+       SND_SOC_DAPM_SPK("Left Spk", NULL),
+       SND_SOC_DAPM_SPK("Right Spk", NULL),
+};
+
 /* helper function to get the number of specific codec */
 static unsigned int get_num_codecs(const char *hid)
 {
@@ -135,12 +149,40 @@ EXPORT_SYMBOL_NS(max_98373_ops, SND_SOC_INTEL_SOF_MAXIM_COMMON);
 int max_98373_spk_codec_init(struct snd_soc_pcm_runtime *rtd)
 {
        struct snd_soc_card *card = rtd->card;
+       unsigned int num_codecs = get_num_codecs(MAX_98373_ACPI_HID);
        int ret;
 
-       ret = snd_soc_dapm_add_routes(&card->dapm, max_98373_dapm_routes,
-                                     ARRAY_SIZE(max_98373_dapm_routes));
-       if (ret)
-               dev_err(rtd->dev, "Speaker map addition failed: %d\n", ret);
+       switch (num_codecs) {
+       case 2:
+               ret = snd_soc_dapm_new_controls(&card->dapm, maxim_2spk_widgets,
+                                               ARRAY_SIZE(maxim_2spk_widgets));
+               if (ret) {
+                       dev_err(rtd->dev, "fail to add max98373 widgets, ret %d\n",
+                               ret);
+                       return ret;
+               }
+
+               ret = snd_soc_add_card_controls(card, maxim_2spk_kcontrols,
+                                               ARRAY_SIZE(maxim_2spk_kcontrols));
+               if (ret) {
+                       dev_err(rtd->dev, "fail to add max98373 kcontrols, ret %d\n",
+                               ret);
+                       return ret;
+               }
+
+               ret = snd_soc_dapm_add_routes(&card->dapm, max_98373_dapm_routes,
+                                             ARRAY_SIZE(max_98373_dapm_routes));
+               if (ret) {
+                       dev_err(rtd->dev, "fail to add max98373 routes, ret %d\n",
+                               ret);
+                       return ret;
+               }
+               break;
+       default:
+               dev_err(rtd->dev, "max98373: invalid num_codecs %d\n", num_codecs);
+               return -EINVAL;
+       }
+
        return ret;
 }
 EXPORT_SYMBOL_NS(max_98373_spk_codec_init, SND_SOC_INTEL_SOF_MAXIM_COMMON);
@@ -287,6 +329,22 @@ static int max_98390_init(struct snd_soc_pcm_runtime *rtd)
                fallthrough;
        case 2:
                /* add regular speakers dapm route */
+               ret = snd_soc_dapm_new_controls(&card->dapm, maxim_2spk_widgets,
+                                               ARRAY_SIZE(maxim_2spk_widgets));
+               if (ret) {
+                       dev_err(rtd->dev, "fail to add max98390 woofer widgets, ret %d\n",
+                               ret);
+                       return ret;
+               }
+
+               ret = snd_soc_add_card_controls(card, maxim_2spk_kcontrols,
+                                               ARRAY_SIZE(maxim_2spk_kcontrols));
+               if (ret) {
+                       dev_err(rtd->dev, "fail to add max98390 woofer kcontrols, ret %d\n",
+                               ret);
+                       return ret;
+               }
+
                ret = snd_soc_dapm_add_routes(&card->dapm, max_98390_dapm_routes,
                                              ARRAY_SIZE(max_98390_dapm_routes));
                if (ret) {
index fe5f9e8dd6520efe80ed97c53702fe8723e0b1e3..dd4dc4ec42556f53adb7dc689aab8b6c4eeccc4b 100644 (file)
@@ -140,15 +140,11 @@ static int sof_card_late_probe(struct snd_soc_card *card)
 static const struct snd_kcontrol_new sof_controls[] = {
        SOC_DAPM_PIN_SWITCH("Headphone Jack"),
        SOC_DAPM_PIN_SWITCH("Headset Mic"),
-       SOC_DAPM_PIN_SWITCH("Left Spk"),
-       SOC_DAPM_PIN_SWITCH("Right Spk"),
 };
 
 static const struct snd_soc_dapm_widget sof_widgets[] = {
        SND_SOC_DAPM_HP("Headphone Jack", NULL),
        SND_SOC_DAPM_MIC("Headset Mic", NULL),
-       SND_SOC_DAPM_SPK("Left Spk", NULL),
-       SND_SOC_DAPM_SPK("Right Spk", NULL),
 };
 
 static const struct snd_soc_dapm_route sof_map[] = {
index 20d094c52d2837792d9eed4fefce9b8581e2cbf6..cb1c21d822f6cbba481bc4782fc5f35e5b665e5f 100644 (file)
 /*
  * Common structures and functions
  */
+static const struct snd_kcontrol_new realtek_2spk_kcontrols[] = {
+       SOC_DAPM_PIN_SWITCH("Left Spk"),
+       SOC_DAPM_PIN_SWITCH("Right Spk"),
+
+};
+
+static const struct snd_soc_dapm_widget realtek_2spk_widgets[] = {
+       SND_SOC_DAPM_SPK("Left Spk", NULL),
+       SND_SOC_DAPM_SPK("Right Spk", NULL),
+};
+
 static const struct snd_kcontrol_new realtek_4spk_kcontrols[] = {
        SOC_DAPM_PIN_SWITCH("WL Ext Spk"),
        SOC_DAPM_PIN_SWITCH("WR Ext Spk"),
@@ -181,6 +192,22 @@ static int rt1011_init(struct snd_soc_pcm_runtime *rtd)
        switch (num_codecs) {
        case 2:
                if (!soc_intel_is_cml()) {
+                       ret = snd_soc_dapm_new_controls(&card->dapm, realtek_2spk_widgets,
+                                                       ARRAY_SIZE(realtek_2spk_widgets));
+                       if (ret) {
+                               dev_err(rtd->dev, "fail to add rt1011 widgets, ret %d\n",
+                                       ret);
+                               return ret;
+                       }
+
+                       ret = snd_soc_add_card_controls(card, realtek_2spk_kcontrols,
+                                                       ARRAY_SIZE(realtek_2spk_kcontrols));
+                       if (ret) {
+                               dev_err(rtd->dev, "fail to add rt1011 kcontrols, ret %d\n",
+                                       ret);
+                               return ret;
+                       }
+
                        ret = snd_soc_dapm_add_routes(&card->dapm, speaker_map_lr,
                                                      ARRAY_SIZE(speaker_map_lr));
                        if (ret) {
@@ -357,6 +384,20 @@ static int rt1015p_init(struct snd_soc_pcm_runtime *rtd)
        struct snd_soc_card *card = rtd->card;
        int ret;
 
+       ret = snd_soc_dapm_new_controls(&card->dapm, realtek_2spk_widgets,
+                                       ARRAY_SIZE(realtek_2spk_widgets));
+       if (ret) {
+               dev_err(rtd->dev, "fail to add rt1015p widgets, ret %d\n", ret);
+               return ret;
+       }
+
+       ret = snd_soc_add_card_controls(card, realtek_2spk_kcontrols,
+                                       ARRAY_SIZE(realtek_2spk_kcontrols));
+       if (ret) {
+               dev_err(rtd->dev, "fail to add rt1015p kcontrols, ret %d\n", ret);
+               return ret;
+       }
+
        if (rt1015p_get_num_codecs() == 1)
                ret = snd_soc_dapm_add_routes(&card->dapm, rt1015p_1dev_dapm_routes,
                                              ARRAY_SIZE(rt1015p_1dev_dapm_routes));
@@ -486,8 +527,42 @@ static struct snd_soc_dai_link_component rt1015_components[] = {
 
 static int speaker_codec_init_lr(struct snd_soc_pcm_runtime *rtd)
 {
-       return snd_soc_dapm_add_routes(&rtd->card->dapm, speaker_map_lr,
-                                       ARRAY_SIZE(speaker_map_lr));
+       struct snd_soc_card *card = rtd->card;
+       unsigned int num_codecs = get_num_codecs(RT1015_ACPI_HID);
+       int ret;
+
+       switch (num_codecs) {
+       case 2:
+               ret = snd_soc_dapm_new_controls(&card->dapm, realtek_2spk_widgets,
+                                               ARRAY_SIZE(realtek_2spk_widgets));
+               if (ret) {
+                       dev_err(rtd->dev, "fail to add rt1015 widgets, ret %d\n",
+                               ret);
+                       return ret;
+               }
+
+               ret = snd_soc_add_card_controls(card, realtek_2spk_kcontrols,
+                                               ARRAY_SIZE(realtek_2spk_kcontrols));
+               if (ret) {
+                       dev_err(rtd->dev, "fail to add rt1015 kcontrols, ret %d\n",
+                               ret);
+                       return ret;
+               }
+
+               ret = snd_soc_dapm_add_routes(&rtd->card->dapm, speaker_map_lr,
+                                             ARRAY_SIZE(speaker_map_lr));
+               if (ret) {
+                       dev_err(rtd->dev, "fail to add rt1015 routes, ret %d\n",
+                               ret);
+                       return ret;
+               }
+               break;
+       default:
+               dev_err(rtd->dev, "rt1015: invalid num_codecs %d\n", num_codecs);
+               return -EINVAL;
+       }
+
+       return ret;
 }
 
 void sof_rt1015_codec_conf(struct snd_soc_card *card)
@@ -624,6 +699,20 @@ static int rt1019p_init(struct snd_soc_pcm_runtime *rtd)
        struct snd_soc_card *card = rtd->card;
        int ret;
 
+       ret = snd_soc_dapm_new_controls(&card->dapm, realtek_2spk_widgets,
+                                       ARRAY_SIZE(realtek_2spk_widgets));
+       if (ret) {
+               dev_err(rtd->dev, "fail to add rt1019p widgets, ret %d\n", ret);
+               return ret;
+       }
+
+       ret = snd_soc_add_card_controls(card, realtek_2spk_kcontrols,
+                                       ARRAY_SIZE(realtek_2spk_kcontrols));
+       if (ret) {
+               dev_err(rtd->dev, "fail to add rt1019p kcontrols, ret %d\n", ret);
+               return ret;
+       }
+
        ret = snd_soc_dapm_add_routes(&card->dapm, rt1019p_dapm_routes,
                                      ARRAY_SIZE(rt1019p_dapm_routes));
        if (ret) {
index 062012de3de22b32a41d5c8d09f8e988447287d2..1e70ce4696508d31e8ff3f0788edc9c4b66decfe 100644 (file)
@@ -431,16 +431,11 @@ static int sof_card_late_probe(struct snd_soc_card *card)
 static const struct snd_kcontrol_new sof_controls[] = {
        SOC_DAPM_PIN_SWITCH("Headphone Jack"),
        SOC_DAPM_PIN_SWITCH("Headset Mic"),
-       SOC_DAPM_PIN_SWITCH("Left Spk"),
-       SOC_DAPM_PIN_SWITCH("Right Spk"),
-
 };
 
 static const struct snd_soc_dapm_widget sof_widgets[] = {
        SND_SOC_DAPM_HP("Headphone Jack", NULL),
        SND_SOC_DAPM_MIC("Headset Mic", NULL),
-       SND_SOC_DAPM_SPK("Left Spk", NULL),
-       SND_SOC_DAPM_SPK("Right Spk", NULL),
 };
 
 static const struct snd_soc_dapm_route sof_map[] = {
@@ -452,6 +447,17 @@ static const struct snd_soc_dapm_route sof_map[] = {
        { "IN1P", NULL, "Headset Mic" },
 };
 
+static const struct snd_kcontrol_new rt5650_spk_kcontrols[] = {
+       SOC_DAPM_PIN_SWITCH("Left Spk"),
+       SOC_DAPM_PIN_SWITCH("Right Spk"),
+
+};
+
+static const struct snd_soc_dapm_widget rt5650_spk_widgets[] = {
+       SND_SOC_DAPM_SPK("Left Spk", NULL),
+       SND_SOC_DAPM_SPK("Right Spk", NULL),
+};
+
 static const struct snd_soc_dapm_route rt5650_spk_dapm_routes[] = {
        /* speaker */
        { "Left Spk", NULL, "SPOL" },
@@ -463,6 +469,22 @@ static int rt5650_spk_init(struct snd_soc_pcm_runtime *rtd)
        struct snd_soc_card *card = rtd->card;
        int ret;
 
+       ret = snd_soc_dapm_new_controls(&card->dapm, rt5650_spk_widgets,
+                                       ARRAY_SIZE(rt5650_spk_widgets));
+       if (ret) {
+               dev_err(rtd->dev, "fail to add rt5650 spk widgets, ret %d\n",
+                       ret);
+               return ret;
+       }
+
+       ret = snd_soc_add_card_controls(card, rt5650_spk_kcontrols,
+                                       ARRAY_SIZE(rt5650_spk_kcontrols));
+       if (ret) {
+               dev_err(rtd->dev, "fail to add rt5650 spk kcontrols, ret %d\n",
+                       ret);
+               return ret;
+       }
+
        ret = snd_soc_dapm_add_routes(&card->dapm, rt5650_spk_dapm_routes,
                                      ARRAY_SIZE(rt5650_spk_dapm_routes));
        if (ret)