From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.6.128.84 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796185417; b=e/4EkJWu3p56yDMY7iiVV7q9doWI6aYCn2mIJ5nlgQsdbQ063/xmeZf4ixTNLunlc8c3 2lkkRfvsinoK6l9xZnht5xCmF4Q6fG9okoWLKXVNhnVZPKBrP0yeLCnE4e+aZV4GVtSu8 oNGRSxe8V/ewupEEPUFdWgIBKRegPKrVaTb3346Ad4KorPjLZoNZzmdTFfO1Y3cDd5MAC vtJPUPDEr0iY+ZrYbSltfhZDqMUKaOYOFgU0ezSFqac+iZv28G9iCMEKKtbpO8gGgw4pV S+hibBYgloBkZiZytP6IyYNKWJSYiK276hg79s/IorRKIpCeS3XjlvsfdXIE43qx6Xg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796185417; 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=lqCjEZQhyI7+AJ/9cjizSnJ7ld8sjizK6oZDutl5kow=; b=AgvrV/WzvheWfLSE6cnJb0ZzjLu32maD8nIEFwe1XBspY9TSLkX2tkii+RtUKIf62dKW ZuNpTCx0mA8dkjH8EbIqZ8rncoK7DKSl4XvJl+tSmoIkXscgJqPsjwEC+YE63Jps0nGhX hJSslYUqXXt+Qev5c+ElxZVWbv0O+pCYJqQUshrN9Ok7kUhz8qH6qj3mcNJro06NM4gzA jHcn5W06al21XgbHRGXsq7CPBIVAKbJDMKpH7FIrl2WfJBIOPfG5DYqYweFVNxT5fejww wWYYcWujvmvbkMzhlWOM2YkPRPrl+QL2mpEDImg0+bj9xGj0/pjZjMCXXPLTp4W5exw== 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=OYmCWNbq; arc=none smtp.remote-ip=74.6.128.84 Received: from sonic312-22.consmr.mail.bf2.yahoo.com (sonic312-22.consmr.mail.bf2.yahoo.com [74.6.128.84]) (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 B8C83606A33A for ; Wed, 2 Dec 2026 04:23:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B8C83606A33A 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=OYmCWNbq DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1796185414; bh=lqCjEZQhyI7+AJ/9cjizSnJ7ld8sjizK6oZDutl5kow=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To:Content-Type; b=OYmCWNbqnz761YSPYzthZDYn9lykMV84fGsfO6GpKBO0F/MUERfHaGn0Tb7BcC+TuLDF3//7FU0AnnyFd8LWLo1r5CCWfocDEppYBmRmZCE83Rg4aLexz5Bf3GFosGXvgIMyLtp4CTRWE0veVso0exHbLcZEGkLW0Pb/PYvJ7y4ARY+gL6mJp0qONithh2KidIfwGd8tBQ4j67pHDWPz+XQPX/0n0p/9CVyPZDQmiy2WxN6NbVPhxNQsj05IrV6kyYY1mlin5Gp+q7m0z7jNBjtYyRHC4Oxry7B6s9sBvIHEFDl8sU2Rshagu++BMJTKJcWbBfwODn69W3uhGMrZsw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1796185414; bh=rHly5luA/bUTSKnWFN3NerEPdxsC3ZktUYViI6xccrI=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=mSPzqEC9fpwhnTBDtX26HkwbP5hwcOeeWO2MS4ykupCHQnmZTdV/l3yuHB9M5azGqH211jLhXdWQhTqoWNLIMhN/cllD3yDK/jXY5Xi3Ggt0Co8wYCuoYgLpUJujqCSZo8JjAxgZ38CT98RNZtt/Ev95SDUoQcGQwjfb4rx+8Ssi2KWf7zK5oKB0q3PYX4MVj1HWXhP0HBdeYHfmRJlTOWrqUarlay7WmAh7H6InGFOpIOFyIMy1LdSYSwS89Q/gP0bVnr8LC84jpNtVkxkLiWyvMzTQnVHhzukl4Y2YnSzWNqyeO/RnHNOxHOnhvNpH0IUZTXlo+cwhdttuYQZc7A== X-YMail-OSG: 7_fktJ4VM1nZkj6wxh7slWdla1E1g9q80ZZbHNFzytHRydgv0Co1CdFGxTiiDIM IUW_Sruv0qbnTuDk5lajxDpgauq15vxXbUzNm2PlrJy5.uxNF7fXMwJWM7advUOXPkGhMos_nxT2 MUFRSnuEQwgs1k8imEqDSETFPreKAEi9JkHRWC3M3I04Dbu5riCBdR2qUIMe3CgKcpD4Rz2dZTUd fUOg5wrQXHLwRAX_r8_SNHbMtbfg_4nk0rM_wVeG6icTHVW0evofc0BGZ6.2hRx15bGzuKGpenj0 6D2uY1ChfgqdWav0cILtzkQjRj_VL5XZcP5qT0oCriIZFTcuXqqWmk0TZ9.FQepH5libDOOX3MFB U1_CEkXCW4lG7CKQGvT8vouzi5yOMiUsVfHCZ9YH..wnJU0Vi807srPsHug1nHx0fQVuE.9ePG1_ kfFldcDbKPNi_ncYABycDCT.pZZ1eqpvJgCGmY8j2z1AEqm3yPdqyrXTgtn.xb750QD2XPMV7eys gp8nqkkI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hFa_l_Gmjp4kS4fUDJNa3vjcESgFR.f_b5kueKjlfVCrgDLZXILROqiQJ_Wg hkN_D2w3HG8JRorJHD.jJINgZ9OwUQixUFsY4pTFo0ZBleF9eURxb2COjVRIx0WaM1jCTuw_haNo fh8hJKtqGBbgziYLoWEGUi45WJqSokNokKZNllCTYtS.Xyzx4Jf_jGeEjBEgMyiCdmjdMM6rYcQa bn47jlYaBH_WX5b404MiZewSw_eskTm7C3.4G4KoBtFOcZONvH16qRdfZ9MFWP_0g5i7zE0bOuP7 IdO5Vu.9ADoMRvmdtg5piXO4AZJOC7vJUrJZEIZhyp60t8J5VaAQFxESfTJ_XtGvMuXswxXZqy.M rO5Vvc7ujgJTXgvmq8BnczZMKwKYsqWZfL_PP40H1Ei9JuqgNL2kEccSAR6ibZefP6AIZl1CfwCH DcHHDatwHSfJQP005flMv7aI23LY6_ydxfuLuEI9Lju.HVOK5__Ahurr3hnfzpuv64H4X.52UxUc Pyh5rQbtkBrWVV.rLZn74UMlAp.l_1w1dtFGshFfTWNiPoQ9mtYFe4M6nHkByUYHb5WgCDXCO6b6 NxyVp_OG6oVx59hO8kqsz72eJIKaUnOYcQvcRniaWQEXsVLvOeIBxcWnvlqR.wMylKdcrAqF_KAt J_zSAKT.Oz4cwgQ.5zo2e6UqO5L_OWKSE8V5JiUxckq2JgmIjrX7MNSSL_g2MxPEaFwHdjpW1wsk _JRHm9L5jg7bnT8E- X-Sonic-MF: X-Sonic-ID: 63d61826-3237-4992-8205-dd9a0adfe1dd Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.bf2.yahoo.com with HTTP; Wed, 2 Dec 2026 04:23:34 +0000 Received: by hermes--production-ne1-768f77cf86-d49lr (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID b4832c03f7603fc3738aaf23d9537159; Wed, 02 Dec 2026 04:23:30 +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 1/5] ALSA: quantum: send the sample-rate wire value when setting the rate Date: Tue, 1 Dec 2026 22:22:27 -0600 Message-ID: <20261202042231.42930-2-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 quantum_set_sample_rate() sends the rate in Hz as a single 32-bit word and expects a sample-rate reply. The device expects the clock source and the sample-rate wire value (1 = 44.1 kHz ... 6 = 192 kHz), two little-endian 32-bit words, and answers with a status word. A QEMU trace of the vendor Windows driver supports this: its set-rate request is 16 bytes long (an 8-byte payload), not 12, and is answered by a 12-byte status message about 210-250 ms later. Send the two-word request, check the status, and read the rate back with TCI_CTRL_GET_SAMPLE_RATE before caching it. Mark the cached rate unknown while a change is in progress, so that a failed change is retried rather than skipped on the next hw_params. 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 | 29 ++++++++++++ sound/pci/quantum/quantum_tci.c | 81 +++++++++++++++++++++++++++++++-- 2 files changed, 105 insertions(+), 5 deletions(-) diff --git a/sound/pci/quantum/quantum.h b/sound/pci/quantum/quantum.h index 822c1f4..2c995b6 100644 --- a/sound/pci/quantum/quantum.h +++ b/sound/pci/quantum/quantum.h @@ -105,6 +105,32 @@ enum quantum_clk_source { CLK_SOURCE_EXTERNAL_ADAT2 = 4, }; +/* + * TCI sample-rate wire values, used by TCI_CTRL_SET_SAMPLE_RATE requests and + * TCI_CTRL_RSP_SAMPLE_RATE replies. Zero means no valid rate. + */ +static inline u32 quantum_rate_to_wire(unsigned int rate) +{ + switch (rate) { + case 44100: return 1; + case 48000: return 2; + case 88200: return 3; + case 96000: return 4; + case 176400: return 5; + case 192000: return 6; + default: return 0; + } +} + +static inline unsigned int quantum_wire_to_rate(u32 wire) +{ + static const unsigned int rates[] = { + 0, 44100, 48000, 88200, 96000, 176400, 192000, + }; + + return wire < ARRAY_SIZE(rates) ? rates[wire] : 0; +} + struct tci_header { __le16 length; u8 channel; @@ -384,6 +410,9 @@ void quantum_midi_receive(struct quantum_chip *chip, const u8 *payload, size_t payload_len); void quantum_midi_tx_work_handler(struct work_struct *work); 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_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_tci.c b/sound/pci/quantum/quantum_tci.c index 59a697b..80dde86 100644 --- a/sound/pci/quantum/quantum_tci.c +++ b/sound/pci/quantum/quantum_tci.c @@ -398,30 +398,101 @@ int quantum_get_serial_number(struct quantum_chip *chip) return 0; } -/* Set the sample rate */ +/* Read the device and clock sample rates for the current clock source */ + +int quantum_get_sample_rate(struct quantum_chip *chip, + unsigned int *device_rate, + unsigned int *clock_rate) +{ + __le32 req = cpu_to_le32(chip->clock_source + 1); + __le32 reply[2] = { 0 }; + size_t len = sizeof(reply); + int ret; + + if (chip->tci_fatal_error) + return -EIO; + + ret = quantum_tci_send_wait(chip, TCI_CHAN_CTRL, + TCI_CTRL_GET_SAMPLE_RATE, + TCI_CTRL_RSP_SAMPLE_RATE, + &req, sizeof(req), reply, &len, 1000); + if (ret < 0) { + dev_err(&chip->pci->dev, "Get sample rate failed: %d\n", ret); + return ret; + } + if (len != sizeof(reply)) + return -EPROTO; + + *device_rate = quantum_wire_to_rate(le32_to_cpu(reply[0])); + *clock_rate = quantum_wire_to_rate(le32_to_cpu(reply[1])); + if (!*device_rate) + return -EPROTO; + + return 0; +} + +/* + * Set the sample rate. The request carries the clock-source and sample-rate + * wire values and is answered with a status word, zero on success. The + * device takes roughly 250 ms to answer. Read the rate back afterwards + * rather than trusting the status alone. + */ int quantum_set_sample_rate(struct quantum_chip *chip, unsigned int rate) { - __le32 val = cpu_to_le32(rate); + struct { + __le32 clock_source; + __le32 rate; + } __packed req; + __le32 status = cpu_to_le32(U32_MAX); + size_t len = sizeof(status); + unsigned int device_rate, clock_rate; + u32 wire = quantum_rate_to_wire(rate); int ret; if (chip->tci_fatal_error) return -EIO; + if (!wire) + return -EINVAL; + if (chip->sample_rate == rate) return 0; + req.clock_source = cpu_to_le32(chip->clock_source + 1); + req.rate = cpu_to_le32(wire); + + /* From here on the device rate is unknown until it is read back. */ + chip->sample_rate = 0; + ret = quantum_tci_send_wait(chip, TCI_CHAN_CTRL, TCI_CTRL_SET_SAMPLE_RATE, - TCI_CTRL_RSP_SAMPLE_RATE, - &val, sizeof(val), NULL, NULL, 1000); + TCI_RSP_STATUS, + &req, sizeof(req), &status, &len, 1000); if (ret < 0) { dev_err(&chip->pci->dev, "Set sample rate failed: %d\n", ret); return ret; } + if (len != sizeof(status) || le32_to_cpu(status)) { + dev_err(&chip->pci->dev, + "Set sample rate to %u Hz rejected: status 0x%08x\n", + rate, le32_to_cpu(status)); + return -EIO; + } + + ret = quantum_get_sample_rate(chip, &device_rate, &clock_rate); + if (ret < 0) + return ret; + if (device_rate != rate) { + dev_err(&chip->pci->dev, + "Sample rate read back as %u Hz, expected %u Hz\n", + device_rate, rate); + return -EIO; + } chip->sample_rate = rate; - dev_dbg(&chip->pci->dev, "sample rate set to %u Hz\n", rate); + dev_dbg(&chip->pci->dev, "sample rate set to %u Hz (clock %u Hz)\n", + rate, clock_rate); return 0; } -- 2.56.1