xref: /rk3399_ARM-atf/drivers/marvell/mochi/cp110_setup.c (revision 4301798db0966aeddfa3b97cd637bdbae10e0919)
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>
1509d40e0eSAntonio Nino Diaz 
16*4eb72fe9SKonstantin Porotchkin #include <efuse_def.h>
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 
109031542fcSKonstantin Porotchkin enum axi_attr {
110031542fcSKonstantin Porotchkin 	AXI_ADUNIT_ATTR = 0,
111031542fcSKonstantin Porotchkin 	AXI_COMUNIT_ATTR,
112031542fcSKonstantin Porotchkin 	AXI_EIP197_ATTR,
113031542fcSKonstantin Porotchkin 	AXI_USB3D_ATTR,
114031542fcSKonstantin Porotchkin 	AXI_USB3H0_ATTR,
115031542fcSKonstantin Porotchkin 	AXI_USB3H1_ATTR,
116031542fcSKonstantin Porotchkin 	AXI_SATA0_ATTR,
117031542fcSKonstantin Porotchkin 	AXI_SATA1_ATTR,
118031542fcSKonstantin Porotchkin 	AXI_DAP_ATTR,
119031542fcSKonstantin Porotchkin 	AXI_DFX_ATTR,
120031542fcSKonstantin Porotchkin 	AXI_DBG_TRC_ATTR = 12,
121031542fcSKonstantin Porotchkin 	AXI_SDIO_ATTR,
122031542fcSKonstantin Porotchkin 	AXI_MSS_ATTR,
123031542fcSKonstantin Porotchkin 	AXI_MAX_ATTR,
124031542fcSKonstantin Porotchkin };
125031542fcSKonstantin Porotchkin 
126031542fcSKonstantin Porotchkin /* Most stream IDS are configured centrally in the CP-110 RFU
127031542fcSKonstantin Porotchkin  * but some are configured inside the unit registers
128031542fcSKonstantin Porotchkin  */
129031542fcSKonstantin Porotchkin #define RFU_STREAM_ID_BASE	(0x450000)
130031542fcSKonstantin Porotchkin #define USB3H_0_STREAM_ID_REG	(RFU_STREAM_ID_BASE + 0xC)
131031542fcSKonstantin Porotchkin #define USB3H_1_STREAM_ID_REG	(RFU_STREAM_ID_BASE + 0x10)
132031542fcSKonstantin Porotchkin #define SATA_0_STREAM_ID_REG	(RFU_STREAM_ID_BASE + 0x14)
133031542fcSKonstantin Porotchkin #define SATA_1_STREAM_ID_REG	(RFU_STREAM_ID_BASE + 0x18)
134c82cf21dSKonstantin Porotchkin #define SDIO_STREAM_ID_REG	(RFU_STREAM_ID_BASE + 0x28)
135031542fcSKonstantin Porotchkin 
136031542fcSKonstantin Porotchkin #define CP_DMA_0_STREAM_ID_REG  (0x6B0010)
137031542fcSKonstantin Porotchkin #define CP_DMA_1_STREAM_ID_REG  (0x6D0010)
138031542fcSKonstantin Porotchkin 
139031542fcSKonstantin Porotchkin /* We allocate IDs 128-255 for PCIe */
140031542fcSKonstantin Porotchkin #define MAX_STREAM_ID		(0x80)
141031542fcSKonstantin Porotchkin 
142c82cf21dSKonstantin Porotchkin static uintptr_t stream_id_reg[] = {
143031542fcSKonstantin Porotchkin 	USB3H_0_STREAM_ID_REG,
144031542fcSKonstantin Porotchkin 	USB3H_1_STREAM_ID_REG,
145031542fcSKonstantin Porotchkin 	CP_DMA_0_STREAM_ID_REG,
146031542fcSKonstantin Porotchkin 	CP_DMA_1_STREAM_ID_REG,
147031542fcSKonstantin Porotchkin 	SATA_0_STREAM_ID_REG,
148031542fcSKonstantin Porotchkin 	SATA_1_STREAM_ID_REG,
149c82cf21dSKonstantin Porotchkin 	SDIO_STREAM_ID_REG,
150031542fcSKonstantin Porotchkin 	0
151031542fcSKonstantin Porotchkin };
152031542fcSKonstantin Porotchkin 
cp110_errata_wa_init(uintptr_t base)153031542fcSKonstantin Porotchkin static void cp110_errata_wa_init(uintptr_t base)
154031542fcSKonstantin Porotchkin {
155031542fcSKonstantin Porotchkin 	uint32_t data;
156031542fcSKonstantin Porotchkin 
157031542fcSKonstantin Porotchkin 	/* ERRATA GL-4076863:
158031542fcSKonstantin Porotchkin 	 * Reset value for global_secure_enable inputs must be changed
159031542fcSKonstantin Porotchkin 	 * from '1' to '0'.
160031542fcSKonstantin Porotchkin 	 * When asserted, only "secured" transactions can enter IHB
161031542fcSKonstantin Porotchkin 	 * configuration space.
162031542fcSKonstantin Porotchkin 	 * However, blocking AXI transactions is performed by IOB.
163031542fcSKonstantin Porotchkin 	 * Performing it also at IHB/HB complicates programming model.
164031542fcSKonstantin Porotchkin 	 *
165031542fcSKonstantin Porotchkin 	 * Enable non-secure access in SOC configuration register
166031542fcSKonstantin Porotchkin 	 */
167031542fcSKonstantin Porotchkin 	data = mmio_read_32(base + MVEBU_SOC_CFG_REG(MVEBU_SOC_CFG_REG_NUM));
168031542fcSKonstantin Porotchkin 	data &= ~MVEBU_SOC_CFG_GLOG_SECURE_EN_MASK;
169031542fcSKonstantin Porotchkin 	mmio_write_32(base + MVEBU_SOC_CFG_REG(MVEBU_SOC_CFG_REG_NUM), data);
170031542fcSKonstantin Porotchkin }
171031542fcSKonstantin Porotchkin 
cp110_pcie_clk_cfg(uintptr_t base)172031542fcSKonstantin Porotchkin static void cp110_pcie_clk_cfg(uintptr_t base)
173031542fcSKonstantin Porotchkin {
174031542fcSKonstantin Porotchkin 	uint32_t pcie0_clk, pcie1_clk, reg;
175031542fcSKonstantin Porotchkin 
176031542fcSKonstantin Porotchkin 	/*
177031542fcSKonstantin Porotchkin 	 * Determine the pcie0/1 clock direction (input/output) from the
178031542fcSKonstantin Porotchkin 	 * sample at reset.
179031542fcSKonstantin Porotchkin 	 */
180031542fcSKonstantin Porotchkin 	reg = mmio_read_32(base + MVEBU_SAMPLE_AT_RESET_REG);
181031542fcSKonstantin Porotchkin 	pcie0_clk = (reg & SAR_PCIE0_CLK_CFG_MASK) >> SAR_PCIE0_CLK_CFG_OFFSET;
182031542fcSKonstantin Porotchkin 	pcie1_clk = (reg & SAR_PCIE1_CLK_CFG_MASK) >> SAR_PCIE1_CLK_CFG_OFFSET;
183031542fcSKonstantin Porotchkin 
1842bcde264SKonstantin Porotchkin 	/* CP110 revision A2 or CN913x */
1852bcde264SKonstantin Porotchkin 	if (cp110_rev_id_get(base) == MVEBU_CP110_REF_ID_A2 ||
1862bcde264SKonstantin Porotchkin 	    cp110_device_id_get(base) == MVEBU_CN9130_DEV_ID) {
187031542fcSKonstantin Porotchkin 		/*
188031542fcSKonstantin Porotchkin 		 * PCIe Reference Clock Buffer Control register must be
189031542fcSKonstantin Porotchkin 		 * set according to the clock direction (input/output)
190031542fcSKonstantin Porotchkin 		 */
191031542fcSKonstantin Porotchkin 		reg = mmio_read_32(base + MVEBU_PCIE_REF_CLK_BUF_CTRL);
192031542fcSKonstantin Porotchkin 		reg &= ~(PCIE0_REFCLK_BUFF_SOURCE | PCIE1_REFCLK_BUFF_SOURCE);
193031542fcSKonstantin Porotchkin 		if (!pcie0_clk)
194031542fcSKonstantin Porotchkin 			reg |= PCIE0_REFCLK_BUFF_SOURCE;
195031542fcSKonstantin Porotchkin 		if (!pcie1_clk)
196031542fcSKonstantin Porotchkin 			reg |= PCIE1_REFCLK_BUFF_SOURCE;
197031542fcSKonstantin Porotchkin 
198031542fcSKonstantin Porotchkin 		mmio_write_32(base + MVEBU_PCIE_REF_CLK_BUF_CTRL, reg);
199031542fcSKonstantin Porotchkin 	}
200031542fcSKonstantin Porotchkin 
201031542fcSKonstantin Porotchkin 	/* CP110 revision A1 */
202031542fcSKonstantin Porotchkin 	if (cp110_rev_id_get(base) == MVEBU_CP110_REF_ID_A1) {
203031542fcSKonstantin Porotchkin 		if (!pcie0_clk || !pcie1_clk) {
204031542fcSKonstantin Porotchkin 			/*
205031542fcSKonstantin Porotchkin 			 * if one of the pcie clocks is set to input,
206031542fcSKonstantin Porotchkin 			 * we need to set mss_push[131] field, otherwise,
207031542fcSKonstantin Porotchkin 			 * the pcie clock might not work.
208031542fcSKonstantin Porotchkin 			 */
209031542fcSKonstantin Porotchkin 			reg = mmio_read_32(base + MVEBU_CP_MSS_DPSHSR_REG);
210031542fcSKonstantin Porotchkin 			reg |= MSS_DPSHSR_REG_PCIE_CLK_SEL;
211031542fcSKonstantin Porotchkin 			mmio_write_32(base + MVEBU_CP_MSS_DPSHSR_REG, reg);
212031542fcSKonstantin Porotchkin 		}
213031542fcSKonstantin Porotchkin 	}
214031542fcSKonstantin Porotchkin }
215031542fcSKonstantin Porotchkin 
216031542fcSKonstantin Porotchkin /* Set a unique stream id for all DMA capable devices */
cp110_stream_id_init(uintptr_t base,uint32_t stream_id)217031542fcSKonstantin Porotchkin static void cp110_stream_id_init(uintptr_t base, uint32_t stream_id)
218031542fcSKonstantin Porotchkin {
219031542fcSKonstantin Porotchkin 	int i = 0;
220031542fcSKonstantin Porotchkin 
221031542fcSKonstantin Porotchkin 	while (stream_id_reg[i]) {
222031542fcSKonstantin Porotchkin 		if (i > MAX_STREAM_ID_PER_CP) {
223031542fcSKonstantin Porotchkin 			NOTICE("Only first %d (maximum) Stream IDs allocated\n",
224031542fcSKonstantin Porotchkin 			       MAX_STREAM_ID_PER_CP);
225031542fcSKonstantin Porotchkin 			return;
226031542fcSKonstantin Porotchkin 		}
227031542fcSKonstantin Porotchkin 
228031542fcSKonstantin Porotchkin 		if ((stream_id_reg[i] == CP_DMA_0_STREAM_ID_REG) ||
229031542fcSKonstantin Porotchkin 		    (stream_id_reg[i] == CP_DMA_1_STREAM_ID_REG))
230031542fcSKonstantin Porotchkin 			mmio_write_32(base + stream_id_reg[i],
231031542fcSKonstantin Porotchkin 				      stream_id << 16 |  stream_id);
232031542fcSKonstantin Porotchkin 		else
233031542fcSKonstantin Porotchkin 			mmio_write_32(base + stream_id_reg[i], stream_id);
234031542fcSKonstantin Porotchkin 
235031542fcSKonstantin Porotchkin 		/* SATA port 0/1 are in the same SATA unit, and they should use
236031542fcSKonstantin Porotchkin 		 * the same STREAM ID number
237031542fcSKonstantin Porotchkin 		 */
238031542fcSKonstantin Porotchkin 		if (stream_id_reg[i] != SATA_0_STREAM_ID_REG)
239031542fcSKonstantin Porotchkin 			stream_id++;
240031542fcSKonstantin Porotchkin 
241031542fcSKonstantin Porotchkin 		i++;
242031542fcSKonstantin Porotchkin 	}
243031542fcSKonstantin Porotchkin }
244031542fcSKonstantin Porotchkin 
cp110_axi_attr_init(uintptr_t base)245031542fcSKonstantin Porotchkin static void cp110_axi_attr_init(uintptr_t base)
246031542fcSKonstantin Porotchkin {
247031542fcSKonstantin Porotchkin 	uint32_t index, data;
248031542fcSKonstantin Porotchkin 
249031542fcSKonstantin Porotchkin 	/* Initialize AXI attributes for Armada-7K/8K SoC */
250031542fcSKonstantin Porotchkin 
251031542fcSKonstantin Porotchkin 	/* Go over the AXI attributes and set Ax-Cache and Ax-Domain */
252031542fcSKonstantin Porotchkin 	for (index = 0; index < AXI_MAX_ATTR; index++) {
253031542fcSKonstantin Porotchkin 		switch (index) {
254031542fcSKonstantin Porotchkin 		/* DFX and MSS unit works with no coherent only -
255031542fcSKonstantin Porotchkin 		 * there's no option to configure the Ax-Cache and Ax-Domain
256031542fcSKonstantin Porotchkin 		 */
257031542fcSKonstantin Porotchkin 		case AXI_DFX_ATTR:
258031542fcSKonstantin Porotchkin 		case AXI_MSS_ATTR:
259031542fcSKonstantin Porotchkin 			continue;
260031542fcSKonstantin Porotchkin 		default:
261031542fcSKonstantin Porotchkin 			/* Set Ax-Cache as cacheable, no allocate, modifiable,
262031542fcSKonstantin Porotchkin 			 * bufferable
263031542fcSKonstantin Porotchkin 			 * The values are different because Read & Write
264031542fcSKonstantin Porotchkin 			 * definition is different in Ax-Cache
265031542fcSKonstantin Porotchkin 			 */
266031542fcSKonstantin Porotchkin 			data = mmio_read_32(base + MVEBU_AXI_ATTR_REG(index));
267031542fcSKonstantin Porotchkin 			data &= ~MVEBU_AXI_ATTR_ARCACHE_MASK;
268031542fcSKonstantin Porotchkin 			data |= (CACHE_ATTR_WRITE_ALLOC |
269031542fcSKonstantin Porotchkin 				 CACHE_ATTR_CACHEABLE   |
270031542fcSKonstantin Porotchkin 				 CACHE_ATTR_BUFFERABLE) <<
271031542fcSKonstantin Porotchkin 				 MVEBU_AXI_ATTR_ARCACHE_OFFSET;
272031542fcSKonstantin Porotchkin 			data &= ~MVEBU_AXI_ATTR_AWCACHE_MASK;
273031542fcSKonstantin Porotchkin 			data |= (CACHE_ATTR_READ_ALLOC |
274031542fcSKonstantin Porotchkin 				 CACHE_ATTR_CACHEABLE  |
275031542fcSKonstantin Porotchkin 				 CACHE_ATTR_BUFFERABLE) <<
276031542fcSKonstantin Porotchkin 				 MVEBU_AXI_ATTR_AWCACHE_OFFSET;
277031542fcSKonstantin Porotchkin 			/* Set Ax-Domain as Outer domain */
278031542fcSKonstantin Porotchkin 			data &= ~MVEBU_AXI_ATTR_ARDOMAIN_MASK;
279031542fcSKonstantin Porotchkin 			data |= DOMAIN_OUTER_SHAREABLE <<
280031542fcSKonstantin Porotchkin 				MVEBU_AXI_ATTR_ARDOMAIN_OFFSET;
281031542fcSKonstantin Porotchkin 			data &= ~MVEBU_AXI_ATTR_AWDOMAIN_MASK;
282031542fcSKonstantin Porotchkin 			data |= DOMAIN_OUTER_SHAREABLE <<
283031542fcSKonstantin Porotchkin 				MVEBU_AXI_ATTR_AWDOMAIN_OFFSET;
284031542fcSKonstantin Porotchkin 			mmio_write_32(base + MVEBU_AXI_ATTR_REG(index), data);
285031542fcSKonstantin Porotchkin 		}
286031542fcSKonstantin Porotchkin 	}
287031542fcSKonstantin Porotchkin 
288031542fcSKonstantin Porotchkin 	/* SATA IOCC supported, cache attributes
289031542fcSKonstantin Porotchkin 	 * for SATA MBUS to AXI configuration.
290031542fcSKonstantin Porotchkin 	 */
291031542fcSKonstantin Porotchkin 	data = mmio_read_32(base + MVEBU_SATA_M2A_AXI_PORT_CTRL_REG);
292031542fcSKonstantin Porotchkin 	data &= ~MVEBU_SATA_M2A_AXI_AWCACHE_MASK;
293031542fcSKonstantin Porotchkin 	data |= (CACHE_ATTR_WRITE_ALLOC |
294031542fcSKonstantin Porotchkin 		 CACHE_ATTR_CACHEABLE   |
295031542fcSKonstantin Porotchkin 		 CACHE_ATTR_BUFFERABLE) <<
296031542fcSKonstantin Porotchkin 		 MVEBU_SATA_M2A_AXI_AWCACHE_OFFSET;
297031542fcSKonstantin Porotchkin 	data &= ~MVEBU_SATA_M2A_AXI_ARCACHE_MASK;
298031542fcSKonstantin Porotchkin 	data |= (CACHE_ATTR_READ_ALLOC |
299031542fcSKonstantin Porotchkin 		 CACHE_ATTR_CACHEABLE  |
300031542fcSKonstantin Porotchkin 		 CACHE_ATTR_BUFFERABLE) <<
301031542fcSKonstantin Porotchkin 		 MVEBU_SATA_M2A_AXI_ARCACHE_OFFSET;
302031542fcSKonstantin Porotchkin 	mmio_write_32(base + MVEBU_SATA_M2A_AXI_PORT_CTRL_REG, data);
303031542fcSKonstantin Porotchkin 
304031542fcSKonstantin Porotchkin 	/* Set all IO's AXI attribute to non-secure access. */
305031542fcSKonstantin Porotchkin 	for (index = 0; index < MVEBU_AXI_PROT_REGS_NUM; index++)
306031542fcSKonstantin Porotchkin 		mmio_write_32(base + MVEBU_AXI_PROT_REG(index),
307031542fcSKonstantin Porotchkin 			      DOMAIN_SYSTEM_SHAREABLE);
308031542fcSKonstantin Porotchkin }
309031542fcSKonstantin Porotchkin 
cp110_amb_init(uintptr_t base)31081646055SGrzegorz Jaszczyk void cp110_amb_init(uintptr_t base)
311031542fcSKonstantin Porotchkin {
312031542fcSKonstantin Porotchkin 	uint32_t reg;
313031542fcSKonstantin Porotchkin 
314031542fcSKonstantin Porotchkin 	/* Open AMB bridge Window to Access COMPHY/MDIO registers */
315031542fcSKonstantin Porotchkin 	reg = mmio_read_32(base + MVEBU_AMB_IP_BRIDGE_WIN_REG(0));
316031542fcSKonstantin Porotchkin 	reg &= ~(MVEBU_AMB_IP_BRIDGE_WIN_SIZE_MASK |
317031542fcSKonstantin Porotchkin 		 MVEBU_AMB_IP_BRIDGE_WIN_EN_MASK);
318031542fcSKonstantin Porotchkin 	reg |= (0x7ff << MVEBU_AMB_IP_BRIDGE_WIN_SIZE_OFFSET) |
319031542fcSKonstantin Porotchkin 	       (0x1 << MVEBU_AMB_IP_BRIDGE_WIN_EN_OFFSET);
320031542fcSKonstantin Porotchkin 	mmio_write_32(base + MVEBU_AMB_IP_BRIDGE_WIN_REG(0), reg);
321031542fcSKonstantin Porotchkin }
322031542fcSKonstantin Porotchkin 
cp110_rtc_init(uintptr_t base)323031542fcSKonstantin Porotchkin static void cp110_rtc_init(uintptr_t base)
324031542fcSKonstantin Porotchkin {
325031542fcSKonstantin Porotchkin 	/* Update MBus timing parameters before accessing RTC registers */
326031542fcSKonstantin Porotchkin 	mmio_clrsetbits_32(base + MVEBU_RTC_BRIDGE_TIMING_CTRL0_REG,
327031542fcSKonstantin Porotchkin 			   MVEBU_RTC_WRCLK_PERIOD_MASK,
328031542fcSKonstantin Porotchkin 			   MVEBU_RTC_WRCLK_PERIOD_DEFAULT);
329031542fcSKonstantin Porotchkin 
330031542fcSKonstantin Porotchkin 	mmio_clrsetbits_32(base + MVEBU_RTC_BRIDGE_TIMING_CTRL0_REG,
331031542fcSKonstantin Porotchkin 			   MVEBU_RTC_WRCLK_SETUP_MASK,
332031542fcSKonstantin Porotchkin 			   MVEBU_RTC_WRCLK_SETUP_DEFAULT <<
333031542fcSKonstantin Porotchkin 			   MVEBU_RTC_WRCLK_SETUP_OFFS);
334031542fcSKonstantin Porotchkin 
335031542fcSKonstantin Porotchkin 	mmio_clrsetbits_32(base + MVEBU_RTC_BRIDGE_TIMING_CTRL1_REG,
336031542fcSKonstantin Porotchkin 			   MVEBU_RTC_READ_OUTPUT_DELAY_MASK,
337031542fcSKonstantin Porotchkin 			   MVEBU_RTC_READ_OUTPUT_DELAY_DEFAULT);
338031542fcSKonstantin Porotchkin 
339031542fcSKonstantin Porotchkin 	/*
340031542fcSKonstantin Porotchkin 	 * Issue reset to the RTC if Clock Correction register
341031542fcSKonstantin Porotchkin 	 * contents did not sustain the reboot/power-on.
342031542fcSKonstantin Porotchkin 	 */
343031542fcSKonstantin Porotchkin 	if ((mmio_read_32(base + MVEBU_RTC_CCR_REG) &
344031542fcSKonstantin Porotchkin 	    MVEBU_RTC_NOMINAL_TIMING_MASK) != MVEBU_RTC_NOMINAL_TIMING) {
345031542fcSKonstantin Porotchkin 		/* Reset Test register */
346031542fcSKonstantin Porotchkin 		mmio_write_32(base + MVEBU_RTC_TEST_CONFIG_REG, 0);
347031542fcSKonstantin Porotchkin 		mdelay(500);
348031542fcSKonstantin Porotchkin 
349031542fcSKonstantin Porotchkin 		/* Reset Status register */
350031542fcSKonstantin Porotchkin 		mmio_write_32(base + MVEBU_RTC_STATUS_REG,
351031542fcSKonstantin Porotchkin 			      (MVEBU_RTC_STATUS_ALARM1_MASK |
352031542fcSKonstantin Porotchkin 			      MVEBU_RTC_STATUS_ALARM2_MASK));
353031542fcSKonstantin Porotchkin 		udelay(62);
354031542fcSKonstantin Porotchkin 
355031542fcSKonstantin Porotchkin 		/* Turn off Int1 and Int2 sources & clear the Alarm count */
356031542fcSKonstantin Porotchkin 		mmio_write_32(base + MVEBU_RTC_IRQ_1_CONFIG_REG, 0);
357031542fcSKonstantin Porotchkin 		mmio_write_32(base + MVEBU_RTC_IRQ_2_CONFIG_REG, 0);
358031542fcSKonstantin Porotchkin 		mmio_write_32(base + MVEBU_RTC_ALARM_1_REG, 0);
359031542fcSKonstantin Porotchkin 		mmio_write_32(base + MVEBU_RTC_ALARM_2_REG, 0);
360031542fcSKonstantin Porotchkin 
361031542fcSKonstantin Porotchkin 		/* Setup nominal register access timing */
362031542fcSKonstantin Porotchkin 		mmio_write_32(base + MVEBU_RTC_CCR_REG,
363031542fcSKonstantin Porotchkin 			      MVEBU_RTC_NOMINAL_TIMING);
364031542fcSKonstantin Porotchkin 
365031542fcSKonstantin Porotchkin 		/* Reset Status register */
366031542fcSKonstantin Porotchkin 		mmio_write_32(base + MVEBU_RTC_STATUS_REG,
367031542fcSKonstantin Porotchkin 			      (MVEBU_RTC_STATUS_ALARM1_MASK |
368031542fcSKonstantin Porotchkin 			      MVEBU_RTC_STATUS_ALARM2_MASK));
369031542fcSKonstantin Porotchkin 		udelay(50);
370031542fcSKonstantin Porotchkin 	}
371031542fcSKonstantin Porotchkin }
372031542fcSKonstantin Porotchkin 
cp110_amb_adec_init(uintptr_t base)373031542fcSKonstantin Porotchkin static void cp110_amb_adec_init(uintptr_t base)
374031542fcSKonstantin Porotchkin {
375031542fcSKonstantin Porotchkin 	/* enable AXI-MBUS by clearing "Bridge Windows Disable" */
376031542fcSKonstantin Porotchkin 	mmio_clrbits_32(base + MVEBU_BRIDGE_WIN_DIS_REG,
377031542fcSKonstantin Porotchkin 			(1 << MVEBU_BRIDGE_WIN_DIS_OFF));
378031542fcSKonstantin Porotchkin 
379031542fcSKonstantin Porotchkin 	/* configure AXI-MBUS windows for CP */
380031542fcSKonstantin Porotchkin 	init_amb_adec(base);
381031542fcSKonstantin Porotchkin }
382031542fcSKonstantin Porotchkin 
cp110_init(uintptr_t cp110_base,uint32_t stream_id)383031542fcSKonstantin Porotchkin void cp110_init(uintptr_t cp110_base, uint32_t stream_id)
384031542fcSKonstantin Porotchkin {
385031542fcSKonstantin Porotchkin 	INFO("%s: Initialize CPx - base = %lx\n", __func__, cp110_base);
386031542fcSKonstantin Porotchkin 
387031542fcSKonstantin Porotchkin 	/* configure IOB windows for CP0*/
388031542fcSKonstantin Porotchkin 	init_iob(cp110_base);
389031542fcSKonstantin Porotchkin 
390031542fcSKonstantin Porotchkin 	/* configure AXI-MBUS windows for CP0*/
391031542fcSKonstantin Porotchkin 	cp110_amb_adec_init(cp110_base);
392031542fcSKonstantin Porotchkin 
393031542fcSKonstantin Porotchkin 	/* configure axi for CP0*/
394031542fcSKonstantin Porotchkin 	cp110_axi_attr_init(cp110_base);
395031542fcSKonstantin Porotchkin 
396031542fcSKonstantin Porotchkin 	/* Execute SW WA for erratas */
397031542fcSKonstantin Porotchkin 	cp110_errata_wa_init(cp110_base);
398031542fcSKonstantin Porotchkin 
399031542fcSKonstantin Porotchkin 	/* Confiure pcie clock according to clock direction */
400031542fcSKonstantin Porotchkin 	cp110_pcie_clk_cfg(cp110_base);
401031542fcSKonstantin Porotchkin 
402031542fcSKonstantin Porotchkin 	/* configure stream id for CP0 */
403031542fcSKonstantin Porotchkin 	cp110_stream_id_init(cp110_base, stream_id);
404031542fcSKonstantin Porotchkin 
405031542fcSKonstantin Porotchkin 	/* Open AMB bridge for comphy for CP0 & CP1*/
40681646055SGrzegorz Jaszczyk 	cp110_amb_init(cp110_base);
407031542fcSKonstantin Porotchkin 
408031542fcSKonstantin Porotchkin 	/* Reset RTC if needed */
409031542fcSKonstantin Porotchkin 	cp110_rtc_init(cp110_base);
410031542fcSKonstantin Porotchkin }
411031542fcSKonstantin Porotchkin 
412031542fcSKonstantin Porotchkin /* Do the minimal setup required to configure the CP in BLE */
cp110_ble_init(uintptr_t cp110_base)413031542fcSKonstantin Porotchkin void cp110_ble_init(uintptr_t cp110_base)
414031542fcSKonstantin Porotchkin {
415031542fcSKonstantin Porotchkin #if PCI_EP_SUPPORT
416031542fcSKonstantin Porotchkin 	INFO("%s: Initialize CPx - base = %lx\n", __func__, cp110_base);
417031542fcSKonstantin Porotchkin 
41881646055SGrzegorz Jaszczyk 	cp110_amb_init(cp110_base);
419031542fcSKonstantin Porotchkin 
420031542fcSKonstantin Porotchkin 	/* Configure PCIe clock */
421031542fcSKonstantin Porotchkin 	cp110_pcie_clk_cfg(cp110_base);
422031542fcSKonstantin Porotchkin 
423031542fcSKonstantin Porotchkin 	/* Configure PCIe endpoint */
424031542fcSKonstantin Porotchkin 	ble_plat_pcie_ep_setup();
425031542fcSKonstantin Porotchkin #endif
426031542fcSKonstantin Porotchkin }
427