From nobody Tue Sep 30 10:52:59 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 4cbZf31nyNz68tJn; Tue, 30 Sep 2025 10:52:59 +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 4cbZf319hzz3R8W; Tue, 30 Sep 2025 10:52:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759229579; 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=iZZ64ZyozRyodkrtdeEqX17lhFJli9gGYRk93FtnpJo=; b=m7thipxf/iM/BO4fczItj3mpqJdfTbPDMQAEIXa7jJCzEmQ1bgQVAMWFv+3J1AHebQuqFY L9i3Qi2Cy1im8f/BBz5vjkXzIfHhYj3yJYerZ0QPJ2TIDz6nAYHY+X9B43Ihrg/QyQA+wO 3z3q72hnQnYCB6OLgUTokqNTo5zR0xj7L4XS9GwlHCvM+B6/Gqt7LaR0xpfXO9vwQX/y3P dEmsLYzzz7jUdeMbzh7DIT1Rxv3bo8ofebbiAwQDnr38jqKkQp/4qzlye1AJLwxorg/YZk wbTm++XL2gtY0FRuM6lEh/thrWZ0w3zo6ijY0RhaiwWs0rTCaDlLouVFDy5T2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759229579; 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=iZZ64ZyozRyodkrtdeEqX17lhFJli9gGYRk93FtnpJo=; b=MIf5kJBSQwlG7aQ6XsRzMCvjowNWsTEz5756HoFYqXpwEoI+SMSHKJDC3o6BmJJO7trJCt oBQhm/+mzN9qZ7EIyQzg2gELeYOExCm+BTrQnKbo9ZV+G4BUeN4YeUbITCFmHY725wfUrZ h/lQkDsVYYf7yWzZeCFn4qkrdwXBhv6Ncd2C4FRhDr5YMSerdDvtdLVvIkUgT9JnKj5Z3Z tar0n7kUL3wOLvVOufxK1XFDYo8Q91wDCOK6Bcn9mhW6M0cxziLTgsd3t8quAOOZk5hebq klgUho+cLJ/aFZ68XeLQd5i1gRdO3TArbV9gdSaTWm2OuO4arVQNYQRvd8fCLg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1759229579; a=rsa-sha256; cv=none; b=Ec+Gy+/0goxALYQErcReRFTDVGrgv5wkrLidKh4xogK0jBalcC/dqhV7fUObL2uVMMOpuJ rdQMSw2EwpI1HXUYr3T/RCh4XLbJfEzpA/KeJVuvujREIg6uVFVB+wzMjIY0Nn8YNK2Zer oEnrYT/7LIIfcEanO4zuY2uphqD5GsYTTMQN1bS98nvofeW0YtSbI000DsrIfJFDS2/2pf hHeARVOLe4zqY3CRjbn56HWF3xbg1IqyIwdaBsGlSpTjG6tU+Ji4/Z2EWmOreKSkA554I8 E8qpz5VNS5WGX0Nw3jtIflmdeoAQ5JkjEDSY+yOVCBtq5x3HD85IfF0L8hRB0w== 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 4cbZf30W4HzYqv; Tue, 30 Sep 2025 10:52:59 +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 58UAqxCi026268; Tue, 30 Sep 2025 10:52:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58UAqxgM026265; Tue, 30 Sep 2025 10:52:59 GMT (envelope-from git) Date: Tue, 30 Sep 2025 10:52:59 GMT Message-Id: <202509301052.58UAqxgM026265@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: 2ffaca551eaf - main - 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/main X-Git-Reftype: branch X-Git-Commit: 2ffaca551eaf32c17f701762ecf29a961cf19aa4 Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=2ffaca551eaf32c17f701762ecf29a961cf19aa4 commit 2ffaca551eaf32c17f701762ecf29a961cf19aa4 Author: Christos Margiolis AuthorDate: 2025-09-30 10:52:44 +0000 Commit: Christos Margiolis 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) {