From nobody Thu Oct 2 07:32:08 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4cck5P1CYrz69DtT; Thu, 02 Oct 2025 07:32:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cck5N6mTQz4JCg; Thu, 02 Oct 2025 07:32:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759390329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9vGcNK8UgCgUtUASTtl1Af8BD4UvUjTlAb2EaME/+CA=; b=dE57maiwWJKIRnEK7SGw/i16rLF6CZlI+Y8X9r89Y4DSfwfg3Zw3503Hm4NkFePHDnKn2e HsTNkr7xFPyYgtTkB3RfJSdSQdFpuD0ghXeIpOqcqbLocpMusviV4/ICaWlBfxIrxpp+G6 w3zdwBkKx8onLSyTYfJjXB4KogmPgWFHC+BxBTIhTS0dtXQQcMcLLxB8i7smXrjSTKltGf XlRPrGf6FK7crd/NqwJEXAxWbT7pu5uHfe+8GJ9K6qVFL/wvzfYaosb4ymShppp902FpM3 P+4URsO6kx6sWBnb6jYSUTcQfkP1RCm2hejmHmBNLlji79JufYiSc61Y4J0Aew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759390329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9vGcNK8UgCgUtUASTtl1Af8BD4UvUjTlAb2EaME/+CA=; b=pAWS9NsT7bZX/1vgm6BuD+D4lNFnQ3/Ph64lJuw1Rdo+c1R5WVIqDxd2NOIfLG6uJa/Kwz WvjwKYzK6PgaSc4EWbTPn1ngnzYvPTGRSV9lWzElWMdj3wDWZa8L5QmeRH7GivTh573mh1 0QxLIAEErhXRNyYS+yVWg903ns0UaMnwMWv3NSQQxVDlhpRRSecYoaX3hI8i00MbYtoZTv r09hQO4ASdvZ5JTQRW/3UnfDzdOp/nQaFWs5GQi50S7n9aaR4IcvhBVI0H29SauZPT8S0q roTm5EEX3km21WuZe5m9gWRP3C5fMgf6keGP9C3eXCf3CVPj7K2F9TemXPB9tA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1759390329; a=rsa-sha256; cv=none; b=aBpIVUNbsNv+FIJdr4LKpqGZ/HEwZqfIOkbJBzhKU1fMClWb5FqSa8HtX4uTfwO+kes1Vj IH4HEogkvbyCMnNxwyuHco4gaSS+MfHo8vZM4I6NwDs3a1Nh8bwY34sW2atEtfCRiXJvMv 2LyF15bDTdSV0VLkrVnK0LgoZWQIE2+9BLIljxc3XgotcLyYJsybpXJu7CzG1EkoSKjWhN R7NWW+zUFiH6qz4e9IQNGHzCl08S7urSZkNDua/pLTrfj4yY87q9P0X7X+mR8LZOsBtdMr aqUeNRyxaLIHmEcaIysEzs17pyvWEdl/XsP5ycpsKBDq+q/a7GeHo9SMqtQlyg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cck5N5w8vzyX2; Thu, 02 Oct 2025 07:32:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5927W8Y1031221; Thu, 2 Oct 2025 07:32:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5927W8ck031218; Thu, 2 Oct 2025 07:32:08 GMT (envelope-from git) Date: Thu, 2 Oct 2025 07:32:08 GMT Message-Id: <202510020732.5927W8ck031218@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Christos Margiolis Subject: git: 57327328f141 - stable/15 - snd_hda: Implement automatic redirection between associations List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 57327328f141bcdb6dbb81f0cd456eeca2080f43 Auto-Submitted: auto-generated The branch stable/15 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=57327328f141bcdb6dbb81f0cd456eeca2080f43 commit 57327328f141bcdb6dbb81f0cd456eeca2080f43 Author: Christos Margiolis AuthorDate: 2025-09-30 10:52:44 +0000 Commit: Christos Margiolis CommitDate: 2025-10-02 07:31:29 +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 (cherry picked from commit 2ffaca551eaf32c17f701762ecf29a961cf19aa4) (cherry picked from commit 5cc36854ee63dc695d90a841d9db587bec67ba24) --- sbin/devd/Makefile | 2 +- sbin/devd/devd.conf.5 | 16 +++++++++++++ sbin/devd/snd.conf | 23 +++++++++++++++++++ sys/dev/sound/pci/hda/hdaa.c | 53 +++++++++++++++++++++++++++++++++----------- 4 files changed, 80 insertions(+), 14 deletions(-) diff --git a/sbin/devd/Makefile b/sbin/devd/Makefile index 5d5721d16884..dad6f4f9c340 100644 --- a/sbin/devd/Makefile +++ b/sbin/devd/Makefile @@ -4,7 +4,7 @@ WARNS?= 6 PACKAGE=devd CONFGROUPS= CONFS DEVD CONFS= devd.conf -DEVD= devmatch.conf +DEVD= devmatch.conf snd.conf DEVDDIR= /etc/devd .if ${MK_ACPI} != "no" DEVD+= asus.conf 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) {