1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Synopsys, Inc. All rights reserved.
4 * Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
13 #include <linux/printk.h>
14 #include <linux/kernel.h>
16 #include <asm/arcregs.h>
17 #include <fdt_support.h>
25 DECLARE_GLOBAL_DATA_PTR;
27 #define ALL_CPU_MASK GENMASK(NR_CPUS - 1, 0)
28 #define MASTER_CPU_ID 0
29 #define APERTURE_SHIFT 28
31 #define SLAVE_CPU_READY 0x12345678
32 #define BOOTSTAGE_1 1 /* after SP, FP setup, before HW init */
33 #define BOOTSTAGE_2 2 /* after HW init, before self halt */
34 #define BOOTSTAGE_3 3 /* after self halt */
35 #define BOOTSTAGE_4 4 /* before app launch */
36 #define BOOTSTAGE_5 5 /* after app launch, unreachable */
38 #define RESET_VECTOR_ADDR 0x0
40 #define CREG_BASE (ARC_PERIPHERAL_BASE + 0x1000)
41 #define CREG_CPU_START (CREG_BASE + 0x400)
42 #define CREG_CPU_START_MASK 0xF
43 #define CREG_CPU_START_POL BIT(4)
45 #define SDIO_BASE (ARC_PERIPHERAL_BASE + 0xA000)
46 #define SDIO_UHS_REG_EXT (SDIO_BASE + 0x108)
47 #define SDIO_UHS_REG_EXT_DIV_2 (2 << 30)
49 /* Uncached access macros */
50 #define arc_read_uncached_32(ptr) \
53 __asm__ __volatile__( \
54 " ld.di %0, [%1] \n" \
60 #define arc_write_uncached_32(ptr, data)\
62 __asm__ __volatile__( \
63 " st.di %0, [%1] \n" \
65 : "r"(data), "r"(ptr)); \
68 struct hsdk_env_core_ctl {
69 u32_env entry[NR_CPUS];
70 u32_env iccm[NR_CPUS];
71 u32_env dccm[NR_CPUS];
74 struct hsdk_env_common_ctl {
88 * Uncached cross-cpu structure. All CPUs must access to this structure fields
89 * only with arc_read_uncached_32() / arc_write_uncached_32() accessors (which
90 * implement ld.di / st.di instructions). Simultaneous cached and uncached
91 * access to this area will lead to data loss.
92 * We flush all data caches in board_early_init_r() as we don't want to have
93 * any dirty line in L1d$ or SL$ in this area.
95 struct hsdk_cross_cpu {
96 /* slave CPU ready flag */
98 /* address of the area, which can be used for stack by slave CPU */
100 /* slave CPU status - bootstage number */
104 * Slave CPU data - it is copy of corresponding fields in
105 * hsdk_env_core_ctl and hsdk_env_common_ctl structures which are
106 * required for slave CPUs initialization.
107 * This fields can be populated by copying from hsdk_env_core_ctl
108 * and hsdk_env_common_ctl structures with sync_cross_cpu_data()
119 u8 cache_padding[ARCH_DMA_MINALIGN];
120 } __aligned(ARCH_DMA_MINALIGN);
122 /* Place for slave CPUs temporary stack */
123 static u32 slave_stack[256 * NR_CPUS] __aligned(ARCH_DMA_MINALIGN);
125 static struct hsdk_env_common_ctl env_common = {};
126 static struct hsdk_env_core_ctl env_core = {};
127 static struct hsdk_cross_cpu cross_cpu_data;
129 static const struct env_map_common env_map_common[] = {
130 { "core_mask", ENV_HEX, true, 0x1, 0xF, &env_common.core_mask },
131 { "non_volatile_limit", ENV_HEX, true, 0, 0xF, &env_common.nvlim },
132 { "icache_ena", ENV_HEX, true, 0, 1, &env_common.icache },
133 { "dcache_ena", ENV_HEX, true, 0, 1, &env_common.dcache },
134 #if defined(CONFIG_BOARD_HSDK_4XD)
135 { "l2_cache_ena", ENV_HEX, true, 0, 1, &env_common.l2_cache },
136 { "csm_location", ENV_HEX, true, 0, NO_CCM, &env_common.csm_location },
137 #endif /* CONFIG_BOARD_HSDK_4XD */
141 static const struct env_map_common env_map_clock[] = {
142 { "cpu_freq", ENV_DEC, false, 100, 1000, &env_common.cpu_freq },
143 { "axi_freq", ENV_DEC, false, 200, 800, &env_common.axi_freq },
144 { "tun_freq", ENV_DEC, false, 0, 150, &env_common.tun_freq },
148 static const struct env_map_percpu env_map_core[] = {
149 { "core_iccm", ENV_HEX, true, {NO_CCM, 0, NO_CCM, 0}, {NO_CCM, 0xF, NO_CCM, 0xF}, &env_core.iccm },
150 { "core_dccm", ENV_HEX, true, {NO_CCM, 0, NO_CCM, 0}, {NO_CCM, 0xF, NO_CCM, 0xF}, &env_core.dccm },
154 static const struct env_map_common env_map_mask[] = {
155 { "core_mask", ENV_HEX, false, 0x1, 0xF, &env_common.core_mask },
159 static const struct env_map_percpu env_map_go[] = {
160 { "core_entry", ENV_HEX, true, {0, 0, 0, 0}, {U32_MAX, U32_MAX, U32_MAX, U32_MAX}, &env_core.entry },
170 static inline enum board_type get_board_type_runtime(void)
172 u32 arc_id = read_aux_reg(ARC_AUX_IDENTITY) & 0xFF;
176 else if (arc_id == 0x54)
177 return T_BOARD_HSDK_4XD;
182 static inline enum board_type get_board_type_config(void)
184 if (IS_ENABLED(CONFIG_BOARD_HSDK))
186 else if (IS_ENABLED(CONFIG_BOARD_HSDK_4XD))
187 return T_BOARD_HSDK_4XD;
192 static bool is_board_match_runtime(enum board_type type_req)
194 return get_board_type_runtime() == type_req;
197 static bool is_board_match_config(enum board_type type_req)
199 return get_board_type_config() == type_req;
202 static const char * board_name(enum board_type type)
206 return "ARC HS Development Kit";
207 case T_BOARD_HSDK_4XD:
208 return "ARC HS4x/HS4xD Development Kit";
214 static bool board_mismatch(void)
216 return get_board_type_config() != get_board_type_runtime();
219 static void sync_cross_cpu_data(void)
223 for (u32 i = 0; i < NR_CPUS; i++) {
224 value = env_core.entry[i].val;
225 arc_write_uncached_32(&cross_cpu_data.entry[i], value);
228 for (u32 i = 0; i < NR_CPUS; i++) {
229 value = env_core.iccm[i].val;
230 arc_write_uncached_32(&cross_cpu_data.iccm[i], value);
233 for (u32 i = 0; i < NR_CPUS; i++) {
234 value = env_core.dccm[i].val;
235 arc_write_uncached_32(&cross_cpu_data.dccm[i], value);
238 value = env_common.core_mask.val;
239 arc_write_uncached_32(&cross_cpu_data.core_mask, value);
241 value = env_common.icache.val;
242 arc_write_uncached_32(&cross_cpu_data.icache, value);
244 value = env_common.dcache.val;
245 arc_write_uncached_32(&cross_cpu_data.dcache, value);
248 /* Can be used only on master CPU */
249 static bool is_cpu_used(u32 cpu_id)
251 return !!(env_common.core_mask.val & BIT(cpu_id));
254 /* TODO: add ICCM BCR and DCCM BCR runtime check */
255 static void init_slave_cpu_func(u32 core)
259 /* Remap ICCM to another memory region if it exists */
260 val = arc_read_uncached_32(&cross_cpu_data.iccm[core]);
262 write_aux_reg(ARC_AUX_ICCM_BASE, val << APERTURE_SHIFT);
264 /* Remap DCCM to another memory region if it exists */
265 val = arc_read_uncached_32(&cross_cpu_data.dccm[core]);
267 write_aux_reg(ARC_AUX_DCCM_BASE, val << APERTURE_SHIFT);
269 if (arc_read_uncached_32(&cross_cpu_data.icache))
274 if (arc_read_uncached_32(&cross_cpu_data.dcache))
280 static void init_cluster_nvlim(void)
282 u32 val = env_common.nvlim.val << APERTURE_SHIFT;
285 write_aux_reg(ARC_AUX_NON_VOLATILE_LIMIT, val);
286 /* AUX_AUX_CACHE_LIMIT reg is missing starting from HS48 */
287 if (is_board_match_runtime(T_BOARD_HSDK))
288 write_aux_reg(AUX_AUX_CACHE_LIMIT, val);
289 flush_n_invalidate_dcache_all();
292 static void init_cluster_slc(void)
294 /* ARC HS38 doesn't support SLC disabling */
295 if (!is_board_match_config(T_BOARD_HSDK_4XD))
298 if (env_common.l2_cache.val)
304 #define CREG_CSM_BASE (CREG_BASE + 0x210)
306 static void init_cluster_csm(void)
308 /* ARC HS38 in HSDK SoC doesn't include CSM */
309 if (!is_board_match_config(T_BOARD_HSDK_4XD))
312 if (env_common.csm_location.val == NO_CCM) {
313 write_aux_reg(ARC_AUX_CSM_ENABLE, 0);
316 * CSM base address is 256kByte aligned but we allow to map
317 * CSM only to aperture start (256MByte aligned)
318 * The field in CREG_CSM_BASE is in 17:2 bits itself so we need
321 u32 csm_base = (env_common.csm_location.val * SZ_1K) << 2;
323 write_aux_reg(ARC_AUX_CSM_ENABLE, 1);
324 writel(csm_base, (void __iomem *)CREG_CSM_BASE);
328 static void init_master_icache(void)
330 if (icache_status()) {
331 /* I$ is enabled - we need to disable it */
332 if (!env_common.icache.val)
335 /* I$ is disabled - we need to enable it */
336 if (env_common.icache.val) {
339 /* invalidate I$ right after enable */
340 invalidate_icache_all();
345 static void init_master_dcache(void)
347 if (dcache_status()) {
348 /* D$ is enabled - we need to disable it */
349 if (!env_common.dcache.val)
352 /* D$ is disabled - we need to enable it */
353 if (env_common.dcache.val)
356 /* TODO: probably we need ti invalidate D$ right after enable */
360 static int cleanup_before_go(void)
362 disable_interrupts();
363 sync_n_cleanup_cache_all();
368 void slave_cpu_set_boot_addr(u32 addr)
370 /* All cores have reset vector pointing to 0 */
371 writel(addr, (void __iomem *)RESET_VECTOR_ADDR);
373 /* Make sure other cores see written value in memory */
374 sync_n_cleanup_cache_all();
377 static inline void halt_this_cpu(void)
379 __builtin_arc_flag(1);
382 static u32 get_masked_cpu_ctart_reg(void)
384 int cmd = readl((void __iomem *)CREG_CPU_START);
387 * Quirk for HSDK-4xD - due to HW issues HSDK can use any pulse polarity
388 * and HSDK-4xD require active low polarity of cpu_start pulse.
390 cmd &= ~CREG_CPU_START_POL;
392 cmd &= ~CREG_CPU_START_MASK;
397 static void smp_kick_cpu_x(u32 cpu_id)
401 if (cpu_id > NR_CPUS)
404 cmd = get_masked_cpu_ctart_reg();
405 cmd |= (1 << cpu_id);
406 writel(cmd, (void __iomem *)CREG_CPU_START);
409 static u32 prepare_cpu_ctart_reg(void)
411 return get_masked_cpu_ctart_reg() | env_common.core_mask.val;
414 /* slave CPU entry for configuration */
415 __attribute__((naked, noreturn, flatten)) noinline void hsdk_core_init_f(void)
417 __asm__ __volatile__(
422 : "r" (&cross_cpu_data.stack_ptr));
424 invalidate_icache_all();
426 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_1);
427 init_slave_cpu_func(CPU_ID_GET());
429 arc_write_uncached_32(&cross_cpu_data.ready_flag, SLAVE_CPU_READY);
430 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_2);
432 /* Halt the processor until the master kick us again */
436 * 3 NOPs after FLAG 1 instruction are no longer required for ARCv2
437 * cores but we leave them for gebug purposes.
443 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_3);
445 /* get the updated entry - invalidate i$ */
446 invalidate_icache_all();
448 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_4);
450 /* Run our program */
451 ((void (*)(void))(arc_read_uncached_32(&cross_cpu_data.entry[CPU_ID_GET()])))();
453 /* This bootstage is unreachable as we don't return from app we launch */
454 arc_write_uncached_32(&cross_cpu_data.status[CPU_ID_GET()], BOOTSTAGE_5);
456 /* Something went terribly wrong */
461 static void clear_cross_cpu_data(void)
463 arc_write_uncached_32(&cross_cpu_data.ready_flag, 0);
464 arc_write_uncached_32(&cross_cpu_data.stack_ptr, 0);
466 for (u32 i = 0; i < NR_CPUS; i++)
467 arc_write_uncached_32(&cross_cpu_data.status[i], 0);
470 static noinline void do_init_slave_cpu(u32 cpu_id)
472 /* attempts number for check clave CPU ready_flag */
474 u32 stack_ptr = (u32)(slave_stack + (64 * cpu_id));
476 if (cpu_id >= NR_CPUS)
479 arc_write_uncached_32(&cross_cpu_data.ready_flag, 0);
481 /* Use global unique place for each slave cpu stack */
482 arc_write_uncached_32(&cross_cpu_data.stack_ptr, stack_ptr);
484 debug("CPU %u: stack pool base: %p\n", cpu_id, slave_stack);
485 debug("CPU %u: current slave stack base: %x\n", cpu_id, stack_ptr);
486 slave_cpu_set_boot_addr((u32)hsdk_core_init_f);
488 smp_kick_cpu_x(cpu_id);
490 debug("CPU %u: cross-cpu flag: %x [before timeout]\n", cpu_id,
491 arc_read_uncached_32(&cross_cpu_data.ready_flag));
493 while (!arc_read_uncached_32(&cross_cpu_data.ready_flag) && attempts--)
496 /* Just to be sure that slave cpu is halted after it set ready_flag */
500 * Only print error here if we reach timeout as there is no option to
501 * halt slave cpu (or check that slave cpu is halted)
504 pr_err("CPU %u is not responding after init!\n", cpu_id);
506 /* Check current stage of slave cpu */
507 if (arc_read_uncached_32(&cross_cpu_data.status[cpu_id]) != BOOTSTAGE_2)
508 pr_err("CPU %u status is unexpected: %d\n", cpu_id,
509 arc_read_uncached_32(&cross_cpu_data.status[cpu_id]));
511 debug("CPU %u: cross-cpu flag: %x [after timeout]\n", cpu_id,
512 arc_read_uncached_32(&cross_cpu_data.ready_flag));
513 debug("CPU %u: status: %d [after timeout]\n", cpu_id,
514 arc_read_uncached_32(&cross_cpu_data.status[cpu_id]));
517 static void do_init_slave_cpus(void)
519 clear_cross_cpu_data();
520 sync_cross_cpu_data();
522 debug("cross_cpu_data location: %#x\n", (u32)&cross_cpu_data);
524 for (u32 i = MASTER_CPU_ID + 1; i < NR_CPUS; i++)
526 do_init_slave_cpu(i);
529 static void do_init_master_cpu(void)
532 * Setup master caches even if master isn't used as we want to use
533 * same cache configuration on all running CPUs
535 init_master_icache();
536 init_master_dcache();
539 enum hsdk_axi_masters {
557 * m master AXI_M_m_SLV0 AXI_M_m_SLV1 AXI_M_m_OFFSET0 AXI_M_m_OFFSET1
558 * 0 HS (CBU) 0x11111111 0x63111111 0xFEDCBA98 0x0E543210
559 * 1 HS (RTT) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
560 * 2 AXI Tunnel 0x88888888 0x88888888 0xFEDCBA98 0x76543210
561 * 3 HDMI-VIDEO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
562 * 4 HDMI-ADUIO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
563 * 5 USB-HOST 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
564 * 6 ETHERNET 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
565 * 7 SDIO 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
566 * 8 GPU 0x77777777 0x77777777 0xFEDCBA98 0x76543210
567 * 9 DMAC (port #1) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
568 * 10 DMAC (port #2) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
569 * 11 DVFS 0x00000000 0x60000000 0x00000000 0x00000000
571 * Please read ARC HS Development IC Specification, section 17.2 for more
572 * information about apertures configuration.
573 * NOTE: we intentionally modify default settings in U-boot. Default settings
574 * are specified in "Table 111 CREG Address Decoder register reset values".
577 #define CREG_AXI_M_SLV0(m) ((void __iomem *)(CREG_BASE + 0x020 * (m)))
578 #define CREG_AXI_M_SLV1(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x004))
579 #define CREG_AXI_M_OFT0(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x008))
580 #define CREG_AXI_M_OFT1(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x00C))
581 #define CREG_AXI_M_UPDT(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x014))
583 #define CREG_AXI_M_HS_CORE_BOOT ((void __iomem *)(CREG_BASE + 0x010))
585 #define CREG_PAE ((void __iomem *)(CREG_BASE + 0x180))
586 #define CREG_PAE_UPDT ((void __iomem *)(CREG_BASE + 0x194))
588 void init_memory_bridge(void)
593 * M_HS_CORE has one unic register - BOOT.
594 * We need to clean boot mirror (BOOT[1:0]) bits in them.
596 reg = readl(CREG_AXI_M_HS_CORE_BOOT) & (~0x3);
597 writel(reg, CREG_AXI_M_HS_CORE_BOOT);
598 writel(0x11111111, CREG_AXI_M_SLV0(M_HS_CORE));
599 writel(0x63111111, CREG_AXI_M_SLV1(M_HS_CORE));
600 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HS_CORE));
601 writel(0x0E543210, CREG_AXI_M_OFT1(M_HS_CORE));
602 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HS_CORE));
604 writel(0x77777777, CREG_AXI_M_SLV0(M_HS_RTT));
605 writel(0x77777777, CREG_AXI_M_SLV1(M_HS_RTT));
606 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HS_RTT));
607 writel(0x76543210, CREG_AXI_M_OFT1(M_HS_RTT));
608 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HS_RTT));
610 writel(0x88888888, CREG_AXI_M_SLV0(M_AXI_TUN));
611 writel(0x88888888, CREG_AXI_M_SLV1(M_AXI_TUN));
612 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_AXI_TUN));
613 writel(0x76543210, CREG_AXI_M_OFT1(M_AXI_TUN));
614 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_AXI_TUN));
616 writel(0x77777777, CREG_AXI_M_SLV0(M_HDMI_VIDEO));
617 writel(0x77777777, CREG_AXI_M_SLV1(M_HDMI_VIDEO));
618 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HDMI_VIDEO));
619 writel(0x76543210, CREG_AXI_M_OFT1(M_HDMI_VIDEO));
620 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HDMI_VIDEO));
622 writel(0x77777777, CREG_AXI_M_SLV0(M_HDMI_AUDIO));
623 writel(0x77777777, CREG_AXI_M_SLV1(M_HDMI_AUDIO));
624 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HDMI_AUDIO));
625 writel(0x76543210, CREG_AXI_M_OFT1(M_HDMI_AUDIO));
626 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_HDMI_AUDIO));
628 writel(0x77777777, CREG_AXI_M_SLV0(M_USB_HOST));
629 writel(0x77999999, CREG_AXI_M_SLV1(M_USB_HOST));
630 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_USB_HOST));
631 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_USB_HOST));
632 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_USB_HOST));
634 writel(0x77777777, CREG_AXI_M_SLV0(M_ETHERNET));
635 writel(0x77999999, CREG_AXI_M_SLV1(M_ETHERNET));
636 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_ETHERNET));
637 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_ETHERNET));
638 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_ETHERNET));
640 writel(0x77777777, CREG_AXI_M_SLV0(M_SDIO));
641 writel(0x77999999, CREG_AXI_M_SLV1(M_SDIO));
642 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_SDIO));
643 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_SDIO));
644 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_SDIO));
646 writel(0x77777777, CREG_AXI_M_SLV0(M_GPU));
647 writel(0x77777777, CREG_AXI_M_SLV1(M_GPU));
648 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_GPU));
649 writel(0x76543210, CREG_AXI_M_OFT1(M_GPU));
650 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_GPU));
652 writel(0x77777777, CREG_AXI_M_SLV0(M_DMAC_0));
653 writel(0x77777777, CREG_AXI_M_SLV1(M_DMAC_0));
654 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_DMAC_0));
655 writel(0x76543210, CREG_AXI_M_OFT1(M_DMAC_0));
656 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_DMAC_0));
658 writel(0x77777777, CREG_AXI_M_SLV0(M_DMAC_1));
659 writel(0x77777777, CREG_AXI_M_SLV1(M_DMAC_1));
660 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_DMAC_1));
661 writel(0x76543210, CREG_AXI_M_OFT1(M_DMAC_1));
662 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_DMAC_1));
664 writel(0x00000000, CREG_AXI_M_SLV0(M_DVFS));
665 writel(0x60000000, CREG_AXI_M_SLV1(M_DVFS));
666 writel(0x00000000, CREG_AXI_M_OFT0(M_DVFS));
667 writel(0x00000000, CREG_AXI_M_OFT1(M_DVFS));
668 writel(UPDATE_VAL, CREG_AXI_M_UPDT(M_DVFS));
670 writel(0x00000000, CREG_PAE);
671 writel(UPDATE_VAL, CREG_PAE_UPDT);
674 static void setup_clocks(void)
678 /* Setup CPU clock */
679 if (env_common.cpu_freq.set) {
680 rate = env_common.cpu_freq.val;
681 soc_clk_ctl("cpu-clk", &rate, CLK_ON | CLK_SET | CLK_MHZ);
684 /* Setup TUN clock */
685 if (env_common.tun_freq.set) {
686 rate = env_common.tun_freq.val;
688 soc_clk_ctl("tun-clk", &rate, CLK_ON | CLK_SET | CLK_MHZ);
690 soc_clk_ctl("tun-clk", NULL, CLK_OFF);
693 if (env_common.axi_freq.set) {
694 rate = env_common.axi_freq.val;
695 soc_clk_ctl("axi-clk", &rate, CLK_SET | CLK_ON | CLK_MHZ);
699 static void do_init_cluster(void)
702 * A multi-core ARC HS configuration always includes only one
703 * ARC_AUX_NON_VOLATILE_LIMIT register, which is shared by all the
706 init_cluster_nvlim();
711 static int check_master_cpu_id(void)
713 if (CPU_ID_GET() == MASTER_CPU_ID)
716 pr_err("u-boot runs on non-master cpu with id: %lu\n", CPU_ID_GET());
721 static noinline int prepare_cpus(void)
725 ret = check_master_cpu_id();
729 ret = envs_process_and_validate(env_map_common, env_map_core, is_cpu_used);
733 printf("CPU start mask is %#x\n", env_common.core_mask.val);
735 do_init_slave_cpus();
736 do_init_master_cpu();
742 static int hsdk_go_run(u32 cpu_start_reg)
744 /* Cleanup caches, disable interrupts */
747 if (env_common.halt_on_boot)
751 * 3 NOPs after FLAG 1 instruction are no longer required for ARCv2
752 * cores but we leave them for gebug purposes.
758 /* Kick chosen slave CPUs */
759 writel(cpu_start_reg, (void __iomem *)CREG_CPU_START);
761 if (is_cpu_used(MASTER_CPU_ID))
762 ((void (*)(void))(env_core.entry[MASTER_CPU_ID].val))();
766 pr_err("u-boot still runs on cpu [%ld]\n", CPU_ID_GET());
769 * We will never return after executing our program if master cpu used
770 * otherwise halt master cpu manually.
778 int board_prep_linux(bootm_headers_t *images)
783 ret = envs_read_validate_common(env_map_mask);
787 /* Rollback to default values */
788 if (!env_common.core_mask.set) {
789 env_common.core_mask.val = ALL_CPU_MASK;
790 env_common.core_mask.set = true;
793 printf("CPU start mask is %#x\n", env_common.core_mask.val);
795 if (!is_cpu_used(MASTER_CPU_ID))
796 pr_err("ERR: try to launch linux with CPU[0] disabled! It doesn't work for ARC.\n");
799 * If we want to launch linux on all CPUs we don't need to patch
800 * linux DTB as it is default configuration
802 if (env_common.core_mask.val == ALL_CPU_MASK)
805 if (!IMAGE_ENABLE_OF_LIBFDT || !images->ft_len) {
806 pr_err("WARN: core_mask setup will work properly only with external DTB!\n");
810 /* patch '/possible-cpus' property according to cpu mask */
811 ofst = fdt_path_offset(images->ft_addr, "/");
812 sprintf(mask, "%s%s%s%s",
813 is_cpu_used(0) ? "0," : "",
814 is_cpu_used(1) ? "1," : "",
815 is_cpu_used(2) ? "2," : "",
816 is_cpu_used(3) ? "3," : "");
817 ret = fdt_setprop_string(images->ft_addr, ofst, "possible-cpus", mask);
819 * If we failed to patch '/possible-cpus' property we don't need break
820 * linux loading process: kernel will handle it but linux will print
821 * warning like "Timeout: CPU1 FAILED to comeup !!!".
822 * So warn here about error, but return 0 like no error had occurred.
825 pr_err("WARN: failed to patch '/possible-cpus' property, ret=%d\n",
831 void board_jump_and_run(ulong entry, int zero, int arch, uint params)
833 void (*kernel_entry)(int zero, int arch, uint params);
836 kernel_entry = (void (*)(int, int, uint))entry;
838 /* Prepare CREG_CPU_START for kicking chosen CPUs */
839 cpu_start_reg = prepare_cpu_ctart_reg();
841 /* In case of run without hsdk_init */
842 slave_cpu_set_boot_addr(entry);
844 /* In case of run with hsdk_init */
845 for (u32 i = 0; i < NR_CPUS; i++) {
846 env_core.entry[i].val = entry;
847 env_core.entry[i].set = true;
849 /* sync cross_cpu struct as we updated core-entry variables */
850 sync_cross_cpu_data();
852 /* Kick chosen slave CPUs */
853 writel(cpu_start_reg, (void __iomem *)CREG_CPU_START);
856 kernel_entry(zero, arch, params);
859 static int hsdk_go_prepare_and_run(void)
861 /* Prepare CREG_CPU_START for kicking chosen CPUs */
862 u32 reg = prepare_cpu_ctart_reg();
864 if (env_common.halt_on_boot)
865 printf("CPU will halt before application start, start application with debugger.\n");
867 return hsdk_go_run(reg);
870 static int do_hsdk_go(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
874 if (board_mismatch()) {
875 printf("ERR: U-boot is not configured for this board!\n");
876 return CMD_RET_FAILURE;
880 * Check for 'halt' parameter. 'halt' = enter halt-mode just before
881 * starting the application; can be used for debug.
884 env_common.halt_on_boot = !strcmp(argv[1], "halt");
885 if (!env_common.halt_on_boot) {
886 pr_err("Unrecognised parameter: \'%s\'\n", argv[1]);
887 return CMD_RET_FAILURE;
891 ret = check_master_cpu_id();
895 ret = envs_process_and_validate(env_map_mask, env_map_go, is_cpu_used);
899 /* sync cross_cpu struct as we updated core-entry variables */
900 sync_cross_cpu_data();
902 ret = hsdk_go_prepare_and_run();
904 return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
908 hsdk_go, 3, 0, do_hsdk_go,
909 "Synopsys HSDK specific command",
910 " - Boot stand-alone application on HSDK\n"
911 "hsdk_go halt - Boot stand-alone application on HSDK, halt CPU just before application run\n"
914 static int do_hsdk_init(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
916 static bool done = false;
919 if (board_mismatch()) {
920 printf("ERR: U-boot is not configured for this board!\n");
921 return CMD_RET_FAILURE;
924 /* hsdk_init can be run only once */
926 printf("HSDK HW is already initialized! Please reset the board if you want to change the configuration.\n");
927 return CMD_RET_FAILURE;
930 ret = prepare_cpus();
934 return ret ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
938 hsdk_init, 1, 0, do_hsdk_init,
939 "Synopsys HSDK specific command",
943 static int do_hsdk_clock_set(cmd_tbl_t *cmdtp, int flag, int argc,
948 /* Strip off leading subcommand argument */
952 envs_cleanup_common(env_map_clock);
955 printf("Set clocks to values specified in environment\n");
956 ret = envs_read_common(env_map_clock);
958 printf("Set clocks to values specified in args\n");
959 ret = args_envs_enumerate(env_map_clock, 2, argc, argv);
963 return CMD_RET_FAILURE;
965 ret = envs_validate_common(env_map_clock);
967 return CMD_RET_FAILURE;
969 /* Setup clock tree HW */
972 return CMD_RET_SUCCESS;
975 static int do_hsdk_clock_get(cmd_tbl_t *cmdtp, int flag, int argc,
980 if (soc_clk_ctl("cpu-clk", &rate, CLK_GET | CLK_MHZ))
981 return CMD_RET_FAILURE;
983 if (env_set_ulong("cpu_freq", rate))
984 return CMD_RET_FAILURE;
986 if (soc_clk_ctl("tun-clk", &rate, CLK_GET | CLK_MHZ))
987 return CMD_RET_FAILURE;
989 if (env_set_ulong("tun_freq", rate))
990 return CMD_RET_FAILURE;
992 if (soc_clk_ctl("axi-clk", &rate, CLK_GET | CLK_MHZ))
993 return CMD_RET_FAILURE;
995 if (env_set_ulong("axi_freq", rate))
996 return CMD_RET_FAILURE;
998 printf("Clock values are saved to environment\n");
1000 return CMD_RET_SUCCESS;
1003 static int do_hsdk_clock_print(cmd_tbl_t *cmdtp, int flag, int argc,
1007 soc_clk_ctl("cpu-clk", NULL, CLK_PRINT | CLK_MHZ);
1008 soc_clk_ctl("tun-clk", NULL, CLK_PRINT | CLK_MHZ);
1009 soc_clk_ctl("axi-clk", NULL, CLK_PRINT | CLK_MHZ);
1010 soc_clk_ctl("ddr-clk", NULL, CLK_PRINT | CLK_MHZ);
1012 return CMD_RET_SUCCESS;
1015 static int do_hsdk_clock_print_all(cmd_tbl_t *cmdtp, int flag, int argc,
1019 * NOTE: as of today we don't use some peripherals like HDMI / EBI
1020 * so we don't want to print their clocks ("hdmi-sys-clk", "hdmi-pll",
1021 * "hdmi-clk", "ebi-clk"). Nevertheless their clock subsystems is fully
1022 * functional and we can print their clocks if it is required
1025 /* CPU clock domain */
1026 soc_clk_ctl("cpu-pll", NULL, CLK_PRINT | CLK_MHZ);
1027 soc_clk_ctl("cpu-clk", NULL, CLK_PRINT | CLK_MHZ);
1030 /* SYS clock domain */
1031 soc_clk_ctl("sys-pll", NULL, CLK_PRINT | CLK_MHZ);
1032 soc_clk_ctl("apb-clk", NULL, CLK_PRINT | CLK_MHZ);
1033 soc_clk_ctl("axi-clk", NULL, CLK_PRINT | CLK_MHZ);
1034 soc_clk_ctl("eth-clk", NULL, CLK_PRINT | CLK_MHZ);
1035 soc_clk_ctl("usb-clk", NULL, CLK_PRINT | CLK_MHZ);
1036 soc_clk_ctl("sdio-clk", NULL, CLK_PRINT | CLK_MHZ);
1037 if (is_board_match_runtime(T_BOARD_HSDK_4XD))
1038 soc_clk_ctl("hdmi-sys-clk", NULL, CLK_PRINT | CLK_MHZ);
1039 soc_clk_ctl("gfx-core-clk", NULL, CLK_PRINT | CLK_MHZ);
1040 if (is_board_match_runtime(T_BOARD_HSDK)) {
1041 soc_clk_ctl("gfx-dma-clk", NULL, CLK_PRINT | CLK_MHZ);
1042 soc_clk_ctl("gfx-cfg-clk", NULL, CLK_PRINT | CLK_MHZ);
1044 soc_clk_ctl("dmac-core-clk", NULL, CLK_PRINT | CLK_MHZ);
1045 soc_clk_ctl("dmac-cfg-clk", NULL, CLK_PRINT | CLK_MHZ);
1046 soc_clk_ctl("sdio-ref-clk", NULL, CLK_PRINT | CLK_MHZ);
1047 soc_clk_ctl("spi-clk", NULL, CLK_PRINT | CLK_MHZ);
1048 soc_clk_ctl("i2c-clk", NULL, CLK_PRINT | CLK_MHZ);
1049 /* soc_clk_ctl("ebi-clk", NULL, CLK_PRINT | CLK_MHZ); */
1050 soc_clk_ctl("uart-clk", NULL, CLK_PRINT | CLK_MHZ);
1053 /* DDR clock domain */
1054 soc_clk_ctl("ddr-clk", NULL, CLK_PRINT | CLK_MHZ);
1057 /* HDMI clock domain */
1058 if (is_board_match_runtime(T_BOARD_HSDK_4XD)) {
1059 soc_clk_ctl("hdmi-pll", NULL, CLK_PRINT | CLK_MHZ);
1060 soc_clk_ctl("hdmi-clk", NULL, CLK_PRINT | CLK_MHZ);
1064 /* TUN clock domain */
1065 soc_clk_ctl("tun-pll", NULL, CLK_PRINT | CLK_MHZ);
1066 soc_clk_ctl("tun-clk", NULL, CLK_PRINT | CLK_MHZ);
1067 soc_clk_ctl("rom-clk", NULL, CLK_PRINT | CLK_MHZ);
1068 soc_clk_ctl("pwm-clk", NULL, CLK_PRINT | CLK_MHZ);
1069 if (is_board_match_runtime(T_BOARD_HSDK_4XD))
1070 soc_clk_ctl("timer-clk", NULL, CLK_PRINT | CLK_MHZ);
1073 return CMD_RET_SUCCESS;
1076 cmd_tbl_t cmd_hsdk_clock[] = {
1077 U_BOOT_CMD_MKENT(set, 3, 0, do_hsdk_clock_set, "", ""),
1078 U_BOOT_CMD_MKENT(get, 3, 0, do_hsdk_clock_get, "", ""),
1079 U_BOOT_CMD_MKENT(print, 4, 0, do_hsdk_clock_print, "", ""),
1080 U_BOOT_CMD_MKENT(print_all, 4, 0, do_hsdk_clock_print_all, "", ""),
1083 static int do_hsdk_clock(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
1088 return CMD_RET_USAGE;
1090 /* Strip off leading 'hsdk_clock' command argument */
1094 c = find_cmd_tbl(argv[0], cmd_hsdk_clock, ARRAY_SIZE(cmd_hsdk_clock));
1096 return CMD_RET_USAGE;
1098 return c->cmd(cmdtp, flag, argc, argv);
1102 hsdk_clock, CONFIG_SYS_MAXARGS, 0, do_hsdk_clock,
1103 "Synopsys HSDK specific clock command",
1104 "set - Set clock to values specified in environment / command line arguments\n"
1105 "hsdk_clock get - Save clock values to environment\n"
1106 "hsdk_clock print - Print main clock values to console\n"
1107 "hsdk_clock print_all - Print all clock values to console\n"
1111 int board_early_init_f(void)
1114 * Setup AXI apertures unconditionally as we want to have DDR
1115 * in 0x00000000 region when we are kicking slave cpus.
1117 init_memory_bridge();
1120 * Switch SDIO external ciu clock divider from default div-by-8 to
1121 * minimum possible div-by-2.
1123 writel(SDIO_UHS_REG_EXT_DIV_2, (void __iomem *)SDIO_UHS_REG_EXT);
1128 int board_early_init_r(void)
1131 * TODO: Init USB here to be able read environment from USB MSD.
1132 * It can be done with usb_init() call. We can't do it right now
1133 * due to brocken USB IP SW reset and lack of USB IP HW reset in
1134 * linux kernel (if we init USB here we will break USB in linux)
1138 * Flush all d$ as we want to use uncached area with st.di / ld.di
1139 * instructions and we don't want to have any dirty line in L1d$ or SL$
1140 * in this area. It is enough to flush all d$ once here as we access to
1141 * uncached area with regular st (non .di) instruction only when we copy
1142 * data during u-boot relocation.
1146 printf("Relocation Offset is: %08lx\n", gd->reloc_off);
1151 int board_late_init(void)
1154 * Populate environment with clock frequency values -
1155 * run hsdk_clock get callback without uboot command run.
1157 do_hsdk_clock_get(NULL, 0, 0, NULL);
1162 int checkboard(void)
1164 printf("Board: Synopsys %s\n", board_name(get_board_type_runtime()));
1166 if (board_mismatch())
1167 printf("WARN: U-boot is configured NOT for this board but for %s!\n",
1168 board_name(get_board_type_config()));