xref: /linux/arch/arm/mach-npcm/platsmp.c (revision fab183d632628381b466a41479489541ac0e29a0)
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2018 Nuvoton Technology corporation.
3 // Copyright 2018 Google, Inc.
4 
5 #define pr_fmt(fmt) "nuvoton,npcm7xx-smp: " fmt
6 
7 #include <linux/delay.h>
8 #include <linux/smp.h>
9 #include <linux/io.h>
10 #include <linux/of.h>
11 #include <linux/of_address.h>
12 #include <asm/cacheflush.h>
13 #include <asm/smp.h>
14 #include <asm/smp_plat.h>
15 #include <asm/smp_scu.h>
16 
17 #define NPCM7XX_SCRPAD_REG 0x13c
18 
19 extern void npcm7xx_secondary_startup(void);
20 
npcm7xx_smp_boot_secondary(unsigned int cpu,struct task_struct * idle)21 static int npcm7xx_smp_boot_secondary(unsigned int cpu,
22 				      struct task_struct *idle)
23 {
24 	struct device_node *gcr_np;
25 	void __iomem *gcr_base;
26 	int ret = 0;
27 
28 	gcr_np = of_find_compatible_node(NULL, NULL, "nuvoton,npcm750-gcr");
29 	if (!gcr_np) {
30 		pr_err("no gcr device node\n");
31 		ret = -ENODEV;
32 		goto out;
33 	}
34 	gcr_base = of_iomap(gcr_np, 0);
35 	of_node_put(gcr_np);
36 	if (!gcr_base) {
37 		pr_err("could not iomap gcr");
38 		ret = -ENOMEM;
39 		goto out;
40 	}
41 
42 	/* give boot ROM kernel start address. */
43 	iowrite32(__pa_symbol(npcm7xx_secondary_startup), gcr_base +
44 		  NPCM7XX_SCRPAD_REG);
45 	/* make sure the previous write is seen by all observers. */
46 	dsb_sev();
47 
48 	iounmap(gcr_base);
49 out:
50 	return ret;
51 }
52 
npcm7xx_smp_prepare_cpus(unsigned int max_cpus)53 static void __init npcm7xx_smp_prepare_cpus(unsigned int max_cpus)
54 {
55 	struct device_node *scu_np;
56 	void __iomem *scu_base;
57 
58 	scu_np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
59 	if (!scu_np) {
60 		pr_err("no scu device node\n");
61 		return;
62 	}
63 	scu_base = of_iomap(scu_np, 0);
64 	of_node_put(scu_np);
65 	if (!scu_base) {
66 		pr_err("could not iomap scu");
67 		return;
68 	}
69 
70 	scu_enable(scu_base);
71 
72 	iounmap(scu_base);
73 }
74 
75 static struct smp_operations npcm7xx_smp_ops __initdata = {
76 	.smp_prepare_cpus = npcm7xx_smp_prepare_cpus,
77 	.smp_boot_secondary = npcm7xx_smp_boot_secondary,
78 };
79 
80 CPU_METHOD_OF_DECLARE(npcm7xx_smp, "nuvoton,npcm750-smp", &npcm7xx_smp_ops);
81