Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3858372rwd; Sat, 17 Jun 2023 03:34:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ41kXKw/JRz9DRB6Br4WVPf0Ge5m0htHTM4eioX3hZrgODt/6rZGC6YfWBZIOpRsj2u0VDB X-Received: by 2002:a92:d945:0:b0:33b:ca8:fdaa with SMTP id l5-20020a92d945000000b0033b0ca8fdaamr2028492ilq.6.1686998052353; Sat, 17 Jun 2023 03:34:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686998052; cv=none; d=google.com; s=arc-20160816; b=EOatp5jEgWG8Vm6XcuATQ47eL6jGL3s0Ksl+qUtUqnZQOe7VNLH3PYDtegBG6ylPTn mtD03SOHANlYoNWe36d2oaCbGLvWu0axgms4KNI869+bgXhWH+n3GHV3hxjaGRPP7EZF kBtN6B3X/+kKXBbc5Wywl8MH6SAcRIQxzewI4WuIzOoROJCJYNYFgjDwp8vKTb3JjJN7 cYTrJHMqRIGQM2iByoegldmpGYhkkKRkEIWFu7nwkLjM0KdjYdxrChIeHZEex8dj027z DpKFKZ7u49Z/jKhG9sxgRb3T9+DoHVLrcZoMnWyzGCg4WJ3c/Ar6QcYEEOlQYAavHFU/ spXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=piM6ASDgch6PVWDiOGs21ydWS2z+iDsSfAmRcYpzIiU=; b=y+6H+9Gcxn17YPiOf9l+psbGEiCAs0sOFpYu/jxn48xOVtLMno4k/TJUcOwXL/uZab XgqRMxgbB6rhPwF5m6/I3AWVrTysCoPaA6uiKMkQvqxjpW0vvUAseH1Lm3Phy+5Lp5v3 Seux5mIyXmgfYI8tBZkiNbKaLaBTOzWfXIwO493mYOF7twPCslBWQdxHrKTWiwqOYgW4 ETzdarzUzUM5B2NE611rxbc8eSBDhtuE7YvHbSldIqsGCNrMPXPc5q3IwTZOLUkDhfU1 OHdzUc7t3TrTvTx27v4msgz2gdtu5QvPoq2a4EqNKw1IrHdpI1pdyX8AUjExg948VCzV giKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oltmanns.dev header.s=MBO0001 header.b=SoeQ25K1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oltmanns.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g7-20020a63be47000000b00543d0bf8632si17345639pgo.866.2023.06.17.03.33.53; Sat, 17 Jun 2023 03:34:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oltmanns.dev header.s=MBO0001 header.b=SoeQ25K1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oltmanns.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244610AbjFQK3z (ORCPT + 99 others); Sat, 17 Jun 2023 06:29:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235928AbjFQK3m (ORCPT ); Sat, 17 Jun 2023 06:29:42 -0400 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050:0:465::101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C247210D; Sat, 17 Jun 2023 03:29:40 -0700 (PDT) Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4Qjshx5qbfz9srL; Sat, 17 Jun 2023 12:29:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1686997777; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=piM6ASDgch6PVWDiOGs21ydWS2z+iDsSfAmRcYpzIiU=; b=SoeQ25K1x4Jyzd4FS1IvZAluHv1wt/1WmOU6WfxqI2hVmUtcpkpSmDzpBPxIGwUkpD09OJ kcrjWcXjSFxaF9Tnrvrlq45WwAAxPjDOhi7dFDNI7nijOFpgv8omIcPwsPtlrfbaRvzpep tMsKn7f43UUYpeeLOzTUpjV6f14RYkaO6it/9hYCXCIUgp9WbbMt5FxWMXM8eK/WrVlQ5q GizaP4RyglSSJxUjfSszx2ajfe9jaBr9ybx+mOcQ7eSFYR+Kki5GB52wiYQa0zewF67Oq6 ZmEkzyr4qda6nvUNXIHp/aHh2yjuPTLHyY2aB+dOXOiCzx/aHM1RBdT6GIVrNw== From: Frank Oltmanns To: Michael Turquette , Stephen Boyd Cc: Frank Oltmanns , "A . s . Dong" , Abel Vesa , Fabio Estevam , linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, NXP Linux Team , Peng Fan , Pengutronix Kernel Team , Sascha Hauer , Shawn Guo , Elaine Zhang Subject: [PATCH v4 1/2] clk: fractional-divider: Improve approximation when zero based and export Date: Sat, 17 Jun 2023 12:29:18 +0200 Message-ID: <20230617102919.27564-2-frank@oltmanns.dev> In-Reply-To: <20230617102919.27564-1-frank@oltmanns.dev> References: <20230617102919.27564-1-frank@oltmanns.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4Qjshx5qbfz9srL X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Consider the CLK_FRAC_DIVIDER_ZERO_BASED flag when finding the best approximation for m and n. By doing so, increase the range of valid values for the numerator and denominator by 1. Furthermore, export the approximation function so that users of this function can be compiled as modules. Cc: A.s. Dong Signed-off-by: Frank Oltmanns --- drivers/clk/clk-fractional-divider.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c index 479297763e70..5067e067e906 100644 --- a/drivers/clk/clk-fractional-divider.c +++ b/drivers/clk/clk-fractional-divider.c @@ -123,6 +123,7 @@ void clk_fractional_divider_general_approximation(struct clk_hw *hw, unsigned long *m, unsigned long *n) { struct clk_fractional_divider *fd = to_clk_fd(hw); + unsigned long max_m, max_n; /* * Get rate closer to *parent_rate to guarantee there is no overflow @@ -138,10 +139,17 @@ void clk_fractional_divider_general_approximation(struct clk_hw *hw, rate <<= scale - fd->nwidth; } - rational_best_approximation(rate, *parent_rate, - GENMASK(fd->mwidth - 1, 0), GENMASK(fd->nwidth - 1, 0), - m, n); + if (fd->flags & CLK_FRAC_DIVIDER_ZERO_BASED) { + max_m = 1 << fd->mwidth; + max_n = 1 << fd->nwidth; + } else { + max_m = GENMASK(fd->mwidth - 1, 0); + max_n = GENMASK(fd->nwidth - 1, 0); + } + + rational_best_approximation(rate, *parent_rate, max_m, max_n, m, n); } +EXPORT_SYMBOL_GPL(clk_fractional_divider_general_approximation); static long clk_fd_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *parent_rate) @@ -169,13 +177,18 @@ static int clk_fd_set_rate(struct clk_hw *hw, unsigned long rate, { struct clk_fractional_divider *fd = to_clk_fd(hw); unsigned long flags = 0; - unsigned long m, n; + unsigned long m, n, max_m, max_n; u32 mmask, nmask; u32 val; - rational_best_approximation(rate, parent_rate, - GENMASK(fd->mwidth - 1, 0), GENMASK(fd->nwidth - 1, 0), - &m, &n); + if (fd->flags & CLK_FRAC_DIVIDER_ZERO_BASED) { + max_m = 1 << fd->mwidth; + max_n = 1 << fd->nwidth; + } else { + max_m = GENMASK(fd->mwidth - 1, 0); + max_n = GENMASK(fd->nwidth - 1, 0); + } + rational_best_approximation(rate, parent_rate, max_m, max_n, &m, &n); if (fd->flags & CLK_FRAC_DIVIDER_ZERO_BASED) { m--; -- 2.41.0