Devicetree
 help / color / mirror / Atom feed
From: Mehmet Fide <mehmet.fide@gmail.com>
To: Mark Brown <broonie@kernel.org>, Liam Girdwood <lgirdwood@gmail.com>
Cc: "Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>, "David Lin" <CTLIN0@nuvoton.com>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Peter Rosin" <peda@lysator.liu.se>,
	"Martin Povišer" <povik+lin@cutebit.org>,
	linux-sound@vger.kernel.org, devicetree@vger.kernel.org,
	patches@opensource.cirrus.com, asahi@lists.linux.dev,
	linux-kernel@vger.kernel.org, mehmet.fide@screeningeagle.com
Subject: [PATCH 7/7] ASoC: nau8810: add MCLK support
Date: Thu,  3 Dec 2026 13:47:33 +0100	[thread overview]
Message-ID: <20261203124733.2101884-8-mehmet.fide@gmail.com> (raw)
In-Reply-To: <20261203124733.2101884-1-mehmet.fide@gmail.com>

From: Mehmet Fide <mehmet.fide@screeningeagle.com>

The codec needs an internal clock of 256 * fs, which the prescalers can
only divide from MCLK. From 25 MHz, 48 kHz and 44.1 kHz both play at
48.8 kHz.

Handle MCLK in the driver as nau8822 does: when the system clock asked
for with mclk-fs differs from MCLK, make it with the PLL. MCLK is
enabled while the codec is out of standby.

Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
 sound/soc/codecs/nau8810.c | 38 +++++++++++++++++++++++++++++++++++++-
 sound/soc/codecs/nau8810.h |  1 +
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/nau8810.c b/sound/soc/codecs/nau8810.c
index a27fa63a2887..311dfa8eea74 100644
--- a/sound/soc/codecs/nau8810.c
+++ b/sound/soc/codecs/nau8810.c
@@ -13,6 +13,7 @@
 #include <linux/moduleparam.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/i2c.h>
@@ -608,11 +609,26 @@ static int nau8810_set_sysclk(struct snd_soc_dai *dai,
 {
 	struct snd_soc_component *component = dai->component;
 	struct nau8810 *nau8810 = snd_soc_component_get_drvdata(component);
+	unsigned long mclk_freq;
 
 	nau8810->clk_id = clk_id;
 	nau8810->sysclk = freq;
+
+	if (nau8810->mclk) {
+		mclk_freq = clk_get_rate(nau8810->mclk);
+		if (mclk_freq != freq) {
+			int ret = nau8810_set_pll(dai, NAU8810_SCLK_MCLK,
+				NAU8810_SCLK_MCLK, mclk_freq, freq);
+			if (ret) {
+				dev_err(component->dev, "Failed to set PLL\n");
+				return ret;
+			}
+			nau8810->clk_id = NAU8810_SCLK_PLL;
+		}
+	}
+
 	dev_dbg(nau8810->dev, "master sysclk %dHz, source %s\n",
-		freq, clk_id == NAU8810_SCLK_PLL ? "PLL" : "MCLK");
+		freq, nau8810->clk_id == NAU8810_SCLK_PLL ? "PLL" : "MCLK");
 
 	return 0;
 }
@@ -803,11 +819,26 @@ static int nau8810_set_bias_level(struct snd_soc_component *component,
 		break;
 
 	case SND_SOC_BIAS_PREPARE:
+		if (nau8810->mclk &&
+		    snd_soc_dapm_get_bias_level(dapm) != SND_SOC_BIAS_ON) {
+			int ret = clk_prepare_enable(nau8810->mclk);
+
+			if (ret) {
+				dev_err(nau8810->dev,
+					"Failed to enable MCLK: %d\n", ret);
+				return ret;
+			}
+		}
+
 		regmap_update_bits(map, NAU8810_REG_POWER1,
 			NAU8810_REFIMP_MASK, NAU8810_REFIMP_80K);
 		break;
 
 	case SND_SOC_BIAS_STANDBY:
+		if (nau8810->mclk &&
+		    snd_soc_dapm_get_bias_level(dapm) != SND_SOC_BIAS_OFF)
+			clk_disable_unprepare(nau8810->mclk);
+
 		regmap_update_bits(map, NAU8810_REG_POWER1,
 			NAU8810_IOBUF_EN | NAU8810_ABIAS_EN,
 			NAU8810_IOBUF_EN | NAU8810_ABIAS_EN);
@@ -922,6 +953,11 @@ static int nau8810_i2c_probe(struct i2c_client *i2c)
 		return PTR_ERR(nau8810->regmap);
 	nau8810->dev = dev;
 
+	nau8810->mclk = devm_clk_get_optional(dev, "mclk");
+	if (IS_ERR(nau8810->mclk))
+		return dev_err_probe(dev, PTR_ERR(nau8810->mclk),
+				     "Error getting MCLK\n");
+
 	regmap_write(nau8810->regmap, NAU8810_REG_RESET, 0x00);
 
 	return devm_snd_soc_register_component(dev,
diff --git a/sound/soc/codecs/nau8810.h b/sound/soc/codecs/nau8810.h
index 33cf0d599c17..c0f81402f293 100644
--- a/sound/soc/codecs/nau8810.h
+++ b/sound/soc/codecs/nau8810.h
@@ -280,6 +280,7 @@ struct nau8810_pll {
 struct nau8810 {
 	struct device *dev;
 	struct regmap *regmap;
+	struct clk *mclk;
 	struct nau8810_pll pll;
 	int sysclk;
 	int clk_id;
-- 
2.56.0


  parent reply	other threads:[~2026-12-03 12:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 12:47 [PATCH 0/7] ASoC: nau8810: add MCLK support Mehmet Fide
2026-12-03 12:47 ` [PATCH 1/7] ASoC: dt-bindings: nau8810: Add MCLK clock Mehmet Fide
2026-12-03 12:57   ` sashiko-bot
2026-12-03 12:47 ` [PATCH 2/7] ASoC: nau8810: move nau8810_set_sysclk() Mehmet Fide
2026-12-03 12:47 ` [PATCH 3/7] ASoC: nau8810: set NAU8810_REFIMP_80K only once Mehmet Fide
2026-12-03 12:47 ` [PATCH 4/7] ASoC: nau8810: Lower debug print priority Mehmet Fide
2026-12-03 12:47 ` [PATCH 5/7] ASoC: nau8810: Do not configure the PLL if freq_out is zero Mehmet Fide
2026-12-03 12:47 ` [PATCH 6/7] ASoC: nau8810: Don't reconfigure PLL to the same values Mehmet Fide
2026-12-03 12:47 ` Mehmet Fide [this message]
2026-12-03 13:21   ` [PATCH 7/7] ASoC: nau8810: add MCLK support sashiko-bot

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=20261203124733.2101884-8-mehmet.fide@gmail.com \
    --to=mehmet.fide@gmail.com \
    --cc=CTLIN0@nuvoton.com \
    --cc=asahi@lists.linux.dev \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=mehmet.fide@screeningeagle.com \
    --cc=nuno.sa@analog.com \
    --cc=patches@opensource.cirrus.com \
    --cc=peda@lysator.liu.se \
    --cc=perex@perex.cz \
    --cc=povik+lin@cutebit.org \
    --cc=robh@kernel.org \
    --cc=tiwai@suse.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