Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mips: ralink: introduce commonly used remap node function

The ralink_of_remap() function is repeated several times on SoC specific
source files. They have the same structure, but just differ in compatible
strings. In order to make commonly use of these codes, this patch
introduces a newly designed mtmips_of_remap_node() function to match and
remap all supported system controller and memory controller nodes.

Build and run tested on MT7620 and MT7628.

Signed-off-by: Shiji Yang <yangshiji66@outlook.com>
Reviewed-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>

authored by

Shiji Yang and committed by
Thomas Bogendoerfer
fd99ac50 89ec9bbe

+35 -54
-2
arch/mips/ralink/common.h
··· 25 25 26 26 extern void __init prom_soc_init(struct ralink_soc_info *soc_info); 27 27 28 - __iomem void *plat_of_remap_node(const char *node); 29 - 30 28 #endif /* _RALINK_COMMON_H__ */
-9
arch/mips/ralink/mt7620.c
··· 47 47 48 48 static struct ralink_soc_info *soc_info_ptr; 49 49 50 - void __init ralink_of_remap(void) 51 - { 52 - rt_sysc_membase = plat_of_remap_node("ralink,mt7620a-sysc"); 53 - rt_memc_membase = plat_of_remap_node("ralink,mt7620a-memc"); 54 - 55 - if (!rt_sysc_membase || !rt_memc_membase) 56 - panic("Failed to remap core resources"); 57 - } 58 - 59 50 static __init void 60 51 mt7620_dram_init(struct ralink_soc_info *soc_info) 61 52 {
-9
arch/mips/ralink/mt7621.c
··· 89 89 memblock_add(MT7621_HIGHMEM_BASE, MT7621_HIGHMEM_SIZE); 90 90 } 91 91 92 - void __init ralink_of_remap(void) 93 - { 94 - rt_sysc_membase = plat_of_remap_node("mediatek,mt7621-sysc"); 95 - rt_memc_membase = plat_of_remap_node("mediatek,mt7621-memc"); 96 - 97 - if (!rt_sysc_membase || !rt_memc_membase) 98 - panic("Failed to remap core resources"); 99 - } 100 - 101 92 static unsigned int __init mt7621_get_soc_name0(void) 102 93 { 103 94 return __raw_readl(MT7621_SYSC_BASE + SYSC_REG_CHIP_NAME0);
+35 -7
arch/mips/ralink/of.c
··· 29 29 __iomem void *rt_memc_membase; 30 30 EXPORT_SYMBOL_GPL(rt_sysc_membase); 31 31 32 - __iomem void *plat_of_remap_node(const char *node) 32 + static const struct of_device_id mtmips_memc_match[] = { 33 + { .compatible = "mediatek,mt7621-memc" }, 34 + { .compatible = "ralink,mt7620a-memc" }, 35 + { .compatible = "ralink,rt2880-memc" }, 36 + { .compatible = "ralink,rt3050-memc" }, 37 + { .compatible = "ralink,rt3883-memc" }, 38 + {} 39 + }; 40 + 41 + static const struct of_device_id mtmips_sysc_match[] = { 42 + { .compatible = "mediatek,mt7621-sysc" }, 43 + { .compatible = "ralink,mt7620a-sysc" }, 44 + { .compatible = "ralink,rt2880-sysc" }, 45 + { .compatible = "ralink,rt3050-sysc" }, 46 + { .compatible = "ralink,rt3883-sysc" }, 47 + {} 48 + }; 49 + 50 + static __iomem void * 51 + mtmips_of_remap_node(const struct of_device_id *match, const char *type) 33 52 { 34 53 struct resource res; 35 54 struct device_node *np; 36 55 37 - np = of_find_compatible_node(NULL, NULL, node); 56 + np = of_find_matching_node(NULL, match); 38 57 if (!np) 39 - panic("Failed to find %s node", node); 58 + panic("Failed to find %s controller node", type); 40 59 41 60 if (of_address_to_resource(np, 0, &res)) 42 - panic("Failed to get resource for %s", node); 43 - 44 - of_node_put(np); 61 + panic("Failed to get resource for %s node", np->name); 45 62 46 63 if (!request_mem_region(res.start, 47 64 resource_size(&res), 48 65 res.name)) 49 - panic("Failed to request resources for %s", node); 66 + panic("Failed to request resources for %s node", np->name); 67 + 68 + of_node_put(np); 50 69 51 70 return ioremap(res.start, resource_size(&res)); 71 + } 72 + 73 + void __init ralink_of_remap(void) 74 + { 75 + rt_sysc_membase = mtmips_of_remap_node(mtmips_sysc_match, "system"); 76 + rt_memc_membase = mtmips_of_remap_node(mtmips_memc_match, "memory"); 77 + 78 + if (!rt_sysc_membase || !rt_memc_membase) 79 + panic("Failed to remap core resources"); 52 80 } 53 81 54 82 void __init plat_mem_setup(void)
-9
arch/mips/ralink/rt288x.c
··· 21 21 22 22 static struct ralink_soc_info *soc_info_ptr; 23 23 24 - void __init ralink_of_remap(void) 25 - { 26 - rt_sysc_membase = plat_of_remap_node("ralink,rt2880-sysc"); 27 - rt_memc_membase = plat_of_remap_node("ralink,rt2880-memc"); 28 - 29 - if (!rt_sysc_membase || !rt_memc_membase) 30 - panic("Failed to remap core resources"); 31 - } 32 - 33 24 static unsigned int __init rt2880_get_soc_name0(void) 34 25 { 35 26 return __raw_readl(RT2880_SYSC_BASE + SYSC_REG_CHIP_NAME0);
-9
arch/mips/ralink/rt305x.c
··· 56 56 return ret; 57 57 } 58 58 59 - void __init ralink_of_remap(void) 60 - { 61 - rt_sysc_membase = plat_of_remap_node("ralink,rt3050-sysc"); 62 - rt_memc_membase = plat_of_remap_node("ralink,rt3050-memc"); 63 - 64 - if (!rt_sysc_membase || !rt_memc_membase) 65 - panic("Failed to remap core resources"); 66 - } 67 - 68 59 static unsigned int __init rt305x_get_soc_name0(void) 69 60 { 70 61 return __raw_readl(RT305X_SYSC_BASE + SYSC_REG_CHIP_NAME0);
-9
arch/mips/ralink/rt3883.c
··· 21 21 22 22 static struct ralink_soc_info *soc_info_ptr; 23 23 24 - void __init ralink_of_remap(void) 25 - { 26 - rt_sysc_membase = plat_of_remap_node("ralink,rt3883-sysc"); 27 - rt_memc_membase = plat_of_remap_node("ralink,rt3883-memc"); 28 - 29 - if (!rt_sysc_membase || !rt_memc_membase) 30 - panic("Failed to remap core resources"); 31 - } 32 - 33 24 static unsigned int __init rt3883_get_soc_name0(void) 34 25 { 35 26 return __raw_readl(RT3883_SYSC_BASE + RT3883_SYSC_REG_CHIPID0_3);