1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Synopsys, Inc. All rights reserved.
4 * Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
9 #include <linux/printk.h>
10 #include <linux/kernel.h>
12 #include <asm/arcregs.h>
13 #include <fdt_support.h>
21 DECLARE_GLOBAL_DATA_PTR;
23 #define ALL_CPU_MASK GENMASK(NR_CPUS - 1, 0)
24 #define MASTER_CPU_ID 0
25 #define APERTURE_SHIFT 28
27 #define SLAVE_CPU_READY 0x12345678
28 #define BOOTSTAGE_1 1 /* after SP, FP setup, before HW init */
29 #define BOOTSTAGE_2 2 /* after HW init, before self halt */
30 #define BOOTSTAGE_3 3 /* after self halt */
31 #define BOOTSTAGE_4 4 /* before app launch */
32 #define BOOTSTAGE_5 5 /* after app launch, unreachable */
34 #define RESET_VECTOR_ADDR 0x0
36 #define CREG_BASE (ARC_PERIPHERAL_BASE + 0x1000)
37 #define CREG_CPU_START (CREG_BASE + 0x400)
38 #define CREG_CPU_START_MASK 0xF
40 #define SDIO_BASE (ARC_PERIPHERAL_BASE + 0xA000)
41 #define SDIO_UHS_REG_EXT (SDIO_BASE + 0x108)
42 #define SDIO_UHS_REG_EXT_DIV_2 (2 << 30)
44 /* Uncached access macros */
45 #define arc_read_uncached_32(ptr) \
48 __asm__ __volatile__( \
49 " ld.di %0, [%1] \n" \
55 #define arc_write_uncached_32(ptr, data)\
57 __asm__ __volatile__( \
58 " st.di %0, [%1] \n" \
60 : "r"(data), "r"(ptr)); \
63 struct hsdk_env_core_ctl {
64 u32_env entry[NR_CPUS];
65 u32_env iccm[NR_CPUS];
66 u32_env dccm[NR_CPUS];
69 struct hsdk_env_common_ctl {
81 * Uncached cross-cpu structure. All CPUs must access to this structure fields
82 * only with arc_read_uncached_32() / arc_write_uncached_32() accessors (which
83 * implement ld.di / st.di instructions). Simultaneous cached and uncached
84 * access to this area will lead to data loss.
85 * We flush all data caches in board_early_init_r() as we don't want to have
86 * any dirty line in L1d$ or SL$ in this area.
88 struct hsdk_cross_cpu {
89 /* slave CPU ready flag */
91 /* address of the area, which can be used for stack by slave CPU */
93 /* slave CPU status - bootstage number */
97 * Slave CPU data - it is copy of corresponding fields in
98 * hsdk_env_core_ctl and hsdk_env_common_ctl structures which are
99 * required for slave CPUs initialization.
100 * This fields can be populated by copying from hsdk_env_core_ctl
101 * and hsdk_env_common_ctl structures with sync_cross_cpu_data()
112 u8 cache_padding[ARCH_DMA_MINALIGN];
113 } __aligned(ARCH_DMA_MINALIGN);
115 /* Place for slave CPUs temporary stack */
116 static u32 slave_stack[256 * NR_CPUS] __aligned(ARCH_DMA_MINALIGN);
118 static struct hsdk_env_common_ctl env_common = {};
119 static struct hsdk_env_core_ctl env_core = {};
120 static struct hsdk_cross_cpu cross_cpu_data;
122 static const struct env_map_common env_map_common[] = {
123 { "core_mask", ENV_HEX, true, 0x1, 0xF, &env_common.core_mask },
124 { "non_volatile_limit", ENV_HEX, true, 0, 0xF, &env_common.nvlim },
125 { "icache_ena", ENV_HEX, true, 0, 1, &env_common.icache },
126 { "dcache_ena", ENV_HEX, true, 0, 1, &env_common.dcache },
130 static const struct env_map_common env_map_clock[] = {
131 { "cpu_freq", ENV_DEC, false, 100, 1000, &env_common.cpu_freq },
132 { "axi_freq", ENV_DEC, false, 200, 800, &env_common.axi_freq },
133 { "tun_freq", ENV_DEC, false, 0, 150, &env_common.tun_freq },
137 static const struct env_map_percpu env_map_core[] = {
138 { "core_iccm", ENV_HEX, true, {NO_CCM, 0, NO_CCM, 0}, {NO_CCM, 0xF, NO_CCM, 0xF}, &env_core.iccm },
139 { "core_dccm", ENV_HEX, true, {NO_CCM, 0, NO_CCM, 0}, {NO_CCM, 0xF, NO_CCM, 0xF}, &env_core.dccm },
143 static const struct env_map_common env_map_mask[] = {
144 { "core_mask", ENV_HEX, false, 0x1, 0xF, &env_common.core_mask },
148 static const struct env_map_percpu env_map_go[] = {
149 { "core_entry", ENV_HEX, true, {0, 0, 0, 0}, {U32_MAX, U32_MAX, U32_MAX, U32_MAX}, &env_core.entry },
153 static void sync_cross_cpu_data(void)
157 for (u32 i = 0; i < NR_CPUS; i++) {
158 value = env_core.entry[i].val;
159 arc_write_uncached_32(&cross_cpu_data.entry[i], value);
162 for (u32 i = 0; i < NR_CPUS; i++) {
163 value = env_core.iccm[i].val;
164 arc_write_uncached_32(&cross_cpu_data.iccm[i], value);
167 for (u32 i = 0; i < NR_CPUS; i++) {
168 value = env_core.dccm[i].val;
169 arc_write_uncached_32(&cross_cpu_data.dccm[i], value);
172 value = env_common.core_mask.val;
173 arc_write_uncached_32(&cross_cpu_data.core_mask, value);
175 value = env_common.icache.val;
176 arc_write_uncached_32(&cross_cpu_data.icache, value);
178 value = env_common.dcache.val;
179 arc_write_uncached_32(&cross_cpu_data.dcache, value);
182 /* Can be used only on master CPU */
183 static bool is_cpu_used(u32 cpu_id)
185 return !!(env_common.core_mask.val & BIT(cpu_id));
188 /* TODO: add ICCM BCR and DCCM BCR runtime check */
189 static void init_slave_cpu_func(u32 core)
193 /* Remap ICCM to another memory region if it exists */
194 val = arc_read_uncached_32(&cross_cpu_data.iccm[core]);
196 write_aux_reg(ARC_AUX_ICCM_BASE, val << APERTURE_SHIFT);
198 /* Remap DCCM to another memory region if it exists */
199 val = arc_read_uncached_32(&cross_cpu_data.dccm[core]);
201 write_aux_reg(ARC_AUX_DCCM_BASE, val << APERTURE_SHIFT);
203 if (arc_read_uncached_32(&cross_cpu_data.icache))
208 if (arc_read_uncached_32(&cross_cpu_data.dcache))
214 static void init_cluster_nvlim(void)
216 u32 val = env_common.nvlim.val << APERTURE_SHIFT;
219 write_aux_reg(ARC_AUX_NON_VOLATILE_LIMIT, val);
220 write_aux_reg(AUX_AUX_CACHE_LIMIT, val);
221 flush_n_invalidate_dcache_all();
224 static void init_master_icache(void)
226 if (icache_status()) {
227 /* I$ is enabled - we need to disable it */
228 if (!env_common.icache.val)
231 /* I$ is disabled - we need to enable it */
232 if (env_common.icache.val) {
235 /* invalidate I$ right after enable */
236 invalidate_icache_all();
241 static void init_master_dcache(void)
243 if (dcache_status()) {
244 /* D$ is enabled - we need to disable it */
245 if (!env_common.dcache.val)
248 /* D$ is disabled - we need to enable it */
249 if (env_common.dcache.val)
252 /* TODO: probably we need ti invalidate D$ right after enable */
256 static int cleanup_before_go(void)
258 disable_interrupts();
259 sync_n_cleanup_cache_all();
264 void slave_cpu_set_boot_addr(u32 addr)
266 /* All cores have reset vector pointing to 0 */
267 writel(addr, (void __iomem *)RESET_VECTOR_ADDR);
269 /* Make sure other cores see written value in memory */
270 sync_n_cleanup_cache_all();
273 static inline void halt_this_cpu(void)
275 __builtin_arc_flag(1);
278 static void smp_kick_cpu_x(u32 cpu_id)
280 int cmd = readl((void __iomem *)CREG_CPU_START);
282 if (cpu_id > NR_CPUS)
285 cmd &= ~CREG_CPU_START_MASK;
286 cmd |= (1 << cpu_id);
287 writel(cmd, (void __iomem *)CREG_CPU_START);
290 static u32 prepare_cpu_ctart_reg(void)
292 int cmd = readl((void __iomem *)CREG_CPU_START);
294 cmd &= ~CREG_CPU_START_MASK;
296 return cmd | env_common.core_mask.val;
299 /* slave CPU entry for configuration */
300 __attribute__((naked, noreturn, flatten)) noinline void hsdk_core_init_f(void)
302 __asm__ __volatile__(
307 : "r" (&cross_cpu_data.stack_ptr));
309 invalidate_icache_all();
311 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_1);
312 init_slave_cpu_func(CPU_ID_GET());
314 arc_write_uncached_32(&cross_cpu_data.ready_flag, SLAVE_CPU_READY);
315 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_2);
317 /* Halt the processor until the master kick us again */
321 * 3 NOPs after FLAG 1 instruction are no longer required for ARCv2
322 * cores but we leave them for gebug purposes.
328 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_3);
330 /* get the updated entry - invalidate i$ */
331 invalidate_icache_all();
333 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_4);
335 /* Run our program */
336 ((void (*)(void))(arc_read_uncached_32(&cross_cpu_data.entry[CPU_ID_GET()])))();
338 /* This bootstage is unreachable as we don't return from app we launch */
339 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_5);
341 /* Something went terribly wrong */
346 static void clear_cross_cpu_data(void)
348 arc_write_uncached_32(&cross_cpu_data.ready_flag, 0);
349 arc_write_uncached_32(&cross_cpu_data.stack_ptr, 0);
351 for (u32 i = 0; i < NR_CPUS; i++)
352 arc_write_uncached_32(&cross_cpu_data.status[i], 0);
355 static noinline void do_init_slave_cpu(u32 cpu_id)
357 /* attempts number for check clave CPU ready_flag */
359 u32 stack_ptr = (u32)(slave_stack + (64 * cpu_id));
361 if (cpu_id >= NR_CPUS)
364 arc_write_uncached_32(&cross_cpu_data.ready_flag, 0);
366 /* Use global unique place for each slave cpu stack */
367 arc_write_uncached_32(&cross_cpu_data.stack_ptr, stack_ptr);
369 debug("CPU %u: stack pool base: %p\n", cpu_id, slave_stack);
370 debug("CPU %u: current slave stack base: %x\n", cpu_id, stack_ptr);
371 slave_cpu_set_boot_addr((u32)hsdk_core_init_f);
373 smp_kick_cpu_x(cpu_id);
375 debug("CPU %u: cross-cpu flag: %x [before timeout]\n", cpu_id,
376 arc_read_uncached_32(&cross_cpu_data.ready_flag));
378 while (!arc_read_uncached_32(&cross_cpu_data.ready_flag) && attempts--)
381 /* Just to be sure that slave cpu is halted after it set ready_flag */
385 * Only print error here if we reach timeout as there is no option to
386 * halt slave cpu (or check that slave cpu is halted)
389 pr_err("CPU %u is not responding after init!\n", cpu_id);
391 /* Check current stage of slave cpu */
392 if (arc_read_uncached_32(&cross_cpu_data.status[cpu_id]) != BOOTSTAGE_2)
393 pr_err("CPU %u status is unexpected: %d\n", cpu_id,
394 arc_read_uncached_32(&cross_cpu_data.status[cpu_id]));
396 debug("CPU %u: cross-cpu flag: %x [after timeout]\n", cpu_id,
397 arc_read_uncached_32(&cross_cpu_data.ready_flag));
398 debug("CPU %u: status: %d [after timeout]\n", cpu_id,
399 arc_read_uncached_32(&cross_cpu_data.status[cpu_id]));
402 static void do_init_slave_cpus(void)
404 clear_cross_cpu_data();
405 sync_cross_cpu_data();
407 debug("cross_cpu_data location: %#x\n", (u32)&cross_cpu_data);
409 for (u32 i = MASTER_CPU_ID + 1; i < NR_CPUS; i++)
411 do_init_slave_cpu(i);
414 static void do_init_master_cpu(void)
417 * Setup master caches even if master isn't used as we want to use
418 * same cache configuration on all running CPUs
420 init_master_icache();
421 init_master_dcache();
424 enum hsdk_axi_masters {
442 * m master AXI_M_m_SLV0 AXI_M_m_SLV1 AXI_M_m_OFFSET0 AXI_M_m_OFFSET1
443 * 0 HS (CBU) 0x11111111 0x63111111 0xFEDCBA98 0x0E543210
444 * 1 HS (RTT) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
445 * 2 AXI Tunnel 0x88888888 0x88888888 0xFEDCBA98 0x76543210
446 * 3 HDMI-VIDEO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
447 * 4 HDMI-ADUIO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
448 * 5 USB-HOST 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
449 * 6 ETHERNET 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
450 * 7 SDIO 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
451 * 8 GPU 0x77777777 0x77777777 0xFEDCBA98 0x76543210
452 * 9 DMAC (port #1) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
453 * 10 DMAC (port #2) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
454 * 11 DVFS 0x00000000 0x60000000 0x00000000 0x00000000
456 * Please read ARC HS Development IC Specification, section 17.2 for more
457 * information about apertures configuration.
458 * NOTE: we intentionally modify default settings in U-boot. Default settings
459 * are specified in "Table 111 CREG Address Decoder register reset values".
462 #define CREG_AXI_M_SLV0(m) ((void __iomem *)(CREG_BASE + 0x020 * (m)))
463 #define CREG_AXI_M_SLV1(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x004))
464 #define CREG_AXI_M_OFT0(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x008))
465 #define CREG_AXI_M_OFT1(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x00C))
466 #define CREG_AXI_M_UPDT(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x014))
468 #define CREG_AXI_M_HS_CORE_BOOT ((void __iomem *)(CREG_BASE + 0x010))
470 #define CREG_PAE ((void __iomem *)(CREG_BASE + 0x180))
471 #define CREG_PAE_UPDT ((void __iomem *)(CREG_BASE + 0x194))
473 void init_memory_bridge(void)
478 * M_HS_CORE has one unic register - BOOT.
479 * We need to clean boot mirror (BOOT[1:0]) bits in them.
481 reg = readl(CREG_AXI_M_HS_CORE_BOOT) & (~0x3);
482 writel(reg, CREG_AXI_M_HS_CORE_BOOT);
483 writel(0x11111111, CREG_AXI_M_SLV0(M_HS_CORE));
484 writel(0x63111111, CREG_AXI_M_SLV1(M_HS_CORE));
485 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HS_CORE));
486 writel(0x0E543210, CREG_AXI_M_OFT1(M_HS_CORE));
487 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HS_CORE));
489 writel(0x77777777, CREG_AXI_M_SLV0(M_HS_RTT));
490 writel(0x77777777, CREG_AXI_M_SLV1(M_HS_RTT));
491 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HS_RTT));
492 writel(0x76543210, CREG_AXI_M_OFT1(M_HS_RTT));
493 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HS_RTT));
495 writel(0x88888888, CREG_AXI_M_SLV0(M_AXI_TUN));
496 writel(0x88888888, CREG_AXI_M_SLV1(M_AXI_TUN));
497 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_AXI_TUN));
498 writel(0x76543210, CREG_AXI_M_OFT1(M_AXI_TUN));
499 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_AXI_TUN));
501 writel(0x77777777, CREG_AXI_M_SLV0(M_HDMI_VIDEO));
502 writel(0x77777777, CREG_AXI_M_SLV1(M_HDMI_VIDEO));
503 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HDMI_VIDEO));
504 writel(0x76543210, CREG_AXI_M_OFT1(M_HDMI_VIDEO));
505 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HDMI_VIDEO));
507 writel(0x77777777, CREG_AXI_M_SLV0(M_HDMI_AUDIO));
508 writel(0x77777777, CREG_AXI_M_SLV1(M_HDMI_AUDIO));
509 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HDMI_AUDIO));
510 writel(0x76543210, CREG_AXI_M_OFT1(M_HDMI_AUDIO));
511 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HDMI_AUDIO));
513 writel(0x77777777, CREG_AXI_M_SLV0(M_USB_HOST));
514 writel(0x77999999, CREG_AXI_M_SLV1(M_USB_HOST));
515 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_USB_HOST));
516 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_USB_HOST));
517 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_USB_HOST));
519 writel(0x77777777, CREG_AXI_M_SLV0(M_ETHERNET));
520 writel(0x77999999, CREG_AXI_M_SLV1(M_ETHERNET));
521 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_ETHERNET));
522 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_ETHERNET));
523 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_ETHERNET));
525 writel(0x77777777, CREG_AXI_M_SLV0(M_SDIO));
526 writel(0x77999999, CREG_AXI_M_SLV1(M_SDIO));
527 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_SDIO));
528 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_SDIO));
529 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_SDIO));
531 writel(0x77777777, CREG_AXI_M_SLV0(M_GPU));
532 writel(0x77777777, CREG_AXI_M_SLV1(M_GPU));
533 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_GPU));
534 writel(0x76543210, CREG_AXI_M_OFT1(M_GPU));
535 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_GPU));
537 writel(0x77777777, CREG_AXI_M_SLV0(M_DMAC_0));
538 writel(0x77777777, CREG_AXI_M_SLV1(M_DMAC_0));
539 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_DMAC_0));
540 writel(0x76543210, CREG_AXI_M_OFT1(M_DMAC_0));
541 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_DMAC_0));
543 writel(0x77777777, CREG_AXI_M_SLV0(M_DMAC_1));
544 writel(0x77777777, CREG_AXI_M_SLV1(M_DMAC_1));
545 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_DMAC_1));
546 writel(0x76543210, CREG_AXI_M_OFT1(M_DMAC_1));
547 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_DMAC_1));
549 writel(0x00000000, CREG_AXI_M_SLV0(M_DVFS));
550 writel(0x60000000, CREG_AXI_M_SLV1(M_DVFS));
551 writel(0x00000000, CREG_AXI_M_OFT0(M_DVFS));
552 writel(0x00000000, CREG_AXI_M_OFT1(M_DVFS));
553 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_DVFS));
555 writel(0x00000000, CREG_PAE);
556 writel(UPDATE_VAL, CREG_PAE_UPDT);
559 static void setup_clocks(void)
563 /* Setup CPU clock */
564 if (env_common.cpu_freq.set) {
565 rate = env_common.cpu_freq.val;
566 soc_clk_ctl("cpu-clk", &rate, CLK_ON | CLK_SET | CLK_MHZ);
569 /* Setup TUN clock */
570 if (env_common.tun_freq.set) {
571 rate = env_common.tun_freq.val;
573 soc_clk_ctl("tun-clk", &rate, CLK_ON | CLK_SET | CLK_MHZ);
575 soc_clk_ctl("tun-clk", NULL, CLK_OFF);
578 if (env_common.axi_freq.set) {
579 rate = env_common.axi_freq.val;
580 soc_clk_ctl("axi-clk", &rate, CLK_SET | CLK_ON | CLK_MHZ);
584 static void do_init_cluster(void)
587 * A multi-core ARC HS configuration always includes only one
588 * ARC_AUX_NON_VOLATILE_LIMIT register, which is shared by all the
591 init_cluster_nvlim();
594 static int check_master_cpu_id(void)
596 if (CPU_ID_GET() == MASTER_CPU_ID)
599 pr_err("u-boot runs on non-master cpu with id: %lu\n", CPU_ID_GET());
604 static noinline int prepare_cpus(void)
608 ret = check_master_cpu_id();
612 ret = envs_process_and_validate(env_map_common, env_map_core, is_cpu_used);
616 printf("CPU start mask is %#x\n", env_common.core_mask.val);
618 do_init_slave_cpus();
619 do_init_master_cpu();
625 static int hsdk_go_run(u32 cpu_start_reg)
627 /* Cleanup caches, disable interrupts */
630 if (env_common.halt_on_boot)
634 * 3 NOPs after FLAG 1 instruction are no longer required for ARCv2
635 * cores but we leave them for gebug purposes.
641 /* Kick chosen slave CPUs */
642 writel(cpu_start_reg, (void __iomem *)CREG_CPU_START);
644 if (is_cpu_used(MASTER_CPU_ID))
645 ((void (*)(void))(env_core.entry[MASTER_CPU_ID].val))();
649 pr_err("u-boot still runs on cpu [%ld]\n", CPU_ID_GET());
652 * We will never return after executing our program if master cpu used
653 * otherwise halt master cpu manually.
661 int board_prep_linux(bootm_headers_t *images)
666 ret = envs_read_validate_common(env_map_mask);
670 /* Rollback to default values */
671 if (!env_common.core_mask.set) {
672 env_common.core_mask.val = ALL_CPU_MASK;
673 env_common.core_mask.set = true;
676 printf("CPU start mask is %#x\n", env_common.core_mask.val);
678 if (!is_cpu_used(MASTER_CPU_ID))
679 pr_err("ERR: try to launch linux with CPU[0] disabled! It doesn't work for ARC.\n");
682 * If we want to launch linux on all CPUs we don't need to patch
683 * linux DTB as it is default configuration
685 if (env_common.core_mask.val == ALL_CPU_MASK)
688 if (!IMAGE_ENABLE_OF_LIBFDT || !images->ft_len) {
689 pr_err("WARN: core_mask setup will work properly only with external DTB!\n");
693 /* patch '/possible-cpus' property according to cpu mask */
694 ofst = fdt_path_offset(images->ft_addr, "/");
695 sprintf(mask, "%s%s%s%s",
696 is_cpu_used(0) ? "0," : "",
697 is_cpu_used(1) ? "1," : "",
698 is_cpu_used(2) ? "2," : "",
699 is_cpu_used(3) ? "3," : "");
700 ret = fdt_setprop_string(images->ft_addr, ofst, "possible-cpus", mask);
702 * If we failed to patch '/possible-cpus' property we don't need break
703 * linux loading process: kernel will handle it but linux will print
704 * warning like "Timeout: CPU1 FAILED to comeup !!!".
705 * So warn here about error, but return 0 like no error had occurred.
708 pr_err("WARN: failed to patch '/possible-cpus' property, ret=%d\n",
714 void board_jump_and_run(ulong entry, int zero, int arch, uint params)
716 void (*kernel_entry)(int zero, int arch, uint params);
719 kernel_entry = (void (*)(int, int, uint))entry;
721 /* Prepare CREG_CPU_START for kicking chosen CPUs */
722 cpu_start_reg = prepare_cpu_ctart_reg();
724 /* In case of run without hsdk_init */
725 slave_cpu_set_boot_addr(entry);
727 /* In case of run with hsdk_init */
728 for (u32 i = 0; i < NR_CPUS; i++) {
729 env_core.entry[i].val = entry;
730 env_core.entry[i].set = true;
732 /* sync cross_cpu struct as we updated core-entry variables */
733 sync_cross_cpu_data();
735 /* Kick chosen slave CPUs */
736 writel(cpu_start_reg, (void __iomem *)CREG_CPU_START);
739 kernel_entry(zero, arch, params);
742 static int hsdk_go_prepare_and_run(void)
744 /* Prepare CREG_CPU_START for kicking chosen CPUs */
745 u32 reg = prepare_cpu_ctart_reg();
747 if (env_common.halt_on_boot)
748 printf("CPU will halt before application start, start application with debugger.\n");
750 return hsdk_go_run(reg);
753 static int do_hsdk_go(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
758 * Check for 'halt' parameter. 'halt' = enter halt-mode just before
759 * starting the application; can be used for debug.
762 env_common.halt_on_boot = !strcmp(argv[1], "halt");
763 if (!env_common.halt_on_boot) {
764 pr_err("Unrecognised parameter: \'%s\'\n", argv[1]);
765 return CMD_RET_FAILURE;
769 ret = check_master_cpu_id();
773 ret = envs_process_and_validate(env_map_mask, env_map_go, is_cpu_used);
777 /* sync cross_cpu struct as we updated core-entry variables */
778 sync_cross_cpu_data();
780 ret = hsdk_go_prepare_and_run();
782 return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
786 hsdk_go, 3, 0, do_hsdk_go,
787 "Synopsys HSDK specific command",
788 " - Boot stand-alone application on HSDK\n"
789 "hsdk_go halt - Boot stand-alone application on HSDK, halt CPU just before application run\n"
792 static int do_hsdk_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
794 static bool done = false;
797 /* hsdk_init can be run only once */
799 printf("HSDK HW is already initialized! Please reset the board if you want to change the configuration.\n");
800 return CMD_RET_FAILURE;
803 ret = prepare_cpus();
807 return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
811 hsdk_init, 1, 0, do_hsdk_init,
812 "Synopsys HSDK specific command",
816 static int do_hsdk_clock_set(cmd_tbl_t *cmdtp, int flag, int argc,
821 /* Strip off leading subcommand argument */
825 envs_cleanup_common(env_map_clock);
828 printf("Set clocks to values specified in environment\n");
829 ret = envs_read_common(env_map_clock);
831 printf("Set clocks to values specified in args\n");
832 ret = args_envs_enumerate(env_map_clock, 2, argc, argv);
836 return CMD_RET_FAILURE;
838 ret = envs_validate_common(env_map_clock);
840 return CMD_RET_FAILURE;
842 /* Setup clock tree HW */
845 return CMD_RET_SUCCESS;
848 static int do_hsdk_clock_get(cmd_tbl_t *cmdtp, int flag, int argc,
853 if (soc_clk_ctl("cpu-clk", &rate, CLK_GET | CLK_MHZ))
854 return CMD_RET_FAILURE;
856 if (env_set_ulong("cpu_freq", rate))
857 return CMD_RET_FAILURE;
859 if (soc_clk_ctl("tun-clk", &rate, CLK_GET | CLK_MHZ))
860 return CMD_RET_FAILURE;
862 if (env_set_ulong("tun_freq", rate))
863 return CMD_RET_FAILURE;
865 if (soc_clk_ctl("axi-clk", &rate, CLK_GET | CLK_MHZ))
866 return CMD_RET_FAILURE;
868 if (env_set_ulong("axi_freq", rate))
869 return CMD_RET_FAILURE;
871 printf("Clock values are saved to environment\n");
873 return CMD_RET_SUCCESS;
876 static int do_hsdk_clock_print(cmd_tbl_t *cmdtp, int flag, int argc,
880 soc_clk_ctl("cpu-clk", NULL, CLK_PRINT | CLK_MHZ);
881 soc_clk_ctl("tun-clk", NULL, CLK_PRINT | CLK_MHZ);
882 soc_clk_ctl("axi-clk", NULL, CLK_PRINT | CLK_MHZ);
883 soc_clk_ctl("ddr-clk", NULL, CLK_PRINT | CLK_MHZ);
885 return CMD_RET_SUCCESS;
888 static int do_hsdk_clock_print_all(cmd_tbl_t *cmdtp, int flag, int argc,
892 * NOTE: as of today we don't use some peripherals like HDMI / EBI
893 * so we don't want to print their clocks ("hdmi-sys-clk", "hdmi-pll",
894 * "hdmi-clk", "ebi-clk"). Nevertheless their clock subsystems is fully
895 * functional and we can print their clocks if it is required
898 /* CPU clock domain */
899 soc_clk_ctl("cpu-pll", NULL, CLK_PRINT | CLK_MHZ);
900 soc_clk_ctl("cpu-clk", NULL, CLK_PRINT | CLK_MHZ);
903 /* SYS clock domain */
904 soc_clk_ctl("sys-pll", NULL, CLK_PRINT | CLK_MHZ);
905 soc_clk_ctl("apb-clk", NULL, CLK_PRINT | CLK_MHZ);
906 soc_clk_ctl("axi-clk", NULL, CLK_PRINT | CLK_MHZ);
907 soc_clk_ctl("eth-clk", NULL, CLK_PRINT | CLK_MHZ);
908 soc_clk_ctl("usb-clk", NULL, CLK_PRINT | CLK_MHZ);
909 soc_clk_ctl("sdio-clk", NULL, CLK_PRINT | CLK_MHZ);
910 /* soc_clk_ctl("hdmi-sys-clk", NULL, CLK_PRINT | CLK_MHZ); */
911 soc_clk_ctl("gfx-core-clk", NULL, CLK_PRINT | CLK_MHZ);
912 soc_clk_ctl("gfx-dma-clk", NULL, CLK_PRINT | CLK_MHZ);
913 soc_clk_ctl("gfx-cfg-clk", NULL, CLK_PRINT | CLK_MHZ);
914 soc_clk_ctl("dmac-core-clk", NULL, CLK_PRINT | CLK_MHZ);
915 soc_clk_ctl("dmac-cfg-clk", NULL, CLK_PRINT | CLK_MHZ);
916 soc_clk_ctl("sdio-ref-clk", NULL, CLK_PRINT | CLK_MHZ);
917 soc_clk_ctl("spi-clk", NULL, CLK_PRINT | CLK_MHZ);
918 soc_clk_ctl("i2c-clk", NULL, CLK_PRINT | CLK_MHZ);
919 /* soc_clk_ctl("ebi-clk", NULL, CLK_PRINT | CLK_MHZ); */
920 soc_clk_ctl("uart-clk", NULL, CLK_PRINT | CLK_MHZ);
923 /* DDR clock domain */
924 soc_clk_ctl("ddr-clk", NULL, CLK_PRINT | CLK_MHZ);
927 /* HDMI clock domain */
928 /* soc_clk_ctl("hdmi-pll", NULL, CLK_PRINT | CLK_MHZ); */
929 /* soc_clk_ctl("hdmi-clk", NULL, CLK_PRINT | CLK_MHZ); */
932 /* TUN clock domain */
933 soc_clk_ctl("tun-pll", NULL, CLK_PRINT | CLK_MHZ);
934 soc_clk_ctl("tun-clk", NULL, CLK_PRINT | CLK_MHZ);
935 soc_clk_ctl("rom-clk", NULL, CLK_PRINT | CLK_MHZ);
936 soc_clk_ctl("pwm-clk", NULL, CLK_PRINT | CLK_MHZ);
939 return CMD_RET_SUCCESS;
942 cmd_tbl_t cmd_hsdk_clock[] = {
943 U_BOOT_CMD_MKENT(set, 3, 0, do_hsdk_clock_set, "", ""),
944 U_BOOT_CMD_MKENT(get, 3, 0, do_hsdk_clock_get, "", ""),
945 U_BOOT_CMD_MKENT(print, 4, 0, do_hsdk_clock_print, "", ""),
946 U_BOOT_CMD_MKENT(print_all, 4, 0, do_hsdk_clock_print_all, "", ""),
949 static int do_hsdk_clock(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
954 return CMD_RET_USAGE;
956 /* Strip off leading 'hsdk_clock' command argument */
960 c = find_cmd_tbl(argv[0], cmd_hsdk_clock, ARRAY_SIZE(cmd_hsdk_clock));
962 return CMD_RET_USAGE;
964 return c->cmd(cmdtp, flag, argc, argv);
968 hsdk_clock, CONFIG_SYS_MAXARGS, 0, do_hsdk_clock,
969 "Synopsys HSDK specific clock command",
970 "set - Set clock to values specified in environment / command line arguments\n"
971 "hsdk_clock get - Save clock values to environment\n"
972 "hsdk_clock print - Print main clock values to console\n"
973 "hsdk_clock print_all - Print all clock values to console\n"
977 int board_early_init_f(void)
980 * Setup AXI apertures unconditionally as we want to have DDR
981 * in 0x00000000 region when we are kicking slave cpus.
983 init_memory_bridge();
988 int board_early_init_r(void)
991 * TODO: Init USB here to be able read environment from USB MSD.
992 * It can be done with usb_init() call. We can't do it right now
993 * due to brocken USB IP SW reset and lack of USB IP HW reset in
994 * linux kernel (if we init USB here we will break USB in linux)
998 * Flush all d$ as we want to use uncached area with st.di / ld.di
999 * instructions and we don't want to have any dirty line in L1d$ or SL$
1000 * in this area. It is enough to flush all d$ once here as we access to
1001 * uncached area with regular st (non .di) instruction only when we copy
1002 * data during u-boot relocation.
1006 printf("Relocation Offset is: %08lx\n", gd->reloc_off);
1011 int board_late_init(void)
1014 * Populate environment with clock frequency values -
1015 * run hsdk_clock get callback without uboot command run.
1017 do_hsdk_clock_get(NULL, 0, 0, NULL);
1022 int board_mmc_init(bd_t *bis)
1024 struct dwmci_host *host = NULL;
1026 host = malloc(sizeof(struct dwmci_host));
1028 printf("dwmci_host malloc fail!\n");
1033 * Switch SDIO external ciu clock divider from default div-by-8 to
1034 * minimum possible div-by-2.
1036 writel(SDIO_UHS_REG_EXT_DIV_2, (void __iomem *)SDIO_UHS_REG_EXT);
1038 memset(host, 0, sizeof(struct dwmci_host));
1039 host->name = "Synopsys Mobile storage";
1040 host->ioaddr = (void *)ARC_DWMMC_BASE;
1042 host->dev_index = 0;
1043 host->bus_hz = 50000000;
1045 add_dwmci(host, host->bus_hz / 2, 400000);