Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp3653146ybe; Sun, 8 Sep 2019 18:56:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqyRHnr0uEupRU9/BNYZFz2MK/BO5+L3f/EdYxMbs5iCCmkIzwAU7P68skRhdclh31MwbN3s X-Received: by 2002:a17:906:6dc1:: with SMTP id j1mr17380901ejt.85.1567994216140; Sun, 08 Sep 2019 18:56:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567994216; cv=none; d=google.com; s=arc-20160816; b=X4zwfN84B8EoHTEz3Yz3ExsTQgRCoo/osuw6kD1Q9hS1jVw/QrCiXp49QAO+2VkAXq rK8cTi8vY+QK+pbQmyqEheiOTpUkA6buvKQG6otM1HlHMF7NAoDQDl7lD9xyMA3GDHM6 YuPqHyat3szQ8igjeweLQA1G8lvNhXg2uHG0C2ZZv4Atx7G0NtwZx/BcR2WeTJ999Uf7 BkOwPhQpZ0eDyVSctwulxsYyo77w/D4dwc4xiiIteDX1np76gwSdbDDGFodBt6vcdwPA GR0dqyp8E71mL4e2h3Jq84IDl1ZU9FSGDMNtznic2kQ7shdH3Kjfp6gA+5q8fFsupvug QxHQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Fl/R98d/Shoe4ioc/IKRF9i01ytuYSvs3hltEft30so=; b=aN+75ojxB0jBema2kmyd9tfSFjwJHUFMeBySBeQCXd0tE8ecHP4azfMl7nXCSTyj6A qwS8CwWQQm5fAba4DcaP+R5QwsBeAqIZtrA0i170pbYEP9XxztVQJ+kzADkTezB474Th 78JYHY7umG2mXdwTJdZ/UvEwBci1jzDQMHeuHk5fqbQRcqh7PdH/8wuAE3aOpoJZaQDa ip3hhd5jQBQpEq9NBAJMn2/3ImsNMG7YYk9WNVfYCbu9XhJkxjG1HL4fSdw0OX9wI57z 3rJVx7Rp2cciEAc3kDIkU1Siy373qJYP4LWHkq0IAwJJ4KCnGyqNYZ/Om3ZdBRr1YIWL jcDQ== 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 y23si7239816edt.114.2019.09.08.18.56.19; Sun, 08 Sep 2019 18:56:56 -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 S2394977AbfIGQhU (ORCPT + 99 others); Sat, 7 Sep 2019 12:37:20 -0400 Received: from www1102.sakura.ne.jp ([219.94.129.142]:16949 "EHLO www1102.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392062AbfIGQhU (ORCPT ); Sat, 7 Sep 2019 12:37:20 -0400 Received: from fsav106.sakura.ne.jp (fsav106.sakura.ne.jp [27.133.134.233]) by www1102.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id x87GawhE091901; Sun, 8 Sep 2019 01:36:58 +0900 (JST) (envelope-from katsuhiro@katsuster.net) Received: from www1102.sakura.ne.jp (219.94.129.142) by fsav106.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav106.sakura.ne.jp); Sun, 08 Sep 2019 01:36:58 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav106.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 x87GatL3091872 (version=TLSv1.2 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 8 Sep 2019 01:36:58 +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 2/2] ASoC: es8316: support fixed and variable both clock rates Date: Sun, 8 Sep 2019 01:36:53 +0900 Message-Id: <20190907163653.9382-2-katsuhiro@katsuster.net> X-Mailer: git-send-email 2.23.0.rc1 In-Reply-To: <20190907163653.9382-1-katsuhiro@katsuster.net> References: <20190907163653.9382-1-katsuhiro@katsuster.net> 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 supports some type of machine drivers that set 0 to mclk when sound device goes to idle state. After applied this patch, sysclk == 0 means there is no constraint of sound rate and other values will set constraints which is derived by sysclk setting. Original code refuses sysclk == 0 setting. 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 Signed-off-by: Katsuhiro Suzuki --- sound/soc/codecs/es8316.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c index 1424ecd6952c..36eef1fb3d18 100644 --- a/sound/soc/codecs/es8316.c +++ b/sound/soc/codecs/es8316.c @@ -370,8 +370,12 @@ static int es8316_set_dai_sysclk(struct snd_soc_dai *codec_dai, es8316->sysclk = freq; - if (freq == 0) + if (freq == 0) { + es8316->sysclk_constraints.list = NULL; + es8316->sysclk_constraints.count = 0; + return 0; + } ret = clk_set_rate(es8316->mclk, freq); if (ret) @@ -450,17 +454,10 @@ static int es8316_pcm_startup(struct snd_pcm_substream *substream, struct snd_soc_component *component = dai->component; struct es8316_priv *es8316 = snd_soc_component_get_drvdata(component); - if (es8316->sysclk == 0) { - dev_err(component->dev, "No sysclk provided\n"); - 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); + if (es8316->sysclk_constraints.list) + snd_pcm_hw_constraint_list(substream->runtime, 0, + SNDRV_PCM_HW_PARAM_RATE, + &es8316->sysclk_constraints); return 0; } @@ -472,11 +469,19 @@ 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; + /* Validate supported sample rates that are autodetected from MCLK */ + 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: -- 2.23.0.rc1