Merge tag 'u-boot-rockchip-20200531' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / drivers / cpu / riscv_cpu.c
index 5e15df590e4a888721a7095802c9726fab9baa1a..cb04f5638db16b69c9625617456fc7684fe285ab 100644 (file)
@@ -7,8 +7,12 @@
 #include <cpu.h>
 #include <dm.h>
 #include <errno.h>
+#include <log.h>
 #include <dm/device-internal.h>
 #include <dm/lists.h>
+#include <linux/bitops.h>
+
+DECLARE_GLOBAL_DATA_PTR;
 
 static int riscv_cpu_get_desc(struct udevice *dev, char *buf, int size)
 {
@@ -44,6 +48,10 @@ static int riscv_cpu_get_count(struct udevice *dev)
        ofnode_for_each_subnode(node, dev_ofnode(dev->parent)) {
                const char *device_type;
 
+               /* skip if hart is marked as not available in the device tree */
+               if (!ofnode_is_available(node))
+                       continue;
+
                device_type = ofnode_read_string(node, "device_type");
                if (!device_type)
                        continue;
@@ -62,7 +70,6 @@ static int riscv_cpu_bind(struct udevice *dev)
 
        /* save the hart id */
        plat->cpu_id = dev_read_addr(dev);
-
        /* first examine the property in current cpu node */
        ret = dev_read_u32(dev, "timebase-frequency", &plat->timebase_freq);
        /* if not found, then look at the parent /cpus node */
@@ -71,7 +78,7 @@ static int riscv_cpu_bind(struct udevice *dev)
                             &plat->timebase_freq);
 
        /*
-        * Bind riscv-timer driver on hart 0
+        * Bind riscv-timer driver on boot hart.
         *
         * We only instantiate one timer device which is enough for U-Boot.
         * Pass the "timebase-frequency" value as the driver data for the
@@ -80,7 +87,7 @@ static int riscv_cpu_bind(struct udevice *dev)
         * Return value is not checked since it's possible that the timer
         * driver is not included.
         */
-       if (!plat->cpu_id && plat->timebase_freq) {
+       if (plat->cpu_id == gd->arch.boot_hart && plat->timebase_freq) {
                drv = lists_driver_lookup_name("riscv_timer");
                if (!drv) {
                        debug("Cannot find the timer driver, not included?\n");