xref: /openbmc/linux/arch/arm/mach-mstar/mstarv7.c (revision 5919eec0)
1312b62b6SDaniel Palmer // SPDX-License-Identifier: GPL-2.0
2312b62b6SDaniel Palmer /*
3312b62b6SDaniel Palmer  * Device Tree support for MStar/Sigmastar Armv7 SoCs
4312b62b6SDaniel Palmer  *
5312b62b6SDaniel Palmer  * Copyright (c) 2020 thingy.jp
6312b62b6SDaniel Palmer  * Author: Daniel Palmer <daniel@thingy.jp>
7312b62b6SDaniel Palmer  */
8312b62b6SDaniel Palmer 
9312b62b6SDaniel Palmer #include <linux/init.h>
10312b62b6SDaniel Palmer #include <asm/mach/arch.h>
11312b62b6SDaniel Palmer #include <asm/mach/map.h>
12312b62b6SDaniel Palmer #include <linux/of.h>
13312b62b6SDaniel Palmer #include <linux/of_address.h>
14312b62b6SDaniel Palmer #include <linux/io.h>
15312b62b6SDaniel Palmer 
16312b62b6SDaniel Palmer /*
17312b62b6SDaniel Palmer  * In the u-boot code the area these registers are in is
18312b62b6SDaniel Palmer  * called "L3 bridge" and there are register descriptions
19312b62b6SDaniel Palmer  * for something in the same area called "AXI".
20312b62b6SDaniel Palmer  *
21312b62b6SDaniel Palmer  * It's not exactly known what this is but the vendor code
22312b62b6SDaniel Palmer  * for both u-boot and linux share calls to "flush the miu pipe".
23312b62b6SDaniel Palmer  * This seems to be to force pending CPU writes to memory so that
24312b62b6SDaniel Palmer  * the state is right before DMA capable devices try to read
25312b62b6SDaniel Palmer  * descriptors and data the CPU has prepared. Without doing this
26312b62b6SDaniel Palmer  * ethernet doesn't work reliably for example.
27312b62b6SDaniel Palmer  */
28312b62b6SDaniel Palmer 
29312b62b6SDaniel Palmer #define MSTARV7_L3BRIDGE_FLUSH		0x14
30312b62b6SDaniel Palmer #define MSTARV7_L3BRIDGE_STATUS		0x40
31312b62b6SDaniel Palmer #define MSTARV7_L3BRIDGE_FLUSH_TRIGGER	BIT(0)
32312b62b6SDaniel Palmer #define MSTARV7_L3BRIDGE_STATUS_DONE	BIT(12)
33312b62b6SDaniel Palmer 
34*5919eec0SDaniel Palmer #ifdef CONFIG_SMP
35*5919eec0SDaniel Palmer #define MSTARV7_CPU1_BOOT_ADDR_HIGH	0x4c
36*5919eec0SDaniel Palmer #define MSTARV7_CPU1_BOOT_ADDR_LOW	0x50
37*5919eec0SDaniel Palmer #define MSTARV7_CPU1_UNLOCK		0x58
38*5919eec0SDaniel Palmer #define MSTARV7_CPU1_UNLOCK_MAGIC	0xbabe
39*5919eec0SDaniel Palmer #endif
40*5919eec0SDaniel Palmer 
41312b62b6SDaniel Palmer static void __iomem *l3bridge;
42312b62b6SDaniel Palmer 
43312b62b6SDaniel Palmer static const char * const mstarv7_board_dt_compat[] __initconst = {
44312b62b6SDaniel Palmer 	"mstar,infinity",
45ba2290b1SDaniel Palmer 	"mstar,infinity2m",
46312b62b6SDaniel Palmer 	"mstar,infinity3",
47312b62b6SDaniel Palmer 	"mstar,mercury5",
48312b62b6SDaniel Palmer 	NULL,
49312b62b6SDaniel Palmer };
50312b62b6SDaniel Palmer 
51312b62b6SDaniel Palmer /*
52312b62b6SDaniel Palmer  * This may need locking to deal with situations where an interrupt
53312b62b6SDaniel Palmer  * happens while we are in here and mb() gets called by the interrupt handler.
54312b62b6SDaniel Palmer  *
55312b62b6SDaniel Palmer  * The vendor code did have a spin lock but it doesn't seem to be needed and
56312b62b6SDaniel Palmer  * removing it hasn't caused any side effects so far.
57312b62b6SDaniel Palmer  *
58312b62b6SDaniel Palmer  * [writel|readl]_relaxed have to be used here because otherwise
59312b62b6SDaniel Palmer  * we'd end up right back in here.
60312b62b6SDaniel Palmer  */
mstarv7_mb(void)61312b62b6SDaniel Palmer static void mstarv7_mb(void)
62312b62b6SDaniel Palmer {
63312b62b6SDaniel Palmer 	/* toggle the flush miu pipe fire bit */
64312b62b6SDaniel Palmer 	writel_relaxed(0, l3bridge + MSTARV7_L3BRIDGE_FLUSH);
65312b62b6SDaniel Palmer 	writel_relaxed(MSTARV7_L3BRIDGE_FLUSH_TRIGGER, l3bridge
66312b62b6SDaniel Palmer 			+ MSTARV7_L3BRIDGE_FLUSH);
67312b62b6SDaniel Palmer 	while (!(readl_relaxed(l3bridge + MSTARV7_L3BRIDGE_STATUS)
68312b62b6SDaniel Palmer 			& MSTARV7_L3BRIDGE_STATUS_DONE)) {
69312b62b6SDaniel Palmer 		/* wait for flush to complete */
70312b62b6SDaniel Palmer 	}
71312b62b6SDaniel Palmer }
72312b62b6SDaniel Palmer 
73*5919eec0SDaniel Palmer #ifdef CONFIG_SMP
mstarv7_boot_secondary(unsigned int cpu,struct task_struct * idle)74*5919eec0SDaniel Palmer static int mstarv7_boot_secondary(unsigned int cpu, struct task_struct *idle)
75*5919eec0SDaniel Palmer {
76*5919eec0SDaniel Palmer 	struct device_node *np;
77*5919eec0SDaniel Palmer 	u32 bootaddr = (u32) __pa_symbol(secondary_startup_arm);
78*5919eec0SDaniel Palmer 	void __iomem *smpctrl;
79*5919eec0SDaniel Palmer 
80*5919eec0SDaniel Palmer 	/*
81*5919eec0SDaniel Palmer 	 * right now we don't know how to boot anything except
82*5919eec0SDaniel Palmer 	 * cpu 1.
83*5919eec0SDaniel Palmer 	 */
84*5919eec0SDaniel Palmer 	if (cpu != 1)
85*5919eec0SDaniel Palmer 		return -EINVAL;
86*5919eec0SDaniel Palmer 
87*5919eec0SDaniel Palmer 	np = of_find_compatible_node(NULL, NULL, "mstar,smpctrl");
88*5919eec0SDaniel Palmer 	smpctrl = of_iomap(np, 0);
89*5919eec0SDaniel Palmer 
90*5919eec0SDaniel Palmer 	if (!smpctrl)
91*5919eec0SDaniel Palmer 		return -ENODEV;
92*5919eec0SDaniel Palmer 
93*5919eec0SDaniel Palmer 	/* set the boot address for the second cpu */
94*5919eec0SDaniel Palmer 	writew(bootaddr & 0xffff, smpctrl + MSTARV7_CPU1_BOOT_ADDR_LOW);
95*5919eec0SDaniel Palmer 	writew((bootaddr >> 16) & 0xffff, smpctrl + MSTARV7_CPU1_BOOT_ADDR_HIGH);
96*5919eec0SDaniel Palmer 
97*5919eec0SDaniel Palmer 	/* unlock the second cpu */
98*5919eec0SDaniel Palmer 	writew(MSTARV7_CPU1_UNLOCK_MAGIC, smpctrl + MSTARV7_CPU1_UNLOCK);
99*5919eec0SDaniel Palmer 
100*5919eec0SDaniel Palmer 	/* and away we go...*/
101*5919eec0SDaniel Palmer 	arch_send_wakeup_ipi_mask(cpumask_of(cpu));
102*5919eec0SDaniel Palmer 
103*5919eec0SDaniel Palmer 	iounmap(smpctrl);
104*5919eec0SDaniel Palmer 
105*5919eec0SDaniel Palmer 	return 0;
106*5919eec0SDaniel Palmer }
107*5919eec0SDaniel Palmer 
108*5919eec0SDaniel Palmer static const struct smp_operations __initdata mstarv7_smp_ops = {
109*5919eec0SDaniel Palmer 	.smp_boot_secondary = mstarv7_boot_secondary,
110*5919eec0SDaniel Palmer };
111*5919eec0SDaniel Palmer #endif
112*5919eec0SDaniel Palmer 
mstarv7_init(void)113312b62b6SDaniel Palmer static void __init mstarv7_init(void)
114312b62b6SDaniel Palmer {
115312b62b6SDaniel Palmer 	struct device_node *np;
116312b62b6SDaniel Palmer 
117312b62b6SDaniel Palmer 	np = of_find_compatible_node(NULL, NULL, "mstar,l3bridge");
118312b62b6SDaniel Palmer 	l3bridge = of_iomap(np, 0);
119312b62b6SDaniel Palmer 	if (l3bridge)
120312b62b6SDaniel Palmer 		soc_mb = mstarv7_mb;
121312b62b6SDaniel Palmer 	else
122312b62b6SDaniel Palmer 		pr_warn("Failed to install memory barrier, DMA will be broken!\n");
123312b62b6SDaniel Palmer }
124312b62b6SDaniel Palmer 
125312b62b6SDaniel Palmer DT_MACHINE_START(MSTARV7_DT, "MStar/Sigmastar Armv7 (Device Tree)")
126312b62b6SDaniel Palmer 	.dt_compat	= mstarv7_board_dt_compat,
127312b62b6SDaniel Palmer 	.init_machine	= mstarv7_init,
128*5919eec0SDaniel Palmer 	.smp		= smp_ops(mstarv7_smp_ops),
129312b62b6SDaniel Palmer MACHINE_END
130