1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2019-2021, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include "juno_alarm_idx.h"
9 #include "system_clock.h"
10 #include "system_mmap.h"
11 
12 #include <mod_gtimer.h>
13 #include <mod_timer.h>
14 
15 #include <fwk_element.h>
16 #include <fwk_id.h>
17 #include <fwk_module.h>
18 #include <fwk_module_idx.h>
19 #include <fwk_time.h>
20 
21 #include <fmw_cmsis.h>
22 
23 static const struct fwk_element gtimer_element_table[] = {
24     [0] = {
25         .name = "",
26         .data = &(struct mod_gtimer_dev_config) {
27             .hw_timer = REFCLK_CNTBASE0_BASE,
28             .hw_counter = REFCLK_CNTCTL_BASE,
29             .control = REFCLK_CNTCONTROL_BASE,
30             .frequency = CLOCK_RATE_REFCLK,
31             .clock_id = FWK_ID_NONE_INIT,
32         }
33     },
34     [1] = { 0 },
35 };
36 
37 struct fwk_module_config config_gtimer = {
38     .elements = FWK_MODULE_STATIC_ELEMENTS_PTR(gtimer_element_table),
39 };
40 
41 static const struct fwk_element timer_element_table[] = {
42     [0] = {
43         .name = "REFCLK",
44         .sub_element_count = (size_t) JUNO_ALARM_IDX_COUNT,
45         .data = &(struct mod_timer_dev_config) {
46             .id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_GTIMER, 0),
47             .timer_irq = (unsigned int) TIMREFCLK_IRQ,
48         },
49     },
50     [1] = { 0 },
51 };
52 
fmw_time_driver(const void ** ctx)53 struct fwk_time_driver fmw_time_driver(const void **ctx)
54 {
55     return mod_gtimer_driver(ctx, config_gtimer.elements.table[0].data);
56 }
57 
timer_get_element_table(fwk_id_t module_id)58 static const struct fwk_element *timer_get_element_table(fwk_id_t module_id)
59 {
60     return timer_element_table;
61 }
62 
63 struct fwk_module_config config_timer = {
64     .elements = FWK_MODULE_DYNAMIC_ELEMENTS(timer_get_element_table),
65 };
66