From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796208232; b=wrEJqz8CgSm+XvmLVdEQ9cOgU2I+Kqdwra3KL430LrRz38XNdOaekk/O/UKAilmFlRhn Kbzilhd/QkR5+UdoHyS7x/LygXUKu3IS2oy90ayRXEDCXlYTkEz5IFogdnDCGaTG8NGY/ jaI2rNDBPMtBszJKHERojsptMoR4kcdFEAqjQ3j7+tP76lGXWzM44DDrYjgbjI0GzW7T/ 9Ni9drMyFUf6dQQb68xTejbM8SXfMzvsBih6hTbQQffXX4wGq+3B7Gyq0TiyzOGQqZWox Hv44vZ2smLrgw6m9C+KscUqbo1INxKE/LrkF3R3h73Ed/DusNPGVTkxBWgI52z7Nnkg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796208232; 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:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=wQ3CaH8f+06xQ4lxCOxVLWLzFyDSzY1RSijgaB7b+uw=; b=iLLIcndtp5bNe8tTxE/Lv8PWWvlfPkGrCKW/JuKiy0TX3tVQFGsO0dJAJwcRtcjkya0B TK3KxiXdKefDbz9v7KBvb/qwGH3ftW5OJGSWBOk83ZfBIwRqA6V12eUZ9Jr/kJO6L33w0 IlBLL2sNm8RMXly6ufHYUSzXtxGSWP3oojd4W8EpVvlysqu29Cx2dKWbZbpuWZwdqKrjH 1LyHvFur6JFYOMcstRwqDnkNTOkYnpOLiRyBl3gAsbzRpi/h3NfrRz6FG1P+QKfsHi/Ex T7XubNGbajHAD0OL6eXRVCEMoXZsaYDEjmr2yNBAgLgz93QaujpPkjgJBFN7FhBYPPw== 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=yYK6pQlc; arc=none smtp.remote-ip=209.85.128.54 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 D0BE1606A69D for ; Wed, 2 Dec 2026 10:43:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D0BE1606A69D 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=yYK6pQlc Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4bb69f5b161so85479915e9.0 for ; Wed, 02 Dec 2026 02:43:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796208229; x=1796813029; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=wQ3CaH8f+06xQ4lxCOxVLWLzFyDSzY1RSijgaB7b+uw=; b=yYK6pQlc6osImaY13mP6pnOZkUBTNlK9+mLchL2x6/eWhtbvPJO6eUos7Creefm3fm NoWzzYn0sPKkDZgwM6RegdhhZEN9+tLrjlYXcazDw7ZiAygFIF5Bxzfz7/p+pgvPfso6 aaRcbBmaOiBLqQf1QDfhwF3T0MZEfUBW0M9YK+FdCy1VkauFJjkVvnyD+CiiyDb2IAPl A/7jIm380pxYZrzdc/ilrqIfbHIUbhoCvmFIIUI8U8HpGrzXiMwoda6cVBGvsZfg6jz3 Q1KGNBMZm7bQ7/5tpHR624M+u4nwyVVpk+QVOkmeOyZ8eEyVbXr2PLf8pvX8bOlj0e22 XH1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796208229; x=1796813029; h=content-transfer-encoding:mime-version: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=wQ3CaH8f+06xQ4lxCOxVLWLzFyDSzY1RSijgaB7b+uw=; b=qP4aZj+qI2oFZGSgwqkrrpoKu7uAlEe9lm2uYfSnrXdEQiwmOTtQQPW8DfBX9VgKwY x2EYQQj5Zr7rOwXPBmXCRoETu+vbbcYnCKTsNFiALE4K635xf4zR5sRhYvGcE1s1N9zm y7xmF0rj6jorw5npqAjfZ8CceG7rl4ixokrDCtDhdEKiHVBeezIlftkHzgWHAHvJ4Dr0 KzsFLRtBcMHYb6uOFLO/InBiM8IdYnonJSAXmk3zFAfCY7JyIILYYx6yt+JBjV2rv36G fD8NL+8OS4A2Rup0Wt/ncEru+rwvC7mKvm2Q0O4+IEgIfG/5+2h3igzN+lFXDxiGagfw RRYg== X-Forwarded-Encrypted: i=1; AL+hErGCABr/Ieg4wznGOnEaDcEWthCFCRgrgy2vzxI6L5I6dERYSjaZG3VhLYEDPDn4h59jRaZwAAw=@vger.kernel.org X-Gm-Message-State: APuU4Z+X6QBcVvbb/HFW8xo0qv/jhk8+qPY5LY3oOIT8AgGaBqAFAEn7 8y+HU7wpComEPmroVdF+r7See3rCPPittXMhvpmhG0WYhDSszlApdujK X-Gm-Gg: AZFdTZce2yWhRh88/5X3Me+1Bqp4fnlz7HGQZBvEqGKwcPowdlfJHSgCt2xdMoZfLz6 lwvssPpI4tKBPbRCJ1QrX8kKSfrZigmydmsJOvciSlqJISxUUza/giwB7GCDMUSJ1GogKjLOGN5 1GukrsU59hwZFkkfoA7w8qZAFl4Yr2EfyCb0hVSf4Ocv48hk9CpzK3Dri6lKfctL0w9cbgK4Pj/ 8syJvh9XSzQ1FyUVUcpomG0jJWIrDLnDkehEm83UHSKP8nLWb60kGC+YZt/4U14m67UIk4L+wTZ uLAuyGLM8oI6DWvLCQEmX0IUTsMPSwFzM2l/n50Bh4LN3cUsoHStTzucx3/MQqMvVlyMCVV7dAC /4G8oHF8v86bxVO0OvBdFkmnD5DxU728vwg73dL0Tv1Q8bqhlUi8VYlDJbqFETs7rXg1t0Ljn1P 16Sd9jPGyQLsprPuwyMMA7JkWZS3YmYaabNRdUBxQmByIL0QebIpEF5JBc2ZFyclwT/otMiLr7E 0W7bpMW0xHLO5QRuNiPOdSnBq7dc8F4zYJgNSMfd2BHT7mW06TUpw1+fjzUYDf+yBi8DO2DLuO5 FL9ZRUcTGaFFjvDt464BtAMIi9gpSqV9DIjh2NYjoHm/67fc+ChLDkTrhvzkcRfE3XfSFPokqun wsp8bqDHs8JdYZ3Vw8v5htC/tUbkus83ATRILZHSm3kS8N54Nh5SMKfE= X-Received: by 2002:a05:600c:e558:10b0:4bb:c9f8:aeb with SMTP id 5b1f17b1804b1-4bbc9f80cb1mr99330175e9.1.1796208229001; Wed, 02 Dec 2026 02:43:49 -0800 (PST) Received: from MYL150-3871.blob.core.windows.net (57.11.28.93.rev.sfr.net. [93.28.11.57]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6bb989eesm75963026f8f.50.2026.12.02.02.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 02:43:48 -0800 (PST) From: Nicolas Thibert To: Thomas Bogendoerfer Cc: linux-mips@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] MIPS: ath79: qca953x: use the mean CPU PLL fraction when dithering Date: Wed, 2 Dec 2026 11:43:45 +0100 Message-Id: <20261202104345.973534-1-nithibert@gmail.com> X-Mailer: git-send-email 2.34.1 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: 8bit The QCA953x CPU PLL can dither its fractional part: when bit 31 of the CPU_DIT_FRAC register (PLL block offset 0x48) is set, the hardware sweeps the fraction between the MIN and MAX fields of that register. Mainline U-Boot enables it for QCA953x (MIN 0, MAX 63, so the CPU clock sweeps 650 to 674.6 MHz with a 25 MHz reference). qca953x_clocks_init() reads the fraction once from CPU_PLL_CONFIG, so with dithering enabled it gets a random sample of the sweep. The CPU clock, the MIPS clocksource and therefore the system time are then off by up to the dithering range, differently on every boot. Measured on a QCA9531 board booted by mainline U-Boot, comparing /proc/uptime with an external clock: the kernel reported 652.3, 653.1 and 673.0 MHz on three boots, and the system time drifted by +16100, +12000 and -15600 ppm respectively, while the real mean frequency was 661 to 663 MHz every time, i.e. the mean of the sweep (662.3 MHz). When dithering is enabled, use the mean (MIN + MAX) / 2 of the fraction. Without dithering nothing changes. Tested on the same board, with U-Boot dithering between MIN 30 and MAX 63: the kernel now reports 643.164 MHz, the mean of the sweep, on every boot. Note that offset 0x48 is also defined as QCA953X_PLL_ETH_SGMII_CONTROL_REG, which has no user. The problem was analysed and this patch written with the help of an AI coding assistant (Claude, Anthropic), from register dumps and the drift measurements above; all measurements and tests were run on hardware. Fixes: af2d1b521bfb ("MIPS: ath79: add support for QCA953x QCA956x TP9343") Cc: stable@vger.kernel.org Signed-off-by: Nicolas Thibert --- arch/mips/ath79/clock.c | 19 +++++++++++++++++-- .../mips/include/asm/mach-ath79/ar71xx_regs.h | 7 +++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/arch/mips/ath79/clock.c b/arch/mips/ath79/clock.c index 050f6553f398..1ae8b21ef04d 100644 --- a/arch/mips/ath79/clock.c +++ b/arch/mips/ath79/clock.c @@ -355,7 +355,7 @@ static void __init qca953x_clocks_init(void __iomem *pll_base) unsigned long ahb_rate; u32 pll, out_div, ref_div, nint, frac, clk_ctrl, postdiv; u32 cpu_pll, ddr_pll; - u32 bootstrap; + u32 bootstrap, dith; bootstrap = ath79_reset_rr(QCA953X_RESET_REG_BOOTSTRAP); if (bootstrap & QCA953X_BOOTSTRAP_REF_CLK_40) @@ -376,7 +376,22 @@ static void __init qca953x_clocks_init(void __iomem *pll_base) QCA953X_PLL_CPU_CONFIG_NFRAC_MASK; cpu_pll = nint * ref_rate / ref_div; - cpu_pll += frac * (ref_rate >> 6) / ref_div; + + /* + * With dithering enabled, the hardware sweeps the fraction between + * MIN and MAX: the one read above is just a sample. Use the mean. + */ + dith = __raw_readl(pll_base + QCA953X_PLL_CPU_DIT_FRAC_REG); + if (dith & QCA953X_PLL_DIT_FRAC_EN) { + u32 fmin = (dith >> QCA953X_PLL_CPU_DIT_FRAC_MIN_SHIFT) & + QCA953X_PLL_CPU_DIT_FRAC_MIN_MASK; + u32 fmax = (dith >> QCA953X_PLL_CPU_DIT_FRAC_MAX_SHIFT) & + QCA953X_PLL_CPU_DIT_FRAC_MAX_MASK; + + cpu_pll += (fmin + fmax) * (ref_rate >> 6) / (2 * ref_div); + } else { + cpu_pll += frac * (ref_rate >> 6) / ref_div; + } cpu_pll /= (1 << out_div); pll = __raw_readl(pll_base + QCA953X_PLL_DDR_CONFIG_REG); diff --git a/arch/mips/include/asm/mach-ath79/ar71xx_regs.h b/arch/mips/include/asm/mach-ath79/ar71xx_regs.h index 5f837060724e..5691e8d6ad07 100644 --- a/arch/mips/include/asm/mach-ath79/ar71xx_regs.h +++ b/arch/mips/include/asm/mach-ath79/ar71xx_regs.h @@ -355,6 +355,7 @@ #define QCA953X_PLL_SWITCH_CLOCK_CONTROL_REG 0x24 #define QCA953X_PLL_ETH_XMII_CONTROL_REG 0x2c #define QCA953X_PLL_ETH_SGMII_CONTROL_REG 0x48 +#define QCA953X_PLL_CPU_DIT_FRAC_REG 0x48 #define QCA953X_PLL_CPU_CONFIG_NFRAC_SHIFT 0 #define QCA953X_PLL_CPU_CONFIG_NFRAC_MASK 0x3f @@ -365,6 +366,12 @@ #define QCA953X_PLL_CPU_CONFIG_OUTDIV_SHIFT 19 #define QCA953X_PLL_CPU_CONFIG_OUTDIV_MASK 0x7 +#define QCA953X_PLL_CPU_DIT_FRAC_MAX_SHIFT 0 +#define QCA953X_PLL_CPU_DIT_FRAC_MAX_MASK 0x3f +#define QCA953X_PLL_CPU_DIT_FRAC_MIN_SHIFT 6 +#define QCA953X_PLL_CPU_DIT_FRAC_MIN_MASK 0x3f +#define QCA953X_PLL_DIT_FRAC_EN BIT(31) + #define QCA953X_PLL_DDR_CONFIG_NFRAC_SHIFT 0 #define QCA953X_PLL_DDR_CONFIG_NFRAC_MASK 0x3ff #define QCA953X_PLL_DDR_CONFIG_NINT_SHIFT 10 -- 2.34.1