From patchwork Thu May 7 16:14:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anson Huang X-Patchwork-Id: 6354561 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A6421BEEE1 for ; Thu, 7 May 2015 08:24:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D44C020386 for ; Thu, 7 May 2015 08:24:02 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E870220320 for ; Thu, 7 May 2015 08:24:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YqH3y-0000zW-U6; Thu, 07 May 2015 08:21:46 +0000 Received: from mail-by2on0127.outbound.protection.outlook.com ([207.46.100.127] helo=na01-by2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YqH3v-0000rM-9f for linux-arm-kernel@lists.infradead.org; Thu, 07 May 2015 08:21:43 +0000 Received: from DM2PR03CA0033.namprd03.prod.outlook.com (10.141.96.32) by BY1PR0301MB1191.namprd03.prod.outlook.com (10.160.195.15) with Microsoft SMTP Server (TLS) id 15.1.154.19; Thu, 7 May 2015 08:21:20 +0000 Received: from BL2FFO11FD017.protection.gbl (2a01:111:f400:7c09::107) by DM2PR03CA0033.outlook.office365.com (2a01:111:e400:2428::32) with Microsoft SMTP Server (TLS) id 15.1.160.16 via Frontend Transport; Thu, 7 May 2015 08:21:20 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; lists.infradead.org; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BL2FFO11FD017.mail.protection.outlook.com (10.173.161.35) with Microsoft SMTP Server (TLS) id 15.1.160.8 via Frontend Transport; Thu, 7 May 2015 08:21:19 +0000 Received: from anson-OptiPlex-790.ap.freescale.net (anson-OptiPlex-790.ap.freescale.net [10.192.242.118]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t478LGWT022952; Thu, 7 May 2015 01:21:16 -0700 From: Anson Huang To: , , , , Subject: [PATCH V3] ARM: imx: correct Audio/Video PLL rate calculation formula Date: Fri, 8 May 2015 00:14:24 +0800 Message-ID: <1431015264-8320-1-git-send-email-b20788@freescale.com> X-Mailer: git-send-email 1.9.1 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(339900001)(189002)(199003)(2201001)(85426001)(50466002)(19580405001)(77156002)(62966003)(33646002)(19580395003)(106466001)(6806004)(104016003)(46102003)(5001960100002)(47776003)(229853001)(5001920100001)(36756003)(50986999)(48376002)(77096005)(87936001)(5001770100001)(105606002)(92566002)(189998001)(50226001)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:BY1PR0301MB1191; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0301MB1191; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:BY1PR0301MB1191; BCL:0; PCL:0; RULEID:; SRVR:BY1PR0301MB1191; X-Forefront-PRVS: 056929CBB8 X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2015 08:21:19.6711 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0301MB1191 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150507_012143_346574_009E7E9D X-CRM114-Status: UNSURE ( 8.68 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.0 (/) Cc: linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00, DATE_IN_FUTURE_06_12, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The audio/video PLL's rate calculation formula is as below in RM: Fref * (DIV_SELECT + NUM / DENOM), in original clk-pllv3's code, below code is used: (parent_rate * div) + ((parent_rate / mfd) * mfn) as it does NOT consider the float data using div, so below calculation formula should be used as a decent method: (parent_rate * div) + ((parent_rate * mfn) / mfd) and we also need to consider parent_rate * mfd may exceed a 32 bit value, 64 bit value should be used. Below is one example of old/new formula's difference: On i.MX7D, DRAM PLL is a Audio/Video type PLL, the target freq is 1066MHz, the register settings are as below: PLL_DDRn: 8060202C -> div = 0x2C DDR_NUM: 06AAAC4D -> mfn = 0x6AAAC4D DDR_DENOM: 100003EC -> mfd = 0x100003EC parent_rate = 24MHz. with old formula, the (parent_rate / mfd) * mfn = 0, with new formula, the (parent_rate * mfn) / mfd = 10MHz, so old formula gets PLL_DDR = 1056MHz, while the updated formuls gets PLL_DDR = 1066MHz which exactly matches the real rate. Signed-off-by: Anson Huang --- changes since V2: improve commit message; replace s64 with u64 to match do_div. drivers/clk/imx/clk-pllv3.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/clk/imx/clk-pllv3.c b/drivers/clk/imx/clk-pllv3.c index 641ebc5..e34a925 100644 --- a/drivers/clk/imx/clk-pllv3.c +++ b/drivers/clk/imx/clk-pllv3.c @@ -203,8 +203,13 @@ static unsigned long clk_pllv3_av_recalc_rate(struct clk_hw *hw, u32 mfn = readl_relaxed(pll->base + PLL_NUM_OFFSET); u32 mfd = readl_relaxed(pll->base + PLL_DENOM_OFFSET); u32 div = readl_relaxed(pll->base) & pll->div_mask; + u64 temp64 = parent_rate; + + temp64 *= mfn; + do_div(temp64, mfd); + + return (parent_rate * div) + temp64; - return (parent_rate * div) + ((parent_rate / mfd) * mfn); } static long clk_pllv3_av_round_rate(struct clk_hw *hw, unsigned long rate,