ramips: add support for 6.1 kernel
[openwrt/openwrt.git] / target / linux / ramips / patches-6.1 / 006-v6.5-mips-ralink-introduce-commonly-used-remap-node-funct.patch
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
5
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.
11
12 Build and run tested on MT7620 and MT7628.
13
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>
17 ---
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(-)
26
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);
30
31 extern void __init prom_soc_init(struct ralink_soc_info *soc_info);
32
33 -__iomem void *plat_of_remap_node(const char *node);
34 -
35 #endif /* _RALINK_COMMON_H__ */
36 --- a/arch/mips/ralink/mt7620.c
37 +++ b/arch/mips/ralink/mt7620.c
38 @@ -43,15 +43,6 @@
39 /* does the board have sdram or ddram */
40 static int dram_type;
41
42 -void __init ralink_of_remap(void)
43 -{
44 - rt_sysc_membase = plat_of_remap_node("ralink,mt7620a-sysc");
45 - rt_memc_membase = plat_of_remap_node("ralink,mt7620a-memc");
46 -
47 - if (!rt_sysc_membase || !rt_memc_membase)
48 - panic("Failed to remap core resources");
49 -}
50 -
51 static __init void
52 mt7620_dram_init(struct ralink_soc_info *soc_info)
53 {
54 --- a/arch/mips/ralink/mt7621.c
55 +++ b/arch/mips/ralink/mt7621.c
56 @@ -89,15 +89,6 @@ static void __init mt7621_memory_detect(
57 memblock_add(MT7621_HIGHMEM_BASE, MT7621_HIGHMEM_SIZE);
58 }
59
60 -void __init ralink_of_remap(void)
61 -{
62 - rt_sysc_membase = plat_of_remap_node("mediatek,mt7621-sysc");
63 - rt_memc_membase = plat_of_remap_node("mediatek,mt7621-memc");
64 -
65 - if (!rt_sysc_membase || !rt_memc_membase)
66 - panic("Failed to remap core resources");
67 -}
68 -
69 static unsigned int __init mt7621_get_soc_name0(void)
70 {
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,28 +29,56 @@ __iomem void *rt_sysc_membase;
75 __iomem void *rt_memc_membase;
76 EXPORT_SYMBOL_GPL(rt_sysc_membase);
77
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" },
85 + {}
86 +};
87 +
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" },
94 + {}
95 +};
96 +
97 +static __iomem void *
98 +mtmips_of_remap_node(const struct of_device_id *match, const char *type)
99 {
100 struct resource res;
101 struct device_node *np;
102
103 - np = of_find_compatible_node(NULL, NULL, node);
104 + np = of_find_matching_node(NULL, match);
105 if (!np)
106 - panic("Failed to find %s node", node);
107 + panic("Failed to find %s controller node", type);
108
109 if (of_address_to_resource(np, 0, &res))
110 - panic("Failed to get resource for %s", node);
111 -
112 - of_node_put(np);
113 + panic("Failed to get resource for %s node", np->name);
114
115 if (!request_mem_region(res.start,
116 resource_size(&res),
117 res.name))
118 - panic("Failed to request resources for %s", node);
119 + panic("Failed to request resources for %s node", np->name);
120 +
121 + of_node_put(np);
122
123 return ioremap(res.start, resource_size(&res));
124 }
125
126 +void __init ralink_of_remap(void)
127 +{
128 + rt_sysc_membase = mtmips_of_remap_node(mtmips_sysc_match, "system");
129 + rt_memc_membase = mtmips_of_remap_node(mtmips_memc_match, "memory");
130 +
131 + if (!rt_sysc_membase || !rt_memc_membase)
132 + panic("Failed to remap core resources");
133 +}
134 +
135 void __init plat_mem_setup(void)
136 {
137 void *dtb;
138 --- a/arch/mips/ralink/rt288x.c
139 +++ b/arch/mips/ralink/rt288x.c
140 @@ -17,15 +17,6 @@
141
142 #include "common.h"
143
144 -void __init ralink_of_remap(void)
145 -{
146 - rt_sysc_membase = plat_of_remap_node("ralink,rt2880-sysc");
147 - rt_memc_membase = plat_of_remap_node("ralink,rt2880-memc");
148 -
149 - if (!rt_sysc_membase || !rt_memc_membase)
150 - panic("Failed to remap core resources");
151 -}
152 -
153 void __init prom_soc_init(struct ralink_soc_info *soc_info)
154 {
155 void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT2880_SYSC_BASE);
156 --- a/arch/mips/ralink/rt305x.c
157 +++ b/arch/mips/ralink/rt305x.c
158 @@ -53,15 +53,6 @@ static unsigned long rt5350_get_mem_size
159 return ret;
160 }
161
162 -void __init ralink_of_remap(void)
163 -{
164 - rt_sysc_membase = plat_of_remap_node("ralink,rt3050-sysc");
165 - rt_memc_membase = plat_of_remap_node("ralink,rt3050-memc");
166 -
167 - if (!rt_sysc_membase || !rt_memc_membase)
168 - panic("Failed to remap core resources");
169 -}
170 -
171 void __init prom_soc_init(struct ralink_soc_info *soc_info)
172 {
173 void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT305X_SYSC_BASE);
174 --- a/arch/mips/ralink/rt3883.c
175 +++ b/arch/mips/ralink/rt3883.c
176 @@ -17,15 +17,6 @@
177
178 #include "common.h"
179
180 -void __init ralink_of_remap(void)
181 -{
182 - rt_sysc_membase = plat_of_remap_node("ralink,rt3883-sysc");
183 - rt_memc_membase = plat_of_remap_node("ralink,rt3883-memc");
184 -
185 - if (!rt_sysc_membase || !rt_memc_membase)
186 - panic("Failed to remap core resources");
187 -}
188 -
189 void __init prom_soc_init(struct ralink_soc_info *soc_info)
190 {
191 void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT3883_SYSC_BASE);