From patchwork Wed Jul 22 07:38:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 11677607 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3E4FF1510 for ; Wed, 22 Jul 2020 07:41:05 +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 10C3120729 for ; Wed, 22 Jul 2020 07:41:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="UQKvbk+V"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="Sqg9nM2h" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 10C3120729 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.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:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=CSrJVRXRlsJJNPQET7BdG5Bk1fbIU6VWIMT1FjZyXSI=; b=UQKvbk+Ve39HYuaA/0ONloXaB 5Zzu+TJ1nl+icoyA74bcn/5XV4sc/4vEfw6uh/P55eb7qS8RG7qqPh/5K2UMmw3r6kiDwsjyC3M2u Z4NHtrMaAKe6lxd6/CqdJ/UjUf41u1jRHeJjg8TUC80yH/SRnfNmYydhZGqvfhLpVKaUZITrBMBSQ Z8PwgGA6zAgZ5DDRUxgS1ypsAh7V0DgsR8NKYCE6VZQ/KSpwwYBcGtI1egerPbFRrrZybzQDCHniK A1jhGqPhpeO4ipMf6Wu2C82gy62nDp8Q04IO7nuryFvMhLO7ed2vpiZjXm0pD2HDZ1YnaN0wGqaR3 GteChP5SQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jy9LJ-0008FH-PZ; Wed, 22 Jul 2020 07:39:09 +0000 Received: from esa4.microchip.iphmx.com ([68.232.154.123]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jy9L3-00086R-Vw for linux-arm-kernel@lists.infradead.org; Wed, 22 Jul 2020 07:38:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1595403533; x=1626939533; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=ZMfmkZLf18cxA6G2RiBnRE2pCDJaovxhZuoeHxv76X4=; b=Sqg9nM2h0tBsKfCWgSR94Z4YWxBmM2hepSziN8m4xVZXbrXuQWQUOk8X 3EUCM0WUzk7Xkm+45GZ0sOr7CkJuz2v6KOT5ADNWzHnzHwE3YGLSOM6FL ++1MdHhvkDZVr+IpGJFkTmFsHRk9/Wqmn/9RAb0XsPzxNOOkIP6zcPC35 /JbUR/iYDOvwQhBHYGV9/RSBgHC6O5o4YZal4uZvBQdfVj/2aGc3X+bpl siiuge4mTlI9SSkS9K7nl/PyOgrfZ5PleYUvqKBFs+jcTmqxDSsuKXby5 4sjg6lZDicVOuJMTWbqJAilF3Ximcndf022x2rxe5DHfWLbNj8OTV84Z8 Q==; IronPort-SDR: xdrfu5N5GYcIT4DRsXaFv+Y2ancADjSTvSjLDJ8NzIUlZIWPNirDtz2YDRnaW5uF0+nHllBxrj cSCoxFlLnSOm0rNtyGn7mHSZn3yYTd7Jk/NPr5Jd2uAHhfrg2VJkuh9fhHRlyZll33nkGfQFmI FeQoezfyxJqm7GYn2JXwsW22azEUK4LblLyGPADggdv0XQC1Z9cvFt9NMUxujtMAJrYlp3LWJH sbeyXA/TiXDI01iy+9q01tZKx+/Ua3bNvEGDz+rQS6A1Gdwv7jVYFnWCVKEEETa0YPlx6Us6Q6 cxk= X-IronPort-AV: E=Sophos;i="5.75,381,1589266800"; d="scan'208";a="80862128" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 22 Jul 2020 00:38:52 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Wed, 22 Jul 2020 00:38:51 -0700 Received: from m18063-ThinkPad-T460p.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.1979.3 via Frontend Transport; Wed, 22 Jul 2020 00:38:48 -0700 From: Claudiu Beznea To: , , , , Subject: [PATCH v2 05/18] clk: at91: sam9x60-pll: check fcore against ranges Date: Wed, 22 Jul 2020 10:38:13 +0300 Message-ID: <1595403506-8209-6-git-send-email-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1595403506-8209-1-git-send-email-claudiu.beznea@microchip.com> References: <1595403506-8209-1-git-send-email-claudiu.beznea@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200722_033854_286752_25DC5B99 X-CRM114-Status: GOOD ( 15.18 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.154.123 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [68.232.154.123 listed in wl.mailspike.net] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders 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: Claudiu Beznea , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, bbrezillon@kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org According to datasheet the range of 600-1200MHz is for the 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 divider is 8 bits wide, is 600/256-1200Hz=2.3-1200MHz. 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 4b7b6c435d4e..a933abebfbaf 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 { @@ -168,6 +171,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; + u64 fcore = 0; if (rate < characteristics->output[0].min || rate > characteristics->output[0].max) @@ -212,6 +216,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 @@ -231,7 +240,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 = {