ASoC: Intel: avs: da7219: Map missing jack kcontrols
authorAlper Nebi Yasak <alpernebiyasak@gmail.com>
Wed, 2 Aug 2023 17:57:15 +0000 (20:57 +0300)
committerMark Brown <broonie@kernel.org>
Mon, 7 Aug 2023 13:32:42 +0000 (14:32 +0100)
This driver does not properly map jack pins to kcontrols that PulseAudio
and PipeWire need to handle jack detection events. The DA7219 codec used
here can detect Headphones, Headset Mic and Line Out connections. Expose
each to userspace as kcontrols and add the necessary widgets.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Link: https://lore.kernel.org/r/20230802175737.263412-6-alpernebiyasak@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/intel/avs/boards/da7219.c

index 964a763..85014d9 100644 (file)
@@ -22,6 +22,7 @@
 static const struct snd_kcontrol_new card_controls[] = {
        SOC_DAPM_PIN_SWITCH("Headphone Jack"),
        SOC_DAPM_PIN_SWITCH("Headset Mic"),
+       SOC_DAPM_PIN_SWITCH("Line Out"),
 };
 
 static int platform_clock_control(struct snd_soc_dapm_widget *w,
@@ -55,6 +56,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
 static const struct snd_soc_dapm_widget card_widgets[] = {
        SND_SOC_DAPM_HP("Headphone Jack", NULL),
        SND_SOC_DAPM_MIC("Headset Mic", NULL),
+       SND_SOC_DAPM_LINE("Line Out", NULL),
        SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0, platform_clock_control,
                            SND_SOC_DAPM_POST_PMD | SND_SOC_DAPM_PRE_PMU),
 };
@@ -68,6 +70,22 @@ static const struct snd_soc_dapm_route card_base_routes[] = {
 
        { "Headphone Jack", NULL, "Platform Clock" },
        { "Headset Mic", NULL, "Platform Clock" },
+       { "Line Out", NULL, "Platform Clock" },
+};
+
+static const struct snd_soc_jack_pin card_headset_pins[] = {
+       {
+               .pin = "Headphone Jack",
+               .mask = SND_JACK_HEADPHONE,
+       },
+       {
+               .pin = "Headset Mic",
+               .mask = SND_JACK_MICROPHONE,
+       },
+       {
+               .pin = "Line Out",
+               .mask = SND_JACK_LINEOUT,
+       },
 };
 
 static int avs_da7219_codec_init(struct snd_soc_pcm_runtime *runtime)
@@ -75,7 +93,9 @@ static int avs_da7219_codec_init(struct snd_soc_pcm_runtime *runtime)
        struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(runtime, 0);
        struct snd_soc_component *component = codec_dai->component;
        struct snd_soc_card *card = runtime->card;
+       struct snd_soc_jack_pin *pins;
        struct snd_soc_jack *jack;
+       int num_pins;
        int clk_freq;
        int ret;
 
@@ -91,14 +111,20 @@ static int avs_da7219_codec_init(struct snd_soc_pcm_runtime *runtime)
                return ret;
        }
 
+       num_pins = ARRAY_SIZE(card_headset_pins);
+       pins = devm_kmemdup(card->dev, card_headset_pins, sizeof(*pins) * num_pins, GFP_KERNEL);
+       if (!pins)
+               return -ENOMEM;
+
        /*
         * Headset buttons map to the google Reference headset.
         * These can be configured by userspace.
         */
-       ret = snd_soc_card_jack_new(card, "Headset Jack",
-                                   SND_JACK_HEADSET | SND_JACK_BTN_0 |
-                                   SND_JACK_BTN_1 | SND_JACK_BTN_2 |
-                                   SND_JACK_BTN_3 | SND_JACK_LINEOUT, jack);
+       ret = snd_soc_card_jack_new_pins(card, "Headset Jack",
+                                        SND_JACK_HEADSET | SND_JACK_BTN_0 |
+                                        SND_JACK_BTN_1 | SND_JACK_BTN_2 |
+                                        SND_JACK_BTN_3 | SND_JACK_LINEOUT,
+                                        jack, pins, num_pins);
        if (ret) {
                dev_err(card->dev, "Headset Jack creation failed: %d\n", ret);
                return ret;