From patchwork Mon Jul 22 17:57:21 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: 11053231 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2226713AC for ; Mon, 22 Jul 2019 17:59:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DEDC2821F for ; Mon, 22 Jul 2019 17:59:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1DAF28488; Mon, 22 Jul 2019 17:59:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.1 required=2.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A624328389 for ; Mon, 22 Jul 2019 17:59:17 +0000 (UTC) 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 0C11E1827; Mon, 22 Jul 2019 19:58:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 0C11E1827 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1563818355; bh=X2Wovxj54BUX9EeWz+yQ8sA2uXEbDvaVd6Df2+EuL4k=; h=Date:In-Reply-To:References:From:To:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=HbC6HMmRhV7SMop6qhOT1H6W+FkcZlJvb91iGP3mKHi99hAUpZDLEqrV+6caXsFse lFvhXMQVPcBLoN+uOsoz5ANGK3u3vGZuV3yLI8IIk+DgN7PjNQ9SlxB/7tQ3UKXGoA lC+6uuq/uSNsUwEkQK1DtgHYkQlYM2IzPh/Aodcw= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 0E494F803D7; Mon, 22 Jul 2019 19:57:31 +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 61A0AF803D6; Mon, 22 Jul 2019 19:57:27 +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 D8FC3F803D5 for ; Mon, 22 Jul 2019 19:57:22 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D8FC3F803D5 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=rere.qmqm.pl header.i=@rere.qmqm.pl header.b="kKxJ9vkq" Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 45sq6B5kvKzHW; Mon, 22 Jul 2019 19:56:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1563818162; bh=GsdL27VirxgcYyB6/yKrLZ/ev5netk3LyKLVYjia/+M=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=kKxJ9vkq/itKGZp7S7QAYFRHtSY+zK2iW3MTr0xeu02kvYxbkxEKvPPZEHRNN+UKq mmglU2zmUeYSueQffoGiucMxUbADcd7VrDATjmQfgx5/C9tRznFR+buFJq/lIIMhsr dDlzkvA9JjxPWGVdODOTU3mp52wE9zyCZZOTulVpG+KTIBRdNKZ4OtDoknV2VL/1/n R1ZYmrB5hIBbxunwhEKSf5aplg1Ome5uP38XqeDxW+1l4zUZILvWMQiNOJZWJUH445 51pD26DMTql1zZ+5oz6chyLxymgyzYbXcfz7mh3HcOXJ8SS0CphsZ9KaJ8CppKlXQD 1O68zo/3cFwjQ== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.100.3 at mail Date: Mon, 22 Jul 2019 19:57:21 +0200 Message-Id: <812430384c2d65fd1a51328e8b589700e239ccae.1563817201.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 Cc: Alexandre Belloni , patches@opensource.cirrus.com, Nicolas Ferre , Takashi Iwai , Liam Girdwood , Ludovic Desroches , Mark Brown , Codrin Ciubotariu Subject: [alsa-devel] [PATCH 2/2] 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 033a38e408b5..2d8cb61a2d97 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; @@ -419,7 +438,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 { @@ -1334,6 +1355,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,