From: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>
To: alsa-devel@alsa-project.org, patches@opensource.cirrus.com
Cc: Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>,
Charles Keepax <ckeepax@opensource.cirrus.com>,
Allison Randal <allison@lohutok.net>,
Enrico Weigelt <info@metux.net>,
zhong jiang <zhongjiang@huawei.com>,
Thomas Gleixner <tglx@linutronix.de>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Anders Roxell <anders.roxell@linaro.org>,
Annaliese McDermond <nh6z@nh6z.net>,
Codrin Ciubotariu <codrin.ciubotariu@microchip.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jerome Brunet <jbrunet@baylibre.com>,
Kate Stewart <kstewart@linuxfoundation.org>,
Kirill Marinushkin <kmarinushkin@birdec.tech>,
Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
Ludovic Desroches <ludovic.desroches@microchip.com>,
Maxime Jourdan <mjourdan@baylibre.com>,
Nariman Poushin <npoushin@opensource.cirrus.com>,
Nicolas Ferre <nicolas.ferre@microchip.com>,
Nikesh Oswal <nikesh@opensource.cirrus.com>,
Paul Cercueil <paul@crapouillou.net>,
Piotr Stankiewicz <piotrs@opensource.cirrus.com>,
Randy Dunlap <rdunlap@infradead.org>,
Richard Fitzgerald <rf@opensource.cirrus.com>,
Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 3/4] ASoC: wm8904: automatically choose clock source
Date: Sun, 25 Aug 2019 14:17:37 +0200 [thread overview]
Message-ID: <0b92f741a4c382cb8d50c1aebfa9da15d7e470ae.1566734631.git.mirq-linux@rere.qmqm.pl> (raw)
In-Reply-To: <cover.1566734630.git.mirq-linux@rere.qmqm.pl>
Choose clock source automatically if not provided. This will be the case
with eg. audio-graph-card.
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
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
next prev parent reply other threads:[~2019-08-25 12:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-25 12:17 [PATCH v2 0/4] wm8904: adapt driver for use with audio-graph-card Michał Mirosław
2019-08-25 12:17 ` [PATCH v2 1/4] ASoC: wm_fll: extract common code for Wolfson FLLs Michał Mirosław
2019-08-25 12:17 ` [PATCH v2 2/4] ASoC: wm8904: use common FLL code Michał Mirosław
2019-08-29 12:57 ` Charles Keepax
2019-08-25 12:17 ` Michał Mirosław [this message]
2019-08-25 12:17 ` [PATCH v2 4/4] [RFT] ASoC: wm8994: " Michał Mirosław
2019-08-27 18:40 ` [PATCH v2 0/4] wm8904: adapt driver for use with audio-graph-card Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0b92f741a4c382cb8d50c1aebfa9da15d7e470ae.1566734631.git.mirq-linux@rere.qmqm.pl \
--to=mirq-linux@rere.qmqm.pl \
--cc=alexandre.belloni@bootlin.com \
--cc=allison@lohutok.net \
--cc=alsa-devel@alsa-project.org \
--cc=anders.roxell@linaro.org \
--cc=broonie@kernel.org \
--cc=ckeepax@opensource.cirrus.com \
--cc=codrin.ciubotariu@microchip.com \
--cc=gregkh@linuxfoundation.org \
--cc=info@metux.net \
--cc=jbrunet@baylibre.com \
--cc=kmarinushkin@birdec.tech \
--cc=kstewart@linuxfoundation.org \
--cc=kuninori.morimoto.gx@renesas.com \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ludovic.desroches@microchip.com \
--cc=mjourdan@baylibre.com \
--cc=nh6z@nh6z.net \
--cc=nicolas.ferre@microchip.com \
--cc=nikesh@opensource.cirrus.com \
--cc=npoushin@opensource.cirrus.com \
--cc=patches@opensource.cirrus.com \
--cc=paul@crapouillou.net \
--cc=perex@perex.cz \
--cc=piotrs@opensource.cirrus.com \
--cc=rdunlap@infradead.org \
--cc=rf@opensource.cirrus.com \
--cc=srinivas.kandagatla@linaro.org \
--cc=tglx@linutronix.de \
--cc=tiwai@suse.com \
--cc=zhongjiang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).