Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp3268382ybj; Mon, 23 Sep 2019 18:15:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqyp+pbq5UFOWJeegHr2u1oS5mInJWfO2OYCZ2185z4bRlJJE/9qUo4rbXV2yu9MoTrNfsTO X-Received: by 2002:a05:6402:184d:: with SMTP id v13mr114859edy.56.1569287742493; Mon, 23 Sep 2019 18:15:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569287742; cv=none; d=google.com; s=arc-20160816; b=VUUo3czNqoeHG+J++Xuzbn+aVKLzx0rtmtll8WELaVs6OfgDMaTiNl7ZDrchBWef40 DX3r0QEqs4QlFkR4c8sIIO0gpHNr56etJLFHzYuckXddb24CXrgXH5HbC3NlBBtZeZku D+k9KYlSNbKejTb7MTnqEisQb1SXlAOq+2J+9DZndBLa2oP73PLgypdDL3gsvMYGe6Wa TvSsRl+c4HOur8wWMTZhlupfZcP5cJ8OVjykE8xcm2UZu23okANtyZsOwMXcAn2CPtf5 3lgF/g55Pl582i7m/FTSou21GF8Y7gXbJGGAB6kIWt8uClHVb8QV724DitOjyoZzkJMt 80vA== 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 :dkim-signature; bh=xsWEA2CaisnmJmlZ+hwsaI5Rs/gazDcAEKYFvUEJsZw=; b=sQiXLKHAbM2/drDgODFYZAOTUX/LJPdUT+qwBOoedwyMc8V95j5arOge4ailORZwLu s3vKnOpmVLCzL8DaEfg7Yi2scGZxEOExJDeS8V8H7/07mNOtRLCe++IMUb2Iqz9MDTuB kVxDDehjahJgqHqEZY5XiHjR61Q1TMhAsnuZfBEmYwOA3N1q/6WZ2T5nwfMEEFjGDp+8 Pf21SGWyebgrLhC80DHeR216fyP/pVDehYn2SxIR7KpuzLxTyyYHVjs3MUXs0nspoW++ vV19shVkVmc4oBcQYaLvUPSxgS/tkQYBiUkMM1PQkJKL9aZEUE12HVvynvqrK80417c6 zcfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ordSCYFR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a2si129338edc.321.2019.09.23.18.15.16; Mon, 23 Sep 2019 18:15:42 -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; dkim=pass header.i=@kernel.org header.s=default header.b=ordSCYFR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391936AbfIVStB (ORCPT + 99 others); Sun, 22 Sep 2019 14:49:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:45554 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391693AbfIVSsi (ORCPT ); Sun, 22 Sep 2019 14:48:38 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 076FB208C2; Sun, 22 Sep 2019 18:48:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569178116; bh=9qfmsiCNaEBBbVAUBNjUeGmGxH7qdzSy+RWQqBp7ZR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ordSCYFRGf1zkUMc2ZSYmyiFfCh0sUbgiXk28MVkKksf1ev1w3bL44Z1qNeKMtYMi nSr6jM86A1dKUW87wReDSqtnVnabsxEBpwr6kQemkOK/myZsTcjzzZJPomd0ed7SBm jS91K2ncL+Fg0SMIzrjG4Ye0ExEX9d9usYZ/u+JQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Katsuhiro Suzuki , Mark Brown , Sasha Levin Subject: [PATCH AUTOSEL 5.3 173/203] ASoC: es8316: support fixed and variable both clock rates Date: Sun, 22 Sep 2019 14:43:19 -0400 Message-Id: <20190922184350.30563-173-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190922184350.30563-1-sashal@kernel.org> References: <20190922184350.30563-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Katsuhiro Suzuki [ Upstream commit ebe02a5b9ef05e3b812af3d628cdf6206d9ba610 ] 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 Link: https://lore.kernel.org/r/20190907163653.9382-2-katsuhiro@katsuster.net Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- 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 96d04896193f2..c47b3c4bb06c7 100644 --- a/sound/soc/codecs/es8316.c +++ b/sound/soc/codecs/es8316.c @@ -368,8 +368,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; + } /* Limit supported sample rates to ones that can be autodetected * by the codec running in slave mode. @@ -444,17 +448,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; } @@ -466,11 +463,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.20.1