1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2017-2021, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include "clock_devices.h"
9 #include "sgm776_mmap.h"
10 #include "system_clock.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 /*
22  * Generic timer driver config
23  */
24 static const struct fwk_element gtimer_dev_table[] = {
25     [0] = {
26         .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_ELEMENT_INIT(
33                             FWK_MODULE_IDX_CLOCK,
34                             CLOCK_DEV_IDX_SYS_NOCMEMCLK),
35         })
36     },
37     [1] = { 0 },
38 };
39 
40 struct fwk_module_config config_gtimer = {
41     .elements = FWK_MODULE_STATIC_ELEMENTS_PTR(gtimer_dev_table),
42 };
43 
fmw_time_driver(const void ** ctx)44 struct fwk_time_driver fmw_time_driver(const void **ctx)
45 {
46     return mod_gtimer_driver(ctx, config_gtimer.elements.table[0].data);
47 }
48 
49 /*
50  * Timer HAL config
51  */
52 static const struct mod_timer_dev_config refclk_config = {
53     .id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_GTIMER, 0),
54 };
55 
56 static const struct fwk_element timer_dev_table[] = {
57     [0] = {
58         .name = "REFCLK",
59         .data = &refclk_config,
60     },
61     [1] = { 0 },
62 };
63 
timer_get_dev_table(fwk_id_t module_id)64 static const struct fwk_element *timer_get_dev_table(fwk_id_t module_id)
65 {
66     return timer_dev_table;
67 }
68 
69 struct fwk_module_config config_timer = {
70     .elements = FWK_MODULE_DYNAMIC_ELEMENTS(timer_get_dev_table),
71 };
72