]> git.sur5r.net Git - u-boot/commitdiff
dm: timer: uclass: add timer init in uclass driver to add timer device
authorMugunthan V N <mugunthanvnm@ti.com>
Sat, 16 Jan 2016 16:03:58 +0000 (21:33 +0530)
committerSimon Glass <sjg@chromium.org>
Thu, 21 Jan 2016 02:06:21 +0000 (19:06 -0700)
Adding timer init function in timer-uclass driver to create and
initialize the timer device on platforms where u-boot,dm-pre-reloc
is not used. Since there will be multiple timer devices in the
system, adding a tick-timer node in chosen node to know which
timer device to be used as tick timer in u-boot.

Signed-off-by: Mugunthan V N <mugunthanvnm@ti.com>
doc/device-tree-bindings/chosen.txt [new file with mode: 0644]
drivers/timer/timer-uclass.c
include/timer.h
lib/time.c

diff --git a/doc/device-tree-bindings/chosen.txt b/doc/device-tree-bindings/chosen.txt
new file mode 100644 (file)
index 0000000..bf9a30a
--- /dev/null
@@ -0,0 +1,43 @@
+The chosen node
+---------------
+The chosen node does not represent a real device, but serves as a place
+for passing data like which serial device to used to print the logs etc
+
+
+stdout-path property
+--------------------
+Device trees may specify the device to be used for boot console output
+with a stdout-path property under /chosen.
+
+Example
+-------
+/ {
+       chosen {
+               stdout-path = "/serial@f00:115200";
+       };
+
+       serial@f00 {
+               compatible = "vendor,some-uart";
+               reg = <0xf00 0x10>;
+       };
+};
+
+tick-timer property
+-------------------
+In a system there are multiple timers, specify which timer to be used
+as the tick-timer. Earlier it was hardcoded in the timer driver now
+since device tree has all the timer nodes. Specify which timer to be
+used as tick timer.
+
+Example
+-------
+/ {
+       chosen {
+               tick-timer = "/timer2@f00";
+       };
+
+       timer2@f00 {
+               compatible = "vendor,some-timer";
+               reg = <0xf00 0x10>;
+       };
+};
index aca421bdea331c4193d98adaf8ec350402ca23d6..04801784ba854d24c2be8823e5950f5809804495 100644 (file)
@@ -6,6 +6,8 @@
 
 #include <common.h>
 #include <dm.h>
+#include <dm/lists.h>
+#include <dm/device-internal.h>
 #include <errno.h>
 #include <timer.h>
 
@@ -56,6 +58,48 @@ u64 timer_conv_64(u32 count)
        return ((u64)gd->timebase_h << 32) | gd->timebase_l;
 }
 
+int notrace dm_timer_init(void)
+{
+       const void *blob = gd->fdt_blob;
+       struct udevice *dev = NULL;
+       int node;
+       int ret;
+
+       if (gd->timer)
+               return 0;
+
+       /* Check for a chosen timer to be used for tick */
+       node = fdtdec_get_chosen_node(blob, "tick-timer");
+       if (node < 0) {
+               /* No chosen timer, trying first available timer */
+               ret = uclass_first_device(UCLASS_TIMER, &dev);
+               if (ret)
+                       return ret;
+               if (!dev)
+                       return -ENODEV;
+       } else {
+               if (uclass_get_device_by_of_offset(UCLASS_TIMER, node, &dev)) {
+                       /*
+                        * If the timer is not marked to be bound before
+                        * relocation, bind it anyway.
+                        */
+                       if (node > 0 &&
+                           !lists_bind_fdt(gd->dm_root, blob, node, &dev)) {
+                               ret = device_probe(dev);
+                               if (ret)
+                                       return ret;
+                       }
+               }
+       }
+
+       if (dev) {
+               gd->timer = dev;
+               return 0;
+       }
+
+       return -ENODEV;
+}
+
 UCLASS_DRIVER(timer) = {
        .id             = UCLASS_TIMER,
        .name           = "timer",
index 7fee17e3d24193c105f44f61ff2f099dc56811eb..f14725cc280b5f93a8074f329b5b4641fbb69753 100644 (file)
@@ -7,6 +7,15 @@
 #ifndef _TIMER_H_
 #define _TIMER_H_
 
+/*
+ * dm_timer_init - initialize a timer for time keeping. On success
+ * initializes gd->timer so that lib/timer can use it for future
+ * referrence.
+ *
+ * @return - 0 on success or error number
+ */
+int dm_timer_init(void);
+
 /*
  * timer_conv_64 - convert 32-bit counter value to 64-bit
  *
index f37a6628d6e80d56e36d4cbaab4f0481a3a3048f..e9f6861b9843773f780ec3bd278340dcb55a2a2e 100644 (file)
@@ -41,23 +41,6 @@ extern unsigned long __weak timer_read_counter(void);
 #endif
 
 #ifdef CONFIG_TIMER
-static int notrace dm_timer_init(void)
-{
-       struct udevice *dev;
-       int ret;
-
-       if (!gd->timer) {
-               ret = uclass_first_device(UCLASS_TIMER, &dev);
-               if (ret)
-                       return ret;
-               if (!dev)
-                       return -ENODEV;
-               gd->timer = dev;
-       }
-
-       return 0;
-}
-
 ulong notrace get_tbclk(void)
 {
        int ret;