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