* [PATCH v2 1/3] ASoC: nau8822: move nau8822_set_dai_sysclk()
2024-06-13 8:46 [PATCH v2 0/3] ASoC: nau8822: add MCLK support Andrejs Cainikovs
@ 2024-06-13 8:46 ` Andrejs Cainikovs
2024-06-13 8:46 ` [PATCH v2 2/3] ASoC: nau8822: set NAU8822_REFIMP_80K only once Andrejs Cainikovs
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Andrejs Cainikovs @ 2024-06-13 8:46 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai
Cc: linux-sound, linux-kernel, Andrejs Cainikovs
From: Andrejs Cainikovs <andrejs.cainikovs@toradex.com>
Next commit in series makes a change which calls nau8822_set_pll() from
nau8822_set_dai_sysclk(). Moving latter after the former would avoid a
forward declaration, and this is exactly what this change does.
Signed-off-by: Andrejs Cainikovs <andrejs.cainikovs@toradex.com>
---
sound/soc/codecs/nau8822.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/sound/soc/codecs/nau8822.c b/sound/soc/codecs/nau8822.c
index e6909e64dfa3..a6741bda6a9e 100644
--- a/sound/soc/codecs/nau8822.c
+++ b/sound/soc/codecs/nau8822.c
@@ -612,20 +612,6 @@ static const struct snd_soc_dapm_route nau8822_dapm_routes[] = {
{"Right DAC", NULL, "Digital Loopback"},
};
-static int nau8822_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
- unsigned int freq, int dir)
-{
- struct snd_soc_component *component = dai->component;
- struct nau8822 *nau8822 = snd_soc_component_get_drvdata(component);
-
- nau8822->div_id = clk_id;
- nau8822->sysclk = freq;
- dev_dbg(component->dev, "master sysclk %dHz, source %s\n", freq,
- clk_id == NAU8822_CLK_PLL ? "PLL" : "MCLK");
-
- return 0;
-}
-
static int nau8822_calc_pll(unsigned int pll_in, unsigned int fs,
struct nau8822_pll *pll_param)
{
@@ -782,6 +768,20 @@ static int nau8822_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
return 0;
}
+static int nau8822_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
+ unsigned int freq, int dir)
+{
+ struct snd_soc_component *component = dai->component;
+ struct nau8822 *nau8822 = snd_soc_component_get_drvdata(component);
+
+ nau8822->div_id = clk_id;
+ nau8822->sysclk = freq;
+ dev_dbg(component->dev, "master sysclk %dHz, source %s\n", freq,
+ clk_id == NAU8822_CLK_PLL ? "PLL" : "MCLK");
+
+ return 0;
+}
+
static int nau8822_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
{
struct snd_soc_component *component = dai->component;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v2 2/3] ASoC: nau8822: set NAU8822_REFIMP_80K only once
2024-06-13 8:46 [PATCH v2 0/3] ASoC: nau8822: add MCLK support Andrejs Cainikovs
2024-06-13 8:46 ` [PATCH v2 1/3] ASoC: nau8822: move nau8822_set_dai_sysclk() Andrejs Cainikovs
@ 2024-06-13 8:46 ` Andrejs Cainikovs
2024-06-13 8:46 ` [PATCH v2 3/3] ASoC: nau8822: add MCLK support Andrejs Cainikovs
2024-06-23 17:21 ` [PATCH v2 0/3] " Mark Brown
3 siblings, 0 replies; 5+ messages in thread
From: Andrejs Cainikovs @ 2024-06-13 8:46 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai
Cc: linux-sound, linux-kernel, Andrejs Cainikovs, Emanuele Ghidoli
From: Andrejs Cainikovs <andrejs.cainikovs@toradex.com>
Following bias state machine logic this bit is set twice before playback.
This change makes sure this bit set is set only once.
Signed-off-by: Andrejs Cainikovs <andrejs.cainikovs@toradex.com>
Suggested-by: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>
---
sound/soc/codecs/nau8822.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sound/soc/codecs/nau8822.c b/sound/soc/codecs/nau8822.c
index a6741bda6a9e..5f9f0953aa2f 100644
--- a/sound/soc/codecs/nau8822.c
+++ b/sound/soc/codecs/nau8822.c
@@ -942,6 +942,8 @@ static int nau8822_set_bias_level(struct snd_soc_component *component,
{
switch (level) {
case SND_SOC_BIAS_ON:
+ break;
+
case SND_SOC_BIAS_PREPARE:
snd_soc_component_update_bits(component,
NAU8822_REG_POWER_MANAGEMENT_1,
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v2 3/3] ASoC: nau8822: add MCLK support
2024-06-13 8:46 [PATCH v2 0/3] ASoC: nau8822: add MCLK support Andrejs Cainikovs
2024-06-13 8:46 ` [PATCH v2 1/3] ASoC: nau8822: move nau8822_set_dai_sysclk() Andrejs Cainikovs
2024-06-13 8:46 ` [PATCH v2 2/3] ASoC: nau8822: set NAU8822_REFIMP_80K only once Andrejs Cainikovs
@ 2024-06-13 8:46 ` Andrejs Cainikovs
2024-06-23 17:21 ` [PATCH v2 0/3] " Mark Brown
3 siblings, 0 replies; 5+ messages in thread
From: Andrejs Cainikovs @ 2024-06-13 8:46 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai
Cc: linux-sound, linux-kernel, Andrejs Cainikovs
From: Andrejs Cainikovs <andrejs.cainikovs@toradex.com>
This change adds MCLK clock handling directly within driver.
When used in combination with simple-audio-card, and mclk-fs is set,
simple-audio-card will change MCLK frequency before configuring PLL.
In some cases, however, MCLK reference clock should be static (see [1]),
which means it needs to be moved away from simple-audio-card.
[1]: https://lore.kernel.org/all/ZfBdxrzX3EnPuGOn@ediswmail9.ad.cirrus.com/
Signed-off-by: Andrejs Cainikovs <andrejs.cainikovs@toradex.com>
---
sound/soc/codecs/nau8822.c | 48 ++++++++++++++++++++++++++++++++++----
sound/soc/codecs/nau8822.h | 1 +
2 files changed, 45 insertions(+), 4 deletions(-)
diff --git a/sound/soc/codecs/nau8822.c b/sound/soc/codecs/nau8822.c
index 5f9f0953aa2f..e1cbaf8a944d 100644
--- a/sound/soc/codecs/nau8822.c
+++ b/sound/soc/codecs/nau8822.c
@@ -14,6 +14,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>
@@ -773,11 +774,26 @@ static int nau8822_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
{
struct snd_soc_component *component = dai->component;
struct nau8822 *nau8822 = snd_soc_component_get_drvdata(component);
+ unsigned long mclk_freq;
nau8822->div_id = clk_id;
nau8822->sysclk = freq;
+
+ if (nau8822->mclk) {
+ mclk_freq = clk_get_rate(nau8822->mclk);
+ if (mclk_freq != freq) {
+ int ret = nau8822_set_pll(dai, NAU8822_CLK_MCLK,
+ NAU8822_CLK_MCLK, mclk_freq, freq);
+ if (ret) {
+ dev_err(component->dev, "Failed to set PLL\n");
+ return ret;
+ }
+ nau8822->div_id = NAU8822_CLK_PLL;
+ }
+ }
+
dev_dbg(component->dev, "master sysclk %dHz, source %s\n", freq,
- clk_id == NAU8822_CLK_PLL ? "PLL" : "MCLK");
+ nau8822->div_id == NAU8822_CLK_PLL ? "PLL" : "MCLK");
return 0;
}
@@ -848,7 +864,7 @@ static int nau8822_hw_params(struct snd_pcm_substream *substream,
{
struct snd_soc_component *component = dai->component;
struct nau8822 *nau8822 = snd_soc_component_get_drvdata(component);
- int val_len = 0, val_rate = 0;
+ int div = 0, val_len = 0, val_rate = 0;
unsigned int ctrl_val, bclk_fs, bclk_div;
/* make BCLK and LRC divide configuration if the codec as master. */
@@ -915,8 +931,10 @@ static int nau8822_hw_params(struct snd_pcm_substream *substream,
/* If the master clock is from MCLK, provide the runtime FS for driver
* to get the master clock prescaler configuration.
*/
- if (nau8822->div_id == NAU8822_CLK_MCLK)
- nau8822_config_clkdiv(dai, 0, params_rate(params));
+ if (nau8822->div_id != NAU8822_CLK_MCLK)
+ div = nau8822->pll.mclk_scaler;
+
+ nau8822_config_clkdiv(dai, div, params_rate(params));
return 0;
}
@@ -940,17 +958,34 @@ static int nau8822_mute(struct snd_soc_dai *dai, int mute, int direction)
static int nau8822_set_bias_level(struct snd_soc_component *component,
enum snd_soc_bias_level level)
{
+ struct nau8822 *nau8822 = snd_soc_component_get_drvdata(component);
+
switch (level) {
case SND_SOC_BIAS_ON:
break;
case SND_SOC_BIAS_PREPARE:
+ if (nau8822->mclk &&
+ snd_soc_component_get_bias_level(component) != SND_SOC_BIAS_ON) {
+ int ret = clk_prepare_enable(nau8822->mclk);
+
+ if (ret) {
+ dev_err(component->dev,
+ "Failed to enable MCLK: %d\n", ret);
+ return ret;
+ }
+ }
+
snd_soc_component_update_bits(component,
NAU8822_REG_POWER_MANAGEMENT_1,
NAU8822_REFIMP_MASK, NAU8822_REFIMP_80K);
break;
case SND_SOC_BIAS_STANDBY:
+ if (nau8822->mclk &&
+ snd_soc_component_get_bias_level(component) != SND_SOC_BIAS_OFF)
+ clk_disable_unprepare(nau8822->mclk);
+
snd_soc_component_update_bits(component,
NAU8822_REG_POWER_MANAGEMENT_1,
NAU8822_IOBUF_EN | NAU8822_ABIAS_EN,
@@ -1127,6 +1162,11 @@ static int nau8822_i2c_probe(struct i2c_client *i2c)
}
i2c_set_clientdata(i2c, nau8822);
+ nau8822->mclk = devm_clk_get_optional(&i2c->dev, "mclk");
+ if (IS_ERR(nau8822->mclk))
+ return dev_err_probe(&i2c->dev, PTR_ERR(nau8822->mclk),
+ "Error getting mclk\n");
+
nau8822->regmap = devm_regmap_init_i2c(i2c, &nau8822_regmap_config);
if (IS_ERR(nau8822->regmap)) {
ret = PTR_ERR(nau8822->regmap);
diff --git a/sound/soc/codecs/nau8822.h b/sound/soc/codecs/nau8822.h
index 6ecd46e45923..13fe0a091e9e 100644
--- a/sound/soc/codecs/nau8822.h
+++ b/sound/soc/codecs/nau8822.h
@@ -215,6 +215,7 @@ struct nau8822_pll {
struct nau8822 {
struct device *dev;
struct regmap *regmap;
+ struct clk *mclk;
struct nau8822_pll pll;
int sysclk;
int div_id;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2 0/3] ASoC: nau8822: add MCLK support
2024-06-13 8:46 [PATCH v2 0/3] ASoC: nau8822: add MCLK support Andrejs Cainikovs
` (2 preceding siblings ...)
2024-06-13 8:46 ` [PATCH v2 3/3] ASoC: nau8822: add MCLK support Andrejs Cainikovs
@ 2024-06-23 17:21 ` Mark Brown
3 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2024-06-23 17:21 UTC (permalink / raw)
To: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Andrejs Cainikovs
Cc: linux-sound, linux-kernel, Andrejs Cainikovs
On Thu, 13 Jun 2024 10:46:49 +0200, Andrejs Cainikovs wrote:
> This change adds local MCLK handling, which would cover a case when a
> reference audio clock is present in a system, but is not allowed to be
> changed, see [1].
>
> [1]: https://lore.kernel.org/all/ZfBdxrzX3EnPuGOn@ediswmail9.ad.cirrus.com/
>
> v1:
> - https://lore.kernel.org/all/20240409121719.337709-1-andrejs.cainikovs@gmail.com/
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/3] ASoC: nau8822: move nau8822_set_dai_sysclk()
commit: 9292013bd3738bd00ee78bf1705620a9881031b5
[2/3] ASoC: nau8822: set NAU8822_REFIMP_80K only once
commit: 9c3b21cc8528d52321c66236c3b794300c78d9e6
[3/3] ASoC: nau8822: add MCLK support
commit: 2604faa7b71291b0ccd17f8d6009f3ff6dae287b
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 5+ messages in thread