Skip to contentSkip to conversation

firmware: mtk: add adsp ipc protocol for SOF

PATCH In review Tinghan Shen 2 participants 5 messages May 12, 2022 – May 17, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v9 cover firmware: mtk: add adsp ipc protocol for SOF

This patch provides mediatek adsp ipc support for SOF. ADSP IPC protocol offers (send/recv) interfaces using mediatek-mailbox APIs.

This patch was tested and confirmed to work with SOF fw on MT8195 cherry board and MT8186 krabby board.

changes since v8:
- fix patchset 2 and 3.
move "depends on MTK_ADSP_IPC" from SND_SOC_SOF_MTK_COMMON to SND_SOC_SOF_MT8195/MT8186 to prevent generating wrong config.

changes since v7:
- rebase to linux-next/next-22020504
- use EXPORT_SYMBOL_GPL instead of EXPORT_SYMBOL in mtk-adsp-ipc.c
- move mtk-adsp-ipc.c out from driver/firmware/mediatek
- add user of mtk-adsp-ipc.h in patchset 2 and 3.

changes since v6:
- rebase to matthias.bgg/linux.git, v5.18-next/soc
- Prefer "GPL" over "GPL v2" for MODULE_LICENSE

changes since v5:
- fix WARNING: modpost: missing MODULE_LICENSE() in drivers/mailbox /mtk-adsp-mailbox.o. Add MODULE_LICENSE in the last line.
- Due to WARNING: Missing or malformed SPDX-License-Identifier tag in line 1 in checkpatch, we don't remove SPDX-License in line 1.

changes since v4:
- add error message for wrong mbox chan

changes since v3:
- rebase on v5.16-rc8
- update reviewers

changes since v2:
- add out tag for two memory free phases

changes since v1:
- add comments for mtk_adsp_ipc_send and mtk_adsp_ipc_recv
- remove useless MODULE_LICENSE
- change label name to out_free

Allen-KH Cheng (1):
ASoC: SOF: mediatek: Add ipc support for mt8195

TingHan Shen (1):
firmware: mediatek: add adsp ipc protocol interface

Tinghan Shen (1):
ASoC: SOF: mediatek: Add mt8186 ipc support

 drivers/firmware/Kconfig                      |   9 +
 drivers/firmware/Makefile                     |   1 +
 drivers/firmware/mtk-adsp-ipc.c               | 157 ++++++++++++++++++
 .../linux/firmware/mediatek/mtk-adsp-ipc.h    |  65 ++++++++
 sound/soc/sof/mediatek/Kconfig                |   2 +
 sound/soc/sof/mediatek/adsp_helper.h          |  12 +-
 sound/soc/sof/mediatek/mt8186/mt8186-loader.c |   5 +
 sound/soc/sof/mediatek/mt8186/mt8186.c        | 141 ++++++++++++++++
 sound/soc/sof/mediatek/mt8195/mt8195.c        | 138 ++++++++++++++-
 9 files changed, 519 insertions(+), 11 deletions(-)
 create mode 100644 drivers/firmware/mtk-adsp-ipc.c
 create mode 100644 include/linux/firmware/mediatek/mtk-adsp-ipc.h
Signature · 1 line
2.18.0
#1 lore raw

PATCH v9 1/3 firmware: mediatek: Add adsp ipc protocol interface

From: TingHan Shen <[email protected]>

Some of mediatek processors contain
the Tensilica HiFix DSP for audio processing.

The communication between Host CPU and DSP firmware is taking place using a shared memory area for message passing.

ADSP IPC protocol offers (send/recv) interfaces using mediatek-mailbox APIs.

We use two mbox channels to implement a request-reply protocol.

---
 drivers/firmware/Kconfig                      |   9 +
 drivers/firmware/Makefile                     |   1 +
 drivers/firmware/mtk-adsp-ipc.c               | 157 ++++++++++++++++++
 .../linux/firmware/mediatek/mtk-adsp-ipc.h    |  65 ++++++++
 4 files changed, 232 insertions(+)
 create mode 100644 drivers/firmware/mtk-adsp-ipc.c
 create mode 100644 include/linux/firmware/mediatek/mtk-adsp-ipc.h
drivers/firmware/Kconfig +9 -0
index d65964996e8d..b59e3041fd62 100644
@@ -203,6 +203,15 @@ config INTEL_STRATIX10_RSU
 
 	  Say Y here if you want Intel RSU support.
 
+config MTK_ADSP_IPC
+	tristate "MTK ADSP IPC Protocol driver"
+	depends on MTK_ADSP_MBOX
+	help
+	  Say yes here to add support for the MediaTek ADSP IPC
+	  between host AP (Linux) and the firmware running on ADSP.
+	  ADSP exists on some mtk processors.
+	  Client might use shared memory to exchange information with ADSP.
+
 config QCOM_SCM
 	tristate
 
drivers/firmware/Makefile +1 -0
index 4e58cb474a68..1be0e8295222 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_INTEL_STRATIX10_RSU)     += stratix10-rsu.o
 obj-$(CONFIG_ISCSI_IBFT_FIND)	+= iscsi_ibft_find.o
 obj-$(CONFIG_ISCSI_IBFT)	+= iscsi_ibft.o
 obj-$(CONFIG_FIRMWARE_MEMMAP)	+= memmap.o
+obj-$(CONFIG_MTK_ADSP_IPC)	+= mtk-adsp-ipc.o
 obj-$(CONFIG_RASPBERRYPI_FIRMWARE) += raspberrypi.o
 obj-$(CONFIG_FW_CFG_SYSFS)	+= qemu_fw_cfg.o
 obj-$(CONFIG_QCOM_SCM)		+= qcom-scm.o
drivers/firmware/mtk-adsp-ipc.c new file +157 -0

157 lines not on this page · raw message

include/linux/firmware/mediatek/mtk-adsp-ipc.h new file +65 -0

65 lines not on this page · raw message

Signature · 1 line
2.18.0
#2 lore raw

PATCH v9 2/3 ASoC: SOF: mediatek: Add ipc support for mt8195

In reply to Tinghan Shen

From: Allen-KH Cheng <[email protected]>

This patch adds mt8195 IPC support by using mailbox.

On mt8195 resource, there are two mboxes used to handle ipc request and reply. We create a mtk-adsp-ipc client device to request mbox controllers.

---
 sound/soc/sof/mediatek/Kconfig         |   1 +
 sound/soc/sof/mediatek/adsp_helper.h   |  12 +--
 sound/soc/sof/mediatek/mt8195/mt8195.c | 138 ++++++++++++++++++++++++-
 3 files changed, 140 insertions(+), 11 deletions(-)
sound/soc/sof/mediatek/Kconfig +1 -0
index f79e76a6f3c6..f1fa15c41891 100644
@@ -33,6 +33,7 @@ config SND_SOC_SOF_MT8186
 config SND_SOC_SOF_MT8195
 	tristate "SOF support for MT8195 audio DSP"
 	select SND_SOC_SOF_MTK_COMMON
+	depends on MTK_ADSP_IPC
 	help
 	  This adds support for Sound Open Firmware for Mediatek platforms
 	  using the mt8195 processors.
sound/soc/sof/mediatek/adsp_helper.h +4 -8
index f269a2b6c26a..4ab998756bbc 100644
@@ -7,24 +7,22 @@
 #ifndef __MTK_ADSP_HELPER_H__
 #define __MTK_ADSP_HELPER_H__
 
+#include <linux/firmware/mediatek/mtk-adsp-ipc.h>
+
 /*
  * Global important adsp data structure.
  */
-#define DSP_MBOX_NUM	3
-
 struct mtk_adsp_chip_info {
 	phys_addr_t pa_sram;
 	phys_addr_t pa_dram; /* adsp dram physical base */
 	phys_addr_t pa_shared_dram; /* adsp dram physical base */
 	phys_addr_t pa_cfgreg;
-	phys_addr_t pa_mboxreg[DSP_MBOX_NUM];
 	u32 sramsize;
 	u32 dramsize;
 	u32 cfgregsize;
 	void __iomem *va_sram; /* corresponding to pa_sram */
 	void __iomem *va_dram; /* corresponding to pa_dram */
 	void __iomem *va_cfgreg;
-	void __iomem *va_mboxreg[DSP_MBOX_NUM];
 	void __iomem *shared_sram; /* part of  va_sram */
 	void __iomem *shared_dram; /* part of  va_dram */
 	phys_addr_t adsp_bootup_addr;
@@ -42,10 +40,8 @@ struct mtk_adsp_chip_info {
 struct adsp_priv {
 	struct device *dev;
 	struct snd_sof_dev *sdev;
-
-	/* DSP IPC handler */
-	struct mbox_controller *adsp_mbox;
-
+	struct mtk_adsp_ipc *dsp_ipc;
+	struct platform_device *ipc_dev;
 	struct mtk_adsp_chip_info *adsp;
 	struct clk **clk;
 	u32 (*ap2adsp_addr)(u32 addr, void *data);
sound/soc/sof/mediatek/mt8195/mt8195.c +135 -3

181 lines not on this page · raw message

Signature · 1 line
2.18.0
#3 lore raw

PATCH v9 3/3 ASoC: SOF: mediatek: Add mt8186 ipc support

In reply to Tinghan Shen

mt8186 DSP uses two hardware mailbox IP to communicate with AP. One mailbox is used for requests coming from AP, and the other one is for requests from DSP.

---
 sound/soc/sof/mediatek/Kconfig                |   1 +
 sound/soc/sof/mediatek/mt8186/mt8186-loader.c |   5 +
 sound/soc/sof/mediatek/mt8186/mt8186.c        | 141 ++++++++++++++++++
 3 files changed, 147 insertions(+)
sound/soc/sof/mediatek/Kconfig +1 -0
index f1fa15c41891..a149dd1b3f44 100644
@@ -24,6 +24,7 @@ config SND_SOC_SOF_MTK_COMMON
 config SND_SOC_SOF_MT8186
 	tristate "SOF support for MT8186 audio DSP"
 	select SND_SOC_SOF_MTK_COMMON
+	depends on MTK_ADSP_IPC
 	help
 	  This adds support for Sound Open Firmware for Mediatek platforms
 	  using the mt8186 processors.
sound/soc/sof/mediatek/mt8186/mt8186-loader.c +5 -0
index 548b12c33d8a..946e6c43204f 100644
@@ -17,6 +17,11 @@ void mt8186_sof_hifixdsp_boot_sequence(struct snd_sof_dev *sdev, u32 boot_addr)
 	snd_sof_dsp_update_bits(sdev, DSP_REG_BAR, ADSP_HIFI_IO_CONFIG,
 				RUNSTALL, RUNSTALL);
 
+	/* enable mbox 0 & 1 IRQ */
+	snd_sof_dsp_update_bits(sdev, DSP_REG_BAR, ADSP_MBOX_IRQ_EN,
+				DSP_MBOX0_IRQ_EN | DSP_MBOX1_IRQ_EN,
+				DSP_MBOX0_IRQ_EN | DSP_MBOX1_IRQ_EN);
+
 	/* set core boot address */
 	snd_sof_dsp_write(sdev, DSP_SECREG_BAR, ADSP_ALTVEC_C0, boot_addr);
 	snd_sof_dsp_write(sdev, DSP_SECREG_BAR, ADSP_ALTVECSEL, ADSP_ALTVECSEL_C0);
sound/soc/sof/mediatek/mt8186/mt8186.c +141 -0

176 lines not on this page · raw message

Signature · 1 line
2.18.0
maintainer
#4 lore raw
In reply to Tinghan Shen
Quoted 8 lines · Tinghan Shen

This patch provides mediatek adsp ipc support for SOF. ADSP IPC protocol offers (send/recv) interfaces using mediatek-mailbox APIs.

This patch was tested and confirmed to work with SOF fw on MT8195 cherry board and MT8186 krabby board.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/3] firmware: mediatek: Add adsp ipc protocol interface

      commit: 9db69df4bdd37eb1f65b6931ee067fb15b9a4d5c
[2/3] ASoC: SOF: mediatek: Add ipc support for mt8195
      commit: aea9350108ed1627f8610c93de44578162b3ee91
[3/3] ASoC: SOF: mediatek: Add mt8186 ipc support
      commit: e0100bfd383c7d994d2e957e85ca56a5fe5a3f43

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark