From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FB93C3A5A5 for ; Thu, 5 Sep 2019 08:22:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3E7762145D for ; Thu, 5 Sep 2019 08:22:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731259AbfIEIWq (ORCPT ); Thu, 5 Sep 2019 04:22:46 -0400 Received: from kirsty.vergenet.net ([202.4.237.240]:58718 "EHLO kirsty.vergenet.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726115AbfIEIWq (ORCPT ); Thu, 5 Sep 2019 04:22:46 -0400 Received: from reginn.horms.nl (watermunt.horms.nl [80.127.179.77]) by kirsty.vergenet.net (Postfix) with ESMTPA id 43B9625B753; Thu, 5 Sep 2019 18:22:44 +1000 (AEST) Received: by reginn.horms.nl (Postfix, from userid 7100) id 43307940AC6; Thu, 5 Sep 2019 10:22:42 +0200 (CEST) Date: Thu, 5 Sep 2019 10:22:42 +0200 From: Simon Horman To: Geert Uytterhoeven Cc: Geert Uytterhoeven , Michael Turquette , Stephen Boyd , linux-clk , Linux-Renesas Subject: Re: [PATCH 1/5] clk: renesas: rcar-gen2-legacy: Switch Z clock to .determine_rate() Message-ID: <20190905082241.hw3v3fy2qkljrbmg@verge.net.au> References: <20190617125238.13761-1-geert+renesas@glider.be> <20190617125238.13761-2-geert+renesas@glider.be> <20190618110937.2s7h5vtssymfrxxq@verge.net.au> <20190902083139.qicqmtrxosnzay2s@verge.net.au> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organisation: Horms Solutions BV User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org On Mon, Sep 02, 2019 at 10:44:25AM +0200, Geert Uytterhoeven wrote: > Hi Simon, > > On Mon, Sep 2, 2019 at 10:31 AM Simon Horman wrote: > > On Fri, Aug 30, 2019 at 10:43:01AM +0200, Geert Uytterhoeven wrote: > > > On Tue, Jun 18, 2019 at 1:09 PM Simon Horman wrote: > > > > On Mon, Jun 17, 2019 at 02:52:34PM +0200, Geert Uytterhoeven wrote: > > > > > As the .round_rate() callback returns a long clock rate, it cannot > > > > > return clock rates that do not fit in signed long, but do fit in > > > > > unsigned long. Hence switch the Z clock on R-Car Gen2 from the old > > > > > .round_rate() callback to the newer .determine_rate() callback, which > > > > > does not suffer from this limitation. > > > > > > > > > > This includes implementing range checking. > > > > > > > > > > Signed-off-by: Geert Uytterhoeven > > > > > > > > --- a/drivers/clk/renesas/clk-rcar-gen2.c > > > > > +++ b/drivers/clk/renesas/clk-rcar-gen2.c > > > > > @@ -66,19 +66,22 @@ static unsigned long cpg_z_clk_recalc_rate(struct clk_hw *hw, > > > > > return div_u64((u64)parent_rate * mult, 32); > > > > > } > > > > > > > > > > -static long cpg_z_clk_round_rate(struct clk_hw *hw, unsigned long rate, > > > > > - unsigned long *parent_rate) > > > > > +static int cpg_z_clk_determine_rate(struct clk_hw *hw, > > > > > + struct clk_rate_request *req) > > > > > { > > > > > - unsigned long prate = *parent_rate; > > > > > - unsigned int mult; > > > > > + unsigned long prate = req->best_parent_rate; > > > > > + unsigned int min_mult, max_mult, mult; > > > > > > > > > > - if (!prate) > > > > > - prate = 1; > > > > > + min_mult = max(div_u64(req->min_rate * 32ULL, prate), 1ULL); > > > > > + max_mult = min(div_u64(req->max_rate * 32ULL, prate), 32ULL); > > > > > > > > nit: the type of the second parameter doesn't look correct to me, > > > > div_u64 expects a u32 divisor. > > > > > > Yes, this should use div64_ul() instead. > > > > Ok, but in that case should the constants be "UL" instead of "UUL" ? > > The first or the second? ;-) > > The multiplication should always be calculated using 64-bit arithmetic, > hence the first ULL suffix. > The max() macro needs two parameters of the same type, and > div64_ul() returns u64, hence the second ULL suffix. Thanks, I see that now.