From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795886443; b=y+Hr/SDxBrdyBICO0vHkYYHNVMJtwb8XrUpVoCUs1r1PzkHXcN3EBiM/c4k96sDJ2SA2 fs8U7PWd/upnbuLCTCsD9ZuG/EGO5Rz8Bssklr7qck9z+kQZEN84/guPyB3RgV9kaMcz1 IyLCqnXLFc9RSrP2TYejIQDzaWnZZan0zHK+KAFWTSEuyZyyzH3NKgP9bpBsAHtmHCZB7 X+HVs/2bCuadaVI7twvQ7FBq02iur4peg1GZpeZCOanMksPWRCfL3sVaNZb3X7djZYkPd wotX6gc7YMBeqQUsEtatf4eN0oE8O/Dn23ak+OZtwsAZomJ1le/DE6zJc9xmf6VX9rQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795886443; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: 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=fOfiKudh7fhMYVFOUwthgs6VucpxOs6nBVfpyJY2/nwgHrxFrytf016D8ju0iO1IMSBI Qc58AubUu7HDuaNf2LaW0XNzxwQXIAnG5adVd90Cs8aBGqXhkBVW6sp+BkNK2lVhPm0Bb hz5XvUyplskh9BBvfoo27xDvPXAFtUqVi4AJriFJkmDHMrI8fBcS+LfDueATwtMmAHY5M feP7RWHE9odk/4j3tGijAIQfnWvHnKxiilPLnD605m7f2sMnNxAKe7M4yQAdiAmT0kgif IM6YSVomoGc+1/DeoBTZcTap/j1np/lmVMYDYY7vBIsJ1zsfFPfE946hTJWF7gf0quQ== 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.42 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 835E4606A325 for ; Sat, 28 Nov 2026 17:20:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 835E4606A325 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-f42.google.com with SMTP id 5b1f17b1804b1-4a35a60499eso69712485e9.0 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=PY2d0xBM4pNEuBBlNvqk35bPYZncIc7iW7YwzJN6lzh2rwJ+R1QUiCrPyAmyyrCLyc Ueh46Hjk3oMNdp7ISgGUF8ips4Jwq5xw94jrav2HP7m0veifPHnH4HlmAaec+5w+KBnW rb5mTE5tf6hRdra4SyKhG2WVmd1MgnKyLnPlFQyZ1XNk1yFGZx5fknl3NcZx861bk9n5 m36rOOk0Ht+nTu3Qx2GXXQi8Xs+Qij3tGYbyvmbCQUe+tJ6ZtUDPx5QDuz3bNQApjzMP oXaKmQhrEDTasDZpNztl4dv11B76hGVZDzLLVPlYS/iUktHARQG82+H96GJ4PyIlesqI JolQ== X-Gm-Message-State: APuU4Z+i/7Nda9j553/oSUyR2/jkD3jPpTvKGa9/VU/Wp1xAKbZnxHZ9 mksRB35YsHMIaUH5T3Gok6nNQFSFeS22Pn44M3s/CehchpihSA+bGHIa X-Gm-Gg: AZFdTZdo0/pYzGnLlVPZYJQqrNpWsiR/ieuSZz2sudKeNxQ3QwCUxGLk1Q87zB6xBTr nIiOi4s0bTWeTczBw7F6sS5p61eRVXWcOTrolyVv3SBSpl2QySm6Y67TK/scBJ/sT/UV2sgtcn3 ryq8dkdb3cpsk/wnTxJbAW9gLW3keJQ4Gx1OEDRCqbZMwm7bCIcvCCGx7WXsfzGTnOUcqVGbZzd ly4DiZEKJJgSRBR8qxSRlQl1KDb7F/h6tJISSZxgzRlTxIrYKS9U9fA4OWTT05r33qMGvFCFJTx eJ8x6pitWNUtf/SAfCNLtq2bPSi8SB7DyK8mMaYtbl4Ogk8v2gcJpPHqv8bREQEsI1ArkU7vAhR VFk2LQi7jkbKSWJQBR2NcNz5jt6BYWY/iQcZzEDoKvyHR4chq/nPyskIveSh5khmfMLU1UqEyVG qUqrgTRW/QyyUELjkt79e3fZMkkDd3nA7frkTcqV3U5741KhQ4xneeFNJPtw/RiqPF+kbcNTjhK wbW6LnuaSqTBQo9+WkoLBRCpByanBP4d7UHPxgpHbBiqi8HGBPuXBfJj23fd8PYlFuV8WCswwHw HMEPQtOFaBCsqCIqyPvN8S/q0RksAWXvxIDRJwICePLGHFHWlMfw7N0Gjz0chvad/wfJyO5vZI3 JPj12qPhYIraRKrMcaQfqLyctWc6G5j9k0jrvz96b/6bLKz2BDQCfey4bRfhHjLpaKPw7S19Wbr akkegkJQXZnGx5Aml1BorN9qP4rt+gIPkCqbspSjG9hyd1a/yVDbkuwzmVbrX2YiOW3xLQlGgYL 2JwShNCs9z3JBiEeg2v7kjehw== 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: stable@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