Skip to contentSkip to conversation

jack detection via input/event on linux

Sound-open-firmware Pierre-Louis Bossart 3 participants 4 messages Jun 3, 2022 4 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#4 lore raw
In reply to a message not in the archive

[Adding alsa-devel, Mark and Takashi to this thread]

Quoted 13 lines · Jaroslav Kysela
Quoted 12 lines · hede

Am 03.06.2022 11:34, schrieb Jaroslav Kysela:

Quoted 6 lines

PA/PW use only ALSA controls at the moment - thus you should define JackControl as defined in use-case.h. But it seems that the driver does not create or publish the ALSA jack control (I see only "iface=CARD,name='HDMI/DP,pcm=2 Jack'" jack controls for HDMI).

                    Jaroslav

Ah, thank you Jaroslav. That's the hint I was searching for atm. JackDev vs. JackControl. I had a vague guess on this but now you made it certain.

Quoted 5 lines
Quoted 1 line

Maybe I should take a look into the driver directly.

It seems that many ASoC drivers do not create kctls - the argument pins is zero in the snd_soc_card_jack_new() call. The SND_JACK_HEADSET should be remapped to kctl in sound/soc/intel/boards/sof_rt5682.c, too.

Did you mean something like the patch below Jaroslav? If yes, most of the Chromebook machine drivers are missing this remapping. That would also explain why the jack detection didn't work on my GLK test device, despite a UCM file that looked good...

(quoted diff) +0 -0

b/sound/soc/intel/boards/sof_rt5682.c
index 5d67a2c87a1d4..1db17ebd26f63 100644

sound/soc/intel/boards/sof_rt5682.c +11 -0
@@ -85,6 +85,17 @@ struct sof_card_private {
 	bool idisp_codec;
 };
 
+static struct snd_soc_jack_pin sof_jack_pins[] = {
+	{
+		.pin    = "Headphone",
+		.mask   = SND_JACK_HEADPHONE,
+	},
+	{
+		.pin    = "Headset Mic",
+		.mask   = SND_JACK_MICROPHONE,
+	},
+};
+
 static int sof_rt5682_quirk_cb(const struct dmi_system_id *id)
 {
 	sof_rt5682_quirk = (unsigned long)id->driver_data;
@@ -295,11 +306,13 @@ static int sof_rt5682_codec_init(struct

snd_soc_pcm_runtime *rtd)
* Headset buttons map to the google Reference headset.
* These can be configured by userspace.
*/
- ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",

-				    SND_JACK_HEADSET | SND_JACK_BTN_0 |
-				    SND_JACK_BTN_1 | SND_JACK_BTN_2 |
-				    SND_JACK_BTN_3,
-				    &ctx->sof_headset);

+ 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,
+ &ctx->sof_headset,
+ sof_jack_pins,
+ ARRAY_SIZE(sof_jack_pins));
if (ret) {
dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); return ret;
@@ -481,7 +494,7 @@ 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("Headphone"),
SOC_DAPM_PIN_SWITCH("Headset Mic"), SOC_DAPM_PIN_SWITCH("Left Spk"), SOC_DAPM_PIN_SWITCH("Right Spk"),
@@ -489,7 +502,7 @@ static const struct snd_kcontrol_new sof_controls[] = {
};

static const struct snd_soc_dapm_widget sof_widgets[] = {
- SND_SOC_DAPM_HP("Headphone Jack", NULL),
+ SND_SOC_DAPM_HP("Headphone", NULL),
SND_SOC_DAPM_MIC("Headset Mic", NULL), SND_SOC_DAPM_SPK("Left Spk", NULL), SND_SOC_DAPM_SPK("Right Spk", NULL),
@@ -501,8 +514,8 @@ static const struct snd_soc_dapm_widget dmic_widgets[] = {

static const struct snd_soc_dapm_route sof_map[] = {
/* HP jack connectors - unknown if we have jack detection */
- { "Headphone Jack", NULL, "HPOL" },
- { "Headphone Jack", NULL, "HPOR" },
+ { "Headphone", NULL, "HPOL" },
+ { "Headphone", NULL, "HPOR" },

/* other jacks */
{ "IN1P", NULL, "Headset Mic" },

maintainer
#5 lore raw
Quoted 18 lines · Pierre-Louis Bossart

[Adding alsa-devel, Mark and Takashi to this thread]

Quoted 15 lines · Jaroslav Kysela
Quoted 13 lines · hede

Am 03.06.2022 11:34, schrieb Jaroslav Kysela:

Quoted 6 lines

PA/PW use only ALSA controls at the moment - thus you should define JackControl as defined in use-case.h. But it seems that the driver does not create or publish the ALSA jack control (I see only "iface=CARD,name='HDMI/DP,pcm=2 Jack'" jack controls for HDMI).

                    Jaroslav

Ah, thank you Jaroslav. That's the hint I was searching for atm. JackDev vs. JackControl. I had a vague guess on this but now you made it certain.

Maybe I should take a look into the driver directly.

Quoted 8 lines
Quoted 3 lines

It seems that many ASoC drivers do not create kctls - the argument pins is zero in the snd_soc_card_jack_new() call. The SND_JACK_HEADSET should be remapped to kctl in sound/soc/intel/boards/sof_rt5682.c, too.

Did you mean something like the patch below Jaroslav? If yes, most of the Chromebook machine drivers are missing this remapping. That would also explain why the jack detection didn't work on my GLK test device, despite a UCM file that looked good...

Yes, it looks like a way to go. It seems that the drivers were tested only with the CRAS audio server. Note that pulseaudio can be run with the user permissions only - thus the input devices may not be reachable.

Thanks,
Jaroslav

Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
#6 lore raw

Jaroslav, would it help if we made our UCMs closer to upstream so we could just send them directly so pulse could test them easier? (this is a goal I have, it just unfortunately really low priority)

Curtis Malainey | Chrome OS Audio Senior Software Engineer | [email protected] | We're Hiring!

Curtis Malainey | Chrome OS Audio Senior Software Engineer | [email protected] | We're Hiring!

Quoted 43 lines · Jaroslav Kysela
Quoted 18 lines · Pierre-Louis Bossart

[Adding alsa-devel, Mark and Takashi to this thread]

Quoted 15 lines · Jaroslav Kysela
Quoted 13 lines · hede

Am 03.06.2022 11:34, schrieb Jaroslav Kysela:

Quoted 6 lines

PA/PW use only ALSA controls at the moment - thus you should define JackControl as defined in use-case.h. But it seems that the driver does not create or publish the ALSA jack control (I see only "iface=CARD,name='HDMI/DP,pcm=2 Jack'" jack controls for HDMI).

Jaroslav

Ah, thank you Jaroslav. That's the hint I was searching for atm. JackDev vs. JackControl. I had a vague guess on this but now you made it certain.

Maybe I should take a look into the driver directly.

Quoted 8 lines
Quoted 3 lines

It seems that many ASoC drivers do not create kctls - the argument pins is zero in the snd_soc_card_jack_new() call. The SND_JACK_HEADSET should be remapped to kctl in sound/soc/intel/boards/sof_rt5682.c, too.

Did you mean something like the patch below Jaroslav? If yes, most of the Chromebook machine drivers are missing this remapping. That would also explain why the jack detection didn't work on my GLK test device, despite a UCM file that looked good...

Yes, it looks like a way to go. It seems that the drivers were tested only with the CRAS audio server. Note that pulseaudio can be run with the user permissions only - thus the input devices may not be reachable.

Thanks,
Jaroslav

--
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
_______________________________________________
Sound-open-firmware mailing list [email protected]
https://mailman.alsa-project.org/mailman/listinfo/sound-open-firmware

#7 lore raw
In reply to Jaroslav Kysela
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

It seems that many ASoC drivers do not create kctls - the argument pins is zero in the snd_soc_card_jack_new() call. The SND_JACK_HEADSET should be remapped to kctl in sound/soc/intel/boards/sof_rt5682.c, too.

Quoted 8 lines
Quoted 4 lines

Did you mean something like the patch below Jaroslav? If yes, most of the Chromebook machine drivers are missing this remapping. That would also explain why the jack detection didn't work on my GLK test device, despite a UCM file that looked good...

Yes, it looks like a way to go. It seems that the drivers were tested only with the CRAS audio server. Note that pulseaudio can be run with the user permissions only - thus the input devices may not be reachable.

I added a similar patch on a GeminiLake device, and it does help with jack detection (along with an update in
https://github.com/alsa-project/alsa-ucm-conf/pull/150).

I can see PulseAudio detecting the changes, but for some reason the automatic switch only happens when the jack is unplugged. I still have to manually select the headphone/headset after plugging it in. Likely still missing something in the UCM file?

D: [pulseaudio] module-alsa-card.c: Jack 'Headphone Jack' is now unplugged

D: [pulseaudio] device-port.c: Setting port [Out] Headphone to status no

D: [pulseaudio] module-switch-on-port-available.c: Trying to switch away from port [Out] Headphone, found [Out] Speaker

D: [pulseaudio] module-alsa-card.c: Jack 'Headset Mic Jack' is now unplugged

D: [pulseaudio] device-port.c: Setting port [In] Headset to status no

D: [pulseaudio] core-subscribe.c: Dropped redundant event due to change event.

D: [pulseaudio] module-switch-on-port-available.c: Trying to switch away from port [In] Headset, found [In] InternalMic

<<< AUTOMATIC SWITCH DONE

D: [pulseaudio] module-alsa-card.c: Jack 'Headphone Jack' is now plugged in

D: [pulseaudio] device-port.c: Setting port [Out] Headphone to status yes

D: [pulseaudio] module-alsa-card.c: Jack 'Headset Mic Jack' is now plugged in

D: [pulseaudio] device-port.c: Setting port [In] Headset to status yes

<<< NOTHING HAPPENS HERE

D: [pulseaudio] module-alsa-card.c: Jack 'Headphone Jack' is now unplugged

D: [pulseaudio] device-port.c: Setting port [Out] Headphone to status no

D: [pulseaudio] module-switch-on-port-available.c: Trying to switch away from port [Out] Headphone, found [Out] Speaker

D: [pulseaudio] module-alsa-card.c: Jack 'Headset Mic Jack' is now unplugged

D: [pulseaudio] device-port.c: Setting port [In] Headset to status no

D: [pulseaudio] core-subscribe.c: Dropped redundant event due to change event.

D: [pulseaudio] module-switch-on-port-available.c: Trying to switch away from port [In] Headset, found [In] InternalMic