Skip to contentSkip to conversation

This patches provide ADSP IPC support for MT8195

PATCH Superseded allen-kh.cheng 2 participants 6 messages Nov 25, 2021 – Nov 26, 2021

Subsystems (3)

v4 of 18 Superseded Latest is v18 →

lore
Share & tools
lore
#0 lore raw

v4 cover This patches provide ADSP IPC support for MT8195

Mediatek ADSP IPC is used to send notification or short message between processors with dsp.·

It will place the message to the share buffer and will access the ADSP mailbox registers to kick dsp.

Two mailboxes used to send notification or short message between processors with dsp

changes since v3:
- reorder MTK_ADSP_IPC_MBOX config
- remove some redundant code
- remove lock in mtk-adsp-mailbox

changes since v2:
- seperate adsp_mailbox into two instances

changes since v1:
- fix dt_binding_check error

Allen-KH Cheng (3):
dt-bindings: mediatek: add adsp-mbox document
firmware: mediatek: add adsp ipc protocol interface
mailbox: mediatek: add support for adsp mailbox controller

 .../bindings/mailbox/mtk,adsp-mbox.yaml       |  52 +++++
 drivers/firmware/Kconfig                      |   1 +
 drivers/firmware/Makefile                     |   1 +
 drivers/firmware/mediatek/Kconfig             |   9 +
 drivers/firmware/mediatek/Makefile            |   2 +
 drivers/firmware/mediatek/mtk-adsp-ipc.c      | 132 +++++++++++++
 drivers/mailbox/Kconfig                       |   7 +
 drivers/mailbox/Makefile                      |   2 +
 drivers/mailbox/mtk-adsp-mailbox.c            | 184 ++++++++++++++++++
 .../linux/firmware/mediatek/mtk-adsp-ipc.h    |  70 +++++++
 10 files changed, 460 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/mtk,adsp-mbox.yaml
 create mode 100644 drivers/firmware/mediatek/Kconfig
 create mode 100644 drivers/firmware/mediatek/Makefile
 create mode 100644 drivers/firmware/mediatek/mtk-adsp-ipc.c
 create mode 100644 drivers/mailbox/mtk-adsp-mailbox.c
 create mode 100644 include/linux/firmware/mediatek/mtk-adsp-ipc.h
Signature · 7 lines
2.18.0


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#1 lore raw

PATCH v4 1/3 dt-bindings: mediatek: add adsp-mbox document

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

This patch adds document for mediatek adsp mbox

---
 .../bindings/mailbox/mtk,adsp-mbox.yaml       | 52 +++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/mtk,adsp-mbox.yaml
Documentation/devicetree/bindings/mailbox/mtk,adsp-mbox.yaml new file +52 -0
new file mode 100644
index 000000000000..a0149566ae56
@@ -0,0 +1,52 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mailbox/mtk,adsp-mbox.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mediatek ADSP mailbox
+
+maintainers:
+  - Allen-KH Cheng <[email protected]>
+
+description: |
+  The MTK ADSP mailbox Inter-Processor Communication (IPC) enables the SoC
+  to ommunicate with ADSP by passing messages through two mailbox channels.
+  The MTK ADSP mailbox IPC also provides the ability for one processor to
+  signal the other processor using interrupts.
+
+properties:
+  compatible:
+    items:
+      - const: mediatek,mt8195-adsp-mbox
+
+  "#mbox-cells":
+    const: 0
+
+  reg:
+    description:
+      Physical address base for dsp mbox base registers.
+
+  interrupts:
+    description:
+      adsp mbox interrupt
+
+required:
+  - compatible
+  - "#mbox-cells"
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    adsp_mailbox0:adsp_mailbox0@10816000 {
+        compatible = "mediatek,mt8195-adsp-mbox";
+        #mbox-cells = <0>;
+        reg = <0x10816000 0x1000>;
+        interrupts = <GIC_SPI 702 IRQ_TYPE_LEVEL_HIGH 0>;
+    };
Signature · 1 line
2.18.0
#2 lore raw

PATCH v4 2/3 firmware: mediatek: add adsp ipc protocol interface

In reply to allen-kh.cheng

From: Allen-KH Cheng <[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                      |   1 +
 drivers/firmware/Makefile                     |   1 +
 drivers/firmware/mediatek/Kconfig             |   9 ++
 drivers/firmware/mediatek/Makefile            |   2 +
 drivers/firmware/mediatek/mtk-adsp-ipc.c      | 132 ++++++++++++++++++
 .../linux/firmware/mediatek/mtk-adsp-ipc.h    |  70 ++++++++++
 6 files changed, 215 insertions(+)
 create mode 100644 drivers/firmware/mediatek/Kconfig
 create mode 100644 drivers/firmware/mediatek/Makefile
 create mode 100644 drivers/firmware/mediatek/mtk-adsp-ipc.c
 create mode 100644 include/linux/firmware/mediatek/mtk-adsp-ipc.h
drivers/firmware/Kconfig +1 -0
index 220a58cf0a44..005f76a9a31a 100644
@@ -301,6 +301,7 @@ source "drivers/firmware/broadcom/Kconfig"
 source "drivers/firmware/google/Kconfig"
 source "drivers/firmware/efi/Kconfig"
 source "drivers/firmware/imx/Kconfig"
+source "drivers/firmware/mediatek/Kconfig"
 source "drivers/firmware/meson/Kconfig"
 source "drivers/firmware/psci/Kconfig"
 source "drivers/firmware/smccc/Kconfig"
drivers/firmware/Makefile +1 -0
index 5ced0673d94b..c0d1f3bdeae4 100644
@@ -33,6 +33,7 @@ obj-$(CONFIG_GOOGLE_FIRMWARE)	+= google/
 obj-$(CONFIG_EFI)		+= efi/
 obj-$(CONFIG_UEFI_CPER)		+= efi/
 obj-y				+= imx/
+obj-y				+= mediatek/
 obj-y				+= psci/
 obj-y				+= smccc/
 obj-y				+= tegra/
drivers/firmware/mediatek/Kconfig new file +9 -0
new file mode 100644
index 000000000000..4d4bf9e62508
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config MTK_ADSP_IPC
+	tristate "MTK ADSP IPC Protocol driver"
+	depends on MTK_ADSP_IPC_MBOX
+	help
+	  Say yes here to add support for the MediaTek ADSP IPC protocol
+	  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 side.
drivers/firmware/mediatek/Makefile new file +2 -0
new file mode 100644
index 000000000000..4e840b65650d
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_MTK_ADSP_IPC)		+= mtk-adsp-ipc.o
drivers/firmware/mediatek/mtk-adsp-ipc.c new file +132 -0

132 lines not on this page · raw message

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

70 lines not on this page · raw message

Signature · 1 line
2.18.0
#3 lore raw

Re: [PATCH v4 2/3] firmware: mediatek: add adsp ipc protocol interface

Quoted 1 line · allen-kh.cheng
drivers/firmware/mediatek/mtk-adsp-ipc.c +0 -0

[...]

drivers/firmware/mediatek/mtk-adsp-ipc.c line 42

Quoted 8 lines
drivers/firmware/mediatek/mtk-adsp-ipc.c +8 -0
+static void adsp_ipc_recv(struct mbox_client *c, void *msg)
+{
+	struct mtk_adsp_chan *chan = container_of(c, struct mtk_adsp_chan, cl);
+
+	if (chan->idx == MTK_ADSP_MBOX_REPLY)
+		chan->ipc->ops->handle_reply(chan->ipc);
+	else
+		chan->ipc->ops->handle_request(chan->ipc);

Using switch ... case ... makes the intention more clear.

Quoted 2 lines
drivers/firmware/mediatek/mtk-adsp-ipc.c +2 -0
+static int mtk_adsp_ipc_probe(struct platform_device *pdev)
+{

[...]

drivers/firmware/mediatek/mtk-adsp-ipc.c line 64

Quoted 4 lines
drivers/firmware/mediatek/mtk-adsp-ipc.c +4 -0
+	for (i = 0; i < MTK_ADSP_MBOX_NUM; i++) {
+		chan_name = kasprintf(GFP_KERNEL, "mbox%d", i);
+		if (!chan_name)
+			return -ENOMEM;

It needs to go error handling path.

drivers/firmware/mediatek/mtk-adsp-ipc.c line 111

Quoted 7 lines
drivers/firmware/mediatek/mtk-adsp-ipc.c +7 -0
+static int mtk_adsp_remove(struct platform_device *pdev)
+{
+	struct mtk_adsp_chan *dsp_chan;
+	struct mtk_adsp_ipc *dsp_ipc;
+	int i;
+
+	dsp_ipc = dev_get_drvdata(&pdev->dev);

To be concise, I would prefer dev_get_drvdata() inline to the line where the variable is declared.

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#4 lore raw

PATCH v4 3/3 mailbox: mediatek: add support for adsp mailbox controller

In reply to allen-kh.cheng

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

This patch is to for MediaTek ADSP IPC mailbox controller driver It is used to send short messages between processors with adsp

---
 drivers/mailbox/Kconfig            |   7 ++
 drivers/mailbox/Makefile           |   2 +
 drivers/mailbox/mtk-adsp-mailbox.c | 184 +++++++++++++++++++++++++++++
 3 files changed, 193 insertions(+)
 create mode 100644 drivers/mailbox/mtk-adsp-mailbox.c
drivers/mailbox/Kconfig +7 -0
index c9fc06c7e685..c44a0102585d 100644
@@ -226,6 +226,13 @@ config STM32_IPCC
 	  with hardware for Inter-Processor Communication Controller (IPCC)
 	  between processors. Say Y here if you want to have this support.
 
+config MTK_ADSP_IPC_MBOX
+	tristate "MediaTek ADSP Mailbox Controller"
+	depends on ARCH_MEDIATEK || COMPILE_TEST
+	help
+	  Say yes here to add support for MediaTek ADSP IPC mailbox controller
+	  driver. It is used to send short messages between processors with dsp.
+
 config MTK_CMDQ_MBOX
 	tristate "MediaTek CMDQ Mailbox Support"
 	depends on ARCH_MEDIATEK || COMPILE_TEST
drivers/mailbox/Makefile +2 -0
index c2089f04887e..13d5c81852ca 100644
@@ -49,6 +49,8 @@ obj-$(CONFIG_TEGRA_HSP_MBOX)	+= tegra-hsp.o
 
 obj-$(CONFIG_STM32_IPCC) 	+= stm32-ipcc.o
 
+obj-$(CONFIG_MTK_ADSP_IPC_MBOX)	+= mtk-adsp-mailbox.o
+
 obj-$(CONFIG_MTK_CMDQ_MBOX)	+= mtk-cmdq-mailbox.o
 
 obj-$(CONFIG_ZYNQMP_IPI_MBOX)	+= zynqmp-ipi-mailbox.o
drivers/mailbox/mtk-adsp-mailbox.c new file +184 -0

184 lines not on this page · raw message

Signature · 7 lines
2.18.0


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#5 lore raw

Re: [PATCH v4 3/3] mailbox: mediatek: add support for adsp mailbox controller

Quoted 1 line · allen-kh.cheng
drivers/mailbox/mtk-adsp-mailbox.c +0 -0

[...]

drivers/mailbox/mtk-adsp-mailbox.c line 99

Quoted 6 lines
drivers/mailbox/mtk-adsp-mailbox.c +6 -0
+static bool mtk_adsp_mbox_last_tx_done(struct mbox_chan *chan)
+{
+	struct adsp_mbox_ch_info *ch_info = chan->con_priv;
+	void __iomem *reg = ch_info->va_reg;
+
+	return (readl(reg + MTK_ADSP_MBOX_IN_CMD) == 0) ? true : false;

To be concise, readl(reg + MTK_ADSP_MBOX_IN_CMD) == 0.

Quoted 2 lines
drivers/mailbox/mtk-adsp-mailbox.c +2 -0
+static int mtk_adsp_mbox_probe(struct platform_device *pdev)
+{

[...]

drivers/mailbox/mtk-adsp-mailbox.c line 142

Quoted 9 lines
drivers/mailbox/mtk-adsp-mailbox.c +9 -0
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "no adsp mbox register resource\n");
+		return -ENXIO;
+	}
+
+	priv->va_mboxreg = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(priv->va_mboxreg))
+		return PTR_ERR(priv->va_mboxreg);

If using devm_platform_ioremap_resource(), it doesn't need to call platform_get_resource(). res is unused.

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek