Can't set-up automatic speaker to headphones switch

Hello, I am having some issues with the sound devices on my Thinkpad 430 (running FreeBSD 13.2-RELEASE). I cannot figure out which numbers to use in device.hints so that the sound switches automatically from speakers to jack. So far, setting 'sysctl hw.snd.default_unit=1' as default and running a script to switch to speakers does the trick.

Here are some outputs, in hopes someone has had a similar issue and can help. Thanks in advance.

loader.conf
Code:
kern.geom.label.disk_ident.enable="0"
kern.geom.label.gptid.enable="0"
cryptodev_load="YES"
zfs_load="YES"
fusefs_load="YES"
snd_driver_load="YES"


 
I just copied someone else attempt and luckily it worked out...

 
  • Thanks
Reactions: mro
Ah yes, fun with nids and friends. The manpage of snd_hda(4) has a very exhaustive example section, where it demonstrates how to configure these things. The whole manpage is definitly worth a read (or two or eight ;)).

Now your case: let's look at your original pin configuration. hdaa.1 corresponds to your HDMI/DP output. hdaa.0 corresponds to your analog inputs and outputs. nids with conn=None are not connected to any of your physical jacks, so we disregard these. Now your original pin configuration is this (only for hdaa.0 and connected nids, in ascending association order):

Code:
nid=20, as=1, seq=0, device=Speaker
nid=21, as=2, seq=0, device=Headphones
nid=24, as=3, seq=0, device=Mic
nid=18, as=4, seq=0, device=Mic

The association number as groups the indivdual pins (=nids). Each pin in an association has the same direction, either all for output or all for input. A seperate PCM device is created for every pair of output and input associations. What does this mean for your original configuration? Well, all your nids have a different association number, so none of your nids form a group. nid=20 corresponds to your speaker (=output), nid=21 corresponds to your headphones (=output), nid=24 and 18 correspond to your mics (=inputs). Now the PCM devices are created with pairing output and input devices (in ascending associotian order). That is:

Code:
PCM0 = { nid20, nid24 } (Speaker + Mic)
PCM1 = { nid21, nid18 } (Headphones + Mic)

That is your original configuration. Now you want to group the headphones with the speaker. We have to give them the same association number. The sequence number seq has a special meaning for the pins inside a group, read snd_hda(4). In order for the sound to switch automagically from the speakers to the headphones (and back), we have to give the headphones the sequence number 15. So this should be our goal:

Code:
nid=20, as=1, seq=0, device=Speaker
nid=21, as=1, seq=15, device=Headphones
nid=24, as=2, seq=0, device=Mic
nid=18, as=3, seq=0, device=Mic

You could change the settings for the mics too (stereo audio recording with a pcm device constructed out of two mic inputs???), but we leave them be for now. The speaker and headphones are now in the same output association. With sequence number 15 for the headphones in this association, the sound driver will switch the sound output when it detects a insert into the headphone jack. We have now one output association (speaker + headphones) and two seperate input associations. These PCM devices will be created:

Code:
PCM0 = { nid20, nid21, nid24 } (Speaker + Headphones + Mic)
PCM1 = { nid18 } (Mic)

So the entry in device.hints should be:

Code:
hint.hdaa.0.nid21.config="as=1 seq=15"

That is, only change the association and sequence number of your headphone nid. If I'm not mistaken, this should do it.
 
Ah yes, fun with nids and friends. The manpage of snd_hda(4) has a very exhaustive example section, where it demonstrates how to configure these things. The whole manpage is definitly worth a read (or two or eight ;)).

Now your case: let's look at your original pin configuration. hdaa.1 corresponds to your HDMI/DP output. hdaa.0 corresponds to your analog inputs and outputs. nids with conn=None are not connected to any of your physical jacks, so we disregard these. Now your original pin configuration is this (only for hdaa.0 and connected nids, in ascending association order):
nid=24, as=3,
Code:
nid=20, as=1, seq=0, device=Speaker
nid=21, as=2, seq=0, device=Headphones
nid=24, as=3, seq=0, device=Mic
nid=18, as=4, seq=0, device=Mic

The association number as groups the indivdual pins (=nids). Each pin in an association has the same direction, either all for output or all for input. A seperate PCM device is created for every pair of output and input associations. What does this mean for your original configuration? Well, all your nids have a different association number, so none of your nids form a group. nid=20 corresponds to your speaker (=output), nid=21 corresponds to your headphones (=output), nid=24 and 18 correspond to your mics (=inputs). Now the PCM devices are created with pairing output and input devices (in ascending associotian order). That is:

Code:
PCM0 = { nid20, nid24 } (Speaker + Mic)
PCM1 = { nid21, nid18 } (Headphones + Mic)

That is your original configuration. Now you want to group the headphones with the speaker. We have to give them the same association number. The sequence number seq has a special meaning for the pins inside a group, read snd_hda(4). In order for the sound to switch automagically from the speakers to the headphones (and back), we have to give the headphones the sequence number 15. So this should be our goal:

Code:
nid=20, as=1, seq=0, device=Speaker
nid=21, as=1, seq=15, device=Headphones
nid=24, as=2, seq=0, device=Mic
nid=18, as=3, seq=0, device=Mic

You could change the settings for the mics too (stereo audio recording with a pcm device constructed out of two mic inputs???), but we leave them be for now. The speaker and headphones are now in the same output association. With sequence number 15 for the headphones in this association, the sound driver will switch the sound output when it detects a insert into the headphone jack. We have now one output association (speaker + headphones) and two seperate input associations. These PCM devices will be created:

Code:
PCM0 = { nid20, nid21, nid24 } (Speaker + Headphones + Mic)
PCM1 = { nid18 } (Mic)

So the entry in device.hints should be:

Code:
hint.hdaa.0.nid21.config="as=1 seq=15"

That is, only change the association and sequence number of your headphone nid. If I'm not mistaken, this should do it.
Works like a charm, thank you so much !
 
Ah yes, fun with nids and friends. The manpage of snd_hda(4) has a very exhaustive example section, where it demonstrates how to configure these things. The whole manpage is definitly worth a read (or two or eight ;)).

etc etc...
Huge thanks for that, I have an AMD chipset ThinkPad X13 Gen 1 and following your steps gets the headphones working / switching, something I've failed to figure out for months.

Specific magic for anyone trying to follow along was:

> % sysctl -a | grep original

Ignore any conn=None lines, result on this machine in ascending order:

>
dev.hdaa.1.nid20_original: 0x90170110 as=1 seq=0 device=Speaker conn=Fixed ctype=Analog loc=Internal color=Unknown misc=1
dev.hdaa.1.nid33_original: 0x04211020 as=2 seq=0 device=Headphones conn=Jack ctype=1/8 loc=Right color=Black misc=0
dev.hdaa.1.nid25_original: 0x04a11030 as=3 seq=0 device=Mic conn=Jack ctype=1/8 loc=Right color=Black misc=0

And the fix therefore, add the following hint to /boot/loader.conf (/boot/device.hints is read only for me and I assume for others on 13.2) to associate Headphones on nid33 into the same group as Speaker on nid20 i.e. "as=1" with "seq=15" to trigger the autoswitching magic:

> hint.hdaa.1.nid33.config="as=1 seq=15"
 
Back
Top