1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Synopsys, Inc. All rights reserved.
4 * Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
14 #include <asm/cache.h>
15 #include <linux/printk.h>
16 #include <linux/kernel.h>
18 #include <asm/arcregs.h>
19 #include <fdt_support.h>
27 DECLARE_GLOBAL_DATA_PTR
;
29 #define ALL_CPU_MASK GENMASK(NR_CPUS - 1, 0)
30 #define MASTER_CPU_ID 0
31 #define APERTURE_SHIFT 28
33 #define SLAVE_CPU_READY 0x12345678
34 #define BOOTSTAGE_1 1 /* after SP, FP setup, before HW init */
35 #define BOOTSTAGE_2 2 /* after HW init, before self halt */
36 #define BOOTSTAGE_3 3 /* after self halt */
37 #define BOOTSTAGE_4 4 /* before app launch */
38 #define BOOTSTAGE_5 5 /* after app launch, unreachable */
40 #define RESET_VECTOR_ADDR 0x0
42 #define CREG_BASE (ARC_PERIPHERAL_BASE + 0x1000)
43 #define CREG_CPU_START (CREG_BASE + 0x400)
44 #define CREG_CPU_START_MASK 0xF
45 #define CREG_CPU_START_POL BIT(4)
47 #define CREG_CORE_BOOT_IMAGE GENMASK(5, 4)
49 #define CREG_CPU_0_ENTRY (CREG_BASE + 0x404)
51 #define SDIO_BASE (ARC_PERIPHERAL_BASE + 0xA000)
52 #define SDIO_UHS_REG_EXT (SDIO_BASE + 0x108)
53 #define SDIO_UHS_REG_EXT_DIV_2 (2 << 30)
55 /* Uncached access macros */
56 #define arc_read_uncached_32(ptr) \
59 __asm__ __volatile__( \
60 " ld.di %0, [%1] \n" \
66 #define arc_write_uncached_32(ptr, data)\
68 __asm__ __volatile__( \
69 " st.di %0, [%1] \n" \
71 : "r"(data), "r"(ptr)); \
74 struct hsdk_env_core_ctl
{
75 u32_env entry
[NR_CPUS
];
76 u32_env iccm
[NR_CPUS
];
77 u32_env dccm
[NR_CPUS
];
80 struct hsdk_env_common_ctl
{
95 * Uncached cross-cpu structure. All CPUs must access to this structure fields
96 * only with arc_read_uncached_32() / arc_write_uncached_32() accessors (which
97 * implement ld.di / st.di instructions). Simultaneous cached and uncached
98 * access to this area will lead to data loss.
99 * We flush all data caches in board_early_init_r() as we don't want to have
100 * any dirty line in L1d$ or SL$ in this area.
102 struct hsdk_cross_cpu
{
103 /* slave CPU ready flag */
105 /* address of the area, which can be used for stack by slave CPU */
107 /* slave CPU status - bootstage number */
111 * Slave CPU data - it is copy of corresponding fields in
112 * hsdk_env_core_ctl and hsdk_env_common_ctl structures which are
113 * required for slave CPUs initialization.
114 * This fields can be populated by copying from hsdk_env_core_ctl
115 * and hsdk_env_common_ctl structures with sync_cross_cpu_data()
126 u8 cache_padding
[ARCH_DMA_MINALIGN
];
127 } __aligned(ARCH_DMA_MINALIGN
);
129 /* Place for slave CPUs temporary stack */
130 static u32 slave_stack
[256 * NR_CPUS
] __aligned(ARCH_DMA_MINALIGN
);
132 static struct hsdk_env_common_ctl env_common
= {};
133 static struct hsdk_env_core_ctl env_core
= {};
134 static struct hsdk_cross_cpu cross_cpu_data
;
136 static const struct env_map_common env_map_common
[] = {
137 { "core_mask", ENV_HEX
, true, 0x1, 0xF, &env_common
.core_mask
},
138 { "non_volatile_limit", ENV_HEX
, true, 0, 0xF, &env_common
.nvlim
},
139 { "icache_ena", ENV_HEX
, true, 0, 1, &env_common
.icache
},
140 { "dcache_ena", ENV_HEX
, true, 0, 1, &env_common
.dcache
},
141 #if defined(CONFIG_BOARD_HSDK_4XD)
142 { "l2_cache_ena", ENV_HEX
, true, 0, 1, &env_common
.l2_cache
},
143 { "csm_location", ENV_HEX
, true, 0, NO_CCM
, &env_common
.csm_location
},
144 { "haps_apb_location", ENV_HEX
, true, 0, 1, &env_common
.haps_apb
},
145 #endif /* CONFIG_BOARD_HSDK_4XD */
149 static const struct env_map_common env_map_clock
[] = {
150 { "cpu_freq", ENV_DEC
, false, 100, 1000, &env_common
.cpu_freq
},
151 { "axi_freq", ENV_DEC
, false, 200, 800, &env_common
.axi_freq
},
152 { "tun_freq", ENV_DEC
, false, 0, 150, &env_common
.tun_freq
},
156 static const struct env_map_percpu env_map_core
[] = {
157 { "core_iccm", ENV_HEX
, true, {NO_CCM
, 0, NO_CCM
, 0}, {NO_CCM
, 0xF, NO_CCM
, 0xF}, &env_core
.iccm
},
158 { "core_dccm", ENV_HEX
, true, {NO_CCM
, 0, NO_CCM
, 0}, {NO_CCM
, 0xF, NO_CCM
, 0xF}, &env_core
.dccm
},
162 static const struct env_map_common env_map_mask
[] = {
163 { "core_mask", ENV_HEX
, false, 0x1, 0xF, &env_common
.core_mask
},
167 static const struct env_map_percpu env_map_go
[] = {
168 { "core_entry", ENV_HEX
, true, {0, 0, 0, 0}, {U32_MAX
, U32_MAX
, U32_MAX
, U32_MAX
}, &env_core
.entry
},
178 static inline enum board_type
get_board_type_runtime(void)
180 u32 arc_id
= read_aux_reg(ARC_AUX_IDENTITY
) & 0xFF;
184 else if (arc_id
== 0x54)
185 return T_BOARD_HSDK_4XD
;
190 static inline enum board_type
get_board_type_config(void)
192 if (IS_ENABLED(CONFIG_BOARD_HSDK
))
194 else if (IS_ENABLED(CONFIG_BOARD_HSDK_4XD
))
195 return T_BOARD_HSDK_4XD
;
200 static bool is_board_match_runtime(enum board_type type_req
)
202 return get_board_type_runtime() == type_req
;
205 static bool is_board_match_config(enum board_type type_req
)
207 return get_board_type_config() == type_req
;
210 static const char * board_name(enum board_type type
)
214 return "ARC HS Development Kit";
215 case T_BOARD_HSDK_4XD
:
216 return "ARC HS4x/HS4xD Development Kit";
222 static bool board_mismatch(void)
224 return get_board_type_config() != get_board_type_runtime();
227 static void sync_cross_cpu_data(void)
231 for (u32 i
= 0; i
< NR_CPUS
; i
++) {
232 value
= env_core
.entry
[i
].val
;
233 arc_write_uncached_32(&cross_cpu_data
.entry
[i
], value
);
236 for (u32 i
= 0; i
< NR_CPUS
; i
++) {
237 value
= env_core
.iccm
[i
].val
;
238 arc_write_uncached_32(&cross_cpu_data
.iccm
[i
], value
);
241 for (u32 i
= 0; i
< NR_CPUS
; i
++) {
242 value
= env_core
.dccm
[i
].val
;
243 arc_write_uncached_32(&cross_cpu_data
.dccm
[i
], value
);
246 value
= env_common
.core_mask
.val
;
247 arc_write_uncached_32(&cross_cpu_data
.core_mask
, value
);
249 value
= env_common
.icache
.val
;
250 arc_write_uncached_32(&cross_cpu_data
.icache
, value
);
252 value
= env_common
.dcache
.val
;
253 arc_write_uncached_32(&cross_cpu_data
.dcache
, value
);
256 /* Can be used only on master CPU */
257 static bool is_cpu_used(u32 cpu_id
)
259 return !!(env_common
.core_mask
.val
& BIT(cpu_id
));
262 /* TODO: add ICCM BCR and DCCM BCR runtime check */
263 static void init_slave_cpu_func(u32 core
)
267 /* Remap ICCM to another memory region if it exists */
268 val
= arc_read_uncached_32(&cross_cpu_data
.iccm
[core
]);
270 write_aux_reg(ARC_AUX_ICCM_BASE
, val
<< APERTURE_SHIFT
);
272 /* Remap DCCM to another memory region if it exists */
273 val
= arc_read_uncached_32(&cross_cpu_data
.dccm
[core
]);
275 write_aux_reg(ARC_AUX_DCCM_BASE
, val
<< APERTURE_SHIFT
);
277 if (arc_read_uncached_32(&cross_cpu_data
.icache
))
282 if (arc_read_uncached_32(&cross_cpu_data
.dcache
))
288 static void init_cluster_nvlim(void)
290 u32 val
= env_common
.nvlim
.val
<< APERTURE_SHIFT
;
293 write_aux_reg(ARC_AUX_NON_VOLATILE_LIMIT
, val
);
294 /* AUX_AUX_CACHE_LIMIT reg is missing starting from HS48 */
295 if (is_board_match_runtime(T_BOARD_HSDK
))
296 write_aux_reg(AUX_AUX_CACHE_LIMIT
, val
);
297 flush_n_invalidate_dcache_all();
300 static void init_cluster_slc(void)
302 /* ARC HS38 doesn't support SLC disabling */
303 if (!is_board_match_config(T_BOARD_HSDK_4XD
))
306 if (env_common
.l2_cache
.val
)
312 #define CREG_CSM_BASE (CREG_BASE + 0x210)
314 static void init_cluster_csm(void)
316 /* ARC HS38 in HSDK SoC doesn't include CSM */
317 if (!is_board_match_config(T_BOARD_HSDK_4XD
))
320 if (env_common
.csm_location
.val
== NO_CCM
) {
321 write_aux_reg(ARC_AUX_CSM_ENABLE
, 0);
324 * CSM base address is 256kByte aligned but we allow to map
325 * CSM only to aperture start (256MByte aligned)
326 * The field in CREG_CSM_BASE is in 17:2 bits itself so we need
329 u32 csm_base
= (env_common
.csm_location
.val
* SZ_1K
) << 2;
331 write_aux_reg(ARC_AUX_CSM_ENABLE
, 1);
332 writel(csm_base
, (void __iomem
*)CREG_CSM_BASE
);
336 static void init_master_icache(void)
338 if (icache_status()) {
339 /* I$ is enabled - we need to disable it */
340 if (!env_common
.icache
.val
)
343 /* I$ is disabled - we need to enable it */
344 if (env_common
.icache
.val
) {
347 /* invalidate I$ right after enable */
348 invalidate_icache_all();
353 static void init_master_dcache(void)
355 if (dcache_status()) {
356 /* D$ is enabled - we need to disable it */
357 if (!env_common
.dcache
.val
)
360 /* D$ is disabled - we need to enable it */
361 if (env_common
.dcache
.val
)
364 /* TODO: probably we need ti invalidate D$ right after enable */
368 static int cleanup_before_go(void)
370 disable_interrupts();
371 sync_n_cleanup_cache_all();
376 void slave_cpu_set_boot_addr(u32 addr
)
378 /* All cores have reset vector pointing to 0 */
379 writel(addr
, (void __iomem
*)RESET_VECTOR_ADDR
);
381 /* Make sure other cores see written value in memory */
382 sync_n_cleanup_cache_all();
385 static inline void halt_this_cpu(void)
387 __builtin_arc_flag(1);
390 static u32
get_masked_cpu_ctart_reg(void)
392 int cmd
= readl((void __iomem
*)CREG_CPU_START
);
395 * Quirk for HSDK-4xD - due to HW issues HSDK can use any pulse polarity
396 * and HSDK-4xD require active low polarity of cpu_start pulse.
398 cmd
&= ~CREG_CPU_START_POL
;
400 cmd
&= ~CREG_CPU_START_MASK
;
405 static void smp_kick_cpu_x(u32 cpu_id
)
409 if (cpu_id
> NR_CPUS
)
412 cmd
= get_masked_cpu_ctart_reg();
413 cmd
|= (1 << cpu_id
);
414 writel(cmd
, (void __iomem
*)CREG_CPU_START
);
417 static u32
prepare_cpu_ctart_reg(void)
419 return get_masked_cpu_ctart_reg() | env_common
.core_mask
.val
;
422 /* slave CPU entry for configuration */
423 __attribute__((naked
, noreturn
, flatten
)) noinline
void hsdk_core_init_f(void)
425 __asm__
__volatile__(
430 : "r" (&cross_cpu_data
.stack_ptr
));
432 invalidate_icache_all();
434 arc_write_uncached_32(&cross_cpu_data
.status
[CPU_ID_GET()], BOOTSTAGE_1
);
435 init_slave_cpu_func(CPU_ID_GET());
437 arc_write_uncached_32(&cross_cpu_data
.ready_flag
, SLAVE_CPU_READY
);
438 arc_write_uncached_32(&cross_cpu_data
.status
[CPU_ID_GET()], BOOTSTAGE_2
);
440 /* Halt the processor until the master kick us again */
444 * 3 NOPs after FLAG 1 instruction are no longer required for ARCv2
445 * cores but we leave them for gebug purposes.
451 arc_write_uncached_32(&cross_cpu_data
.status
[CPU_ID_GET()], BOOTSTAGE_3
);
453 /* get the updated entry - invalidate i$ */
454 invalidate_icache_all();
456 arc_write_uncached_32(&cross_cpu_data
.status
[CPU_ID_GET()], BOOTSTAGE_4
);
458 /* Run our program */
459 ((void (*)(void))(arc_read_uncached_32(&cross_cpu_data
.entry
[CPU_ID_GET()])))();
461 /* This bootstage is unreachable as we don't return from app we launch */
462 arc_write_uncached_32(&cross_cpu_data
.status
[CPU_ID_GET()], BOOTSTAGE_5
);
464 /* Something went terribly wrong */
469 static void clear_cross_cpu_data(void)
471 arc_write_uncached_32(&cross_cpu_data
.ready_flag
, 0);
472 arc_write_uncached_32(&cross_cpu_data
.stack_ptr
, 0);
474 for (u32 i
= 0; i
< NR_CPUS
; i
++)
475 arc_write_uncached_32(&cross_cpu_data
.status
[i
], 0);
478 static noinline
void do_init_slave_cpu(u32 cpu_id
)
480 /* attempts number for check clave CPU ready_flag */
482 u32 stack_ptr
= (u32
)(slave_stack
+ (64 * cpu_id
));
484 if (cpu_id
>= NR_CPUS
)
487 arc_write_uncached_32(&cross_cpu_data
.ready_flag
, 0);
489 /* Use global unique place for each slave cpu stack */
490 arc_write_uncached_32(&cross_cpu_data
.stack_ptr
, stack_ptr
);
492 debug("CPU %u: stack pool base: %p\n", cpu_id
, slave_stack
);
493 debug("CPU %u: current slave stack base: %x\n", cpu_id
, stack_ptr
);
494 slave_cpu_set_boot_addr((u32
)hsdk_core_init_f
);
496 smp_kick_cpu_x(cpu_id
);
498 debug("CPU %u: cross-cpu flag: %x [before timeout]\n", cpu_id
,
499 arc_read_uncached_32(&cross_cpu_data
.ready_flag
));
501 while (!arc_read_uncached_32(&cross_cpu_data
.ready_flag
) && attempts
--)
504 /* Just to be sure that slave cpu is halted after it set ready_flag */
508 * Only print error here if we reach timeout as there is no option to
509 * halt slave cpu (or check that slave cpu is halted)
512 pr_err("CPU %u is not responding after init!\n", cpu_id
);
514 /* Check current stage of slave cpu */
515 if (arc_read_uncached_32(&cross_cpu_data
.status
[cpu_id
]) != BOOTSTAGE_2
)
516 pr_err("CPU %u status is unexpected: %d\n", cpu_id
,
517 arc_read_uncached_32(&cross_cpu_data
.status
[cpu_id
]));
519 debug("CPU %u: cross-cpu flag: %x [after timeout]\n", cpu_id
,
520 arc_read_uncached_32(&cross_cpu_data
.ready_flag
));
521 debug("CPU %u: status: %d [after timeout]\n", cpu_id
,
522 arc_read_uncached_32(&cross_cpu_data
.status
[cpu_id
]));
525 static void do_init_slave_cpus(void)
527 clear_cross_cpu_data();
528 sync_cross_cpu_data();
530 debug("cross_cpu_data location: %#x\n", (u32
)&cross_cpu_data
);
532 for (u32 i
= MASTER_CPU_ID
+ 1; i
< NR_CPUS
; i
++)
534 do_init_slave_cpu(i
);
537 static void do_init_master_cpu(void)
540 * Setup master caches even if master isn't used as we want to use
541 * same cache configuration on all running CPUs
543 init_master_icache();
544 init_master_dcache();
547 enum hsdk_axi_masters
{
565 * m master AXI_M_m_SLV0 AXI_M_m_SLV1 AXI_M_m_OFFSET0 AXI_M_m_OFFSET1
566 * 0 HS (CBU) 0x11111111 0x63111111 0xFEDCBA98 0x0E543210
567 * 1 HS (RTT) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
568 * 2 AXI Tunnel 0x88888888 0x88888888 0xFEDCBA98 0x76543210
569 * 3 HDMI-VIDEO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
570 * 4 HDMI-ADUIO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
571 * 5 USB-HOST 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
572 * 6 ETHERNET 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
573 * 7 SDIO 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
574 * 8 GPU 0x77777777 0x77777777 0xFEDCBA98 0x76543210
575 * 9 DMAC (port #1) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
576 * 10 DMAC (port #2) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
577 * 11 DVFS 0x00000000 0x60000000 0x00000000 0x00000000
579 * Please read ARC HS Development IC Specification, section 17.2 for more
580 * information about apertures configuration.
581 * NOTE: we intentionally modify default settings in U-boot. Default settings
582 * are specified in "Table 111 CREG Address Decoder register reset values".
585 #define CREG_AXI_M_SLV0(m) ((void __iomem *)(CREG_BASE + 0x020 * (m)))
586 #define CREG_AXI_M_SLV1(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x004))
587 #define CREG_AXI_M_OFT0(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x008))
588 #define CREG_AXI_M_OFT1(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x00C))
589 #define CREG_AXI_M_UPDT(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x014))
591 #define CREG_AXI_M_HS_CORE_BOOT ((void __iomem *)(CREG_BASE + 0x010))
593 #define CREG_PAE ((void __iomem *)(CREG_BASE + 0x180))
594 #define CREG_PAE_UPDT ((void __iomem *)(CREG_BASE + 0x194))
596 void init_memory_bridge(void)
601 * M_HS_CORE has one unic register - BOOT.
602 * We need to clean boot mirror (BOOT[1:0]) bits in them.
604 reg
= readl(CREG_AXI_M_HS_CORE_BOOT
) & (~0x3);
605 writel(reg
, CREG_AXI_M_HS_CORE_BOOT
);
606 writel(0x11111111, CREG_AXI_M_SLV0(M_HS_CORE
));
607 writel(0x63111111, CREG_AXI_M_SLV1(M_HS_CORE
));
608 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HS_CORE
));
609 writel(0x0E543210, CREG_AXI_M_OFT1(M_HS_CORE
));
610 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_HS_CORE
));
612 writel(0x77777777, CREG_AXI_M_SLV0(M_HS_RTT
));
613 writel(0x77777777, CREG_AXI_M_SLV1(M_HS_RTT
));
614 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HS_RTT
));
615 writel(0x76543210, CREG_AXI_M_OFT1(M_HS_RTT
));
616 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_HS_RTT
));
618 writel(0x88888888, CREG_AXI_M_SLV0(M_AXI_TUN
));
619 writel(0x88888888, CREG_AXI_M_SLV1(M_AXI_TUN
));
620 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_AXI_TUN
));
621 writel(0x76543210, CREG_AXI_M_OFT1(M_AXI_TUN
));
622 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_AXI_TUN
));
624 writel(0x77777777, CREG_AXI_M_SLV0(M_HDMI_VIDEO
));
625 writel(0x77777777, CREG_AXI_M_SLV1(M_HDMI_VIDEO
));
626 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HDMI_VIDEO
));
627 writel(0x76543210, CREG_AXI_M_OFT1(M_HDMI_VIDEO
));
628 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_HDMI_VIDEO
));
630 writel(0x77777777, CREG_AXI_M_SLV0(M_HDMI_AUDIO
));
631 writel(0x77777777, CREG_AXI_M_SLV1(M_HDMI_AUDIO
));
632 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HDMI_AUDIO
));
633 writel(0x76543210, CREG_AXI_M_OFT1(M_HDMI_AUDIO
));
634 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_HDMI_AUDIO
));
636 writel(0x77777777, CREG_AXI_M_SLV0(M_USB_HOST
));
637 writel(0x77999999, CREG_AXI_M_SLV1(M_USB_HOST
));
638 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_USB_HOST
));
639 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_USB_HOST
));
640 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_USB_HOST
));
642 writel(0x77777777, CREG_AXI_M_SLV0(M_ETHERNET
));
643 writel(0x77999999, CREG_AXI_M_SLV1(M_ETHERNET
));
644 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_ETHERNET
));
645 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_ETHERNET
));
646 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_ETHERNET
));
648 writel(0x77777777, CREG_AXI_M_SLV0(M_SDIO
));
649 writel(0x77999999, CREG_AXI_M_SLV1(M_SDIO
));
650 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_SDIO
));
651 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_SDIO
));
652 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_SDIO
));
654 writel(0x77777777, CREG_AXI_M_SLV0(M_GPU
));
655 writel(0x77777777, CREG_AXI_M_SLV1(M_GPU
));
656 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_GPU
));
657 writel(0x76543210, CREG_AXI_M_OFT1(M_GPU
));
658 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_GPU
));
660 writel(0x77777777, CREG_AXI_M_SLV0(M_DMAC_0
));
661 writel(0x77777777, CREG_AXI_M_SLV1(M_DMAC_0
));
662 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_DMAC_0
));
663 writel(0x76543210, CREG_AXI_M_OFT1(M_DMAC_0
));
664 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_DMAC_0
));
666 writel(0x77777777, CREG_AXI_M_SLV0(M_DMAC_1
));
667 writel(0x77777777, CREG_AXI_M_SLV1(M_DMAC_1
));
668 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_DMAC_1
));
669 writel(0x76543210, CREG_AXI_M_OFT1(M_DMAC_1
));
670 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_DMAC_1
));
672 writel(0x00000000, CREG_AXI_M_SLV0(M_DVFS
));
673 writel(0x60000000, CREG_AXI_M_SLV1(M_DVFS
));
674 writel(0x00000000, CREG_AXI_M_OFT0(M_DVFS
));
675 writel(0x00000000, CREG_AXI_M_OFT1(M_DVFS
));
676 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_DVFS
));
678 writel(0x00000000, CREG_PAE
);
679 writel(UPDATE_VAL
, CREG_PAE_UPDT
);
683 * For HSDK-4xD we do additional AXI bridge tweaking in hsdk_init command:
684 * - we shrink IOC region.
685 * - we configure HS CORE SLV1 aperture depending on haps_apb_location
686 * environment variable.
688 * As we've already configured AXI bridge in init_memory_bridge we don't
689 * do full configuration here but reconfigure changed part.
691 * m master AXI_M_m_SLV0 AXI_M_m_SLV1 AXI_M_m_OFFSET0 AXI_M_m_OFFSET1
692 * 0 HS (CBU) 0x11111111 0x63111111 0xFEDCBA98 0x0E543210 [haps_apb_location = 0]
693 * 0 HS (CBU) 0x11111111 0x61111111 0xFEDCBA98 0x06543210 [haps_apb_location = 1]
694 * 1 HS (RTT) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
695 * 2 AXI Tunnel 0x88888888 0x88888888 0xFEDCBA98 0x76543210
696 * 3 HDMI-VIDEO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
697 * 4 HDMI-ADUIO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
698 * 5 USB-HOST 0x77777777 0x77779999 0xFEDCBA98 0x7654BA98
699 * 6 ETHERNET 0x77777777 0x77779999 0xFEDCBA98 0x7654BA98
700 * 7 SDIO 0x77777777 0x77779999 0xFEDCBA98 0x7654BA98
701 * 8 GPU 0x77777777 0x77777777 0xFEDCBA98 0x76543210
702 * 9 DMAC (port #1) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
703 * 10 DMAC (port #2) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
704 * 11 DVFS 0x00000000 0x60000000 0x00000000 0x00000000
706 void tweak_memory_bridge_cfg(void)
709 * Only HSDK-4xD requre additional AXI bridge tweaking depending on
710 * haps_apb_location environment variable
712 if (!is_board_match_config(T_BOARD_HSDK_4XD
))
715 if (env_common
.haps_apb
.val
) {
716 writel(0x61111111, CREG_AXI_M_SLV1(M_HS_CORE
));
717 writel(0x06543210, CREG_AXI_M_OFT1(M_HS_CORE
));
719 writel(0x63111111, CREG_AXI_M_SLV1(M_HS_CORE
));
720 writel(0x0E543210, CREG_AXI_M_OFT1(M_HS_CORE
));
722 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_HS_CORE
));
724 writel(0x77779999, CREG_AXI_M_SLV1(M_USB_HOST
));
725 writel(0x7654BA98, CREG_AXI_M_OFT1(M_USB_HOST
));
726 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_USB_HOST
));
728 writel(0x77779999, CREG_AXI_M_SLV1(M_ETHERNET
));;
729 writel(0x7654BA98, CREG_AXI_M_OFT1(M_ETHERNET
));
730 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_ETHERNET
));
732 writel(0x77779999, CREG_AXI_M_SLV1(M_SDIO
));
733 writel(0x7654BA98, CREG_AXI_M_OFT1(M_SDIO
));
734 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_SDIO
));
737 static void setup_clocks(void)
741 /* Setup CPU clock */
742 if (env_common
.cpu_freq
.set
) {
743 rate
= env_common
.cpu_freq
.val
;
744 soc_clk_ctl("cpu-clk", &rate
, CLK_ON
| CLK_SET
| CLK_MHZ
);
747 /* Setup TUN clock */
748 if (env_common
.tun_freq
.set
) {
749 rate
= env_common
.tun_freq
.val
;
751 soc_clk_ctl("tun-clk", &rate
, CLK_ON
| CLK_SET
| CLK_MHZ
);
753 soc_clk_ctl("tun-clk", NULL
, CLK_OFF
);
756 if (env_common
.axi_freq
.set
) {
757 rate
= env_common
.axi_freq
.val
;
758 soc_clk_ctl("axi-clk", &rate
, CLK_SET
| CLK_ON
| CLK_MHZ
);
762 static void do_init_cluster(void)
765 * A multi-core ARC HS configuration always includes only one
766 * ARC_AUX_NON_VOLATILE_LIMIT register, which is shared by all the
769 init_cluster_nvlim();
772 tweak_memory_bridge_cfg();
775 static int check_master_cpu_id(void)
777 if (CPU_ID_GET() == MASTER_CPU_ID
)
780 pr_err("u-boot runs on non-master cpu with id: %lu\n", CPU_ID_GET());
785 static noinline
int prepare_cpus(void)
789 ret
= check_master_cpu_id();
793 ret
= envs_process_and_validate(env_map_common
, env_map_core
, is_cpu_used
);
797 printf("CPU start mask is %#x\n", env_common
.core_mask
.val
);
799 do_init_slave_cpus();
800 do_init_master_cpu();
806 static int hsdk_go_run(u32 cpu_start_reg
)
808 /* Cleanup caches, disable interrupts */
811 if (env_common
.halt_on_boot
)
815 * 3 NOPs after FLAG 1 instruction are no longer required for ARCv2
816 * cores but we leave them for gebug purposes.
822 /* Kick chosen slave CPUs */
823 writel(cpu_start_reg
, (void __iomem
*)CREG_CPU_START
);
825 if (is_cpu_used(MASTER_CPU_ID
))
826 ((void (*)(void))(env_core
.entry
[MASTER_CPU_ID
].val
))();
830 pr_err("u-boot still runs on cpu [%ld]\n", CPU_ID_GET());
833 * We will never return after executing our program if master cpu used
834 * otherwise halt master cpu manually.
842 int board_prep_linux(bootm_headers_t
*images
)
847 ret
= envs_read_validate_common(env_map_mask
);
851 /* Rollback to default values */
852 if (!env_common
.core_mask
.set
) {
853 env_common
.core_mask
.val
= ALL_CPU_MASK
;
854 env_common
.core_mask
.set
= true;
857 printf("CPU start mask is %#x\n", env_common
.core_mask
.val
);
859 if (!is_cpu_used(MASTER_CPU_ID
))
860 pr_err("ERR: try to launch linux with CPU[0] disabled! It doesn't work for ARC.\n");
863 * If we want to launch linux on all CPUs we don't need to patch
864 * linux DTB as it is default configuration
866 if (env_common
.core_mask
.val
== ALL_CPU_MASK
)
869 if (!IMAGE_ENABLE_OF_LIBFDT
|| !images
->ft_len
) {
870 pr_err("WARN: core_mask setup will work properly only with external DTB!\n");
874 /* patch '/possible-cpus' property according to cpu mask */
875 ofst
= fdt_path_offset(images
->ft_addr
, "/");
876 sprintf(mask
, "%s%s%s%s",
877 is_cpu_used(0) ? "0," : "",
878 is_cpu_used(1) ? "1," : "",
879 is_cpu_used(2) ? "2," : "",
880 is_cpu_used(3) ? "3," : "");
881 ret
= fdt_setprop_string(images
->ft_addr
, ofst
, "possible-cpus", mask
);
883 * If we failed to patch '/possible-cpus' property we don't need break
884 * linux loading process: kernel will handle it but linux will print
885 * warning like "Timeout: CPU1 FAILED to comeup !!!".
886 * So warn here about error, but return 0 like no error had occurred.
889 pr_err("WARN: failed to patch '/possible-cpus' property, ret=%d\n",
895 void board_jump_and_run(ulong entry
, int zero
, int arch
, uint params
)
897 void (*kernel_entry
)(int zero
, int arch
, uint params
);
900 kernel_entry
= (void (*)(int, int, uint
))entry
;
902 /* Prepare CREG_CPU_START for kicking chosen CPUs */
903 cpu_start_reg
= prepare_cpu_ctart_reg();
905 /* In case of run without hsdk_init */
906 slave_cpu_set_boot_addr(entry
);
908 /* In case of run with hsdk_init */
909 for (u32 i
= 0; i
< NR_CPUS
; i
++) {
910 env_core
.entry
[i
].val
= entry
;
911 env_core
.entry
[i
].set
= true;
913 /* sync cross_cpu struct as we updated core-entry variables */
914 sync_cross_cpu_data();
916 /* Kick chosen slave CPUs */
917 writel(cpu_start_reg
, (void __iomem
*)CREG_CPU_START
);
920 kernel_entry(zero
, arch
, params
);
923 static int hsdk_go_prepare_and_run(void)
925 /* Prepare CREG_CPU_START for kicking chosen CPUs */
926 u32 reg
= prepare_cpu_ctart_reg();
928 if (env_common
.halt_on_boot
)
929 printf("CPU will halt before application start, start application with debugger.\n");
931 return hsdk_go_run(reg
);
934 static int do_hsdk_go(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *const argv
[])
938 if (board_mismatch()) {
939 printf("ERR: U-boot is not configured for this board!\n");
940 return CMD_RET_FAILURE
;
944 * Check for 'halt' parameter. 'halt' = enter halt-mode just before
945 * starting the application; can be used for debug.
948 env_common
.halt_on_boot
= !strcmp(argv
[1], "halt");
949 if (!env_common
.halt_on_boot
) {
950 pr_err("Unrecognised parameter: \'%s\'\n", argv
[1]);
951 return CMD_RET_FAILURE
;
955 ret
= check_master_cpu_id();
959 ret
= envs_process_and_validate(env_map_mask
, env_map_go
, is_cpu_used
);
963 /* sync cross_cpu struct as we updated core-entry variables */
964 sync_cross_cpu_data();
966 ret
= hsdk_go_prepare_and_run();
968 return ret
? CMD_RET_FAILURE
: CMD_RET_SUCCESS
;
972 hsdk_go
, 3, 0, do_hsdk_go
,
973 "Synopsys HSDK specific command",
974 " - Boot stand-alone application on HSDK\n"
975 "hsdk_go halt - Boot stand-alone application on HSDK, halt CPU just before application run\n"
979 * We may simply use static variable here to store init status, but we also want
980 * to avoid the situation when we reload U-boot via MDB after previous
981 * init is done but HW reset (board reset) isn't done. So let's store the
982 * init status in any unused register (i.e CREG_CPU_0_ENTRY) so status will
983 * survive after U-boot is reloaded via MDB.
985 #define INIT_MARKER_REGISTER ((void __iomem *)CREG_CPU_0_ENTRY)
986 /* must be equal to INIT_MARKER_REGISTER reset value */
987 #define INIT_MARKER_PENDING 0
989 static bool init_marker_get(void)
991 return readl(INIT_MARKER_REGISTER
) != INIT_MARKER_PENDING
;
994 static void init_mark_done(void)
996 writel(~INIT_MARKER_PENDING
, INIT_MARKER_REGISTER
);
999 static int do_hsdk_init(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *const argv
[])
1003 if (board_mismatch()) {
1004 printf("ERR: U-boot is not configured for this board!\n");
1005 return CMD_RET_FAILURE
;
1008 /* hsdk_init can be run only once */
1009 if (init_marker_get()) {
1010 printf("HSDK HW is already initialized! Please reset the board if you want to change the configuration.\n");
1011 return CMD_RET_FAILURE
;
1014 ret
= prepare_cpus();
1018 return ret
? CMD_RET_FAILURE
: CMD_RET_SUCCESS
;
1022 hsdk_init
, 1, 0, do_hsdk_init
,
1023 "Synopsys HSDK specific command",
1027 static int do_hsdk_clock_set(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
1032 /* Strip off leading subcommand argument */
1036 envs_cleanup_common(env_map_clock
);
1039 printf("Set clocks to values specified in environment\n");
1040 ret
= envs_read_common(env_map_clock
);
1042 printf("Set clocks to values specified in args\n");
1043 ret
= args_envs_enumerate(env_map_clock
, 2, argc
, argv
);
1047 return CMD_RET_FAILURE
;
1049 ret
= envs_validate_common(env_map_clock
);
1051 return CMD_RET_FAILURE
;
1053 /* Setup clock tree HW */
1056 return CMD_RET_SUCCESS
;
1059 static int do_hsdk_clock_get(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
1064 if (soc_clk_ctl("cpu-clk", &rate
, CLK_GET
| CLK_MHZ
))
1065 return CMD_RET_FAILURE
;
1067 if (env_set_ulong("cpu_freq", rate
))
1068 return CMD_RET_FAILURE
;
1070 if (soc_clk_ctl("tun-clk", &rate
, CLK_GET
| CLK_MHZ
))
1071 return CMD_RET_FAILURE
;
1073 if (env_set_ulong("tun_freq", rate
))
1074 return CMD_RET_FAILURE
;
1076 if (soc_clk_ctl("axi-clk", &rate
, CLK_GET
| CLK_MHZ
))
1077 return CMD_RET_FAILURE
;
1079 if (env_set_ulong("axi_freq", rate
))
1080 return CMD_RET_FAILURE
;
1082 printf("Clock values are saved to environment\n");
1084 return CMD_RET_SUCCESS
;
1087 static int do_hsdk_clock_print(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
1091 soc_clk_ctl("cpu-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1092 soc_clk_ctl("tun-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1093 soc_clk_ctl("axi-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1094 soc_clk_ctl("ddr-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1096 return CMD_RET_SUCCESS
;
1099 static int do_hsdk_clock_print_all(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
1103 * NOTE: as of today we don't use some peripherals like HDMI / EBI
1104 * so we don't want to print their clocks ("hdmi-sys-clk", "hdmi-pll",
1105 * "hdmi-clk", "ebi-clk"). Nevertheless their clock subsystems is fully
1106 * functional and we can print their clocks if it is required
1109 /* CPU clock domain */
1110 soc_clk_ctl("cpu-pll", NULL
, CLK_PRINT
| CLK_MHZ
);
1111 soc_clk_ctl("cpu-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1114 /* SYS clock domain */
1115 soc_clk_ctl("sys-pll", NULL
, CLK_PRINT
| CLK_MHZ
);
1116 soc_clk_ctl("apb-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1117 soc_clk_ctl("axi-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1118 soc_clk_ctl("eth-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1119 soc_clk_ctl("usb-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1120 soc_clk_ctl("sdio-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1121 if (is_board_match_runtime(T_BOARD_HSDK_4XD
))
1122 soc_clk_ctl("hdmi-sys-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1123 soc_clk_ctl("gfx-core-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1124 if (is_board_match_runtime(T_BOARD_HSDK
)) {
1125 soc_clk_ctl("gfx-dma-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1126 soc_clk_ctl("gfx-cfg-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1128 soc_clk_ctl("dmac-core-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1129 soc_clk_ctl("dmac-cfg-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1130 soc_clk_ctl("sdio-ref-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1131 soc_clk_ctl("spi-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1132 soc_clk_ctl("i2c-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1133 /* soc_clk_ctl("ebi-clk", NULL, CLK_PRINT | CLK_MHZ); */
1134 soc_clk_ctl("uart-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1137 /* DDR clock domain */
1138 soc_clk_ctl("ddr-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1141 /* HDMI clock domain */
1142 if (is_board_match_runtime(T_BOARD_HSDK_4XD
)) {
1143 soc_clk_ctl("hdmi-pll", NULL
, CLK_PRINT
| CLK_MHZ
);
1144 soc_clk_ctl("hdmi-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1148 /* TUN clock domain */
1149 soc_clk_ctl("tun-pll", NULL
, CLK_PRINT
| CLK_MHZ
);
1150 soc_clk_ctl("tun-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1151 soc_clk_ctl("rom-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1152 soc_clk_ctl("pwm-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1153 if (is_board_match_runtime(T_BOARD_HSDK_4XD
))
1154 soc_clk_ctl("timer-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1157 return CMD_RET_SUCCESS
;
1160 cmd_tbl_t cmd_hsdk_clock
[] = {
1161 U_BOOT_CMD_MKENT(set
, 3, 0, do_hsdk_clock_set
, "", ""),
1162 U_BOOT_CMD_MKENT(get
, 3, 0, do_hsdk_clock_get
, "", ""),
1163 U_BOOT_CMD_MKENT(print
, 4, 0, do_hsdk_clock_print
, "", ""),
1164 U_BOOT_CMD_MKENT(print_all
, 4, 0, do_hsdk_clock_print_all
, "", ""),
1167 static int do_hsdk_clock(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *const argv
[])
1172 return CMD_RET_USAGE
;
1174 /* Strip off leading 'hsdk_clock' command argument */
1178 c
= find_cmd_tbl(argv
[0], cmd_hsdk_clock
, ARRAY_SIZE(cmd_hsdk_clock
));
1180 return CMD_RET_USAGE
;
1182 return c
->cmd(cmdtp
, flag
, argc
, argv
);
1186 hsdk_clock
, CONFIG_SYS_MAXARGS
, 0, do_hsdk_clock
,
1187 "Synopsys HSDK specific clock command",
1188 "set - Set clock to values specified in environment / command line arguments\n"
1189 "hsdk_clock get - Save clock values to environment\n"
1190 "hsdk_clock print - Print main clock values to console\n"
1191 "hsdk_clock print_all - Print all clock values to console\n"
1195 int board_early_init_f(void)
1198 * Setup AXI apertures unconditionally as we want to have DDR
1199 * in 0x00000000 region when we are kicking slave cpus.
1201 init_memory_bridge();
1204 * Switch SDIO external ciu clock divider from default div-by-8 to
1205 * minimum possible div-by-2.
1207 writel(SDIO_UHS_REG_EXT_DIV_2
, (void __iomem
*)SDIO_UHS_REG_EXT
);
1212 int board_early_init_r(void)
1215 * TODO: Init USB here to be able read environment from USB MSD.
1216 * It can be done with usb_init() call. We can't do it right now
1217 * due to brocken USB IP SW reset and lack of USB IP HW reset in
1218 * linux kernel (if we init USB here we will break USB in linux)
1222 * Flush all d$ as we want to use uncached area with st.di / ld.di
1223 * instructions and we don't want to have any dirty line in L1d$ or SL$
1224 * in this area. It is enough to flush all d$ once here as we access to
1225 * uncached area with regular st (non .di) instruction only when we copy
1226 * data during u-boot relocation.
1230 printf("Relocation Offset is: %08lx\n", gd
->reloc_off
);
1235 int board_late_init(void)
1238 * Populate environment with clock frequency values -
1239 * run hsdk_clock get callback without uboot command run.
1241 do_hsdk_clock_get(NULL
, 0, 0, NULL
);
1246 int checkboard(void)
1250 printf("Board: Synopsys %s\n", board_name(get_board_type_runtime()));
1252 if (board_mismatch())
1253 printf("WARN: U-boot is configured NOT for this board but for %s!\n",
1254 board_name(get_board_type_config()));
1256 reg
= readl(CREG_AXI_M_HS_CORE_BOOT
) & CREG_CORE_BOOT_IMAGE
;
1257 printf("U-boot autostart: %s\n", reg
? "enabled" : "disabled");