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