From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.6.134.125 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796185422; b=T1m4LA74bOFPuv5nufkfjuP8VaGxM5WQeiSYvpvMTkrmvTL0BP07Mmf1Ps01HxL6Gfsg aOwjQl0a7NVaev9ZqrgHRCsqMX+C3MEr6Vl/rkBC8wBxQ4fLNJZO0ndtZQoyRKZvWaUlO Wzuit3ovs6EKDruH0HInS770bjJAbL/1MhHCnGLxguA6jUOUusdfBcq+5I7EG8iNq3W9A mehWnAB+01RwOE+7DUEgwbxpt30/HNngmXA5UHjJUv0uHsF3/OE+fMkmvRZnsAhdPkga/ rISM7xwFJ2rZzdHQ9hybnyoW6tgL57DKMVPJ3DoJ7RZ1echAoQPBgfN7kMwsPg9Td/Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796185422; h=DMARC-Filter:DKIM-Signature:X-SONIC-DKIM-SIGN:X-YMail-OSG:X-Sonic-MF: X-Sonic-ID:Received:Received:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=kA7FInJrNjUdzVu31gN9sZL8N0hbGXXVngs0CqAAcU8=; b=1HV3cXpRTdTt1H0OX08gBZzT8e4VW/oeK5P8uvzBKThpC+vOS4/XY9R8ZDwUfH6t2j7z 10YfItAr8V8cARalEBp1I56ZT40FQclfWiChbjE+/FZxAq6FxGXlS1byp4y4BYTwxSBR3 8LI3RGCTEdmoUSiwV0x8MvZylGNePJjWs4xfCqaCXjpEKwRlk6aEI7bHOWpE1FaXlaYcE yLw3jfjzwuniNAcV8WvNHmttEbdNxtTe7Ypumay5IbbYZah692OPF12wZeaRc6RzJYRLO Hxkwogs4A4QDR26bZ1hdjaKBBvBS7WwO6yhvroK+2OWpzwSvxECJs+mUOR603/xYTHQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=yahoo.com; spf=pass smtp.mailfrom=yahoo.com; dkim=pass header.d=yahoo.com header.i=@yahoo.com header.a=rsa-sha256 header.s=s2048 header.b=C9dnitSg; arc=none smtp.remote-ip=74.6.134.125 Received: from sonic315-15.consmr.mail.bf2.yahoo.com (sonic315-15.consmr.mail.bf2.yahoo.com [74.6.134.125]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99D54606A330 for ; Wed, 2 Dec 2026 04:23:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 99D54606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=yahoo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yahoo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yahoo.com header.i=@yahoo.com header.a=rsa-sha256 header.s=s2048 header.b=C9dnitSg DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1796185420; bh=kA7FInJrNjUdzVu31gN9sZL8N0hbGXXVngs0CqAAcU8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To:Content-Type; b=C9dnitSgT40GdD4zCH7l7RDJWaeMIFA4W68pjIqCFd59D01N/JBlK8iZB/QORxx4ZabfBLqVxsqfvf06W870B7vueLMXa1T2gjiHdVFZC0+SbqSHfCOPn3hPVX5eMOiLXEEuF2hqo2Jt9nplDbDmP9osV6ESa2R/gebqtlNDxCiY3cVrcne5UrWikyuzUDmR7ukPSrx8qW1aicVjAubVfM/UEUDfGdKXfDQy3u8Z0U4SYJtK7YhiO+3JRAfmdOTXLzLGOqluli88JbvZSXTHvOeqZuoOTT5EhiydQCt7brdM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WS2r4jTYVe8AwtQBT4ZGT4a6MTkxkkMyyBDnZ6_0JQkpfEjAZrSIp O5X1g.aVuD4mUxTE23Pk7e1sSSZWUNdrdG79GdtPpxfSf4oKn1wtaTqVPpmoV.yLdjpOaIOID4GZ 09zeRyisP4434uXsDVb5vH0fbxVmiiwzOnuNPX_r3rmbABKkBuJdT0e59r3EpRbpbqTm0PVFsMz5 wMF_ljS6q0dhC2TP7jn9i8rwSpNMTIedY9MFdNXhBK6qAWEi8w9MYIKYxwyxMZt2Z34PLNP3IlFF CiMloPt6xgm13DMGXCTEElRlsdVZ94TSN3O606f6sLZKl2wF9SVYMTa3JIS.yarLrLRhx.PW8_a4 IxmEdJ6e7GlBLvwb53hGPu8.HQw5kvgLUcyHMbj7kabhANw9ip5MjbKgr0TizzmIPCJzsKdBl5E3 9gYXndV9xGdpRHRaB3YezUn2MgmvThx45gzYfIyfEaeuSV3z2qyyeHAjUN6UZXCZjGhK02dwEiT6 hMlnnBem5R.HvN5CabAcNyVDSHiyNn5GpLCz9oYzEpyfEPqIZg9wiMMelg5KOTH5RPI_p.2DGU5i gjyk3mctIrrrtfiul3ecvB5aGFP04840vD5U2V1ZNLJ2V1jcdeTYPQXV.IN68sWPM13D_p28vYrF 5znb3qxBhoNGLLoIJKwE_Uj2Uk_ZtSn30rh.XHq7t1Q9yP1gM3wSV.auJaMKGrtUbFGSNcOmV.0E U569VMadEvKtv5G0chvZiqw-- X-Sonic-MF: X-Sonic-ID: 8e15e813-d7d3-470a-bf68-522c134d70c9 Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.bf2.yahoo.com with HTTP; Wed, 2 Dec 2026 04:23:40 +0000 Received: by hermes--production-ne1-768f77cf86-d49lr (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID b4832c03f7603fc3738aaf23d9537159; Wed, 02 Dec 2026 04:23:35 +0000 (UTC) From: Miles Ramage To: Nicholas Johnson , Jaroslav Kysela , Takashi Iwai Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, Jamie Steele , Miles Ramage Subject: [RFC PATCH 3/5] ALSA: quantum: tie the channel count to the sample rate Date: Tue, 1 Dec 2026 22:22:29 -0600 Message-ID: <20261202042231.42930-4-miles.ramage@yahoo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202042231.42930-1-miles.ramage@yahoo.com> References: <59ad0f62-dd4c-4d42-b50a-ab91bf469fb7@gmail.com> <20261202042231.42930-1-miles.ramage@yahoo.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The device narrows its frame above 48 kHz. QUANTUM_REG_CHANNEL_COUNTS reads 0x1a1a at 44.1/48 kHz, and a QEMU trace of the vendor Windows driver shows 0x1212 at 96 kHz and 0x0808 at 192 kHz: 26, 18 and 8 channels per direction. The vendor driver streamed at those widths. quantum_pcm_open() accepts only 26 channels and fails with -EIO when the device reports anything else, so the higher bands cannot be used, and a device left at 96 kHz cannot be opened at all. Advertise 8 to 26 channels and add hw rules that tie channels and rate together. Reject a mismatched pair in hw_params, and wait for the channel-count register to match the new band after a rate change before the DMA buffers are sized from it. Link: https://github.com/jamie-steele/presonus-quantum-linux/pull/54 Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Miles Ramage --- sound/pci/quantum/quantum.h | 19 +++++++ sound/pci/quantum/quantum_pcm.c | 95 ++++++++++++++++++++++++--------- sound/pci/quantum/quantum_tci.c | 29 ++++++++++ 3 files changed, 117 insertions(+), 26 deletions(-) diff --git a/sound/pci/quantum/quantum.h b/sound/pci/quantum/quantum.h index 2c995b6..d2d1527 100644 --- a/sound/pci/quantum/quantum.h +++ b/sound/pci/quantum/quantum.h @@ -131,6 +131,24 @@ static inline unsigned int quantum_wire_to_rate(u32 wire) return wire < ARRAY_SIZE(rates) ? rates[wire] : 0; } +/* + * Channels per direction in each speed band, as reported by + * QUANTUM_REG_CHANNEL_COUNTS once the device runs at that rate. + */ +#define QUANTUM_CHANNELS_MIN 8 +#define QUANTUM_CHANNELS_MAX 26 + +static inline unsigned int quantum_rate_channels(unsigned int rate) +{ + if (!rate) + return 0; + if (rate > 96000) + return 8; + if (rate > 48000) + return 18; + return 26; +} + struct tci_header { __le16 length; u8 channel; @@ -413,6 +431,7 @@ int quantum_set_sample_rate(struct quantum_chip *chip, unsigned int rate); int quantum_get_sample_rate(struct quantum_chip *chip, unsigned int *device_rate, unsigned int *clock_rate); +int quantum_wait_channel_counts(struct quantum_chip *chip, unsigned int rate); int quantum_set_clock_source(struct quantum_chip *chip, unsigned int source); int quantum_get_clock_source(struct quantum_chip *chip, unsigned int *source); int quantum_get_serial_number(struct quantum_chip *chip); diff --git a/sound/pci/quantum/quantum_pcm.c b/sound/pci/quantum/quantum_pcm.c index 857d741..5575072 100644 --- a/sound/pci/quantum/quantum_pcm.c +++ b/sound/pci/quantum/quantum_pcm.c @@ -1,13 +1,8 @@ // SPDX-License-Identifier: GPL-2.0-only /* Copyright (C) 2026 Nicholas Johnson */ +#include #include "quantum.h" -static const unsigned int quantum_channel_counts[] = { 26 }; -static const struct snd_pcm_hw_constraint_list quantum_channel_list = { - .count = ARRAY_SIZE(quantum_channel_counts), - .list = quantum_channel_counts, -}; - static const unsigned int quantum_rates[] = { 44100, 48000, 88200, 96000, 176400, 192000, }; @@ -49,12 +44,55 @@ static int quantum_pcm_hw_rule_period_size(struct snd_pcm_hw_params *params, return snd_interval_list(p, count, list, 0); } +/* + * The frame width depends on the speed band: 26 channels per direction up + * to 48 kHz, 18 up to 96 kHz and 8 up to 192 kHz. Tie channels and rate + * together in both directions. + */ +static int quantum_pcm_hw_rule_channels(struct snd_pcm_hw_params *params, + struct snd_pcm_hw_rule *rule) +{ + struct snd_interval *c = hw_param_interval(params, + SNDRV_PCM_HW_PARAM_CHANNELS); + const struct snd_interval *r = hw_param_interval_c(params, + SNDRV_PCM_HW_PARAM_RATE); + unsigned int list[ARRAY_SIZE(quantum_rates)]; + unsigned int count = 0; + unsigned int i, ch; + + for (i = 0; i < ARRAY_SIZE(quantum_rates); i++) { + if (!snd_interval_test(r, quantum_rates[i])) + continue; + ch = quantum_rate_channels(quantum_rates[i]); + if (!count || list[count - 1] != ch) + list[count++] = ch; + } + + return snd_interval_list(c, count, list, 0); +} + +static int quantum_pcm_hw_rule_rate(struct snd_pcm_hw_params *params, + struct snd_pcm_hw_rule *rule) +{ + struct snd_interval *r = hw_param_interval(params, + SNDRV_PCM_HW_PARAM_RATE); + const struct snd_interval *c = hw_param_interval_c(params, + SNDRV_PCM_HW_PARAM_CHANNELS); + unsigned int list[ARRAY_SIZE(quantum_rates)]; + unsigned int count = 0; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(quantum_rates); i++) + if (snd_interval_test(c, quantum_rate_channels(quantum_rates[i]))) + list[count++] = quantum_rates[i]; + + return snd_interval_list(r, count, list, 0); +} + static int quantum_pcm_open(struct snd_pcm_substream *ss) { struct quantum_chip *chip = ss->pcm->private_data; struct snd_pcm_runtime *runtime = ss->runtime; - u32 channel_cfg; - u32 channels; int err; if (quantum_device_gone(chip)) @@ -66,17 +104,6 @@ static int quantum_pcm_open(struct snd_pcm_substream *ss) if (!chip->tci_ready) return -EAGAIN; - channel_cfg = quantum_read32(chip, QUANTUM_REG_CHANNEL_COUNTS); - channels = ss->stream == SNDRV_PCM_STREAM_PLAYBACK ? - ((channel_cfg >> 8) & 0xff) : - (channel_cfg & 0xff); - - if (!channels) - return -EIO; - - if (channels != 26) - return -EIO; - runtime->hw.info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_INTERLEAVED | @@ -90,21 +117,29 @@ static int quantum_pcm_open(struct snd_pcm_substream *ss) SNDRV_PCM_RATE_192000; runtime->hw.rate_min = 44100; runtime->hw.rate_max = 192000; - runtime->hw.channels_min = channels; - runtime->hw.channels_max = channels; - runtime->hw.period_bytes_min = 32 * channels * sizeof(s32); - runtime->hw.period_bytes_max = 512 * channels * sizeof(s32); + runtime->hw.channels_min = QUANTUM_CHANNELS_MIN; + runtime->hw.channels_max = QUANTUM_CHANNELS_MAX; + runtime->hw.period_bytes_min = 32 * QUANTUM_CHANNELS_MIN * sizeof(s32); + runtime->hw.period_bytes_max = 512 * QUANTUM_CHANNELS_MAX * sizeof(s32); runtime->hw.periods_min = 1; runtime->hw.periods_max = 1024; - runtime->hw.buffer_bytes_max = 65536 * channels * sizeof(s32); + runtime->hw.buffer_bytes_max = 65536 * QUANTUM_CHANNELS_MAX * + sizeof(s32); err = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &quantum_rate_list); if (err < 0) return err; - err = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, - &quantum_channel_list); + err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, + quantum_pcm_hw_rule_channels, NULL, + SNDRV_PCM_HW_PARAM_RATE, -1); + if (err < 0) + return err; + + err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, + quantum_pcm_hw_rule_rate, NULL, + SNDRV_PCM_HW_PARAM_CHANNELS, -1); if (err < 0) return err; @@ -149,6 +184,9 @@ static int quantum_pcm_hw_params(struct snd_pcm_substream *ss, if (!chip->tci_ready) return -EAGAIN; + if (params_channels(params) != quantum_rate_channels(rate)) + return -EINVAL; + pages = snd_pcm_lib_malloc_pages(ss, params_buffer_bytes(params)); if (pages < 0) return pages; @@ -186,6 +224,11 @@ static int quantum_pcm_hw_params(struct snd_pcm_substream *ss, goto out_free_pages; } + /* Also catches a cached rate that no longer matches the device. */ + err = quantum_wait_channel_counts(chip, rate); + if (err < 0) + goto out_free_pages; + err = quantum_allocate_dma_resources(chip, rate, params_period_size(params), params_buffer_size(params), diff --git a/sound/pci/quantum/quantum_tci.c b/sound/pci/quantum/quantum_tci.c index ee7d6e7..5f5a425 100644 --- a/sound/pci/quantum/quantum_tci.c +++ b/sound/pci/quantum/quantum_tci.c @@ -491,12 +491,41 @@ int quantum_set_sample_rate(struct quantum_chip *chip, unsigned int rate) return -EIO; } + ret = quantum_wait_channel_counts(chip, rate); + if (ret < 0) + return ret; + chip->sample_rate = rate; dev_dbg(&chip->pci->dev, "sample rate set to %u Hz (clock %u Hz)\n", rate, clock_rate); return 0; } +/* + * Wait for QUANTUM_REG_CHANNEL_COUNTS to report the channel count of the + * band containing @rate, in both directions. + */ +int quantum_wait_channel_counts(struct quantum_chip *chip, unsigned int rate) +{ + unsigned int want = quantum_rate_channels(rate); + u32 cfg; + int i; + + for (i = 0; i < 100; i++) { + cfg = quantum_read32(chip, QUANTUM_REG_CHANNEL_COUNTS); + if ((cfg & 0xff) == want && ((cfg >> 8) & 0xff) == want) + return 0; + if (quantum_device_gone(chip)) + return -ENODEV; + usleep_range(1000, 2000); + } + + dev_err(&chip->pci->dev, + "channel counts 0x%08x do not match %u channels at %u Hz\n", + cfg, want, rate); + return -EIO; +} + /* Set the clock source */ int quantum_set_clock_source(struct quantum_chip *chip, unsigned int source) -- 2.56.1