From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795886444; b=US20Mb1ymEM/5PUHYEL+PhicKhzdlug6lYPd+FL6C9Q2S6zhZOEvmA+W7dfP0Or7WdG3 BR6w/FuKKuR0l/jYzE1VVNjZ0VmnsRIFlMpCKC0QhKVbuM2LOZznkWevKT8JQ5YITTfIG k6ePJnpNQSkU7yhlC7jOPyI013UYN6DO7Js4Cafqf4ECgzV3RkTICYLrhpLCKRbGFzHld n9zhF1qh5dsGlbBi7v88sJQqJmzg92lpJ9IMvBLQm5jum6BvUnWOp74RRQRu/w9KBOLIH msC+c/68wGohjGQp9gkI7eBH4i7LDrmgNinlyr7VTXIcZTSUwHRfGSXZx2W29p3lsIQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795886444; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type; bh=11Mi+fL3w0fj7mLlPaCOBuZ2CzRrFt6hh9UvAMZZPmY=; b=d4yKQhQCAEzzUYHZYPP1S/OHTSKL0XLfb9md8mSv4+dMD3E1LMff8NDuIspaGiBaJlUK YgDqSPtv3n/rg1tY+9XN0RIpAkofPjys3cL0Qjk6lowIwcM5B0zPx1oFS4DiQ6ZiZO49L 0pyH3HmfQ4gepIE83cTZHnxgkNVG61s4OvnWQQYmTn9LW7i8Ip9f0QL64ImenTq7SK8Le 6M7i/hpipmtN59A9woDMKExhiGAdvCRsV4IybLGfwSm3fVft7f4/4AZEGs9wZTvCGNCaH DgklWeAsDS/17MSeaUmg+TlbVnE+W/v6BtjuKaHwKLRIy9NmCkMz+WnDpkksFOK7ckw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=JfntTNM6; arc=none smtp.remote-ip=209.85.128.51 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80DDF606A324 for ; Sat, 28 Nov 2026 17:20:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 80DDF606A324 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=JfntTNM6 Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-49d05d51553so62899665e9.2 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=vger.kernel.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=JfntTNM62puMyg6/XYZzBfDuAjSkuaXjKxTE/mByM1mnr2A0KnPQSKInEg7/8aHGM4 Kh+CUsToOTu2/M4U1TO8nWMOhLDy1bsCcCGBavU36PlsuAf+tBd1bqdKkgTBoK1DxwMH 32nBsxu8mXlodve6muMSyE50UBYIPwVQZLJkilTgWGaSTagTo9THm6iEh+WC4y+7e0rE 9qkUdzjXoOeJDujMOpuVnIz3vKun+dbqjq7oORBjuWUMV8iWvz4bX4lt7BUxk2bZ+0yw mtFr+DoKQVVJO60LmymiIkHhPBihusRgjEVzr0MAMs7Mbuh6QOBE8AqH3g9YImxOTO4p Wvqw== 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+fL3w0fj7mLlPaCOBuZ2CzRrFt6hh9UvAMZZPmY=; b=SN9PaGnS/8EcQaILIVdg1cnr6Sh4Ttv/z0nBmOV1BOx891Z7qjQL8btcebDyBcdTO0 dX5jX9PgNGRgFAyA5aS8mFXXt6v02nFWDZphyCZPEoX5Fn3FJXrXXG/wCLPEwMWE8xAv 7wEsxUz7h3L2L0v0y1kJW1h0buAVUmrPk21vof51EeiARfC7HwWhys3Y/EfiuuXJT4CZ dMWg8LafWGLVQQBAXbCMlDGV0RE7yLvPRc93F7MWjq8LZGzdh1RvH/l/QRBtgZe95FP0 7UiBDD05pxasFed0TonYaHvQIltdUzEQYzQrVndtft2kPTqDECQUWCTUIzvO9+IzGcoI DtFg== X-Forwarded-Encrypted: i=1; AL+hErGzgbpmDZoHGE8tj982OZ2timbX00O6IZAtZbzyorjddJZzc55y8Q2lJ9waAl+rvjYfPAdcpAs8qCQ=@vger.kernel.org X-Gm-Message-State: APuU4Z9tCE0AJ4kwmeJtOEBODctEbKZMmZbk8zw+ror8I6SlTd14YZi7 1whsKC18ItZLA4XiTOEX/qJMtjcMTRwUrUBuZhu6QQXr5A2lmTd4E71p X-Gm-Gg: AZFdTZcNFM3bqmjFD+3WYR2Nt6kja0CpK20TrNmz+56b7uLO4FuRQwXKjN8LvpgPdFv ebbuJ+KE5+KWxk1dYJY0gvs680HLwWtCMwuEc0Pfn8PHXcFZyP+NMyWivhizfgmTfqSM1ugpjNj nw2AHZZhP7CeKmiHIzts6p7eTEr8iXsmdpndso/+PIxDf/GdiP9oZSfmBNkZNnTyDXfy3AVMMGx /N3yNhORMuJ3C+x8p8ztBVOC/itylXJPq+D8ZBi9GsjdtFdPyUsNLN6q4jW1UtfRuRu8L6KXdCJ yqWY0jx/UG6Pp9MHK5kfQnEVX9DmbTMfLRk7r0AzOTH/dYS4OvSUe66tgl+hx77fNoAbKZ13xyC JKG6WTD5SDYNKnFl+FJI3kfgnRiGwYF3Fj7NN5TPWUKRzdCRF4vP6WqMt6HlLIlyA1znFB5eF/q lbgHlglXzOQzcpBJfQ/H9r3KD4IJlC7iCbYvf2l+xUVj+m1/cQPakYwCC8cicLT7rRXM3aSVJuG XOSubVmNMn0aPEKwNkgQEbE4PuhZZTziN5vWsSS9iNyrIW74YwIr0w2HwZM/LVakpTfkhvLMbRv udj6ff2QbM3nHob8pdN1WAx08d2GMkjI1BzdcNICE/+oeiYZ9nzjMG5n/+3sD3zH0t5ZZx32c42 IyPVGP0aDk0AmChjv0quhVQH3DtpRnEfmbaaL2uNXyns7+1Yde9iDIn0eQZDgd5X5Wi2LdJDnup KTT2uaaZceiac8RHbOcIoVqab6zKySvhD8+8WOxj9A3TE+QqOYY2QaCJLUzK4VAMiCTewcwuROK E8+zC20x3XpTbMWuJVkaiojFg== 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-Mailing-List: linux-clk@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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