1031542fcSKonstantin Porotchkin /* 22d1d2f05SMarcin Wojtas * Copyright (C) 2018-2020 Marvell International Ltd. 3031542fcSKonstantin Porotchkin * 4031542fcSKonstantin Porotchkin * SPDX-License-Identifier: BSD-3-Clause 5031542fcSKonstantin Porotchkin * https://spdx.org/licenses 6031542fcSKonstantin Porotchkin */ 7031542fcSKonstantin Porotchkin 8031542fcSKonstantin Porotchkin /* CP110 Marvell SoC driver */ 9031542fcSKonstantin Porotchkin 1009d40e0eSAntonio Nino Diaz #include <common/debug.h> 1109d40e0eSAntonio Nino Diaz #include <drivers/delay_timer.h> 1209d40e0eSAntonio Nino Diaz #include <drivers/marvell/amb_adec.h> 1309d40e0eSAntonio Nino Diaz #include <drivers/marvell/iob.h> 1409d40e0eSAntonio Nino Diaz #include <drivers/marvell/mochi/cp110_setup.h> 1557660d9dSKonstantin Porotchkin #include <drivers/rambus/trng_ip_76.h> 1609d40e0eSAntonio Nino Diaz 17*4eb72fe9SKonstantin Porotchkin #include <efuse_def.h> 18031542fcSKonstantin Porotchkin #include <plat_marvell.h> 19031542fcSKonstantin Porotchkin 20031542fcSKonstantin Porotchkin /* 21031542fcSKonstantin Porotchkin * AXI Configuration. 22031542fcSKonstantin Porotchkin */ 23031542fcSKonstantin Porotchkin 24031542fcSKonstantin Porotchkin /* Used for Units of CP-110 (e.g. USB device, USB Host, and etc) */ 25031542fcSKonstantin Porotchkin #define MVEBU_AXI_ATTR_OFFSET (0x441300) 26031542fcSKonstantin Porotchkin #define MVEBU_AXI_ATTR_REG(index) (MVEBU_AXI_ATTR_OFFSET + \ 27031542fcSKonstantin Porotchkin 0x4 * index) 28031542fcSKonstantin Porotchkin 29031542fcSKonstantin Porotchkin /* AXI Protection bits */ 30031542fcSKonstantin Porotchkin #define MVEBU_AXI_PROT_OFFSET (0x441200) 31031542fcSKonstantin Porotchkin 32031542fcSKonstantin Porotchkin /* AXI Protection regs */ 33031542fcSKonstantin Porotchkin #define MVEBU_AXI_PROT_REG(index) ((index <= 4) ? \ 34031542fcSKonstantin Porotchkin (MVEBU_AXI_PROT_OFFSET + \ 35031542fcSKonstantin Porotchkin 0x4 * index) : \ 36031542fcSKonstantin Porotchkin (MVEBU_AXI_PROT_OFFSET + 0x18)) 37031542fcSKonstantin Porotchkin #define MVEBU_AXI_PROT_REGS_NUM (6) 38031542fcSKonstantin Porotchkin 39031542fcSKonstantin Porotchkin #define MVEBU_SOC_CFGS_OFFSET (0x441900) 40031542fcSKonstantin Porotchkin #define MVEBU_SOC_CFG_REG(index) (MVEBU_SOC_CFGS_OFFSET + \ 41031542fcSKonstantin Porotchkin 0x4 * index) 42031542fcSKonstantin Porotchkin #define MVEBU_SOC_CFG_REG_NUM (0) 43031542fcSKonstantin Porotchkin #define MVEBU_SOC_CFG_GLOG_SECURE_EN_MASK (0xE) 44031542fcSKonstantin Porotchkin 45031542fcSKonstantin Porotchkin /* SATA3 MBUS to AXI regs */ 46031542fcSKonstantin Porotchkin #define MVEBU_BRIDGE_WIN_DIS_REG (MVEBU_SOC_CFGS_OFFSET + 0x10) 47031542fcSKonstantin Porotchkin #define MVEBU_BRIDGE_WIN_DIS_OFF (0x0) 48031542fcSKonstantin Porotchkin 49031542fcSKonstantin Porotchkin /* SATA3 MBUS to AXI regs */ 50031542fcSKonstantin Porotchkin #define MVEBU_SATA_M2A_AXI_PORT_CTRL_REG (0x54ff04) 51031542fcSKonstantin Porotchkin 52031542fcSKonstantin Porotchkin /* AXI to MBUS bridge registers */ 53031542fcSKonstantin Porotchkin #define MVEBU_AMB_IP_OFFSET (0x13ff00) 54031542fcSKonstantin Porotchkin #define MVEBU_AMB_IP_BRIDGE_WIN_REG(win) (MVEBU_AMB_IP_OFFSET + \ 55031542fcSKonstantin Porotchkin (win * 0x8)) 56031542fcSKonstantin Porotchkin #define MVEBU_AMB_IP_BRIDGE_WIN_EN_OFFSET 0 57031542fcSKonstantin Porotchkin #define MVEBU_AMB_IP_BRIDGE_WIN_EN_MASK \ 58031542fcSKonstantin Porotchkin (0x1 << MVEBU_AMB_IP_BRIDGE_WIN_EN_OFFSET) 59031542fcSKonstantin Porotchkin #define MVEBU_AMB_IP_BRIDGE_WIN_SIZE_OFFSET 16 60031542fcSKonstantin Porotchkin #define MVEBU_AMB_IP_BRIDGE_WIN_SIZE_MASK \ 61b19498b9SJustin Chadwell (0xffffu << MVEBU_AMB_IP_BRIDGE_WIN_SIZE_OFFSET) 62031542fcSKonstantin Porotchkin 63031542fcSKonstantin Porotchkin #define MVEBU_SAMPLE_AT_RESET_REG (0x440600) 64031542fcSKonstantin Porotchkin #define SAR_PCIE1_CLK_CFG_OFFSET 31 65b19498b9SJustin Chadwell #define SAR_PCIE1_CLK_CFG_MASK (0x1u << SAR_PCIE1_CLK_CFG_OFFSET) 66031542fcSKonstantin Porotchkin #define SAR_PCIE0_CLK_CFG_OFFSET 30 67031542fcSKonstantin Porotchkin #define SAR_PCIE0_CLK_CFG_MASK (0x1 << SAR_PCIE0_CLK_CFG_OFFSET) 68031542fcSKonstantin Porotchkin #define SAR_I2C_INIT_EN_OFFSET 24 69031542fcSKonstantin Porotchkin #define SAR_I2C_INIT_EN_MASK (1 << SAR_I2C_INIT_EN_OFFSET) 70031542fcSKonstantin Porotchkin 71031542fcSKonstantin Porotchkin /******************************************************************************* 72031542fcSKonstantin Porotchkin * PCIE clock buffer control 73031542fcSKonstantin Porotchkin ******************************************************************************/ 74031542fcSKonstantin Porotchkin #define MVEBU_PCIE_REF_CLK_BUF_CTRL (0x4404F0) 75031542fcSKonstantin Porotchkin #define PCIE1_REFCLK_BUFF_SOURCE 0x800 76031542fcSKonstantin Porotchkin #define PCIE0_REFCLK_BUFF_SOURCE 0x400 77031542fcSKonstantin Porotchkin 78031542fcSKonstantin Porotchkin /******************************************************************************* 79031542fcSKonstantin Porotchkin * MSS Device Push Set Register 80031542fcSKonstantin Porotchkin ******************************************************************************/ 81031542fcSKonstantin Porotchkin #define MVEBU_CP_MSS_DPSHSR_REG (0x280040) 82031542fcSKonstantin Porotchkin #define MSS_DPSHSR_REG_PCIE_CLK_SEL 0x8 83031542fcSKonstantin Porotchkin 84031542fcSKonstantin Porotchkin /******************************************************************************* 85031542fcSKonstantin Porotchkin * RTC Configuration 86031542fcSKonstantin Porotchkin ******************************************************************************/ 87031542fcSKonstantin Porotchkin #define MVEBU_RTC_BASE (0x284000) 88031542fcSKonstantin Porotchkin #define MVEBU_RTC_STATUS_REG (MVEBU_RTC_BASE + 0x0) 89031542fcSKonstantin Porotchkin #define MVEBU_RTC_STATUS_ALARM1_MASK 0x1 90031542fcSKonstantin Porotchkin #define MVEBU_RTC_STATUS_ALARM2_MASK 0x2 91031542fcSKonstantin Porotchkin #define MVEBU_RTC_IRQ_1_CONFIG_REG (MVEBU_RTC_BASE + 0x4) 92031542fcSKonstantin Porotchkin #define MVEBU_RTC_IRQ_2_CONFIG_REG (MVEBU_RTC_BASE + 0x8) 93031542fcSKonstantin Porotchkin #define MVEBU_RTC_TIME_REG (MVEBU_RTC_BASE + 0xC) 94031542fcSKonstantin Porotchkin #define MVEBU_RTC_ALARM_1_REG (MVEBU_RTC_BASE + 0x10) 95031542fcSKonstantin Porotchkin #define MVEBU_RTC_ALARM_2_REG (MVEBU_RTC_BASE + 0x14) 96031542fcSKonstantin Porotchkin #define MVEBU_RTC_CCR_REG (MVEBU_RTC_BASE + 0x18) 97031542fcSKonstantin Porotchkin #define MVEBU_RTC_NOMINAL_TIMING 0x2000 98031542fcSKonstantin Porotchkin #define MVEBU_RTC_NOMINAL_TIMING_MASK 0x7FFF 99031542fcSKonstantin Porotchkin #define MVEBU_RTC_TEST_CONFIG_REG (MVEBU_RTC_BASE + 0x1C) 100031542fcSKonstantin Porotchkin #define MVEBU_RTC_BRIDGE_TIMING_CTRL0_REG (MVEBU_RTC_BASE + 0x80) 101031542fcSKonstantin Porotchkin #define MVEBU_RTC_WRCLK_PERIOD_MASK 0xFFFF 102031542fcSKonstantin Porotchkin #define MVEBU_RTC_WRCLK_PERIOD_DEFAULT 0x3FF 103031542fcSKonstantin Porotchkin #define MVEBU_RTC_WRCLK_SETUP_OFFS 16 104031542fcSKonstantin Porotchkin #define MVEBU_RTC_WRCLK_SETUP_MASK 0xFFFF0000 105031542fcSKonstantin Porotchkin #define MVEBU_RTC_WRCLK_SETUP_DEFAULT 0x29 106031542fcSKonstantin Porotchkin #define MVEBU_RTC_BRIDGE_TIMING_CTRL1_REG (MVEBU_RTC_BASE + 0x84) 107031542fcSKonstantin Porotchkin #define MVEBU_RTC_READ_OUTPUT_DELAY_MASK 0xFFFF 108031542fcSKonstantin Porotchkin #define MVEBU_RTC_READ_OUTPUT_DELAY_DEFAULT 0x1F 109031542fcSKonstantin Porotchkin 11057660d9dSKonstantin Porotchkin /******************************************************************************* 11157660d9dSKonstantin Porotchkin * TRNG Configuration 11257660d9dSKonstantin Porotchkin ******************************************************************************/ 11357660d9dSKonstantin Porotchkin #define MVEBU_TRNG_BASE (0x760000) 114*4eb72fe9SKonstantin Porotchkin #define MVEBU_EFUSE_TRNG_ENABLE_EFUSE_WORD MVEBU_AP_LDX_220_189_EFUSE_OFFS 115*4eb72fe9SKonstantin Porotchkin #define MVEBU_EFUSE_TRNG_ENABLE_BIT_OFFSET 13 /* LD0[202] */ 11657660d9dSKonstantin Porotchkin 117031542fcSKonstantin Porotchkin enum axi_attr { 118031542fcSKonstantin Porotchkin AXI_ADUNIT_ATTR = 0, 119031542fcSKonstantin Porotchkin AXI_COMUNIT_ATTR, 120031542fcSKonstantin Porotchkin AXI_EIP197_ATTR, 121031542fcSKonstantin Porotchkin AXI_USB3D_ATTR, 122031542fcSKonstantin Porotchkin AXI_USB3H0_ATTR, 123031542fcSKonstantin Porotchkin AXI_USB3H1_ATTR, 124031542fcSKonstantin Porotchkin AXI_SATA0_ATTR, 125031542fcSKonstantin Porotchkin AXI_SATA1_ATTR, 126031542fcSKonstantin Porotchkin AXI_DAP_ATTR, 127031542fcSKonstantin Porotchkin AXI_DFX_ATTR, 128031542fcSKonstantin Porotchkin AXI_DBG_TRC_ATTR = 12, 129031542fcSKonstantin Porotchkin AXI_SDIO_ATTR, 130031542fcSKonstantin Porotchkin AXI_MSS_ATTR, 131031542fcSKonstantin Porotchkin AXI_MAX_ATTR, 132031542fcSKonstantin Porotchkin }; 133031542fcSKonstantin Porotchkin 134031542fcSKonstantin Porotchkin /* Most stream IDS are configured centrally in the CP-110 RFU 135031542fcSKonstantin Porotchkin * but some are configured inside the unit registers 136031542fcSKonstantin Porotchkin */ 137031542fcSKonstantin Porotchkin #define RFU_STREAM_ID_BASE (0x450000) 138031542fcSKonstantin Porotchkin #define USB3H_0_STREAM_ID_REG (RFU_STREAM_ID_BASE + 0xC) 139031542fcSKonstantin Porotchkin #define USB3H_1_STREAM_ID_REG (RFU_STREAM_ID_BASE + 0x10) 140031542fcSKonstantin Porotchkin #define SATA_0_STREAM_ID_REG (RFU_STREAM_ID_BASE + 0x14) 141031542fcSKonstantin Porotchkin #define SATA_1_STREAM_ID_REG (RFU_STREAM_ID_BASE + 0x18) 142c82cf21dSKonstantin Porotchkin #define SDIO_STREAM_ID_REG (RFU_STREAM_ID_BASE + 0x28) 143031542fcSKonstantin Porotchkin 144031542fcSKonstantin Porotchkin #define CP_DMA_0_STREAM_ID_REG (0x6B0010) 145031542fcSKonstantin Porotchkin #define CP_DMA_1_STREAM_ID_REG (0x6D0010) 146031542fcSKonstantin Porotchkin 147031542fcSKonstantin Porotchkin /* We allocate IDs 128-255 for PCIe */ 148031542fcSKonstantin Porotchkin #define MAX_STREAM_ID (0x80) 149031542fcSKonstantin Porotchkin 150c82cf21dSKonstantin Porotchkin static uintptr_t stream_id_reg[] = { 151031542fcSKonstantin Porotchkin USB3H_0_STREAM_ID_REG, 152031542fcSKonstantin Porotchkin USB3H_1_STREAM_ID_REG, 153031542fcSKonstantin Porotchkin CP_DMA_0_STREAM_ID_REG, 154031542fcSKonstantin Porotchkin CP_DMA_1_STREAM_ID_REG, 155031542fcSKonstantin Porotchkin SATA_0_STREAM_ID_REG, 156031542fcSKonstantin Porotchkin SATA_1_STREAM_ID_REG, 157c82cf21dSKonstantin Porotchkin SDIO_STREAM_ID_REG, 158031542fcSKonstantin Porotchkin 0 159031542fcSKonstantin Porotchkin }; 160031542fcSKonstantin Porotchkin 161031542fcSKonstantin Porotchkin static void cp110_errata_wa_init(uintptr_t base) 162031542fcSKonstantin Porotchkin { 163031542fcSKonstantin Porotchkin uint32_t data; 164031542fcSKonstantin Porotchkin 165031542fcSKonstantin Porotchkin /* ERRATA GL-4076863: 166031542fcSKonstantin Porotchkin * Reset value for global_secure_enable inputs must be changed 167031542fcSKonstantin Porotchkin * from '1' to '0'. 168031542fcSKonstantin Porotchkin * When asserted, only "secured" transactions can enter IHB 169031542fcSKonstantin Porotchkin * configuration space. 170031542fcSKonstantin Porotchkin * However, blocking AXI transactions is performed by IOB. 171031542fcSKonstantin Porotchkin * Performing it also at IHB/HB complicates programming model. 172031542fcSKonstantin Porotchkin * 173031542fcSKonstantin Porotchkin * Enable non-secure access in SOC configuration register 174031542fcSKonstantin Porotchkin */ 175031542fcSKonstantin Porotchkin data = mmio_read_32(base + MVEBU_SOC_CFG_REG(MVEBU_SOC_CFG_REG_NUM)); 176031542fcSKonstantin Porotchkin data &= ~MVEBU_SOC_CFG_GLOG_SECURE_EN_MASK; 177031542fcSKonstantin Porotchkin mmio_write_32(base + MVEBU_SOC_CFG_REG(MVEBU_SOC_CFG_REG_NUM), data); 178031542fcSKonstantin Porotchkin } 179031542fcSKonstantin Porotchkin 180031542fcSKonstantin Porotchkin static void cp110_pcie_clk_cfg(uintptr_t base) 181031542fcSKonstantin Porotchkin { 182031542fcSKonstantin Porotchkin uint32_t pcie0_clk, pcie1_clk, reg; 183031542fcSKonstantin Porotchkin 184031542fcSKonstantin Porotchkin /* 185031542fcSKonstantin Porotchkin * Determine the pcie0/1 clock direction (input/output) from the 186031542fcSKonstantin Porotchkin * sample at reset. 187031542fcSKonstantin Porotchkin */ 188031542fcSKonstantin Porotchkin reg = mmio_read_32(base + MVEBU_SAMPLE_AT_RESET_REG); 189031542fcSKonstantin Porotchkin pcie0_clk = (reg & SAR_PCIE0_CLK_CFG_MASK) >> SAR_PCIE0_CLK_CFG_OFFSET; 190031542fcSKonstantin Porotchkin pcie1_clk = (reg & SAR_PCIE1_CLK_CFG_MASK) >> SAR_PCIE1_CLK_CFG_OFFSET; 191031542fcSKonstantin Porotchkin 1922bcde264SKonstantin Porotchkin /* CP110 revision A2 or CN913x */ 1932bcde264SKonstantin Porotchkin if (cp110_rev_id_get(base) == MVEBU_CP110_REF_ID_A2 || 1942bcde264SKonstantin Porotchkin cp110_device_id_get(base) == MVEBU_CN9130_DEV_ID) { 195031542fcSKonstantin Porotchkin /* 196031542fcSKonstantin Porotchkin * PCIe Reference Clock Buffer Control register must be 197031542fcSKonstantin Porotchkin * set according to the clock direction (input/output) 198031542fcSKonstantin Porotchkin */ 199031542fcSKonstantin Porotchkin reg = mmio_read_32(base + MVEBU_PCIE_REF_CLK_BUF_CTRL); 200031542fcSKonstantin Porotchkin reg &= ~(PCIE0_REFCLK_BUFF_SOURCE | PCIE1_REFCLK_BUFF_SOURCE); 201031542fcSKonstantin Porotchkin if (!pcie0_clk) 202031542fcSKonstantin Porotchkin reg |= PCIE0_REFCLK_BUFF_SOURCE; 203031542fcSKonstantin Porotchkin if (!pcie1_clk) 204031542fcSKonstantin Porotchkin reg |= PCIE1_REFCLK_BUFF_SOURCE; 205031542fcSKonstantin Porotchkin 206031542fcSKonstantin Porotchkin mmio_write_32(base + MVEBU_PCIE_REF_CLK_BUF_CTRL, reg); 207031542fcSKonstantin Porotchkin } 208031542fcSKonstantin Porotchkin 209031542fcSKonstantin Porotchkin /* CP110 revision A1 */ 210031542fcSKonstantin Porotchkin if (cp110_rev_id_get(base) == MVEBU_CP110_REF_ID_A1) { 211031542fcSKonstantin Porotchkin if (!pcie0_clk || !pcie1_clk) { 212031542fcSKonstantin Porotchkin /* 213031542fcSKonstantin Porotchkin * if one of the pcie clocks is set to input, 214031542fcSKonstantin Porotchkin * we need to set mss_push[131] field, otherwise, 215031542fcSKonstantin Porotchkin * the pcie clock might not work. 216031542fcSKonstantin Porotchkin */ 217031542fcSKonstantin Porotchkin reg = mmio_read_32(base + MVEBU_CP_MSS_DPSHSR_REG); 218031542fcSKonstantin Porotchkin reg |= MSS_DPSHSR_REG_PCIE_CLK_SEL; 219031542fcSKonstantin Porotchkin mmio_write_32(base + MVEBU_CP_MSS_DPSHSR_REG, reg); 220031542fcSKonstantin Porotchkin } 221031542fcSKonstantin Porotchkin } 222031542fcSKonstantin Porotchkin } 223031542fcSKonstantin Porotchkin 224031542fcSKonstantin Porotchkin /* Set a unique stream id for all DMA capable devices */ 225031542fcSKonstantin Porotchkin static void cp110_stream_id_init(uintptr_t base, uint32_t stream_id) 226031542fcSKonstantin Porotchkin { 227031542fcSKonstantin Porotchkin int i = 0; 228031542fcSKonstantin Porotchkin 229031542fcSKonstantin Porotchkin while (stream_id_reg[i]) { 230031542fcSKonstantin Porotchkin if (i > MAX_STREAM_ID_PER_CP) { 231031542fcSKonstantin Porotchkin NOTICE("Only first %d (maximum) Stream IDs allocated\n", 232031542fcSKonstantin Porotchkin MAX_STREAM_ID_PER_CP); 233031542fcSKonstantin Porotchkin return; 234031542fcSKonstantin Porotchkin } 235031542fcSKonstantin Porotchkin 236031542fcSKonstantin Porotchkin if ((stream_id_reg[i] == CP_DMA_0_STREAM_ID_REG) || 237031542fcSKonstantin Porotchkin (stream_id_reg[i] == CP_DMA_1_STREAM_ID_REG)) 238031542fcSKonstantin Porotchkin mmio_write_32(base + stream_id_reg[i], 239031542fcSKonstantin Porotchkin stream_id << 16 | stream_id); 240031542fcSKonstantin Porotchkin else 241031542fcSKonstantin Porotchkin mmio_write_32(base + stream_id_reg[i], stream_id); 242031542fcSKonstantin Porotchkin 243031542fcSKonstantin Porotchkin /* SATA port 0/1 are in the same SATA unit, and they should use 244031542fcSKonstantin Porotchkin * the same STREAM ID number 245031542fcSKonstantin Porotchkin */ 246031542fcSKonstantin Porotchkin if (stream_id_reg[i] != SATA_0_STREAM_ID_REG) 247031542fcSKonstantin Porotchkin stream_id++; 248031542fcSKonstantin Porotchkin 249031542fcSKonstantin Porotchkin i++; 250031542fcSKonstantin Porotchkin } 251031542fcSKonstantin Porotchkin } 252031542fcSKonstantin Porotchkin 253031542fcSKonstantin Porotchkin static void cp110_axi_attr_init(uintptr_t base) 254031542fcSKonstantin Porotchkin { 255031542fcSKonstantin Porotchkin uint32_t index, data; 256031542fcSKonstantin Porotchkin 257031542fcSKonstantin Porotchkin /* Initialize AXI attributes for Armada-7K/8K SoC */ 258031542fcSKonstantin Porotchkin 259031542fcSKonstantin Porotchkin /* Go over the AXI attributes and set Ax-Cache and Ax-Domain */ 260031542fcSKonstantin Porotchkin for (index = 0; index < AXI_MAX_ATTR; index++) { 261031542fcSKonstantin Porotchkin switch (index) { 262031542fcSKonstantin Porotchkin /* DFX and MSS unit works with no coherent only - 263031542fcSKonstantin Porotchkin * there's no option to configure the Ax-Cache and Ax-Domain 264031542fcSKonstantin Porotchkin */ 265031542fcSKonstantin Porotchkin case AXI_DFX_ATTR: 266031542fcSKonstantin Porotchkin case AXI_MSS_ATTR: 267031542fcSKonstantin Porotchkin continue; 268031542fcSKonstantin Porotchkin default: 269031542fcSKonstantin Porotchkin /* Set Ax-Cache as cacheable, no allocate, modifiable, 270031542fcSKonstantin Porotchkin * bufferable 271031542fcSKonstantin Porotchkin * The values are different because Read & Write 272031542fcSKonstantin Porotchkin * definition is different in Ax-Cache 273031542fcSKonstantin Porotchkin */ 274031542fcSKonstantin Porotchkin data = mmio_read_32(base + MVEBU_AXI_ATTR_REG(index)); 275031542fcSKonstantin Porotchkin data &= ~MVEBU_AXI_ATTR_ARCACHE_MASK; 276031542fcSKonstantin Porotchkin data |= (CACHE_ATTR_WRITE_ALLOC | 277031542fcSKonstantin Porotchkin CACHE_ATTR_CACHEABLE | 278031542fcSKonstantin Porotchkin CACHE_ATTR_BUFFERABLE) << 279031542fcSKonstantin Porotchkin MVEBU_AXI_ATTR_ARCACHE_OFFSET; 280031542fcSKonstantin Porotchkin data &= ~MVEBU_AXI_ATTR_AWCACHE_MASK; 281031542fcSKonstantin Porotchkin data |= (CACHE_ATTR_READ_ALLOC | 282031542fcSKonstantin Porotchkin CACHE_ATTR_CACHEABLE | 283031542fcSKonstantin Porotchkin CACHE_ATTR_BUFFERABLE) << 284031542fcSKonstantin Porotchkin MVEBU_AXI_ATTR_AWCACHE_OFFSET; 285031542fcSKonstantin Porotchkin /* Set Ax-Domain as Outer domain */ 286031542fcSKonstantin Porotchkin data &= ~MVEBU_AXI_ATTR_ARDOMAIN_MASK; 287031542fcSKonstantin Porotchkin data |= DOMAIN_OUTER_SHAREABLE << 288031542fcSKonstantin Porotchkin MVEBU_AXI_ATTR_ARDOMAIN_OFFSET; 289031542fcSKonstantin Porotchkin data &= ~MVEBU_AXI_ATTR_AWDOMAIN_MASK; 290031542fcSKonstantin Porotchkin data |= DOMAIN_OUTER_SHAREABLE << 291031542fcSKonstantin Porotchkin MVEBU_AXI_ATTR_AWDOMAIN_OFFSET; 292031542fcSKonstantin Porotchkin mmio_write_32(base + MVEBU_AXI_ATTR_REG(index), data); 293031542fcSKonstantin Porotchkin } 294031542fcSKonstantin Porotchkin } 295031542fcSKonstantin Porotchkin 296031542fcSKonstantin Porotchkin /* SATA IOCC supported, cache attributes 297031542fcSKonstantin Porotchkin * for SATA MBUS to AXI configuration. 298031542fcSKonstantin Porotchkin */ 299031542fcSKonstantin Porotchkin data = mmio_read_32(base + MVEBU_SATA_M2A_AXI_PORT_CTRL_REG); 300031542fcSKonstantin Porotchkin data &= ~MVEBU_SATA_M2A_AXI_AWCACHE_MASK; 301031542fcSKonstantin Porotchkin data |= (CACHE_ATTR_WRITE_ALLOC | 302031542fcSKonstantin Porotchkin CACHE_ATTR_CACHEABLE | 303031542fcSKonstantin Porotchkin CACHE_ATTR_BUFFERABLE) << 304031542fcSKonstantin Porotchkin MVEBU_SATA_M2A_AXI_AWCACHE_OFFSET; 305031542fcSKonstantin Porotchkin data &= ~MVEBU_SATA_M2A_AXI_ARCACHE_MASK; 306031542fcSKonstantin Porotchkin data |= (CACHE_ATTR_READ_ALLOC | 307031542fcSKonstantin Porotchkin CACHE_ATTR_CACHEABLE | 308031542fcSKonstantin Porotchkin CACHE_ATTR_BUFFERABLE) << 309031542fcSKonstantin Porotchkin MVEBU_SATA_M2A_AXI_ARCACHE_OFFSET; 310031542fcSKonstantin Porotchkin mmio_write_32(base + MVEBU_SATA_M2A_AXI_PORT_CTRL_REG, data); 311031542fcSKonstantin Porotchkin 312031542fcSKonstantin Porotchkin /* Set all IO's AXI attribute to non-secure access. */ 313031542fcSKonstantin Porotchkin for (index = 0; index < MVEBU_AXI_PROT_REGS_NUM; index++) 314031542fcSKonstantin Porotchkin mmio_write_32(base + MVEBU_AXI_PROT_REG(index), 315031542fcSKonstantin Porotchkin DOMAIN_SYSTEM_SHAREABLE); 316031542fcSKonstantin Porotchkin } 317031542fcSKonstantin Porotchkin 31881646055SGrzegorz Jaszczyk void cp110_amb_init(uintptr_t base) 319031542fcSKonstantin Porotchkin { 320031542fcSKonstantin Porotchkin uint32_t reg; 321031542fcSKonstantin Porotchkin 322031542fcSKonstantin Porotchkin /* Open AMB bridge Window to Access COMPHY/MDIO registers */ 323031542fcSKonstantin Porotchkin reg = mmio_read_32(base + MVEBU_AMB_IP_BRIDGE_WIN_REG(0)); 324031542fcSKonstantin Porotchkin reg &= ~(MVEBU_AMB_IP_BRIDGE_WIN_SIZE_MASK | 325031542fcSKonstantin Porotchkin MVEBU_AMB_IP_BRIDGE_WIN_EN_MASK); 326031542fcSKonstantin Porotchkin reg |= (0x7ff << MVEBU_AMB_IP_BRIDGE_WIN_SIZE_OFFSET) | 327031542fcSKonstantin Porotchkin (0x1 << MVEBU_AMB_IP_BRIDGE_WIN_EN_OFFSET); 328031542fcSKonstantin Porotchkin mmio_write_32(base + MVEBU_AMB_IP_BRIDGE_WIN_REG(0), reg); 329031542fcSKonstantin Porotchkin } 330031542fcSKonstantin Porotchkin 331031542fcSKonstantin Porotchkin static void cp110_rtc_init(uintptr_t base) 332031542fcSKonstantin Porotchkin { 333031542fcSKonstantin Porotchkin /* Update MBus timing parameters before accessing RTC registers */ 334031542fcSKonstantin Porotchkin mmio_clrsetbits_32(base + MVEBU_RTC_BRIDGE_TIMING_CTRL0_REG, 335031542fcSKonstantin Porotchkin MVEBU_RTC_WRCLK_PERIOD_MASK, 336031542fcSKonstantin Porotchkin MVEBU_RTC_WRCLK_PERIOD_DEFAULT); 337031542fcSKonstantin Porotchkin 338031542fcSKonstantin Porotchkin mmio_clrsetbits_32(base + MVEBU_RTC_BRIDGE_TIMING_CTRL0_REG, 339031542fcSKonstantin Porotchkin MVEBU_RTC_WRCLK_SETUP_MASK, 340031542fcSKonstantin Porotchkin MVEBU_RTC_WRCLK_SETUP_DEFAULT << 341031542fcSKonstantin Porotchkin MVEBU_RTC_WRCLK_SETUP_OFFS); 342031542fcSKonstantin Porotchkin 343031542fcSKonstantin Porotchkin mmio_clrsetbits_32(base + MVEBU_RTC_BRIDGE_TIMING_CTRL1_REG, 344031542fcSKonstantin Porotchkin MVEBU_RTC_READ_OUTPUT_DELAY_MASK, 345031542fcSKonstantin Porotchkin MVEBU_RTC_READ_OUTPUT_DELAY_DEFAULT); 346031542fcSKonstantin Porotchkin 347031542fcSKonstantin Porotchkin /* 348031542fcSKonstantin Porotchkin * Issue reset to the RTC if Clock Correction register 349031542fcSKonstantin Porotchkin * contents did not sustain the reboot/power-on. 350031542fcSKonstantin Porotchkin */ 351031542fcSKonstantin Porotchkin if ((mmio_read_32(base + MVEBU_RTC_CCR_REG) & 352031542fcSKonstantin Porotchkin MVEBU_RTC_NOMINAL_TIMING_MASK) != MVEBU_RTC_NOMINAL_TIMING) { 353031542fcSKonstantin Porotchkin /* Reset Test register */ 354031542fcSKonstantin Porotchkin mmio_write_32(base + MVEBU_RTC_TEST_CONFIG_REG, 0); 355031542fcSKonstantin Porotchkin mdelay(500); 356031542fcSKonstantin Porotchkin 357031542fcSKonstantin Porotchkin /* Reset Status register */ 358031542fcSKonstantin Porotchkin mmio_write_32(base + MVEBU_RTC_STATUS_REG, 359031542fcSKonstantin Porotchkin (MVEBU_RTC_STATUS_ALARM1_MASK | 360031542fcSKonstantin Porotchkin MVEBU_RTC_STATUS_ALARM2_MASK)); 361031542fcSKonstantin Porotchkin udelay(62); 362031542fcSKonstantin Porotchkin 363031542fcSKonstantin Porotchkin /* Turn off Int1 and Int2 sources & clear the Alarm count */ 364031542fcSKonstantin Porotchkin mmio_write_32(base + MVEBU_RTC_IRQ_1_CONFIG_REG, 0); 365031542fcSKonstantin Porotchkin mmio_write_32(base + MVEBU_RTC_IRQ_2_CONFIG_REG, 0); 366031542fcSKonstantin Porotchkin mmio_write_32(base + MVEBU_RTC_ALARM_1_REG, 0); 367031542fcSKonstantin Porotchkin mmio_write_32(base + MVEBU_RTC_ALARM_2_REG, 0); 368031542fcSKonstantin Porotchkin 369031542fcSKonstantin Porotchkin /* Setup nominal register access timing */ 370031542fcSKonstantin Porotchkin mmio_write_32(base + MVEBU_RTC_CCR_REG, 371031542fcSKonstantin Porotchkin MVEBU_RTC_NOMINAL_TIMING); 372031542fcSKonstantin Porotchkin 373031542fcSKonstantin Porotchkin /* Reset Status register */ 374031542fcSKonstantin Porotchkin mmio_write_32(base + MVEBU_RTC_STATUS_REG, 375031542fcSKonstantin Porotchkin (MVEBU_RTC_STATUS_ALARM1_MASK | 376031542fcSKonstantin Porotchkin MVEBU_RTC_STATUS_ALARM2_MASK)); 377031542fcSKonstantin Porotchkin udelay(50); 378031542fcSKonstantin Porotchkin } 379031542fcSKonstantin Porotchkin } 380031542fcSKonstantin Porotchkin 381031542fcSKonstantin Porotchkin static void cp110_amb_adec_init(uintptr_t base) 382031542fcSKonstantin Porotchkin { 383031542fcSKonstantin Porotchkin /* enable AXI-MBUS by clearing "Bridge Windows Disable" */ 384031542fcSKonstantin Porotchkin mmio_clrbits_32(base + MVEBU_BRIDGE_WIN_DIS_REG, 385031542fcSKonstantin Porotchkin (1 << MVEBU_BRIDGE_WIN_DIS_OFF)); 386031542fcSKonstantin Porotchkin 387031542fcSKonstantin Porotchkin /* configure AXI-MBUS windows for CP */ 388031542fcSKonstantin Porotchkin init_amb_adec(base); 389031542fcSKonstantin Porotchkin } 390031542fcSKonstantin Porotchkin 39157660d9dSKonstantin Porotchkin static void cp110_trng_init(uintptr_t base) 39257660d9dSKonstantin Porotchkin { 39357660d9dSKonstantin Porotchkin static bool done; 39457660d9dSKonstantin Porotchkin int ret; 395*4eb72fe9SKonstantin Porotchkin uint32_t reg_val, efuse; 396*4eb72fe9SKonstantin Porotchkin 397*4eb72fe9SKonstantin Porotchkin /* Set access to LD0 */ 398*4eb72fe9SKonstantin Porotchkin reg_val = mmio_read_32(MVEBU_AP_EFUSE_SRV_CTRL_REG); 399*4eb72fe9SKonstantin Porotchkin reg_val &= ~EFUSE_SRV_CTRL_LD_SELECT_MASK; 400*4eb72fe9SKonstantin Porotchkin mmio_write_32(MVEBU_AP_EFUSE_SRV_CTRL_REG, reg_val); 401*4eb72fe9SKonstantin Porotchkin 402*4eb72fe9SKonstantin Porotchkin /* Obtain the AP LD0 bit defining TRNG presence */ 403*4eb72fe9SKonstantin Porotchkin efuse = mmio_read_32(MVEBU_EFUSE_TRNG_ENABLE_EFUSE_WORD); 404*4eb72fe9SKonstantin Porotchkin efuse >>= MVEBU_EFUSE_TRNG_ENABLE_BIT_OFFSET; 405*4eb72fe9SKonstantin Porotchkin efuse &= 1; 406*4eb72fe9SKonstantin Porotchkin 407*4eb72fe9SKonstantin Porotchkin if (efuse == 0) { 408*4eb72fe9SKonstantin Porotchkin VERBOSE("TRNG is not present, skipping"); 409*4eb72fe9SKonstantin Porotchkin return; 410*4eb72fe9SKonstantin Porotchkin } 41157660d9dSKonstantin Porotchkin 41257660d9dSKonstantin Porotchkin if (!done) { 41357660d9dSKonstantin Porotchkin ret = eip76_rng_probe(base + MVEBU_TRNG_BASE); 41457660d9dSKonstantin Porotchkin if (ret != 0) { 41557660d9dSKonstantin Porotchkin ERROR("Failed to init TRNG @ 0x%lx\n", base); 41657660d9dSKonstantin Porotchkin return; 41757660d9dSKonstantin Porotchkin } 41857660d9dSKonstantin Porotchkin done = true; 41957660d9dSKonstantin Porotchkin } 42057660d9dSKonstantin Porotchkin } 421031542fcSKonstantin Porotchkin void cp110_init(uintptr_t cp110_base, uint32_t stream_id) 422031542fcSKonstantin Porotchkin { 423031542fcSKonstantin Porotchkin INFO("%s: Initialize CPx - base = %lx\n", __func__, cp110_base); 424031542fcSKonstantin Porotchkin 425031542fcSKonstantin Porotchkin /* configure IOB windows for CP0*/ 426031542fcSKonstantin Porotchkin init_iob(cp110_base); 427031542fcSKonstantin Porotchkin 428031542fcSKonstantin Porotchkin /* configure AXI-MBUS windows for CP0*/ 429031542fcSKonstantin Porotchkin cp110_amb_adec_init(cp110_base); 430031542fcSKonstantin Porotchkin 431031542fcSKonstantin Porotchkin /* configure axi for CP0*/ 432031542fcSKonstantin Porotchkin cp110_axi_attr_init(cp110_base); 433031542fcSKonstantin Porotchkin 434031542fcSKonstantin Porotchkin /* Execute SW WA for erratas */ 435031542fcSKonstantin Porotchkin cp110_errata_wa_init(cp110_base); 436031542fcSKonstantin Porotchkin 437031542fcSKonstantin Porotchkin /* Confiure pcie clock according to clock direction */ 438031542fcSKonstantin Porotchkin cp110_pcie_clk_cfg(cp110_base); 439031542fcSKonstantin Porotchkin 440031542fcSKonstantin Porotchkin /* configure stream id for CP0 */ 441031542fcSKonstantin Porotchkin cp110_stream_id_init(cp110_base, stream_id); 442031542fcSKonstantin Porotchkin 443031542fcSKonstantin Porotchkin /* Open AMB bridge for comphy for CP0 & CP1*/ 44481646055SGrzegorz Jaszczyk cp110_amb_init(cp110_base); 445031542fcSKonstantin Porotchkin 446031542fcSKonstantin Porotchkin /* Reset RTC if needed */ 447031542fcSKonstantin Porotchkin cp110_rtc_init(cp110_base); 44857660d9dSKonstantin Porotchkin 44957660d9dSKonstantin Porotchkin /* TRNG init - for CP0 only */ 45057660d9dSKonstantin Porotchkin cp110_trng_init(cp110_base); 451031542fcSKonstantin Porotchkin } 452031542fcSKonstantin Porotchkin 453031542fcSKonstantin Porotchkin /* Do the minimal setup required to configure the CP in BLE */ 454031542fcSKonstantin Porotchkin void cp110_ble_init(uintptr_t cp110_base) 455031542fcSKonstantin Porotchkin { 456031542fcSKonstantin Porotchkin #if PCI_EP_SUPPORT 457031542fcSKonstantin Porotchkin INFO("%s: Initialize CPx - base = %lx\n", __func__, cp110_base); 458031542fcSKonstantin Porotchkin 45981646055SGrzegorz Jaszczyk cp110_amb_init(cp110_base); 460031542fcSKonstantin Porotchkin 461031542fcSKonstantin Porotchkin /* Configure PCIe clock */ 462031542fcSKonstantin Porotchkin cp110_pcie_clk_cfg(cp110_base); 463031542fcSKonstantin Porotchkin 464031542fcSKonstantin Porotchkin /* Configure PCIe endpoint */ 465031542fcSKonstantin Porotchkin ble_plat_pcie_ep_setup(); 466031542fcSKonstantin Porotchkin #endif 467031542fcSKonstantin Porotchkin } 468