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=CIwXfohAq8zTPyofy4HoWJZsGjIsvXVfFOGZKnc/P30cVL+98I/FnlMvl6y4R7XoGJsA vobuHtWBf6fWXndJcNKVx3slYOBC1OuUVQikjV0vbJcnU1KJsb+iDZI+U4dxE5A82nMaD c5NNUom5YQsEJq0o920/Z3morZZONPpaLa6YYv+AVk2p41LbBrAvygsvG/vIeZkGlIHRe r7norgS8aGmLwjlm/edhCH6tJK+rWC/iL8YLQ0qWsKXfw5Xc8GOriU8sSBsEQj6iarnWO BRkzeuixr2I2CBpZNuffGaZhhXXnvy7wrE59LOBQd6d2CHBS/gJx14stSK9uLatfG9w== 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=4H4009PtV5RSCkGQlgioS41LlhoTpklOU4hX5HMJBOVKBNm32G7ZiljcvwgyBByvCmRi qpTQv6krGzXE8JU9Uhhb1KmBTndaLhiLf53bT+zI9qDTh96bZpceWCyacuLdXi6pP99in zBVdDUivubptcJKYKEq1Yf3VY6KfFEDkwSdKd8plWVaghmXORW8RWwz3kQoavXLfS5qYr reWKpeFQUMwipZ/GMOTOHFmD6oA4+5IHBMBiCAKIPk9VGe1l+Z0hZHIJc1Gm5x+FDkvDA OIsnSYaHqx22CWru28c3b+1lLIiSfscbYmNE2FoVwfX10xOo25tuQqmwqk3m/cy6+gw== 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=eiVJeNPY; 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 80C9B606A323 for ; Sat, 28 Nov 2026 17:20:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 80C9B606A323 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=eiVJeNPY Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4a207b02a2cso64767995e9.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.linux.dev; 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=eiVJeNPYPaaCGOk7I2fkZ/snBlDsN2iJIhG6UC0Bb4XQ/OluctUpzWbmWvSEQD4cfR niNNhY8Oh6+WXPnF/wVKIz5eZZL6UtBTZHwZWapAmixcHO5GQGnNFrGjF2FSTin/kglY 3ayOXI5BaPyDsJ8Q9k0SI3Z6wXTcTXh9hOT1+1tbeiJ6jMjlGlEBsCIEp0JyL9hyvBiT hof7qBs++GzvnKZpiVpOaBMbX98BXHDEkA/NHTQcPC/D56QMt2MJcGl7Rc+nZnx4cwVN xl6kr5RVzIJyh8QkmEGNunudNXRbjIBiqsg7YmWYeXQyjT7S9H+vFrs01doImi/RVDOX 4Q1w== 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=Dg9HtTae2h1/n4/XXZVois/zZHR6VTj25IsBb0T95B986RP52dTBJOMrhAybNXXPni wdeEOrZDk3XOxh4aGFLgwa638ekSCBl4jwT5HQTyLIimI6s0omM5gLxUBy1YLpzAQKf4 9pelOG/7/5lZX8h1hXP4/NBTa3BsoO9HPufX2x/zRy1A2AJUmGD6PC3BSzL3vSuvB2UO 9RGXoHLXyhWcE5KG3EwrsjPBPspc/506RC84eBvjUrGyYFqi3T+jy5XRGmmUW9o84vYo IR2heitOppgi3dv+GqLHnalhbs89n63TvA7DWtw6xEfMpORIArSCqcYgemgUxPxS1wbI OwsA== X-Forwarded-Encrypted: i=1; AL+hErFC3tHFHF/Fe1NtzGxzTTZgPw+YDY23tK6DE+5hhnaKk/PloI7JTjuj0WMImi2r8a6puAvbxS1jAgQvNw==@lists.linux.dev X-Gm-Message-State: APuU4Z+far5KhmMPC/pkbNWIgW0GWdliTUMc8YPvbjZa5/bRNPK4Xb4U BpU3dQlLgqeCfLhXnol7B6Q6hsKzB53RCn//tjhXR4dKgfM61nKmyO1W X-Gm-Gg: AZFdTZeDTrVRJpxQKr39NbIWLylNdAQxGxsUXnKwgZV4IQEEn7zPQImomIlKx3jefqk +bctrPuoswjT6dJMxc5FBYDrjBps4nJxxBk9hOqHq5j1j11KrG/jjvSZ+SHF9t/yT64K5Dvxas1 QMcYeOxDfb7m9CqqMfZ+C7xySJVAslYc97XJ3oZMWZ88u1ca75pM/MbbKjnqU1iOuqzuEmJZekH g9GxN7QvaT3JTscxzhO00gpV1v6au35p5yJ6twCoZeX6T176nNRGG+JIVH1n0X5luQLMdRGf97t lYf5Zj9duQc/EMyoibMavFBM8MAawJ8ANEeMjdBMTYiLy38VVqmG4tsyyQoqby9auEvfFTfUly3 TqYhOaiN6WhNbL5zX4vWxR4sv9e2B1KJ2InRbPxjz9AEanTgHZ8+MooOTj1ZLTAQkhFXP5q9+m9 aM62nXP6DH1JbzTzUtxk+VdrnLeviD+9nQO2VnA985OSRdcrA0G+Lkc1z3BIrLGmWYb3lkvRlBm AMzrqr/SfmFPOG0jlG029V3+/eRjP61KyS+INFwznv0FQHHjTxiJMfZxaj/BaYvXTXeSDq4A4gR DKp8UKqyKbPrPqiBdN1qCPvme9aMgoAYOaTTIlXcQKfhyVLb9/U6UfWM0CMfmEZbNN2I1fLxIN/ pLx1x7zHX0eJ+wUuglZkkWHKDP3xWEnGodHMviYjukVeHThF/zO3eMQIaqttfkoaybBqSuNUb/l r4lX4SnG7kRyyA8MednMoh7mk3r5A2wveMtKEfhLNfxMj1sKyXoDkPH0XjeKNZHTDTFXPxv8pHl 1AujDW2oJld3D/Au8rR8pE26A== 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-sunxi@lists.linux.dev 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