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=-10.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 3DFC9C433E2 for ; Fri, 17 Jul 2020 09:25:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2031C2063A for ; Fri, 17 Jul 2020 09:25:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726238AbgGQJZg (ORCPT ); Fri, 17 Jul 2020 05:25:36 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:50945 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725912AbgGQJZg (ORCPT ); Fri, 17 Jul 2020 05:25:36 -0400 X-Originating-IP: 90.65.108.121 Received: from localhost (lfbn-lyo-1-1676-121.w90-65.abo.wanadoo.fr [90.65.108.121]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 930011BF235; Fri, 17 Jul 2020 09:23:54 +0000 (UTC) Date: Fri, 17 Jul 2020 11:23:54 +0200 From: Alexandre Belloni To: Claudiu Beznea Cc: mturquette@baylibre.com, sboyd@kernel.org, nicolas.ferre@microchip.com, ludovic.desroches@microchip.com, bbrezillon@kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 06/19] clk: at91: sam9x60-pll: check fcore against ranges Message-ID: <20200717092354.GO3428@piout.net> References: <1594812267-6697-1-git-send-email-claudiu.beznea@microchip.com> <1594812267-6697-7-git-send-email-claudiu.beznea@microchip.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1594812267-6697-7-git-send-email-claudiu.beznea@microchip.com> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org On 15/07/2020 14:24:14+0300, Claudiu Beznea wrote: > According to datasheet the range of 600-1200MHz is for the the the is repeated here > frequency generated by the fractional part of the PLL (namely > Fcorepllck according to datasheet). With this in mind the output > range of the PLL itself (fractional + div), taking into account > that the diverder is 8 bits wide, is 600/256-1200Hz=2.3-1200MHz. > divider > Fixes: a436c2a447e59 ("clk: at91: add sam9x60 PLL driver") > Signed-off-by: Claudiu Beznea > --- > drivers/clk/at91/clk-sam9x60-pll.c | 12 +++++++++++- > drivers/clk/at91/sam9x60.c | 2 +- > 2 files changed, 12 insertions(+), 2 deletions(-) > > diff --git a/drivers/clk/at91/clk-sam9x60-pll.c b/drivers/clk/at91/clk-sam9x60-pll.c > index dfb91c190bd1..00f2afd6e9b6 100644 > --- a/drivers/clk/at91/clk-sam9x60-pll.c > +++ b/drivers/clk/at91/clk-sam9x60-pll.c > @@ -21,6 +21,9 @@ > #define UPLL_DIV 2 > #define PLL_MUL_MAX (FIELD_GET(PMC_PLL_CTRL1_MUL_MSK, UINT_MAX) + 1) > > +#define FCORE_MIN (600000000) > +#define FCORE_MAX (1200000000) > + > #define PLL_MAX_ID 1 > > struct sam9x60_pll { > @@ -169,6 +172,7 @@ static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll, > unsigned long bestdiv = 0; > unsigned long bestmul = 0; > unsigned long bestfrac = 0; > + unsigned long long fcore = 0; maybe it would be best to go for u64 here as this is what you cast into later. > > if (rate < characteristics->output[0].min || > rate > characteristics->output[0].max) > @@ -213,6 +217,11 @@ static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll, > remainder = rate - tmprate; > } > > + fcore = parent_rate * (tmpmul + 1) + > + ((u64)parent_rate * tmpfrac >> 22); > + if (fcore < FCORE_MIN || fcore > FCORE_MAX) > + continue; > + > /* > * Compare the remainder with the best remainder found until > * now and elect a new best multiplier/divider pair if the > @@ -232,7 +241,8 @@ static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll, > } > > /* Check if bestrate is a valid output rate */ > - if (bestrate < characteristics->output[0].min || > + if (fcore < FCORE_MIN || fcore > FCORE_MAX || > + bestrate < characteristics->output[0].min || > bestrate > characteristics->output[0].max) > return -ERANGE; > > diff --git a/drivers/clk/at91/sam9x60.c b/drivers/clk/at91/sam9x60.c > index 3e20aa68259f..633891b98d43 100644 > --- a/drivers/clk/at91/sam9x60.c > +++ b/drivers/clk/at91/sam9x60.c > @@ -22,7 +22,7 @@ static const struct clk_master_layout sam9x60_master_layout = { > }; > > static const struct clk_range plla_outputs[] = { > - { .min = 300000000, .max = 600000000 }, > + { .min = 2343750, .max = 1200000000 }, > }; > > static const struct clk_pll_characteristics plla_characteristics = { > -- > 2.7.4 > -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com 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=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 1AC20C433DF for ; Fri, 17 Jul 2020 09:29:03 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 629782063A for ; Fri, 17 Jul 2020 09:29:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="fnUD/YTp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 629782063A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bootlin.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=d2e0umtujG7/Zo2FS1Rl5SIYIIwuYTOrMhe5oGTNpS4=; b=fnUD/YTpxaAoW4cG5cGZinVLL qctXAI2ZmLbUyhsCRJo+yfehKkeCyR39Eg/AIelj5ZvHV8w2s+Se6FosD9/yd+naGMQIFe0HNLWGg ikC+mncPWjNmszHBbrSEDXYWMNIZrNc6ZI9Ze6o/hwD0f/wV+moXHKsMjn0mR7u3WPQ+L/JmFFSsb 10UdqDY+1K9MJqt09wyFkEji50YIDJB6FGgYRmw/KHPH0cIdMh8OKP6EOlIkwEMcHSPfJIQZNuwPu NAzwrXlmVdzVgGXZpq6ytlWrEyv0QF33Gd1+pEF/4fe5B0koc+BlGNcu1nQUf/xfH1S78yf8Z2hUz 1cV95AS+g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jwMdt-0004xt-KD; Fri, 17 Jul 2020 09:26:57 +0000 Received: from relay8-d.mail.gandi.net ([217.70.183.201]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jwMca-0004Lj-PT for linux-arm-kernel@lists.infradead.org; Fri, 17 Jul 2020 09:25:38 +0000 X-Originating-IP: 90.65.108.121 Received: from localhost (lfbn-lyo-1-1676-121.w90-65.abo.wanadoo.fr [90.65.108.121]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 930011BF235; Fri, 17 Jul 2020 09:23:54 +0000 (UTC) Date: Fri, 17 Jul 2020 11:23:54 +0200 From: Alexandre Belloni To: Claudiu Beznea Subject: Re: [PATCH 06/19] clk: at91: sam9x60-pll: check fcore against ranges Message-ID: <20200717092354.GO3428@piout.net> References: <1594812267-6697-1-git-send-email-claudiu.beznea@microchip.com> <1594812267-6697-7-git-send-email-claudiu.beznea@microchip.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1594812267-6697-7-git-send-email-claudiu.beznea@microchip.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200717_052537_044086_CD8A1F5B X-CRM114-Status: GOOD ( 20.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bbrezillon@kernel.org, sboyd@kernel.org, mturquette@baylibre.com, linux-kernel@vger.kernel.org, ludovic.desroches@microchip.com, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 15/07/2020 14:24:14+0300, Claudiu Beznea wrote: > According to datasheet the range of 600-1200MHz is for the the the is repeated here > frequency generated by the fractional part of the PLL (namely > Fcorepllck according to datasheet). With this in mind the output > range of the PLL itself (fractional + div), taking into account > that the diverder is 8 bits wide, is 600/256-1200Hz=2.3-1200MHz. > divider > Fixes: a436c2a447e59 ("clk: at91: add sam9x60 PLL driver") > Signed-off-by: Claudiu Beznea > --- > drivers/clk/at91/clk-sam9x60-pll.c | 12 +++++++++++- > drivers/clk/at91/sam9x60.c | 2 +- > 2 files changed, 12 insertions(+), 2 deletions(-) > > diff --git a/drivers/clk/at91/clk-sam9x60-pll.c b/drivers/clk/at91/clk-sam9x60-pll.c > index dfb91c190bd1..00f2afd6e9b6 100644 > --- a/drivers/clk/at91/clk-sam9x60-pll.c > +++ b/drivers/clk/at91/clk-sam9x60-pll.c > @@ -21,6 +21,9 @@ > #define UPLL_DIV 2 > #define PLL_MUL_MAX (FIELD_GET(PMC_PLL_CTRL1_MUL_MSK, UINT_MAX) + 1) > > +#define FCORE_MIN (600000000) > +#define FCORE_MAX (1200000000) > + > #define PLL_MAX_ID 1 > > struct sam9x60_pll { > @@ -169,6 +172,7 @@ static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll, > unsigned long bestdiv = 0; > unsigned long bestmul = 0; > unsigned long bestfrac = 0; > + unsigned long long fcore = 0; maybe it would be best to go for u64 here as this is what you cast into later. > > if (rate < characteristics->output[0].min || > rate > characteristics->output[0].max) > @@ -213,6 +217,11 @@ static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll, > remainder = rate - tmprate; > } > > + fcore = parent_rate * (tmpmul + 1) + > + ((u64)parent_rate * tmpfrac >> 22); > + if (fcore < FCORE_MIN || fcore > FCORE_MAX) > + continue; > + > /* > * Compare the remainder with the best remainder found until > * now and elect a new best multiplier/divider pair if the > @@ -232,7 +241,8 @@ static long sam9x60_pll_get_best_div_mul(struct sam9x60_pll *pll, > } > > /* Check if bestrate is a valid output rate */ > - if (bestrate < characteristics->output[0].min || > + if (fcore < FCORE_MIN || fcore > FCORE_MAX || > + bestrate < characteristics->output[0].min || > bestrate > characteristics->output[0].max) > return -ERANGE; > > diff --git a/drivers/clk/at91/sam9x60.c b/drivers/clk/at91/sam9x60.c > index 3e20aa68259f..633891b98d43 100644 > --- a/drivers/clk/at91/sam9x60.c > +++ b/drivers/clk/at91/sam9x60.c > @@ -22,7 +22,7 @@ static const struct clk_master_layout sam9x60_master_layout = { > }; > > static const struct clk_range plla_outputs[] = { > - { .min = 300000000, .max = 600000000 }, > + { .min = 2343750, .max = 1200000000 }, > }; > > static const struct clk_pll_characteristics plla_characteristics = { > -- > 2.7.4 > -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel