kernel: config: add missing symbol for kenrel 6.6
[openwrt/staging/nbd.git] / target / linux / ramips / patches-5.15 / 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 @@ -58,15 +58,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,26 +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 + panic("Failed to get resource for %s node", np->name);
112
113 if (!request_mem_region(res.start,
114 resource_size(&res),
115 res.name))
116 - panic("Failed to request resources for %s", node);
117 + panic("Failed to request resources for %s node", np->name);
118 +
119 + of_node_put(np);
120
121 return ioremap(res.start, resource_size(&res));
122 }
123
124 +void __init ralink_of_remap(void)
125 +{
126 + rt_sysc_membase = mtmips_of_remap_node(mtmips_sysc_match, "system");
127 + rt_memc_membase = mtmips_of_remap_node(mtmips_memc_match, "memory");
128 +
129 + if (!rt_sysc_membase || !rt_memc_membase)
130 + panic("Failed to remap core resources");
131 +}
132 +
133 void __init device_tree_init(void)
134 {
135 unflatten_and_copy_device_tree();
136 --- a/arch/mips/ralink/rt288x.c
137 +++ b/arch/mips/ralink/rt288x.c
138 @@ -17,15 +17,6 @@
139
140 #include "common.h"
141
142 -void __init ralink_of_remap(void)
143 -{
144 - rt_sysc_membase = plat_of_remap_node("ralink,rt2880-sysc");
145 - rt_memc_membase = plat_of_remap_node("ralink,rt2880-memc");
146 -
147 - if (!rt_sysc_membase || !rt_memc_membase)
148 - panic("Failed to remap core resources");
149 -}
150 -
151 void __init prom_soc_init(struct ralink_soc_info *soc_info)
152 {
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
157 return ret;
158 }
159
160 -void __init ralink_of_remap(void)
161 -{
162 - rt_sysc_membase = plat_of_remap_node("ralink,rt3050-sysc");
163 - rt_memc_membase = plat_of_remap_node("ralink,rt3050-memc");
164 -
165 - if (!rt_sysc_membase || !rt_memc_membase)
166 - panic("Failed to remap core resources");
167 -}
168 -
169 void __init prom_soc_init(struct ralink_soc_info *soc_info)
170 {
171 void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT305X_SYSC_BASE);
172 --- a/arch/mips/ralink/rt3883.c
173 +++ b/arch/mips/ralink/rt3883.c
174 @@ -17,15 +17,6 @@
175
176 #include "common.h"
177
178 -void __init ralink_of_remap(void)
179 -{
180 - rt_sysc_membase = plat_of_remap_node("ralink,rt3883-sysc");
181 - rt_memc_membase = plat_of_remap_node("ralink,rt3883-memc");
182 -
183 - if (!rt_sysc_membase || !rt_memc_membase)
184 - panic("Failed to remap core resources");
185 -}
186 -
187 void __init prom_soc_init(struct ralink_soc_info *soc_info)
188 {
189 void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT3883_SYSC_BASE);