From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85913400DFA for ; Tue, 21 Jul 2026 02:14:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784600097; cv=none; b=I+zp9mHS3h9lrOj1SiQJS2wL8ORFFdbMYZq3g+Y1wKK2DCsPAqjyBXv9zaWNNQ4PcAS2HndPleJEH27a8YfNhVxz9GfXnHsTIvwBVtW7rZ2WKKs5fiwmy3s3VOvfcRicYbmqJZshDKI5xdMHUCoG77kSu9t7GY73AGAepYTjM+I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784600097; c=relaxed/simple; bh=7iYJyleZBwgksxOOmPrkRVeVrn+YU5L3ImQL22TAFUQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r5CAc6/Y1AI4mKLIosA2F4lnPHzVLhv9rzckr5UrHK64ImW0RGXQ/zmB567LNix0tYh2Tm+TgMP3NvMpAAt+DXC9siXeZvm3YmAanf8hUaVAJIIJRioY7Vs6ng/iP80oEo4kls51Gj4kVvEAUuA6keHdJY4Nm1JdtwQPch+/Uzo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LQCQsRsi; arc=none smtp.client-ip=209.85.214.179 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.b="LQCQsRsi" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2ca64c3ce5fso124011635ad.3 for ; Mon, 20 Jul 2026 19:14:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784600096; x=1785204896; darn=vger.kernel.org; h=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=fUEMfFXXEJWfpYYV6BprYH6yq5tTMFc+tIMi7bPpkS8=; b=LQCQsRsiiES1XpztBA5NE+Cw6bPHZ8kLpKVsWaiMV3iJpH2DB7A06hQx8SvNhtPE9l 3UPwJsxsgfZ9veuLSGoqkiGLGRiwuHzT6ZmZcA66AuoVsuj6v7gKnEAmcFVkmji5hijj G5y8FPax4RPX+sBJEL/GgB43TvXy8ASSH8gvaa6fkctfSMEEO87dpplEsEmK2NGTHyg/ CGkqXiT25hJAig9nT/U5CbWGHc8YBEVNjBaqGQD5MDsMBFEKpbA7t2ePR8QBDXCz2Il7 bb39DRllLOXjbr5xirBWJAOvRoY3NriQu4JDD/cX46NH0TeSVqHiwsAVXZ302v389KiM 59jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784600096; x=1785204896; h=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=fUEMfFXXEJWfpYYV6BprYH6yq5tTMFc+tIMi7bPpkS8=; b=BJnyPqEKffyeZjySzHmVfKThgDl4/s2eENdHGHOnQ8G11DMFVTT1UVC/u1MoRvtTTg 0gqwQiEFqNLB/1GWvd56yx+Mn3ko+ng4EivwGOmlQJfQNh9W34PKHXvIIseLx70Ma1zc JfXOIaKfmWFj/jO70uHdMT2JA0mB6K/REjBcfWaL46YewduETJbift6gQCyRHo6A2+BH 9E3qYYISphp+BHvejN/olzNJQdFTC4BZ9wRKlty4TVlRIGh3QyAaZRvBrzoTgMGdLfAj w8I7n3hJYvmBhWBi3aPS+tze/VpAB5+ojLF9p3a83S5/zd7vA2PnKlAEj/qnwuXjlolk YHDg== X-Forwarded-Encrypted: i=1; AHgh+Rqopm3T7wfTNL7gUd5Q20OkOFe9W8OvfE0shZL+g+jDObqF1wImiRVJOaJqt05qthqcRcCU5P0SSaVI0zY=@vger.kernel.org X-Gm-Message-State: AOJu0Yzgaljc7ZcDNZ6SQe9IAExTaAOK9oSc460yA/I+naBO5i3L4nv2 yt2ZlmiaYjzNDHQSf84ATXXwKbaabLs6JQ9C39a299AUZHeBvSaO8TvN X-Gm-Gg: AR+sD10XQzheJJtDHZonSiDXiqzgvKJ1UJyPQQHesyjCD62C7BheoBoK2MH9H6n4UBu O8CZ/2/22ac9nyZ0KwOCgxYpEZeccXJp0GZdAchJQxODZOhakaShwY3KhZCUUdnRnFIUaLLeeFg w+03te8pX3Ew9vrJhlTAVZVo0g/Yr+bxCxjDMqSgm+TgN1iiTJp8GFTl1mX/ZcsbMAaxqI69Qp2 I0rE/IMOdJ5TVRh770TPG0KQAcsKOUQbm66rsK+Q68B0+7G3vG7lqwIEpZ/6BEirJAGJIfM3piS YfveP2UiQTftVe+6kbbhlf5x3xeQcU9dgAnQAzVFaUBFgzOEq3Fy19gJ8mMIK2ALV4N06Kqp2+F wkP5+nMVoYQ/HUD7SJZOc6fM7ZPVHfNxug7OJToOPefBWrZ85Uolfoi5zkhqYbyhSxvp2DLEPpA c7DLpmLjwEFLSRmpaxtqvmvL127jGKL/d+K0z6qhnu7zhlRSlhaQCNF2/0DHguT6g= X-Received: by 2002:a17:90b:56d0:b0:38e:e0b:320d with SMTP id 98e67ed59e1d1-38e4b594707mr17316465a91.41.1784600095935; Mon, 20 Jul 2026 19:14:55 -0700 (PDT) Received: from localhost.localdomain (60-250-196-139.hinet-ip.hinet.net. [60.250.196.139]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-38e9235a4dcsm586241a91.12.2026.07.20.19.14.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2026 19:14:55 -0700 (PDT) From: Joey Lu To: mturquette@baylibre.com, sboyd@kernel.org Cc: ychuang3@nuvoton.com, schung@nuvoton.com, yclu4@nuvoton.com, linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Joey Lu , Brian Masney Subject: [PATCH v4 2/3] clk: nuvoton: ma35d1: fix PLL_CTL1_FRAC bit field width and fractional calc Date: Tue, 21 Jul 2026 10:13:55 +0800 Message-ID: <20260721021356.288506-3-a0987203069@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260721021356.288506-1-a0987203069@gmail.com> References: <20260721021356.288506-1-a0987203069@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit PLL_CTL1_FRAC was defined as GENMASK(31, 24), covering only 8 bits. The hardware fractional field occupies bits [31:8] (24 bits), so the mask must be GENMASK(31, 8). The previous fractional-mode calculation used FIELD_MAX(PLL_CTL1_FRAC) as the denominator to obtain 2 decimal places. With the corrected 24-bit mask the old divisor is wrong; replace the arithmetic with a proper 24-bit fixed-point rounding to 3 decimal places using the kernel's DIV_ROUND_CLOSEST_ULL helper: n_frac = n * 1000 + DIV_ROUND_CLOSEST_ULL(x * 1000, 1 << 24) Fixes: 691521a367cf ("clk: nuvoton: Add clock driver for ma35d1 clock controller") Signed-off-by: Joey Lu Reviewed-by: Brian Masney --- drivers/clk/nuvoton/clk-ma35d1-pll.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/clk/nuvoton/clk-ma35d1-pll.c b/drivers/clk/nuvoton/clk-ma35d1-pll.c index bfedd45bd04b..eb9d69d2077b 100644 --- a/drivers/clk/nuvoton/clk-ma35d1-pll.c +++ b/drivers/clk/nuvoton/clk-ma35d1-pll.c @@ -48,7 +48,7 @@ #define PLL_CTL1_PD BIT(0) #define PLL_CTL1_BP BIT(1) #define PLL_CTL1_OUTDIV GENMASK(6, 4) -#define PLL_CTL1_FRAC GENMASK(31, 24) +#define PLL_CTL1_FRAC GENMASK(31, 8) #define PLL_CTL2_SLOPE GENMASK(23, 0) #define INDIV_MIN 1 @@ -113,9 +113,9 @@ static unsigned long ma35d1_calc_pll_freq(u8 mode, u32 *reg_ctl, unsigned long p pll_freq = div_u64(pll_freq, m * p); } else { x = FIELD_GET(PLL_CTL1_FRAC, reg_ctl[1]); - /* 2 decimal places floating to integer (ex. 1.23 to 123) */ - n = n * 100 + ((x * 100) / FIELD_MAX(PLL_CTL1_FRAC)); - pll_freq = div_u64(parent_rate * n, 100 * m * p); + /* convert 24-bit fraction to 3 decimal digits, rounding to closest */ + n = n * 1000 + DIV_ROUND_CLOSEST_ULL((u64)x * 1000, 1ULL << 24); + pll_freq = div_u64((u64)parent_rate * n, 1000 * m * p); } return pll_freq; } -- 2.43.0