xref: /rk3399_ARM-atf/drivers/marvell/mochi/ap807_setup.c (revision c3c51b3283bf76552beb649c6cfc95110a1231d9)
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 /* AP807 Marvell SoC driver */
9031542fcSKonstantin Porotchkin 
1009d40e0eSAntonio Nino Diaz #include <common/debug.h>
1109d40e0eSAntonio Nino Diaz #include <drivers/marvell/cache_llc.h>
1209d40e0eSAntonio Nino Diaz #include <drivers/marvell/ccu.h>
1309d40e0eSAntonio Nino Diaz #include <drivers/marvell/io_win.h>
14*c3c51b32SGrzegorz Jaszczyk #include <drivers/marvell/iob.h>
1509d40e0eSAntonio Nino Diaz #include <drivers/marvell/mci.h>
1609d40e0eSAntonio Nino Diaz #include <drivers/marvell/mochi/ap_setup.h>
1709d40e0eSAntonio Nino Diaz #include <lib/mmio.h>
1809d40e0eSAntonio Nino Diaz 
19031542fcSKonstantin Porotchkin #include <mvebu_def.h>
20031542fcSKonstantin Porotchkin 
21031542fcSKonstantin Porotchkin #define SMMU_sACR				(MVEBU_SMMU_BASE + 0x10)
22031542fcSKonstantin Porotchkin #define SMMU_sACR_PG_64K			(1 << 16)
23031542fcSKonstantin Porotchkin 
24031542fcSKonstantin Porotchkin #define CCU_GSPMU_CR				(MVEBU_CCU_BASE(MVEBU_AP0) \
25031542fcSKonstantin Porotchkin 								+ 0x3F0)
26031542fcSKonstantin Porotchkin #define GSPMU_CPU_CONTROL			(0x1 << 0)
27031542fcSKonstantin Porotchkin 
28031542fcSKonstantin Porotchkin #define CCU_HTC_CR				(MVEBU_CCU_BASE(MVEBU_AP0) \
29031542fcSKonstantin Porotchkin 								+ 0x200)
30031542fcSKonstantin Porotchkin #define CCU_SET_POC_OFFSET			5
31031542fcSKonstantin Porotchkin 
32031542fcSKonstantin Porotchkin #define DSS_CR0					(MVEBU_RFU_BASE + 0x100)
33031542fcSKonstantin Porotchkin #define DVM_48BIT_VA_ENABLE			(1 << 21)
34031542fcSKonstantin Porotchkin 
352da75ae1SGrzegorz Jaszczyk 
362da75ae1SGrzegorz Jaszczyk /* SoC RFU / IHBx4 Control */
372da75ae1SGrzegorz Jaszczyk #define MCIX4_807_REG_START_ADDR_REG(unit_id)	(MVEBU_RFU_BASE + \
382da75ae1SGrzegorz Jaszczyk 						0x4258 + (unit_id * 0x4))
392da75ae1SGrzegorz Jaszczyk 
40031542fcSKonstantin Porotchkin /* Secure MoChi incoming access */
41031542fcSKonstantin Porotchkin #define SEC_MOCHI_IN_ACC_REG			(MVEBU_RFU_BASE + 0x4738)
42031542fcSKonstantin Porotchkin #define SEC_MOCHI_IN_ACC_IHB0_EN		(1)
43031542fcSKonstantin Porotchkin #define SEC_MOCHI_IN_ACC_IHB1_EN		(1 << 3)
44031542fcSKonstantin Porotchkin #define SEC_MOCHI_IN_ACC_IHB2_EN		(1 << 6)
45031542fcSKonstantin Porotchkin #define SEC_MOCHI_IN_ACC_PIDI_EN		(1 << 9)
46031542fcSKonstantin Porotchkin #define SEC_IN_ACCESS_ENA_ALL_MASTERS		(SEC_MOCHI_IN_ACC_IHB0_EN | \
47031542fcSKonstantin Porotchkin 						 SEC_MOCHI_IN_ACC_IHB1_EN | \
48031542fcSKonstantin Porotchkin 						 SEC_MOCHI_IN_ACC_IHB2_EN | \
49031542fcSKonstantin Porotchkin 						 SEC_MOCHI_IN_ACC_PIDI_EN)
50031542fcSKonstantin Porotchkin 
51031542fcSKonstantin Porotchkin /* SYSRST_OUTn Config definitions */
52031542fcSKonstantin Porotchkin #define MVEBU_SYSRST_OUT_CONFIG_REG		(MVEBU_MISC_SOC_BASE + 0x4)
53031542fcSKonstantin Porotchkin #define WD_MASK_SYS_RST_OUT			(1 << 2)
54031542fcSKonstantin Porotchkin 
55031542fcSKonstantin Porotchkin /* DSS PHY for DRAM */
56031542fcSKonstantin Porotchkin #define DSS_SCR_REG				(MVEBU_RFU_BASE + 0x208)
57031542fcSKonstantin Porotchkin #define DSS_PPROT_OFFS				4
58031542fcSKonstantin Porotchkin #define DSS_PPROT_MASK				0x7
59031542fcSKonstantin Porotchkin #define DSS_PPROT_PRIV_SECURE_DATA		0x1
60031542fcSKonstantin Porotchkin 
61031542fcSKonstantin Porotchkin /* Used for Units of AP-807 (e.g. SDIO and etc) */
62031542fcSKonstantin Porotchkin #define MVEBU_AXI_ATTR_BASE			(MVEBU_REGS_BASE + 0x6F4580)
63031542fcSKonstantin Porotchkin #define MVEBU_AXI_ATTR_REG(index)		(MVEBU_AXI_ATTR_BASE + \
64031542fcSKonstantin Porotchkin 							0x4 * index)
65031542fcSKonstantin Porotchkin 
66031542fcSKonstantin Porotchkin enum axi_attr {
67031542fcSKonstantin Porotchkin 	AXI_SDIO_ATTR = 0,
68031542fcSKonstantin Porotchkin 	AXI_DFX_ATTR,
69031542fcSKonstantin Porotchkin 	AXI_MAX_ATTR,
70031542fcSKonstantin Porotchkin };
71031542fcSKonstantin Porotchkin 
72031542fcSKonstantin Porotchkin static void ap_sec_masters_access_en(uint32_t enable)
73031542fcSKonstantin Porotchkin {
74031542fcSKonstantin Porotchkin 	uint32_t reg;
75031542fcSKonstantin Porotchkin 
76031542fcSKonstantin Porotchkin 	/* Open/Close incoming access for all masters.
77031542fcSKonstantin Porotchkin 	 * The access is disabled in trusted boot mode
78031542fcSKonstantin Porotchkin 	 * Could only be done in EL3
79031542fcSKonstantin Porotchkin 	 */
80031542fcSKonstantin Porotchkin 	reg = mmio_read_32(SEC_MOCHI_IN_ACC_REG);
81031542fcSKonstantin Porotchkin 	if (enable)
82031542fcSKonstantin Porotchkin 		mmio_write_32(SEC_MOCHI_IN_ACC_REG, reg |
83031542fcSKonstantin Porotchkin 			      SEC_IN_ACCESS_ENA_ALL_MASTERS);
84031542fcSKonstantin Porotchkin 	else
85031542fcSKonstantin Porotchkin 		mmio_write_32(SEC_MOCHI_IN_ACC_REG,
86031542fcSKonstantin Porotchkin 			      reg & ~SEC_IN_ACCESS_ENA_ALL_MASTERS);
87031542fcSKonstantin Porotchkin }
88031542fcSKonstantin Porotchkin 
89031542fcSKonstantin Porotchkin static void setup_smmu(void)
90031542fcSKonstantin Porotchkin {
91031542fcSKonstantin Porotchkin 	uint32_t reg;
92031542fcSKonstantin Porotchkin 
93031542fcSKonstantin Porotchkin 	/* Set the SMMU page size to 64 KB */
94031542fcSKonstantin Porotchkin 	reg = mmio_read_32(SMMU_sACR);
95031542fcSKonstantin Porotchkin 	reg |= SMMU_sACR_PG_64K;
96031542fcSKonstantin Porotchkin 	mmio_write_32(SMMU_sACR, reg);
97031542fcSKonstantin Porotchkin }
98031542fcSKonstantin Porotchkin 
99031542fcSKonstantin Porotchkin static void init_aurora2(void)
100031542fcSKonstantin Porotchkin {
101031542fcSKonstantin Porotchkin 	uint32_t reg;
102031542fcSKonstantin Porotchkin 
103031542fcSKonstantin Porotchkin 	/* Enable GSPMU control by CPU */
104031542fcSKonstantin Porotchkin 	reg = mmio_read_32(CCU_GSPMU_CR);
105031542fcSKonstantin Porotchkin 	reg |= GSPMU_CPU_CONTROL;
106031542fcSKonstantin Porotchkin 	mmio_write_32(CCU_GSPMU_CR, reg);
107031542fcSKonstantin Porotchkin 
108031542fcSKonstantin Porotchkin #if LLC_ENABLE
109031542fcSKonstantin Porotchkin 	/* Enable LLC for AP807 in exclusive mode */
110031542fcSKonstantin Porotchkin 	llc_enable(0, 1);
111031542fcSKonstantin Porotchkin 
112031542fcSKonstantin Porotchkin 	/* Set point of coherency to DDR.
113031542fcSKonstantin Porotchkin 	 * This is required by units which have
114031542fcSKonstantin Porotchkin 	 * SW cache coherency
115031542fcSKonstantin Porotchkin 	 */
116031542fcSKonstantin Porotchkin 	reg = mmio_read_32(CCU_HTC_CR);
117031542fcSKonstantin Porotchkin 	reg |= (0x1 << CCU_SET_POC_OFFSET);
118031542fcSKonstantin Porotchkin 	mmio_write_32(CCU_HTC_CR, reg);
119031542fcSKonstantin Porotchkin #endif /* LLC_ENABLE */
120031542fcSKonstantin Porotchkin }
121031542fcSKonstantin Porotchkin 
122031542fcSKonstantin Porotchkin 
123031542fcSKonstantin Porotchkin /* MCIx indirect access register are based by default at 0xf4000000/0xf6000000
124031542fcSKonstantin Porotchkin  * to avoid conflict of internal registers of units connected via MCIx, which
125031542fcSKonstantin Porotchkin  * can be based on the same address (i.e CP1 base is also 0xf4000000),
126031542fcSKonstantin Porotchkin  * the following routines remaps the MCIx indirect bases to another domain
127031542fcSKonstantin Porotchkin  */
128031542fcSKonstantin Porotchkin static void mci_remap_indirect_access_base(void)
129031542fcSKonstantin Porotchkin {
130031542fcSKonstantin Porotchkin 	uint32_t mci;
131031542fcSKonstantin Porotchkin 
132031542fcSKonstantin Porotchkin 	for (mci = 0; mci < MCI_MAX_UNIT_ID; mci++)
1332da75ae1SGrzegorz Jaszczyk 		mmio_write_32(MCIX4_807_REG_START_ADDR_REG(mci),
134031542fcSKonstantin Porotchkin 				  MVEBU_MCI_REG_BASE_REMAP(mci) >>
135031542fcSKonstantin Porotchkin 				  MCI_REMAP_OFF_SHIFT);
136031542fcSKonstantin Porotchkin }
137031542fcSKonstantin Porotchkin 
138031542fcSKonstantin Porotchkin static void ap807_axi_attr_init(void)
139031542fcSKonstantin Porotchkin {
140031542fcSKonstantin Porotchkin 	uint32_t index, data;
141031542fcSKonstantin Porotchkin 
142031542fcSKonstantin Porotchkin 	/* Initialize AXI attributes for AP807 */
143031542fcSKonstantin Porotchkin 	/* Go over the AXI attributes and set Ax-Cache and Ax-Domain */
144031542fcSKonstantin Porotchkin 	for (index = 0; index < AXI_MAX_ATTR; index++) {
145031542fcSKonstantin Porotchkin 		switch (index) {
146031542fcSKonstantin Porotchkin 		/* DFX works with no coherent only -
147031542fcSKonstantin Porotchkin 		 * there's no option to configure the Ax-Cache and Ax-Domain
148031542fcSKonstantin Porotchkin 		 */
149031542fcSKonstantin Porotchkin 		case AXI_DFX_ATTR:
150031542fcSKonstantin Porotchkin 			continue;
151031542fcSKonstantin Porotchkin 		default:
152031542fcSKonstantin Porotchkin 			/* Set Ax-Cache as cacheable, no allocate, modifiable,
153031542fcSKonstantin Porotchkin 			 * bufferable.
154031542fcSKonstantin Porotchkin 			 * The values are different because Read & Write
155031542fcSKonstantin Porotchkin 			 * definition is different in Ax-Cache
156031542fcSKonstantin Porotchkin 			 */
157031542fcSKonstantin Porotchkin 			data = mmio_read_32(MVEBU_AXI_ATTR_REG(index));
158031542fcSKonstantin Porotchkin 			data &= ~MVEBU_AXI_ATTR_ARCACHE_MASK;
159031542fcSKonstantin Porotchkin 			data |= (CACHE_ATTR_WRITE_ALLOC |
160031542fcSKonstantin Porotchkin 				 CACHE_ATTR_CACHEABLE   |
161031542fcSKonstantin Porotchkin 				 CACHE_ATTR_BUFFERABLE) <<
162031542fcSKonstantin Porotchkin 				 MVEBU_AXI_ATTR_ARCACHE_OFFSET;
163031542fcSKonstantin Porotchkin 			data &= ~MVEBU_AXI_ATTR_AWCACHE_MASK;
164031542fcSKonstantin Porotchkin 			data |= (CACHE_ATTR_READ_ALLOC |
165031542fcSKonstantin Porotchkin 				 CACHE_ATTR_CACHEABLE  |
166031542fcSKonstantin Porotchkin 				 CACHE_ATTR_BUFFERABLE) <<
167031542fcSKonstantin Porotchkin 				 MVEBU_AXI_ATTR_AWCACHE_OFFSET;
168031542fcSKonstantin Porotchkin 			/* Set Ax-Domain as Outer domain */
169031542fcSKonstantin Porotchkin 			data &= ~MVEBU_AXI_ATTR_ARDOMAIN_MASK;
170031542fcSKonstantin Porotchkin 			data |= DOMAIN_OUTER_SHAREABLE <<
171031542fcSKonstantin Porotchkin 				MVEBU_AXI_ATTR_ARDOMAIN_OFFSET;
172031542fcSKonstantin Porotchkin 			data &= ~MVEBU_AXI_ATTR_AWDOMAIN_MASK;
173031542fcSKonstantin Porotchkin 			data |= DOMAIN_OUTER_SHAREABLE <<
174031542fcSKonstantin Porotchkin 				MVEBU_AXI_ATTR_AWDOMAIN_OFFSET;
175031542fcSKonstantin Porotchkin 			mmio_write_32(MVEBU_AXI_ATTR_REG(index), data);
176031542fcSKonstantin Porotchkin 		}
177031542fcSKonstantin Porotchkin 	}
178031542fcSKonstantin Porotchkin }
179031542fcSKonstantin Porotchkin 
180031542fcSKonstantin Porotchkin static void misc_soc_configurations(void)
181031542fcSKonstantin Porotchkin {
182031542fcSKonstantin Porotchkin 	uint32_t reg;
183031542fcSKonstantin Porotchkin 
184031542fcSKonstantin Porotchkin 	/* Enable 48-bit VA */
185031542fcSKonstantin Porotchkin 	mmio_setbits_32(DSS_CR0, DVM_48BIT_VA_ENABLE);
186031542fcSKonstantin Porotchkin 
187031542fcSKonstantin Porotchkin 	/* Un-mask Watchdog reset from influencing the SYSRST_OUTn.
188031542fcSKonstantin Porotchkin 	 * Otherwise, upon WD timeout, the WD reset signal won't trigger reset
189031542fcSKonstantin Porotchkin 	 */
190031542fcSKonstantin Porotchkin 	reg = mmio_read_32(MVEBU_SYSRST_OUT_CONFIG_REG);
191031542fcSKonstantin Porotchkin 	reg &= ~(WD_MASK_SYS_RST_OUT);
192031542fcSKonstantin Porotchkin 	mmio_write_32(MVEBU_SYSRST_OUT_CONFIG_REG, reg);
193031542fcSKonstantin Porotchkin }
194031542fcSKonstantin Porotchkin 
195*c3c51b32SGrzegorz Jaszczyk /*
196*c3c51b32SGrzegorz Jaszczyk  * By default all external CPs start with configuration address space set to
197*c3c51b32SGrzegorz Jaszczyk  * 0xf200_0000. To overcome this issue, go in the loop and initialize the
198*c3c51b32SGrzegorz Jaszczyk  * CP one by one, using temporary window configuration which allows to access
199*c3c51b32SGrzegorz Jaszczyk  * each CP and update its configuration space according to decoding
200*c3c51b32SGrzegorz Jaszczyk  * windows scheme defined for each platform.
201*c3c51b32SGrzegorz Jaszczyk  */
202*c3c51b32SGrzegorz Jaszczyk void update_cp110_default_win(int cp_id)
203*c3c51b32SGrzegorz Jaszczyk {
204*c3c51b32SGrzegorz Jaszczyk 	int mci_id = cp_id - 1;
205*c3c51b32SGrzegorz Jaszczyk 	uintptr_t cp110_base, cp110_temp_base;
206*c3c51b32SGrzegorz Jaszczyk 
207*c3c51b32SGrzegorz Jaszczyk 	/* CP110 default configuration address space */
208*c3c51b32SGrzegorz Jaszczyk 	cp110_temp_base = MVEBU_AP_IO_BASE(MVEBU_AP0);
209*c3c51b32SGrzegorz Jaszczyk 
210*c3c51b32SGrzegorz Jaszczyk 	struct addr_map_win iowin_temp_win = {
211*c3c51b32SGrzegorz Jaszczyk 		.base_addr = cp110_temp_base,
212*c3c51b32SGrzegorz Jaszczyk 		.win_size = MVEBU_CP_OFFSET,
213*c3c51b32SGrzegorz Jaszczyk 	};
214*c3c51b32SGrzegorz Jaszczyk 
215*c3c51b32SGrzegorz Jaszczyk 	iowin_temp_win.target_id = mci_id;
216*c3c51b32SGrzegorz Jaszczyk 	iow_temp_win_insert(0, &iowin_temp_win, 1);
217*c3c51b32SGrzegorz Jaszczyk 
218*c3c51b32SGrzegorz Jaszczyk 	/* Calculate the new CP110 - base address */
219*c3c51b32SGrzegorz Jaszczyk 	cp110_base = MVEBU_CP_REGS_BASE(cp_id);
220*c3c51b32SGrzegorz Jaszczyk 	/* Go and update the CP110 configuration address space */
221*c3c51b32SGrzegorz Jaszczyk 	iob_cfg_space_update(0, cp_id, cp110_temp_base, cp110_base);
222*c3c51b32SGrzegorz Jaszczyk 
223*c3c51b32SGrzegorz Jaszczyk 	/* Remove the temporary IO-WIN window */
224*c3c51b32SGrzegorz Jaszczyk 	iow_temp_win_remove(0, &iowin_temp_win, 1);
225*c3c51b32SGrzegorz Jaszczyk }
226*c3c51b32SGrzegorz Jaszczyk 
227031542fcSKonstantin Porotchkin void ap_init(void)
228031542fcSKonstantin Porotchkin {
229031542fcSKonstantin Porotchkin 	/* Setup Aurora2. */
230031542fcSKonstantin Porotchkin 	init_aurora2();
231031542fcSKonstantin Porotchkin 
232031542fcSKonstantin Porotchkin 	/* configure MCI mapping */
233031542fcSKonstantin Porotchkin 	mci_remap_indirect_access_base();
234031542fcSKonstantin Porotchkin 
235031542fcSKonstantin Porotchkin 	/* configure IO_WIN windows */
236031542fcSKonstantin Porotchkin 	init_io_win(MVEBU_AP0);
237031542fcSKonstantin Porotchkin 
238031542fcSKonstantin Porotchkin 	/* configure CCU windows */
239031542fcSKonstantin Porotchkin 	init_ccu(MVEBU_AP0);
240031542fcSKonstantin Porotchkin 
241031542fcSKonstantin Porotchkin 	/* configure the SMMU */
242031542fcSKonstantin Porotchkin 	setup_smmu();
243031542fcSKonstantin Porotchkin 
244031542fcSKonstantin Porotchkin 	/* Open AP incoming access for all masters */
245031542fcSKonstantin Porotchkin 	ap_sec_masters_access_en(1);
246031542fcSKonstantin Porotchkin 
247031542fcSKonstantin Porotchkin 	/* configure axi for AP */
248031542fcSKonstantin Porotchkin 	ap807_axi_attr_init();
249031542fcSKonstantin Porotchkin 
250031542fcSKonstantin Porotchkin 	/* misc configuration of the SoC */
251031542fcSKonstantin Porotchkin 	misc_soc_configurations();
252031542fcSKonstantin Porotchkin }
253031542fcSKonstantin Porotchkin 
254031542fcSKonstantin Porotchkin static void ap807_dram_phy_access_config(void)
255031542fcSKonstantin Porotchkin {
256031542fcSKonstantin Porotchkin 	uint32_t reg_val;
257031542fcSKonstantin Porotchkin 	/* Update DSS port access permission to DSS_PHY */
258031542fcSKonstantin Porotchkin 	reg_val = mmio_read_32(DSS_SCR_REG);
259031542fcSKonstantin Porotchkin 	reg_val &= ~(DSS_PPROT_MASK << DSS_PPROT_OFFS);
260031542fcSKonstantin Porotchkin 	reg_val |= ((DSS_PPROT_PRIV_SECURE_DATA & DSS_PPROT_MASK) <<
261031542fcSKonstantin Porotchkin 		    DSS_PPROT_OFFS);
262031542fcSKonstantin Porotchkin 	mmio_write_32(DSS_SCR_REG, reg_val);
263031542fcSKonstantin Porotchkin }
264031542fcSKonstantin Porotchkin 
265031542fcSKonstantin Porotchkin void ap_ble_init(void)
266031542fcSKonstantin Porotchkin {
267031542fcSKonstantin Porotchkin 	/* Enable DSS port */
268031542fcSKonstantin Porotchkin 	ap807_dram_phy_access_config();
269031542fcSKonstantin Porotchkin }
270031542fcSKonstantin Porotchkin 
271031542fcSKonstantin Porotchkin int ap_get_count(void)
272031542fcSKonstantin Porotchkin {
273031542fcSKonstantin Porotchkin 	return 1;
274031542fcSKonstantin Porotchkin }
275031542fcSKonstantin Porotchkin 
276031542fcSKonstantin Porotchkin 
277