* [PATCH 0/1] clk/ASoC: sunxi: fix H616 audio PLL and codec clock rates @ 2026-11-27 21:42 Daniel Golle 2026-11-27 21:42 ` [PATCH 1/1] clk: sunxi-ng: h616: fix " Daniel Golle 2026-11-28 14:19 ` [PATCH 0/1] clk/ASoC: sunxi: fix H616 " Mark Brown 0 siblings, 2 replies; 4+ messages in thread From: Daniel Golle @ 2026-11-27 21:42 UTC (permalink / raw) To: Stephen Boyd, Brian Masney, Jerome Brunet, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai, bui duc phuc, Kees Cook, Daniel Golle, Ryan Walklin, Andre Przywara, linux-clk, linux-arm-kernel, linux-sunxi, linux-sound Cc: stable, Marcus Cooper, Philippe Simons, Krzysztof Kozlowski The H616 CCU reports the audio PLL at half its real frequency since its sigma-delta table was added, and the H616 codec support was tuned on top of that, so the two errors cancel for the analogue codec. Other users of the audio PLL run at the wrong rate: sun4i-spdif plays at twice the requested rate once the codec has moved the PLL to its sigma-delta setting, and an I2S driver for the Audio Hub that asks for 24.576 MHz gets 49.152 MHz. The fix is a single patch spanning clk and ASoC. Correcting the CCU alone halves the codec rate, and doubling the codec request alone makes the codec run at twice its rate on the current CCU, so a two-patch series would leave one commit with broken audio for bisection and for stable backports, which need both halves together. I would suggest the patch goes through the sunxi clk tree with an ack from Mark for the sun4i-codec hunk; taking it through ASoC with an ack for the CCU hunk works just as well. Tool use: the root cause analysis, the patch and the text of both mails were produced with an AI coding assistant (Claude Code) during a longer session, which was asked to bring up HDMI audio on an H618 TV box, then to find out why the analogue codec played at half speed after the CCU correction, and to prepare this fix. It measured the PLL, the module clock and the DAC drain rate on the hardware with devmem and the AC_DAC_CNT counter, and checked them against the PLL formula of the H616 manual and against the vendor-derived H616 codec driver carried by Armbian, which requests twice the table rate. The measurements in the notes of the patch come from those runs; pitch and channel order were checked by ear. Daniel Golle (1): clk: sunxi-ng: h616: fix audio PLL and codec clock rates drivers/clk/sunxi-ng/ccu-sun50i-h616.c | 4 ++-- sound/soc/sunxi/sun4i-codec.c | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f -- 2.56.1 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/1] clk: sunxi-ng: h616: fix audio PLL and codec clock rates 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 ` Daniel Golle 2026-11-28 17:20 ` Jernej Škrabec 2026-11-28 14:19 ` [PATCH 0/1] clk/ASoC: sunxi: fix H616 " Mark Brown 1 sibling, 1 reply; 4+ messages in thread From: Daniel Golle @ 2026-11-27 21:42 UTC (permalink / raw) To: Stephen Boyd, Brian Masney, Jerome Brunet, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai, bui duc phuc, Kees Cook, Daniel Golle, Ryan Walklin, Andre Przywara, linux-clk, linux-arm-kernel, linux-sunxi, linux-sound Cc: stable, Marcus Cooper, Philippe Simons, Krzysztof Kozlowski 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") 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; -- 2.56.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] clk: sunxi-ng: h616: fix audio PLL and codec clock rates 2026-11-27 21:42 ` [PATCH 1/1] clk: sunxi-ng: h616: fix " Daniel Golle @ 2026-11-28 17:20 ` Jernej Škrabec 0 siblings, 0 replies; 4+ messages in thread From: Jernej Škrabec @ 2026-11-28 17:20 UTC (permalink / raw) To: Stephen Boyd, Brian Masney, Jerome Brunet, Chen-Yu Tsai, Samuel Holland, Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai, bui duc phuc, Kees Cook, Daniel Golle, Ryan Walklin, Andre Przywara, linux-clk, linux-arm-kernel, linux-sunxi, linux-sound, Daniel Golle Cc: stable, Marcus Cooper, Philippe Simons, Krzysztof Kozlowski 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; > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 0/1] clk/ASoC: sunxi: fix H616 audio PLL and codec clock rates 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 14:19 ` Mark Brown 1 sibling, 0 replies; 4+ messages in thread From: Mark Brown @ 2026-11-28 14:19 UTC (permalink / raw) To: Daniel Golle Cc: Stephen Boyd, Brian Masney, Jerome Brunet, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Liam Girdwood, Jaroslav Kysela, Takashi Iwai, bui duc phuc, Kees Cook, Ryan Walklin, Andre Przywara, linux-clk, linux-arm-kernel, linux-sunxi, linux-sound, stable, Marcus Cooper, Philippe Simons, Krzysztof Kozlowski [-- Attachment #1: Type: text/plain, Size: 830 bytes --] On Fri, Nov 27, 2026 at 09:42:18PM +0000, Daniel Golle wrote: > The H616 CCU reports the audio PLL at half its real frequency since its > sigma-delta table was added, and the H616 codec support was tuned on > top of that, so the two errors cancel for the analogue codec. Other > users of the audio PLL run at the wrong rate: sun4i-spdif plays at > twice the requested rate once the codec has moved the PLL to its > sigma-delta setting, and an I2S driver for the Audio Hub that asks for > 24.576 MHz gets 49.152 MHz. Please don't send cover letters for single patches, if there is anything that needs saying put it in the changelog of the patch or after the --- if it's administrative stuff. This reduces mail volume and ensures that any important information is recorded in the changelog rather than being lost. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-28 17:20 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 2026-11-28 14:19 ` [PATCH 0/1] clk/ASoC: sunxi: fix H616 " Mark Brown
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox