Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2178109ybl; Sat, 31 Aug 2019 09:28:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqzX3pHNAUk6XosQfeCYsWfcpwx9GmpsGqquQlHcm+L9C9eG62alKsuBAoRLy6vbLTvZ7yTq X-Received: by 2002:a62:4d41:: with SMTP id a62mr25240069pfb.155.1567268939060; Sat, 31 Aug 2019 09:28:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567268939; cv=none; d=google.com; s=arc-20160816; b=MQczEruVCpl62PkRhHUEQakHn0d6qDgZJ6fNFLoRZw0ObEKL1NZsh7iKr8/70YtSP1 H9O7DNtI2CpBmIldlpQH3kKgdOeGifP+ovMq6rT6eH8o+vn6pQF8M8bwyNi020P965r1 71pORhgjlSTu2WpLIBoG499kR02VRgPM+698EKgbpF6KaRgUfwdrNv/Pzyb5kHdEdQe/ F8tauhOxhdZppGad7m9QKdU8o1Ulv0WMS8t25r/FT6WEJlasXEdcDj6uv6gnpqjducMU jgbK1y96gqB+ELrfX3t9U7WRi59jCv2tZliW4Ac6IfQdyrwzy3wTgJCxnJPQTGuGzdhB vPCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=uJRl6lb30ZcOCssR0gaNW7Z7TfzhpwePcg1CizE60h4=; b=D2ay82FNDG1k8UReafZYbHkIJMyUSZ+KiqN6nfhGS1IG+zRrTB74Ek+sOGN8sUQkqR lWWDf01kl5F4HfuyITk2MjxDTKiNcCTbNb8+u8kO9SyQmHlpPRvyMvmoyZMPL9vMAH9k AuFt+S+Uee2QDVH1YwhfLYDaDT7ICp12PJth4fTXipcp6D66h7b2iXsqwGvHWTgf9VBh Hj4t5oQrloAnfL2R0TyQQLEcB4UOAMFp03C+jyXXM5JLKtRfk/F8K13IO9r6vKWJFnKB KOO4Eile5IUc3XUn4+LeEweNQT99b0ZF+MM9EIuq5mGc+yeSnahNYikvIlRl8jgub8UJ zf2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n10si7671388plk.433.2019.08.31.09.28.43; Sat, 31 Aug 2019 09:28:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728464AbfHaQ1S (ORCPT + 99 others); Sat, 31 Aug 2019 12:27:18 -0400 Received: from www1102.sakura.ne.jp ([219.94.129.142]:36740 "EHLO www1102.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728244AbfHaQ1R (ORCPT ); Sat, 31 Aug 2019 12:27:17 -0400 Received: from fsav105.sakura.ne.jp (fsav105.sakura.ne.jp [27.133.134.232]) by www1102.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id x7VGQsjq085473; Sun, 1 Sep 2019 01:26:54 +0900 (JST) (envelope-from katsuhiro@katsuster.net) Received: from www1102.sakura.ne.jp (219.94.129.142) by fsav105.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav105.sakura.ne.jp); Sun, 01 Sep 2019 01:26:54 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav105.sakura.ne.jp) Received: from localhost.localdomain (118.153.231.153.ap.dti.ne.jp [153.231.153.118]) (authenticated bits=0) by www1102.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id x7VGQort085462 (version=TLSv1.2 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 1 Sep 2019 01:26:53 +0900 (JST) (envelope-from katsuhiro@katsuster.net) From: Katsuhiro Suzuki To: Mark Brown , David Yang , Daniel Drake , Hans de Goede Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Katsuhiro Suzuki Subject: [PATCH v2 1/3] ASoC: es8316: judge PCM rate at later timing Date: Sun, 1 Sep 2019 01:26:48 +0900 Message-Id: <20190831162650.19822-1-katsuhiro@katsuster.net> X-Mailer: git-send-email 2.23.0.rc1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch change the judge timing about playing/capturing PCM rate. Original code set constraints list of PCM rate limits at set_sysclk. This strategy works well if system is using fixed rate clock. But some boards and SoC (such as RockPro64 and RockChip I2S) has connected SoC MCLK out to ES8316 MCLK in. In this case, SoC side I2S will choose suitable frequency of MCLK such as fs * mclk-fs when user starts playing or capturing. Bad scenario as follows (mclk-fs = 256): - Initialize sysclk by correct value (Ex. 12.288MHz) - ES8316 set constraints of PCM rate by sysclk 48kHz (1/256), 32kHz (1/384), 30.720kHz (1/400), 24kHz (1/512), 16kHz (1/768), 12kHz (1/1024) - Play 48kHz sound, it's acceptable - Sysclk is not changed - Play 32kHz sound, it's acceptable - Set sysclk by 8.192MHz (= fs * mclk-fs = 32k * 256) - ES8316 set constraints of PCM rate by sysclk 32kHz (1/256), 21.33kHz (1/384), 20.48kHz (1/400), 16kHz (1/512), 10.66kHz (1/768), 8kHz (1/1024) - Play 48kHz again, but it's NOT acceptable because constraints list does not allow 48kHz Root cause of this strange behavior is changing constraints list at set_sysclk timing. It seems that is too early to determine. So this patch does not use constraints list and check PCM rate limit more later timing at hw_params. Signed-off-by: Katsuhiro Suzuki --- sound/soc/codecs/es8316.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c index ed2959dbe1fb..229808fa627c 100644 --- a/sound/soc/codecs/es8316.c +++ b/sound/soc/codecs/es8316.c @@ -363,27 +363,12 @@ static int es8316_set_dai_sysclk(struct snd_soc_dai *codec_dai, { struct snd_soc_component *component = codec_dai->component; struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); - int i; - int count = 0; es8316->sysclk = freq; if (freq == 0) return 0; - /* Limit supported sample rates to ones that can be autodetected - * by the codec running in slave mode. - */ - for (i = 0; i < NR_SUPPORTED_MCLK_LRCK_RATIOS; i++) { - const unsigned int ratio = supported_mclk_lrck_ratios[i]; - - if (freq % ratio == 0) - es8316->allowed_rates[count++] = freq / ratio; - } - - es8316->sysclk_constraints.list = es8316->allowed_rates; - es8316->sysclk_constraints.count = count; - return 0; } @@ -449,13 +434,6 @@ static int es8316_pcm_startup(struct snd_pcm_substream *substream, return -EINVAL; } - /* The set of sample rates that can be supported depends on the - * MCLK supplied to the CODEC. - */ - snd_pcm_hw_constraint_list(substream->runtime, 0, - SNDRV_PCM_HW_PARAM_RATE, - &es8316->sysclk_constraints); - return 0; } @@ -466,12 +444,27 @@ static int es8316_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_soc_component *component = dai->component; struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); u8 wordlen = 0; + int i; if (!es8316->sysclk) { dev_err(component->dev, "No MCLK configured\n"); return -EINVAL; } + /* Limit supported sample rates to ones that can be autodetected + * by the codec running in slave mode. + */ + for (i = 0; i < NR_SUPPORTED_MCLK_LRCK_RATIOS; i++) { + const unsigned int ratio = supported_mclk_lrck_ratios[i]; + + if (es8316->sysclk % ratio != 0) + continue; + if (es8316->sysclk / ratio == params_rate(params)) + break; + } + if (i == NR_SUPPORTED_MCLK_LRCK_RATIOS) + return -EINVAL; + switch (params_format(params)) { case SNDRV_PCM_FORMAT_S16_LE: wordlen = ES8316_SERDATA2_LEN_16; -- 2.23.0.rc1