1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Synopsys, Inc. All rights reserved.
4 * Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
11 #include <linux/printk.h>
12 #include <linux/kernel.h>
14 #include <asm/arcregs.h>
15 #include <fdt_support.h>
23 DECLARE_GLOBAL_DATA_PTR;
25 #define ALL_CPU_MASK GENMASK(NR_CPUS - 1, 0)
26 #define MASTER_CPU_ID 0
27 #define APERTURE_SHIFT 28
29 #define SLAVE_CPU_READY 0x12345678
30 #define BOOTSTAGE_1 1 /* after SP, FP setup, before HW init */
31 #define BOOTSTAGE_2 2 /* after HW init, before self halt */
32 #define BOOTSTAGE_3 3 /* after self halt */
33 #define BOOTSTAGE_4 4 /* before app launch */
34 #define BOOTSTAGE_5 5 /* after app launch, unreachable */
36 #define RESET_VECTOR_ADDR 0x0
38 #define CREG_BASE (ARC_PERIPHERAL_BASE + 0x1000)
39 #define CREG_CPU_START (CREG_BASE + 0x400)
40 #define CREG_CPU_START_MASK 0xF
42 #define SDIO_BASE (ARC_PERIPHERAL_BASE + 0xA000)
43 #define SDIO_UHS_REG_EXT (SDIO_BASE + 0x108)
44 #define SDIO_UHS_REG_EXT_DIV_2 (2 << 30)
46 /* Uncached access macros */
47 #define arc_read_uncached_32(ptr) \
50 __asm__ __volatile__( \
51 " ld.di %0, [%1] \n" \
57 #define arc_write_uncached_32(ptr, data)\
59 __asm__ __volatile__( \
60 " st.di %0, [%1] \n" \
62 : "r"(data), "r"(ptr)); \
65 struct hsdk_env_core_ctl {
66 u32_env entry[NR_CPUS];
67 u32_env iccm[NR_CPUS];
68 u32_env dccm[NR_CPUS];
71 struct hsdk_env_common_ctl {
83 * Uncached cross-cpu structure. All CPUs must access to this structure fields
84 * only with arc_read_uncached_32() / arc_write_uncached_32() accessors (which
85 * implement ld.di / st.di instructions). Simultaneous cached and uncached
86 * access to this area will lead to data loss.
87 * We flush all data caches in board_early_init_r() as we don't want to have
88 * any dirty line in L1d$ or SL$ in this area.
90 struct hsdk_cross_cpu {
91 /* slave CPU ready flag */
93 /* address of the area, which can be used for stack by slave CPU */
95 /* slave CPU status - bootstage number */
99 * Slave CPU data - it is copy of corresponding fields in
100 * hsdk_env_core_ctl and hsdk_env_common_ctl structures which are
101 * required for slave CPUs initialization.
102 * This fields can be populated by copying from hsdk_env_core_ctl
103 * and hsdk_env_common_ctl structures with sync_cross_cpu_data()
114 u8 cache_padding[ARCH_DMA_MINALIGN];
115 } __aligned(ARCH_DMA_MINALIGN);
117 /* Place for slave CPUs temporary stack */
118 static u32 slave_stack[256 * NR_CPUS] __aligned(ARCH_DMA_MINALIGN);
120 static struct hsdk_env_common_ctl env_common = {};
121 static struct hsdk_env_core_ctl env_core = {};
122 static struct hsdk_cross_cpu cross_cpu_data;
124 static const struct env_map_common env_map_common[] = {
125 { "core_mask", ENV_HEX, true, 0x1, 0xF, &env_common.core_mask },
126 { "non_volatile_limit", ENV_HEX, true, 0, 0xF, &env_common.nvlim },
127 { "icache_ena", ENV_HEX, true, 0, 1, &env_common.icache },
128 { "dcache_ena", ENV_HEX, true, 0, 1, &env_common.dcache },
132 static const struct env_map_common env_map_clock[] = {
133 { "cpu_freq", ENV_DEC, false, 100, 1000, &env_common.cpu_freq },
134 { "axi_freq", ENV_DEC, false, 200, 800, &env_common.axi_freq },
135 { "tun_freq", ENV_DEC, false, 0, 150, &env_common.tun_freq },
139 static const struct env_map_percpu env_map_core[] = {
140 { "core_iccm", ENV_HEX, true, {NO_CCM, 0, NO_CCM, 0}, {NO_CCM, 0xF, NO_CCM, 0xF}, &env_core.iccm },
141 { "core_dccm", ENV_HEX, true, {NO_CCM, 0, NO_CCM, 0}, {NO_CCM, 0xF, NO_CCM, 0xF}, &env_core.dccm },
145 static const struct env_map_common env_map_mask[] = {
146 { "core_mask", ENV_HEX, false, 0x1, 0xF, &env_common.core_mask },
150 static const struct env_map_percpu env_map_go[] = {
151 { "core_entry", ENV_HEX, true, {0, 0, 0, 0}, {U32_MAX, U32_MAX, U32_MAX, U32_MAX}, &env_core.entry },
155 static void sync_cross_cpu_data(void)
159 for (u32 i = 0; i < NR_CPUS; i++) {
160 value = env_core.entry[i].val;
161 arc_write_uncached_32(&cross_cpu_data.entry[i], value);
164 for (u32 i = 0; i < NR_CPUS; i++) {
165 value = env_core.iccm[i].val;
166 arc_write_uncached_32(&cross_cpu_data.iccm[i], value);
169 for (u32 i = 0; i < NR_CPUS; i++) {
170 value = env_core.dccm[i].val;
171 arc_write_uncached_32(&cross_cpu_data.dccm[i], value);
174 value = env_common.core_mask.val;
175 arc_write_uncached_32(&cross_cpu_data.core_mask, value);
177 value = env_common.icache.val;
178 arc_write_uncached_32(&cross_cpu_data.icache, value);
180 value = env_common.dcache.val;
181 arc_write_uncached_32(&cross_cpu_data.dcache, value);
184 /* Can be used only on master CPU */
185 static bool is_cpu_used(u32 cpu_id)
187 return !!(env_common.core_mask.val & BIT(cpu_id));
190 /* TODO: add ICCM BCR and DCCM BCR runtime check */
191 static void init_slave_cpu_func(u32 core)
195 /* Remap ICCM to another memory region if it exists */
196 val = arc_read_uncached_32(&cross_cpu_data.iccm[core]);
198 write_aux_reg(ARC_AUX_ICCM_BASE, val << APERTURE_SHIFT);
200 /* Remap DCCM to another memory region if it exists */
201 val = arc_read_uncached_32(&cross_cpu_data.dccm[core]);
203 write_aux_reg(ARC_AUX_DCCM_BASE, val << APERTURE_SHIFT);
205 if (arc_read_uncached_32(&cross_cpu_data.icache))
210 if (arc_read_uncached_32(&cross_cpu_data.dcache))
216 static void init_cluster_nvlim(void)
218 u32 val = env_common.nvlim.val << APERTURE_SHIFT;
221 write_aux_reg(ARC_AUX_NON_VOLATILE_LIMIT, val);
222 write_aux_reg(AUX_AUX_CACHE_LIMIT, val);
223 flush_n_invalidate_dcache_all();
226 static void init_master_icache(void)
228 if (icache_status()) {
229 /* I$ is enabled - we need to disable it */
230 if (!env_common.icache.val)
233 /* I$ is disabled - we need to enable it */
234 if (env_common.icache.val) {
237 /* invalidate I$ right after enable */
238 invalidate_icache_all();
243 static void init_master_dcache(void)
245 if (dcache_status()) {
246 /* D$ is enabled - we need to disable it */
247 if (!env_common.dcache.val)
250 /* D$ is disabled - we need to enable it */
251 if (env_common.dcache.val)
254 /* TODO: probably we need ti invalidate D$ right after enable */
258 static int cleanup_before_go(void)
260 disable_interrupts();
261 sync_n_cleanup_cache_all();
266 void slave_cpu_set_boot_addr(u32 addr)
268 /* All cores have reset vector pointing to 0 */
269 writel(addr, (void __iomem *)RESET_VECTOR_ADDR);
271 /* Make sure other cores see written value in memory */
272 sync_n_cleanup_cache_all();
275 static inline void halt_this_cpu(void)
277 __builtin_arc_flag(1);
280 static void smp_kick_cpu_x(u32 cpu_id)
282 int cmd = readl((void __iomem *)CREG_CPU_START);
284 if (cpu_id > NR_CPUS)
287 cmd &= ~CREG_CPU_START_MASK;
288 cmd |= (1 << cpu_id);
289 writel(cmd, (void __iomem *)CREG_CPU_START);
292 static u32 prepare_cpu_ctart_reg(void)
294 int cmd = readl((void __iomem *)CREG_CPU_START);
296 cmd &= ~CREG_CPU_START_MASK;
298 return cmd | env_common.core_mask.val;
301 /* slave CPU entry for configuration */
302 __attribute__((naked, noreturn, flatten)) noinline void hsdk_core_init_f(void)
304 __asm__ __volatile__(
309 : "r" (&cross_cpu_data.stack_ptr));
311 invalidate_icache_all();
313 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_1);
314 init_slave_cpu_func(CPU_ID_GET());
316 arc_write_uncached_32(&cross_cpu_data.ready_flag, SLAVE_CPU_READY);
317 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_2);
319 /* Halt the processor until the master kick us again */
323 * 3 NOPs after FLAG 1 instruction are no longer required for ARCv2
324 * cores but we leave them for gebug purposes.
330 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_3);
332 /* get the updated entry - invalidate i$ */
333 invalidate_icache_all();
335 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_4);
337 /* Run our program */
338 ((void (*)(void))(arc_read_uncached_32(&cross_cpu_data.entry[CPU_ID_GET()])))();
340 /* This bootstage is unreachable as we don't return from app we launch */
341 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_5);
343 /* Something went terribly wrong */
348 static void clear_cross_cpu_data(void)
350 arc_write_uncached_32(&cross_cpu_data.ready_flag, 0);
351 arc_write_uncached_32(&cross_cpu_data.stack_ptr, 0);
353 for (u32 i = 0; i < NR_CPUS; i++)
354 arc_write_uncached_32(&cross_cpu_data.status[i], 0);
357 static noinline void do_init_slave_cpu(u32 cpu_id)
359 /* attempts number for check clave CPU ready_flag */
361 u32 stack_ptr = (u32)(slave_stack + (64 * cpu_id));
363 if (cpu_id >= NR_CPUS)
366 arc_write_uncached_32(&cross_cpu_data.ready_flag, 0);
368 /* Use global unique place for each slave cpu stack */
369 arc_write_uncached_32(&cross_cpu_data.stack_ptr, stack_ptr);
371 debug("CPU %u: stack pool base: %p\n", cpu_id, slave_stack);
372 debug("CPU %u: current slave stack base: %x\n", cpu_id, stack_ptr);
373 slave_cpu_set_boot_addr((u32)hsdk_core_init_f);
375 smp_kick_cpu_x(cpu_id);
377 debug("CPU %u: cross-cpu flag: %x [before timeout]\n", cpu_id,
378 arc_read_uncached_32(&cross_cpu_data.ready_flag));
380 while (!arc_read_uncached_32(&cross_cpu_data.ready_flag) && attempts--)
383 /* Just to be sure that slave cpu is halted after it set ready_flag */
387 * Only print error here if we reach timeout as there is no option to
388 * halt slave cpu (or check that slave cpu is halted)
391 pr_err("CPU %u is not responding after init!\n", cpu_id);
393 /* Check current stage of slave cpu */
394 if (arc_read_uncached_32(&cross_cpu_data.status[cpu_id]) != BOOTSTAGE_2)
395 pr_err("CPU %u status is unexpected: %d\n", cpu_id,
396 arc_read_uncached_32(&cross_cpu_data.status[cpu_id]));
398 debug("CPU %u: cross-cpu flag: %x [after timeout]\n", cpu_id,
399 arc_read_uncached_32(&cross_cpu_data.ready_flag));
400 debug("CPU %u: status: %d [after timeout]\n", cpu_id,
401 arc_read_uncached_32(&cross_cpu_data.status[cpu_id]));
404 static void do_init_slave_cpus(void)
406 clear_cross_cpu_data();
407 sync_cross_cpu_data();
409 debug("cross_cpu_data location: %#x\n", (u32)&cross_cpu_data);
411 for (u32 i = MASTER_CPU_ID + 1; i < NR_CPUS; i++)
413 do_init_slave_cpu(i);
416 static void do_init_master_cpu(void)
419 * Setup master caches even if master isn't used as we want to use
420 * same cache configuration on all running CPUs
422 init_master_icache();
423 init_master_dcache();
426 enum hsdk_axi_masters {
444 * m master AXI_M_m_SLV0 AXI_M_m_SLV1 AXI_M_m_OFFSET0 AXI_M_m_OFFSET1
445 * 0 HS (CBU) 0x11111111 0x63111111 0xFEDCBA98 0x0E543210
446 * 1 HS (RTT) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
447 * 2 AXI Tunnel 0x88888888 0x88888888 0xFEDCBA98 0x76543210
448 * 3 HDMI-VIDEO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
449 * 4 HDMI-ADUIO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
450 * 5 USB-HOST 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
451 * 6 ETHERNET 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
452 * 7 SDIO 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
453 * 8 GPU 0x77777777 0x77777777 0xFEDCBA98 0x76543210
454 * 9 DMAC (port #1) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
455 * 10 DMAC (port #2) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
456 * 11 DVFS 0x00000000 0x60000000 0x00000000 0x00000000
458 * Please read ARC HS Development IC Specification, section 17.2 for more
459 * information about apertures configuration.
460 * NOTE: we intentionally modify default settings in U-boot. Default settings
461 * are specified in "Table 111 CREG Address Decoder register reset values".
464 #define CREG_AXI_M_SLV0(m) ((void __iomem *)(CREG_BASE + 0x020 * (m)))
465 #define CREG_AXI_M_SLV1(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x004))
466 #define CREG_AXI_M_OFT0(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x008))
467 #define CREG_AXI_M_OFT1(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x00C))
468 #define CREG_AXI_M_UPDT(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x014))
470 #define CREG_AXI_M_HS_CORE_BOOT ((void __iomem *)(CREG_BASE + 0x010))
472 #define CREG_PAE ((void __iomem *)(CREG_BASE + 0x180))
473 #define CREG_PAE_UPDT ((void __iomem *)(CREG_BASE + 0x194))
475 void init_memory_bridge(void)
480 * M_HS_CORE has one unic register - BOOT.
481 * We need to clean boot mirror (BOOT[1:0]) bits in them.
483 reg = readl(CREG_AXI_M_HS_CORE_BOOT) & (~0x3);
484 writel(reg, CREG_AXI_M_HS_CORE_BOOT);
485 writel(0x11111111, CREG_AXI_M_SLV0(M_HS_CORE));
486 writel(0x63111111, CREG_AXI_M_SLV1(M_HS_CORE));
487 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HS_CORE));
488 writel(0x0E543210, CREG_AXI_M_OFT1(M_HS_CORE));
489 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HS_CORE));
491 writel(0x77777777, CREG_AXI_M_SLV0(M_HS_RTT));
492 writel(0x77777777, CREG_AXI_M_SLV1(M_HS_RTT));
493 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HS_RTT));
494 writel(0x76543210, CREG_AXI_M_OFT1(M_HS_RTT));
495 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HS_RTT));
497 writel(0x88888888, CREG_AXI_M_SLV0(M_AXI_TUN));
498 writel(0x88888888, CREG_AXI_M_SLV1(M_AXI_TUN));
499 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_AXI_TUN));
500 writel(0x76543210, CREG_AXI_M_OFT1(M_AXI_TUN));
501 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_AXI_TUN));
503 writel(0x77777777, CREG_AXI_M_SLV0(M_HDMI_VIDEO));
504 writel(0x77777777, CREG_AXI_M_SLV1(M_HDMI_VIDEO));
505 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HDMI_VIDEO));
506 writel(0x76543210, CREG_AXI_M_OFT1(M_HDMI_VIDEO));
507 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HDMI_VIDEO));
509 writel(0x77777777, CREG_AXI_M_SLV0(M_HDMI_AUDIO));
510 writel(0x77777777, CREG_AXI_M_SLV1(M_HDMI_AUDIO));
511 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HDMI_AUDIO));
512 writel(0x76543210, CREG_AXI_M_OFT1(M_HDMI_AUDIO));
513 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HDMI_AUDIO));
515 writel(0x77777777, CREG_AXI_M_SLV0(M_USB_HOST));
516 writel(0x77999999, CREG_AXI_M_SLV1(M_USB_HOST));
517 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_USB_HOST));
518 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_USB_HOST));
519 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_USB_HOST));
521 writel(0x77777777, CREG_AXI_M_SLV0(M_ETHERNET));
522 writel(0x77999999, CREG_AXI_M_SLV1(M_ETHERNET));
523 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_ETHERNET));
524 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_ETHERNET));
525 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_ETHERNET));
527 writel(0x77777777, CREG_AXI_M_SLV0(M_SDIO));
528 writel(0x77999999, CREG_AXI_M_SLV1(M_SDIO));
529 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_SDIO));
530 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_SDIO));
531 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_SDIO));
533 writel(0x77777777, CREG_AXI_M_SLV0(M_GPU));
534 writel(0x77777777, CREG_AXI_M_SLV1(M_GPU));
535 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_GPU));
536 writel(0x76543210, CREG_AXI_M_OFT1(M_GPU));
537 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_GPU));
539 writel(0x77777777, CREG_AXI_M_SLV0(M_DMAC_0));
540 writel(0x77777777, CREG_AXI_M_SLV1(M_DMAC_0));
541 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_DMAC_0));
542 writel(0x76543210, CREG_AXI_M_OFT1(M_DMAC_0));
543 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_DMAC_0));
545 writel(0x77777777, CREG_AXI_M_SLV0(M_DMAC_1));
546 writel(0x77777777, CREG_AXI_M_SLV1(M_DMAC_1));
547 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_DMAC_1));
548 writel(0x76543210, CREG_AXI_M_OFT1(M_DMAC_1));
549 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_DMAC_1));
551 writel(0x00000000, CREG_AXI_M_SLV0(M_DVFS));
552 writel(0x60000000, CREG_AXI_M_SLV1(M_DVFS));
553 writel(0x00000000, CREG_AXI_M_OFT0(M_DVFS));
554 writel(0x00000000, CREG_AXI_M_OFT1(M_DVFS));
555 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_DVFS));
557 writel(0x00000000, CREG_PAE);
558 writel(UPDATE_VAL, CREG_PAE_UPDT);
561 static void setup_clocks(void)
565 /* Setup CPU clock */
566 if (env_common.cpu_freq.set) {
567 rate = env_common.cpu_freq.val;
568 soc_clk_ctl("cpu-clk", &rate, CLK_ON | CLK_SET | CLK_MHZ);
571 /* Setup TUN clock */
572 if (env_common.tun_freq.set) {
573 rate = env_common.tun_freq.val;
575 soc_clk_ctl("tun-clk", &rate, CLK_ON | CLK_SET | CLK_MHZ);
577 soc_clk_ctl("tun-clk", NULL, CLK_OFF);
580 if (env_common.axi_freq.set) {
581 rate = env_common.axi_freq.val;
582 soc_clk_ctl("axi-clk", &rate, CLK_SET | CLK_ON | CLK_MHZ);
586 static void do_init_cluster(void)
589 * A multi-core ARC HS configuration always includes only one
590 * ARC_AUX_NON_VOLATILE_LIMIT register, which is shared by all the
593 init_cluster_nvlim();
596 static int check_master_cpu_id(void)
598 if (CPU_ID_GET() == MASTER_CPU_ID)
601 pr_err("u-boot runs on non-master cpu with id: %lu\n", CPU_ID_GET());
606 static noinline int prepare_cpus(void)
610 ret = check_master_cpu_id();
614 ret = envs_process_and_validate(env_map_common, env_map_core, is_cpu_used);
618 printf("CPU start mask is %#x\n", env_common.core_mask.val);
620 do_init_slave_cpus();
621 do_init_master_cpu();
627 static int hsdk_go_run(u32 cpu_start_reg)
629 /* Cleanup caches, disable interrupts */
632 if (env_common.halt_on_boot)
636 * 3 NOPs after FLAG 1 instruction are no longer required for ARCv2
637 * cores but we leave them for gebug purposes.
643 /* Kick chosen slave CPUs */
644 writel(cpu_start_reg, (void __iomem *)CREG_CPU_START);
646 if (is_cpu_used(MASTER_CPU_ID))
647 ((void (*)(void))(env_core.entry[MASTER_CPU_ID].val))();
651 pr_err("u-boot still runs on cpu [%ld]\n", CPU_ID_GET());
654 * We will never return after executing our program if master cpu used
655 * otherwise halt master cpu manually.
663 int board_prep_linux(bootm_headers_t *images)
668 ret = envs_read_validate_common(env_map_mask);
672 /* Rollback to default values */
673 if (!env_common.core_mask.set) {
674 env_common.core_mask.val = ALL_CPU_MASK;
675 env_common.core_mask.set = true;
678 printf("CPU start mask is %#x\n", env_common.core_mask.val);
680 if (!is_cpu_used(MASTER_CPU_ID))
681 pr_err("ERR: try to launch linux with CPU[0] disabled! It doesn't work for ARC.\n");
684 * If we want to launch linux on all CPUs we don't need to patch
685 * linux DTB as it is default configuration
687 if (env_common.core_mask.val == ALL_CPU_MASK)
690 if (!IMAGE_ENABLE_OF_LIBFDT || !images->ft_len) {
691 pr_err("WARN: core_mask setup will work properly only with external DTB!\n");
695 /* patch '/possible-cpus' property according to cpu mask */
696 ofst = fdt_path_offset(images->ft_addr, "/");
697 sprintf(mask, "%s%s%s%s",
698 is_cpu_used(0) ? "0," : "",
699 is_cpu_used(1) ? "1," : "",
700 is_cpu_used(2) ? "2," : "",
701 is_cpu_used(3) ? "3," : "");
702 ret = fdt_setprop_string(images->ft_addr, ofst, "possible-cpus", mask);
704 * If we failed to patch '/possible-cpus' property we don't need break
705 * linux loading process: kernel will handle it but linux will print
706 * warning like "Timeout: CPU1 FAILED to comeup !!!".
707 * So warn here about error, but return 0 like no error had occurred.
710 pr_err("WARN: failed to patch '/possible-cpus' property, ret=%d\n",
716 void board_jump_and_run(ulong entry, int zero, int arch, uint params)
718 void (*kernel_entry)(int zero, int arch, uint params);
721 kernel_entry = (void (*)(int, int, uint))entry;
723 /* Prepare CREG_CPU_START for kicking chosen CPUs */
724 cpu_start_reg = prepare_cpu_ctart_reg();
726 /* In case of run without hsdk_init */
727 slave_cpu_set_boot_addr(entry);
729 /* In case of run with hsdk_init */
730 for (u32 i = 0; i < NR_CPUS; i++) {
731 env_core.entry[i].val = entry;
732 env_core.entry[i].set = true;
734 /* sync cross_cpu struct as we updated core-entry variables */
735 sync_cross_cpu_data();
737 /* Kick chosen slave CPUs */
738 writel(cpu_start_reg, (void __iomem *)CREG_CPU_START);
741 kernel_entry(zero, arch, params);
744 static int hsdk_go_prepare_and_run(void)
746 /* Prepare CREG_CPU_START for kicking chosen CPUs */
747 u32 reg = prepare_cpu_ctart_reg();
749 if (env_common.halt_on_boot)
750 printf("CPU will halt before application start, start application with debugger.\n");
752 return hsdk_go_run(reg);
755 static int do_hsdk_go(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
760 * Check for 'halt' parameter. 'halt' = enter halt-mode just before
761 * starting the application; can be used for debug.
764 env_common.halt_on_boot = !strcmp(argv[1], "halt");
765 if (!env_common.halt_on_boot) {
766 pr_err("Unrecognised parameter: \'%s\'\n", argv[1]);
767 return CMD_RET_FAILURE;
771 ret = check_master_cpu_id();
775 ret = envs_process_and_validate(env_map_mask, env_map_go, is_cpu_used);
779 /* sync cross_cpu struct as we updated core-entry variables */
780 sync_cross_cpu_data();
782 ret = hsdk_go_prepare_and_run();
784 return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
788 hsdk_go, 3, 0, do_hsdk_go,
789 "Synopsys HSDK specific command",
790 " - Boot stand-alone application on HSDK\n"
791 "hsdk_go halt - Boot stand-alone application on HSDK, halt CPU just before application run\n"
794 static int do_hsdk_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
796 static bool done = false;
799 /* hsdk_init can be run only once */
801 printf("HSDK HW is already initialized! Please reset the board if you want to change the configuration.\n");
802 return CMD_RET_FAILURE;
805 ret = prepare_cpus();
809 return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
813 hsdk_init, 1, 0, do_hsdk_init,
814 "Synopsys HSDK specific command",
818 static int do_hsdk_clock_set(cmd_tbl_t *cmdtp, int flag, int argc,
823 /* Strip off leading subcommand argument */
827 envs_cleanup_common(env_map_clock);
830 printf("Set clocks to values specified in environment\n");
831 ret = envs_read_common(env_map_clock);
833 printf("Set clocks to values specified in args\n");
834 ret = args_envs_enumerate(env_map_clock, 2, argc, argv);
838 return CMD_RET_FAILURE;
840 ret = envs_validate_common(env_map_clock);
842 return CMD_RET_FAILURE;
844 /* Setup clock tree HW */
847 return CMD_RET_SUCCESS;
850 static int do_hsdk_clock_get(cmd_tbl_t *cmdtp, int flag, int argc,
855 if (soc_clk_ctl("cpu-clk", &rate, CLK_GET | CLK_MHZ))
856 return CMD_RET_FAILURE;
858 if (env_set_ulong("cpu_freq", rate))
859 return CMD_RET_FAILURE;
861 if (soc_clk_ctl("tun-clk", &rate, CLK_GET | CLK_MHZ))
862 return CMD_RET_FAILURE;
864 if (env_set_ulong("tun_freq", rate))
865 return CMD_RET_FAILURE;
867 if (soc_clk_ctl("axi-clk", &rate, CLK_GET | CLK_MHZ))
868 return CMD_RET_FAILURE;
870 if (env_set_ulong("axi_freq", rate))
871 return CMD_RET_FAILURE;
873 printf("Clock values are saved to environment\n");
875 return CMD_RET_SUCCESS;
878 static int do_hsdk_clock_print(cmd_tbl_t *cmdtp, int flag, int argc,
882 soc_clk_ctl("cpu-clk", NULL, CLK_PRINT | CLK_MHZ);
883 soc_clk_ctl("tun-clk", NULL, CLK_PRINT | CLK_MHZ);
884 soc_clk_ctl("axi-clk", NULL, CLK_PRINT | CLK_MHZ);
885 soc_clk_ctl("ddr-clk", NULL, CLK_PRINT | CLK_MHZ);
887 return CMD_RET_SUCCESS;
890 static int do_hsdk_clock_print_all(cmd_tbl_t *cmdtp, int flag, int argc,
894 * NOTE: as of today we don't use some peripherals like HDMI / EBI
895 * so we don't want to print their clocks ("hdmi-sys-clk", "hdmi-pll",
896 * "hdmi-clk", "ebi-clk"). Nevertheless their clock subsystems is fully
897 * functional and we can print their clocks if it is required
900 /* CPU clock domain */
901 soc_clk_ctl("cpu-pll", NULL, CLK_PRINT | CLK_MHZ);
902 soc_clk_ctl("cpu-clk", NULL, CLK_PRINT | CLK_MHZ);
905 /* SYS clock domain */
906 soc_clk_ctl("sys-pll", NULL, CLK_PRINT | CLK_MHZ);
907 soc_clk_ctl("apb-clk", NULL, CLK_PRINT | CLK_MHZ);
908 soc_clk_ctl("axi-clk", NULL, CLK_PRINT | CLK_MHZ);
909 soc_clk_ctl("eth-clk", NULL, CLK_PRINT | CLK_MHZ);
910 soc_clk_ctl("usb-clk", NULL, CLK_PRINT | CLK_MHZ);
911 soc_clk_ctl("sdio-clk", NULL, CLK_PRINT | CLK_MHZ);
912 /* soc_clk_ctl("hdmi-sys-clk", NULL, CLK_PRINT | CLK_MHZ); */
913 soc_clk_ctl("gfx-core-clk", NULL, CLK_PRINT | CLK_MHZ);
914 soc_clk_ctl("gfx-dma-clk", NULL, CLK_PRINT | CLK_MHZ);
915 soc_clk_ctl("gfx-cfg-clk", NULL, CLK_PRINT | CLK_MHZ);
916 soc_clk_ctl("dmac-core-clk", NULL, CLK_PRINT | CLK_MHZ);
917 soc_clk_ctl("dmac-cfg-clk", NULL, CLK_PRINT | CLK_MHZ);
918 soc_clk_ctl("sdio-ref-clk", NULL, CLK_PRINT | CLK_MHZ);
919 soc_clk_ctl("spi-clk", NULL, CLK_PRINT | CLK_MHZ);
920 soc_clk_ctl("i2c-clk", NULL, CLK_PRINT | CLK_MHZ);
921 /* soc_clk_ctl("ebi-clk", NULL, CLK_PRINT | CLK_MHZ); */
922 soc_clk_ctl("uart-clk", NULL, CLK_PRINT | CLK_MHZ);
925 /* DDR clock domain */
926 soc_clk_ctl("ddr-clk", NULL, CLK_PRINT | CLK_MHZ);
929 /* HDMI clock domain */
930 /* soc_clk_ctl("hdmi-pll", NULL, CLK_PRINT | CLK_MHZ); */
931 /* soc_clk_ctl("hdmi-clk", NULL, CLK_PRINT | CLK_MHZ); */
934 /* TUN clock domain */
935 soc_clk_ctl("tun-pll", NULL, CLK_PRINT | CLK_MHZ);
936 soc_clk_ctl("tun-clk", NULL, CLK_PRINT | CLK_MHZ);
937 soc_clk_ctl("rom-clk", NULL, CLK_PRINT | CLK_MHZ);
938 soc_clk_ctl("pwm-clk", NULL, CLK_PRINT | CLK_MHZ);
941 return CMD_RET_SUCCESS;
944 cmd_tbl_t cmd_hsdk_clock[] = {
945 U_BOOT_CMD_MKENT(set, 3, 0, do_hsdk_clock_set, "", ""),
946 U_BOOT_CMD_MKENT(get, 3, 0, do_hsdk_clock_get, "", ""),
947 U_BOOT_CMD_MKENT(print, 4, 0, do_hsdk_clock_print, "", ""),
948 U_BOOT_CMD_MKENT(print_all, 4, 0, do_hsdk_clock_print_all, "", ""),
951 static int do_hsdk_clock(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
956 return CMD_RET_USAGE;
958 /* Strip off leading 'hsdk_clock' command argument */
962 c = find_cmd_tbl(argv[0], cmd_hsdk_clock, ARRAY_SIZE(cmd_hsdk_clock));
964 return CMD_RET_USAGE;
966 return c->cmd(cmdtp, flag, argc, argv);
970 hsdk_clock, CONFIG_SYS_MAXARGS, 0, do_hsdk_clock,
971 "Synopsys HSDK specific clock command",
972 "set - Set clock to values specified in environment / command line arguments\n"
973 "hsdk_clock get - Save clock values to environment\n"
974 "hsdk_clock print - Print main clock values to console\n"
975 "hsdk_clock print_all - Print all clock values to console\n"
979 int board_early_init_f(void)
982 * Setup AXI apertures unconditionally as we want to have DDR
983 * in 0x00000000 region when we are kicking slave cpus.
985 init_memory_bridge();
988 * Switch SDIO external ciu clock divider from default div-by-8 to
989 * minimum possible div-by-2.
991 writel(SDIO_UHS_REG_EXT_DIV_2, (void __iomem *)SDIO_UHS_REG_EXT);
996 int board_early_init_r(void)
999 * TODO: Init USB here to be able read environment from USB MSD.
1000 * It can be done with usb_init() call. We can't do it right now
1001 * due to brocken USB IP SW reset and lack of USB IP HW reset in
1002 * linux kernel (if we init USB here we will break USB in linux)
1006 * Flush all d$ as we want to use uncached area with st.di / ld.di
1007 * instructions and we don't want to have any dirty line in L1d$ or SL$
1008 * in this area. It is enough to flush all d$ once here as we access to
1009 * uncached area with regular st (non .di) instruction only when we copy
1010 * data during u-boot relocation.
1014 printf("Relocation Offset is: %08lx\n", gd->reloc_off);
1019 int board_late_init(void)
1022 * Populate environment with clock frequency values -
1023 * run hsdk_clock get callback without uboot command run.
1025 do_hsdk_clock_get(NULL, 0, 0, NULL);
1030 int checkboard(void)
1032 puts("Board: Synopsys ARC HS Development Kit\n");