1c0474d58SKonstantin Porotchkin /* 2c0474d58SKonstantin Porotchkin * Copyright (C) 2018 Marvell International Ltd. 3c0474d58SKonstantin Porotchkin * 4c0474d58SKonstantin Porotchkin * SPDX-License-Identifier: BSD-3-Clause 5c0474d58SKonstantin Porotchkin * https://spdx.org/licenses 6c0474d58SKonstantin Porotchkin */ 7c0474d58SKonstantin Porotchkin 8c0474d58SKonstantin Porotchkin /* CCU unit device driver for Marvell AP807, AP807 and AP810 SoCs */ 9c0474d58SKonstantin Porotchkin 1009d40e0eSAntonio Nino Diaz #include <common/debug.h> 1109d40e0eSAntonio Nino Diaz #include <drivers/marvell/ccu.h> 1209d40e0eSAntonio Nino Diaz #include <lib/mmio.h> 1309d40e0eSAntonio Nino Diaz 1494d6dd67SKonstantin Porotchkin #include <armada_common.h> 15c0474d58SKonstantin Porotchkin #include <mvebu.h> 16c0474d58SKonstantin Porotchkin #include <mvebu_def.h> 17c0474d58SKonstantin Porotchkin 18c0474d58SKonstantin Porotchkin #if LOG_LEVEL >= LOG_LEVEL_INFO 19c0474d58SKonstantin Porotchkin #define DEBUG_ADDR_MAP 20c0474d58SKonstantin Porotchkin #endif 21c0474d58SKonstantin Porotchkin 22c0474d58SKonstantin Porotchkin /* common defines */ 23c0474d58SKonstantin Porotchkin #define WIN_ENABLE_BIT (0x1) 2439b6cc66SAntonio Nino Diaz /* Physical address of the base of the window = {AddrLow[19:0],20'h0} */ 25c0474d58SKonstantin Porotchkin #define ADDRESS_SHIFT (20 - 4) 26c0474d58SKonstantin Porotchkin #define ADDRESS_MASK (0xFFFFFFF0) 27c0474d58SKonstantin Porotchkin #define CCU_WIN_ALIGNMENT (0x100000) 28c0474d58SKonstantin Porotchkin 29c0474d58SKonstantin Porotchkin #define IS_DRAM_TARGET(tgt) ((((tgt) == DRAM_0_TID) || \ 30c0474d58SKonstantin Porotchkin ((tgt) == DRAM_1_TID) || \ 31c0474d58SKonstantin Porotchkin ((tgt) == RAR_TID)) ? 1 : 0) 32c0474d58SKonstantin Porotchkin 33*5e4c97d0SStefan Chulski #define CCU_RGF(win) (MVEBU_CCU_BASE(MVEBU_AP0) + \ 34*5e4c97d0SStefan Chulski 0x90 + 4 * (win)) 35*5e4c97d0SStefan Chulski 36c0474d58SKonstantin Porotchkin /* For storage of CR, SCR, ALR, AHR abd GCR */ 37c0474d58SKonstantin Porotchkin static uint32_t ccu_regs_save[MVEBU_CCU_MAX_WINS * 4 + 1]; 38c0474d58SKonstantin Porotchkin 39c0474d58SKonstantin Porotchkin #ifdef DEBUG_ADDR_MAP 40c0474d58SKonstantin Porotchkin static void dump_ccu(int ap_index) 41c0474d58SKonstantin Porotchkin { 42c0474d58SKonstantin Porotchkin uint32_t win_id, win_cr, alr, ahr; 43c0474d58SKonstantin Porotchkin uint8_t target_id; 44c0474d58SKonstantin Porotchkin uint64_t start, end; 45c0474d58SKonstantin Porotchkin 46c0474d58SKonstantin Porotchkin /* Dump all AP windows */ 4739b6cc66SAntonio Nino Diaz printf("\tbank target start end\n"); 4839b6cc66SAntonio Nino Diaz printf("\t----------------------------------------------------\n"); 49c0474d58SKonstantin Porotchkin for (win_id = 0; win_id < MVEBU_CCU_MAX_WINS; win_id++) { 50c0474d58SKonstantin Porotchkin win_cr = mmio_read_32(CCU_WIN_CR_OFFSET(ap_index, win_id)); 51c0474d58SKonstantin Porotchkin if (win_cr & WIN_ENABLE_BIT) { 52c0474d58SKonstantin Porotchkin target_id = (win_cr >> CCU_TARGET_ID_OFFSET) & 53c0474d58SKonstantin Porotchkin CCU_TARGET_ID_MASK; 54c0474d58SKonstantin Porotchkin alr = mmio_read_32(CCU_WIN_ALR_OFFSET(ap_index, 55c0474d58SKonstantin Porotchkin win_id)); 56c0474d58SKonstantin Porotchkin ahr = mmio_read_32(CCU_WIN_AHR_OFFSET(ap_index, 57c0474d58SKonstantin Porotchkin win_id)); 58c0474d58SKonstantin Porotchkin start = ((uint64_t)alr << ADDRESS_SHIFT); 59c0474d58SKonstantin Porotchkin end = (((uint64_t)ahr + 0x10) << ADDRESS_SHIFT); 60957a5addSKonstantin Porotchkin printf("\tccu%d %02x 0x%016llx 0x%016llx\n", 61957a5addSKonstantin Porotchkin win_id, target_id, start, end); 62c0474d58SKonstantin Porotchkin } 63c0474d58SKonstantin Porotchkin } 64c0474d58SKonstantin Porotchkin win_cr = mmio_read_32(CCU_WIN_GCR_OFFSET(ap_index)); 65c0474d58SKonstantin Porotchkin target_id = (win_cr >> CCU_GCR_TARGET_OFFSET) & CCU_GCR_TARGET_MASK; 6639b6cc66SAntonio Nino Diaz printf("\tccu GCR %d - all other transactions\n", target_id); 67c0474d58SKonstantin Porotchkin } 68c0474d58SKonstantin Porotchkin #endif 69c0474d58SKonstantin Porotchkin 70c0474d58SKonstantin Porotchkin void ccu_win_check(struct addr_map_win *win) 71c0474d58SKonstantin Porotchkin { 72c0474d58SKonstantin Porotchkin /* check if address is aligned to 1M */ 73c0474d58SKonstantin Porotchkin if (IS_NOT_ALIGN(win->base_addr, CCU_WIN_ALIGNMENT)) { 74c0474d58SKonstantin Porotchkin win->base_addr = ALIGN_UP(win->base_addr, CCU_WIN_ALIGNMENT); 75c0474d58SKonstantin Porotchkin NOTICE("%s: Align up the base address to 0x%llx\n", 76c0474d58SKonstantin Porotchkin __func__, win->base_addr); 77c0474d58SKonstantin Porotchkin } 78c0474d58SKonstantin Porotchkin 79c0474d58SKonstantin Porotchkin /* size parameter validity check */ 80c0474d58SKonstantin Porotchkin if (IS_NOT_ALIGN(win->win_size, CCU_WIN_ALIGNMENT)) { 81c0474d58SKonstantin Porotchkin win->win_size = ALIGN_UP(win->win_size, CCU_WIN_ALIGNMENT); 82c0474d58SKonstantin Porotchkin NOTICE("%s: Aligning size to 0x%llx\n", 83c0474d58SKonstantin Porotchkin __func__, win->win_size); 84c0474d58SKonstantin Porotchkin } 85c0474d58SKonstantin Porotchkin } 86c0474d58SKonstantin Porotchkin 87957a5addSKonstantin Porotchkin int ccu_is_win_enabled(int ap_index, uint32_t win_id) 88957a5addSKonstantin Porotchkin { 89957a5addSKonstantin Porotchkin return mmio_read_32(CCU_WIN_CR_OFFSET(ap_index, win_id)) & 90957a5addSKonstantin Porotchkin WIN_ENABLE_BIT; 91957a5addSKonstantin Porotchkin } 92957a5addSKonstantin Porotchkin 93c0474d58SKonstantin Porotchkin void ccu_enable_win(int ap_index, struct addr_map_win *win, uint32_t win_id) 94c0474d58SKonstantin Porotchkin { 95c0474d58SKonstantin Porotchkin uint32_t ccu_win_reg; 96c0474d58SKonstantin Porotchkin uint32_t alr, ahr; 97c0474d58SKonstantin Porotchkin uint64_t end_addr; 98c0474d58SKonstantin Porotchkin 99c0474d58SKonstantin Porotchkin if ((win_id == 0) || (win_id > MVEBU_CCU_MAX_WINS)) { 100c0474d58SKonstantin Porotchkin ERROR("Enabling wrong CCU window %d!\n", win_id); 101c0474d58SKonstantin Porotchkin return; 102c0474d58SKonstantin Porotchkin } 103c0474d58SKonstantin Porotchkin 104c0474d58SKonstantin Porotchkin end_addr = (win->base_addr + win->win_size - 1); 105c0474d58SKonstantin Porotchkin alr = (uint32_t)((win->base_addr >> ADDRESS_SHIFT) & ADDRESS_MASK); 106c0474d58SKonstantin Porotchkin ahr = (uint32_t)((end_addr >> ADDRESS_SHIFT) & ADDRESS_MASK); 107c0474d58SKonstantin Porotchkin 108c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_ALR_OFFSET(ap_index, win_id), alr); 109c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_AHR_OFFSET(ap_index, win_id), ahr); 110c0474d58SKonstantin Porotchkin 111c0474d58SKonstantin Porotchkin ccu_win_reg = WIN_ENABLE_BIT; 112c0474d58SKonstantin Porotchkin ccu_win_reg |= (win->target_id & CCU_TARGET_ID_MASK) 113c0474d58SKonstantin Porotchkin << CCU_TARGET_ID_OFFSET; 114c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_CR_OFFSET(ap_index, win_id), ccu_win_reg); 115c0474d58SKonstantin Porotchkin } 116c0474d58SKonstantin Porotchkin 117c0474d58SKonstantin Porotchkin static void ccu_disable_win(int ap_index, uint32_t win_id) 118c0474d58SKonstantin Porotchkin { 119c0474d58SKonstantin Porotchkin uint32_t win_reg; 120c0474d58SKonstantin Porotchkin 121c0474d58SKonstantin Porotchkin if ((win_id == 0) || (win_id > MVEBU_CCU_MAX_WINS)) { 122c0474d58SKonstantin Porotchkin ERROR("Disabling wrong CCU window %d!\n", win_id); 123c0474d58SKonstantin Porotchkin return; 124c0474d58SKonstantin Porotchkin } 125c0474d58SKonstantin Porotchkin 126c0474d58SKonstantin Porotchkin win_reg = mmio_read_32(CCU_WIN_CR_OFFSET(ap_index, win_id)); 127c0474d58SKonstantin Porotchkin win_reg &= ~WIN_ENABLE_BIT; 128c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_CR_OFFSET(ap_index, win_id), win_reg); 129c0474d58SKonstantin Porotchkin } 130c0474d58SKonstantin Porotchkin 131c0474d58SKonstantin Porotchkin /* Insert/Remove temporary window for using the out-of reset default 132c0474d58SKonstantin Porotchkin * CPx base address to access the CP configuration space prior to 133c0474d58SKonstantin Porotchkin * the further base address update in accordance with address mapping 134c0474d58SKonstantin Porotchkin * design. 135c0474d58SKonstantin Porotchkin * 136c0474d58SKonstantin Porotchkin * NOTE: Use the same window array for insertion and removal of 137c0474d58SKonstantin Porotchkin * temporary windows. 138c0474d58SKonstantin Porotchkin */ 139c0474d58SKonstantin Porotchkin void ccu_temp_win_insert(int ap_index, struct addr_map_win *win, int size) 140c0474d58SKonstantin Porotchkin { 141c0474d58SKonstantin Porotchkin uint32_t win_id; 142c0474d58SKonstantin Porotchkin 143c0474d58SKonstantin Porotchkin for (int i = 0; i < size; i++) { 144c0474d58SKonstantin Porotchkin win_id = MVEBU_CCU_MAX_WINS - 1 - i; 145c0474d58SKonstantin Porotchkin ccu_win_check(win); 146c0474d58SKonstantin Porotchkin ccu_enable_win(ap_index, win, win_id); 147c0474d58SKonstantin Porotchkin win++; 148c0474d58SKonstantin Porotchkin } 149c0474d58SKonstantin Porotchkin } 150c0474d58SKonstantin Porotchkin 151c0474d58SKonstantin Porotchkin /* 152c0474d58SKonstantin Porotchkin * NOTE: Use the same window array for insertion and removal of 153c0474d58SKonstantin Porotchkin * temporary windows. 154c0474d58SKonstantin Porotchkin */ 155c0474d58SKonstantin Porotchkin void ccu_temp_win_remove(int ap_index, struct addr_map_win *win, int size) 156c0474d58SKonstantin Porotchkin { 157c0474d58SKonstantin Porotchkin uint32_t win_id; 158c0474d58SKonstantin Porotchkin 159c0474d58SKonstantin Porotchkin for (int i = 0; i < size; i++) { 160c0474d58SKonstantin Porotchkin uint64_t base; 161c0474d58SKonstantin Porotchkin uint32_t target; 162c0474d58SKonstantin Porotchkin 163c0474d58SKonstantin Porotchkin win_id = MVEBU_CCU_MAX_WINS - 1 - i; 164c0474d58SKonstantin Porotchkin 165c0474d58SKonstantin Porotchkin target = mmio_read_32(CCU_WIN_CR_OFFSET(ap_index, win_id)); 166c0474d58SKonstantin Porotchkin target >>= CCU_TARGET_ID_OFFSET; 167c0474d58SKonstantin Porotchkin target &= CCU_TARGET_ID_MASK; 168c0474d58SKonstantin Porotchkin 169c0474d58SKonstantin Porotchkin base = mmio_read_32(CCU_WIN_ALR_OFFSET(ap_index, win_id)); 170c0474d58SKonstantin Porotchkin base <<= ADDRESS_SHIFT; 171c0474d58SKonstantin Porotchkin 172c0474d58SKonstantin Porotchkin if ((win->target_id != target) || (win->base_addr != base)) { 173c0474d58SKonstantin Porotchkin ERROR("%s: Trying to remove bad window-%d!\n", 174c0474d58SKonstantin Porotchkin __func__, win_id); 175c0474d58SKonstantin Porotchkin continue; 176c0474d58SKonstantin Porotchkin } 177c0474d58SKonstantin Porotchkin ccu_disable_win(ap_index, win_id); 178c0474d58SKonstantin Porotchkin win++; 179c0474d58SKonstantin Porotchkin } 180c0474d58SKonstantin Porotchkin } 181c0474d58SKonstantin Porotchkin 182c0474d58SKonstantin Porotchkin /* Returns current DRAM window target (DRAM_0_TID, DRAM_1_TID, RAR_TID) 183c0474d58SKonstantin Porotchkin * NOTE: Call only once for each AP. 184c0474d58SKonstantin Porotchkin * The AP0 DRAM window is located at index 2 only at the BL31 execution start. 185c0474d58SKonstantin Porotchkin * Then it relocated to index 1 for matching the rest of APs DRAM settings. 186c0474d58SKonstantin Porotchkin * Calling this function after relocation will produce wrong results on AP0 187c0474d58SKonstantin Porotchkin */ 188c0474d58SKonstantin Porotchkin static uint32_t ccu_dram_target_get(int ap_index) 189c0474d58SKonstantin Porotchkin { 190c0474d58SKonstantin Porotchkin /* On BLE stage the AP0 DRAM window is opened by the BootROM at index 2. 191c0474d58SKonstantin Porotchkin * All the rest of detected APs will use window at index 1. 192c0474d58SKonstantin Porotchkin * The AP0 DRAM window is moved from index 2 to 1 during 193c0474d58SKonstantin Porotchkin * init_ccu() execution. 194c0474d58SKonstantin Porotchkin */ 195c0474d58SKonstantin Porotchkin const uint32_t win_id = (ap_index == 0) ? 2 : 1; 196c0474d58SKonstantin Porotchkin uint32_t target; 197c0474d58SKonstantin Porotchkin 198c0474d58SKonstantin Porotchkin target = mmio_read_32(CCU_WIN_CR_OFFSET(ap_index, win_id)); 199c0474d58SKonstantin Porotchkin target >>= CCU_TARGET_ID_OFFSET; 200c0474d58SKonstantin Porotchkin target &= CCU_TARGET_ID_MASK; 201c0474d58SKonstantin Porotchkin 202c0474d58SKonstantin Porotchkin return target; 203c0474d58SKonstantin Porotchkin } 204c0474d58SKonstantin Porotchkin 205c0474d58SKonstantin Porotchkin void ccu_dram_target_set(int ap_index, uint32_t target) 206c0474d58SKonstantin Porotchkin { 207c0474d58SKonstantin Porotchkin /* On BLE stage the AP0 DRAM window is opened by the BootROM at index 2. 208c0474d58SKonstantin Porotchkin * All the rest of detected APs will use window at index 1. 209c0474d58SKonstantin Porotchkin * The AP0 DRAM window is moved from index 2 to 1 210c0474d58SKonstantin Porotchkin * during init_ccu() execution. 211c0474d58SKonstantin Porotchkin */ 212c0474d58SKonstantin Porotchkin const uint32_t win_id = (ap_index == 0) ? 2 : 1; 213c0474d58SKonstantin Porotchkin uint32_t dram_cr; 214c0474d58SKonstantin Porotchkin 215c0474d58SKonstantin Porotchkin dram_cr = mmio_read_32(CCU_WIN_CR_OFFSET(ap_index, win_id)); 216c0474d58SKonstantin Porotchkin dram_cr &= ~(CCU_TARGET_ID_MASK << CCU_TARGET_ID_OFFSET); 217c0474d58SKonstantin Porotchkin dram_cr |= (target & CCU_TARGET_ID_MASK) << CCU_TARGET_ID_OFFSET; 218c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_CR_OFFSET(ap_index, win_id), dram_cr); 219c0474d58SKonstantin Porotchkin } 220c0474d58SKonstantin Porotchkin 221c0474d58SKonstantin Porotchkin /* Setup CCU DRAM window and enable it */ 222c0474d58SKonstantin Porotchkin void ccu_dram_win_config(int ap_index, struct addr_map_win *win) 223c0474d58SKonstantin Porotchkin { 224c0474d58SKonstantin Porotchkin #if IMAGE_BLE /* BLE */ 225c0474d58SKonstantin Porotchkin /* On BLE stage the AP0 DRAM window is opened by the BootROM at index 2. 226c0474d58SKonstantin Porotchkin * Since the BootROM is not accessing DRAM at BLE stage, 227c0474d58SKonstantin Porotchkin * the DRAM window can be temporarely disabled. 228c0474d58SKonstantin Porotchkin */ 229c0474d58SKonstantin Porotchkin const uint32_t win_id = (ap_index == 0) ? 2 : 1; 230c0474d58SKonstantin Porotchkin #else /* end of BLE */ 231c0474d58SKonstantin Porotchkin /* At the ccu_init() execution stage, DRAM windows of all APs 232c0474d58SKonstantin Porotchkin * are arranged at index 1. 233c0474d58SKonstantin Porotchkin * The AP0 still has the old window BootROM DRAM at index 2, so 234c0474d58SKonstantin Porotchkin * the window-1 can be safely disabled without breaking the DRAM access. 235c0474d58SKonstantin Porotchkin */ 236c0474d58SKonstantin Porotchkin const uint32_t win_id = 1; 237c0474d58SKonstantin Porotchkin #endif 238c0474d58SKonstantin Porotchkin 239c0474d58SKonstantin Porotchkin ccu_disable_win(ap_index, win_id); 240c0474d58SKonstantin Porotchkin /* enable write secure (and clear read secure) */ 241c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_SCR_OFFSET(ap_index, win_id), 242c0474d58SKonstantin Porotchkin CCU_WIN_ENA_WRITE_SECURE); 243c0474d58SKonstantin Porotchkin ccu_win_check(win); 244c0474d58SKonstantin Porotchkin ccu_enable_win(ap_index, win, win_id); 245c0474d58SKonstantin Porotchkin } 246c0474d58SKonstantin Porotchkin 247c0474d58SKonstantin Porotchkin /* Save content of CCU window + GCR */ 248c0474d58SKonstantin Porotchkin static void ccu_save_win_range(int ap_id, int win_first, 249c0474d58SKonstantin Porotchkin int win_last, uint32_t *buffer) 250c0474d58SKonstantin Porotchkin { 251c0474d58SKonstantin Porotchkin int win_id, idx; 252c0474d58SKonstantin Porotchkin /* Save CCU */ 253c0474d58SKonstantin Porotchkin for (idx = 0, win_id = win_first; win_id <= win_last; win_id++) { 254c0474d58SKonstantin Porotchkin buffer[idx++] = mmio_read_32(CCU_WIN_CR_OFFSET(ap_id, win_id)); 255c0474d58SKonstantin Porotchkin buffer[idx++] = mmio_read_32(CCU_WIN_SCR_OFFSET(ap_id, win_id)); 256c0474d58SKonstantin Porotchkin buffer[idx++] = mmio_read_32(CCU_WIN_ALR_OFFSET(ap_id, win_id)); 257c0474d58SKonstantin Porotchkin buffer[idx++] = mmio_read_32(CCU_WIN_AHR_OFFSET(ap_id, win_id)); 258c0474d58SKonstantin Porotchkin } 259c0474d58SKonstantin Porotchkin buffer[idx] = mmio_read_32(CCU_WIN_GCR_OFFSET(ap_id)); 260c0474d58SKonstantin Porotchkin } 261c0474d58SKonstantin Porotchkin 262c0474d58SKonstantin Porotchkin /* Restore content of CCU window + GCR */ 263c0474d58SKonstantin Porotchkin static void ccu_restore_win_range(int ap_id, int win_first, 264c0474d58SKonstantin Porotchkin int win_last, uint32_t *buffer) 265c0474d58SKonstantin Porotchkin { 266c0474d58SKonstantin Porotchkin int win_id, idx; 267c0474d58SKonstantin Porotchkin /* Restore CCU */ 268c0474d58SKonstantin Porotchkin for (idx = 0, win_id = win_first; win_id <= win_last; win_id++) { 269c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_CR_OFFSET(ap_id, win_id), buffer[idx++]); 270c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_SCR_OFFSET(ap_id, win_id), buffer[idx++]); 271c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_ALR_OFFSET(ap_id, win_id), buffer[idx++]); 272c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_AHR_OFFSET(ap_id, win_id), buffer[idx++]); 273c0474d58SKonstantin Porotchkin } 274c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_GCR_OFFSET(ap_id), buffer[idx]); 275c0474d58SKonstantin Porotchkin } 276c0474d58SKonstantin Porotchkin 277c0474d58SKonstantin Porotchkin void ccu_save_win_all(int ap_id) 278c0474d58SKonstantin Porotchkin { 279c0474d58SKonstantin Porotchkin ccu_save_win_range(ap_id, 0, MVEBU_CCU_MAX_WINS - 1, ccu_regs_save); 280c0474d58SKonstantin Porotchkin } 281c0474d58SKonstantin Porotchkin 282c0474d58SKonstantin Porotchkin void ccu_restore_win_all(int ap_id) 283c0474d58SKonstantin Porotchkin { 284c0474d58SKonstantin Porotchkin ccu_restore_win_range(ap_id, 0, MVEBU_CCU_MAX_WINS - 1, ccu_regs_save); 285c0474d58SKonstantin Porotchkin } 286c0474d58SKonstantin Porotchkin 287c0474d58SKonstantin Porotchkin int init_ccu(int ap_index) 288c0474d58SKonstantin Porotchkin { 289c0474d58SKonstantin Porotchkin struct addr_map_win *win, *dram_win; 290c0474d58SKonstantin Porotchkin uint32_t win_id, win_reg; 291c0474d58SKonstantin Porotchkin uint32_t win_count, array_id; 292c0474d58SKonstantin Porotchkin uint32_t dram_target; 293c0474d58SKonstantin Porotchkin #if IMAGE_BLE 294c0474d58SKonstantin Porotchkin /* In BootROM context CCU Window-1 295c0474d58SKonstantin Porotchkin * has SRAM_TID target and should not be disabled 296c0474d58SKonstantin Porotchkin */ 297c0474d58SKonstantin Porotchkin const uint32_t win_start = 2; 298c0474d58SKonstantin Porotchkin #else 299c0474d58SKonstantin Porotchkin const uint32_t win_start = 1; 300c0474d58SKonstantin Porotchkin #endif 301c0474d58SKonstantin Porotchkin 302c0474d58SKonstantin Porotchkin INFO("Initializing CCU Address decoding\n"); 303c0474d58SKonstantin Porotchkin 304c0474d58SKonstantin Porotchkin /* Get the array of the windows and fill the map data */ 305c0474d58SKonstantin Porotchkin marvell_get_ccu_memory_map(ap_index, &win, &win_count); 306c0474d58SKonstantin Porotchkin if (win_count <= 0) { 307c0474d58SKonstantin Porotchkin INFO("No windows configurations found\n"); 308c0474d58SKonstantin Porotchkin } else if (win_count > (MVEBU_CCU_MAX_WINS - 1)) { 309c0474d58SKonstantin Porotchkin ERROR("CCU mem map array > than max available windows (%d)\n", 310c0474d58SKonstantin Porotchkin MVEBU_CCU_MAX_WINS); 311c0474d58SKonstantin Porotchkin win_count = MVEBU_CCU_MAX_WINS; 312c0474d58SKonstantin Porotchkin } 313c0474d58SKonstantin Porotchkin 314c0474d58SKonstantin Porotchkin /* Need to set GCR to DRAM before all CCU windows are disabled for 315c0474d58SKonstantin Porotchkin * securing the normal access to DRAM location, which the ATF is running 316c0474d58SKonstantin Porotchkin * from. Once all CCU windows are set, which have to include the 317c0474d58SKonstantin Porotchkin * dedicated DRAM window as well, the GCR can be switched to the target 318c0474d58SKonstantin Porotchkin * defined by the platform configuration. 319c0474d58SKonstantin Porotchkin */ 320c0474d58SKonstantin Porotchkin dram_target = ccu_dram_target_get(ap_index); 321c0474d58SKonstantin Porotchkin win_reg = (dram_target & CCU_GCR_TARGET_MASK) << CCU_GCR_TARGET_OFFSET; 322c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_GCR_OFFSET(ap_index), win_reg); 323c0474d58SKonstantin Porotchkin 324c0474d58SKonstantin Porotchkin /* If the DRAM window was already configured at the BLE stage, 325c0474d58SKonstantin Porotchkin * only the window target considered valid, the address range should be 326c0474d58SKonstantin Porotchkin * updated according to the platform configuration. 327c0474d58SKonstantin Porotchkin */ 328c0474d58SKonstantin Porotchkin for (dram_win = win, array_id = 0; array_id < win_count; 329c0474d58SKonstantin Porotchkin array_id++, dram_win++) { 330c0474d58SKonstantin Porotchkin if (IS_DRAM_TARGET(dram_win->target_id)) { 331c0474d58SKonstantin Porotchkin dram_win->target_id = dram_target; 332c0474d58SKonstantin Porotchkin break; 333c0474d58SKonstantin Porotchkin } 334c0474d58SKonstantin Porotchkin } 335c0474d58SKonstantin Porotchkin 336c0474d58SKonstantin Porotchkin /* Disable all AP CCU windows 337c0474d58SKonstantin Porotchkin * Window-0 is always bypassed since it already contains 338c0474d58SKonstantin Porotchkin * data allowing the internal configuration space access 339c0474d58SKonstantin Porotchkin */ 340c0474d58SKonstantin Porotchkin for (win_id = win_start; win_id < MVEBU_CCU_MAX_WINS; win_id++) { 341c0474d58SKonstantin Porotchkin ccu_disable_win(ap_index, win_id); 342c0474d58SKonstantin Porotchkin /* enable write secure (and clear read secure) */ 343c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_SCR_OFFSET(ap_index, win_id), 344c0474d58SKonstantin Porotchkin CCU_WIN_ENA_WRITE_SECURE); 345c0474d58SKonstantin Porotchkin } 346c0474d58SKonstantin Porotchkin 347c0474d58SKonstantin Porotchkin /* win_id is the index of the current ccu window 348c0474d58SKonstantin Porotchkin * array_id is the index of the current memory map window entry 349c0474d58SKonstantin Porotchkin */ 350c0474d58SKonstantin Porotchkin for (win_id = win_start, array_id = 0; 351c0474d58SKonstantin Porotchkin ((win_id < MVEBU_CCU_MAX_WINS) && (array_id < win_count)); 352c0474d58SKonstantin Porotchkin win_id++) { 353c0474d58SKonstantin Porotchkin ccu_win_check(win); 354c0474d58SKonstantin Porotchkin ccu_enable_win(ap_index, win, win_id); 355c0474d58SKonstantin Porotchkin win++; 356c0474d58SKonstantin Porotchkin array_id++; 357c0474d58SKonstantin Porotchkin } 358c0474d58SKonstantin Porotchkin 359c0474d58SKonstantin Porotchkin /* Get & set the default target according to board topology */ 360c0474d58SKonstantin Porotchkin win_reg = (marvell_get_ccu_gcr_target(ap_index) & CCU_GCR_TARGET_MASK) 361c0474d58SKonstantin Porotchkin << CCU_GCR_TARGET_OFFSET; 362c0474d58SKonstantin Porotchkin mmio_write_32(CCU_WIN_GCR_OFFSET(ap_index), win_reg); 363c0474d58SKonstantin Porotchkin 364c0474d58SKonstantin Porotchkin #ifdef DEBUG_ADDR_MAP 365c0474d58SKonstantin Porotchkin dump_ccu(ap_index); 366c0474d58SKonstantin Porotchkin #endif 367c0474d58SKonstantin Porotchkin 368c0474d58SKonstantin Porotchkin INFO("Done CCU Address decoding Initializing\n"); 369c0474d58SKonstantin Porotchkin 370c0474d58SKonstantin Porotchkin return 0; 371c0474d58SKonstantin Porotchkin } 372*5e4c97d0SStefan Chulski 373*5e4c97d0SStefan Chulski void errata_wa_init(void) 374*5e4c97d0SStefan Chulski { 375*5e4c97d0SStefan Chulski /* 376*5e4c97d0SStefan Chulski * EERATA ID: RES-3033912 - Internal Address Space Init state causes 377*5e4c97d0SStefan Chulski * a hang upon accesses to [0xf070_0000, 0xf07f_ffff] 378*5e4c97d0SStefan Chulski * Workaround: Boot Firmware (ATF) should configure CCU_RGF_WIN(4) to 379*5e4c97d0SStefan Chulski * split [0x6e_0000, 0xff_ffff] to values [0x6e_0000, 0x6f_ffff] and 380*5e4c97d0SStefan Chulski * [0x80_0000, 0xff_ffff] that cause accesses to the 381*5e4c97d0SStefan Chulski * segment of [0xf070_0000, 0xf07f_ffff] to act as RAZWI. 382*5e4c97d0SStefan Chulski */ 383*5e4c97d0SStefan Chulski mmio_write_32(CCU_RGF(4), 0x37f9b809); 384*5e4c97d0SStefan Chulski mmio_write_32(CCU_RGF(5), 0x7ffa0009); 385*5e4c97d0SStefan Chulski } 386