]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
riscv: timer: Add support for an early timer
authorPragnesh Patel <pragnesh.patel@sifive.com>
Sun, 17 Jan 2021 12:41:25 +0000 (18:11 +0530)
committerAndes <uboot@andestech.com>
Mon, 18 Jan 2021 03:06:32 +0000 (11:06 +0800)
Added support for timer_early_get_count() and timer_early_get_rate()
This is mostly useful in tracing.

Signed-off-by: Pragnesh Patel <pragnesh.patel@sifive.com>
Reviewed-by: Rick Chen <rick@andestech.com>
drivers/timer/andes_plmt_timer.c
drivers/timer/riscv_timer.c
drivers/timer/sifive_clint_timer.c
include/configs/ax25-ae350.h
include/configs/qemu-riscv.h
include/configs/sifive-fu540.h

index db2cf86f638a1b016b8bd1d8f5ae2acc8e16c716..a3797b22c74c4b3198a0c270ed48daabc97a3ee5 100644 (file)
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base))
 
-static u64 andes_plmt_get_count(struct udevice *dev)
+static u64 notrace andes_plmt_get_count(struct udevice *dev)
 {
        return readq((void __iomem *)MTIME_REG(dev_get_priv(dev)));
 }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE) && IS_ENABLED(CONFIG_TIMER_EARLY)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+ */
+unsigned long notrace timer_early_get_rate(void)
+{
+       return RISCV_MMODE_TIMER_FREQ;
+}
+
+/**
+ * timer_early_get_count() - Get the timer count before driver model
+ *
+ */
+u64 notrace timer_early_get_count(void)
+{
+       return readq((void __iomem *)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops andes_plmt_ops = {
        .get_count = andes_plmt_get_count,
 };
index 21ae1840571a23d29d12b494d89f5b8352b190a1..3627ed79b8196b11d129cea6872a1bafbb3139af 100644 (file)
@@ -16,7 +16,7 @@
 #include <timer.h>
 #include <asm/csr.h>
 
-static u64 riscv_timer_get_count(struct udevice *dev)
+static u64 notrace riscv_timer_get_count(struct udevice *dev)
 {
        __maybe_unused u32 hi, lo;
 
@@ -31,6 +31,25 @@ static u64 riscv_timer_get_count(struct udevice *dev)
        return ((u64)hi << 32) | lo;
 }
 
+#if CONFIG_IS_ENABLED(RISCV_SMODE) && IS_ENABLED(CONFIG_TIMER_EARLY)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+ */
+unsigned long notrace timer_early_get_rate(void)
+{
+       return RISCV_SMODE_TIMER_FREQ;
+}
+
+/**
+ * timer_early_get_count() - Get the timer count before driver model
+ *
+ */
+u64 notrace timer_early_get_count(void)
+{
+       return riscv_timer_get_count(NULL);
+}
+#endif
+
 static int riscv_timer_probe(struct udevice *dev)
 {
        struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
index de23b85404b66cf2a4cb91beb6b68ad7ed70289c..de7b4b95c9e9a89a53d59d52186d2d8d70be2f0a 100644 (file)
 /* mtime register */
 #define MTIME_REG(base)                        ((ulong)(base) + 0xbff8)
 
-static u64 sifive_clint_get_count(struct udevice *dev)
+static u64 notrace sifive_clint_get_count(struct udevice *dev)
 {
        return readq((void __iomem *)MTIME_REG(dev_get_priv(dev)));
 }
 
+#if CONFIG_IS_ENABLED(RISCV_MMODE) && IS_ENABLED(CONFIG_TIMER_EARLY)
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+ */
+unsigned long notrace timer_early_get_rate(void)
+{
+       return RISCV_MMODE_TIMER_FREQ;
+}
+
+/**
+ * timer_early_get_count() - Get the timer count before driver model
+ *
+ */
+u64 notrace timer_early_get_count(void)
+{
+       return readq((void __iomem *)MTIME_REG(RISCV_MMODE_TIMERBASE));
+}
+#endif
+
 static const struct timer_ops sifive_clint_ops = {
        .get_count = sifive_clint_get_count,
 };
index b2606e794dd27dc54051bddbb5ecff5ad9b2198b..bd9c371f83551a944c727ae5ab1f0c0d0ee91a09 100644 (file)
 #endif
 #endif
 
+#define RISCV_MMODE_TIMERBASE           0xe6000000
+#define RISCV_MMODE_TIMER_FREQ          60000000
+
+#define RISCV_SMODE_TIMER_FREQ          60000000
+
 /*
  * CPU and Board Configuration Options
  */
index a2f33587c2418da0f34010fde8e9a0143e42190c..5291de83f8d8ca92e3718deedf0bf6c491a0c35a 100644 (file)
 
 #define CONFIG_STANDALONE_LOAD_ADDR    0x80200000
 
+#define RISCV_MMODE_TIMERBASE          0x2000000
+#define RISCV_MMODE_TIMER_FREQ         1000000
+
+#define RISCV_SMODE_TIMER_FREQ         1000000
+
 /* Environment options */
 
 #ifndef CONFIG_SPL_BUILD
index c1c79db1474579c209f07108a8ef9d8451182f34..0d69d1c5482382b724e7f40a630f5b09f11c60aa 100644 (file)
 
 #define CONFIG_STANDALONE_LOAD_ADDR    0x80200000
 
+#define RISCV_MMODE_TIMERBASE          0x2000000
+#define RISCV_MMODE_TIMER_FREQ         1000000
+
+#define RISCV_SMODE_TIMER_FREQ         1000000
+
 /* Environment options */
 
 #ifndef CONFIG_SPL_BUILD