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>
#include <dm.h>
#include <dm/lists.h>
#include <dm/device-internal.h>
+#include <clk.h>
#include <errno.h>
#include <timer.h>
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;
}