blob: 54bc6674f293d5aeedcfd6942edad89f9193d297 [file] [log] [blame]
Konstantin Porotchkin01c84d42018-02-26 16:01:57 +02001/*
Marcin Wojtasfadde2b2020-05-12 18:19:33 +02002 * Copyright (C) 2018-2020 Marvell International Ltd.
Konstantin Porotchkin01c84d42018-02-26 16:01:57 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 * https://spdx.org/licenses
6 */
7
8/* CP110 Marvell SoC driver */
9
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <common/debug.h>
11#include <drivers/delay_timer.h>
12#include <drivers/marvell/amb_adec.h>
13#include <drivers/marvell/iob.h>
14#include <drivers/marvell/mochi/cp110_setup.h>
Konstantin Porotchkin7b9e4d42020-07-26 17:49:54 +030015#include <drivers/rambus/trng_ip_76.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000016
Konstantin Porotchkin01c84d42018-02-26 16:01:57 +020017#include <plat_marvell.h>
18
19/*
20 * AXI Configuration.
21 */
22
23 /* Used for Units of CP-110 (e.g. USB device, USB Host, and etc) */
24#define MVEBU_AXI_ATTR_OFFSET (0x441300)
25#define MVEBU_AXI_ATTR_REG(index) (MVEBU_AXI_ATTR_OFFSET + \
26 0x4 * index)
27
28/* AXI Protection bits */
29#define MVEBU_AXI_PROT_OFFSET (0x441200)
30
31/* AXI Protection regs */
32#define MVEBU_AXI_PROT_REG(index) ((index <= 4) ? \
33 (MVEBU_AXI_PROT_OFFSET + \
34 0x4 * index) : \
35 (MVEBU_AXI_PROT_OFFSET + 0x18))
36#define MVEBU_AXI_PROT_REGS_NUM (6)
37
38#define MVEBU_SOC_CFGS_OFFSET (0x441900)
39#define MVEBU_SOC_CFG_REG(index) (MVEBU_SOC_CFGS_OFFSET + \
40 0x4 * index)
41#define MVEBU_SOC_CFG_REG_NUM (0)
42#define MVEBU_SOC_CFG_GLOG_SECURE_EN_MASK (0xE)
43
44/* SATA3 MBUS to AXI regs */
45#define MVEBU_BRIDGE_WIN_DIS_REG (MVEBU_SOC_CFGS_OFFSET + 0x10)
46#define MVEBU_BRIDGE_WIN_DIS_OFF (0x0)
47
48/* SATA3 MBUS to AXI regs */
49#define MVEBU_SATA_M2A_AXI_PORT_CTRL_REG (0x54ff04)
50
51/* AXI to MBUS bridge registers */
52#define MVEBU_AMB_IP_OFFSET (0x13ff00)
53#define MVEBU_AMB_IP_BRIDGE_WIN_REG(win) (MVEBU_AMB_IP_OFFSET + \
54 (win * 0x8))
55#define MVEBU_AMB_IP_BRIDGE_WIN_EN_OFFSET 0
56#define MVEBU_AMB_IP_BRIDGE_WIN_EN_MASK \
57 (0x1 << MVEBU_AMB_IP_BRIDGE_WIN_EN_OFFSET)
58#define MVEBU_AMB_IP_BRIDGE_WIN_SIZE_OFFSET 16
59#define MVEBU_AMB_IP_BRIDGE_WIN_SIZE_MASK \
Justin Chadwellfed41a12019-07-03 14:04:33 +010060 (0xffffu << MVEBU_AMB_IP_BRIDGE_WIN_SIZE_OFFSET)
Konstantin Porotchkin01c84d42018-02-26 16:01:57 +020061
62#define MVEBU_SAMPLE_AT_RESET_REG (0x440600)
63#define SAR_PCIE1_CLK_CFG_OFFSET 31
Justin Chadwellfed41a12019-07-03 14:04:33 +010064#define SAR_PCIE1_CLK_CFG_MASK (0x1u << SAR_PCIE1_CLK_CFG_OFFSET)
Konstantin Porotchkin01c84d42018-02-26 16:01:57 +020065#define SAR_PCIE0_CLK_CFG_OFFSET 30
66#define SAR_PCIE0_CLK_CFG_MASK (0x1 << SAR_PCIE0_CLK_CFG_OFFSET)
67#define SAR_I2C_INIT_EN_OFFSET 24
68#define SAR_I2C_INIT_EN_MASK (1 << SAR_I2C_INIT_EN_OFFSET)
69
70/*******************************************************************************
71 * PCIE clock buffer control
72 ******************************************************************************/
73#define MVEBU_PCIE_REF_CLK_BUF_CTRL (0x4404F0)
74#define PCIE1_REFCLK_BUFF_SOURCE 0x800
75#define PCIE0_REFCLK_BUFF_SOURCE 0x400
76
77/*******************************************************************************
78 * MSS Device Push Set Register
79 ******************************************************************************/
80#define MVEBU_CP_MSS_DPSHSR_REG (0x280040)
81#define MSS_DPSHSR_REG_PCIE_CLK_SEL 0x8
82
83/*******************************************************************************
84 * RTC Configuration
85 ******************************************************************************/
86#define MVEBU_RTC_BASE (0x284000)
87#define MVEBU_RTC_STATUS_REG (MVEBU_RTC_BASE + 0x0)
88#define MVEBU_RTC_STATUS_ALARM1_MASK 0x1
89#define MVEBU_RTC_STATUS_ALARM2_MASK 0x2
90#define MVEBU_RTC_IRQ_1_CONFIG_REG (MVEBU_RTC_BASE + 0x4)
91#define MVEBU_RTC_IRQ_2_CONFIG_REG (MVEBU_RTC_BASE + 0x8)
92#define MVEBU_RTC_TIME_REG (MVEBU_RTC_BASE + 0xC)
93#define MVEBU_RTC_ALARM_1_REG (MVEBU_RTC_BASE + 0x10)
94#define MVEBU_RTC_ALARM_2_REG (MVEBU_RTC_BASE + 0x14)
95#define MVEBU_RTC_CCR_REG (MVEBU_RTC_BASE + 0x18)
96#define MVEBU_RTC_NOMINAL_TIMING 0x2000
97#define MVEBU_RTC_NOMINAL_TIMING_MASK 0x7FFF
98#define MVEBU_RTC_TEST_CONFIG_REG (MVEBU_RTC_BASE + 0x1C)
99#define MVEBU_RTC_BRIDGE_TIMING_CTRL0_REG (MVEBU_RTC_BASE + 0x80)
100#define MVEBU_RTC_WRCLK_PERIOD_MASK 0xFFFF
101#define MVEBU_RTC_WRCLK_PERIOD_DEFAULT 0x3FF
102#define MVEBU_RTC_WRCLK_SETUP_OFFS 16
103#define MVEBU_RTC_WRCLK_SETUP_MASK 0xFFFF0000
104#define MVEBU_RTC_WRCLK_SETUP_DEFAULT 0x29
105#define MVEBU_RTC_BRIDGE_TIMING_CTRL1_REG (MVEBU_RTC_BASE + 0x84)
106#define MVEBU_RTC_READ_OUTPUT_DELAY_MASK 0xFFFF
107#define MVEBU_RTC_READ_OUTPUT_DELAY_DEFAULT 0x1F
108
Konstantin Porotchkin7b9e4d42020-07-26 17:49:54 +0300109/*******************************************************************************
110 * TRNG Configuration
111 ******************************************************************************/
112#define MVEBU_TRNG_BASE (0x760000)
113
Konstantin Porotchkin01c84d42018-02-26 16:01:57 +0200114enum axi_attr {
115 AXI_ADUNIT_ATTR = 0,
116 AXI_COMUNIT_ATTR,
117 AXI_EIP197_ATTR,
118 AXI_USB3D_ATTR,
119 AXI_USB3H0_ATTR,
120 AXI_USB3H1_ATTR,
121 AXI_SATA0_ATTR,
122 AXI_SATA1_ATTR,
123 AXI_DAP_ATTR,
124 AXI_DFX_ATTR,
125 AXI_DBG_TRC_ATTR = 12,
126 AXI_SDIO_ATTR,
127 AXI_MSS_ATTR,
128 AXI_MAX_ATTR,
129};
130
131/* Most stream IDS are configured centrally in the CP-110 RFU
132 * but some are configured inside the unit registers
133 */
134#define RFU_STREAM_ID_BASE (0x450000)
135#define USB3H_0_STREAM_ID_REG (RFU_STREAM_ID_BASE + 0xC)
136#define USB3H_1_STREAM_ID_REG (RFU_STREAM_ID_BASE + 0x10)
137#define SATA_0_STREAM_ID_REG (RFU_STREAM_ID_BASE + 0x14)
138#define SATA_1_STREAM_ID_REG (RFU_STREAM_ID_BASE + 0x18)
Konstantin Porotchkin97fb7582020-10-19 11:28:54 +0300139#define SDIO_STREAM_ID_REG (RFU_STREAM_ID_BASE + 0x28)
Konstantin Porotchkin01c84d42018-02-26 16:01:57 +0200140
141#define CP_DMA_0_STREAM_ID_REG (0x6B0010)
142#define CP_DMA_1_STREAM_ID_REG (0x6D0010)
143
144/* We allocate IDs 128-255 for PCIe */
145#define MAX_STREAM_ID (0x80)
146
Konstantin Porotchkin97fb7582020-10-19 11:28:54 +0300147static uintptr_t stream_id_reg[] = {
Konstantin Porotchkin01c84d42018-02-26 16:01:57 +0200148 USB3H_0_STREAM_ID_REG,
149 USB3H_1_STREAM_ID_REG,
150 CP_DMA_0_STREAM_ID_REG,
151 CP_DMA_1_STREAM_ID_REG,
152 SATA_0_STREAM_ID_REG,
153 SATA_1_STREAM_ID_REG,
Konstantin Porotchkin97fb7582020-10-19 11:28:54 +0300154 SDIO_STREAM_ID_REG,
Konstantin Porotchkin01c84d42018-02-26 16:01:57 +0200155 0
156};
157
158static void cp110_errata_wa_init(uintptr_t base)
159{
160 uint32_t data;
161
162 /* ERRATA GL-4076863:
163 * Reset value for global_secure_enable inputs must be changed
164 * from '1' to '0'.
165 * When asserted, only "secured" transactions can enter IHB
166 * configuration space.
167 * However, blocking AXI transactions is performed by IOB.
168 * Performing it also at IHB/HB complicates programming model.
169 *
170 * Enable non-secure access in SOC configuration register
171 */
172 data = mmio_read_32(base + MVEBU_SOC_CFG_REG(MVEBU_SOC_CFG_REG_NUM));
173 data &= ~MVEBU_SOC_CFG_GLOG_SECURE_EN_MASK;
174 mmio_write_32(base + MVEBU_SOC_CFG_REG(MVEBU_SOC_CFG_REG_NUM), data);
175}
176
177static void cp110_pcie_clk_cfg(uintptr_t base)
178{
179 uint32_t pcie0_clk, pcie1_clk, reg;
180
181 /*
182 * Determine the pcie0/1 clock direction (input/output) from the
183 * sample at reset.
184 */
185 reg = mmio_read_32(base + MVEBU_SAMPLE_AT_RESET_REG);
186 pcie0_clk = (reg & SAR_PCIE0_CLK_CFG_MASK) >> SAR_PCIE0_CLK_CFG_OFFSET;
187 pcie1_clk = (reg & SAR_PCIE1_CLK_CFG_MASK) >> SAR_PCIE1_CLK_CFG_OFFSET;
188
189 /* CP110 revision A2 */
190 if (cp110_rev_id_get(base) == MVEBU_CP110_REF_ID_A2) {
191 /*
192 * PCIe Reference Clock Buffer Control register must be
193 * set according to the clock direction (input/output)
194 */
195 reg = mmio_read_32(base + MVEBU_PCIE_REF_CLK_BUF_CTRL);
196 reg &= ~(PCIE0_REFCLK_BUFF_SOURCE | PCIE1_REFCLK_BUFF_SOURCE);
197 if (!pcie0_clk)
198 reg |= PCIE0_REFCLK_BUFF_SOURCE;
199 if (!pcie1_clk)
200 reg |= PCIE1_REFCLK_BUFF_SOURCE;
201
202 mmio_write_32(base + MVEBU_PCIE_REF_CLK_BUF_CTRL, reg);
203 }
204
205 /* CP110 revision A1 */
206 if (cp110_rev_id_get(base) == MVEBU_CP110_REF_ID_A1) {
207 if (!pcie0_clk || !pcie1_clk) {
208 /*
209 * if one of the pcie clocks is set to input,
210 * we need to set mss_push[131] field, otherwise,
211 * the pcie clock might not work.
212 */
213 reg = mmio_read_32(base + MVEBU_CP_MSS_DPSHSR_REG);
214 reg |= MSS_DPSHSR_REG_PCIE_CLK_SEL;
215 mmio_write_32(base + MVEBU_CP_MSS_DPSHSR_REG, reg);
216 }
217 }
218}
219
220/* Set a unique stream id for all DMA capable devices */
221static void cp110_stream_id_init(uintptr_t base, uint32_t stream_id)
222{
223 int i = 0;
224
225 while (stream_id_reg[i]) {
226 if (i > MAX_STREAM_ID_PER_CP) {
227 NOTICE("Only first %d (maximum) Stream IDs allocated\n",
228 MAX_STREAM_ID_PER_CP);
229 return;
230 }
231
232 if ((stream_id_reg[i] == CP_DMA_0_STREAM_ID_REG) ||
233 (stream_id_reg[i] == CP_DMA_1_STREAM_ID_REG))
234 mmio_write_32(base + stream_id_reg[i],
235 stream_id << 16 | stream_id);
236 else
237 mmio_write_32(base + stream_id_reg[i], stream_id);
238
239 /* SATA port 0/1 are in the same SATA unit, and they should use
240 * the same STREAM ID number
241 */
242 if (stream_id_reg[i] != SATA_0_STREAM_ID_REG)
243 stream_id++;
244
245 i++;
246 }
247}
248
249static void cp110_axi_attr_init(uintptr_t base)
250{
251 uint32_t index, data;
252
253 /* Initialize AXI attributes for Armada-7K/8K SoC */
254
255 /* Go over the AXI attributes and set Ax-Cache and Ax-Domain */
256 for (index = 0; index < AXI_MAX_ATTR; index++) {
257 switch (index) {
258 /* DFX and MSS unit works with no coherent only -
259 * there's no option to configure the Ax-Cache and Ax-Domain
260 */
261 case AXI_DFX_ATTR:
262 case AXI_MSS_ATTR:
263 continue;
264 default:
265 /* Set Ax-Cache as cacheable, no allocate, modifiable,
266 * bufferable
267 * The values are different because Read & Write
268 * definition is different in Ax-Cache
269 */
270 data = mmio_read_32(base + MVEBU_AXI_ATTR_REG(index));
271 data &= ~MVEBU_AXI_ATTR_ARCACHE_MASK;
272 data |= (CACHE_ATTR_WRITE_ALLOC |
273 CACHE_ATTR_CACHEABLE |
274 CACHE_ATTR_BUFFERABLE) <<
275 MVEBU_AXI_ATTR_ARCACHE_OFFSET;
276 data &= ~MVEBU_AXI_ATTR_AWCACHE_MASK;
277 data |= (CACHE_ATTR_READ_ALLOC |
278 CACHE_ATTR_CACHEABLE |
279 CACHE_ATTR_BUFFERABLE) <<
280 MVEBU_AXI_ATTR_AWCACHE_OFFSET;
281 /* Set Ax-Domain as Outer domain */
282 data &= ~MVEBU_AXI_ATTR_ARDOMAIN_MASK;
283 data |= DOMAIN_OUTER_SHAREABLE <<
284 MVEBU_AXI_ATTR_ARDOMAIN_OFFSET;
285 data &= ~MVEBU_AXI_ATTR_AWDOMAIN_MASK;
286 data |= DOMAIN_OUTER_SHAREABLE <<
287 MVEBU_AXI_ATTR_AWDOMAIN_OFFSET;
288 mmio_write_32(base + MVEBU_AXI_ATTR_REG(index), data);
289 }
290 }
291
292 /* SATA IOCC supported, cache attributes
293 * for SATA MBUS to AXI configuration.
294 */
295 data = mmio_read_32(base + MVEBU_SATA_M2A_AXI_PORT_CTRL_REG);
296 data &= ~MVEBU_SATA_M2A_AXI_AWCACHE_MASK;
297 data |= (CACHE_ATTR_WRITE_ALLOC |
298 CACHE_ATTR_CACHEABLE |
299 CACHE_ATTR_BUFFERABLE) <<
300 MVEBU_SATA_M2A_AXI_AWCACHE_OFFSET;
301 data &= ~MVEBU_SATA_M2A_AXI_ARCACHE_MASK;
302 data |= (CACHE_ATTR_READ_ALLOC |
303 CACHE_ATTR_CACHEABLE |
304 CACHE_ATTR_BUFFERABLE) <<
305 MVEBU_SATA_M2A_AXI_ARCACHE_OFFSET;
306 mmio_write_32(base + MVEBU_SATA_M2A_AXI_PORT_CTRL_REG, data);
307
308 /* Set all IO's AXI attribute to non-secure access. */
309 for (index = 0; index < MVEBU_AXI_PROT_REGS_NUM; index++)
310 mmio_write_32(base + MVEBU_AXI_PROT_REG(index),
311 DOMAIN_SYSTEM_SHAREABLE);
312}
313
Grzegorz Jaszczyk17e43dd2017-08-18 16:42:12 +0200314void cp110_amb_init(uintptr_t base)
Konstantin Porotchkin01c84d42018-02-26 16:01:57 +0200315{
316 uint32_t reg;
317
318 /* Open AMB bridge Window to Access COMPHY/MDIO registers */
319 reg = mmio_read_32(base + MVEBU_AMB_IP_BRIDGE_WIN_REG(0));
320 reg &= ~(MVEBU_AMB_IP_BRIDGE_WIN_SIZE_MASK |
321 MVEBU_AMB_IP_BRIDGE_WIN_EN_MASK);
322 reg |= (0x7ff << MVEBU_AMB_IP_BRIDGE_WIN_SIZE_OFFSET) |
323 (0x1 << MVEBU_AMB_IP_BRIDGE_WIN_EN_OFFSET);
324 mmio_write_32(base + MVEBU_AMB_IP_BRIDGE_WIN_REG(0), reg);
325}
326
327static void cp110_rtc_init(uintptr_t base)
328{
329 /* Update MBus timing parameters before accessing RTC registers */
330 mmio_clrsetbits_32(base + MVEBU_RTC_BRIDGE_TIMING_CTRL0_REG,
331 MVEBU_RTC_WRCLK_PERIOD_MASK,
332 MVEBU_RTC_WRCLK_PERIOD_DEFAULT);
333
334 mmio_clrsetbits_32(base + MVEBU_RTC_BRIDGE_TIMING_CTRL0_REG,
335 MVEBU_RTC_WRCLK_SETUP_MASK,
336 MVEBU_RTC_WRCLK_SETUP_DEFAULT <<
337 MVEBU_RTC_WRCLK_SETUP_OFFS);
338
339 mmio_clrsetbits_32(base + MVEBU_RTC_BRIDGE_TIMING_CTRL1_REG,
340 MVEBU_RTC_READ_OUTPUT_DELAY_MASK,
341 MVEBU_RTC_READ_OUTPUT_DELAY_DEFAULT);
342
343 /*
344 * Issue reset to the RTC if Clock Correction register
345 * contents did not sustain the reboot/power-on.
346 */
347 if ((mmio_read_32(base + MVEBU_RTC_CCR_REG) &
348 MVEBU_RTC_NOMINAL_TIMING_MASK) != MVEBU_RTC_NOMINAL_TIMING) {
349 /* Reset Test register */
350 mmio_write_32(base + MVEBU_RTC_TEST_CONFIG_REG, 0);
351 mdelay(500);
352
Konstantin Porotchkin01c84d42018-02-26 16:01:57 +0200353 /* Reset Status register */
354 mmio_write_32(base + MVEBU_RTC_STATUS_REG,
355 (MVEBU_RTC_STATUS_ALARM1_MASK |
356 MVEBU_RTC_STATUS_ALARM2_MASK));
357 udelay(62);
358
359 /* Turn off Int1 and Int2 sources & clear the Alarm count */
360 mmio_write_32(base + MVEBU_RTC_IRQ_1_CONFIG_REG, 0);
361 mmio_write_32(base + MVEBU_RTC_IRQ_2_CONFIG_REG, 0);
362 mmio_write_32(base + MVEBU_RTC_ALARM_1_REG, 0);
363 mmio_write_32(base + MVEBU_RTC_ALARM_2_REG, 0);
364
365 /* Setup nominal register access timing */
366 mmio_write_32(base + MVEBU_RTC_CCR_REG,
367 MVEBU_RTC_NOMINAL_TIMING);
368
Konstantin Porotchkin01c84d42018-02-26 16:01:57 +0200369 /* Reset Status register */
370 mmio_write_32(base + MVEBU_RTC_STATUS_REG,
371 (MVEBU_RTC_STATUS_ALARM1_MASK |
372 MVEBU_RTC_STATUS_ALARM2_MASK));
373 udelay(50);
374 }
375}
376
377static void cp110_amb_adec_init(uintptr_t base)
378{
379 /* enable AXI-MBUS by clearing "Bridge Windows Disable" */
380 mmio_clrbits_32(base + MVEBU_BRIDGE_WIN_DIS_REG,
381 (1 << MVEBU_BRIDGE_WIN_DIS_OFF));
382
383 /* configure AXI-MBUS windows for CP */
384 init_amb_adec(base);
385}
386
Konstantin Porotchkin7b9e4d42020-07-26 17:49:54 +0300387static void cp110_trng_init(uintptr_t base)
388{
389 static bool done;
390 int ret;
391
392 if (!done) {
393 ret = eip76_rng_probe(base + MVEBU_TRNG_BASE);
394 if (ret != 0) {
395 ERROR("Failed to init TRNG @ 0x%lx\n", base);
396 return;
397 }
398 done = true;
399 }
400}
Konstantin Porotchkin01c84d42018-02-26 16:01:57 +0200401void cp110_init(uintptr_t cp110_base, uint32_t stream_id)
402{
403 INFO("%s: Initialize CPx - base = %lx\n", __func__, cp110_base);
404
405 /* configure IOB windows for CP0*/
406 init_iob(cp110_base);
407
408 /* configure AXI-MBUS windows for CP0*/
409 cp110_amb_adec_init(cp110_base);
410
411 /* configure axi for CP0*/
412 cp110_axi_attr_init(cp110_base);
413
414 /* Execute SW WA for erratas */
415 cp110_errata_wa_init(cp110_base);
416
417 /* Confiure pcie clock according to clock direction */
418 cp110_pcie_clk_cfg(cp110_base);
419
420 /* configure stream id for CP0 */
421 cp110_stream_id_init(cp110_base, stream_id);
422
423 /* Open AMB bridge for comphy for CP0 & CP1*/
Grzegorz Jaszczyk17e43dd2017-08-18 16:42:12 +0200424 cp110_amb_init(cp110_base);
Konstantin Porotchkin01c84d42018-02-26 16:01:57 +0200425
426 /* Reset RTC if needed */
427 cp110_rtc_init(cp110_base);
Konstantin Porotchkin7b9e4d42020-07-26 17:49:54 +0300428
429 /* TRNG init - for CP0 only */
430 cp110_trng_init(cp110_base);
Konstantin Porotchkin01c84d42018-02-26 16:01:57 +0200431}
432
433/* Do the minimal setup required to configure the CP in BLE */
434void cp110_ble_init(uintptr_t cp110_base)
435{
436#if PCI_EP_SUPPORT
437 INFO("%s: Initialize CPx - base = %lx\n", __func__, cp110_base);
438
Grzegorz Jaszczyk17e43dd2017-08-18 16:42:12 +0200439 cp110_amb_init(cp110_base);
Konstantin Porotchkin01c84d42018-02-26 16:01:57 +0200440
441 /* Configure PCIe clock */
442 cp110_pcie_clk_cfg(cp110_base);
443
444 /* Configure PCIe endpoint */
445 ble_plat_pcie_ep_setup();
446#endif
447}