From patchwork Sun Aug 25 12:17:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= X-Patchwork-Id: 11121633 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 21C2813B1 for ; Thu, 29 Aug 2019 15:11:07 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A90CF22CED for ; Thu, 29 Aug 2019 15:11:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="AU1WO6pu"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="AUtdOu+1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A90CF22CED Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=rere.qmqm.pl Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id ED24816FC; Thu, 29 Aug 2019 17:10:14 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz ED24816FC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1567091465; bh=CE6R76MMGVSloRRvAulEnKYQP+3R4V1n6B8VrgmKIXU=; h=Date:In-Reply-To:References:From:To:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=AU1WO6puN98+/6EITrzGDyVvLBJBjL5dPV7b5KDibLe9L2tidnv35iPoiYjCnjXgE gy8fO1WzcFGxl5Bn+Gxgu0K9INsgsy/KbF1+6v6lIbNMHxB6NrU3FpBw7M0Kmd9YVM +aC/mnnqQz6UHHvI6kE0lVUaHCaUOEQQ9KPJaoFA= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id ABB42F89671; Wed, 28 Aug 2019 07:58:36 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 39517F8014A; Sun, 25 Aug 2019 14:27:40 +0200 (CEST) Received: from rere.qmqm.pl (rere.qmqm.pl [91.227.64.183]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id E8D1BF80212 for ; Sun, 25 Aug 2019 14:17:38 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E8D1BF80212 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="AUtdOu+1" Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 46GYyB0Qd1zM6; Sun, 25 Aug 2019 14:16:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1566735362; bh=Al1lbbPw+zZcMOPjHh4luaJeNVrX1Hy7lFV9zPv3gns=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=AUtdOu+12L8K334By+FEnF5Sz8vjG/7tlzwrridx/BYCNe1nDD8qbDIXTCIGlTHC4 JJY9OdYg474V+1OT1P4kqrH9WlT1AmltPhjkpH3AXlibgJ8P8sgJGFwfVYbERr0p6z 1H0w93OxlvbHTrC9Z2AhilyUgS4AJMiBFBd4YE88ir9xv/IOUdzaTsZMENESU379Vn UBLu9T3+5CY97OzHZxoBOvux0csC2S7TpFv56DfdeRKaOirB0qhBgsbUnZPXLeiDuT J25VmB+hOeat6/A0o8USeCMQ6+TjfUl0N3DIgaMPHTQVv/RkcnVLVlVzr1EycZ86bQ zK90APevAdooQ== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.101.2 at mail Date: Sun, 25 Aug 2019 14:17:37 +0200 Message-Id: <0b92f741a4c382cb8d50c1aebfa9da15d7e470ae.1566734631.git.mirq-linux@rere.qmqm.pl> In-Reply-To: References: From: =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= MIME-Version: 1.0 To: alsa-devel@alsa-project.org, patches@opensource.cirrus.com X-Mailman-Approved-At: Wed, 28 Aug 2019 07:58:25 +0200 Cc: Kate Stewart , Maxime Jourdan , Alexandre Belloni , Kuninori Morimoto , Kirill Marinushkin , Takashi Iwai , Paul Cercueil , Srinivas Kandagatla , Jerome Brunet , Anders Roxell , Ludovic Desroches , linux-arm-kernel@lists.infradead.org, Codrin Ciubotariu , Charles Keepax , Liam Girdwood , Piotr Stankiewicz , Annaliese McDermond , Richard Fitzgerald , Mark Brown , Nariman Poushin , Thomas Gleixner , zhong jiang , Allison Randal , Greg Kroah-Hartman , Randy Dunlap , Nikesh Oswal , Nicolas Ferre , linux-kernel@vger.kernel.org, Enrico Weigelt Subject: [alsa-devel] [PATCH v2 3/4] ASoC: wm8904: automatically choose clock source X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Choose clock source automatically if not provided. This will be the case with eg. audio-graph-card. Signed-off-by: Michał Mirosław --- sound/soc/codecs/wm8904.c | 42 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/wm8904.c b/sound/soc/codecs/wm8904.c index c9318fe34f91..946315d4cecf 100644 --- a/sound/soc/codecs/wm8904.c +++ b/sound/soc/codecs/wm8904.c @@ -367,15 +367,34 @@ static int wm8904_enable_sysclk(struct wm8904_priv *priv) return err; } +static int wm8904_bump_fll_sysclk(unsigned int *rate); + static int wm8904_set_sysclk(struct snd_soc_dai *dai, int clk_id, unsigned int rate, int dir) { struct snd_soc_component *component = dai->component; struct wm8904_priv *wm8904 = snd_soc_component_get_drvdata(component); unsigned int clock0, clock2; - int err; + int err, do_div = false; switch (clk_id) { + case 0: + if (rate == clk_round_rate(wm8904->mclk, rate)) { + clk_id = WM8904_CLK_MCLK; + } else if (rate * 2 == clk_round_rate(wm8904->mclk, rate * 2)) { + rate *= 2; + clk_id = WM8904_CLK_MCLK; + do_div = true; + } else { + clk_id = WM8904_CLK_FLL; + err = wm8904_bump_fll_sysclk(&rate); + if (err) { + dev_dbg(component->dev, "Can't match %u over FLL 1406250 Hz minimum\n", rate); + return err; + } + } + break; + case WM8904_CLK_MCLK: case WM8904_CLK_FLL: break; @@ -421,7 +440,9 @@ static int wm8904_set_sysclk(struct snd_soc_dai *dai, int clk_id, } /* SYSCLK shouldn't be over 13.5MHz */ - if (rate > 13500000) { + if (rate > 13500000) + do_div = true; + if (do_div) { clock0 = WM8904_MCLK_DIV; wm8904->sysclk_rate = rate / 2; } else { @@ -1350,6 +1371,23 @@ static struct { { 480, 20 }, }; +static int wm8904_bump_fll_sysclk(unsigned int *rate) +{ + int i; + + /* bump SYSCLK rate if below minimal FLL output */ + + for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) { + if (*rate * bclk_divs[i].div >= 1406250 * 10) + break; + } + + if (i == ARRAY_SIZE(bclk_divs)) + return -ERANGE; + + *rate = (*rate * bclk_divs[i].div) / 10; + return 0; +} static int wm8904_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params,