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