Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4821841ybe; Mon, 9 Sep 2019 15:24:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5SHBpHlLX3T9kc4in7147BRThUPsXfxKSdGOobPViljRJrRw6MY9Fks8SZ3FyNfoMGQ9e X-Received: by 2002:a05:6402:6da:: with SMTP id n26mr6530581edy.234.1568067891367; Mon, 09 Sep 2019 15:24:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568067891; cv=none; d=google.com; s=arc-20160816; b=RKUa2jwt550OjPl86p5uf/GtAXw2qW5NpB582ii8ovl08vVbaM1g0M9A0g7eHxgkux Xj12m9GGf7cbiWO2WadkBKDS7k7Aa+6FSW6ax1KiBZU/nu7Iq+RdLaB+hV3p47tmDOjT 6lZYBDIEXkk+HmEG3z8VyORZ34cCVvvlp7sbxQ5i5jusI0kkJHLYhiS6CNF/HrSsyfpD bthZJi7xlTPP0SH3CVkjTWUTzDKu6cqzZxl0VIDT95+lxjmtUdrpzUKbAeo9eL19Czti 6YekW6zqnPia/0P5RGDPq6uWmzxVM/qol4O3DtaDiBpJ+R6pSt3mwo4vjMVBiVax7LSA 6Fkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:message-id:in-reply-to:subject:cc:to :from:dkim-signature; bh=qvEqsVB11jXmmerUvV31z20Vlpx17lLYw1fsBAjdagI=; b=JDCNObXNXvjaUZ50bK5ET1hSHBRjo68JdOS4YMkpG1iLprFs+42QLH7bZ2wg9ahbbo hbB4HdD/tYGM/Q/sPJCrsU8BLvAiQBwkg3Str4AHPOJC3C4Yx1bWaqjicby9AYtxkzZx PCVG3956I2v9JqzfshstfHR3wvK0d3O1Zl/jNy/gw6rJib+/sUISXsj5cKoGInWcSetw xBlIEG4YOAVJeicQmXOhDnP7XjWNGuj/nhMbK67p/dFS4MTWz9eMByMeQc52ihabdIEI FtIooJ3HVKHdV9uemTYa8OLTIFn83RcErOawcD02COUOfmgVX15+eNLAD+N6vNhh6G3l N6Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=pXNo7qq2; 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=fail (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 y15si8235222eje.204.2019.09.09.15.24.26; Mon, 09 Sep 2019 15:24:51 -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=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=pXNo7qq2; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729855AbfIIKHw (ORCPT + 99 others); Mon, 9 Sep 2019 06:07:52 -0400 Received: from heliosphere.sirena.org.uk ([172.104.155.198]:56116 "EHLO heliosphere.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728993AbfIIKH1 (ORCPT ); Mon, 9 Sep 2019 06:07:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sirena.org.uk; s=20170815-heliosphere; h=Date:Message-Id:In-Reply-To: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner: List-Archive; bh=qvEqsVB11jXmmerUvV31z20Vlpx17lLYw1fsBAjdagI=; b=pXNo7qq2UWBq spzRhEcGVj6jjCwtX6iq9ax3WlEaALupG2KGNADYj377FRXB5YK4B4iPhuIcB7TK+5I3QetDm0iRm ZVttrfHQEuFTtXHUzTXds1OPS6QUk+fk4ykoDpRgEFTR2APfm+NXYLjMvX5IUAhAJJZqEDQhZQQ0B KE+Z4=; Received: from [148.69.85.38] (helo=fitzroy.sirena.org.uk) by heliosphere.sirena.org.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1i7GZq-0001s5-0D; Mon, 09 Sep 2019 10:07:18 +0000 Received: by fitzroy.sirena.org.uk (Postfix, from userid 1000) id 559AED02D83; Mon, 9 Sep 2019 11:07:17 +0100 (BST) From: Mark Brown To: Katsuhiro Suzuki Cc: alsa-devel@alsa-project.org, Daniel Drake , David Yang , Hans de Goede , linux-kernel@vger.kernel.org, Mark Brown Subject: Applied "ASoC: es8316: support fixed and variable both clock rates" to the asoc tree In-Reply-To: <20190907163653.9382-2-katsuhiro@katsuster.net> X-Patchwork-Hint: ignore Message-Id: <20190909100717.559AED02D83@fitzroy.sirena.org.uk> Date: Mon, 9 Sep 2019 11:07:17 +0100 (BST) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch ASoC: es8316: support fixed and variable both clock rates has been applied to the asoc tree at https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.4 All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark From ebe02a5b9ef05e3b812af3d628cdf6206d9ba610 Mon Sep 17 00:00:00 2001 From: Katsuhiro Suzuki Date: Sun, 8 Sep 2019 01:36:53 +0900 Subject: [PATCH] ASoC: es8316: support fixed and variable both clock rates 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 --- 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 e9fa4981ccef..9150e7068467 100644 --- a/sound/soc/codecs/es8316.c +++ b/sound/soc/codecs/es8316.c @@ -367,8 +367,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) @@ -447,17 +451,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; } @@ -469,11 +466,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