From nobody Tue Oct 29 16:18:12 2024 X-Original-To: dev-commits-src-main@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 4XdFmP06J6z5bf3w; Tue, 29 Oct 2024 16:18:13 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XdFmN6bW7z4kQY; Tue, 29 Oct 2024 16:18:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730218692; 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=4/nAxxnfeW+FMluK4g0XhFhN1pUn0fT2E7eZSPmvc8I=; b=C+Qu2pQOHJg0KWp/4ztlDOFg5FV4NZpEWLzdDRWzvkoSyXvKsdB1PT3kBT+GQ//1tO4927 S/DS3nqAKiC3dE46RRpQiBnrAAdWp2Y1JptqK1rcnVtru/aAe6tSCc6P2PBvCMd41H81BV cuyPgBr2G5IDpRoPAsBHge4jMWjeerXGrJIOwpNokuXLdi5Ax5ixB56D5iIZPC8UC5dcLx gjszEvpbmfiHsH/5oYvg7HrWn6nqOPQSK7lznRW08ZsF7cLm1laix/k4tCWc5iNd8eXCsr EwFY2GSE/i5Z7TsT2RdAqDmKOrDQpqe2pCnYeoWw7UuYnCVtn8PcjhlBHjYqeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730218692; 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=4/nAxxnfeW+FMluK4g0XhFhN1pUn0fT2E7eZSPmvc8I=; b=k7Rf/roMjfX+9uNvhFxynzcrceZkze98ffVMooz/My0ca4mXA3Dn3cK59ZNEOndr5dGyqS DAQ9ZD9jbBezxLPO+fUVz2TKszw5QD9MTwB760FuaFnwO9wx2TScQ19WrfmD6hz7ly+yEz tVOmLXCHYsBJBbKu8bLhBUOgX3T/uVM0NxILfOwDSC9pY/ff3w41XAVfucKhRrJav1Ib9C vusAvK5YE0oWpGh0jIc6mY30FbgT7urErvCkFiYzuqk0AxUGJ4PubWNWSvGWO5MvS1zgYa T6vYEYlsKujVoZ1KQtD+Nc1TI2jGgajCEpLE2E8jGaKjzBLOsiHS6kW3qMeaZQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730218692; a=rsa-sha256; cv=none; b=D6vWpBi8StL/KrOPsR7N6pOazecmt03VY27zngVyum5qu9pzlGCzIRCHotypAuJPrUzvI6 TFOaP0V9iBx1jS1dWDmMLElIpVYlezc26cv6UYWUPPqOd78yW4ioNSMStKvj2O0sjDcMB1 cXFUkTe2nOHvzZ+Ett1BbcOq5U5De5QfoBFkVWHNejVNiU2btDXJG9y6+LtRVXcSo+XPg8 X0Ifxz3/APlZHYxWIRGvh5VZnaW54so3Rs/3vi2Oc4lQY164xCZTh1T54JjLlc9qfrp4aF eFOmJtH+VwFl6zTWdlJwRPJOSA00XgbyV2UmpsUUa8o9KR1zwEMxRx5k1ga+Tg== 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 4XdFmN6BrqzW77; Tue, 29 Oct 2024 16:18:12 +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 49TGIC8W040728; Tue, 29 Oct 2024 16:18:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49TGICCZ040725; Tue, 29 Oct 2024 16:18:12 GMT (envelope-from git) Date: Tue, 29 Oct 2024 16:18:12 GMT Message-Id: <202410291618.49TGICCZ040725@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: 14457cf7d6fe - main - snd_hdsp(4): Add sysctls to select analog signal levels. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: 14457cf7d6fe2b2a7e23c349f6bfb41a09eec993 Auto-Submitted: auto-generated The branch main has been updated by br: URL: https://cgit.FreeBSD.org/src/commit/?id=14457cf7d6fe2b2a7e23c349f6bfb41a09eec993 commit 14457cf7d6fe2b2a7e23c349f6bfb41a09eec993 Author: Florian Walpen AuthorDate: 2024-10-29 16:12:29 +0000 Commit: Ruslan Bukin CommitDate: 2024-10-29 16:15:58 +0000 snd_hdsp(4): Add sysctls to select analog signal levels. RME HDSP 9632 sound cards support different sensitivity levels at the analog input, and different gain levels for the analog line and phones outputs. Expose these settings as sysctl tunables. Tested on hardware: - Phones output volume changes according to sysctl setting (caution, still extremely loud). - Create loop to feedback the line output to line input. - Iterate through input signal levels and observe volume changes in recorded audio. - Iterate through output signal levels and observe volume changes in recorded audio. Reviewed by: br, christos Differential Revision: https://reviews.freebsd.org/D47330 --- share/man/man4/snd_hdsp.4 | 24 ++++- sys/dev/sound/pci/hdsp.c | 220 ++++++++++++++++++++++++++++++++++++++++++++++ sys/dev/sound/pci/hdsp.h | 56 +++++++----- 3 files changed, 275 insertions(+), 25 deletions(-) diff --git a/share/man/man4/snd_hdsp.4 b/share/man/man4/snd_hdsp.4 index d6661c80b2ea..ca24bcf22cd0 100644 --- a/share/man/man4/snd_hdsp.4 +++ b/share/man/man4/snd_hdsp.4 @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd September 28, 2024 +.Dd October 28, 2024 .Dt SND_HDSP 4 .Os .Sh NAME @@ -134,6 +134,28 @@ for accurately synchronized signals (required for recording digital audio). .El .Pp +The following tunables are applicable to HDSP 9632 devices only: +.Bl -tag -width indent +.It Va dev.hdsp.0.input_level +Select the sensitivity of the analog line input. +Available reference levels for the input signal are +.Ql LowGain , +.Ql +4dBu +and +.Ql -10dBV . +.It Va dev.hdsp.0.output_level +Select the gain level of the analog line output. +Available reference levels for the output signal are +.Ql HighGain , +.Ql +4dBu +and +.Ql -10dBV . +.It Va dev.hdsp.0.phones_level +Adjust the gain level of the phones output, separately from the analog line +output. +The signal can be lowered by 6 or 12 dB. +.El +.Pp Where appropriate these sysctl values are modeled after official RME software on other platforms, and adopt their terminology. Consult the RME user manuals for additional information. diff --git a/sys/dev/sound/pci/hdsp.c b/sys/dev/sound/pci/hdsp.c index cf251a5636a1..03e885df63aa 100644 --- a/sys/dev/sound/pci/hdsp.c +++ b/sys/dev/sound/pci/hdsp.c @@ -231,6 +231,198 @@ hdsp_map_dmabuf(struct sc_info *sc) hdsp_write_4(sc, HDSP_PAGE_ADDR_BUF_IN, raddr); } +static const char * +hdsp_control_input_level(uint32_t control) +{ + switch (control & HDSP_INPUT_LEVEL_MASK) { + case HDSP_INPUT_LEVEL_LOWGAIN: + return ("LowGain"); + case HDSP_INPUT_LEVEL_PLUS4DBU: + return ("+4dBu"); + case HDSP_INPUT_LEVEL_MINUS10DBV: + return ("-10dBV"); + default: + return (NULL); + } +} + +static int +hdsp_sysctl_input_level(SYSCTL_HANDLER_ARGS) +{ + struct sc_info *sc; + const char *label; + char buf[16] = "invalid"; + int error; + uint32_t control; + + sc = oidp->oid_arg1; + + /* Only available on HDSP 9632. */ + if (sc->type != HDSP_9632) + return (ENXIO); + + /* Extract current input level from control register. */ + control = sc->ctrl_register & HDSP_INPUT_LEVEL_MASK; + label = hdsp_control_input_level(control); + if (label != NULL) + strlcpy(buf, label, sizeof(buf)); + + /* Process sysctl string request. */ + error = sysctl_handle_string(oidp, buf, sizeof(buf), req); + if (error != 0 || req->newptr == NULL) + return (error); + + /* Find input level matching the sysctl string. */ + label = hdsp_control_input_level(HDSP_INPUT_LEVEL_LOWGAIN); + if (strncasecmp(buf, label, sizeof(buf)) == 0) + control = HDSP_INPUT_LEVEL_LOWGAIN; + label = hdsp_control_input_level(HDSP_INPUT_LEVEL_PLUS4DBU); + if (strncasecmp(buf, label, sizeof(buf)) == 0) + control = HDSP_INPUT_LEVEL_PLUS4DBU; + label = hdsp_control_input_level(HDSP_INPUT_LEVEL_MINUS10DBV); + if (strncasecmp(buf, label, sizeof(buf)) == 0) + control = HDSP_INPUT_LEVEL_MINUS10DBV; + + /* Set input level in control register. */ + control &= HDSP_INPUT_LEVEL_MASK; + if (control != (sc->ctrl_register & HDSP_INPUT_LEVEL_MASK)) { + snd_mtxlock(sc->lock); + sc->ctrl_register &= ~HDSP_INPUT_LEVEL_MASK; + sc->ctrl_register |= control; + hdsp_write_4(sc, HDSP_CONTROL_REG, sc->ctrl_register); + snd_mtxunlock(sc->lock); + } + return (0); +} + +static const char * +hdsp_control_output_level(uint32_t control) +{ + switch (control & HDSP_OUTPUT_LEVEL_MASK) { + case HDSP_OUTPUT_LEVEL_MINUS10DBV: + return ("-10dBV"); + case HDSP_OUTPUT_LEVEL_PLUS4DBU: + return ("+4dBu"); + case HDSP_OUTPUT_LEVEL_HIGHGAIN: + return ("HighGain"); + default: + return (NULL); + } +} + +static int +hdsp_sysctl_output_level(SYSCTL_HANDLER_ARGS) +{ + struct sc_info *sc; + const char *label; + char buf[16] = "invalid"; + int error; + uint32_t control; + + sc = oidp->oid_arg1; + + /* Only available on HDSP 9632. */ + if (sc->type != HDSP_9632) + return (ENXIO); + + /* Extract current output level from control register. */ + control = sc->ctrl_register & HDSP_OUTPUT_LEVEL_MASK; + label = hdsp_control_output_level(control); + if (label != NULL) + strlcpy(buf, label, sizeof(buf)); + + /* Process sysctl string request. */ + error = sysctl_handle_string(oidp, buf, sizeof(buf), req); + if (error != 0 || req->newptr == NULL) + return (error); + + /* Find output level matching the sysctl string. */ + label = hdsp_control_output_level(HDSP_OUTPUT_LEVEL_MINUS10DBV); + if (strncasecmp(buf, label, sizeof(buf)) == 0) + control = HDSP_OUTPUT_LEVEL_MINUS10DBV; + label = hdsp_control_output_level(HDSP_OUTPUT_LEVEL_PLUS4DBU); + if (strncasecmp(buf, label, sizeof(buf)) == 0) + control = HDSP_OUTPUT_LEVEL_PLUS4DBU; + label = hdsp_control_output_level(HDSP_OUTPUT_LEVEL_HIGHGAIN); + if (strncasecmp(buf, label, sizeof(buf)) == 0) + control = HDSP_OUTPUT_LEVEL_HIGHGAIN; + + /* Set output level in control register. */ + control &= HDSP_OUTPUT_LEVEL_MASK; + if (control != (sc->ctrl_register & HDSP_OUTPUT_LEVEL_MASK)) { + snd_mtxlock(sc->lock); + sc->ctrl_register &= ~HDSP_OUTPUT_LEVEL_MASK; + sc->ctrl_register |= control; + hdsp_write_4(sc, HDSP_CONTROL_REG, sc->ctrl_register); + snd_mtxunlock(sc->lock); + } + return (0); +} + +static const char * +hdsp_control_phones_level(uint32_t control) +{ + switch (control & HDSP_PHONES_LEVEL_MASK) { + case HDSP_PHONES_LEVEL_MINUS12DB: + return ("-12dB"); + case HDSP_PHONES_LEVEL_MINUS6DB: + return ("-6dB"); + case HDSP_PHONES_LEVEL_0DB: + return ("0dB"); + default: + return (NULL); + } +} + +static int +hdsp_sysctl_phones_level(SYSCTL_HANDLER_ARGS) +{ + struct sc_info *sc; + const char *label; + char buf[16] = "invalid"; + int error; + uint32_t control; + + sc = oidp->oid_arg1; + + /* Only available on HDSP 9632. */ + if (sc->type != HDSP_9632) + return (ENXIO); + + /* Extract current phones level from control register. */ + control = sc->ctrl_register & HDSP_PHONES_LEVEL_MASK; + label = hdsp_control_phones_level(control); + if (label != NULL) + strlcpy(buf, label, sizeof(buf)); + + /* Process sysctl string request. */ + error = sysctl_handle_string(oidp, buf, sizeof(buf), req); + if (error != 0 || req->newptr == NULL) + return (error); + + /* Find phones level matching the sysctl string. */ + label = hdsp_control_phones_level(HDSP_PHONES_LEVEL_MINUS12DB); + if (strncasecmp(buf, label, sizeof(buf)) == 0) + control = HDSP_PHONES_LEVEL_MINUS12DB; + label = hdsp_control_phones_level(HDSP_PHONES_LEVEL_MINUS6DB); + if (strncasecmp(buf, label, sizeof(buf)) == 0) + control = HDSP_PHONES_LEVEL_MINUS6DB; + label = hdsp_control_phones_level(HDSP_PHONES_LEVEL_0DB); + if (strncasecmp(buf, label, sizeof(buf)) == 0) + control = HDSP_PHONES_LEVEL_0DB; + + /* Set phones level in control register. */ + control &= HDSP_PHONES_LEVEL_MASK; + if (control != (sc->ctrl_register & HDSP_PHONES_LEVEL_MASK)) { + snd_mtxlock(sc->lock); + sc->ctrl_register &= ~HDSP_PHONES_LEVEL_MASK; + sc->ctrl_register |= control; + hdsp_write_4(sc, HDSP_CONTROL_REG, sc->ctrl_register); + snd_mtxunlock(sc->lock); + } + return (0); +} + static int hdsp_sysctl_sample_rate(SYSCTL_HANDLER_ARGS) { @@ -606,6 +798,14 @@ hdsp_init(struct sc_info *sc) sc->ctrl_register &= ~HDSP_CONTROL_LINE_OUT; sc->ctrl_register |= HDSP_CONTROL_LINE_OUT; + /* Default gain levels. */ + sc->ctrl_register &= ~HDSP_INPUT_LEVEL_MASK; + sc->ctrl_register |= HDSP_INPUT_LEVEL_LOWGAIN; + sc->ctrl_register &= ~HDSP_OUTPUT_LEVEL_MASK; + sc->ctrl_register |= HDSP_OUTPUT_LEVEL_MINUS10DBV; + sc->ctrl_register &= ~HDSP_PHONES_LEVEL_MASK; + sc->ctrl_register |= HDSP_PHONES_LEVEL_MINUS12DB; + hdsp_write_4(sc, HDSP_CONTROL_REG, sc->ctrl_register); if (sc->type == HDSP_9652) @@ -732,6 +932,26 @@ hdsp_attach(device_t dev) sc, 0, hdsp_sysctl_sample_rate, "A", "Force sample rate (32000, 44100, 48000, ... 192000)"); + if (sc->type == HDSP_9632) { + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, + "phones_level", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, + sc, 0, hdsp_sysctl_phones_level, "A", + "Phones output level ('0dB', '-6dB', '-12dB')"); + + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, + "output_level", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, + sc, 0, hdsp_sysctl_output_level, "A", + "Analog output level ('HighGain', '+4dBU', '-10dBV')"); + + SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), + SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, + "input_level", CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE, + sc, 0, hdsp_sysctl_input_level, "A", + "Analog input level ('LowGain', '+4dBU', '-10dBV')"); + } + return (bus_generic_attach(dev)); } diff --git a/sys/dev/sound/pci/hdsp.h b/sys/dev/sound/pci/hdsp.h index 981188ad8aff..8ac438cd79f9 100644 --- a/sys/dev/sound/pci/hdsp.h +++ b/sys/dev/sound/pci/hdsp.h @@ -80,39 +80,47 @@ #define HDSP_LAT_BYTES_MIN (32 * 4) #define hdsp_encode_latency(x) (((x)<<1) & HDSP_LAT_MASK) -/* Gain */ -#define HDSP_ADGain0 (1 << 25) -#define HDSP_ADGain1 (1 << 26) -#define HDSP_DAGain0 (1 << 27) -#define HDSP_DAGain1 (1 << 28) -#define HDSP_PhoneGain0 (1 << 29) -#define HDSP_PhoneGain1 (1 << 30) - -#define HDSP_ADGainMask (HDSP_ADGain0 | HDSP_ADGain1) -#define HDSP_ADGainMinus10dBV (HDSP_ADGainMask) -#define HDSP_ADGainPlus4dBu (HDSP_ADGain0) -#define HDSP_ADGainLowGain 0 - -#define HDSP_DAGainMask (HDSP_DAGain0 | HDSP_DAGain1) -#define HDSP_DAGainHighGain (HDSP_DAGainMask) -#define HDSP_DAGainPlus4dBu (HDSP_DAGain0) -#define HDSP_DAGainMinus10dBV 0 - -#define HDSP_PhoneGainMask (HDSP_PhoneGain0|HDSP_PhoneGain1) -#define HDSP_PhoneGain0dB HDSP_PhoneGainMask -#define HDSP_PhoneGainMinus6dB (HDSP_PhoneGain0) -#define HDSP_PhoneGainMinus12dB 0 - -/* Settings */ +/* Register addresses */ #define HDSP_RESET_POINTER 0 #define HDSP_CONTROL_REG 64 #define HDSP_CONTROL2_REG 256 #define HDSP_STATUS_REG 0 #define HDSP_STATUS2_REG 192 +/* Control register flags */ #define HDSP_ENABLE (1 << 0) #define HDSP_CONTROL_SPDIF_COAX (1 << 14) #define HDSP_CONTROL_LINE_OUT (1 << 24) +#define HDSP_CONTROL_INPUT_GAIN0 (1 << 25) +#define HDSP_CONTROL_INPUT_GAIN1 (1 << 26) +#define HDSP_CONTROL_OUTPUT_GAIN0 (1 << 27) +#define HDSP_CONTROL_OUTPUT_GAIN1 (1 << 28) +#define HDSP_CONTROL_PHONES_GAIN0 (1 << 29) +#define HDSP_CONTROL_PHONES_GAIN1 (1 << 30) + +/* Analog input gain level */ +#define HDSP_INPUT_LEVEL_MASK (HDSP_CONTROL_INPUT_GAIN0 | \ + HDSP_CONTROL_INPUT_GAIN1) +#define HDSP_INPUT_LEVEL_LOWGAIN 0 +#define HDSP_INPUT_LEVEL_PLUS4DBU (HDSP_CONTROL_INPUT_GAIN0) +#define HDSP_INPUT_LEVEL_MINUS10DBV (HDSP_CONTROL_INPUT_GAIN0 | \ + HDSP_CONTROL_INPUT_GAIN1) + +/* Analog output gain level */ +#define HDSP_OUTPUT_LEVEL_MASK (HDSP_CONTROL_OUTPUT_GAIN0 | \ + HDSP_CONTROL_OUTPUT_GAIN1) +#define HDSP_OUTPUT_LEVEL_MINUS10DBV 0 +#define HDSP_OUTPUT_LEVEL_PLUS4DBU (HDSP_CONTROL_OUTPUT_GAIN0) +#define HDSP_OUTPUT_LEVEL_HIGHGAIN (HDSP_CONTROL_OUTPUT_GAIN0 | \ + HDSP_CONTROL_OUTPUT_GAIN1) + +/* Phones output gain level */ +#define HDSP_PHONES_LEVEL_MASK (HDSP_CONTROL_PHONES_GAIN0 | \ + HDSP_CONTROL_PHONES_GAIN1) +#define HDSP_PHONES_LEVEL_MINUS12DB 0 +#define HDSP_PHONES_LEVEL_MINUS6DB (HDSP_CONTROL_PHONES_GAIN0) +#define HDSP_PHONES_LEVEL_0DB (HDSP_CONTROL_PHONES_GAIN0 | \ + HDSP_CONTROL_PHONES_GAIN1) /* Interrupts */ #define HDSP_AUDIO_IRQ_PENDING (1 << 0)