1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include <config_power_domain.h>
9 #include <juno_id.h>
10 #include <system_clock.h>
11 
12 #include <mod_debug.h>
13 #include <mod_juno_debug.h>
14 
15 #include <fwk_element.h>
16 #include <fwk_mm.h>
17 #include <fwk_module.h>
18 #include <fwk_module_idx.h>
19 
20 /* Debug clock settings for Juno with default values for R0 */
21 static struct juno_css_debug_dev clock_settings = {
22     .div_atclk = (SYSINCLK / (533UL * FWK_MHZ)),
23     .manual_reset_required = true,
24     .div_pclk = 1,
25     .div_traceclk = (SYSINCLK / (150UL * FWK_MHZ)),
26 };
27 
28 static struct fwk_element juno_debug_element_table[] = {
29     [0] = {
30         .name = "JUNO DEBUG",
31         .data = &((struct mod_juno_debug_dev_config){
32             .pd_dbgsys_id =
33                 FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_POWER_DOMAIN,
34                                     POWER_DOMAIN_IDX_DBGSYS),
35             .pd_big_sstop_id =
36                 FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_POWER_DOMAIN,
37                                     POWER_DOMAIN_IDX_BIG_SSTOP),
38             .pd_little_sstop_id =
39                 FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_POWER_DOMAIN,
40                                     POWER_DOMAIN_IDX_LITTLE_SSTOP),
41         }),
42     },
43     [1] = { 0 }, /* Termination description */
44 };
45 
get_juno_debug_elem_table(fwk_id_t module_id)46 static const struct fwk_element *get_juno_debug_elem_table(fwk_id_t module_id)
47 {
48     int status;
49     enum juno_idx_revision revision;
50     struct mod_juno_debug_dev_config *juno_debug_config;
51 
52     status = juno_id_get_revision(&revision);
53     if (status != FWK_SUCCESS) {
54         return NULL;
55     }
56 
57     juno_debug_config = (struct mod_juno_debug_dev_config *)
58         juno_debug_element_table[0].data;
59 
60     juno_debug_config->clk_settings = &clock_settings;
61 
62     /* Adjust Debug clock settings for Juno R1 & Juno R2 */
63     if (revision != JUNO_IDX_REVISION_R0) {
64         juno_debug_config->clk_settings->div_atclk =
65             (SYSINCLK / (400UL * FWK_MHZ)),
66         juno_debug_config->clk_settings->manual_reset_required = false;
67     }
68 
69     return juno_debug_element_table;
70 }
71 
72 struct fwk_module_config config_juno_debug = {
73     .data =
74         &(struct mod_juno_debug_config){
75             .timer_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_TIMER, 0),
76         },
77 
78     .elements = FWK_MODULE_DYNAMIC_ELEMENTS(get_juno_debug_elem_table),
79 };
80