From 9e5bccafbfd41325e69740413d7623c9bdaa0fc3 Mon Sep 17 00:00:00 2001 From: Andrew Perepech Date: Mon, 19 May 2025 18:03:28 -0700 Subject: [PATCH 1/5] platform/mtk: Add Zephyr support for MTK MT8365 platform Add Zephyr support for MTK MT8365 platform Signed-off-by: Andrew Perepech --- src/platform/mtk/dai.c | 17 ++++++ .../mtk/include/platform/lib/memory.h | 2 +- src/platform/mtk/platform.c | 53 +++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/platform/mtk/dai.c b/src/platform/mtk/dai.c index cb6ebc144624..2f6170bf2a6a 100644 --- a/src/platform/mtk/dai.c +++ b/src/platform/mtk/dai.c @@ -22,6 +22,9 @@ #elif defined(CONFIG_SOC_MT8196) #define MTK_AFE_BASE 0x1a110000 #define SRAM_CPU_START 0x1a210000 +#elif defined(CONFIG_SOC_MT8365) +#define MTK_AFE_BASE 0x11220000 +#define SRAM_CPU_START 0x40020000 #else #error Unrecognized device #endif @@ -269,6 +272,20 @@ static unsigned int mtk_afe_fs_timing(unsigned int rate) { 192000, 14 }, { 352800, 7 }, { 384000, 3 }, +#elif defined(CONFIG_SOC_MT8365) + { 8000, 0 }, + { 11025, 1 }, + { 12000, 2 }, + { 16000, 4 }, + { 22050, 5 }, + { 24000, 6 }, + { 32000, 8 }, + { 44100, 9 }, + { 48000, 10 }, + { 88200, 11 }, + { 96000, 12 }, + { 176400, 13 }, + { 192000, 14 }, #else { 8000, 0 }, { 11025, 1 }, diff --git a/src/platform/mtk/include/platform/lib/memory.h b/src/platform/mtk/include/platform/lib/memory.h index a84809bf2d48..26806ab394ba 100644 --- a/src/platform/mtk/include/platform/lib/memory.h +++ b/src/platform/mtk/include/platform/lib/memory.h @@ -42,7 +42,7 @@ static inline void *platform_shared_get(void *ptr, int bytes) * validation that the kernel driver interprets the manifest * correctly. Right now we're using the historical addresses. */ -#ifdef CONFIG_SOC_MT8195 +#if defined(CONFIG_SOC_MT8195) || defined(CONFIG_SOC_MT8365) #define MTK_IPC_BASE (DT_REG_ADDR(DT_NODELABEL(dram0)) + 0x800000) #else #define MTK_IPC_BASE (DT_REG_ADDR(DT_NODELABEL(dram0)) + 0x500000) diff --git a/src/platform/mtk/platform.c b/src/platform/mtk/platform.c index 1592c020f7a2..c189af1f0a16 100644 --- a/src/platform/mtk/platform.c +++ b/src/platform/mtk/platform.c @@ -24,12 +24,25 @@ void mtk_dai_init(struct sof *sof); +#ifndef CONFIG_SOC_MT8365 #define MBOX0 DEVICE_DT_GET(DT_INST(0, mediatek_mbox)) #define MBOX1 DEVICE_DT_GET(DT_INST(1, mediatek_mbox)) +#else +#define IPI DEVICE_DT_GET(DT_INST(0, mediatek_ipi)) + +#define MAILBOX_DEBUG_BASE MTK_IPC_WIN_BASE(DEBUG) + +#define SRAM_REG_OP_CPU2DSP 0x8 +#define SRAM_REG_OP_DSP2CPU 0xC + +#define ADSP_IPI_OP_REQ 0x1 +#define ADSP_IPI_OP_RSP 0x2 +#endif /* Use the same UUID as in "ipc-zephyr.c", which is actually an Intel driver */ SOF_DEFINE_REG_UUID(zipc_task); +#ifndef CONFIG_SOC_MT8365 static void mbox_cmd_fn(const struct device *mbox, void *arg) { /* We're in ISR context. This unblocks the IPC task thread, @@ -38,6 +51,7 @@ static void mbox_cmd_fn(const struct device *mbox, void *arg) */ ipc_schedule_process(ipc_get()); } +#endif enum task_state ipc_platform_do_cmd(struct ipc *ipc) { @@ -54,13 +68,23 @@ enum task_state ipc_platform_do_cmd(struct ipc *ipc) void ipc_platform_complete_cmd(struct ipc *ipc) { +#ifndef CONFIG_SOC_MT8365 mtk_adsp_mbox_signal(MBOX0, 1); +#else + *(uint32_t *)(MAILBOX_DEBUG_BASE + SRAM_REG_OP_DSP2CPU) = ADSP_IPI_OP_RSP; + mtk_adsp_ipi_signal(IPI, 1); +#endif } static void mtk_ipc_send(const void *msg, size_t sz) { mailbox_dspbox_write(0, msg, sz); +#ifndef CONFIG_SOC_MT8365 mtk_adsp_mbox_signal(MBOX1, 0); +#else + *(uint32_t *)(MAILBOX_DEBUG_BASE + SRAM_REG_OP_DSP2CPU) = ADSP_IPI_OP_REQ; + mtk_adsp_ipi_signal(IPI, 1); +#endif } int ipc_platform_send_msg(const struct ipc_msg *msg) @@ -75,11 +99,36 @@ int ipc_platform_send_msg(const struct ipc_msg *msg) return 0; } +#ifndef CONFIG_SOC_MT8365 static void mbox_reply_fn(const struct device *mbox, void *arg) { ipc_get()->is_notification_pending = false; } +#else + +static void ipi_handler_fn(const struct device *ipi, void *arg) +{ + uint32_t op; + + op = *(uint32_t *)(MAILBOX_DEBUG_BASE + SRAM_REG_OP_CPU2DSP); + + switch (op) { + case ADSP_IPI_OP_REQ: + /* new message from host */ + ipc_schedule_process(ipc_get()); + break; + case ADSP_IPI_OP_RSP: + /* reply message(done) from host */ + ipc_get()->is_notification_pending = false; + break; + default: + /* do nothing */ + break; + } +} +#endif + /* "Host Page Table" support. The platform is responsible for * providing a buffer into which the IPC layer reads a DMA "page * table" from the host. This isn't really a page table, it's a @@ -114,8 +163,12 @@ int platform_ipc_init(struct ipc *ipc) schedule_task_init_edf(&ipc->ipc_task, SOF_UUID(zipc_task_uuid), &ipc_task_ops, ipc, 0, 0); +#ifndef CONFIG_SOC_MT8365 mtk_adsp_mbox_set_handler(MBOX0, 0, mbox_cmd_fn, NULL); mtk_adsp_mbox_set_handler(MBOX1, 1, mbox_reply_fn, NULL); +#else + mtk_adsp_ipi_set_handler(IPI, 0, ipi_handler_fn, NULL); +#endif return 0; } From 32656ef44189b8535a4e4d8aa6457495a0f737a0 Mon Sep 17 00:00:00 2001 From: Andrew Perepech Date: Tue, 7 Oct 2025 12:05:18 -0700 Subject: [PATCH 2/5] app/boards: Add configuration for MT8365 board Add configuration for Mediatek MT8365 board Signed-off-by: Andrew Perepech --- app/boards/mt8365_mt8365_adsp.conf | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 app/boards/mt8365_mt8365_adsp.conf diff --git a/app/boards/mt8365_mt8365_adsp.conf b/app/boards/mt8365_mt8365_adsp.conf new file mode 100644 index 000000000000..7c9d3647e8cc --- /dev/null +++ b/app/boards/mt8365_mt8365_adsp.conf @@ -0,0 +1,10 @@ +# Boilerplate. Because the "Platform" is a kconfig "choice" (of which +# "MTK" is an member), it can't be selected automatically from other +# kconfigs, nor expressed as a default. Don't put anything else here. +# Board-level config goes in Zephyr (and ideally in DTS). App-level +# config goes in prj.conf. +CONFIG_MTK=y + +# Override project default setting so 1 millisecond is exactly +# represented by an integral number of ticks. +CONFIG_SYS_CLOCK_TICKS_PER_SEC=13000 \ No newline at end of file From e12973389369c1f68c52bad338601fbdb5739104 Mon Sep 17 00:00:00 2001 From: Andrew Perepech Date: Tue, 7 Oct 2025 12:08:37 -0700 Subject: [PATCH 3/5] scripts: Add MT8365 to the SOF Zephyr build script Add MT8365 platform to the SOF Zephyr build script Signed-off-by: Andrew Perepech --- scripts/xtensa-build-zephyr.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/xtensa-build-zephyr.py b/scripts/xtensa-build-zephyr.py index 40931ba6623a..45ffd68fc676 100755 --- a/scripts/xtensa-build-zephyr.py +++ b/scripts/xtensa-build-zephyr.py @@ -145,6 +145,11 @@ class PlatformConfig: f"RJ-2024.3{xtensa_tools_version_postfix}", "HiFi5_MPU_lock_2023_11", ), + "mt8365" : PlatformConfig( + "mtk", "mt8365/mt8365/adsp", + f"RJ-2024.3{xtensa_tools_version_postfix}", + "hifi4_Aquila_E2_PROD", + ), } # These can all be built out of the box. --all builds all these. @@ -1288,7 +1293,7 @@ def gzip_compress(fname, gzdst=None): RI_INFO_UNSUPPORTED += ['imx8', 'imx8x', 'imx8m', 'imx8ulp', 'imx95'] RI_INFO_UNSUPPORTED += ['rn', 'acp_6_0'] -RI_INFO_UNSUPPORTED += ['mt8186', 'mt8188', 'mt8195', 'mt8196'] +RI_INFO_UNSUPPORTED += ['mt8186', 'mt8188', 'mt8195', 'mt8196', 'mt8365'] # For temporary workarounds. Unlike _UNSUPPORTED above, the platforms below will print a warning. RI_INFO_FIXME = [ ] From 9bd165d45c4da86b25f4c1a7f41a6702a2f1b327 Mon Sep 17 00:00:00 2001 From: Andrew Perepech Date: Wed, 30 Jul 2025 12:07:12 -0700 Subject: [PATCH 4/5] platform/mtk: Allow AFE DAI configs without .fs property Allow creating DAI configs without .fs property. MT8365 afe_tdm_in and afe_tdm_out DAIs does not have register to configure sampling rate. Signed-off-by: Andrew Perepech --- src/platform/mtk/dai.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/mtk/dai.c b/src/platform/mtk/dai.c index 2f6170bf2a6a..f1ba45036dd5 100644 --- a/src/platform/mtk/dai.c +++ b/src/platform/mtk/dai.c @@ -136,7 +136,7 @@ static void cfg_convert(const struct afe_cfg *src, struct mtk_base_memif_data *d .base = DT_PROP(n, base), \ .end = DT_PROP(n, end), \ .cur = DT_PROP(n, cur), \ - .fs = DT_PROP(n, fs), \ + COND_PROP(n, fs) \ .hd = DT_PROP(n, hd), \ .enable = DT_PROP(n, enable), \ COND_PROP(n, mono) \ From ff78dd09da9699cd191a82f83b55ba1521ff0a0c Mon Sep 17 00:00:00 2001 From: Andrew Perepech Date: Wed, 4 Jun 2025 12:49:07 -0700 Subject: [PATCH 5/5] zephyr: alloc: Move heap on MT8365 platform to ADSP SRAM sram0 memory region holds vectors and heap. On MT8365 platform it is assigned to DRAM. Allocate heap on MT8365 platform on ADSP SRAM instead. Signed-off-by: Andrew Perepech --- src/platform/mtk/dai.c | 2 +- zephyr/lib/alloc.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/platform/mtk/dai.c b/src/platform/mtk/dai.c index f1ba45036dd5..17fbc665dfbe 100644 --- a/src/platform/mtk/dai.c +++ b/src/platform/mtk/dai.c @@ -24,7 +24,7 @@ #define SRAM_CPU_START 0x1a210000 #elif defined(CONFIG_SOC_MT8365) #define MTK_AFE_BASE 0x11220000 -#define SRAM_CPU_START 0x40020000 +#define SRAM_CPU_START 0x1e000000 #else #error Unrecognized device #endif diff --git a/zephyr/lib/alloc.c b/zephyr/lib/alloc.c index 17d8d1a20af5..0507678915bf 100644 --- a/zephyr/lib/alloc.c +++ b/zephyr/lib/alloc.c @@ -120,10 +120,17 @@ char __aligned(8) heapmem[HEAPMEM_SIZE]; #elif defined(CONFIG_SOC_FAMILY_MTK) extern char _mtk_adsp_sram_end; +#if defined(CONFIG_SOC_MT8365) +#define SRAM_START DT_REG_ADDR(DT_NODELABEL(sram1)) +#define SRAM_SIZE DT_REG_SIZE(DT_NODELABEL(sram1)) +#define heapmem ((uint8_t *)SRAM_START) +#else #define SRAM_START DT_REG_ADDR(DT_NODELABEL(sram0)) #define SRAM_SIZE DT_REG_SIZE(DT_NODELABEL(sram0)) -#define SRAM_END (SRAM_START + SRAM_SIZE) #define heapmem ((uint8_t *)ALIGN_UP((uintptr_t)&_mtk_adsp_sram_end, PLATFORM_DCACHE_ALIGN)) +#endif /* CONFIG_SOC_MT8365 */ + +#define SRAM_END (SRAM_START + SRAM_SIZE) /* Heap size is limited to 0x7fffU chunk units when CONFIG_SYS_HEAP_SMALL_ONLY is set */ #if defined(CONFIG_SYS_HEAP_SMALL_ONLY)