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