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 "config_timer.h"
10 #include "sgm775_mmap.h"
11 #include "system_clock.h"
12 
13 #include <mod_gtimer.h>
14 #include <mod_timer.h>
15 
16 #include <fwk_element.h>
17 #include <fwk_id.h>
18 #include <fwk_module.h>
19 #include <fwk_module_idx.h>
20 #include <fwk_time.h>
21 
22 #include <fmw_cmsis.h>
23 
24 /*
25  * Generic timer driver config
26  */
27 static const struct fwk_element gtimer_dev_table[] = {
28     [0] = {
29         .name = "REFCLK",
30         .data = &((struct mod_gtimer_dev_config) {
31             .hw_timer   = REFCLK_CNTBASE0_BASE,
32             .hw_counter = REFCLK_CNTCTL_BASE,
33             .control    = REFCLK_CNTCONTROL_BASE,
34             .frequency = CLOCK_RATE_REFCLK,
35             .clock_id = FWK_ID_ELEMENT_INIT(
36                             FWK_MODULE_IDX_CLOCK,
37                             CLOCK_DEV_IDX_FCMCLK),
38         })
39     },
40     [1] = { 0 },
41 };
42 
43 struct fwk_module_config config_gtimer = {
44     .elements = FWK_MODULE_STATIC_ELEMENTS_PTR(gtimer_dev_table),
45 };
46 
fmw_time_driver(const void ** ctx)47 struct fwk_time_driver fmw_time_driver(const void **ctx)
48 {
49     return mod_gtimer_driver(ctx, config_gtimer.elements.table[0].data);
50 }
51 
52 /*
53  * Timer HAL config
54  */
55 static const struct mod_timer_dev_config refclk_config = {
56     .id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_GTIMER, 0),
57     .timer_irq = TIMREFCLK_IRQ,
58 };
59 
60 static const struct fwk_element timer_dev_table[] = {
61     [CONFIG_TIMER_ELEMENT_IDX_REFCLK] = {
62         .name = "REFCLK",
63         .data = &refclk_config,
64         .sub_element_count = CONFIG_TIMER_REFCLK_SUB_ELEMENT_IDX_COUNT,
65     },
66     [CONFIG_TIMER_ELEMENT_IDX_COUNT] = { 0 },
67 };
68 
timer_get_dev_table(fwk_id_t module_id)69 static const struct fwk_element *timer_get_dev_table(fwk_id_t module_id)
70 {
71     return timer_dev_table;
72 }
73 
74 struct fwk_module_config config_timer = {
75     .elements = FWK_MODULE_DYNAMIC_ELEMENTS(timer_get_dev_table),
76 };
77