1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Synopsys, Inc. All rights reserved.
4 * Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
15 #include <asm/cache.h>
16 #include <asm/global_data.h>
17 #include <linux/bitops.h>
18 #include <linux/delay.h>
19 #include <linux/printk.h>
20 #include <linux/kernel.h>
22 #include <asm/arcregs.h>
23 #include <fdt_support.h>
31 DECLARE_GLOBAL_DATA_PTR
;
33 #define ALL_CPU_MASK GENMASK(NR_CPUS - 1, 0)
34 #define MASTER_CPU_ID 0
35 #define APERTURE_SHIFT 28
37 #define SLAVE_CPU_READY 0x12345678
38 #define BOOTSTAGE_1 1 /* after SP, FP setup, before HW init */
39 #define BOOTSTAGE_2 2 /* after HW init, before self halt */
40 #define BOOTSTAGE_3 3 /* after self halt */
41 #define BOOTSTAGE_4 4 /* before app launch */
42 #define BOOTSTAGE_5 5 /* after app launch, unreachable */
44 #define RESET_VECTOR_ADDR 0x0
46 #define CREG_BASE (ARC_PERIPHERAL_BASE + 0x1000)
47 #define CREG_CPU_START (CREG_BASE + 0x400)
48 #define CREG_CPU_START_MASK 0xF
49 #define CREG_CPU_START_POL BIT(4)
51 #define CREG_CORE_BOOT_IMAGE GENMASK(5, 4)
53 #define CREG_CPU_0_ENTRY (CREG_BASE + 0x404)
55 #define SDIO_BASE (ARC_PERIPHERAL_BASE + 0xA000)
56 #define SDIO_UHS_REG_EXT (SDIO_BASE + 0x108)
57 #define SDIO_UHS_REG_EXT_DIV_2 (2 << 30)
59 /* Uncached access macros */
60 #define arc_read_uncached_32(ptr) \
63 __asm__ __volatile__( \
64 " ld.di %0, [%1] \n" \
70 #define arc_write_uncached_32(ptr, data)\
72 __asm__ __volatile__( \
73 " st.di %0, [%1] \n" \
75 : "r"(data), "r"(ptr)); \
78 struct hsdk_env_core_ctl
{
79 u32_env entry
[NR_CPUS
];
80 u32_env iccm
[NR_CPUS
];
81 u32_env dccm
[NR_CPUS
];
84 struct hsdk_env_common_ctl
{
99 * Uncached cross-cpu structure. All CPUs must access to this structure fields
100 * only with arc_read_uncached_32() / arc_write_uncached_32() accessors (which
101 * implement ld.di / st.di instructions). Simultaneous cached and uncached
102 * access to this area will lead to data loss.
103 * We flush all data caches in board_early_init_r() as we don't want to have
104 * any dirty line in L1d$ or SL$ in this area.
106 struct hsdk_cross_cpu
{
107 /* slave CPU ready flag */
109 /* address of the area, which can be used for stack by slave CPU */
111 /* slave CPU status - bootstage number */
115 * Slave CPU data - it is copy of corresponding fields in
116 * hsdk_env_core_ctl and hsdk_env_common_ctl structures which are
117 * required for slave CPUs initialization.
118 * This fields can be populated by copying from hsdk_env_core_ctl
119 * and hsdk_env_common_ctl structures with sync_cross_cpu_data()
130 u8 cache_padding
[ARCH_DMA_MINALIGN
];
131 } __aligned(ARCH_DMA_MINALIGN
);
133 /* Place for slave CPUs temporary stack */
134 static u32 slave_stack
[256 * NR_CPUS
] __aligned(ARCH_DMA_MINALIGN
);
136 static struct hsdk_env_common_ctl env_common
= {};
137 static struct hsdk_env_core_ctl env_core
= {};
138 static struct hsdk_cross_cpu cross_cpu_data
;
140 static const struct env_map_common env_map_common
[] = {
141 { "core_mask", ENV_HEX
, true, 0x1, 0xF, &env_common
.core_mask
},
142 { "non_volatile_limit", ENV_HEX
, true, 0, 0xF, &env_common
.nvlim
},
143 { "icache_ena", ENV_HEX
, true, 0, 1, &env_common
.icache
},
144 { "dcache_ena", ENV_HEX
, true, 0, 1, &env_common
.dcache
},
145 #if defined(CONFIG_BOARD_HSDK_4XD)
146 { "l2_cache_ena", ENV_HEX
, true, 0, 1, &env_common
.l2_cache
},
147 { "csm_location", ENV_HEX
, true, 0, NO_CCM
, &env_common
.csm_location
},
148 { "haps_apb_location", ENV_HEX
, true, 0, 1, &env_common
.haps_apb
},
149 #endif /* CONFIG_BOARD_HSDK_4XD */
153 static const struct env_map_common env_map_clock
[] = {
154 { "cpu_freq", ENV_DEC
, false, 100, 1000, &env_common
.cpu_freq
},
155 { "axi_freq", ENV_DEC
, false, 200, 800, &env_common
.axi_freq
},
156 { "tun_freq", ENV_DEC
, false, 0, 150, &env_common
.tun_freq
},
160 static const struct env_map_percpu env_map_core
[] = {
161 { "core_iccm", ENV_HEX
, true, {NO_CCM
, 0, NO_CCM
, 0}, {NO_CCM
, 0xF, NO_CCM
, 0xF}, &env_core
.iccm
},
162 { "core_dccm", ENV_HEX
, true, {NO_CCM
, 0, NO_CCM
, 0}, {NO_CCM
, 0xF, NO_CCM
, 0xF}, &env_core
.dccm
},
166 static const struct env_map_common env_map_mask
[] = {
167 { "core_mask", ENV_HEX
, false, 0x1, 0xF, &env_common
.core_mask
},
171 static const struct env_map_percpu env_map_go
[] = {
172 { "core_entry", ENV_HEX
, true, {0, 0, 0, 0}, {U32_MAX
, U32_MAX
, U32_MAX
, U32_MAX
}, &env_core
.entry
},
182 static inline enum board_type
get_board_type_runtime(void)
184 u32 arc_id
= read_aux_reg(ARC_AUX_IDENTITY
) & 0xFF;
188 else if (arc_id
== 0x54)
189 return T_BOARD_HSDK_4XD
;
194 static inline enum board_type
get_board_type_config(void)
196 if (IS_ENABLED(CONFIG_BOARD_HSDK
))
198 else if (IS_ENABLED(CONFIG_BOARD_HSDK_4XD
))
199 return T_BOARD_HSDK_4XD
;
204 static bool is_board_match_runtime(enum board_type type_req
)
206 return get_board_type_runtime() == type_req
;
209 static bool is_board_match_config(enum board_type type_req
)
211 return get_board_type_config() == type_req
;
214 static const char * board_name(enum board_type type
)
218 return "ARC HS Development Kit";
219 case T_BOARD_HSDK_4XD
:
220 return "ARC HS4x/HS4xD Development Kit";
226 static bool board_mismatch(void)
228 return get_board_type_config() != get_board_type_runtime();
231 static void sync_cross_cpu_data(void)
235 for (u32 i
= 0; i
< NR_CPUS
; i
++) {
236 value
= env_core
.entry
[i
].val
;
237 arc_write_uncached_32(&cross_cpu_data
.entry
[i
], value
);
240 for (u32 i
= 0; i
< NR_CPUS
; i
++) {
241 value
= env_core
.iccm
[i
].val
;
242 arc_write_uncached_32(&cross_cpu_data
.iccm
[i
], value
);
245 for (u32 i
= 0; i
< NR_CPUS
; i
++) {
246 value
= env_core
.dccm
[i
].val
;
247 arc_write_uncached_32(&cross_cpu_data
.dccm
[i
], value
);
250 value
= env_common
.core_mask
.val
;
251 arc_write_uncached_32(&cross_cpu_data
.core_mask
, value
);
253 value
= env_common
.icache
.val
;
254 arc_write_uncached_32(&cross_cpu_data
.icache
, value
);
256 value
= env_common
.dcache
.val
;
257 arc_write_uncached_32(&cross_cpu_data
.dcache
, value
);
260 /* Can be used only on master CPU */
261 static bool is_cpu_used(u32 cpu_id
)
263 return !!(env_common
.core_mask
.val
& BIT(cpu_id
));
266 /* TODO: add ICCM BCR and DCCM BCR runtime check */
267 static void init_slave_cpu_func(u32 core
)
271 /* Remap ICCM to another memory region if it exists */
272 val
= arc_read_uncached_32(&cross_cpu_data
.iccm
[core
]);
274 write_aux_reg(ARC_AUX_ICCM_BASE
, val
<< APERTURE_SHIFT
);
276 /* Remap DCCM to another memory region if it exists */
277 val
= arc_read_uncached_32(&cross_cpu_data
.dccm
[core
]);
279 write_aux_reg(ARC_AUX_DCCM_BASE
, val
<< APERTURE_SHIFT
);
281 if (arc_read_uncached_32(&cross_cpu_data
.icache
))
286 if (arc_read_uncached_32(&cross_cpu_data
.dcache
))
292 static void init_cluster_nvlim(void)
294 u32 val
= env_common
.nvlim
.val
<< APERTURE_SHIFT
;
297 write_aux_reg(ARC_AUX_NON_VOLATILE_LIMIT
, val
);
298 /* AUX_AUX_CACHE_LIMIT reg is missing starting from HS48 */
299 if (is_board_match_runtime(T_BOARD_HSDK
))
300 write_aux_reg(AUX_AUX_CACHE_LIMIT
, val
);
301 flush_n_invalidate_dcache_all();
304 static void init_cluster_slc(void)
306 /* ARC HS38 doesn't support SLC disabling */
307 if (!is_board_match_config(T_BOARD_HSDK_4XD
))
310 if (env_common
.l2_cache
.val
)
316 #define CREG_CSM_BASE (CREG_BASE + 0x210)
318 static void init_cluster_csm(void)
320 /* ARC HS38 in HSDK SoC doesn't include CSM */
321 if (!is_board_match_config(T_BOARD_HSDK_4XD
))
324 if (env_common
.csm_location
.val
== NO_CCM
) {
325 write_aux_reg(ARC_AUX_CSM_ENABLE
, 0);
328 * CSM base address is 256kByte aligned but we allow to map
329 * CSM only to aperture start (256MByte aligned)
330 * The field in CREG_CSM_BASE is in 17:2 bits itself so we need
333 u32 csm_base
= (env_common
.csm_location
.val
* SZ_1K
) << 2;
335 write_aux_reg(ARC_AUX_CSM_ENABLE
, 1);
336 writel(csm_base
, (void __iomem
*)CREG_CSM_BASE
);
340 static void init_master_icache(void)
342 if (icache_status()) {
343 /* I$ is enabled - we need to disable it */
344 if (!env_common
.icache
.val
)
347 /* I$ is disabled - we need to enable it */
348 if (env_common
.icache
.val
) {
351 /* invalidate I$ right after enable */
352 invalidate_icache_all();
357 static void init_master_dcache(void)
359 if (dcache_status()) {
360 /* D$ is enabled - we need to disable it */
361 if (!env_common
.dcache
.val
)
364 /* D$ is disabled - we need to enable it */
365 if (env_common
.dcache
.val
)
368 /* TODO: probably we need ti invalidate D$ right after enable */
372 static int cleanup_before_go(void)
374 disable_interrupts();
375 sync_n_cleanup_cache_all();
380 void slave_cpu_set_boot_addr(u32 addr
)
382 /* All cores have reset vector pointing to 0 */
383 writel(addr
, (void __iomem
*)RESET_VECTOR_ADDR
);
385 /* Make sure other cores see written value in memory */
386 sync_n_cleanup_cache_all();
389 static inline void halt_this_cpu(void)
391 __builtin_arc_flag(1);
394 static u32
get_masked_cpu_ctart_reg(void)
396 int cmd
= readl((void __iomem
*)CREG_CPU_START
);
399 * Quirk for HSDK-4xD - due to HW issues HSDK can use any pulse polarity
400 * and HSDK-4xD require active low polarity of cpu_start pulse.
402 cmd
&= ~CREG_CPU_START_POL
;
404 cmd
&= ~CREG_CPU_START_MASK
;
409 static void smp_kick_cpu_x(u32 cpu_id
)
413 if (cpu_id
> NR_CPUS
)
416 cmd
= get_masked_cpu_ctart_reg();
417 cmd
|= (1 << cpu_id
);
418 writel(cmd
, (void __iomem
*)CREG_CPU_START
);
421 static u32
prepare_cpu_ctart_reg(void)
423 return get_masked_cpu_ctart_reg() | env_common
.core_mask
.val
;
426 /* slave CPU entry for configuration */
427 __attribute__((naked
, noreturn
, flatten
)) noinline
void hsdk_core_init_f(void)
429 __asm__
__volatile__(
434 : "r" (&cross_cpu_data
.stack_ptr
));
436 invalidate_icache_all();
438 arc_write_uncached_32(&cross_cpu_data
.status
[CPU_ID_GET()], BOOTSTAGE_1
);
439 init_slave_cpu_func(CPU_ID_GET());
441 arc_write_uncached_32(&cross_cpu_data
.ready_flag
, SLAVE_CPU_READY
);
442 arc_write_uncached_32(&cross_cpu_data
.status
[CPU_ID_GET()], BOOTSTAGE_2
);
444 /* Halt the processor until the master kick us again */
448 * 3 NOPs after FLAG 1 instruction are no longer required for ARCv2
449 * cores but we leave them for gebug purposes.
455 arc_write_uncached_32(&cross_cpu_data
.status
[CPU_ID_GET()], BOOTSTAGE_3
);
457 /* get the updated entry - invalidate i$ */
458 invalidate_icache_all();
460 arc_write_uncached_32(&cross_cpu_data
.status
[CPU_ID_GET()], BOOTSTAGE_4
);
462 /* Run our program */
463 ((void (*)(void))(arc_read_uncached_32(&cross_cpu_data
.entry
[CPU_ID_GET()])))();
465 /* This bootstage is unreachable as we don't return from app we launch */
466 arc_write_uncached_32(&cross_cpu_data
.status
[CPU_ID_GET()], BOOTSTAGE_5
);
468 /* Something went terribly wrong */
473 static void clear_cross_cpu_data(void)
475 arc_write_uncached_32(&cross_cpu_data
.ready_flag
, 0);
476 arc_write_uncached_32(&cross_cpu_data
.stack_ptr
, 0);
478 for (u32 i
= 0; i
< NR_CPUS
; i
++)
479 arc_write_uncached_32(&cross_cpu_data
.status
[i
], 0);
482 static noinline
void do_init_slave_cpu(u32 cpu_id
)
484 /* attempts number for check clave CPU ready_flag */
486 u32 stack_ptr
= (u32
)(slave_stack
+ (64 * cpu_id
));
488 if (cpu_id
>= NR_CPUS
)
491 arc_write_uncached_32(&cross_cpu_data
.ready_flag
, 0);
493 /* Use global unique place for each slave cpu stack */
494 arc_write_uncached_32(&cross_cpu_data
.stack_ptr
, stack_ptr
);
496 debug("CPU %u: stack pool base: %p\n", cpu_id
, slave_stack
);
497 debug("CPU %u: current slave stack base: %x\n", cpu_id
, stack_ptr
);
498 slave_cpu_set_boot_addr((u32
)hsdk_core_init_f
);
500 smp_kick_cpu_x(cpu_id
);
502 debug("CPU %u: cross-cpu flag: %x [before timeout]\n", cpu_id
,
503 arc_read_uncached_32(&cross_cpu_data
.ready_flag
));
505 while (!arc_read_uncached_32(&cross_cpu_data
.ready_flag
) && attempts
--)
508 /* Just to be sure that slave cpu is halted after it set ready_flag */
512 * Only print error here if we reach timeout as there is no option to
513 * halt slave cpu (or check that slave cpu is halted)
516 pr_err("CPU %u is not responding after init!\n", cpu_id
);
518 /* Check current stage of slave cpu */
519 if (arc_read_uncached_32(&cross_cpu_data
.status
[cpu_id
]) != BOOTSTAGE_2
)
520 pr_err("CPU %u status is unexpected: %d\n", cpu_id
,
521 arc_read_uncached_32(&cross_cpu_data
.status
[cpu_id
]));
523 debug("CPU %u: cross-cpu flag: %x [after timeout]\n", cpu_id
,
524 arc_read_uncached_32(&cross_cpu_data
.ready_flag
));
525 debug("CPU %u: status: %d [after timeout]\n", cpu_id
,
526 arc_read_uncached_32(&cross_cpu_data
.status
[cpu_id
]));
529 static void do_init_slave_cpus(void)
531 clear_cross_cpu_data();
532 sync_cross_cpu_data();
534 debug("cross_cpu_data location: %#x\n", (u32
)&cross_cpu_data
);
536 for (u32 i
= MASTER_CPU_ID
+ 1; i
< NR_CPUS
; i
++)
538 do_init_slave_cpu(i
);
541 static void do_init_master_cpu(void)
544 * Setup master caches even if master isn't used as we want to use
545 * same cache configuration on all running CPUs
547 init_master_icache();
548 init_master_dcache();
551 enum hsdk_axi_masters
{
569 * m master AXI_M_m_SLV0 AXI_M_m_SLV1 AXI_M_m_OFFSET0 AXI_M_m_OFFSET1
570 * 0 HS (CBU) 0x11111111 0x63111111 0xFEDCBA98 0x0E543210
571 * 1 HS (RTT) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
572 * 2 AXI Tunnel 0x88888888 0x88888888 0xFEDCBA98 0x76543210
573 * 3 HDMI-VIDEO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
574 * 4 HDMI-ADUIO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
575 * 5 USB-HOST 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
576 * 6 ETHERNET 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
577 * 7 SDIO 0x77777777 0x77999999 0xFEDCBA98 0x76DCBA98
578 * 8 GPU 0x77777777 0x77777777 0xFEDCBA98 0x76543210
579 * 9 DMAC (port #1) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
580 * 10 DMAC (port #2) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
581 * 11 DVFS 0x00000000 0x60000000 0x00000000 0x00000000
583 * Please read ARC HS Development IC Specification, section 17.2 for more
584 * information about apertures configuration.
585 * NOTE: we intentionally modify default settings in U-Boot. Default settings
586 * are specified in "Table 111 CREG Address Decoder register reset values".
589 #define CREG_AXI_M_SLV0(m) ((void __iomem *)(CREG_BASE + 0x020 * (m)))
590 #define CREG_AXI_M_SLV1(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x004))
591 #define CREG_AXI_M_OFT0(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x008))
592 #define CREG_AXI_M_OFT1(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x00C))
593 #define CREG_AXI_M_UPDT(m) ((void __iomem *)(CREG_BASE + 0x020 * (m) + 0x014))
595 #define CREG_AXI_M_HS_CORE_BOOT ((void __iomem *)(CREG_BASE + 0x010))
597 #define CREG_PAE ((void __iomem *)(CREG_BASE + 0x180))
598 #define CREG_PAE_UPDT ((void __iomem *)(CREG_BASE + 0x194))
600 void init_memory_bridge(void)
605 * M_HS_CORE has one unic register - BOOT.
606 * We need to clean boot mirror (BOOT[1:0]) bits in them.
608 reg
= readl(CREG_AXI_M_HS_CORE_BOOT
) & (~0x3);
609 writel(reg
, CREG_AXI_M_HS_CORE_BOOT
);
610 writel(0x11111111, CREG_AXI_M_SLV0(M_HS_CORE
));
611 writel(0x63111111, CREG_AXI_M_SLV1(M_HS_CORE
));
612 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HS_CORE
));
613 writel(0x0E543210, CREG_AXI_M_OFT1(M_HS_CORE
));
614 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_HS_CORE
));
616 writel(0x77777777, CREG_AXI_M_SLV0(M_HS_RTT
));
617 writel(0x77777777, CREG_AXI_M_SLV1(M_HS_RTT
));
618 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HS_RTT
));
619 writel(0x76543210, CREG_AXI_M_OFT1(M_HS_RTT
));
620 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_HS_RTT
));
622 writel(0x88888888, CREG_AXI_M_SLV0(M_AXI_TUN
));
623 writel(0x88888888, CREG_AXI_M_SLV1(M_AXI_TUN
));
624 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_AXI_TUN
));
625 writel(0x76543210, CREG_AXI_M_OFT1(M_AXI_TUN
));
626 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_AXI_TUN
));
628 writel(0x77777777, CREG_AXI_M_SLV0(M_HDMI_VIDEO
));
629 writel(0x77777777, CREG_AXI_M_SLV1(M_HDMI_VIDEO
));
630 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HDMI_VIDEO
));
631 writel(0x76543210, CREG_AXI_M_OFT1(M_HDMI_VIDEO
));
632 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_HDMI_VIDEO
));
634 writel(0x77777777, CREG_AXI_M_SLV0(M_HDMI_AUDIO
));
635 writel(0x77777777, CREG_AXI_M_SLV1(M_HDMI_AUDIO
));
636 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_HDMI_AUDIO
));
637 writel(0x76543210, CREG_AXI_M_OFT1(M_HDMI_AUDIO
));
638 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_HDMI_AUDIO
));
640 writel(0x77777777, CREG_AXI_M_SLV0(M_USB_HOST
));
641 writel(0x77999999, CREG_AXI_M_SLV1(M_USB_HOST
));
642 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_USB_HOST
));
643 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_USB_HOST
));
644 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_USB_HOST
));
646 writel(0x77777777, CREG_AXI_M_SLV0(M_ETHERNET
));
647 writel(0x77999999, CREG_AXI_M_SLV1(M_ETHERNET
));
648 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_ETHERNET
));
649 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_ETHERNET
));
650 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_ETHERNET
));
652 writel(0x77777777, CREG_AXI_M_SLV0(M_SDIO
));
653 writel(0x77999999, CREG_AXI_M_SLV1(M_SDIO
));
654 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_SDIO
));
655 writel(0x76DCBA98, CREG_AXI_M_OFT1(M_SDIO
));
656 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_SDIO
));
658 writel(0x77777777, CREG_AXI_M_SLV0(M_GPU
));
659 writel(0x77777777, CREG_AXI_M_SLV1(M_GPU
));
660 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_GPU
));
661 writel(0x76543210, CREG_AXI_M_OFT1(M_GPU
));
662 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_GPU
));
664 writel(0x77777777, CREG_AXI_M_SLV0(M_DMAC_0
));
665 writel(0x77777777, CREG_AXI_M_SLV1(M_DMAC_0
));
666 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_DMAC_0
));
667 writel(0x76543210, CREG_AXI_M_OFT1(M_DMAC_0
));
668 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_DMAC_0
));
670 writel(0x77777777, CREG_AXI_M_SLV0(M_DMAC_1
));
671 writel(0x77777777, CREG_AXI_M_SLV1(M_DMAC_1
));
672 writel(0xFEDCBA98, CREG_AXI_M_OFT0(M_DMAC_1
));
673 writel(0x76543210, CREG_AXI_M_OFT1(M_DMAC_1
));
674 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_DMAC_1
));
676 writel(0x00000000, CREG_AXI_M_SLV0(M_DVFS
));
677 writel(0x60000000, CREG_AXI_M_SLV1(M_DVFS
));
678 writel(0x00000000, CREG_AXI_M_OFT0(M_DVFS
));
679 writel(0x00000000, CREG_AXI_M_OFT1(M_DVFS
));
680 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_DVFS
));
682 writel(0x00000000, CREG_PAE
);
683 writel(UPDATE_VAL
, CREG_PAE_UPDT
);
687 * For HSDK-4xD we do additional AXI bridge tweaking in hsdk_init command:
688 * - we shrink IOC region.
689 * - we configure HS CORE SLV1 aperture depending on haps_apb_location
690 * environment variable.
692 * As we've already configured AXI bridge in init_memory_bridge we don't
693 * do full configuration here but reconfigure changed part.
695 * m master AXI_M_m_SLV0 AXI_M_m_SLV1 AXI_M_m_OFFSET0 AXI_M_m_OFFSET1
696 * 0 HS (CBU) 0x11111111 0x63111111 0xFEDCBA98 0x0E543210 [haps_apb_location = 0]
697 * 0 HS (CBU) 0x11111111 0x61111111 0xFEDCBA98 0x06543210 [haps_apb_location = 1]
698 * 1 HS (RTT) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
699 * 2 AXI Tunnel 0x88888888 0x88888888 0xFEDCBA98 0x76543210
700 * 3 HDMI-VIDEO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
701 * 4 HDMI-ADUIO 0x77777777 0x77777777 0xFEDCBA98 0x76543210
702 * 5 USB-HOST 0x77777777 0x77779999 0xFEDCBA98 0x7654BA98
703 * 6 ETHERNET 0x77777777 0x77779999 0xFEDCBA98 0x7654BA98
704 * 7 SDIO 0x77777777 0x77779999 0xFEDCBA98 0x7654BA98
705 * 8 GPU 0x77777777 0x77777777 0xFEDCBA98 0x76543210
706 * 9 DMAC (port #1) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
707 * 10 DMAC (port #2) 0x77777777 0x77777777 0xFEDCBA98 0x76543210
708 * 11 DVFS 0x00000000 0x60000000 0x00000000 0x00000000
710 void tweak_memory_bridge_cfg(void)
713 * Only HSDK-4xD requre additional AXI bridge tweaking depending on
714 * haps_apb_location environment variable
716 if (!is_board_match_config(T_BOARD_HSDK_4XD
))
719 if (env_common
.haps_apb
.val
) {
720 writel(0x61111111, CREG_AXI_M_SLV1(M_HS_CORE
));
721 writel(0x06543210, CREG_AXI_M_OFT1(M_HS_CORE
));
723 writel(0x63111111, CREG_AXI_M_SLV1(M_HS_CORE
));
724 writel(0x0E543210, CREG_AXI_M_OFT1(M_HS_CORE
));
726 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_HS_CORE
));
728 writel(0x77779999, CREG_AXI_M_SLV1(M_USB_HOST
));
729 writel(0x7654BA98, CREG_AXI_M_OFT1(M_USB_HOST
));
730 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_USB_HOST
));
732 writel(0x77779999, CREG_AXI_M_SLV1(M_ETHERNET
));;
733 writel(0x7654BA98, CREG_AXI_M_OFT1(M_ETHERNET
));
734 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_ETHERNET
));
736 writel(0x77779999, CREG_AXI_M_SLV1(M_SDIO
));
737 writel(0x7654BA98, CREG_AXI_M_OFT1(M_SDIO
));
738 writel(UPDATE_VAL
, CREG_AXI_M_UPDT(M_SDIO
));
741 static void setup_clocks(void)
745 /* Setup CPU clock */
746 if (env_common
.cpu_freq
.set
) {
747 rate
= env_common
.cpu_freq
.val
;
748 soc_clk_ctl("cpu-clk", &rate
, CLK_ON
| CLK_SET
| CLK_MHZ
);
751 /* Setup TUN clock */
752 if (env_common
.tun_freq
.set
) {
753 rate
= env_common
.tun_freq
.val
;
755 soc_clk_ctl("tun-clk", &rate
, CLK_ON
| CLK_SET
| CLK_MHZ
);
757 soc_clk_ctl("tun-clk", NULL
, CLK_OFF
);
760 if (env_common
.axi_freq
.set
) {
761 rate
= env_common
.axi_freq
.val
;
762 soc_clk_ctl("axi-clk", &rate
, CLK_SET
| CLK_ON
| CLK_MHZ
);
766 static void do_init_cluster(void)
769 * A multi-core ARC HS configuration always includes only one
770 * ARC_AUX_NON_VOLATILE_LIMIT register, which is shared by all the
773 init_cluster_nvlim();
776 tweak_memory_bridge_cfg();
779 static int check_master_cpu_id(void)
781 if (CPU_ID_GET() == MASTER_CPU_ID
)
784 pr_err("u-boot runs on non-master cpu with id: %lu\n", CPU_ID_GET());
789 static noinline
int prepare_cpus(void)
793 ret
= check_master_cpu_id();
797 ret
= envs_process_and_validate(env_map_common
, env_map_core
, is_cpu_used
);
801 printf("CPU start mask is %#x\n", env_common
.core_mask
.val
);
803 do_init_slave_cpus();
804 do_init_master_cpu();
810 static int hsdk_go_run(u32 cpu_start_reg
)
812 /* Cleanup caches, disable interrupts */
815 if (env_common
.halt_on_boot
)
819 * 3 NOPs after FLAG 1 instruction are no longer required for ARCv2
820 * cores but we leave them for gebug purposes.
826 /* Kick chosen slave CPUs */
827 writel(cpu_start_reg
, (void __iomem
*)CREG_CPU_START
);
829 if (is_cpu_used(MASTER_CPU_ID
))
830 ((void (*)(void))(env_core
.entry
[MASTER_CPU_ID
].val
))();
834 pr_err("u-boot still runs on cpu [%ld]\n", CPU_ID_GET());
837 * We will never return after executing our program if master cpu used
838 * otherwise halt master cpu manually.
846 int board_prep_linux(struct bootm_headers
*images
)
851 ret
= envs_read_validate_common(env_map_mask
);
855 /* Rollback to default values */
856 if (!env_common
.core_mask
.set
) {
857 env_common
.core_mask
.val
= ALL_CPU_MASK
;
858 env_common
.core_mask
.set
= true;
861 printf("CPU start mask is %#x\n", env_common
.core_mask
.val
);
863 if (!is_cpu_used(MASTER_CPU_ID
))
864 pr_err("ERR: try to launch linux with CPU[0] disabled! It doesn't work for ARC.\n");
867 * If we want to launch linux on all CPUs we don't need to patch
868 * linux DTB as it is default configuration
870 if (env_common
.core_mask
.val
== ALL_CPU_MASK
)
873 if (!CONFIG_IS_ENABLED(OF_LIBFDT
) || !images
->ft_len
) {
874 pr_err("WARN: core_mask setup will work properly only with external DTB!\n");
878 /* patch '/possible-cpus' property according to cpu mask */
879 ofst
= fdt_path_offset(images
->ft_addr
, "/");
880 sprintf(mask
, "%s%s%s%s",
881 is_cpu_used(0) ? "0," : "",
882 is_cpu_used(1) ? "1," : "",
883 is_cpu_used(2) ? "2," : "",
884 is_cpu_used(3) ? "3," : "");
885 ret
= fdt_setprop_string(images
->ft_addr
, ofst
, "possible-cpus", mask
);
887 * If we failed to patch '/possible-cpus' property we don't need break
888 * linux loading process: kernel will handle it but linux will print
889 * warning like "Timeout: CPU1 FAILED to comeup !!!".
890 * So warn here about error, but return 0 like no error had occurred.
893 pr_err("WARN: failed to patch '/possible-cpus' property, ret=%d\n",
899 void board_jump_and_run(ulong entry
, int zero
, int arch
, uint params
)
901 void (*kernel_entry
)(int zero
, int arch
, uint params
);
904 kernel_entry
= (void (*)(int, int, uint
))entry
;
906 /* Prepare CREG_CPU_START for kicking chosen CPUs */
907 cpu_start_reg
= prepare_cpu_ctart_reg();
909 /* In case of run without hsdk_init */
910 slave_cpu_set_boot_addr(entry
);
912 /* In case of run with hsdk_init */
913 for (u32 i
= 0; i
< NR_CPUS
; i
++) {
914 env_core
.entry
[i
].val
= entry
;
915 env_core
.entry
[i
].set
= true;
917 /* sync cross_cpu struct as we updated core-entry variables */
918 sync_cross_cpu_data();
920 /* Kick chosen slave CPUs */
921 writel(cpu_start_reg
, (void __iomem
*)CREG_CPU_START
);
924 kernel_entry(zero
, arch
, params
);
927 static int hsdk_go_prepare_and_run(void)
929 /* Prepare CREG_CPU_START for kicking chosen CPUs */
930 u32 reg
= prepare_cpu_ctart_reg();
932 if (env_common
.halt_on_boot
)
933 printf("CPU will halt before application start, start application with debugger.\n");
935 return hsdk_go_run(reg
);
938 static int do_hsdk_go(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
943 if (board_mismatch()) {
944 printf("ERR: U-Boot is not configured for this board!\n");
945 return CMD_RET_FAILURE
;
949 * Check for 'halt' parameter. 'halt' = enter halt-mode just before
950 * starting the application; can be used for debug.
953 env_common
.halt_on_boot
= !strcmp(argv
[1], "halt");
954 if (!env_common
.halt_on_boot
) {
955 pr_err("Unrecognised parameter: \'%s\'\n", argv
[1]);
956 return CMD_RET_FAILURE
;
960 ret
= check_master_cpu_id();
964 ret
= envs_process_and_validate(env_map_mask
, env_map_go
, is_cpu_used
);
968 /* sync cross_cpu struct as we updated core-entry variables */
969 sync_cross_cpu_data();
971 ret
= hsdk_go_prepare_and_run();
973 return ret
? CMD_RET_FAILURE
: CMD_RET_SUCCESS
;
977 hsdk_go
, 3, 0, do_hsdk_go
,
978 "Synopsys HSDK specific command",
979 " - Boot stand-alone application on HSDK\n"
980 "hsdk_go halt - Boot stand-alone application on HSDK, halt CPU just before application run\n"
984 * We may simply use static variable here to store init status, but we also want
985 * to avoid the situation when we reload U-Boot via MDB after previous
986 * init is done but HW reset (board reset) isn't done. So let's store the
987 * init status in any unused register (i.e CREG_CPU_0_ENTRY) so status will
988 * survive after U-Boot is reloaded via MDB.
990 #define INIT_MARKER_REGISTER ((void __iomem *)CREG_CPU_0_ENTRY)
991 /* must be equal to INIT_MARKER_REGISTER reset value */
992 #define INIT_MARKER_PENDING 0
994 static bool init_marker_get(void)
996 return readl(INIT_MARKER_REGISTER
) != INIT_MARKER_PENDING
;
999 static void init_mark_done(void)
1001 writel(~INIT_MARKER_PENDING
, INIT_MARKER_REGISTER
);
1004 static int do_hsdk_init(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
1009 if (board_mismatch()) {
1010 printf("ERR: U-Boot is not configured for this board!\n");
1011 return CMD_RET_FAILURE
;
1014 /* hsdk_init can be run only once */
1015 if (init_marker_get()) {
1016 printf("HSDK HW is already initialized! Please reset the board if you want to change the configuration.\n");
1017 return CMD_RET_FAILURE
;
1020 ret
= prepare_cpus();
1024 return ret
? CMD_RET_FAILURE
: CMD_RET_SUCCESS
;
1028 hsdk_init
, 1, 0, do_hsdk_init
,
1029 "Synopsys HSDK specific command",
1033 static int do_hsdk_clock_set(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
1038 /* Strip off leading subcommand argument */
1042 envs_cleanup_common(env_map_clock
);
1045 printf("Set clocks to values specified in environment\n");
1046 ret
= envs_read_common(env_map_clock
);
1048 printf("Set clocks to values specified in args\n");
1049 ret
= args_envs_enumerate(env_map_clock
, 2, argc
, argv
);
1053 return CMD_RET_FAILURE
;
1055 ret
= envs_validate_common(env_map_clock
);
1057 return CMD_RET_FAILURE
;
1059 /* Setup clock tree HW */
1062 return CMD_RET_SUCCESS
;
1065 static int do_hsdk_clock_get(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
1070 if (soc_clk_ctl("cpu-clk", &rate
, CLK_GET
| CLK_MHZ
))
1071 return CMD_RET_FAILURE
;
1073 if (env_set_ulong("cpu_freq", rate
))
1074 return CMD_RET_FAILURE
;
1076 if (soc_clk_ctl("tun-clk", &rate
, CLK_GET
| CLK_MHZ
))
1077 return CMD_RET_FAILURE
;
1079 if (env_set_ulong("tun_freq", rate
))
1080 return CMD_RET_FAILURE
;
1082 if (soc_clk_ctl("axi-clk", &rate
, CLK_GET
| CLK_MHZ
))
1083 return CMD_RET_FAILURE
;
1085 if (env_set_ulong("axi_freq", rate
))
1086 return CMD_RET_FAILURE
;
1088 printf("Clock values are saved to environment\n");
1090 return CMD_RET_SUCCESS
;
1093 static int do_hsdk_clock_print(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
1097 soc_clk_ctl("cpu-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1098 soc_clk_ctl("tun-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1099 soc_clk_ctl("axi-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1100 soc_clk_ctl("ddr-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1102 return CMD_RET_SUCCESS
;
1105 static int do_hsdk_clock_print_all(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
1109 * NOTE: as of today we don't use some peripherals like HDMI / EBI
1110 * so we don't want to print their clocks ("hdmi-sys-clk", "hdmi-pll",
1111 * "hdmi-clk", "ebi-clk"). Nevertheless their clock subsystems is fully
1112 * functional and we can print their clocks if it is required
1115 /* CPU clock domain */
1116 soc_clk_ctl("cpu-pll", NULL
, CLK_PRINT
| CLK_MHZ
);
1117 soc_clk_ctl("cpu-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1120 /* SYS clock domain */
1121 soc_clk_ctl("sys-pll", NULL
, CLK_PRINT
| CLK_MHZ
);
1122 soc_clk_ctl("apb-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1123 soc_clk_ctl("axi-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1124 soc_clk_ctl("eth-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1125 soc_clk_ctl("usb-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1126 soc_clk_ctl("sdio-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1127 if (is_board_match_runtime(T_BOARD_HSDK_4XD
))
1128 soc_clk_ctl("hdmi-sys-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1129 soc_clk_ctl("gfx-core-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1130 if (is_board_match_runtime(T_BOARD_HSDK
)) {
1131 soc_clk_ctl("gfx-dma-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1132 soc_clk_ctl("gfx-cfg-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1134 soc_clk_ctl("dmac-core-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1135 soc_clk_ctl("dmac-cfg-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1136 soc_clk_ctl("sdio-ref-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1137 soc_clk_ctl("spi-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1138 soc_clk_ctl("i2c-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1139 /* soc_clk_ctl("ebi-clk", NULL, CLK_PRINT | CLK_MHZ); */
1140 soc_clk_ctl("uart-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1143 /* DDR clock domain */
1144 soc_clk_ctl("ddr-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1147 /* HDMI clock domain */
1148 if (is_board_match_runtime(T_BOARD_HSDK_4XD
)) {
1149 soc_clk_ctl("hdmi-pll", NULL
, CLK_PRINT
| CLK_MHZ
);
1150 soc_clk_ctl("hdmi-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1154 /* TUN clock domain */
1155 soc_clk_ctl("tun-pll", NULL
, CLK_PRINT
| CLK_MHZ
);
1156 soc_clk_ctl("tun-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1157 soc_clk_ctl("rom-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1158 soc_clk_ctl("pwm-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1159 if (is_board_match_runtime(T_BOARD_HSDK_4XD
))
1160 soc_clk_ctl("timer-clk", NULL
, CLK_PRINT
| CLK_MHZ
);
1163 return CMD_RET_SUCCESS
;
1166 struct cmd_tbl cmd_hsdk_clock
[] = {
1167 U_BOOT_CMD_MKENT(set
, 3, 0, do_hsdk_clock_set
, "", ""),
1168 U_BOOT_CMD_MKENT(get
, 3, 0, do_hsdk_clock_get
, "", ""),
1169 U_BOOT_CMD_MKENT(print
, 4, 0, do_hsdk_clock_print
, "", ""),
1170 U_BOOT_CMD_MKENT(print_all
, 4, 0, do_hsdk_clock_print_all
, "", ""),
1173 static int do_hsdk_clock(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
1179 return CMD_RET_USAGE
;
1181 /* Strip off leading 'hsdk_clock' command argument */
1185 c
= find_cmd_tbl(argv
[0], cmd_hsdk_clock
, ARRAY_SIZE(cmd_hsdk_clock
));
1187 return CMD_RET_USAGE
;
1189 return c
->cmd(cmdtp
, flag
, argc
, argv
);
1193 hsdk_clock
, CONFIG_SYS_MAXARGS
, 0, do_hsdk_clock
,
1194 "Synopsys HSDK specific clock command",
1195 "set - Set clock to values specified in environment / command line arguments\n"
1196 "hsdk_clock get - Save clock values to environment\n"
1197 "hsdk_clock print - Print main clock values to console\n"
1198 "hsdk_clock print_all - Print all clock values to console\n"
1202 int board_early_init_f(void)
1205 * Setup AXI apertures unconditionally as we want to have DDR
1206 * in 0x00000000 region when we are kicking slave cpus.
1208 init_memory_bridge();
1211 * Switch SDIO external ciu clock divider from default div-by-8 to
1212 * minimum possible div-by-2.
1214 writel(SDIO_UHS_REG_EXT_DIV_2
, (void __iomem
*)SDIO_UHS_REG_EXT
);
1219 int board_early_init_r(void)
1222 * TODO: Init USB here to be able read environment from USB MSD.
1223 * It can be done with usb_init() call. We can't do it right now
1224 * due to brocken USB IP SW reset and lack of USB IP HW reset in
1225 * linux kernel (if we init USB here we will break USB in linux)
1229 * Flush all d$ as we want to use uncached area with st.di / ld.di
1230 * instructions and we don't want to have any dirty line in L1d$ or SL$
1231 * in this area. It is enough to flush all d$ once here as we access to
1232 * uncached area with regular st (non .di) instruction only when we copy
1233 * data during u-boot relocation.
1237 printf("Relocation Offset is: %08lx\n", gd
->reloc_off
);
1242 int board_late_init(void)
1245 * Populate environment with clock frequency values -
1246 * run hsdk_clock get callback without uboot command run.
1248 do_hsdk_clock_get(NULL
, 0, 0, NULL
);
1253 int checkboard(void)
1257 printf("Board: Synopsys %s\n", board_name(get_board_type_runtime()));
1259 if (board_mismatch())
1260 printf("WARN: U-Boot is configured NOT for this board but for %s!\n",
1261 board_name(get_board_type_config()));
1263 reg
= readl(CREG_AXI_M_HS_CORE_BOOT
) & CREG_CORE_BOOT_IMAGE
;
1264 printf("U-Boot autostart: %s\n", reg
? "enabled" : "disabled");