[PATCH v2 08/14] realtek: add board file for MACH_REALTEK_RTL
Sander Vanheule
sander at svanheule.net
Sun Dec 12 12:01:30 PST 2021
To maintain compatibility with existing drivers, which require the
soc_info struct to be available, add a downstream board file for the
MACH_REALTEK_RTL platform.
MIPS_GENERIC based platforms will iterate through the array of available
MIPS_MACHINE-s to perform platform detection. For devicetree based
platforms, this happens via a call to fixup_fdt. Use this call to
perform the SoC detection, adapted from the old prom.c file.
A list of supported root compatibles are provided, along with matching
register offsets for where to find the SoC model. This offset is then
the only one probed in place of the old detection heuristic.
MIPS_GENERIC also implements its own custom get_system_type(), which can
be customized via the system_type variable. Set this variable to ensure
the specific SoC ID is available at runtime from /proc/cpuinfo.
Co-developed-by: INAGAKI Hiroshi <musashino.open at gmail.com>
Signed-off-by: INAGAKI Hiroshi <musashino.open at gmail.com>
Signed-off-by: Sander Vanheule <sander at svanheule.net>
Tested-by: Bjørn Mork <bjorn at mork.no>
---
v2:
- Fix function definition formatting
---
.../arch/mips/generic/board-realtek.c | 145 ++++++++++++++++++
...-in-board-realtek-for-generic-kernel.patch | 9 ++
2 files changed, 154 insertions(+)
create mode 100644 target/linux/realtek/files-5.10/arch/mips/generic/board-realtek.c
create mode 100644 target/linux/realtek/patches-5.10/309-mips-built-in-board-realtek-for-generic-kernel.patch
diff --git a/target/linux/realtek/files-5.10/arch/mips/generic/board-realtek.c b/target/linux/realtek/files-5.10/arch/mips/generic/board-realtek.c
new file mode 100644
index 000000000000..8ebebcfa7257
--- /dev/null
+++ b/target/linux/realtek/files-5.10/arch/mips/generic/board-realtek.c
@@ -0,0 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Board detection for the Realtek RTL838X, RTL839X, RTL930X, RTL931X SoCs
+ *
+ * based on the original BSP by
+ * Copyright (C) 2006-2012 Tony Wu (tonywu at realtek.com)
+ * Copyright (C) 2020 B. Koblitz
+ *
+ */
+
+#include <asm/bootinfo.h>
+#include <asm/machine.h>
+
+#include <asm/mach-rtl838x/mach-rtl83xx.h>
+
+struct rtl83xx_soc_info soc_info;
+
+static __init void identify_rtl9302(u32 model)
+{
+ switch (model & 0xfffffff0) {
+ case 0x93020810:
+ soc_info.name = "RTL9302A 12x2.5G";
+ break;
+ case 0x93021010:
+ soc_info.name = "RTL9302B 8x2.5G";
+ break;
+ case 0x93021810:
+ soc_info.name = "RTL9302C 16x2.5G";
+ break;
+ case 0x93022010:
+ soc_info.name = "RTL9302D 24x2.5G";
+ break;
+ case 0x93020800:
+ soc_info.name = "RTL9302A";
+ break;
+ case 0x93021000:
+ soc_info.name = "RTL9302B";
+ break;
+ case 0x93021800:
+ soc_info.name = "RTL9302C";
+ break;
+ case 0x93022000:
+ soc_info.name = "RTL9302D";
+ break;
+ case 0x93023001:
+ soc_info.name = "RTL9302F";
+ break;
+ default:
+ soc_info.name = "RTL9302";
+ }
+}
+
+static __init void realtek_detect(u32 info_addr)
+{
+ u32 model;
+
+ model = sw_r32(info_addr);
+ soc_info.id = model >> 16 & 0xFFFF;
+
+ switch (soc_info.id) {
+ case 0x8328:
+ soc_info.name = "RTL8328";
+ soc_info.family = RTL8328_FAMILY_ID;
+ break;
+ case 0x8332:
+ soc_info.name = "RTL8332";
+ soc_info.family = RTL8380_FAMILY_ID;
+ break;
+ case 0x8380:
+ soc_info.name = "RTL8380";
+ soc_info.family = RTL8380_FAMILY_ID;
+ break;
+ case 0x8382:
+ soc_info.name = "RTL8382";
+ soc_info.family = RTL8380_FAMILY_ID;
+ break;
+ case 0x8390:
+ soc_info.name = "RTL8390";
+ soc_info.family = RTL8390_FAMILY_ID;
+ break;
+ case 0x8391:
+ soc_info.name = "RTL8391";
+ soc_info.family = RTL8390_FAMILY_ID;
+ break;
+ case 0x8392:
+ soc_info.name = "RTL8392";
+ soc_info.family = RTL8390_FAMILY_ID;
+ break;
+ case 0x8393:
+ soc_info.name = "RTL8393";
+ soc_info.family = RTL8390_FAMILY_ID;
+ break;
+ case 0x9301:
+ soc_info.name = "RTL9301";
+ soc_info.family = RTL9300_FAMILY_ID;
+ break;
+ case 0x9302:
+ identify_rtl9302(model);
+ soc_info.family = RTL9300_FAMILY_ID;
+ break;
+ case 0x9313:
+ soc_info.name = "RTL9313";
+ soc_info.family = RTL9310_FAMILY_ID;
+ break;
+ default:
+ soc_info.name = "DEFAULT";
+ soc_info.family = 0;
+ }
+
+ system_type = soc_info.name;
+}
+
+static __init const void *realtek_fixup_fdt(const void *fdt, const void *match_data)
+{
+ realtek_detect((u32) match_data);
+
+ return fdt;
+}
+
+static const struct of_device_id realtek_board_ids[] = {
+ /* Downstream compatibles */
+ {
+ .compatible = "realtek,rtl838x-soc",
+ .data = (const void *)RTL838X_MODEL_NAME_INFO,
+ },
+ {
+ .compatible = "realtek,rtl839x-soc",
+ .data = (const void *)RTL839X_MODEL_NAME_INFO,
+ },
+ {
+ .compatible = "realtek,rtl93xx-soc",
+ .data = (const void *)RTL93XX_MODEL_NAME_INFO,
+ },
+ /* Upstream compatibles */
+ {
+ .compatible = "realtek,rtl8382-soc",
+ .data = (const void *)RTL838X_MODEL_NAME_INFO,
+ },
+ { /* sentinel */ }
+};
+
+MIPS_MACHINE(realtek) = {
+ .matches = realtek_board_ids,
+ .fixup_fdt = realtek_fixup_fdt,
+};
diff --git a/target/linux/realtek/patches-5.10/309-mips-built-in-board-realtek-for-generic-kernel.patch b/target/linux/realtek/patches-5.10/309-mips-built-in-board-realtek-for-generic-kernel.patch
new file mode 100644
index 000000000000..83f4d09e19ab
--- /dev/null
+++ b/target/linux/realtek/patches-5.10/309-mips-built-in-board-realtek-for-generic-kernel.patch
@@ -0,0 +1,9 @@
+--- a/arch/mips/generic/Makefile
++++ b/arch/mips/generic/Makefile
+@@ -11,5 +11,6 @@ obj-y += proc.o
+ obj-$(CONFIG_YAMON_DT_SHIM) += yamon-dt.o
+ obj-$(CONFIG_LEGACY_BOARD_SEAD3) += board-sead3.o
+ obj-$(CONFIG_LEGACY_BOARD_OCELOT) += board-ocelot.o
++obj-$(CONFIG_MACH_REALTEK_RTL) += board-realtek.o
+ obj-$(CONFIG_MACH_INGENIC) += board-ingenic.o
+ obj-$(CONFIG_VIRT_BOARD_RANCHU) += board-ranchu.o
--
2.33.1
More information about the openwrt-devel
mailing list