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