Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp67813rwd; Wed, 14 Jun 2023 12:18:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ75Y0Pks/srRtNNoLSfUwQhJD334IfQG6JFSE7DQ48YGYTi82nlikVkiDvvRy1bHrC7plfH X-Received: by 2002:a2e:b0e2:0:b0:2b1:a8bb:99ab with SMTP id h2-20020a2eb0e2000000b002b1a8bb99abmr7203449ljl.19.1686770306527; Wed, 14 Jun 2023 12:18:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686770306; cv=none; d=google.com; s=arc-20160816; b=oLdSeToXkWXF6HQKU2E5Hk26q7W713RhwKrwX/xKAoEYLrXJ+uNo2TW75eKu4EuACm yHmWz4ecGG3p7IEo6QrXCx2tNXDjExEkGTPZHPwra289pNl2ozqJEchjoF5ENizuvE3A bRq4mc9r6WEeLBhe4SLqdxeKa53mNzl6rF5Ci+EgawaLjwLBwGfTciq/Sdc0BzwE9+pb Opxjw6HhJgTXItXn35Dc+ifuq4ZZ2ivY6Rpf/Bfpzax7oQHDFutMSsOUjX3WPDbM/uve p9G1azJFwpqn5/LsO2rhvHQsXKf7pmTKIKpSLhhGGmvGwcbdJZXoN9SQlkcL7SV2DheH qRBQ== 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=VrLmhksuKVuR06TD0+BUnlxKpggr1/sz/Cz0h1//L8s=; b=DOYWDWM0hHRa4wDvSaJZGyTKSduUaTzPAPt0q7iStU1TY5o5GL6bf/pCELXNBaigwg WTCZcG1lp6OxdvaB2Wpr6eA/EzfgUHTJTzGmf1zClqyy2GX2dNmtqrWjkXEYlMm5jpBg zYXGfx1AE3i9BlesS5xTUz+1LTDjwTrqmmqoQcD3easEgVAux2hvbqkcJ7oJ//YIn0Eu 95Hs6j7TN4hjBNzUtbn6qJn0RqcMHBXfUAOmV/Arl99GHrxn9JHdMlsHHbJBXYYYTK/5 HcZWIjXNv0EMo1YXdiBBW3rpW7VJipbNFndTsEPpNI0OFmlQ+wUy1GsXcpvBqsKcyzhN tPig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oltmanns.dev header.s=MBO0001 header.b=WjWwCk6j; 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 p12-20020a056402074c00b0051498cea5e7si8899827edy.521.2023.06.14.12.18.01; Wed, 14 Jun 2023 12:18:26 -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=WjWwCk6j; 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 S230373AbjFNSzq (ORCPT + 99 others); Wed, 14 Jun 2023 14:55:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231233AbjFNSzn (ORCPT ); Wed, 14 Jun 2023 14:55:43 -0400 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [IPv6:2001:67c:2050:0:465::202]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4829D213F; Wed, 14 Jun 2023 11:55:41 -0700 (PDT) Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.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-202.mailbox.org (Postfix) with ESMTPS id 4QhF495C6jz9sb7; Wed, 14 Jun 2023 20:55:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1686768937; 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=VrLmhksuKVuR06TD0+BUnlxKpggr1/sz/Cz0h1//L8s=; b=WjWwCk6j2MniTbXSl2SAPFVfklJQk3NJ+5Z7JsFiZSOQEMebo+xkoIEUU2ueEPZ0yq03YY a2GrbGSNNkWt+p0YAIR0MRaJbNnod4dALFBFxsvI6Vf5pYPKmSlyRHwq5FxRMvvjuloIsv XliJlNegvk8KcqtOTKLVx2DezRpQSuD0GQXnnQMzImKFKIoalLJLrvK3qIF1NamioGk/O6 lT5FhC6aNZQd+uJ8VORLDHju1LIwwVA6b9mL7tP7Alo9JfxVPU7M24ZWDAdKX+Gw7t2nXr zv6F91eCnYEvNZIvBagC8Vdp2YyzMeLjTROGeE5Ec9Nj88g5XRromatHmHGzLw== 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 Subject: [PATCH v3 1/2] clk: fractional-divider: Improve approximation when zero based Date: Wed, 14 Jun 2023 20:55:20 +0200 Message-ID: <20230614185521.477924-2-frank@oltmanns.dev> In-Reply-To: <20230614185521.477924-1-frank@oltmanns.dev> References: <20230614185521.477924-1-frank@oltmanns.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Cc: A.s. Dong Signed-off-by: Frank Oltmanns --- drivers/clk/clk-fractional-divider.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c index 479297763e70..7da21cd2bdb1 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,9 +139,15 @@ 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); } static long clk_fd_round_rate(struct clk_hw *hw, unsigned long rate, @@ -169,13 +176,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