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