Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2931583ybl; Sun, 25 Aug 2019 05:19:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqzlvKTdBJukvg2c+N/oh/hQvhcWZOUlKnJAxtPh7UMmWl20QNkw+S7ect+fREjzZQmk1UQk X-Received: by 2002:a17:902:a6:: with SMTP id a35mr14663471pla.130.1566735597942; Sun, 25 Aug 2019 05:19:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566735597; cv=none; d=google.com; s=arc-20160816; b=U2lBNGN0XOooVKjGNryD9pnanhMrBzKmUnl/U4C7Vj/dFqM5O7oCfZf802TcsSR60u AMrnUhkJrmE4nfAzoKpRtnhlzHb523b3GnXjCx10Y3LXap+Skc2ufC6l1NziBvHk3RY3 Q+9ZKmZIq8iEqSA/2MW9+oSGCmDa0coLaQ86tHr8wWpmadrw48QclHXvL0WhL44QAwcQ pPuj+8Cb01DWAZxRyxqOQoklS3VVkFkvQsFIlPk7xxhSNtG6YD4Zen2WydlrGdCmLtky Ti3HoZky/IzZSrpAuxDc10dK/lqttUSDPFuVo4Kk5QIcnhsH270d2JgRrsQyyJhyp30g JZvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:content-transfer-encoding :mime-version:subject:from:references:in-reply-to:message-id:date :dkim-signature; bh=glDMrcfrWJ9EQDwzzOHAjDdcDFBvI5HDn0WuyiNfJ9k=; b=hDShvfhp9X0o0eYh9vCdECsqGb+UAwLBb2rGOp2UK8Ua8bV3OIxeXNBeBDzM9d1Ten 5aPLsOuTaYkvNYRp0o6Mt3shmUjWzxMQ1Z89CvOKC61U5blZOV/12cGukqN9ZjGmhypr Ze0qCQdaMg9xcVouCj2fDOVuY54gz4+lpEBr0H8DV3JwN3wWnY/LLXNxSLHZK4aRnhti NMtReEP901XlJy+/OVl+5C7R8gZR95sXjliaKilrAjhJU6XfD8lXD2wtglJzB2mS5J83 bj+op/Y+rA+vSdIJR8ToEk/zjlLK2PeijCuXzpkG3/YOlEflU5DPc6iK6vBXr7o0w+cb PZ1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=AUtdOu+1; 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 r3si7110238plb.215.2019.08.25.05.19.38; Sun, 25 Aug 2019 05:19:57 -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=@rere.qmqm.pl header.s=1 header.b=AUtdOu+1; 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 S1728138AbfHYMRm (ORCPT + 99 others); Sun, 25 Aug 2019 08:17:42 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:15893 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727285AbfHYMRl (ORCPT ); Sun, 25 Aug 2019 08:17:41 -0400 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?q?Micha=C5=82=20Miros=C5=82aw?= Subject: [PATCH v2 3/4] ASoC: wm8904: automatically choose clock source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To: alsa-devel@alsa-project.org, patches@opensource.cirrus.com Cc: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Charles Keepax , Allison Randal , Enrico Weigelt , zhong jiang , Thomas Gleixner , Alexandre Belloni , Anders Roxell , Annaliese McDermond , Codrin Ciubotariu , Greg Kroah-Hartman , Jerome Brunet , Kate Stewart , Kirill Marinushkin , Kuninori Morimoto , Ludovic Desroches , Maxime Jourdan , Nariman Poushin , Nicolas Ferre , Nikesh Oswal , Paul Cercueil , Piotr Stankiewicz , Randy Dunlap , Richard Fitzgerald , Srinivas Kandagatla , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, -- 2.20.1