1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include "config_clock.h"
9 #include "morello_scp_mmap.h"
10 
11 #include <mod_cdns_i2c.h>
12 
13 #include <fwk_element.h>
14 #include <fwk_id.h>
15 #include <fwk_macros.h>
16 #include <fwk_module.h>
17 #include <fwk_module_idx.h>
18 
19 #include <fmw_cmsis.h>
20 
21 #include <stdbool.h>
22 
23 static const struct fwk_element i2c_element_desc_table[4] = {
24     [0] = {
25         .name = "SPD-I2C",
26         .data = &((struct mod_cdns_i2c_device_config) {
27             .reg_base = DIMM_SPD_I2C_BASE,
28             .clock_rate_hz = OSC_FREQ_HZ,
29             .bus_speed_hz = MOD_CDNS_I2C_SPEED_NORMAL,
30             .mode = MOD_CDNS_I2C_CONTROLLER_MODE,
31             .ack_en = MOD_CDNS_I2C_ACK_ENABLE,
32             .addr_size = MOD_CDNS_I2C_ADDRESS_7_BIT,
33             .hold_mode = MOD_CDNS_I2C_HOLD_ON,
34             .callback_mod_id = FWK_ID_NONE_INIT,
35             .fifo_depth = 8,
36             .max_xfr_size = 15,
37         }),
38     },
39     [1] = {
40         .name = "C2C-I2C",
41         .data = &((struct mod_cdns_i2c_device_config) {
42             .reg_base = SCP_I2C0_BASE,
43             .clock_rate_hz = (50UL * FWK_MHZ),
44             .bus_speed_hz = MOD_CDNS_I2C_SPEED_NORMAL,
45             .mode = MOD_CDNS_I2C_TARGET_MODE,
46             .ack_en = MOD_CDNS_I2C_ACK_ENABLE,
47             .addr_size = MOD_CDNS_I2C_ADDRESS_7_BIT,
48             .hold_mode = MOD_CDNS_I2C_HOLD_OFF,
49             .target_addr = 0x14,
50             .irq = SCP_I2C0_IRQ,
51             .callback_mod_id = FWK_ID_NONE_INIT,
52             .fifo_depth = 8,
53             .max_xfr_size = 15,
54         }),
55     },
56     [2] = {
57         .name = "PCC-I2C",
58         .data = &((struct mod_cdns_i2c_device_config) {
59             .reg_base = SCP_I2C2_BASE,
60             .clock_rate_hz = (100UL * FWK_MHZ),
61             .bus_speed_hz = MOD_CDNS_I2C_SPEED_NORMAL,
62             .mode = MOD_CDNS_I2C_CONTROLLER_MODE,
63             .ack_en = MOD_CDNS_I2C_ACK_ENABLE,
64             .addr_size = MOD_CDNS_I2C_ADDRESS_7_BIT,
65             .hold_mode = MOD_CDNS_I2C_HOLD_ON,
66             .callback_mod_id = FWK_ID_NONE_INIT,
67             .fifo_depth = 8,
68             .max_xfr_size = 15,
69         }),
70     },
71     [3] = { 0 }, /* Termination description. */
72 };
73 
get_i2c_table(fwk_id_t module_id)74 static const struct fwk_element *get_i2c_table(fwk_id_t module_id)
75 {
76     return i2c_element_desc_table;
77 }
78 
79 const struct fwk_module_config config_cdns_i2c = {
80     .elements = FWK_MODULE_DYNAMIC_ELEMENTS(get_i2c_table),
81 };
82