Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp213657pxv; Wed, 14 Jul 2021 02:13:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3XjDcMMMI4vBa3Xpc/46RLx43fyhrGobPDCA4GQFjAGpxw+p4w9gbRFZkLAW/U31MuXZj X-Received: by 2002:a5e:8612:: with SMTP id z18mr6560976ioj.38.1626254012473; Wed, 14 Jul 2021 02:13:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626254012; cv=none; d=google.com; s=arc-20160816; b=H/tGitU2vglp5A/SCcS5lWxgttCvARHXozP5vRfj4MAO3Apqo/8Kp/zvY1c63aI3zr 2dNdcoOFSeOewFvvjyjLpbIsqti+TOQieJJ1ugGMw7u6ScDz5I27pKohMibGGY2bnv1M 5kb94u2llHJ0GIHnGy7728QP4qYv9949U/M7MGDTBTiGdKmRIzAMFzHUGjvXPx6VJhSd xqG7E4isUogMJVGvbJ6uGpzXLmxBpi8a1DcklUHkJ3a8uNtjOt50/lm3y8wm1U4OBvNL YxL9Edic9nB2xSRety5T+Y/th3M2GDQuTJTNvQ7/WA9b7ICMOCYN+KqC1jC/Ikdvl4/Y lNPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=9b0yaVMsZcvmFYCK5wij5sloL+MjtdAf3BBMFGKXR7g=; b=y365739e1ax/YM+nirhh/fHFwnI2XqF534UQZBHDcgJlamO7L+x4tO+GBmuZ4COayc X/AeZ5z1hTyKSBfqYIbi1N6PTyOh1eETSGTy+7fnYJ2sYZthdJLSErASswbdcA6JsQOO SVk+Jyq/E+blGtPhm8+d+9Lox3rKKquRnKTFExUesAu6HPMChAcijIJpX8qrUIs+YRtM h1TmL6oX1AWbNolOJmoLWB316OwoKLbzDYgQ3IgYLdC9PjMay6IAGvP81XBhzMrxEWtt ZfRce/vxYpE2x8f5hCYs0VuT3r2iniyh9aKsLl9NClJU0Sp41IxPRbSlngb/r4nGVIcw r7Ug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n12si1774903ilq.134.2021.07.14.02.13.18; Wed, 14 Jul 2021 02:13:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238242AbhGNJP3 (ORCPT + 99 others); Wed, 14 Jul 2021 05:15:29 -0400 Received: from mga14.intel.com ([192.55.52.115]:12515 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238123AbhGNJP3 (ORCPT ); Wed, 14 Jul 2021 05:15:29 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10044"; a="210130738" X-IronPort-AV: E=Sophos;i="5.84,238,1620716400"; d="scan'208";a="210130738" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2021 02:12:37 -0700 X-IronPort-AV: E=Sophos;i="5.84,238,1620716400"; d="scan'208";a="413227226" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2021 02:12:35 -0700 Received: from andy by smile with local (Exim 4.94.2) (envelope-from ) id 1m3awP-00DFh0-4X; Wed, 14 Jul 2021 12:12:29 +0300 Date: Wed, 14 Jul 2021 12:12:29 +0300 From: Andy Shevchenko To: Liu Ying Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Heikki Krogerus , Michael Turquette , Stephen Boyd , Dong Aisheng , NXP Linux Team , Jacky Bai Subject: Re: [RFC PATCH] clk: fractional-divider: Correct max_{m,n} handed over to rational_best_approximation() Message-ID: References: <20210714064129.1321277-1-victor.liu@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210714064129.1321277-1-victor.liu@nxp.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 14, 2021 at 02:41:29PM +0800, Liu Ying wrote: > If a fractional divider clock has the flag > CLK_FRAC_DIVIDER_ZERO_BASED set, the maximum > numerator and denominator handed over to > rational_best_approximation(), in this case > max_m and max_n, should be increased by one > comparing to those have the flag unset. Without > this patch, a zero based fractional divider > with 1-bit mwidth and 3-bit nwidth would wrongly > generate 96MHz clock rate if the parent clock > rate is 288MHz, while the expected clock rate > is 115.2MHz with m = 2 and n = 5. Make sure that your editor is configured to allow you to have lines ~70-72 characters long. ... > The patch is RFC, because the rationale behind the below snippet in > clk_fd_general_approximation() is unclear to Jacky and me and we are > not sure if there is any room to improve this patch due to the snippet. > Maybe, Andy may help shed some light here. Thanks. > > -----------------------------------8<--------------------------------- > /* > * Get rate closer to *parent_rate to guarantee there is no overflow > * for m and n. In the result it will be the nearest rate left shifted > * by (scale - fd->nwidth) bits. > */ I don't know how to rephrase above comment better. > scale = fls_long(*parent_rate / rate - 1); > if (scale > fd->nwidth) > rate <<= scale - fd->nwidth; This takes an advantage of the numbers be in a form of n = k * 2^m, (1) where m will be scale in the snippet above. Thus, if n can be represented by (1), we opportunistically reduce amount of bits needed for it by shifting right by m bits. Does it make sense? The code looks good to me, btw, although I dunno if you need to call the newly introduced function before or after the above mentioned snippet. -- With Best Regards, Andy Shevchenko