Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1611850rwb; Fri, 19 Aug 2022 06:39:11 -0700 (PDT) X-Google-Smtp-Source: AA6agR4/MfvK9wzqnyuTSYhqIn3SZwCAm5wVDv9j+BzwtX2HlHQ6UC6rWC3xVXb2KB3godybK6z3 X-Received: by 2002:a17:907:a05a:b0:730:98b2:16d7 with SMTP id gz26-20020a170907a05a00b0073098b216d7mr4953300ejc.394.1660916351638; Fri, 19 Aug 2022 06:39:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660916351; cv=none; d=google.com; s=arc-20160816; b=HswnvnAjVq8eviskJq7NsLyPx7WxIy16+yE2qlwBAQMixGPlSFZbzS2jz1VifViLaY F1c5DOFkZpc0VfncDcNV4LTZiTpQ+/i92YtIeQYKDDp/vLtfWcaHtCfQAuOMOOWM5USh u9c+yokAang4xfVcRhz3eJk35bdAf7kwhjsyc1+kF082FsQQ0osghxXz4u22kNdEZFh7 AGBKWotaLnSUq8CewHZwTi2FerR1qXDe5BhUHMOH4H6pNICVNzwEPSjEGpk46UBuG2wG cM94zzPWNUyYUvkktzplcieCjvk9HzUi/awykoBCBHH0Hi5767Bf2yntAc4nh1W3YLVe kwdg== 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=VG7YSU/cYAKrW65aE8mh5zeQwZiWTAjDbpKQXBnwCro=; b=HL9nXsShIp07suCihGNsu0tdZqKJcLzm49BuVdWHkxCtr8wE3Z7TEnCObvQce0AXb1 LtPQxyx4p2SJ782BpDlqmZNiEiJfAtFvQ8IegN+DKMLPWffRW83lBvagqt8RYjJD+RJ4 QAXQGD5nmMqFZdSOqtNyJzALx5HmIvrnkwFgfDKAw85Vqverakm3s+JjGu7iiiAzGIbd DprVK+52pGwui7xaxp52qqAt35qTlPV/4MWpdoj0rBjOrL+lQuzZxe4XRlLftWHRDC86 oGUdro0MtxCRxW92EoCWx1IAqHgH3QEAKaDggbROkZgxocdQa5k3Isw0mJQ7ayroKLY4 ejsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=hseGJlHF; 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=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j10-20020a056402238a00b00445cf52471csi2986872eda.364.2022.08.19.06.38.45; Fri, 19 Aug 2022 06:39:11 -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=@cirrus.com header.s=PODMain02222019 header.b=hseGJlHF; 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=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349145AbiHSMxG (ORCPT + 99 others); Fri, 19 Aug 2022 08:53:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349104AbiHSMwt (ORCPT ); Fri, 19 Aug 2022 08:52:49 -0400 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EEA3DAEE4 for ; Fri, 19 Aug 2022 05:52:48 -0700 (PDT) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27J5opPo018534; Fri, 19 Aug 2022 07:52:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=VG7YSU/cYAKrW65aE8mh5zeQwZiWTAjDbpKQXBnwCro=; b=hseGJlHFyKI4oLN8yXRxvhLzeh3FUYZ8P6CN4jHUqJvdL5nDsQsztJqri5yFpiHBoPQj 1s40Km0Z2AFV/4JYNUkVu/JCf5eIpS4AJqroAv7z543MaHkCtjRI5Au5zYTlt+/n/Ey6 Nd4X5p/QutuH0WuHdU8psI7kXumEDemUlg5ebjap9hXXs0Bc1TqVihPjJQSkBYdX0tJP +0DvckFxd8s98GlLagE0Wx9g0RMjjR+HNF6weN0lombIKCqEmwXje6yatavQ0lVG0sTv ZV/3tFcxDDmiLqUrVr1Q5n0SZzyInbUlmdWRiMWOofw/+fKkGkV9Y8plv4QRHs4FvA5m 1Q== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3hx9c1yrtp-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Aug 2022 07:52:37 -0500 Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.9; Fri, 19 Aug 2022 07:52:34 -0500 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1118.9 via Frontend Transport; Fri, 19 Aug 2022 07:52:34 -0500 Received: from edi-sw-dsktp-006.ad.cirrus.com (edi-sw-dsktp-006.ad.cirrus.com [198.90.251.95]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 9515C11DA; Fri, 19 Aug 2022 12:52:34 +0000 (UTC) From: Richard Fitzgerald To: CC: , , , Richard Fitzgerald Subject: [PATCH 03/12] ASoC: cs42l42: Ensure MCLKint is a multiple of the sample rate Date: Fri, 19 Aug 2022 13:52:21 +0100 Message-ID: <20220819125230.42731-4-rf@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220819125230.42731-1-rf@opensource.cirrus.com> References: <20220819125230.42731-1-rf@opensource.cirrus.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: CENTUxRxpjrLobtgkyOYKYw1H2jZ2Pyj X-Proofpoint-GUID: CENTUxRxpjrLobtgkyOYKYw1H2jZ2Pyj X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,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 The chosen clocking configuration must give an internal MCLK (MCLKint) that is an integer multiple of the sample rate. On I2S each of the supported bit clock frequencies can only be generated from one sample rate group (either the 44100 or the 48000) so the code could use only the bitclock to look up a PLL config. The relationship between sample rate and bitclock frequency is more complex on Soundwire and so it is possible to set a frame shape to generate a bitclock from the "wrong" group. For example 2*147 with a 48000 sample rate would give a bitclock of 14112000 which on I2S could only be derived from a 44100 sample rate. Signed-off-by: Richard Fitzgerald --- sound/soc/codecs/cs42l42.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sound/soc/codecs/cs42l42.c b/sound/soc/codecs/cs42l42.c index 1745b83310ac..66c10d24169d 100644 --- a/sound/soc/codecs/cs42l42.c +++ b/sound/soc/codecs/cs42l42.c @@ -649,7 +649,8 @@ static const struct cs42l42_pll_params pll_ratio_table[] = { { 24576000, 1, 0x03, 0x40, 0x000000, 0x03, 0x10, 12288000, 128, 1} }; -static int cs42l42_pll_config(struct snd_soc_component *component, unsigned int clk) +static int cs42l42_pll_config(struct snd_soc_component *component, unsigned int clk, + unsigned int sample_rate) { struct cs42l42_private *cs42l42 = snd_soc_component_get_drvdata(component); int i; @@ -664,6 +665,10 @@ static int cs42l42_pll_config(struct snd_soc_component *component, unsigned int } for (i = 0; i < ARRAY_SIZE(pll_ratio_table); i++) { + /* MCLKint must be a multiple of the sample rate */ + if (pll_ratio_table[i].mclk_int % sample_rate) + continue; + if (pll_ratio_table[i].sclk == clk) { cs42l42->pll_config = i; @@ -889,6 +894,7 @@ static int cs42l42_pcm_hw_params(struct snd_pcm_substream *substream, struct cs42l42_private *cs42l42 = snd_soc_component_get_drvdata(component); unsigned int channels = params_channels(params); unsigned int width = (params_width(params) / 8) - 1; + unsigned int sample_rate = params_rate(params); unsigned int slot_width = 0; unsigned int val = 0; unsigned int bclk; @@ -949,11 +955,11 @@ static int cs42l42_pcm_hw_params(struct snd_pcm_substream *substream, break; } - ret = cs42l42_pll_config(component, bclk); + ret = cs42l42_pll_config(component, bclk, sample_rate); if (ret) return ret; - cs42l42_src_config(component, params_rate(params)); + cs42l42_src_config(component, sample_rate); return 0; } -- 2.30.2