@@ -13,6 +13,7 @@
#include <common.h>
#include <dm.h>
#include <errno.h>
+#include <fdt_support.h>
#include <timer.h>
#include <asm/csr.h>
@@ -53,9 +54,18 @@ u64 notrace timer_early_get_count(void)
static int riscv_timer_probe(struct udevice *dev)
{
struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
-
/* clock frequency was passed from the cpu driver as driver data */
- uc_priv->clock_rate = dev->driver_data;
+ u32 rate = dev->driver_data;
+
+ if (!rate && gd->fdt_blob) { /* not called from CPU driver? */
+ rate = fdt_getprop_u32_default(gd->fdt_blob,
+ "/cpus", "timebase-frequency", 0);
+ }
+ uc_priv->clock_rate = rate;
+
+ /* timer uclass post_probe will later fail with -EINVAL. Hint at the cause! */
+ if (!rate)
+ log_err("riscv_timer_probe with clock rate 0\n");
return 0;
}
@@ -64,10 +74,15 @@ static const struct timer_ops riscv_timer_ops = {
.get_count = riscv_timer_get_count,
};
+static const struct udevice_id riscv_timer_ids[] = {
+ { .compatible = "riscv,timer", },
+ { }
+};
+
U_BOOT_DRIVER(riscv_timer) = {
.name = "riscv_timer",
.id = UCLASS_TIMER,
+ .of_match = of_match_ptr(riscv_timer_ids),
.probe = riscv_timer_probe,
.ops = &riscv_timer_ops,
- .flags = DM_FLAG_PRE_RELOC,
};
@@ -6,6 +6,7 @@
/dts-v1/;
#include <dt-bindings/clock/starfive,jh7110-crg.h>
#include <dt-bindings/reset/starfive,jh7110-crg.h>
+#include <dt-bindings/interrupt-controller/riscv-hart.h>
/ {
compatible = "starfive,jh7110";
@@ -204,6 +205,15 @@
};
};
+ timer {
+ compatible = "riscv,timer";
+ interrupts-extended = <&cpu0_intc HART_INT_S_TIMER>,
+ <&cpu1_intc HART_INT_S_TIMER>,
+ <&cpu2_intc HART_INT_S_TIMER>,
+ <&cpu3_intc HART_INT_S_TIMER>,
+ <&cpu4_intc HART_INT_S_TIMER>;
+ };
+
osc: oscillator {
compatible = "fixed-clock";
clock-output-names = "osc";
@@ -102,4 +102,3 @@ CONFIG_PINCTRL_STARFIVE=y
# CONFIG_RAM_SIFIVE is not set
CONFIG_SYS_NS16550=y
CONFIG_CADENCE_QSPI=y
-CONFIG_TIMER_EARLY=y