Date: Tue, 30 Sep 2025 10:52:59 GMT From: Christos Margiolis <christos@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 2ffaca551eaf - main - snd_hda: Implement automatic redirection between associations Message-ID: <202509301052.58UAqxgM026265@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=2ffaca551eaf32c17f701762ecf29a961cf19aa4 commit 2ffaca551eaf32c17f701762ecf29a961cf19aa4 Author: Christos Margiolis <christos@FreeBSD.org> AuthorDate: 2025-09-30 10:52:44 +0000 Commit: Christos Margiolis <christos@FreeBSD.org> CommitDate: 2025-09-30 10:52:44 +0000 snd_hda: Implement automatic redirection between associations For audio to be redirected to the headphones/headset after plugging the jack, or back to the speaker/internal mic when unplugging it, the speaker and headphone pins need to be part of the same association (i.e., the same PCM device). This patch makes it possible to redirect audio even between different associations, which can reduce the need for manual pin patching. The idea is that we issue a devctl_notify() from within the jack detection callback whenever a jack is (un-)plugged to redirect audio to the appropriate device. Then the snd.conf devd script is responsible for using virtual_oss to change the playback/recording device to whatever snd_hda(4) selected. The reason for requiring virtual_oss is that it has hot-swapping support, which is necessary for jack redirection. Sponsored by: The FreeBSD Foundation MFC after: 2 days Differential Revision: https://reviews.freebsd.org/D50070 --- sbin/devd/Makefile | 5 +++++ sbin/devd/devd.conf.5 | 16 +++++++++++++ sbin/devd/snd.conf | 23 +++++++++++++++++++ sys/dev/sound/pci/hda/hdaa.c | 53 +++++++++++++++++++++++++++++++++----------- 4 files changed, 84 insertions(+), 13 deletions(-) diff --git a/sbin/devd/Makefile b/sbin/devd/Makefile index 5d5721d16884..f65eee93dd4b 100644 --- a/sbin/devd/Makefile +++ b/sbin/devd/Makefile @@ -51,6 +51,11 @@ NVMEDIR= ${DEVDDIR} NVME+= nvmf.conf NVMEPACKAGE= nvme-tools +CONFGROUPS+= SND +SNDDIR= ${DEVDDIR} +SND+= snd.conf +SNDPACKAGE= snd + .if ${MK_USB} != "no" DEVD+= uath.conf ulpt.conf .endif diff --git a/sbin/devd/devd.conf.5 b/sbin/devd/devd.conf.5 index baf4b9d3a183..8df3e910e076 100644 --- a/sbin/devd/devd.conf.5 +++ b/sbin/devd/devd.conf.5 @@ -652,6 +652,22 @@ and for details. .El .Pp +.Bl -column "System" "Subsystem" "1234567" -compact +.Sy "System" Ta Sy "Subsystem" Ta Sy "Type" Ta Sy "Description" +.It Li SND Ta Ta Ta +Events related to the +.Xr sound 4 +driver. +.It Li SND Ta Li CONN Ta Li IN Ta +Connected input device specified in +.Pa cdev +variable. +.It Li SND Ta Li CONN Ta Li OUT Ta +Connected output device specified in +.Pa cdev +variable. +.El +.Pp .\" .\" End of tables .\" diff --git a/sbin/devd/snd.conf b/sbin/devd/snd.conf new file mode 100644 index 000000000000..cf9cd9e94191 --- /dev/null +++ b/sbin/devd/snd.conf @@ -0,0 +1,23 @@ +# Audio redirection +notify 0 { + match "system" "SND"; + match "subsystem" "CONN"; + match "type" "IN"; + match "cdev" "dsp[0-9]+"; + + # FIXME: We are hardcoding /dev/vdsp.ctl here, simply because it is a + # common virtual_oss control device name. Until we find a proper way to + # define control devices here, /dev/vdsp.ctl can be changed to the + # control device of choice. + action "/usr/sbin/virtual_oss_cmd /dev/vdsp.ctl -R /dev/$cdev"; +}; + +notify 0 { + match "system" "SND"; + match "subsystem" "CONN"; + match "type" "OUT"; + match "cdev" "dsp[0-9]+"; + + # FIXME: See comment above. + action "/usr/sbin/virtual_oss_cmd /dev/vdsp.ctl -P /dev/$cdev"; +}; diff --git a/sys/dev/sound/pci/hda/hdaa.c b/sys/dev/sound/pci/hda/hdaa.c index 1e486b01b168..5dbb5c4f4453 100644 --- a/sys/dev/sound/pci/hda/hdaa.c +++ b/sys/dev/sound/pci/hda/hdaa.c @@ -532,9 +532,11 @@ static void hdaa_presence_handler(struct hdaa_widget *w) { struct hdaa_devinfo *devinfo = w->devinfo; - struct hdaa_audio_as *as; + struct hdaa_audio_as *as, *asp; + char buf[32]; uint32_t res; - int connected, old; + int connected, old, i; + bool active; if (w->enable == 0 || w->type != HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX) @@ -552,13 +554,6 @@ hdaa_presence_handler(struct hdaa_widget *w) if (connected == old) return; w->wclass.pin.connected = connected; - HDA_BOOTVERBOSE( - if (connected || old != 2) { - device_printf(devinfo->dev, - "Pin sense: nid=%d sense=0x%08x (%sconnected)\n", - w->nid, res, !connected ? "dis" : ""); - } - ); as = &devinfo->as[w->bindas]; if (as->hpredir >= 0 && as->pins[15] == w->nid) @@ -567,6 +562,38 @@ hdaa_presence_handler(struct hdaa_widget *w) hdaa_autorecsrc_handler(as, w); if (old != 2) hdaa_channels_handler(as); + + if (connected || old != 2) { + HDA_BOOTVERBOSE( + device_printf(devinfo->dev, + "Pin sense: nid=%d sense=0x%08x (%sconnected)\n", + w->nid, res, !connected ? "dis" : ""); + ); + if (as->hpredir >= 0) + return; + for (i = 0, active = false; i < devinfo->num_devs; i++) { + if (device_get_unit(devinfo->devs[i].dev) == snd_unit) { + active = true; + break; + } + } + /* Proceed only if we are currently using this codec. */ + if (!active) + return; + for (i = 0; i < devinfo->ascnt; i++) { + asp = &devinfo->as[i]; + if (!asp->enable) + continue; + if ((connected && asp->index == as->index) || + (!connected && asp->dir == as->dir)) { + snprintf(buf, sizeof(buf), "cdev=dsp%d", + device_get_unit(asp->pdevinfo->dev)); + devctl_notify("SND", "CONN", + asp->dir == HDAA_CTL_IN ? "IN" : "OUT", buf); + break; + } + } + } } /* @@ -6193,16 +6220,16 @@ hdaa_configure(device_t dev) device_printf(dev, "Applying direct built-in patches...\n"); ); hdaa_patch_direct(devinfo); - HDA_BOOTHVERBOSE( - device_printf(dev, "Pin sense init...\n"); - ); - hdaa_sense_init(devinfo); HDA_BOOTHVERBOSE( device_printf(dev, "Creating PCM devices...\n"); ); hdaa_unlock(devinfo); hdaa_create_pcms(devinfo); hdaa_lock(devinfo); + HDA_BOOTHVERBOSE( + device_printf(dev, "Pin sense init...\n"); + ); + hdaa_sense_init(devinfo); HDA_BOOTVERBOSE( if (devinfo->quirks != 0) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202509301052.58UAqxgM026265>