From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CFBF606A31C for ; Sat, 28 Nov 2026 17:20:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=lNRs4wRl; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=v7zmCs0R DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=11Mi+fL3w0fj7mLlPaCOBuZ2CzRrFt6hh9UvAMZZPmY=; b=lNRs4wRlMRd2AONb4qv7kRQzab 5wmmLUR0SBqm0miMFm21vrfaD49HXQ9FuKeFRDyolkrdBmsSiNaRqFUm6K5aIusUFF85ib5P+Gp5M +4JE7ixSltgjvRgidP+LXriCOGJ+7guljhkdv3VHBP8F6us/v0wP9KMAYlQcQGWBFTaLgR+QCSdgv it/wDwOSWUMgupb69WOatEKej0aOnJZnwzwre8zdQyu9LvkmB/bk1Rn3xWUxqyQT0+Tkt73uq5uFC 2LI0ne3Ewl1EG0zhWDHqmB1qI4HinqDbvYa9HWEo0Ai4TD/JCLWn28UkELvj2PG1XzRYmA86Zv1xe 6nmaDatQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXM6R-000000010gr-2RW3; Sat, 28 Nov 2026 17:20:47 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXM6O-000000010gO-07Ma for linux-arm-kernel@lists.infradead.org; Sat, 28 Nov 2026 17:20:45 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4a207b02a2cso64767985e9.1 for ; Sat, 28 Nov 2026 09:20:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795886442; x=1796491242; darn=lists.infradead.org; h=content-type:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=11Mi+fL3w0fj7mLlPaCOBuZ2CzRrFt6hh9UvAMZZPmY=; b=v7zmCs0RXEhs87z4TByY/WhRXaoRWAB3WrhEbastiYHqUTMOST57Vz3uqugseM9dZ1 tV/2SJ/ks/LHME83+qSSvG3Aghuh1U61k7J80PpiC1ZKWAJerKKbvOoba69T0+ibC3Ug 9vwg6pLPEBZbSuE1QYehif7E2wgrUi+ma18MmQr1viQliIqKNsJQchVXuGXEx2cci8ZS hI3uyGPsPwg9VgEK2vxnBaJBo96G1WFJ/npDMqUWfwiyW6mSCf5YMkoA5k7qWpSE697I X2SRuaAOsYSrZcLwY1CgI8KoEpLndG8k/qD0cSwEQGGEdvFauXis2Ozg8yJwvJCu10fP 2UmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795886442; x=1796491242; h=content-type:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=11Mi+fL3w0fj7mLlPaCOBuZ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qMRCNSlPtRX8dCiSWSOzDoSIjHj82HES77kyJy4eel2ZJUE5q70DhOsk6r8qOr+h7uQtzk4J0jg objoMr6DDG/CH5YdQOCDuR7ATww72NtEQ5GLjnMDB6ryj81MVENgi7zWAongyghaoIz5vcxdrcn 11a8mkJgOYPKm+wgWGLbiFT+zKxqg+bVGGlqDvraNq5f1tkHiz/j2ira+1ZjzDT2koZgCWOHLGK 8mJsHQq7xAGoBSPED29mT0+MQSFml7MeKOg7Nrs7DuGmuu67LVc2tDZg6DBzEHYbGGVDczB2VKz Tu644xHnT5XV7exfFkJUm1fT4Ws/rRM+nFMmJxPy9L8nQd3vSGF9RnCWOA3P3PcOMMlfzOhTS1L K+WxJ7GKRT0e1x1ye/BgLp65A== X-Received: by 2002:a05:600c:1d03:b0:4bb:6118:4f57 with SMTP id 5b1f17b1804b1-4bb888130cfmr647905425e9.18.1795886441600; Sat, 28 Nov 2026 09:20:41 -0800 (PST) Received: from jernej-laptop.localnet ([2a00:ee2:6a02:9300:bb69:6bcf:1b11:e85b]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbb97e5356sm113082735e9.4.2026.11.28.09.20.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 09:20:40 -0800 (PST) From: Jernej =?UTF-8?B?xaBrcmFiZWM=?= 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@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-sound@vger.kernel.org, Daniel Golle Cc: stable@vger.kernel.org, Marcus Cooper , Philippe Simons , Krzysztof Kozlowski 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 Message-ID: In-Reply-To: <9b134cf8ba90d4524188d4b5977fd1d8335dc751.1795815223.git.daniel@makrotopia.org> References: <9b134cf8ba90d4524188d4b5977fd1d8335dc751.1795815223.git.daniel@makrotopia.org> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261128_092044_133570_E12B891C X-CRM114-Status: GOOD ( 33.12 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Dne petek, 27. november 2026 ob 22:42:44 Srednjeevropski standardni =C4=8Da= s 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 =3D 40, P =3D 5, M0 =3D 2 and > pattern 0xc001eb85 (a fractional N of 40.96) give 24 MHz * 40.96 / 5 / > 2 =3D 98.304 MHz for PLL_AUDIO(4X). Store the rates in front of the post > divider. >=20 > 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. >=20 > Fixes: d0c322b6e4bf ("clk: sunxi-ng: h616: Add sigma-delta modulation set= tings 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 > Cc: Andre Przywara > Cc: Marcus Cooper > Cc: Philippe Simons > Cc: Krzysztof Kozlowski > Signed-off-by: Daniel Golle > --- > 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: >=20 > 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 >=20 > 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. >=20 > 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. >=20 > --- > drivers/clk/sunxi-ng/ccu-sun50i-h616.c | 4 ++-- > sound/soc/sunxi/sun4i-codec.c | 8 ++++++++ > 2 files changed, 10 insertions(+), 2 deletions(-) >=20 > diff --git a/drivers/clk/sunxi-ng/ccu-sun50i-h616.c b/drivers/clk/sunxi-n= g/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 =3D { > * frequencies with less error. > */ > static struct ccu_sdm_setting pll_audio_sdm_table[] =3D { > - { .rate =3D 90316800, .pattern =3D 0xc001288d, .m =3D 3, .n =3D 22 }, > - { .rate =3D 98304000, .pattern =3D 0xc001eb85, .m =3D 5, .n =3D 40 }, > + { .rate =3D 180633600, .pattern =3D 0xc001288d, .m =3D 3, .n =3D 22 }, > + { .rate =3D 196608000, .pattern =3D 0xc001eb85, .m =3D 5, .n =3D 40 }, > }; > =20 > #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; > =20 > /* 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_subst= ream *substream, > if (!clk_freq) > return -EINVAL; > =20 > + if (scodec->double_mod_freq) > + clk_freq *=3D 2; > + > ret =3D 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; > }; > =20 > @@ -2237,6 +2242,7 @@ static const struct sun4i_codec_quirks sun50i_h616_= codec_quirks =3D { > .reg_dac_txdata =3D SUN8I_H3_CODEC_DAC_TXDATA, > .has_reset =3D true, > .playback_only =3D true, > + .double_mod_freq =3D true, > .dma_max_burst =3D SUN4I_DMA_MAX_BURST, > }; > =20 > @@ -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"); > =20 > + scodec->double_mod_freq =3D quirks->double_mod_freq; > + > /* DMA configuration for TX FIFO */ > scodec->playback_dma_data.addr =3D res->start + quirks->reg_dac_txdata; > scodec->playback_dma_data.maxburst =3D quirks->dma_max_burst; >=20