From patchwork Wed May 24 07:41:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Ciocaltea X-Patchwork-Id: 98355 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2669239vqo; Wed, 24 May 2023 00:55:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ47fYbgwv4txDydb8reXMf/FCDLJy3yxl8E3DkwUt6O+CODMjeYS7MdilhP2KC3HHzRcWCt X-Received: by 2002:a05:6a21:3299:b0:101:4348:3e4e with SMTP id yt25-20020a056a21329900b0010143483e4emr19349597pzb.42.1684914904962; Wed, 24 May 2023 00:55:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684914904; cv=none; d=google.com; s=arc-20160816; b=HM8NvP1pbzYLCmcWunPbF6sMplvEDLkqKDeNEF8jgbplf057As7VrF3UCwjcPn68Wr 0rTOvuettizFdlkVDV6ZxwjoBNbGRtf+M+b4E4p3KjAIxgly9ZRfZunHH96unid4Zjc/ D+PcvNBDnjR318PhqrxnR6lV0eqF4DLz8vSCa/3GaaMtvgoFtma3Ks53jgnZDTbSqHtm utjpbFrIZ27W1orhAo+40oRQq16D5pJ2rLSIrsaY2Ftq2Ag5Q56GhZOU2sww68iumBr3 iFY51sE2NI0ks0JIl4lTn5G1TA6R8Yq4BasCn40ENDwBwz+mOG4zUUPG012jsULWPYE5 edbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gwZmjt6lK4OQ7KURI4e5bgw009dfOTbRMAhV/sOexqY=; b=SR4MzD0zrbVYB7GYJL1CxlWNNbLViH0yxcpnq6/mRhpcn0r1sK4mjvgQAa42KMhO3Z p6GKYfUnK9uZuvWGhDyphCeBhYaTsVo+7IepyMrMdmaHyWpFl1Ig6wuCuuv+81m41Ndj gwvWUzCZxFYdn3pHMsULiJTprlJruSFwIi7e/FmYe/FA4RKF4mqAnb1z2RshXGfw/0t6 hM6Mv5Ls1eX4g0+jAVw+QHwMMG4IPnpAdguQLsHOgasdOki+r0Zylazndc4NMuebb/3X hRvWjDfJ23D8uFpxWSilCo/CdJpsO5PYpniZA+1M2PpTI47kgGy00ZllLk+IgSyS02Rl 0LTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=guHh2BSY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s7-20020a637707000000b00534951b1b85si765657pgc.279.2023.05.24.00.54.52; Wed, 24 May 2023 00:55:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=guHh2BSY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240041AbjEXHmO (ORCPT + 99 others); Wed, 24 May 2023 03:42:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240025AbjEXHmJ (ORCPT ); Wed, 24 May 2023 03:42:09 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D8529D; Wed, 24 May 2023 00:42:07 -0700 (PDT) Received: from localhost (unknown [188.27.34.213]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: cristicc) by madras.collabora.co.uk (Postfix) with ESMTPSA id 2EC2F66059A4; Wed, 24 May 2023 08:42:06 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1684914126; bh=JWCo/GiQIjgEd33TLlVz5h/VBvQ/u8Y9VSES2Wef+Cs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=guHh2BSYUS5UFvmOnh4vu8yu95UUSTNL+6Y80h+c0yZCnhsjVELoebtXgv1s+kNvU YoAz+N+yTIWAGBVBXWvngfo+VXZUc6meYNielFhHZxlueddOveDw8wI/YzLOpAMXtI z0tNjhsfuSwhGOmos0t5yD/wW5RnwtVfoQhlx5QyzXh0p704epqPb96bfl3nclpZ3m 4fipHtiioj1Z5mR16Pn1+akbINwMUwdYoUWg61UPKftKOGV6Ussew+lpNEjgDe8ozs nqNRVN0Tr4Rzi0xt0XjGzcI62ml4VP/8hMp8makZZDi4uAgN0p/eVXP2pt531T7j6T IsnTEQ5tiQTbw== From: Cristian Ciocaltea To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiko Stuebner , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Zhu Ning , Pierre-Louis Bossart , Charles Keepax , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?q?=C3=B6nig?= , David Yang , Daniel Drake Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, kernel@collabora.com Subject: [PATCH 2/3] ASoC: es8316: Do not set rate constraints for unsupported MCLKs Date: Wed, 24 May 2023 10:41:55 +0300 Message-Id: <20230524074156.147387-3-cristian.ciocaltea@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230524074156.147387-1-cristian.ciocaltea@collabora.com> References: <20230524074156.147387-1-cristian.ciocaltea@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766761331369022810?= X-GMAIL-MSGID: =?utf-8?q?1766761331369022810?= When using the codec through the generic audio graph card, there are at least two calls of es8316_set_dai_sysclk(), with the effect of limiting the allowed sample rates according to the MCLK/LRCK ratios supported by the codec: 1. During audio card setup, to set the initial MCLK - see asoc_simple_init_dai(). 2. Before opening a stream, to update MCLK, according to the stream sample rate and the multiplication factor - see asoc_simple_hw_params(). In some cases the initial MCLK might be set to a frequency that doesn't match any of the supported ratios, e.g. 12287999 instead of 12288000, which is only 1 Hz below the supported clock, as that is what the hardware reports. This creates an empty list of rate constraints, which is further passed to snd_pcm_hw_constraint_list() via es8316_pcm_startup(), and causes the following error on the very first access of the sound card: $ speaker-test -D hw:Analog,0 -F S16_LE -c 2 -t wav Broken configuration for playback: no configurations available: Invalid argument Setting of hwparams failed: Invalid argument Note that all subsequent retries succeed thanks to the updated MCLK set at point 2 above, which uses a computed frequency value instead of a reading from the hardware registers. Normally this would have mitigated the issue, but es8316_pcm_startup() executes before the 2nd call to es8316_set_dai_sysclk(), hence it cannot make use of the updated constraints. Since es8316_pcm_hw_params() performs anyway a final validation of MCLK against the stream sample rate and the supported MCLK/LRCK ratios, fix the issue by ensuring that sysclk_constraints list is only set when at least one supported sample rate is autodetected by the codec. Fixes: b8b88b70875a ("ASoC: add es8316 codec driver") Signed-off-by: Cristian Ciocaltea --- sound/soc/codecs/es8316.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c index 773c94fd3547..a78c0049a30c 100644 --- a/sound/soc/codecs/es8316.c +++ b/sound/soc/codecs/es8316.c @@ -386,7 +386,7 @@ static int es8316_set_dai_sysclk(struct snd_soc_dai *codec_dai, es8316->allowed_rates[count++] = freq / ratio; } - es8316->sysclk_constraints.list = es8316->allowed_rates; + es8316->sysclk_constraints.list = count ? es8316->allowed_rates : NULL; es8316->sysclk_constraints.count = count; return 0;