Merge tag 'u-boot-rockchip-20200531' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / drivers / timer / cadence-ttc.c
index 3541e5c841278fa308697ef94876406ebd7f9634..e6b6dfe3765c3bec2c96a2662556fe221bb3e550 100644 (file)
@@ -4,10 +4,14 @@
  */
 
 #include <common.h>
+#include <bootstage.h>
 #include <dm.h>
 #include <errno.h>
+#include <init.h>
 #include <timer.h>
 #include <asm/io.h>
+#include <linux/bitops.h>
+#include <linux/err.h>
 
 #define CNT_CNTRL_RESET                BIT(4)
 
@@ -31,6 +35,28 @@ struct cadence_ttc_priv {
        struct cadence_ttc_regs *regs;
 };
 
+#if CONFIG_IS_ENABLED(BOOTSTAGE)
+ulong timer_get_boot_us(void)
+{
+       u64 ticks = 0;
+       u32 rate = 1;
+       u64 us;
+       int ret;
+
+       ret = dm_timer_init();
+       if (!ret) {
+               /* The timer is available */
+               rate = timer_get_rate(gd->timer);
+               timer_get_count(gd->timer, &ticks);
+       } else {
+               return 0;
+       }
+
+       us = (ticks * 1000) / rate;
+       return us;
+}
+#endif
+
 static int cadence_ttc_get_count(struct udevice *dev, u64 *count)
 {
        struct cadence_ttc_priv *priv = dev_get_priv(dev);
@@ -89,5 +115,4 @@ U_BOOT_DRIVER(cadence_ttc) = {
        .priv_auto_alloc_size = sizeof(struct cadence_ttc_priv),
        .probe = cadence_ttc_probe,
        .ops = &cadence_ttc_ops,
-       .flags = DM_FLAG_PRE_RELOC,
 };