1 From fd99ac5055d4705e91c73d1adba18bc71c8511a8 Mon Sep 17 00:00:00 2001
2 From: Shiji Yang <yangshiji66@outlook.com>
3 Date: Tue, 20 Jun 2023 19:44:32 +0800
4 Subject: [PATCH] mips: ralink: introduce commonly used remap node function
6 The ralink_of_remap() function is repeated several times on SoC specific
7 source files. They have the same structure, but just differ in compatible
8 strings. In order to make commonly use of these codes, this patch
9 introduces a newly designed mtmips_of_remap_node() function to match and
10 remap all supported system controller and memory controller nodes.
12 Build and run tested on MT7620 and MT7628.
14 Signed-off-by: Shiji Yang <yangshiji66@outlook.com>
15 Reviewed-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
16 Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
18 arch/mips/ralink/common.h | 2 --
19 arch/mips/ralink/mt7620.c | 9 ---------
20 arch/mips/ralink/mt7621.c | 9 ---------
21 arch/mips/ralink/of.c | 42 +++++++++++++++++++++++++++++++++++-------
22 arch/mips/ralink/rt288x.c | 9 ---------
23 arch/mips/ralink/rt305x.c | 9 ---------
24 arch/mips/ralink/rt3883.c | 9 ---------
25 7 files changed, 35 insertions(+), 54 deletions(-)
27 --- a/arch/mips/ralink/common.h
28 +++ b/arch/mips/ralink/common.h
29 @@ -25,6 +25,4 @@ extern void ralink_of_remap(void);
31 extern void __init prom_soc_init(struct ralink_soc_info *soc_info);
33 -__iomem void *plat_of_remap_node(const char *node);
35 #endif /* _RALINK_COMMON_H__ */
36 --- a/arch/mips/ralink/mt7620.c
37 +++ b/arch/mips/ralink/mt7620.c
39 /* does the board have sdram or ddram */
42 -void __init ralink_of_remap(void)
44 - rt_sysc_membase = plat_of_remap_node("ralink,mt7620a-sysc");
45 - rt_memc_membase = plat_of_remap_node("ralink,mt7620a-memc");
47 - if (!rt_sysc_membase || !rt_memc_membase)
48 - panic("Failed to remap core resources");
52 mt7620_dram_init(struct ralink_soc_info *soc_info)
54 --- a/arch/mips/ralink/mt7621.c
55 +++ b/arch/mips/ralink/mt7621.c
56 @@ -58,15 +58,6 @@ static void __init mt7621_memory_detect(
57 memblock_add(MT7621_HIGHMEM_BASE, MT7621_HIGHMEM_SIZE);
60 -void __init ralink_of_remap(void)
62 - rt_sysc_membase = plat_of_remap_node("mediatek,mt7621-sysc");
63 - rt_memc_membase = plat_of_remap_node("mediatek,mt7621-memc");
65 - if (!rt_sysc_membase || !rt_memc_membase)
66 - panic("Failed to remap core resources");
69 static unsigned int __init mt7621_get_soc_name0(void)
71 return __raw_readl(MT7621_SYSC_BASE + SYSC_REG_CHIP_NAME0);
72 --- a/arch/mips/ralink/of.c
73 +++ b/arch/mips/ralink/of.c
74 @@ -29,26 +29,56 @@ __iomem void *rt_sysc_membase;
75 __iomem void *rt_memc_membase;
76 EXPORT_SYMBOL_GPL(rt_sysc_membase);
78 -__iomem void *plat_of_remap_node(const char *node)
79 +static const struct of_device_id mtmips_memc_match[] = {
80 + { .compatible = "mediatek,mt7621-memc" },
81 + { .compatible = "ralink,mt7620a-memc" },
82 + { .compatible = "ralink,rt2880-memc" },
83 + { .compatible = "ralink,rt3050-memc" },
84 + { .compatible = "ralink,rt3883-memc" },
88 +static const struct of_device_id mtmips_sysc_match[] = {
89 + { .compatible = "mediatek,mt7621-sysc" },
90 + { .compatible = "ralink,mt7620a-sysc" },
91 + { .compatible = "ralink,rt2880-sysc" },
92 + { .compatible = "ralink,rt3050-sysc" },
93 + { .compatible = "ralink,rt3883-sysc" },
97 +static __iomem void *
98 +mtmips_of_remap_node(const struct of_device_id *match, const char *type)
101 struct device_node *np;
103 - np = of_find_compatible_node(NULL, NULL, node);
104 + np = of_find_matching_node(NULL, match);
106 - panic("Failed to find %s node", node);
107 + panic("Failed to find %s controller node", type);
109 if (of_address_to_resource(np, 0, &res))
110 - panic("Failed to get resource for %s", node);
111 + panic("Failed to get resource for %s node", np->name);
113 if (!request_mem_region(res.start,
116 - panic("Failed to request resources for %s", node);
117 + panic("Failed to request resources for %s node", np->name);
121 return ioremap(res.start, resource_size(&res));
124 +void __init ralink_of_remap(void)
126 + rt_sysc_membase = mtmips_of_remap_node(mtmips_sysc_match, "system");
127 + rt_memc_membase = mtmips_of_remap_node(mtmips_memc_match, "memory");
129 + if (!rt_sysc_membase || !rt_memc_membase)
130 + panic("Failed to remap core resources");
133 void __init device_tree_init(void)
135 unflatten_and_copy_device_tree();
136 --- a/arch/mips/ralink/rt288x.c
137 +++ b/arch/mips/ralink/rt288x.c
142 -void __init ralink_of_remap(void)
144 - rt_sysc_membase = plat_of_remap_node("ralink,rt2880-sysc");
145 - rt_memc_membase = plat_of_remap_node("ralink,rt2880-memc");
147 - if (!rt_sysc_membase || !rt_memc_membase)
148 - panic("Failed to remap core resources");
151 void __init prom_soc_init(struct ralink_soc_info *soc_info)
153 void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT2880_SYSC_BASE);
154 --- a/arch/mips/ralink/rt305x.c
155 +++ b/arch/mips/ralink/rt305x.c
156 @@ -53,15 +53,6 @@ static unsigned long rt5350_get_mem_size
160 -void __init ralink_of_remap(void)
162 - rt_sysc_membase = plat_of_remap_node("ralink,rt3050-sysc");
163 - rt_memc_membase = plat_of_remap_node("ralink,rt3050-memc");
165 - if (!rt_sysc_membase || !rt_memc_membase)
166 - panic("Failed to remap core resources");
169 void __init prom_soc_init(struct ralink_soc_info *soc_info)
171 void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT305X_SYSC_BASE);
172 --- a/arch/mips/ralink/rt3883.c
173 +++ b/arch/mips/ralink/rt3883.c
178 -void __init ralink_of_remap(void)
180 - rt_sysc_membase = plat_of_remap_node("ralink,rt3883-sysc");
181 - rt_memc_membase = plat_of_remap_node("ralink,rt3883-memc");
183 - if (!rt_sysc_membase || !rt_memc_membase)
184 - panic("Failed to remap core resources");
187 void __init prom_soc_init(struct ralink_soc_info *soc_info)
189 void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT3883_SYSC_BASE);