aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorZakharov Vlad <Vladislav.Zakharov@synopsys.com>2016-12-09 17:18:32 +0300
committerTom Rini <trini@konsulko.com>2016-12-27 11:24:10 -0500
commita5acafb25598ef409f48a7884316a9a4e96c63a4 (patch)
tree07dfbc12afa1c0ff70ec4731e6cb3b9e02afc995 /drivers
parentbd2e9714c851770652253fab858cb50ecd95d329 (diff)
downloadu-boot-a5acafb25598ef409f48a7884316a9a4e96c63a4.zip
u-boot-a5acafb25598ef409f48a7884316a9a4e96c63a4.tar.gz
u-boot-a5acafb25598ef409f48a7884316a9a4e96c63a4.tar.bz2
timer: Support clocks via phandle
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 <vzakhar@synopsys.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/timer/timer-uclass.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c
index f8ddf93..5c63e6b 100644
--- a/drivers/timer/timer-uclass.c
+++ b/drivers/timer/timer-uclass.c
@@ -8,6 +8,7 @@
#include <dm.h>
#include <dm/lists.h>
#include <dm/device-internal.h>
+#include <clk.h>
#include <errno.h>
#include <timer.h>
@@ -42,9 +43,19 @@ 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;
+ ulong ret;
+
+ err = clk_get_by_index(dev, 0, &timer_clk);
+ if (!err) {
+ ret = clk_get_rate(&timer_clk);
+ if (IS_ERR_VALUE(ret))
+ return ret;
+ uc_priv->clock_rate = ret;
+ } else
+ uc_priv->clock_rate = fdtdec_get_int(gd->fdt_blob,
+ dev->of_offset, "clock-frequency", 0);
return 0;
}