From: "Jernej Škrabec" <jernej.skrabec@gmail.com>
To: Stephen Boyd <sboyd@kernel.org>,
Brian Masney <bmasney+clk@redhat.com>,
Jerome Brunet <jbrunet+clk@baylibre.com>,
Chen-Yu Tsai <wens@kernel.org>,
Samuel Holland <samuel@sholland.org>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>,
bui duc phuc <phucduc.bui@gmail.com>,
Kees Cook <kees+treewide@kernel.org>,
Daniel Golle <daniel@makrotopia.org>,
Ryan Walklin <ryan@testtoast.com>,
Andre Przywara <andre.przywara@arm.com>,
linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev, linux-sound@vger.kernel.org,
Daniel Golle <daniel@makrotopia.org>
Cc: stable@vger.kernel.org, Marcus Cooper <codekipper@gmail.com>,
Philippe Simons <simons.philippe@gmail.com>,
Krzysztof Kozlowski <krzk@kernel.org>
Subject: Re: [PATCH 1/1] clk: sunxi-ng: h616: fix audio PLL and codec clock rates
Date: Sat, 28 Nov 2026 18:20:38 +0100 [thread overview]
Message-ID: <hJTjmTRiQyqIclDed76TBQ@gmail.com> (raw)
In-Reply-To: <9b134cf8ba90d4524188d4b5977fd1d8335dc751.1795815223.git.daniel@makrotopia.org>
Dne petek, 27. november 2026 ob 22:42:44 Srednjeevropski standardni čas je Daniel Golle napisal(a):
> The sigma-delta table of the H616 audio PLL holds the PLL_AUDIO(4X)
> rates of 90.3168 and 98.304 MHz, which already include the M0 output
> divider of 2, and ccu_nm divides the table rate by fixed_post_div once
> more. The PLL and the 4x, 2x and 1x clocks derived from it are therefore
> reported at half their real frequency: N = 40, P = 5, M0 = 2 and
> pattern 0xc001eb85 (a fractional N of 40.96) give 24 MHz * 40.96 / 5 /
> 2 = 98.304 MHz for PLL_AUDIO(4X). Store the rates in front of the post
> divider.
>
> The H616 codec only played at the right speed because of this: its DAC
> needs a module clock of 49.152 MHz for the 48 kHz family and 45.1584 MHz
> for the 44.1 kHz family, and the 24.576 MHz requested by the sun4i-codec
> rate table landed on pll-audio-2x running at 49.152 MHz. Request twice
> the table rate on the H616, in the same change, as either half on its
> own leaves the codec playing at the wrong speed.
>
> Fixes: d0c322b6e4bf ("clk: sunxi-ng: h616: Add sigma-delta modulation settings for audio PLL")
> Fixes: 9155c321a1d0 ("ASoC: sun4i-codec: support allwinner H616 codec")
This patch is correct. However, split it to two different patches, one
for clock and one for audio codec.
Best regards,
Jernej
> Cc: stable@vger.kernel.org
> Cc: Ryan Walklin <ryan@testtoast.com>
> Cc: Andre Przywara <andre.przywara@arm.com>
> Cc: Marcus Cooper <codekipper@gmail.com>
> Cc: Philippe Simons <simons.philippe@gmail.com>
> Cc: Krzysztof Kozlowski <krzk@kernel.org>
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> ---
> Measurements on an H618 (X98H TV box), DAC drain rate from AC_DAC_CNT
> and aplay run time of a 4 s 48 kHz stereo file:
>
> kernel CODEC_1X_CLK real module clock drain run time
> unpatched mux 2X 49.152 MHz 96360/s 4.06 s
> CCU fix only mux 1X 24.576 MHz 48160/s 8.03 s
> CCU fix, 2X mux mux 2X 49.152 MHz 96360/s real time
> this patch mux 2X 49.152 MHz - 4.06 s
>
> With this patch the 44.1 kHz family runs at 45.1584 MHz and also plays
> in real time. Codec streams of either family keep their rate when they
> alternate with streams of the out-of-tree Audio Hub HDMI driver, which
> retunes the PLL between the two settings. A guitar tuner held to
> headphones on the line out read 440 Hz for 60 s sines of 440 Hz at 48
> and at 44.1 kHz, and 880 Hz on the right channel only for a 60 s 880 Hz
> right-channel sine at 48 kHz.
>
> The real rates follow the PLL_AUDIO_CTRL formula of the H616 manual
> (3.3.5.12) from the register contents (0xb9042701 with pattern
> 0xc001eb85 for the 48 kHz family, 0xb9021501 with 0xc001288d for 44.1
> kHz). The same halving made sun4i-spdif run at twice its rate whenever
> the codec had moved the PLL to its sigma-delta setting first (a 4 s
> file played in 2.01 s). With the fix it plays in real time whenever the
> PLL already runs in the rate family of the stream; the spdif clock
> cannot retune the PLL itself, which is a separate problem.
>
> ---
> drivers/clk/sunxi-ng/ccu-sun50i-h616.c | 4 ++--
> sound/soc/sunxi/sun4i-codec.c | 8 ++++++++
> 2 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/clk/sunxi-ng/ccu-sun50i-h616.c b/drivers/clk/sunxi-ng/ccu-sun50i-h616.c
> index 955c614830fae..6af0c1318ccf2 100644
> --- a/drivers/clk/sunxi-ng/ccu-sun50i-h616.c
> +++ b/drivers/clk/sunxi-ng/ccu-sun50i-h616.c
> @@ -223,8 +223,8 @@ static struct ccu_nkmp pll_de_clk = {
> * frequencies with less error.
> */
> static struct ccu_sdm_setting pll_audio_sdm_table[] = {
> - { .rate = 90316800, .pattern = 0xc001288d, .m = 3, .n = 22 },
> - { .rate = 98304000, .pattern = 0xc001eb85, .m = 5, .n = 40 },
> + { .rate = 180633600, .pattern = 0xc001288d, .m = 3, .n = 22 },
> + { .rate = 196608000, .pattern = 0xc001eb85, .m = 5, .n = 40 },
> };
>
> #define SUN50I_H616_PLL_AUDIO_REG 0x078
> diff --git a/sound/soc/sunxi/sun4i-codec.c b/sound/soc/sunxi/sun4i-codec.c
> index 9d5bc3d7b4dfa..759343bec42a8 100644
> --- a/sound/soc/sunxi/sun4i-codec.c
> +++ b/sound/soc/sunxi/sun4i-codec.c
> @@ -333,6 +333,7 @@ struct sun4i_codec {
> struct reset_control *rst;
> struct gpio_desc *gpio_pa;
> struct gpio_desc *gpio_hp;
> + bool double_mod_freq;
>
> /* ADC_FIFOC register is at different offset on different SoCs */
> struct regmap_field *reg_adc_fifoc;
> @@ -661,6 +662,9 @@ static int sun4i_codec_hw_params(struct snd_pcm_substream *substream,
> if (!clk_freq)
> return -EINVAL;
>
> + if (scodec->double_mod_freq)
> + clk_freq *= 2;
> +
> ret = clk_set_rate(scodec->clk_module, clk_freq);
> if (ret)
> return ret;
> @@ -2147,6 +2151,7 @@ struct sun4i_codec_quirks {
> unsigned int reg_adc_rxdata; /* RX FIFO offset for DMA config */
> bool has_reset;
> bool playback_only;
> + bool double_mod_freq;
> u32 dma_max_burst;
> };
>
> @@ -2237,6 +2242,7 @@ static const struct sun4i_codec_quirks sun50i_h616_codec_quirks = {
> .reg_dac_txdata = SUN8I_H3_CODEC_DAC_TXDATA,
> .has_reset = true,
> .playback_only = true,
> + .double_mod_freq = true,
> .dma_max_burst = SUN4I_DMA_MAX_BURST,
> };
>
> @@ -2365,6 +2371,8 @@ static int sun4i_codec_probe(struct platform_device *pdev)
> return dev_err_probe(&pdev->dev, PTR_ERR(scodec->reg_dac_fifoc),
> "Failed to create regmap fields\n");
>
> + scodec->double_mod_freq = quirks->double_mod_freq;
> +
> /* DMA configuration for TX FIFO */
> scodec->playback_dma_data.addr = res->start + quirks->reg_dac_txdata;
> scodec->playback_dma_data.maxburst = quirks->dma_max_burst;
>
next prev parent reply other threads:[~2026-11-28 17:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 21:42 [PATCH 0/1] clk/ASoC: sunxi: fix H616 audio PLL and codec clock rates Daniel Golle
2026-11-27 21:42 ` [PATCH 1/1] clk: sunxi-ng: h616: fix " Daniel Golle
2026-11-28 17:20 ` Jernej Škrabec [this message]
2026-11-28 14:19 ` [PATCH 0/1] clk/ASoC: sunxi: fix H616 " 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=hJTjmTRiQyqIclDed76TBQ@gmail.com \
--to=jernej.skrabec@gmail.com \
--cc=andre.przywara@arm.com \
--cc=bmasney+clk@redhat.com \
--cc=broonie@kernel.org \
--cc=codekipper@gmail.com \
--cc=daniel@makrotopia.org \
--cc=jbrunet+clk@baylibre.com \
--cc=kees+treewide@kernel.org \
--cc=krzk@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=perex@perex.cz \
--cc=phucduc.bui@gmail.com \
--cc=ryan@testtoast.com \
--cc=samuel@sholland.org \
--cc=sboyd@kernel.org \
--cc=simons.philippe@gmail.com \
--cc=stable@vger.kernel.org \
--cc=tiwai@suse.com \
--cc=wens@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.