006-v6.5-mips-ralink-introduce-commonly-used-remap-node-funct.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. From fd99ac5055d4705e91c73d1adba18bc71c8511a8 Mon Sep 17 00:00:00 2001
  2. From: Shiji Yang <[email protected]>
  3. Date: Tue, 20 Jun 2023 19:44:32 +0800
  4. Subject: [PATCH] mips: ralink: introduce commonly used remap node function
  5. The ralink_of_remap() function is repeated several times on SoC specific
  6. source files. They have the same structure, but just differ in compatible
  7. strings. In order to make commonly use of these codes, this patch
  8. introduces a newly designed mtmips_of_remap_node() function to match and
  9. remap all supported system controller and memory controller nodes.
  10. Build and run tested on MT7620 and MT7628.
  11. Signed-off-by: Shiji Yang <[email protected]>
  12. Reviewed-by: Sergio Paracuellos <[email protected]>
  13. Signed-off-by: Thomas Bogendoerfer <[email protected]>
  14. ---
  15. arch/mips/ralink/common.h | 2 --
  16. arch/mips/ralink/mt7620.c | 9 ---------
  17. arch/mips/ralink/mt7621.c | 9 ---------
  18. arch/mips/ralink/of.c | 42 +++++++++++++++++++++++++++++++++++-------
  19. arch/mips/ralink/rt288x.c | 9 ---------
  20. arch/mips/ralink/rt305x.c | 9 ---------
  21. arch/mips/ralink/rt3883.c | 9 ---------
  22. 7 files changed, 35 insertions(+), 54 deletions(-)
  23. --- a/arch/mips/ralink/common.h
  24. +++ b/arch/mips/ralink/common.h
  25. @@ -25,6 +25,4 @@ extern void ralink_of_remap(void);
  26. extern void __init prom_soc_init(struct ralink_soc_info *soc_info);
  27. -__iomem void *plat_of_remap_node(const char *node);
  28. -
  29. #endif /* _RALINK_COMMON_H__ */
  30. --- a/arch/mips/ralink/mt7620.c
  31. +++ b/arch/mips/ralink/mt7620.c
  32. @@ -43,15 +43,6 @@
  33. /* does the board have sdram or ddram */
  34. static int dram_type;
  35. -void __init ralink_of_remap(void)
  36. -{
  37. - rt_sysc_membase = plat_of_remap_node("ralink,mt7620a-sysc");
  38. - rt_memc_membase = plat_of_remap_node("ralink,mt7620a-memc");
  39. -
  40. - if (!rt_sysc_membase || !rt_memc_membase)
  41. - panic("Failed to remap core resources");
  42. -}
  43. -
  44. static __init void
  45. mt7620_dram_init(struct ralink_soc_info *soc_info)
  46. {
  47. --- a/arch/mips/ralink/mt7621.c
  48. +++ b/arch/mips/ralink/mt7621.c
  49. @@ -89,15 +89,6 @@ static void __init mt7621_memory_detect(
  50. memblock_add(MT7621_HIGHMEM_BASE, MT7621_HIGHMEM_SIZE);
  51. }
  52. -void __init ralink_of_remap(void)
  53. -{
  54. - rt_sysc_membase = plat_of_remap_node("mediatek,mt7621-sysc");
  55. - rt_memc_membase = plat_of_remap_node("mediatek,mt7621-memc");
  56. -
  57. - if (!rt_sysc_membase || !rt_memc_membase)
  58. - panic("Failed to remap core resources");
  59. -}
  60. -
  61. static unsigned int __init mt7621_get_soc_name0(void)
  62. {
  63. return __raw_readl(MT7621_SYSC_BASE + SYSC_REG_CHIP_NAME0);
  64. --- a/arch/mips/ralink/of.c
  65. +++ b/arch/mips/ralink/of.c
  66. @@ -29,28 +29,56 @@ __iomem void *rt_sysc_membase;
  67. __iomem void *rt_memc_membase;
  68. EXPORT_SYMBOL_GPL(rt_sysc_membase);
  69. -__iomem void *plat_of_remap_node(const char *node)
  70. +static const struct of_device_id mtmips_memc_match[] = {
  71. + { .compatible = "mediatek,mt7621-memc" },
  72. + { .compatible = "ralink,mt7620a-memc" },
  73. + { .compatible = "ralink,rt2880-memc" },
  74. + { .compatible = "ralink,rt3050-memc" },
  75. + { .compatible = "ralink,rt3883-memc" },
  76. + {}
  77. +};
  78. +
  79. +static const struct of_device_id mtmips_sysc_match[] = {
  80. + { .compatible = "mediatek,mt7621-sysc" },
  81. + { .compatible = "ralink,mt7620a-sysc" },
  82. + { .compatible = "ralink,rt2880-sysc" },
  83. + { .compatible = "ralink,rt3050-sysc" },
  84. + { .compatible = "ralink,rt3883-sysc" },
  85. + {}
  86. +};
  87. +
  88. +static __iomem void *
  89. +mtmips_of_remap_node(const struct of_device_id *match, const char *type)
  90. {
  91. struct resource res;
  92. struct device_node *np;
  93. - np = of_find_compatible_node(NULL, NULL, node);
  94. + np = of_find_matching_node(NULL, match);
  95. if (!np)
  96. - panic("Failed to find %s node", node);
  97. + panic("Failed to find %s controller node", type);
  98. if (of_address_to_resource(np, 0, &res))
  99. - panic("Failed to get resource for %s", node);
  100. -
  101. - of_node_put(np);
  102. + panic("Failed to get resource for %s node", np->name);
  103. if (!request_mem_region(res.start,
  104. resource_size(&res),
  105. res.name))
  106. - panic("Failed to request resources for %s", node);
  107. + panic("Failed to request resources for %s node", np->name);
  108. +
  109. + of_node_put(np);
  110. return ioremap(res.start, resource_size(&res));
  111. }
  112. +void __init ralink_of_remap(void)
  113. +{
  114. + rt_sysc_membase = mtmips_of_remap_node(mtmips_sysc_match, "system");
  115. + rt_memc_membase = mtmips_of_remap_node(mtmips_memc_match, "memory");
  116. +
  117. + if (!rt_sysc_membase || !rt_memc_membase)
  118. + panic("Failed to remap core resources");
  119. +}
  120. +
  121. void __init plat_mem_setup(void)
  122. {
  123. void *dtb;
  124. --- a/arch/mips/ralink/rt288x.c
  125. +++ b/arch/mips/ralink/rt288x.c
  126. @@ -17,15 +17,6 @@
  127. #include "common.h"
  128. -void __init ralink_of_remap(void)
  129. -{
  130. - rt_sysc_membase = plat_of_remap_node("ralink,rt2880-sysc");
  131. - rt_memc_membase = plat_of_remap_node("ralink,rt2880-memc");
  132. -
  133. - if (!rt_sysc_membase || !rt_memc_membase)
  134. - panic("Failed to remap core resources");
  135. -}
  136. -
  137. void __init prom_soc_init(struct ralink_soc_info *soc_info)
  138. {
  139. void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT2880_SYSC_BASE);
  140. --- a/arch/mips/ralink/rt305x.c
  141. +++ b/arch/mips/ralink/rt305x.c
  142. @@ -53,15 +53,6 @@ static unsigned long rt5350_get_mem_size
  143. return ret;
  144. }
  145. -void __init ralink_of_remap(void)
  146. -{
  147. - rt_sysc_membase = plat_of_remap_node("ralink,rt3050-sysc");
  148. - rt_memc_membase = plat_of_remap_node("ralink,rt3050-memc");
  149. -
  150. - if (!rt_sysc_membase || !rt_memc_membase)
  151. - panic("Failed to remap core resources");
  152. -}
  153. -
  154. void __init prom_soc_init(struct ralink_soc_info *soc_info)
  155. {
  156. void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT305X_SYSC_BASE);
  157. --- a/arch/mips/ralink/rt3883.c
  158. +++ b/arch/mips/ralink/rt3883.c
  159. @@ -17,15 +17,6 @@
  160. #include "common.h"
  161. -void __init ralink_of_remap(void)
  162. -{
  163. - rt_sysc_membase = plat_of_remap_node("ralink,rt3883-sysc");
  164. - rt_memc_membase = plat_of_remap_node("ralink,rt3883-memc");
  165. -
  166. - if (!rt_sysc_membase || !rt_memc_membase)
  167. - panic("Failed to remap core resources");
  168. -}
  169. -
  170. void __init prom_soc_init(struct ralink_soc_info *soc_info)
  171. {
  172. void __iomem *sysc = (void __iomem *) KSEG1ADDR(RT3883_SYSC_BASE);