ASoC: qcom: sc7280: Map missing jack kcontrols
authorAlper Nebi Yasak <alpernebiyasak@gmail.com>
Wed, 2 Aug 2023 17:57:31 +0000 (20:57 +0300)
committerMark Brown <broonie@kernel.org>
Mon, 7 Aug 2023 13:33:02 +0000 (14:33 +0100)
This driver does not properly map jack pins to kcontrols that PulseAudio
and PipeWire need to handle jack detection events. The RT5682 and
RT5682s codecs used here can detect Headphone and Headset Mic
connections. Expose each to userspace as a kcontrol.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Link: https://lore.kernel.org/r/20230802175737.263412-22-alpernebiyasak@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/qcom/sc7280.c

index 787dd49..43010e4 100644 (file)
@@ -43,6 +43,17 @@ static void sc7280_jack_free(struct snd_jack *jack)
        snd_soc_component_set_jack(component, NULL, NULL);
 }
 
+static struct snd_soc_jack_pin sc7280_jack_pins[] = {
+       {
+               .pin = "Headphone Jack",
+               .mask = SND_JACK_HEADPHONE,
+       },
+       {
+               .pin = "Headset Mic",
+               .mask = SND_JACK_MICROPHONE,
+       },
+};
+
 static int sc7280_headset_init(struct snd_soc_pcm_runtime *rtd)
 {
        struct snd_soc_card *card = rtd->card;
@@ -54,13 +65,15 @@ static int sc7280_headset_init(struct snd_soc_pcm_runtime *rtd)
        int rval, i;
 
        if (!pdata->jack_setup) {
-               rval = snd_soc_card_jack_new(card, "Headset Jack",
-                                            SND_JACK_HEADSET | SND_JACK_LINEOUT |
-                                            SND_JACK_MECHANICAL |
-                                            SND_JACK_BTN_0 | SND_JACK_BTN_1 |
-                                            SND_JACK_BTN_2 | SND_JACK_BTN_3 |
-                                            SND_JACK_BTN_4 | SND_JACK_BTN_5,
-                                            &pdata->hs_jack);
+               rval = snd_soc_card_jack_new_pins(card, "Headset Jack",
+                                                 SND_JACK_HEADSET | SND_JACK_LINEOUT |
+                                                 SND_JACK_MECHANICAL |
+                                                 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
+                                                 SND_JACK_BTN_2 | SND_JACK_BTN_3 |
+                                                 SND_JACK_BTN_4 | SND_JACK_BTN_5,
+                                                 &pdata->hs_jack,
+                                                 sc7280_jack_pins,
+                                                 ARRAY_SIZE(sc7280_jack_pins));
 
                if (rval < 0) {
                        dev_err(card->dev, "Unable to add Headset Jack\n");
@@ -361,6 +374,11 @@ static const struct snd_soc_dapm_widget sc7280_snd_widgets[] = {
        SND_SOC_DAPM_MIC("Headset Mic", NULL),
 };
 
+static const struct snd_kcontrol_new sc7280_snd_controls[] = {
+       SOC_DAPM_PIN_SWITCH("Headphone Jack"),
+       SOC_DAPM_PIN_SWITCH("Headset Mic"),
+};
+
 static int sc7280_snd_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
                                         struct snd_pcm_hw_params *params)
 {
@@ -396,6 +414,8 @@ static int sc7280_snd_platform_probe(struct platform_device *pdev)
 
        card->dapm_widgets = sc7280_snd_widgets;
        card->num_dapm_widgets = ARRAY_SIZE(sc7280_snd_widgets);
+       card->controls = sc7280_snd_controls;
+       card->num_controls = ARRAY_SIZE(sc7280_snd_controls);
 
        ret = qcom_snd_parse_of(card);
        if (ret)