From patchwork Fri Jan 27 13:15:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Longchamp X-Patchwork-Id: 720669 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3v8zxb4Y7vz9t1L for ; Sat, 28 Jan 2017 00:23:15 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3v8zxb3kfXzDqjj for ; Sat, 28 Jan 2017 00:23:15 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-de.keymile.com (mail-de.keymile.com [195.8.104.250]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3v8zv61365zDqZl for ; Sat, 28 Jan 2017 00:21:06 +1100 (AEDT) Received: from secmail.keymile.com ([195.8.104.201]:40255 helo=totemomail) by mail-de.keymile.com with smtp (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1cX6NB-0006xr-00; Fri, 27 Jan 2017 14:15:25 +0100 Received: from 10.9.1.54 ([10.9.1.54]) by secmail.keymile.com (Totemo SMTP Server) with SMTP ID 286; Fri, 27 Jan 2017 14:16:03 +0100 (CET) Received: from ch10650.keymile.net ([172.31.34.66]) by mailrelay.keymile.net (8.12.2/8.12.2) with ESMTP id v0RDFKMp014180; Fri, 27 Jan 2017 14:15:23 +0100 (MET) From: Valentin Longchamp To: linuxppc-dev@lists.ozlabs.org Subject: [RFC 1/3] soc/fsl/qe: round brg_freq to 1kHz granularity Date: Fri, 27 Jan 2017 14:15:15 +0100 Message-Id: <1485522917-2150-2-git-send-email-valentin.longchamp@keymile.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1485522917-2150-1-git-send-email-valentin.longchamp@keymile.com> References: <1485522917-2150-1-git-send-email-valentin.longchamp@keymile.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: oss@buserror.net, Valentin Longchamp , qiang.zhao@nxp.com Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Because of integer computation rounding in u-boot (that sets the QE brg-frequency DTS prop), the clk value is 99999999 Hz even though it is 100 MHz. When setting brg clks that are exact divisors of 100 MHz, this small differnce plays a role and can result in lower clks to be output (for instance 20 MHz - divide by 5 - results in 16.666 MHz - divide by 6). This patch fixes that by "forcing" the brg_clk to the nearest kHz when the difference is below 2 integer rouding errors (i.e. 4). Signed-off-by: Valentin Longchamp --- drivers/soc/fsl/qe/qe.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c index 2707a82..5482302 100644 --- a/drivers/soc/fsl/qe/qe.c +++ b/drivers/soc/fsl/qe/qe.c @@ -163,11 +163,15 @@ int qe_issue_cmd(u32 cmd, u32 device, u8 mcn_protocol, u32 cmd_input) */ static unsigned int brg_clk = 0; +#define CLK_GRAN (1000) +#define CLK_GRAN_LIMIT (5) + unsigned int qe_get_brg_clk(void) { struct device_node *qe; int size; const u32 *prop; + unsigned int mod; if (brg_clk) return brg_clk; @@ -185,6 +189,15 @@ unsigned int qe_get_brg_clk(void) of_node_put(qe); + /* round this if near to a multiple of CLK_GRAN */ + mod = brg_clk % CLK_GRAN; + if (mod) { + if (mod < CLK_GRAN_LIMIT) + brg_clk -= mod; + else if (mod > (CLK_GRAN - CLK_GRAN_LIMIT)) + brg_clk += CLK_GRAN - mod; + } + return brg_clk; } EXPORT_SYMBOL(qe_get_brg_clk);