-
Notifications
You must be signed in to change notification settings - Fork 349
Add a few fixes for Mediatek mt8188 and mt8195 platforms #10137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2e3f214
fa92c53
cacbaad
85ab536
18f80dc
46e5cd9
46515b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,16 +12,25 @@ | |||||||||||||||||
| */ | ||||||||||||||||||
| #if defined(CONFIG_SOC_MT8186) | ||||||||||||||||||
| #define MTK_AFE_BASE 0x11210000 | ||||||||||||||||||
| #define SRAM_CPU_START 0x10800000 | ||||||||||||||||||
| #elif defined(CONFIG_SOC_SERIES_MT818X) | ||||||||||||||||||
| #define MTK_AFE_BASE 0x10b10000 | ||||||||||||||||||
| #define SRAM_CPU_START 0x10d00000 | ||||||||||||||||||
| #elif defined(CONFIG_SOC_MT8195) | ||||||||||||||||||
| #define MTK_AFE_BASE 0x10890000 | ||||||||||||||||||
| #define SRAM_CPU_START 0x10840000 | ||||||||||||||||||
| #elif defined(CONFIG_SOC_MT8196) | ||||||||||||||||||
| #define MTK_AFE_BASE 0x1a110000 | ||||||||||||||||||
| #define SRAM_CPU_START 0x1a210000 | ||||||||||||||||||
| #else | ||||||||||||||||||
| #error Unrecognized device | ||||||||||||||||||
| #endif | ||||||||||||||||||
|
|
||||||||||||||||||
| #define SRAM_ADSP_START DT_REG_ADDR(DT_NODELABEL(sram0)) | ||||||||||||||||||
| #define SRAM_SIZE DT_REG_SIZE(DT_NODELABEL(sram0)) | ||||||||||||||||||
| #define SRAM_ADSP_END (SRAM_ADSP_START + SRAM_SIZE) | ||||||||||||||||||
| #define SRAM_CPU_END (SRAM_CPU_START + SRAM_SIZE) | ||||||||||||||||||
|
|
||||||||||||||||||
| /* Bitfield register: address, left shift amount, and number of bits */ | ||||||||||||||||||
| struct afe_bitfld { | ||||||||||||||||||
| uint32_t reg; | ||||||||||||||||||
|
|
@@ -70,7 +79,7 @@ struct afe_cfg { | |||||||||||||||||
| */ | ||||||||||||||||||
| static void cfg_convert(const struct afe_cfg *src, struct mtk_base_memif_data *dst) | ||||||||||||||||||
| { | ||||||||||||||||||
| #define REGCVT(R) (((R) > 0) ? ((R) - MTK_AFE_BASE) : -1) | ||||||||||||||||||
| #define REGCVT(R) (((R) > 0) ? ((R) - MTK_AFE_BASE) : 0) | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW: this isn't the AFE driver's struct though, it's the Zephyr-side intermediate. I chose -1 because in a few spots it looked like a zero had valid semantic meaning. But I was doing the port blind.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andyross , I've tried to avoid AFE refactoring that were crashing with a memory violation exception when Lines 92 to 94 in 800f6ce
sof/src/drivers/mediatek/afe/afe-drv.c Lines 179 to 183 in 800f6ce
|
||||||||||||||||||
|
|
||||||||||||||||||
| #define COPYBIT(S, Dr, Ds) do { \ | ||||||||||||||||||
| dst->Dr = REGCVT(src->S.reg); \ | ||||||||||||||||||
|
|
@@ -199,10 +208,68 @@ static const struct dai_info mtk_dai_info = { | |||||||||||||||||
| .num_dai_types = ARRAY_SIZE(mtk_dai_types), | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| #if defined(CONFIG_SOC_SERIES_MT818X) || defined(CONFIG_SOC_MT8195) | ||||||||||||||||||
| static unsigned int mtk_afe2adsp_addr(unsigned int addr) | ||||||||||||||||||
| { | ||||||||||||||||||
| /* CPU -> ADSP address remap */ | ||||||||||||||||||
| if ((addr >= SRAM_CPU_START) && (addr < SRAM_CPU_END)) { | ||||||||||||||||||
| addr = SRAM_ADSP_START + (addr - SRAM_CPU_START); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return addr; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| static unsigned int mtk_adsp2afe_addr(unsigned int addr) | ||||||||||||||||||
| { | ||||||||||||||||||
| /* ADSP -> CPU address remap */ | ||||||||||||||||||
| if ((addr >= SRAM_ADSP_START) && (addr < SRAM_ADSP_END)) { | ||||||||||||||||||
| addr = SRAM_CPU_START + (addr - SRAM_ADSP_START); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return addr; | ||||||||||||||||||
| } | ||||||||||||||||||
| #endif | ||||||||||||||||||
|
|
||||||||||||||||||
| /* Static table of fs register values. TODO: binary search */ | ||||||||||||||||||
| static unsigned int mtk_afe_fs_timing(unsigned int rate) | ||||||||||||||||||
| { | ||||||||||||||||||
| static const struct { int hz, reg; } rate2reg[] = { | ||||||||||||||||||
| #if defined(CONFIG_SOC_MT8188) || defined(CONFIG_SOC_MT8195) | ||||||||||||||||||
| { 7350, 16 }, | ||||||||||||||||||
| { 8000, 0 }, | ||||||||||||||||||
| { 11025, 17 }, | ||||||||||||||||||
| { 12000, 1 }, | ||||||||||||||||||
| { 14700, 18 }, | ||||||||||||||||||
| { 16000, 2 }, | ||||||||||||||||||
| { 22050, 19 }, | ||||||||||||||||||
| { 24000, 3 }, | ||||||||||||||||||
| { 29400, 20 }, | ||||||||||||||||||
| { 32000, 4 }, | ||||||||||||||||||
| { 44100, 21 }, | ||||||||||||||||||
| { 48000, 5 }, | ||||||||||||||||||
| { 88200, 22 }, | ||||||||||||||||||
| { 96000, 6 }, | ||||||||||||||||||
| { 176400, 23 }, | ||||||||||||||||||
| { 192000, 7 }, | ||||||||||||||||||
| { 352800, 24 }, | ||||||||||||||||||
| { 384000, 8 }, | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As these tables grow, it's probably best to migrate them to DTS, or to some better-abstracted representation (like, it looks like most of the divisor values are the same between platforms, but some only have a subset of the available frequencies?) |
||||||||||||||||||
| #elif defined(CONFIG_SOC_MT8186) | ||||||||||||||||||
| { 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 }, | ||||||||||||||||||
| { 352800, 7 }, | ||||||||||||||||||
| { 384000, 3 }, | ||||||||||||||||||
| #else | ||||||||||||||||||
| { 8000, 0 }, | ||||||||||||||||||
| { 11025, 1 }, | ||||||||||||||||||
| { 12000, 2 }, | ||||||||||||||||||
|
|
@@ -218,6 +285,7 @@ static unsigned int mtk_afe_fs_timing(unsigned int rate) | |||||||||||||||||
| { 192000, 18 }, | ||||||||||||||||||
| { 352800, 21 }, | ||||||||||||||||||
| { 384000, 22 }, | ||||||||||||||||||
| #endif | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| for (int i = 0; i < ARRAY_SIZE(rate2reg); i++) | ||||||||||||||||||
|
|
@@ -242,6 +310,10 @@ struct mtk_base_afe_platform mtk_afe_platform = { | |||||||||||||||||
| .dais_size = ARRAY_SIZE(mtk_dais), | ||||||||||||||||||
| .afe_fs = mtk_afe_fs, | ||||||||||||||||||
| .irq_fs = mtk_afe_fs_timing, | ||||||||||||||||||
| #if defined(CONFIG_SOC_SERIES_MT818X) || defined(CONFIG_SOC_MT8195) | ||||||||||||||||||
| .afe2adsp_addr = mtk_afe2adsp_addr, | ||||||||||||||||||
| .adsp2afe_addr = mtk_adsp2afe_addr, | ||||||||||||||||||
| #endif | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| int mtk_dai_init(struct sof *sof) | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,7 +122,11 @@ enum sof_dma_cb_status { | |
| /* Attributes have been ported to Zephyr. This condition is necessary until full support of | ||
| * CONFIG_SOF_ZEPHYR_STRICT_HEADERS. | ||
| */ | ||
| #ifdef CONFIG_ZEPHYR_NATIVE_DRIVERS | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one seems confusing. This header shouldn't be included if the SOF drivers are in use, no? I suspect the real bug here is upstream header hygiene, some include or another should probably be guarded.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| struct sof_dma; | ||
| #else | ||
| struct dma; | ||
| #endif | ||
|
|
||
| /** | ||
| * \brief Element of SG list (as array item). | ||
|
|
@@ -194,7 +198,11 @@ struct dma_plat_data { | |
| uint32_t period_count; | ||
| }; | ||
|
|
||
| #ifdef CONFIG_ZEPHYR_NATIVE_DRIVERS | ||
| struct sof_dma { | ||
| #else | ||
| struct dma { | ||
| #endif | ||
| struct dma_plat_data plat_data; | ||
| struct k_spinlock lock; /**< locking mechanism */ | ||
| int sref; /**< simple ref counter, guarded by lock */ | ||
|
|
@@ -206,7 +214,11 @@ struct sof_dma { | |
| }; | ||
|
|
||
| struct dma_chan_data { | ||
| #ifdef CONFIG_ZEPHYR_NATIVE_DRIVERS | ||
| struct sof_dma *dma; | ||
| #else | ||
| struct dma *dma; | ||
| #endif | ||
|
|
||
| uint32_t status; | ||
| uint32_t direction; | ||
|
|
@@ -224,14 +236,22 @@ struct dma_chan_data { | |
| }; | ||
|
|
||
| struct dma_info { | ||
| #ifdef CONFIG_ZEPHYR_NATIVE_DRIVERS | ||
| struct sof_dma *dma_array; | ||
| #else | ||
| struct dma *dma_array; | ||
| #endif | ||
| size_t num_dmas; | ||
| }; | ||
|
|
||
| /* generic DMA DSP <-> Host copier */ | ||
| struct dma_copy { | ||
| struct dma_chan_data *chan; | ||
| #ifdef CONFIG_ZEPHYR_NATIVE_DRIVERS | ||
| struct sof_dma *dmac; | ||
| #else | ||
| struct dma *dmac; | ||
| #endif | ||
| }; | ||
|
|
||
| struct audio_stream; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,7 +113,13 @@ extern char _mtk_adsp_sram_end; | |
| #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)) | ||
|
|
||
| /* Heap size is limited to 0x7fffU chunk units when CONFIG_SYS_HEAP_SMALL_ONLY is set */ | ||
| #if defined(CONFIG_SYS_HEAP_SMALL_ONLY) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly not sure why SOF is setting this. It's a code size thing, intended to reduce .text footprint on devices whose RAM heaps will never be beyond 256kb. But SOF is actually a really large Zephyr app. Probably best to just turn it off. But doing the clamp here just for safety isn't wrong either, and it allows cleaner use of the suffix of the region for non-heap things. |
||
| #define HEAPMEM_SIZE MIN(((uint8_t *)SRAM_END - heapmem), 0x7fff * 8) | ||
| #else | ||
| #define HEAPMEM_SIZE ((uint8_t *)SRAM_END - heapmem) | ||
| #endif /* CONFIG_SYS_HEAP_SMALL_ONLY */ | ||
|
|
||
| #else | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: maybe "HOST_START" or "AP_START" or "LINUX_START" and not "CPU", which is ambiguous. (Zephyr has "cpus" too).