1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright 2022 Microchip 4 */ 5 6 #include <assert.h> 7 #include <config.h> 8 #include <drivers/clk.h> 9 #include <drivers/clk_dt.h> 10 #include <kernel/boot.h> 11 #include <kernel/dt.h> 12 #include <kernel/panic.h> 13 #include <libfdt.h> 14 15 static unsigned long freq; 16 17 static TEE_Result get_freq_from_dt(void) 18 { 19 int node; 20 struct clk *clk; 21 const void *fdt = get_embedded_dt(); 22 23 if (!fdt) 24 panic(); 25 26 if (IS_ENABLED(CFG_SAMA7G5)) 27 node = fdt_node_offset_by_compatible(fdt, -1, "arm,cortex-a7"); 28 else 29 node = fdt_node_offset_by_compatible(fdt, -1, "arm,cortex-a5"); 30 31 if (!node) 32 panic(); 33 34 if (clk_dt_get_by_name(fdt, node, "cpu", &clk)) 35 panic(); 36 37 freq = clk_get_rate(clk); 38 39 return TEE_SUCCESS; 40 } 41 early_init_late(get_freq_from_dt); 42 43 unsigned long plat_get_freq(void) 44 { 45 assert(freq); 46 47 return freq; 48 } 49