platform: generic: Add Sophgo sg2042 platform support
authorInochi Amaoto <inochiama@outlook.com>
Thu, 19 Oct 2023 23:57:18 +0000 (07:57 +0800)
committerAnup Patel <anup@brainfault.org>
Thu, 16 Nov 2023 15:52:27 +0000 (21:22 +0530)
Add Sophgo sg2042 soc support

Signed-off-by: Inochi Amaoto <inochiama@outlook.com>
Reviewed-by: Guo Ren <guoren@kernel.org>
Reviewed-by: Anup Patel <anup@brainfault.org>
platform/generic/Kconfig
platform/generic/configs/defconfig
platform/generic/sophgo/objects.mk [new file with mode: 0644]
platform/generic/sophgo/sg2042.c [new file with mode: 0644]

index f9e7ed2ab94fb0cafe973e7f4a15831fcce68fc9..a902cf37d927bee276cc626c8e70b8c74bd1817a 100644 (file)
@@ -49,6 +49,12 @@ config PLATFORM_SIFIVE_FU740
        depends on FDT_RESET && FDT_I2C
        default n
 
+config PLATFORM_SOPHGO_SG2042
+       bool "Sophgo sg2042 support"
+       select THEAD_C9XX_ERRATA
+       select THEAD_C9XX_PMU
+       default n
+
 config PLATFORM_STARFIVE_JH7110
        bool "StarFive JH7110 support"
        default n
index 95bab61ea5d9cbcce4f8d2a5469fdcec4611c7b8..1ce6a1204cfca5b68f20dd0e8d54194280db855a 100644 (file)
@@ -3,6 +3,7 @@ CONFIG_PLATFORM_ANDES_AE350=y
 CONFIG_PLATFORM_RENESAS_RZFIVE=y
 CONFIG_PLATFORM_SIFIVE_FU540=y
 CONFIG_PLATFORM_SIFIVE_FU740=y
+CONFIG_PLATFORM_SOPHGO_SG2042=y
 CONFIG_PLATFORM_STARFIVE_JH7110=y
 CONFIG_PLATFORM_THEAD=y
 CONFIG_FDT_GPIO=y
diff --git a/platform/generic/sophgo/objects.mk b/platform/generic/sophgo/objects.mk
new file mode 100644 (file)
index 0000000..3d2908a
--- /dev/null
@@ -0,0 +1,9 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (C) 2023 Inochi Amaoto <inochiama@outlook.com>
+# Copyright (C) 2023 Alibaba Group Holding Limited.
+#
+
+carray-platform_override_modules-$(CONFIG_PLATFORM_SOPHGO_SG2042) += sophgo_sg2042
+platform-objs-$(CONFIG_PLATFORM_SOPHGO_SG2042) += sophgo/sg2042.o
diff --git a/platform/generic/sophgo/sg2042.c b/platform/generic/sophgo/sg2042.c
new file mode 100644 (file)
index 0000000..ae2d702
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Authors:
+ *   Inochi Amaoto <inochiama@outlook.com>
+ *
+ */
+
+#include <platform_override.h>
+#include <thead/c9xx_errata.h>
+#include <thead/c9xx_pmu.h>
+#include <sbi/sbi_const.h>
+#include <sbi/sbi_domain.h>
+#include <sbi/sbi_platform.h>
+#include <sbi/sbi_scratch.h>
+#include <sbi/sbi_string.h>
+#include <sbi_utils/fdt/fdt_helper.h>
+#include <sbi_utils/timer/aclint_mtimer.h>
+
+#define SOPHGO_SG2042_TIMER_BASE       0x70ac000000ULL
+#define SOPHGO_SG2042_TIMER_SIZE       0x10000UL
+#define SOPHGO_SG2042_TIMER_NUM                16
+
+static int sophgo_sg2042_early_init(bool cold_boot,
+                                   const struct fdt_match *match)
+{
+       thead_register_tlb_flush_trap_handler();
+
+       /*
+        * Sophgo sg2042 soc use separate 16 timers while initiating,
+        * merge them as a single domain to avoid wasting.
+        */
+       if (cold_boot)
+               return sbi_domain_root_add_memrange(
+                                       (ulong)SOPHGO_SG2042_TIMER_BASE,
+                                       SOPHGO_SG2042_TIMER_SIZE *
+                                       SOPHGO_SG2042_TIMER_NUM,
+                                       MTIMER_REGION_ALIGN,
+                                       (SBI_DOMAIN_MEMREGION_MMIO |
+                                        SBI_DOMAIN_MEMREGION_M_READABLE |
+                                        SBI_DOMAIN_MEMREGION_M_WRITABLE));
+
+
+       return 0;
+}
+
+static int sophgo_sg2042_extensions_init(const struct fdt_match *match,
+                                        struct sbi_hart_features *hfeatures)
+{
+       thead_c9xx_register_pmu_device();
+       return 0;
+}
+
+static const struct fdt_match sophgo_sg2042_match[] = {
+       { .compatible = "sophgo,sg2042" },
+       { },
+};
+
+const struct platform_override sophgo_sg2042 = {
+       .match_table            = sophgo_sg2042_match,
+       .early_init             = sophgo_sg2042_early_init,
+       .extensions_init        = sophgo_sg2042_extensions_init,
+};