1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Synopsys, Inc. All rights reserved.
4 * Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
12 #include <linux/printk.h>
13 #include <linux/kernel.h>
15 #include <asm/arcregs.h>
16 #include <fdt_support.h>
24 DECLARE_GLOBAL_DATA_PTR;
26 #define ALL_CPU_MASK GENMASK(NR_CPUS - 1, 0)
27 #define MASTER_CPU_ID 0
28 #define APERTURE_SHIFT 28
30 #define SLAVE_CPU_READY 0x12345678
31 #define BOOTSTAGE_1 1 /* after SP, FP setup, before HW init */
32 #define BOOTSTAGE_2 2 /* after HW init, before self halt */
33 #define BOOTSTAGE_3 3 /* after self halt */
34 #define BOOTSTAGE_4 4 /* before app launch */
35 #define BOOTSTAGE_5 5 /* after app launch, unreachable */
37 #define RESET_VECTOR_ADDR 0x0
39 #define CREG_BASE (ARC_PERIPHERAL_BASE + 0x1000)
40 #define CREG_CPU_START (CREG_BASE + 0x400)
41 #define CREG_CPU_START_MASK 0xF
43 #define SDIO_BASE (ARC_PERIPHERAL_BASE + 0xA000)
44 #define SDIO_UHS_REG_EXT (SDIO_BASE + 0x108)
45 #define SDIO_UHS_REG_EXT_DIV_2 (2 << 30)
47 /* Uncached access macros */
48 #define arc_read_uncached_32(ptr) \
51 __asm__ __volatile__( \
52 " ld.di %0, [%1] \n" \
58 #define arc_write_uncached_32(ptr, data)\
60 __asm__ __volatile__( \
61 " st.di %0, [%1] \n" \
63 : "r"(data), "r"(ptr)); \
66 struct hsdk_env_core_ctl {
67 u32_env entry[NR_CPUS];
68 u32_env iccm[NR_CPUS];
69 u32_env dccm[NR_CPUS];
72 struct hsdk_env_common_ctl {
84 * Uncached cross-cpu structure. All CPUs must access to this structure fields
85 * only with arc_read_uncached_32() / arc_write_uncached_32() accessors (which
86 * implement ld.di / st.di instructions). Simultaneous cached and uncached
87 * access to this area will lead to data loss.
88 * We flush all data caches in board_early_init_r() as we don't want to have
89 * any dirty line in L1d$ or SL$ in this area.
91 struct hsdk_cross_cpu {
92 /* slave CPU ready flag */
94 /* address of the area, which can be used for stack by slave CPU */
96 /* slave CPU status - bootstage number */
100 * Slave CPU data - it is copy of corresponding fields in
101 * hsdk_env_core_ctl and hsdk_env_common_ctl structures which are
102 * required for slave CPUs initialization.
103 * This fields can be populated by copying from hsdk_env_core_ctl
104 * and hsdk_env_common_ctl structures with sync_cross_cpu_data()
115 u8 cache_padding[ARCH_DMA_MINALIGN];
116 } __aligned(ARCH_DMA_MINALIGN);
118 /* Place for slave CPUs temporary stack */
119 static u32 slave_stack[256 * NR_CPUS] __aligned(ARCH_DMA_MINALIGN);
121 static struct hsdk_env_common_ctl env_common = {};
122 static struct hsdk_env_core_ctl env_core = {};
123 static struct hsdk_cross_cpu cross_cpu_data;
125 static const struct env_map_common env_map_common[] = {
126 { "core_mask", ENV_HEX, true, 0x1, 0xF, &env_common.core_mask },
127 { "non_volatile_limit", ENV_HEX, true, 0, 0xF, &env_common.nvlim },
128 { "icache_ena", ENV_HEX, true, 0, 1, &env_common.icache },
129 { "dcache_ena", ENV_HEX, true, 0, 1, &env_common.dcache },
133 static const struct env_map_common env_map_clock[] = {
134 { "cpu_freq", ENV_DEC, false, 100, 1000, &env_common.cpu_freq },
135 { "axi_freq", ENV_DEC, false, 200, 800, &env_common.axi_freq },
136 { "tun_freq", ENV_DEC, false, 0, 150, &env_common.tun_freq },
140 static const struct env_map_percpu env_map_core[] = {
141 { "core_iccm", ENV_HEX, true, {NO_CCM, 0, NO_CCM, 0}, {NO_CCM, 0xF, NO_CCM, 0xF}, &env_core.iccm },
142 { "core_dccm", ENV_HEX, true, {NO_CCM, 0, NO_CCM, 0}, {NO_CCM, 0xF, NO_CCM, 0xF}, &env_core.dccm },
146 static const struct env_map_common env_map_mask[] = {
147 { "core_mask", ENV_HEX, false, 0x1, 0xF, &env_common.core_mask },
151 static const struct env_map_percpu env_map_go[] = {
152 { "core_entry", ENV_HEX, true, {0, 0, 0, 0}, {U32_MAX, U32_MAX, U32_MAX, U32_MAX}, &env_core.entry },
156 static void sync_cross_cpu_data(void)
160 for (u32 i = 0; i < NR_CPUS; i++) {
161 value = env_core.entry[i].val;
162 arc_write_uncached_32(&cross_cpu_data.entry[i], value);
165 for (u32 i = 0; i < NR_CPUS; i++) {
166 value = env_core.iccm[i].val;
167 arc_write_uncached_32(&cross_cpu_data.iccm[i], value);
170 for (u32 i = 0; i < NR_CPUS; i++) {
171 value = env_core.dccm[i].val;
172 arc_write_uncached_32(&cross_cpu_data.dccm[i], value);
175 value = env_common.core_mask.val;
176 arc_write_uncached_32(&cross_cpu_data.core_mask, value);
178 value = env_common.icache.val;
179 arc_write_uncached_32(&cross_cpu_data.icache, value);
181 value = env_common.dcache.val;
182 arc_write_uncached_32(&cross_cpu_data.dcache, value);
185 /* Can be used only on master CPU */
186 static bool is_cpu_used(u32 cpu_id)
188 return !!(env_common.core_mask.val & BIT(cpu_id));
191 /* TODO: add ICCM BCR and DCCM BCR runtime check */
192 static void init_slave_cpu_func(u32 core)
196 /* Remap ICCM to another memory region if it exists */
197 val = arc_read_uncached_32(&cross_cpu_data.iccm[core]);
199 write_aux_reg(ARC_AUX_ICCM_BASE, val << APERTURE_SHIFT);
201 /* Remap DCCM to another memory region if it exists */
202 val = arc_read_uncached_32(&cross_cpu_data.dccm[core]);
204 write_aux_reg(ARC_AUX_DCCM_BASE, val << APERTURE_SHIFT);
206 if (arc_read_uncached_32(&cross_cpu_data.icache))
211 if (arc_read_uncached_32(&cross_cpu_data.dcache))
217 static void init_cluster_nvlim(void)
219 u32 val = env_common.nvlim.val << APERTURE_SHIFT;
222 write_aux_reg(ARC_AUX_NON_VOLATILE_LIMIT, val);
223 write_aux_reg(AUX_AUX_CACHE_LIMIT, val);
224 flush_n_invalidate_dcache_all();
227 static void init_master_icache(void)
229 if (icache_status()) {
230 /* I$ is enabled - we need to disable it */
231 if (!env_common.icache.val)
234 /* I$ is disabled - we need to enable it */
235 if (env_common.icache.val) {
238 /* invalidate I$ right after enable */
239 invalidate_icache_all();
244 static void init_master_dcache(void)
246 if (dcache_status()) {
247 /* D$ is enabled - we need to disable it */
248 if (!env_common.dcache.val)
251 /* D$ is disabled - we need to enable it */
252 if (env_common.dcache.val)
255 /* TODO: probably we need ti invalidate D$ right after enable */
259 static int cleanup_before_go(void)
261 disable_interrupts();
262 sync_n_cleanup_cache_all();
267 void slave_cpu_set_boot_addr(u32 addr)
269 /* All cores have reset vector pointing to 0 */
270 writel(addr, (void __iomem *)RESET_VECTOR_ADDR);
272 /* Make sure other cores see written value in memory */
273 sync_n_cleanup_cache_all();
276 static inline void halt_this_cpu(void)
278 __builtin_arc_flag(1);
281 static void smp_kick_cpu_x(u32 cpu_id)
283 int cmd = readl((void __iomem *)CREG_CPU_START);
285 if (cpu_id > NR_CPUS)
288 cmd &= ~CREG_CPU_START_MASK;
289 cmd |= (1 << cpu_id);
290 writel(cmd, (void __iomem *)CREG_CPU_START);
293 static u32 prepare_cpu_ctart_reg(void)
295 int cmd = readl((void __iomem *)CREG_CPU_START);
297 cmd &= ~CREG_CPU_START_MASK;
299 return cmd | env_common.core_mask.val;
302 /* slave CPU entry for configuration */
303 __attribute__((naked, noreturn, flatten)) noinline void hsdk_core_init_f(void)
305 __asm__ __volatile__(
310 : "r" (&cross_cpu_data.stack_ptr));
312 invalidate_icache_all();
314 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_1);
315 init_slave_cpu_func(CPU_ID_GET());
317 arc_write_uncached_32(&cross_cpu_data.ready_flag, SLAVE_CPU_READY);
318 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_2);
320 /* Halt the processor until the master kick us again */
324 * 3 NOPs after FLAG 1 instruction are no longer required for ARCv2
325 * cores but we leave them for gebug purposes.
331 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_3);
333 /* get the updated entry - invalidate i$ */
334 invalidate_icache_all();
336 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_4);
338 /* Run our program */
339 ((void (*)(void))(arc_read_uncached_32(&cross_cpu_data.entry[CPU_ID_GET()])))();
341 /* This bootstage is unreachable as we don't return from app we launch */
342 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_5);
344 /* Something went terribly wrong */
349 static void clear_cross_cpu_data(void)
351 arc_write_uncached_32(&cross_cpu_data.ready_flag, 0);
352 arc_write_uncached_32(&cross_cpu_data.stack_ptr, 0);
354 for (u32 i = 0; i < NR_CPUS; i++)
355 arc_write_uncached_32(&cross_cpu_data.status[i], 0);
358 static noinline void do_init_slave_cpu(u32 cpu_id)
360 /* attempts number for check clave CPU ready_flag */
362 u32 stack_ptr = (u32)(slave_stack + (64 * cpu_id));
364 if (cpu_id >= NR_CPUS)
367 arc_write_uncached_32(&cross_cpu_data.ready_flag, 0);
369 /* Use global unique place for each slave cpu stack */
370 arc_write_uncached_32(&cross_cpu_data.stack_ptr, stack_ptr);
372 debug("CPU %u: stack pool base: %p\n", cpu_id, slave_stack);
373 debug("CPU %u: current slave stack base: %x\n", cpu_id, stack_ptr);
374 slave_cpu_set_boot_addr((u32)hsdk_core_init_f);
376 smp_kick_cpu_x(cpu_id);
378 debug("CPU %u: cross-cpu flag: %x [before timeout]\n", cpu_id,
379 arc_read_uncached_32(&cross_cpu_data.ready_flag));
381 while (!arc_read_uncached_32(&cross_cpu_data.ready_flag) && attempts--)
384 /* Just to be sure that slave cpu is halted after it set ready_flag */
388 * Only print error here if we reach timeout as there is no option to
389 * halt slave cpu (or check that slave cpu is halted)
392 pr_err("CPU %u is not responding after init!\n", cpu_id);
394 /* Check current stage of slave cpu */
395 if (arc_read_uncached_32(&cross_cpu_data.status[cpu_id]) != BOOTSTAGE_2)
396 pr_err("CPU %u status is unexpected: %d\n", cpu_id,
397 arc_read_uncached_32(&cross_cpu_data.status[cpu_id]));
399 debug("CPU %u: cross-cpu flag: %x [after timeout]\n", cpu_id,
400 arc_read_uncached_32(&cross_cpu_data.ready_flag));
401 debug("CPU %u: status: %d [after timeout]\n", cpu_id,
402 arc_read_uncached_32(&cross_cpu_data.status[cpu_id]));
405 static void do_init_slave_cpus(void)
407 clear_cross_cpu_data();
408 sync_cross_cpu_data();
410 debug("cross_cpu_data location: %#x\n", (u32)&cross_cpu_data);
412 for (u32 i = MASTER_CPU_ID + 1; i < NR_CPUS; i++)
414 do_init_slave_cpu(i);
417 static void do_init_master_cpu(void)
420 * Setup master caches even if master isn't used as we want to use
421 * same cache configuration on all running CPUs
423 init_master_icache();
424 init_master_dcache();
427 enum hsdk_axi_masters {
445 * m master AXI_M_m_SLV0 AXI_M_m_SLV1 AXI_M_m_OFFSET0 AXI_M_m_OFFSET1
446 * 0 HS (CBU) 0x11111111 0x63111111 0xFEDCBA98 0x0E543210
447 * 1 HS (RTT) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
448 * 2 AXI Tunnel 0x88888888 0x88888888 0xFEDCBA98 0x76543210
449 * 3 HDMI-VIDEO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
450 * 4 HDMI-ADUIO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
451 * 5 USB-HOST 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
452 * 6 ETHERNET 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
453 * 7 SDIO 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
454 * 8 GPU 0x77777777 0x77777777 0xFEDCBA98 0x76543210
455 * 9 DMAC (port #1) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
456 * 10 DMAC (port #2) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
457 * 11 DVFS 0x00000000 0x60000000 0x00000000 0x00000000
459 * Please read ARC HS Development IC Specification, section 17.2 for more
460 * information about apertures configuration.
461 * NOTE: we intentionally modify default settings in U-boot. Default settings
462 * are specified in "Table 111 CREG Address Decoder register reset values".
465 #define CREG_AXI_M_SLV0(m) ((void __iomem *)(CREG_BASE + 0x020 * (m)))
466 #define CREG_AXI_M_SLV1(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x004))
467 #define CREG_AXI_M_OFT0(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x008))
468 #define CREG_AXI_M_OFT1(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x00C))
469 #define CREG_AXI_M_UPDT(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x014))
471 #define CREG_AXI_M_HS_CORE_BOOT ((void __iomem *)(CREG_BASE + 0x010))
473 #define CREG_PAE ((void __iomem *)(CREG_BASE + 0x180))
474 #define CREG_PAE_UPDT ((void __iomem *)(CREG_BASE + 0x194))
476 void init_memory_bridge(void)
481 * M_HS_CORE has one unic register - BOOT.
482 * We need to clean boot mirror (BOOT[1:0]) bits in them.
484 reg = readl(CREG_AXI_M_HS_CORE_BOOT) & (~0x3);
485 writel(reg, CREG_AXI_M_HS_CORE_BOOT);
486 writel(0x11111111, CREG_AXI_M_SLV0(M_HS_CORE));
487 writel(0x63111111, CREG_AXI_M_SLV1(M_HS_CORE));
488 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HS_CORE));
489 writel(0x0E543210, CREG_AXI_M_OFT1(M_HS_CORE));
490 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HS_CORE));
492 writel(0x77777777, CREG_AXI_M_SLV0(M_HS_RTT));
493 writel(0x77777777, CREG_AXI_M_SLV1(M_HS_RTT));
494 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HS_RTT));
495 writel(0x76543210, CREG_AXI_M_OFT1(M_HS_RTT));
496 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HS_RTT));
498 writel(0x88888888, CREG_AXI_M_SLV0(M_AXI_TUN));
499 writel(0x88888888, CREG_AXI_M_SLV1(M_AXI_TUN));
500 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_AXI_TUN));
501 writel(0x76543210, CREG_AXI_M_OFT1(M_AXI_TUN));
502 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_AXI_TUN));
504 writel(0x77777777, CREG_AXI_M_SLV0(M_HDMI_VIDEO));
505 writel(0x77777777, CREG_AXI_M_SLV1(M_HDMI_VIDEO));
506 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HDMI_VIDEO));
507 writel(0x76543210, CREG_AXI_M_OFT1(M_HDMI_VIDEO));
508 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HDMI_VIDEO));
510 writel(0x77777777, CREG_AXI_M_SLV0(M_HDMI_AUDIO));
511 writel(0x77777777, CREG_AXI_M_SLV1(M_HDMI_AUDIO));
512 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HDMI_AUDIO));
513 writel(0x76543210, CREG_AXI_M_OFT1(M_HDMI_AUDIO));
514 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HDMI_AUDIO));
516 writel(0x77777777, CREG_AXI_M_SLV0(M_USB_HOST));
517 writel(0x77999999, CREG_AXI_M_SLV1(M_USB_HOST));
518 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_USB_HOST));
519 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_USB_HOST));
520 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_USB_HOST));
522 writel(0x77777777, CREG_AXI_M_SLV0(M_ETHERNET));
523 writel(0x77999999, CREG_AXI_M_SLV1(M_ETHERNET));
524 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_ETHERNET));
525 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_ETHERNET));
526 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_ETHERNET));
528 writel(0x77777777, CREG_AXI_M_SLV0(M_SDIO));
529 writel(0x77999999, CREG_AXI_M_SLV1(M_SDIO));
530 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_SDIO));
531 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_SDIO));
532 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_SDIO));
534 writel(0x77777777, CREG_AXI_M_SLV0(M_GPU));
535 writel(0x77777777, CREG_AXI_M_SLV1(M_GPU));
536 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_GPU));
537 writel(0x76543210, CREG_AXI_M_OFT1(M_GPU));
538 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_GPU));
540 writel(0x77777777, CREG_AXI_M_SLV0(M_DMAC_0));
541 writel(0x77777777, CREG_AXI_M_SLV1(M_DMAC_0));
542 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_DMAC_0));
543 writel(0x76543210, CREG_AXI_M_OFT1(M_DMAC_0));
544 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_DMAC_0));
546 writel(0x77777777, CREG_AXI_M_SLV0(M_DMAC_1));
547 writel(0x77777777, CREG_AXI_M_SLV1(M_DMAC_1));
548 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_DMAC_1));
549 writel(0x76543210, CREG_AXI_M_OFT1(M_DMAC_1));
550 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_DMAC_1));
552 writel(0x00000000, CREG_AXI_M_SLV0(M_DVFS));
553 writel(0x60000000, CREG_AXI_M_SLV1(M_DVFS));
554 writel(0x00000000, CREG_AXI_M_OFT0(M_DVFS));
555 writel(0x00000000, CREG_AXI_M_OFT1(M_DVFS));
556 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_DVFS));
558 writel(0x00000000, CREG_PAE);
559 writel(UPDATE_VAL, CREG_PAE_UPDT);
562 static void setup_clocks(void)
566 /* Setup CPU clock */
567 if (env_common.cpu_freq.set) {
568 rate = env_common.cpu_freq.val;
569 soc_clk_ctl("cpu-clk", &rate, CLK_ON | CLK_SET | CLK_MHZ);
572 /* Setup TUN clock */
573 if (env_common.tun_freq.set) {
574 rate = env_common.tun_freq.val;
576 soc_clk_ctl("tun-clk", &rate, CLK_ON | CLK_SET | CLK_MHZ);
578 soc_clk_ctl("tun-clk", NULL, CLK_OFF);
581 if (env_common.axi_freq.set) {
582 rate = env_common.axi_freq.val;
583 soc_clk_ctl("axi-clk", &rate, CLK_SET | CLK_ON | CLK_MHZ);
587 static void do_init_cluster(void)
590 * A multi-core ARC HS configuration always includes only one
591 * ARC_AUX_NON_VOLATILE_LIMIT register, which is shared by all the
594 init_cluster_nvlim();
597 static int check_master_cpu_id(void)
599 if (CPU_ID_GET() == MASTER_CPU_ID)
602 pr_err("u-boot runs on non-master cpu with id: %lu\n", CPU_ID_GET());
607 static noinline int prepare_cpus(void)
611 ret = check_master_cpu_id();
615 ret = envs_process_and_validate(env_map_common, env_map_core, is_cpu_used);
619 printf("CPU start mask is %#x\n", env_common.core_mask.val);
621 do_init_slave_cpus();
622 do_init_master_cpu();
628 static int hsdk_go_run(u32 cpu_start_reg)
630 /* Cleanup caches, disable interrupts */
633 if (env_common.halt_on_boot)
637 * 3 NOPs after FLAG 1 instruction are no longer required for ARCv2
638 * cores but we leave them for gebug purposes.
644 /* Kick chosen slave CPUs */
645 writel(cpu_start_reg, (void __iomem *)CREG_CPU_START);
647 if (is_cpu_used(MASTER_CPU_ID))
648 ((void (*)(void))(env_core.entry[MASTER_CPU_ID].val))();
652 pr_err("u-boot still runs on cpu [%ld]\n", CPU_ID_GET());
655 * We will never return after executing our program if master cpu used
656 * otherwise halt master cpu manually.
664 int board_prep_linux(bootm_headers_t *images)
669 ret = envs_read_validate_common(env_map_mask);
673 /* Rollback to default values */
674 if (!env_common.core_mask.set) {
675 env_common.core_mask.val = ALL_CPU_MASK;
676 env_common.core_mask.set = true;
679 printf("CPU start mask is %#x\n", env_common.core_mask.val);
681 if (!is_cpu_used(MASTER_CPU_ID))
682 pr_err("ERR: try to launch linux with CPU[0] disabled! It doesn't work for ARC.\n");
685 * If we want to launch linux on all CPUs we don't need to patch
686 * linux DTB as it is default configuration
688 if (env_common.core_mask.val == ALL_CPU_MASK)
691 if (!IMAGE_ENABLE_OF_LIBFDT || !images->ft_len) {
692 pr_err("WARN: core_mask setup will work properly only with external DTB!\n");
696 /* patch '/possible-cpus' property according to cpu mask */
697 ofst = fdt_path_offset(images->ft_addr, "/");
698 sprintf(mask, "%s%s%s%s",
699 is_cpu_used(0) ? "0," : "",
700 is_cpu_used(1) ? "1," : "",
701 is_cpu_used(2) ? "2," : "",
702 is_cpu_used(3) ? "3," : "");
703 ret = fdt_setprop_string(images->ft_addr, ofst, "possible-cpus", mask);
705 * If we failed to patch '/possible-cpus' property we don't need break
706 * linux loading process: kernel will handle it but linux will print
707 * warning like "Timeout: CPU1 FAILED to comeup !!!".
708 * So warn here about error, but return 0 like no error had occurred.
711 pr_err("WARN: failed to patch '/possible-cpus' property, ret=%d\n",
717 void board_jump_and_run(ulong entry, int zero, int arch, uint params)
719 void (*kernel_entry)(int zero, int arch, uint params);
722 kernel_entry = (void (*)(int, int, uint))entry;
724 /* Prepare CREG_CPU_START for kicking chosen CPUs */
725 cpu_start_reg = prepare_cpu_ctart_reg();
727 /* In case of run without hsdk_init */
728 slave_cpu_set_boot_addr(entry);
730 /* In case of run with hsdk_init */
731 for (u32 i = 0; i < NR_CPUS; i++) {
732 env_core.entry[i].val = entry;
733 env_core.entry[i].set = true;
735 /* sync cross_cpu struct as we updated core-entry variables */
736 sync_cross_cpu_data();
738 /* Kick chosen slave CPUs */
739 writel(cpu_start_reg, (void __iomem *)CREG_CPU_START);
742 kernel_entry(zero, arch, params);
745 static int hsdk_go_prepare_and_run(void)
747 /* Prepare CREG_CPU_START for kicking chosen CPUs */
748 u32 reg = prepare_cpu_ctart_reg();
750 if (env_common.halt_on_boot)
751 printf("CPU will halt before application start, start application with debugger.\n");
753 return hsdk_go_run(reg);
756 static int do_hsdk_go(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
761 * Check for 'halt' parameter. 'halt' = enter halt-mode just before
762 * starting the application; can be used for debug.
765 env_common.halt_on_boot = !strcmp(argv[1], "halt");
766 if (!env_common.halt_on_boot) {
767 pr_err("Unrecognised parameter: \'%s\'\n", argv[1]);
768 return CMD_RET_FAILURE;
772 ret = check_master_cpu_id();
776 ret = envs_process_and_validate(env_map_mask, env_map_go, is_cpu_used);
780 /* sync cross_cpu struct as we updated core-entry variables */
781 sync_cross_cpu_data();
783 ret = hsdk_go_prepare_and_run();
785 return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
789 hsdk_go, 3, 0, do_hsdk_go,
790 "Synopsys HSDK specific command",
791 " - Boot stand-alone application on HSDK\n"
792 "hsdk_go halt - Boot stand-alone application on HSDK, halt CPU just before application run\n"
795 static int do_hsdk_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
797 static bool done = false;
800 /* hsdk_init can be run only once */
802 printf("HSDK HW is already initialized! Please reset the board if you want to change the configuration.\n");
803 return CMD_RET_FAILURE;
806 ret = prepare_cpus();
810 return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
814 hsdk_init, 1, 0, do_hsdk_init,
815 "Synopsys HSDK specific command",
819 static int do_hsdk_clock_set(cmd_tbl_t *cmdtp, int flag, int argc,
824 /* Strip off leading subcommand argument */
828 envs_cleanup_common(env_map_clock);
831 printf("Set clocks to values specified in environment\n");
832 ret = envs_read_common(env_map_clock);
834 printf("Set clocks to values specified in args\n");
835 ret = args_envs_enumerate(env_map_clock, 2, argc, argv);
839 return CMD_RET_FAILURE;
841 ret = envs_validate_common(env_map_clock);
843 return CMD_RET_FAILURE;
845 /* Setup clock tree HW */
848 return CMD_RET_SUCCESS;
851 static int do_hsdk_clock_get(cmd_tbl_t *cmdtp, int flag, int argc,
856 if (soc_clk_ctl("cpu-clk", &rate, CLK_GET | CLK_MHZ))
857 return CMD_RET_FAILURE;
859 if (env_set_ulong("cpu_freq", rate))
860 return CMD_RET_FAILURE;
862 if (soc_clk_ctl("tun-clk", &rate, CLK_GET | CLK_MHZ))
863 return CMD_RET_FAILURE;
865 if (env_set_ulong("tun_freq", rate))
866 return CMD_RET_FAILURE;
868 if (soc_clk_ctl("axi-clk", &rate, CLK_GET | CLK_MHZ))
869 return CMD_RET_FAILURE;
871 if (env_set_ulong("axi_freq", rate))
872 return CMD_RET_FAILURE;
874 printf("Clock values are saved to environment\n");
876 return CMD_RET_SUCCESS;
879 static int do_hsdk_clock_print(cmd_tbl_t *cmdtp, int flag, int argc,
883 soc_clk_ctl("cpu-clk", NULL, CLK_PRINT | CLK_MHZ);
884 soc_clk_ctl("tun-clk", NULL, CLK_PRINT | CLK_MHZ);
885 soc_clk_ctl("axi-clk", NULL, CLK_PRINT | CLK_MHZ);
886 soc_clk_ctl("ddr-clk", NULL, CLK_PRINT | CLK_MHZ);
888 return CMD_RET_SUCCESS;
891 static int do_hsdk_clock_print_all(cmd_tbl_t *cmdtp, int flag, int argc,
895 * NOTE: as of today we don't use some peripherals like HDMI / EBI
896 * so we don't want to print their clocks ("hdmi-sys-clk", "hdmi-pll",
897 * "hdmi-clk", "ebi-clk"). Nevertheless their clock subsystems is fully
898 * functional and we can print their clocks if it is required
901 /* CPU clock domain */
902 soc_clk_ctl("cpu-pll", NULL, CLK_PRINT | CLK_MHZ);
903 soc_clk_ctl("cpu-clk", NULL, CLK_PRINT | CLK_MHZ);
906 /* SYS clock domain */
907 soc_clk_ctl("sys-pll", NULL, CLK_PRINT | CLK_MHZ);
908 soc_clk_ctl("apb-clk", NULL, CLK_PRINT | CLK_MHZ);
909 soc_clk_ctl("axi-clk", NULL, CLK_PRINT | CLK_MHZ);
910 soc_clk_ctl("eth-clk", NULL, CLK_PRINT | CLK_MHZ);
911 soc_clk_ctl("usb-clk", NULL, CLK_PRINT | CLK_MHZ);
912 soc_clk_ctl("sdio-clk", NULL, CLK_PRINT | CLK_MHZ);
913 /* soc_clk_ctl("hdmi-sys-clk", NULL, CLK_PRINT | CLK_MHZ); */
914 soc_clk_ctl("gfx-core-clk", NULL, CLK_PRINT | CLK_MHZ);
915 soc_clk_ctl("gfx-dma-clk", NULL, CLK_PRINT | CLK_MHZ);
916 soc_clk_ctl("gfx-cfg-clk", NULL, CLK_PRINT | CLK_MHZ);
917 soc_clk_ctl("dmac-core-clk", NULL, CLK_PRINT | CLK_MHZ);
918 soc_clk_ctl("dmac-cfg-clk", NULL, CLK_PRINT | CLK_MHZ);
919 soc_clk_ctl("sdio-ref-clk", NULL, CLK_PRINT | CLK_MHZ);
920 soc_clk_ctl("spi-clk", NULL, CLK_PRINT | CLK_MHZ);
921 soc_clk_ctl("i2c-clk", NULL, CLK_PRINT | CLK_MHZ);
922 /* soc_clk_ctl("ebi-clk", NULL, CLK_PRINT | CLK_MHZ); */
923 soc_clk_ctl("uart-clk", NULL, CLK_PRINT | CLK_MHZ);
926 /* DDR clock domain */
927 soc_clk_ctl("ddr-clk", NULL, CLK_PRINT | CLK_MHZ);
930 /* HDMI clock domain */
931 /* soc_clk_ctl("hdmi-pll", NULL, CLK_PRINT | CLK_MHZ); */
932 /* soc_clk_ctl("hdmi-clk", NULL, CLK_PRINT | CLK_MHZ); */
935 /* TUN clock domain */
936 soc_clk_ctl("tun-pll", NULL, CLK_PRINT | CLK_MHZ);
937 soc_clk_ctl("tun-clk", NULL, CLK_PRINT | CLK_MHZ);
938 soc_clk_ctl("rom-clk", NULL, CLK_PRINT | CLK_MHZ);
939 soc_clk_ctl("pwm-clk", NULL, CLK_PRINT | CLK_MHZ);
942 return CMD_RET_SUCCESS;
945 cmd_tbl_t cmd_hsdk_clock[] = {
946 U_BOOT_CMD_MKENT(set, 3, 0, do_hsdk_clock_set, "", ""),
947 U_BOOT_CMD_MKENT(get, 3, 0, do_hsdk_clock_get, "", ""),
948 U_BOOT_CMD_MKENT(print, 4, 0, do_hsdk_clock_print, "", ""),
949 U_BOOT_CMD_MKENT(print_all, 4, 0, do_hsdk_clock_print_all, "", ""),
952 static int do_hsdk_clock(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
957 return CMD_RET_USAGE;
959 /* Strip off leading 'hsdk_clock' command argument */
963 c = find_cmd_tbl(argv[0], cmd_hsdk_clock, ARRAY_SIZE(cmd_hsdk_clock));
965 return CMD_RET_USAGE;
967 return c->cmd(cmdtp, flag, argc, argv);
971 hsdk_clock, CONFIG_SYS_MAXARGS, 0, do_hsdk_clock,
972 "Synopsys HSDK specific clock command",
973 "set - Set clock to values specified in environment / command line arguments\n"
974 "hsdk_clock get - Save clock values to environment\n"
975 "hsdk_clock print - Print main clock values to console\n"
976 "hsdk_clock print_all - Print all clock values to console\n"
980 int board_early_init_f(void)
983 * Setup AXI apertures unconditionally as we want to have DDR
984 * in 0x00000000 region when we are kicking slave cpus.
986 init_memory_bridge();
989 * Switch SDIO external ciu clock divider from default div-by-8 to
990 * minimum possible div-by-2.
992 writel(SDIO_UHS_REG_EXT_DIV_2, (void __iomem *)SDIO_UHS_REG_EXT);
997 int board_early_init_r(void)
1000 * TODO: Init USB here to be able read environment from USB MSD.
1001 * It can be done with usb_init() call. We can't do it right now
1002 * due to brocken USB IP SW reset and lack of USB IP HW reset in
1003 * linux kernel (if we init USB here we will break USB in linux)
1007 * Flush all d$ as we want to use uncached area with st.di / ld.di
1008 * instructions and we don't want to have any dirty line in L1d$ or SL$
1009 * in this area. It is enough to flush all d$ once here as we access to
1010 * uncached area with regular st (non .di) instruction only when we copy
1011 * data during u-boot relocation.
1015 printf("Relocation Offset is: %08lx\n", gd->reloc_off);
1020 int board_late_init(void)
1023 * Populate environment with clock frequency values -
1024 * run hsdk_clock get callback without uboot command run.
1026 do_hsdk_clock_get(NULL, 0, 0, NULL);
1031 int checkboard(void)
1033 puts("Board: Synopsys ARC HS Development Kit\n");