Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2219600imm; Sun, 23 Sep 2018 23:51:13 -0700 (PDT) X-Google-Smtp-Source: ACcGV62ECpnoVRxFK461XS/kE5QYTqrBT5XkVmnZBFTkwhxkeOzlZWGzTgeOb4qSqcJn8pr9FVrM X-Received: by 2002:a63:a745:: with SMTP id w5-v6mr8147070pgo.374.1537771873799; Sun, 23 Sep 2018 23:51:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537771873; cv=none; d=google.com; s=arc-20160816; b=qwKBgIIz5ujapY8m6EoUtNkjwbb8eNHuwNuLttvatgPwU54TKvDw/FR+GaIUdWweJc GDnPz3000wx9sO6gcWjYL/ItxeadoCpACpBZnT2xhsZX/UoZwwcPKm6/lgQlumWFHgDW 5vZmhmFyj/GJAVg2LYW4qRXUcrr0n2hzZFraEZPUYbi7tTvkq1a0UYlEyGrUv68NIV3G sgrqOJTWoDIDeW442EEnWlapvK4wFCqZU22mF3kqmIV7KVvLBuDfdZ+zdaHZO06JRsZb EF9TfV+KbFq0PNsiVhaPW06EODhVIS/g+n18WDqWHNTeaQIAl8na1CzmiicfnooK2epG seIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=F1qCW5F0IriD7EP7ethxyZYmmFg1AMuoVanaIq2lI7s=; b=hbEDR2oY4q+s/zevGMob3+Oh1PLaDUkcMaFVJo/62Hzt64jw3pyNWyTs6hN82+DDZu W7Ojt94p/cY8Ail2pYkEcVQlmOr+SFtByrgAgZE/OKzj/pKR9p0TvBhvPMltWlX/Efsa 46wIAQImUVIlbWcD5rGvUMO97ZFuiFy4amR6+zOqww3Zl3CCfKxsIqyvtpoZPOUP2d7n 4rVPVXqtB7qnI+27g0cr4EGpnqG1I7LMuppzvVY5PAS4+TngKD0ZUQ/x4u03WXMc1NDi wTSMJvDREXr2W9KT5Y5K7wFZmLdflQmefIkaz5dMJXuYm1A0MJavdxf1m+b0BA7+/3aL dJ3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u135-v6si3114446pfc.79.2018.09.23.23.50.46; Sun, 23 Sep 2018 23:51:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727253AbeIXMsE (ORCPT + 99 others); Mon, 24 Sep 2018 08:48:04 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:37759 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726157AbeIXMsE (ORCPT ); Mon, 24 Sep 2018 08:48:04 -0400 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1g4KeA-0003In-Py; Mon, 24 Sep 2018 08:47:06 +0200 Received: from sha by dude.hi.pengutronix.de with local (Exim 4.91) (envelope-from ) id 1g4Ke7-0007IH-SK; Mon, 24 Sep 2018 08:47:03 +0200 Date: Mon, 24 Sep 2018 08:47:03 +0200 From: Sascha Hauer To: Abel Vesa Cc: Lucas Stach , Sascha Hauer , Dong Aisheng , Fabio Estevam , Anson Huang , Andrey Smirnov , Rob Herring , linux-imx@nxp.com, Abel Vesa , Shawn Guo , Michael Turquette , Stephen Boyd , open list , "moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" , "open list:COMMON CLK FRAMEWORK" Subject: Re: [PATCH v8 4/5] clk: imx: add imx composite clock Message-ID: <20180924064703.GY4097@pengutronix.de> References: <1537531894-18499-1-git-send-email-abel.vesa@nxp.com> <1537531894-18499-5-git-send-email-abel.vesa@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1537531894-18499-5-git-send-email-abel.vesa@nxp.com> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 08:39:50 up 129 days, 18:20, 153 users, load average: 0.68, 1.36, 1.30 User-Agent: Mutt/1.10.0 (2018-05-17) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Abel, On Fri, Sep 21, 2018 at 03:11:33PM +0300, Abel Vesa wrote: > Since a lot of clocks on imx8 are formed by a mux, gate, predivider and > divider, the idea here is to combine all of those into one composite clock, > but we need to deal with both predivider and divider at the same time and > therefore we add the imx_clk_composite_divider_ops and register the composite > clock with those. > > Signed-off-by: Abel Vesa > Suggested-by: Sascha Hauer > --- > drivers/clk/imx/Makefile | 1 + > drivers/clk/imx/clk-composite.c | 156 ++++++++++++++++++++++++++++++++++++++++ > drivers/clk/imx/clk.h | 14 ++++ > 3 files changed, 171 insertions(+) > create mode 100644 drivers/clk/imx/clk-composite.c > > +static int imx_clk_composite_divider_set_rate(struct clk_hw *hw, > + unsigned long rate, > + unsigned long parent_rate) > +{ > + struct clk_divider *divider = to_clk_divider(hw); > + unsigned long prediv_rate; > + unsigned long flags = 0; > + int prediv_value; > + int div_value; > + u32 val; > + > + prediv_value = divider_get_val(rate, parent_rate, NULL, > + PCG_PREDIV_WIDTH, CLK_DIVIDER_ROUND_CLOSEST); > + if (prediv_value < 0) > + return prediv_value; > + > + prediv_rate = DIV_ROUND_UP_ULL((u64)parent_rate, prediv_value + 1); > + > + div_value = divider_get_val(rate, prediv_rate, NULL, > + PCG_DIV_WIDTH, CLK_DIVIDER_ROUND_CLOSEST); > + if (div_value < 0) > + return div_value; Does this work with expected accuracy? Consider the best divider you are looking for is 9. With the above you'll end up with a predivider of 8 and a postdivider of 1 instead of the optimum divider values of 3 and 3. I think you have to iterate over all possible divider combinations and then use the best one found. The original divider code does this, albeit a little obfuscated. You have to do the same in round_rate aswell. Sorry, I missed that when I last looked at it in v6. Sascha -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |