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