From nobody Tue Jan 30 15:14:59 2024
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 4TPTHR2YB6z591Ph;
Tue, 30 Jan 2024 15:14: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 "R3" (verified OK))
by mx1.freebsd.org (Postfix) with ESMTPS id 4TPTHR1sbGz3ww8;
Tue, 30 Jan 2024 15:14:59 +0000 (UTC)
(envelope-from git@FreeBSD.org)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
t=1706627699;
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=I1yEPx3NX18F1CfGbU0SST82zsDYzxFpLEsdN2safi0=;
b=dyKdb01T+ibgWwh0C/sw+Kks013bic21kz/UrrlFIMPd7B1EQkkq7A5d1A1b4zZzYIaZE0
bhDgkFZS10J2Hdfr7P4U0AtyUvzg8NhdQLhgIeWEKkqhRkVvwOE9UuLOT2XNfBmRJwXUck
RdCZrgySQX/XwoxGJY7dnIL2EZC20pbtAd7Hq86nYCF1LhXuR/8TVa4Zu0I6OF53nkRk7o
CUCWY5l94Eim8kftpTABJoigcDO/pFAj9SnwzY3pzwsZz9xc6LHDi6H4eUY/+ZSdgxh+y5
ptynPwkjlGlt6JH8n37BClPlayVn/8xWppC9fFrl0K4gkZ1jaNqk5pj0qAP4IA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org;
s=dkim; t=1706627699;
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=I1yEPx3NX18F1CfGbU0SST82zsDYzxFpLEsdN2safi0=;
b=XZBcou2pG0hBzuwaim6FePaES7Kx99pmaRd58pVEGCPZNym/scAuto8wc4ymZS9MGDpQhK
pK/4x0hJUTPq8hiES1DLav98DVzvVULD0JILhWNoJebkYMdEEDCr3k7dhpMkjQRCMfU00C
wp69H8UHDDYeT3pRJ5GLu9a5wi0gyTSqg37PLbv33ZGMJhnMktEvnGV+pS7u3d8pPWn8/f
VWQauWObY7M5Sn7P8ptbWPtFtw2ipxbyRYpzU1iBNJmk/NVM8LI6a7kQCQkjLKaEszMhmU
79R94X7EV+SfhIf6d/cSy/p4K6xzqMJIttey2ZYivrtTMHTVPFwenfvqQHUS8Q==
ARC-Authentication-Results: i=1;
mx1.freebsd.org;
none
ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706627699; a=rsa-sha256; cv=none;
b=BnZGFjsxz2+JnA7jcHhlK0uKa0HEy1FnehvQCCyd5xrdkS9F+69O2ra1dQPHoJtFvraq5/
1DYNXDJM8i1fcAEVa925lMyEHj5XKPUxp7h3QZOWoICKlUkmAI64UYt1DzhE0/YiyWO1kQ
9mOPHQquXhLRZ3Cv3qJbFJwp3RiJpS7EbOsqPM57S7A6qOFfuUcKXo2pItUOay501t0Yn8
YC86if09Y3D7883FcvzZPor0rU7G7WyW1vqgVKthFoR8JcjDiZYpuNV/E3KQth+ZaammHT
MxbF3mCdzevE1xfOyTaZRJUpeFZiroykM+5dUImsDnGDTE75a5wMwGulXyqlig==
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 4TPTHR0wpGzgxw;
Tue, 30 Jan 2024 15:14:59 +0000 (UTC)
(envelope-from git@FreeBSD.org)
Received: from gitrepo.freebsd.org ([127.0.1.44])
by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40UFExq5096824;
Tue, 30 Jan 2024 15:14:59 GMT
(envelope-from git@gitrepo.freebsd.org)
Received: (from git@localhost)
by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40UFExYg096821;
Tue, 30 Jan 2024 15:14:59 GMT
(envelope-from git)
Date: Tue, 30 Jan 2024 15:14:59 GMT
Message-Id: <202401301514.40UFExYg096821@gitrepo.freebsd.org>
To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org,
dev-commits-src-main@FreeBSD.org
From: Ruslan Bukin
Subject: git: 6c892b79de59 - main - snd_hdspe(4): Per device sysctl
for sample rate.
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:
Sender: owner-dev-commits-src-all@freebsd.org
X-BeenThere: dev-commits-src-all@freebsd.org
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Git-Committer: br
X-Git-Repository: src
X-Git-Refname: refs/heads/main
X-Git-Reftype: branch
X-Git-Commit: 6c892b79de590443a180269507f61f3d8a9ec879
Auto-Submitted: auto-generated
The branch main has been updated by br:
URL: https://cgit.FreeBSD.org/src/commit/?id=6c892b79de590443a180269507f61f3d8a9ec879
commit 6c892b79de590443a180269507f61f3d8a9ec879
Author: Florian Walpen
AuthorDate: 2024-01-30 15:07:57 +0000
Commit: Ruslan Bukin
CommitDate: 2024-01-30 15:07:57 +0000
snd_hdspe(4): Per device sysctl for sample rate.
Some hardware setups require a specific sample rate due to devices being
connected to digital ports (AES, S/PDIF, ADAT). Add a per device sysctl
"sample_rate" to let the user override sample rate requests from the pcm
infrastructure, when needed.
Differential Revision: https://reviews.freebsd.org/D43659
---
share/man/man4/snd_hdspe.4 | 6 +++++-
sys/dev/sound/pci/hdspe-pcm.c | 3 +++
sys/dev/sound/pci/hdspe.c | 42 ++++++++++++++++++++++++++++++++++++++++++
sys/dev/sound/pci/hdspe.h | 1 +
4 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/share/man/man4/snd_hdspe.4 b/share/man/man4/snd_hdspe.4
index d4ddc70f4070..7d8cc2adc1af 100644
--- a/share/man/man4/snd_hdspe.4
+++ b/share/man/man4/snd_hdspe.4
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd January 19, 2024
+.Dd January 29, 2024
.Dt SND_HDSPE 4
.Os
.Sh NAME
@@ -76,6 +76,10 @@ To adjust the following sysctl identifiers for a specific sound card, insert
the respective device number in place of
.Ql 0 .
.Bl -tag -width indent
+.It Va dev.hdspe.0.sample_rate
+Set a fixed sample rate from 32000, 44100, 48000, up to 192000.
+This is usually required for digital connections (AES, S/PDIF, ADAT).
+The default value of 0 adjusts the sample rate according to pcm device settings.
.It Va dev.hdspe.0.period
The number of samples processed per interrupt, from 32, 64, 128, up to 4096.
Setting a lower value here results in less latency, but increases system load
diff --git a/sys/dev/sound/pci/hdspe-pcm.c b/sys/dev/sound/pci/hdspe-pcm.c
index f6c7c84e026e..cf764f19a933 100644
--- a/sys/dev/sound/pci/hdspe-pcm.c
+++ b/sys/dev/sound/pci/hdspe-pcm.c
@@ -814,6 +814,9 @@ hdspechan_setspeed(kobj_t obj, void *data, uint32_t speed)
if (hdspe_running(sc) == 1)
goto end;
+ if (sc->force_speed > 0)
+ speed = sc->force_speed;
+
/* First look for equal frequency. */
for (i = 0; rate_map[i].speed != 0; i++) {
if (rate_map[i].speed == speed)
diff --git a/sys/dev/sound/pci/hdspe.c b/sys/dev/sound/pci/hdspe.c
index b1ca67bdc313..1d1068c9f8fe 100644
--- a/sys/dev/sound/pci/hdspe.c
+++ b/sys/dev/sound/pci/hdspe.c
@@ -228,6 +228,41 @@ hdspe_map_dmabuf(struct sc_info *sc)
}
}
+static int
+hdspe_sysctl_sample_rate(SYSCTL_HANDLER_ARGS)
+{
+ struct sc_info *sc = oidp->oid_arg1;
+ int error;
+ unsigned int speed, multiplier;
+
+ speed = sc->force_speed;
+
+ /* Process sysctl (unsigned) integer request. */
+ error = sysctl_handle_int(oidp, &speed, 0, req);
+ if (error != 0 || req->newptr == NULL)
+ return (error);
+
+ /* Speed from 32000 to 192000, 0 falls back to pcm speed setting. */
+ sc->force_speed = 0;
+ if (speed > 0) {
+ multiplier = 1;
+ if (speed > (96000 + 128000) / 2)
+ multiplier = 4;
+ else if (speed > (48000 + 64000) / 2)
+ multiplier = 2;
+
+ if (speed < ((32000 + 44100) / 2) * multiplier)
+ sc->force_speed = 32000 * multiplier;
+ else if (speed < ((44100 + 48000) / 2) * multiplier)
+ sc->force_speed = 44100 * multiplier;
+ else
+ sc->force_speed = 48000 * multiplier;
+ }
+
+ return (0);
+}
+
+
static int
hdspe_sysctl_period(SYSCTL_HANDLER_ARGS)
{
@@ -455,6 +490,7 @@ hdspe_init(struct sc_info *sc)
/* Set rate. */
sc->speed = HDSPE_SPEED_DEFAULT;
+ sc->force_speed = 0;
sc->ctrl_register &= ~HDSPE_FREQ_MASK;
sc->ctrl_register |= HDSPE_FREQ_MASK_DEFAULT;
hdspe_write_4(sc, HDSPE_CONTROL_REG, sc->ctrl_register);
@@ -562,6 +598,12 @@ hdspe_attach(device_t dev)
sc, 0, hdspe_sysctl_period, "A",
"Force period of samples per interrupt (32, 64, ... 4096)");
+ SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
+ SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
+ "sample_rate", CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_MPSAFE,
+ sc, 0, hdspe_sysctl_sample_rate, "A",
+ "Force sample rate (32000, 44100, 48000, ... 192000)");
+
return (bus_generic_attach(dev));
}
diff --git a/sys/dev/sound/pci/hdspe.h b/sys/dev/sound/pci/hdspe.h
index 81116e0cd437..26694f60ce58 100644
--- a/sys/dev/sound/pci/hdspe.h
+++ b/sys/dev/sound/pci/hdspe.h
@@ -228,6 +228,7 @@ struct sc_info {
uint32_t period;
uint32_t speed;
uint32_t force_period;
+ uint32_t force_speed;
};
#define hdspe_read_1(sc, regno) \