From patchwork Thu Nov 17 17:08:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zakharov Vlad X-Patchwork-Id: 696201 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3tKSJn2Whrz9t0X for ; Fri, 18 Nov 2016 04:08:57 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9C8ACA754A; Thu, 17 Nov 2016 18:08:54 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ji49Ii4TsOfW; Thu, 17 Nov 2016 18:08:54 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F2A254B9F9; Thu, 17 Nov 2016 18:08:53 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 976214B9F9 for ; Thu, 17 Nov 2016 18:08:50 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id N85rnH8YSPBR for ; Thu, 17 Nov 2016 18:08:50 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from smtprelay.synopsys.com (us01smtprelay-2.synopsys.com [198.182.47.9]) by theia.denx.de (Postfix) with ESMTPS id 262774B99D for ; Thu, 17 Nov 2016 18:08:46 +0100 (CET) Received: from mailhost.synopsys.com (mailhost3.synopsys.com [10.12.238.238]) by smtprelay.synopsys.com (Postfix) with ESMTP id AC9F024E0344; Thu, 17 Nov 2016 09:08:44 -0800 (PST) Received: from mailhost.synopsys.com (localhost [127.0.0.1]) by mailhost.synopsys.com (Postfix) with ESMTP id 6DFB3E2F; Thu, 17 Nov 2016 09:08:44 -0800 (PST) Received: from vzakhar-8460.internal.synopsys.com (vzakhar-8460.internal.synopsys.com [10.121.14.112]) by mailhost.synopsys.com (Postfix) with ESMTP id 46AD7E17; Thu, 17 Nov 2016 09:08:42 -0800 (PST) From: Vlad Zakharov To: U-Boot Mailing List Date: Thu, 17 Nov 2016 20:08:20 +0300 Message-Id: <1479402500-20064-1-git-send-email-vzakhar@synopsys.com> X-Mailer: git-send-email 2.7.4 Cc: Vlad Zakharov , Alexey Brodkin Subject: [U-Boot] [PATCH] timer: Support clocks via phandle X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Earlier timer driver needed a clock-frequency property in compatible device-tree nodes. Another way is to reference a clock via a phandle. So now timer_pre_probe tries to get clock by reference through device tree. In case it is impossible to get clock device through the reference, clock-frequency property of the timer node is read to provide backward compatibility. Signed-off-by: Vlad Zakharov --- drivers/timer/timer-uclass.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c index f8ddf93..cca41f1 100644 --- a/drivers/timer/timer-uclass.c +++ b/drivers/timer/timer-uclass.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -42,9 +43,17 @@ unsigned long notrace timer_get_rate(struct udevice *dev) static int timer_pre_probe(struct udevice *dev) { struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev); - - uc_priv->clock_rate = fdtdec_get_int(gd->fdt_blob, dev->of_offset, - "clock-frequency", 0); + struct clk *timer_clk; + int err; + + err = clk_get_by_index(dev, 0, timer_clk); + if (!err) { + uc_priv->clock_rate = clk_get_rate(timer_clk); + if (uc_priv->clock_rate < 0) + return uc_priv->clock_rate; + } else + uc_priv->clock_rate = fdtdec_get_int(gd->fdt_blob, + dev->of_offset, "clock-frequency", 0); return 0; }