lib: utils/fdt: Add fdt_parse_timebase_frequency() function
authorAnup Patel <anup.patel@wdc.com>
Tue, 14 Sep 2021 15:35:42 +0000 (21:05 +0530)
committerAnup Patel <anup@brainfault.org>
Sun, 26 Sep 2021 14:22:07 +0000 (19:52 +0530)
We add fdt_parse_timebase_frequency() function which can be used
by ACLINT mtimer driver and platform code to get timebase frequency.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
include/sbi_utils/fdt/fdt_helper.h
lib/utils/fdt/fdt_helper.c

index 2246254..5cb7340 100644 (file)
@@ -50,6 +50,8 @@ int fdt_parse_hart_id(void *fdt, int cpu_offset, u32 *hartid);
 
 int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid);
 
+int fdt_parse_timebase_frequency(void *fdt, unsigned long *freq);
+
 int fdt_parse_gaisler_uart_node(void *fdt, int nodeoffset,
                                struct platform_uart_data *uart);
 
index 5628337..5bf4021 100644 (file)
@@ -269,6 +269,27 @@ int fdt_parse_max_hart_id(void *fdt, u32 *max_hartid)
        return 0;
 }
 
+int fdt_parse_timebase_frequency(void *fdt, unsigned long *freq)
+{
+       const fdt32_t *val;
+       int len, cpus_offset;
+
+       if (!fdt || !freq)
+               return SBI_EINVAL;
+
+       cpus_offset = fdt_path_offset(fdt, "/cpus");
+       if (cpus_offset < 0)
+               return cpus_offset;
+
+       val = fdt_getprop(fdt, cpus_offset, "timebase-frequency", &len);
+       if (len > 0 && val)
+               *freq = fdt32_to_cpu(*val);
+       else
+               return SBI_ENOENT;
+
+       return 0;
+}
+
 int fdt_parse_gaisler_uart_node(void *fdt, int nodeoffset,
                                struct platform_uart_data *uart)
 {