Bo-Chen Chen | 297b634 | 2022-08-29 19:05:06 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only OR MIT */ |
| 2 | |
| 3 | #include <console/console.h> |
| 4 | #include <soc/devapc.h> |
| 5 | #include <soc/devapc_common.h> |
| 6 | |
| 7 | void *getreg_domain(uintptr_t base, unsigned int offset, |
| 8 | enum domain_id domain_id, unsigned int index) |
| 9 | { |
| 10 | return (void *)(base + offset + domain_id * DOMAIN_OFT + index * IDX_OFT); |
| 11 | } |
| 12 | |
| 13 | void *getreg(uintptr_t base, unsigned int offset) |
| 14 | { |
| 15 | return getreg_domain(base, offset, 0, 0); |
| 16 | } |
| 17 | |
| 18 | void set_module_apc(uintptr_t base, uint32_t module, enum domain_id domain_id, |
| 19 | enum devapc_perm_type perm) |
| 20 | { |
| 21 | uint32_t apc_register_index; |
| 22 | uint32_t apc_set_index; |
| 23 | |
| 24 | apc_register_index = module / MOD_NO_IN_1_DEVAPC; |
| 25 | apc_set_index = module % MOD_NO_IN_1_DEVAPC; |
| 26 | |
| 27 | clrsetbits32(getreg_domain(base, 0, domain_id, apc_register_index), |
| 28 | 0x3 << (apc_set_index * 2), |
| 29 | perm << (apc_set_index * 2)); |
| 30 | } |
Yidi Lin | 78b29f4 | 2022-12-20 15:30:38 +0800 | [diff] [blame] | 31 | |
| 32 | void dapc_init(void) |
| 33 | { |
| 34 | size_t i; |
| 35 | uintptr_t devapc_ao_base; |
| 36 | |
| 37 | for (i = 0; i < devapc_init_cnt; i++) { |
| 38 | devapc_ao_base = devapc_init[i].base; |
| 39 | |
| 40 | /* Init dapc */ |
| 41 | write32(getreg(devapc_ao_base, AO_APC_CON), 0x0); |
| 42 | write32(getreg(devapc_ao_base, AO_APC_CON), 0x1); |
| 43 | |
| 44 | /* Initialization */ |
| 45 | if (devapc_init[i].init) |
| 46 | devapc_init[i].init(devapc_ao_base); |
| 47 | |
Yidi Lin | 63d26b8 | 2022-12-20 16:42:53 +0800 | [diff] [blame^] | 48 | /* Dump setting */ |
| 49 | if (CONFIG(DEVAPC_DEBUG) && devapc_init[i].dump) |
Yidi Lin | 78b29f4 | 2022-12-20 15:30:38 +0800 | [diff] [blame] | 50 | devapc_init[i].dump(devapc_ao_base); |
| 51 | } |
| 52 | } |