1 /* 2 * Copyright (C) 2018 Marvell International Ltd. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * https://spdx.org/licenses 6 */ 7 8 /* AP807 Marvell SoC driver */ 9 10 #include <common/debug.h> 11 #include <drivers/marvell/cache_llc.h> 12 #include <drivers/marvell/ccu.h> 13 #include <drivers/marvell/io_win.h> 14 #include <drivers/marvell/iob.h> 15 #include <drivers/marvell/mci.h> 16 #include <drivers/marvell/mochi/ap_setup.h> 17 #include <lib/mmio.h> 18 19 #include <mvebu_def.h> 20 21 #define SMMU_sACR (MVEBU_SMMU_BASE + 0x10) 22 #define SMMU_sACR_PG_64K (1 << 16) 23 24 #define CCU_GSPMU_CR (MVEBU_CCU_BASE(MVEBU_AP0) \ 25 + 0x3F0) 26 #define GSPMU_CPU_CONTROL (0x1 << 0) 27 28 #define CCU_HTC_CR (MVEBU_CCU_BASE(MVEBU_AP0) \ 29 + 0x200) 30 #define CCU_SET_POC_OFFSET 5 31 32 #define DSS_CR0 (MVEBU_RFU_BASE + 0x100) 33 #define DVM_48BIT_VA_ENABLE (1 << 21) 34 35 36 /* SoC RFU / IHBx4 Control */ 37 #define MCIX4_807_REG_START_ADDR_REG(unit_id) (MVEBU_RFU_BASE + \ 38 0x4258 + (unit_id * 0x4)) 39 40 /* Secure MoChi incoming access */ 41 #define SEC_MOCHI_IN_ACC_REG (MVEBU_RFU_BASE + 0x4738) 42 #define SEC_MOCHI_IN_ACC_IHB0_EN (1) 43 #define SEC_MOCHI_IN_ACC_IHB1_EN (1 << 3) 44 #define SEC_MOCHI_IN_ACC_IHB2_EN (1 << 6) 45 #define SEC_MOCHI_IN_ACC_PIDI_EN (1 << 9) 46 #define SEC_IN_ACCESS_ENA_ALL_MASTERS (SEC_MOCHI_IN_ACC_IHB0_EN | \ 47 SEC_MOCHI_IN_ACC_IHB1_EN | \ 48 SEC_MOCHI_IN_ACC_IHB2_EN | \ 49 SEC_MOCHI_IN_ACC_PIDI_EN) 50 51 /* SYSRST_OUTn Config definitions */ 52 #define MVEBU_SYSRST_OUT_CONFIG_REG (MVEBU_MISC_SOC_BASE + 0x4) 53 #define WD_MASK_SYS_RST_OUT (1 << 2) 54 55 /* DSS PHY for DRAM */ 56 #define DSS_SCR_REG (MVEBU_RFU_BASE + 0x208) 57 #define DSS_PPROT_OFFS 4 58 #define DSS_PPROT_MASK 0x7 59 #define DSS_PPROT_PRIV_SECURE_DATA 0x1 60 61 /* Used for Units of AP-807 (e.g. SDIO and etc) */ 62 #define MVEBU_AXI_ATTR_BASE (MVEBU_REGS_BASE + 0x6F4580) 63 #define MVEBU_AXI_ATTR_REG(index) (MVEBU_AXI_ATTR_BASE + \ 64 0x4 * index) 65 66 enum axi_attr { 67 AXI_SDIO_ATTR = 0, 68 AXI_DFX_ATTR, 69 AXI_MAX_ATTR, 70 }; 71 72 static void ap_sec_masters_access_en(uint32_t enable) 73 { 74 uint32_t reg; 75 76 /* Open/Close incoming access for all masters. 77 * The access is disabled in trusted boot mode 78 * Could only be done in EL3 79 */ 80 reg = mmio_read_32(SEC_MOCHI_IN_ACC_REG); 81 if (enable) 82 mmio_write_32(SEC_MOCHI_IN_ACC_REG, reg | 83 SEC_IN_ACCESS_ENA_ALL_MASTERS); 84 else 85 mmio_write_32(SEC_MOCHI_IN_ACC_REG, 86 reg & ~SEC_IN_ACCESS_ENA_ALL_MASTERS); 87 } 88 89 static void setup_smmu(void) 90 { 91 uint32_t reg; 92 93 /* Set the SMMU page size to 64 KB */ 94 reg = mmio_read_32(SMMU_sACR); 95 reg |= SMMU_sACR_PG_64K; 96 mmio_write_32(SMMU_sACR, reg); 97 } 98 99 static void init_aurora2(void) 100 { 101 uint32_t reg; 102 103 /* Enable GSPMU control by CPU */ 104 reg = mmio_read_32(CCU_GSPMU_CR); 105 reg |= GSPMU_CPU_CONTROL; 106 mmio_write_32(CCU_GSPMU_CR, reg); 107 108 #if LLC_ENABLE 109 /* Enable LLC for AP807 in exclusive mode */ 110 llc_enable(0, 1); 111 112 /* Set point of coherency to DDR. 113 * This is required by units which have 114 * SW cache coherency 115 */ 116 reg = mmio_read_32(CCU_HTC_CR); 117 reg |= (0x1 << CCU_SET_POC_OFFSET); 118 mmio_write_32(CCU_HTC_CR, reg); 119 #endif /* LLC_ENABLE */ 120 121 errata_wa_init(); 122 } 123 124 125 /* MCIx indirect access register are based by default at 0xf4000000/0xf6000000 126 * to avoid conflict of internal registers of units connected via MCIx, which 127 * can be based on the same address (i.e CP1 base is also 0xf4000000), 128 * the following routines remaps the MCIx indirect bases to another domain 129 */ 130 static void mci_remap_indirect_access_base(void) 131 { 132 uint32_t mci; 133 134 for (mci = 0; mci < MCI_MAX_UNIT_ID; mci++) 135 mmio_write_32(MCIX4_807_REG_START_ADDR_REG(mci), 136 MVEBU_MCI_REG_BASE_REMAP(mci) >> 137 MCI_REMAP_OFF_SHIFT); 138 } 139 140 static void ap807_axi_attr_init(void) 141 { 142 uint32_t index, data; 143 144 /* Initialize AXI attributes for AP807 */ 145 /* Go over the AXI attributes and set Ax-Cache and Ax-Domain */ 146 for (index = 0; index < AXI_MAX_ATTR; index++) { 147 switch (index) { 148 /* DFX works with no coherent only - 149 * there's no option to configure the Ax-Cache and Ax-Domain 150 */ 151 case AXI_DFX_ATTR: 152 continue; 153 default: 154 /* Set Ax-Cache as cacheable, no allocate, modifiable, 155 * bufferable. 156 * The values are different because Read & Write 157 * definition is different in Ax-Cache 158 */ 159 data = mmio_read_32(MVEBU_AXI_ATTR_REG(index)); 160 data &= ~MVEBU_AXI_ATTR_ARCACHE_MASK; 161 data |= (CACHE_ATTR_WRITE_ALLOC | 162 CACHE_ATTR_CACHEABLE | 163 CACHE_ATTR_BUFFERABLE) << 164 MVEBU_AXI_ATTR_ARCACHE_OFFSET; 165 data &= ~MVEBU_AXI_ATTR_AWCACHE_MASK; 166 data |= (CACHE_ATTR_READ_ALLOC | 167 CACHE_ATTR_CACHEABLE | 168 CACHE_ATTR_BUFFERABLE) << 169 MVEBU_AXI_ATTR_AWCACHE_OFFSET; 170 /* Set Ax-Domain as Outer domain */ 171 data &= ~MVEBU_AXI_ATTR_ARDOMAIN_MASK; 172 data |= DOMAIN_OUTER_SHAREABLE << 173 MVEBU_AXI_ATTR_ARDOMAIN_OFFSET; 174 data &= ~MVEBU_AXI_ATTR_AWDOMAIN_MASK; 175 data |= DOMAIN_OUTER_SHAREABLE << 176 MVEBU_AXI_ATTR_AWDOMAIN_OFFSET; 177 mmio_write_32(MVEBU_AXI_ATTR_REG(index), data); 178 } 179 } 180 } 181 182 static void misc_soc_configurations(void) 183 { 184 uint32_t reg; 185 186 /* Enable 48-bit VA */ 187 mmio_setbits_32(DSS_CR0, DVM_48BIT_VA_ENABLE); 188 189 /* Un-mask Watchdog reset from influencing the SYSRST_OUTn. 190 * Otherwise, upon WD timeout, the WD reset signal won't trigger reset 191 */ 192 reg = mmio_read_32(MVEBU_SYSRST_OUT_CONFIG_REG); 193 reg &= ~(WD_MASK_SYS_RST_OUT); 194 mmio_write_32(MVEBU_SYSRST_OUT_CONFIG_REG, reg); 195 } 196 197 /* 198 * By default all external CPs start with configuration address space set to 199 * 0xf200_0000. To overcome this issue, go in the loop and initialize the 200 * CP one by one, using temporary window configuration which allows to access 201 * each CP and update its configuration space according to decoding 202 * windows scheme defined for each platform. 203 */ 204 void update_cp110_default_win(int cp_id) 205 { 206 int mci_id = cp_id - 1; 207 uintptr_t cp110_base, cp110_temp_base; 208 209 /* CP110 default configuration address space */ 210 cp110_temp_base = MVEBU_AP_IO_BASE(MVEBU_AP0); 211 212 struct addr_map_win iowin_temp_win = { 213 .base_addr = cp110_temp_base, 214 .win_size = MVEBU_CP_OFFSET, 215 }; 216 217 iowin_temp_win.target_id = mci_id; 218 iow_temp_win_insert(0, &iowin_temp_win, 1); 219 220 /* Calculate the new CP110 - base address */ 221 cp110_base = MVEBU_CP_REGS_BASE(cp_id); 222 /* Go and update the CP110 configuration address space */ 223 iob_cfg_space_update(0, cp_id, cp110_temp_base, cp110_base); 224 225 /* Remove the temporary IO-WIN window */ 226 iow_temp_win_remove(0, &iowin_temp_win, 1); 227 } 228 229 void ap_init(void) 230 { 231 /* Setup Aurora2. */ 232 init_aurora2(); 233 234 /* configure MCI mapping */ 235 mci_remap_indirect_access_base(); 236 237 /* configure IO_WIN windows */ 238 init_io_win(MVEBU_AP0); 239 240 /* configure CCU windows */ 241 init_ccu(MVEBU_AP0); 242 243 /* configure the SMMU */ 244 setup_smmu(); 245 246 /* Open AP incoming access for all masters */ 247 ap_sec_masters_access_en(1); 248 249 /* configure axi for AP */ 250 ap807_axi_attr_init(); 251 252 /* misc configuration of the SoC */ 253 misc_soc_configurations(); 254 } 255 256 static void ap807_dram_phy_access_config(void) 257 { 258 uint32_t reg_val; 259 /* Update DSS port access permission to DSS_PHY */ 260 reg_val = mmio_read_32(DSS_SCR_REG); 261 reg_val &= ~(DSS_PPROT_MASK << DSS_PPROT_OFFS); 262 reg_val |= ((DSS_PPROT_PRIV_SECURE_DATA & DSS_PPROT_MASK) << 263 DSS_PPROT_OFFS); 264 mmio_write_32(DSS_SCR_REG, reg_val); 265 } 266 267 void ap_ble_init(void) 268 { 269 /* Enable DSS port */ 270 ap807_dram_phy_access_config(); 271 } 272 273 int ap_get_count(void) 274 { 275 return 1; 276 } 277 278 279