Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / Atom feed
From: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>
To: alsa-devel@alsa-project.org, patches@opensource.cirrus.com
Cc: Kate Stewart <kstewart@linuxfoundation.org>,
	Maxime Jourdan <mjourdan@baylibre.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
	Kirill Marinushkin <kmarinushkin@birdec.tech>,
	Takashi Iwai <tiwai@suse.com>,
	Paul Cercueil <paul@crapouillou.net>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
	Jerome Brunet <jbrunet@baylibre.com>,
	Anders Roxell <anders.roxell@linaro.org>,
	Ludovic Desroches <ludovic.desroches@microchip.com>,
	linux-arm-kernel@lists.infradead.org,
	Codrin Ciubotariu <codrin.ciubotariu@microchip.com>,
	Charles Keepax <ckeepax@opensource.cirrus.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Piotr Stankiewicz <piotrs@opensource.cirrus.com>,
	Annaliese McDermond <nh6z@nh6z.net>,
	Richard Fitzgerald <rf@opensource.cirrus.com>,
	Mark Brown <broonie@kernel.org>,
	Nariman Poushin <npoushin@opensource.cirrus.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Jaroslav Kysela <perex@perex.cz>,
	zhong jiang <zhongjiang@huawei.com>,
	Allison Randal <allison@lohutok.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Nikesh Oswal <nikesh@opensource.cirrus.com>,
	linux-kernel@vger.kernel.org, Enrico Weigelt <info@metux.net>
Subject: [PATCH v2 3/4] ASoC: wm8904: automatically choose clock source
Date: Sun, 25 Aug 2019 14:17:37 +0200
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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply index

Thread overview: 6+ 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-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 publically 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=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

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/1 linux-arm-kernel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org
	public-inbox-index linux-arm-kernel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git