[PATCH v3 0/2] Add master clock handling for nau8824
nau8824 has external MCLK pin. So add enable/disable external clock management.
Signed-off-by: Maxim Kochetkov fido_max@inbox.ru --- Changes in v3: - move bindings before their users - use devm_clk_get_optional() - let clock API care about NULL ptr
Changes in v2: - move the devm_clk_get() to the nau8824_read_device()
Maxim Kochetkov (2): ASoC: dt-bindings: nau8824: Add master clock handling ASoC: codecs: nau8824: Add master clock handling
.../bindings/sound/nuvoton,nau8824.yaml | 8 +++++++ sound/soc/codecs/nau8824.c | 21 +++++++++++++++++-- sound/soc/codecs/nau8824.h | 1 + 3 files changed, 28 insertions(+), 2 deletions(-)
Use master clock "mclk" if provided through device tree.
Signed-off-by: Maxim Kochetkov fido_max@inbox.ru Reviewed-by: Krzysztof Kozlowski krzysztof.kozlowski@linaro.org --- .../devicetree/bindings/sound/nuvoton,nau8824.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/Documentation/devicetree/bindings/sound/nuvoton,nau8824.yaml b/Documentation/devicetree/bindings/sound/nuvoton,nau8824.yaml index 3dbf438c3841..232dc16a94a3 100644 --- a/Documentation/devicetree/bindings/sound/nuvoton,nau8824.yaml +++ b/Documentation/devicetree/bindings/sound/nuvoton,nau8824.yaml @@ -23,6 +23,14 @@ properties: '#sound-dai-cells': const: 0
+ clocks: + items: + - description: The phandle of the master clock to the CODEC + + clock-names: + items: + - const: mclk + interrupts: maxItems: 1
Use master clock "mclk" if provided through device tree.
Signed-off-by: Maxim Kochetkov fido_max@inbox.ru --- sound/soc/codecs/nau8824.c | 21 +++++++++++++++++++-- sound/soc/codecs/nau8824.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/sound/soc/codecs/nau8824.c b/sound/soc/codecs/nau8824.c index f92b95b21cae..12540397fd4d 100644 --- a/sound/soc/codecs/nau8824.c +++ b/sound/soc/codecs/nau8824.c @@ -506,6 +506,7 @@ static int system_clock_control(struct snd_soc_dapm_widget *w, struct regmap *regmap = nau8824->regmap; unsigned int value; bool clk_fll, error; + int ret;
if (SND_SOC_DAPM_EVENT_OFF(event)) { dev_dbg(nau8824->dev, "system clock control : POWER OFF\n"); @@ -520,8 +521,15 @@ static int system_clock_control(struct snd_soc_dapm_widget *w, } else { nau8824_config_sysclk(nau8824, NAU8824_CLK_DIS, 0); } + + clk_disable_unprepare(nau8824->mclk); } else { dev_dbg(nau8824->dev, "system clock control : POWER ON\n"); + + ret = clk_prepare_enable(nau8824->mclk); + if (ret) + return ret; + /* Check the clock source setting is proper or not * no matter the source is from FLL or MCLK. */ @@ -563,16 +571,21 @@ static int dmic_clock_control(struct snd_soc_dapm_widget *w, struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component); int src; + unsigned int freq; + + freq = clk_get_rate(nau8824->mclk); + if (!freq) + freq = nau8824->fs * 256;
/* The DMIC clock is gotten from system clock (256fs) divided by * DMIC_SRC (1, 2, 4, 8, 16, 32). The clock has to be equal or * less than 3.072 MHz. */ for (src = 0; src < 5; src++) { - if ((0x1 << (8 - src)) * nau8824->fs <= DMIC_CLK) + if (freq / (0x1 << src) <= DMIC_CLK) break; } - dev_dbg(nau8824->dev, "dmic src %d for mclk %d\n", src, nau8824->fs * 256); + dev_dbg(nau8824->dev, "dmic src %d for mclk %d\n", src, freq); regmap_update_bits(nau8824->regmap, NAU8824_REG_CLK_DIVIDER, NAU8824_CLK_DMIC_SRC_MASK, (src << NAU8824_CLK_DMIC_SRC_SFT));
@@ -1871,6 +1884,10 @@ static int nau8824_read_device_properties(struct device *dev, if (ret) nau8824->jack_eject_debounce = 1;
+ nau8824->mclk = devm_clk_get_optional(dev, "mclk"); + if (IS_ERR(nau8824->mclk)) + return PTR_ERR(nau8824->mclk); + return 0; }
diff --git a/sound/soc/codecs/nau8824.h b/sound/soc/codecs/nau8824.h index 5fcfc43dfc85..d8e19515133c 100644 --- a/sound/soc/codecs/nau8824.h +++ b/sound/soc/codecs/nau8824.h @@ -434,6 +434,7 @@ struct nau8824 { struct snd_soc_jack *jack; struct work_struct jdet_work; struct semaphore jd_sem; + struct clk *mclk; int fs; int irq; int resume_lock;
On Tue, 02 Jul 2024 00:16:20 +0300, Maxim Kochetkov wrote:
nau8824 has external MCLK pin. So add enable/disable external clock management.
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/2] ASoC: dt-bindings: nau8824: Add master clock handling commit: fcad7177eb7854ce244ce863c82583d8a6ce5952 [2/2] ASoC: codecs: nau8824: Add master clock handling commit: 1d3724c92dc20584f76033347384b8c1536480af
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
participants (2)
-
Mark Brown
-
Maxim Kochetkov