[RFC PATCH 2/5] ALSA: quantum: track the device sample rate correctly
From: Miles Ramage
Date: Tue Dec 01 2026 - 23:23:42 EST
The driver assumes the device starts at 48 kHz, but the device keeps
its rate across driver loads. If it was left at another rate,
quantum_set_sample_rate(chip, 48000) returns early and the device
streams at the wrong rate. Read the clock source and sample rate during
probe, and cache the rate as unknown (zero) if that fails, so the next
hw_params sets it.
The clock-status event (channel 0x32, code 0x33) carries the sample
rate as a wire value, not in Hz. The device sends it after every rate
change, for example "source=0 rate=4" after switching to 96 kHz, and
the driver cached 4 as the rate. Decode it.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Miles Ramage <miles.ramage@xxxxxxxxx>
---
sound/pci/quantum/quantum_main.c | 25 ++++++++++++++++++++++++-
sound/pci/quantum/quantum_tci.c | 3 ++-
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/sound/pci/quantum/quantum_main.c b/sound/pci/quantum/quantum_main.c
index 16c81cc..c7c73e8 100644
--- a/sound/pci/quantum/quantum_main.c
+++ b/sound/pci/quantum/quantum_main.c
@@ -113,7 +113,7 @@ static void quantum_device_init(struct quantum_chip *chip)
dev_dbg(&chip->pci->dev, "DFU payload size: 0x%08x\n",
dfu_payload_size);
- chip->sample_rate = 48000;
+ chip->sample_rate = 0; /* unknown until read from the device */
chip->clock_source = CLK_SOURCE_INTERNAL;
chip->powered_on = true;
}
@@ -552,6 +552,28 @@ void quantum_power_state_changed(struct quantum_chip *chip, bool powered_on)
}
}
+/*
+ * The device keeps its clock source and sample rate across driver loads, so
+ * read them rather than assuming the 48 kHz power-on default. Failure is not
+ * fatal: an unknown rate (zero) makes the next hw_params set it explicitly.
+ */
+static void quantum_read_initial_rate(struct quantum_chip *chip)
+{
+ unsigned int source, device_rate, clock_rate;
+
+ if (!quantum_get_clock_source(chip, &source) &&
+ !quantum_get_sample_rate(chip, &device_rate, &clock_rate)) {
+ chip->sample_rate = device_rate;
+ dev_dbg(&chip->pci->dev,
+ "initial rate %u Hz (clock %u Hz), source %u\n",
+ device_rate, clock_rate, source);
+ } else {
+ chip->sample_rate = 0;
+ dev_warn(&chip->pci->dev,
+ "could not read the initial sample rate\n");
+ }
+}
+
/* Device creation */
static int snd_quantum_create(struct snd_card *card, struct pci_dev *pci,
@@ -664,6 +686,7 @@ static int snd_quantum_create(struct snd_card *card, struct pci_dev *pci,
if (!ret) {
chip->tci_ready = true;
chip->tci_initialized = true;
+ quantum_read_initial_rate(chip);
err = snd_quantum_pcm_new(chip);
if (err) {
dev_err(&pci->dev, "PCM creation failed: %d\n", err);
diff --git a/sound/pci/quantum/quantum_tci.c b/sound/pci/quantum/quantum_tci.c
index 80dde86..ee7d6e7 100644
--- a/sound/pci/quantum/quantum_tci.c
+++ b/sound/pci/quantum/quantum_tci.c
@@ -173,7 +173,8 @@ void quantum_process_rx_messages(struct quantum_chip *chip)
"clock event: source=%u rate=%u\n",
wire_cs - 1, sr);
chip->clock_source = wire_cs - 1;
- chip->sample_rate = sr;
+ /* The rate is a wire value, not Hz. */
+ chip->sample_rate = quantum_wire_to_rate(sr);
}
break;
--
2.56.1