From: Krzysztof Kozlowski <krzk@kernel.org>
To: "Karl.Li" <karl.li@mediatek.com>,
Jassi Brar <jassisinghbrar@gmail.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
Chungying Lu <chungying.lu@mediatek.com>,
Project_Global_Chrome_Upstream_Group@mediatek.com
Subject: Re: [PATCH 3/3] mailbox: mediatek: Add mtk-apu-mailbox driver
Date: Thu, 24 Oct 2024 11:45:53 +0200 [thread overview]
Message-ID: <d1264f6b-07bd-41e4-848d-1775a1f45884@kernel.org> (raw)
In-Reply-To: <20241024092608.431581-4-karl.li@mediatek.com>
On 24/10/2024 11:25, Karl.Li wrote:
> From: Karl Li <karl.li@mediatek.com>
>
> Add mtk-apu-mailbox driver to support the communication with
> APU remote microprocessor.
>
> Also, the mailbox hardware contains extra spare (scratch) registers
> that other hardware blocks use to communicate through.
> Expose these with custom mtk_apu_mbox_(read|write)() functions.
>
> Signed-off-by: Karl Li <karl.li@mediatek.com>
> ---
> drivers/mailbox/Kconfig | 9 +
> drivers/mailbox/Makefile | 2 +
> drivers/mailbox/mtk-apu-mailbox.c | 222 ++++++++++++++++++++++++
> include/linux/mailbox/mtk-apu-mailbox.h | 20 +++
> 4 files changed, 253 insertions(+)
> create mode 100644 drivers/mailbox/mtk-apu-mailbox.c
> create mode 100644 include/linux/mailbox/mtk-apu-mailbox.h
>
> diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig
> index 6fb995778636..2338e08a110a 100644
> --- a/drivers/mailbox/Kconfig
> +++ b/drivers/mailbox/Kconfig
> @@ -240,6 +240,15 @@ config MTK_ADSP_MBOX
> between processors with ADSP. It will place the message to share
> buffer and will access the ipc control.
>
> +config MTK_APU_MBOX
> + tristate "MediaTek APU Mailbox Support"
> + depends on ARCH_MEDIATEK || COMPILE_TEST
> + help
> + Say yes here to add support for the MediaTek APU Mailbox
> + driver. The mailbox implementation provides access from the
> + application processor to the MediaTek AI Processing Unit.
> + If unsure say N.
> +
> config MTK_CMDQ_MBOX
> tristate "MediaTek CMDQ Mailbox Support"
> depends on ARCH_MEDIATEK || COMPILE_TEST
> diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile
> index 3c3c27d54c13..6b6dcc78d644 100644
> --- a/drivers/mailbox/Makefile
> +++ b/drivers/mailbox/Makefile
> @@ -53,6 +53,8 @@ obj-$(CONFIG_STM32_IPCC) += stm32-ipcc.o
>
> obj-$(CONFIG_MTK_ADSP_MBOX) += mtk-adsp-mailbox.o
>
> +obj-$(CONFIG_MTK_APU_MBOX) += mtk-apu-mailbox.o
> +
> obj-$(CONFIG_MTK_CMDQ_MBOX) += mtk-cmdq-mailbox.o
>
> obj-$(CONFIG_ZYNQMP_IPI_MBOX) += zynqmp-ipi-mailbox.o
> diff --git a/drivers/mailbox/mtk-apu-mailbox.c b/drivers/mailbox/mtk-apu-mailbox.c
> new file mode 100644
> index 000000000000..b347ebd34ef7
> --- /dev/null
> +++ b/drivers/mailbox/mtk-apu-mailbox.c
> @@ -0,0 +1,222 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2024 MediaTek Inc.
> + */
> +
> +#include <asm/io.h>
> +#include <linux/bits.h>
> +#include <linux/interrupt.h>
> +#include <linux/mailbox_controller.h>
> +#include <linux/mailbox/mtk-apu-mailbox.h>
> +#include <linux/platform_device.h>
> +
> +#define INBOX (0x0)
> +#define OUTBOX (0x20)
> +#define INBOX_IRQ (0xc0)
> +#define OUTBOX_IRQ (0xc4)
> +#define INBOX_IRQ_MASK (0xd0)
> +
> +#define SPARE_OFF_START (0x40)
> +#define SPARE_OFF_END (0xB0)
> +
> +struct mtk_apu_mailbox {
> + struct device *dev;
> + void __iomem *regs;
> + struct mbox_controller controller;
> + u32 msgs[MSG_MBOX_SLOTS];
> +};
> +
> +struct mtk_apu_mailbox *g_mbox;
Why this is global? And why do you support only one device?
No, drop.
> +
> +static irqreturn_t mtk_apu_mailbox_irq_top_half(int irq, void *dev_id)
> +{
> + struct mtk_apu_mailbox *mbox = dev_id;
> + struct mbox_chan *link = &mbox->controller.chans[0];
> + int i;
> +
> + for (i = 0; i < MSG_MBOX_SLOTS; i++)
> + mbox->msgs[i] = readl(mbox->regs + OUTBOX + i * sizeof(u32));
> +
> + mbox_chan_received_data(link, &mbox->msgs);
> +
> + return IRQ_WAKE_THREAD;
> +}
> +
...
> +/**
> + * mtk_apu_mbox_write - Write value to specifice mtk_apu_mbox spare register.
> + * @val: Value to be written.
> + * @offset: Offset of the spare register.
> + *
> + * Return: 0 if successful
> + * negative value if error happened
> + */
> +int mtk_apu_mbox_write(u32 val, u32 offset)
> +{
> + if (!g_mbox) {
> + pr_err("mtk apu mbox was not initialized, stop writing register\n");
> + return -ENODEV;
> + }
> +
> + if (offset < SPARE_OFF_START || offset >= SPARE_OFF_END) {
> + dev_err(g_mbox->dev, "Invalid offset %d for mtk apu mbox spare register\n", offset);
> + return -EINVAL;
> + }
> +
> + writel(val, g_mbox->regs + offset);
> + return 0;
> +}
> +EXPORT_SYMBOL_NS(mtk_apu_mbox_write, MTK_APU_MAILBOX);
Use mailbox API. This is really poor solution.
> +
> +/**
> + * mtk_apu_mbox_read - Read value to specifice mtk_apu_mbox spare register.
> + * @offset: Offset of the spare register.
> + * @val: Pointer to store read value.
> + *
> + * Return: 0 if successful
> + * negative value if error happened
> + */
> +int mtk_apu_mbox_read(u32 offset, u32 *val)
> +{
> + if (!g_mbox) {
> + pr_err("mtk apu mbox was not initialized, stop reading register\n");
> + return -ENODEV;
> + }
> +
> + if (offset < SPARE_OFF_START || offset >= SPARE_OFF_END) {
> + dev_err(g_mbox->dev, "Invalid offset %d for mtk apu mbox spare register\n", offset);
> + return -EINVAL;
> + }
> +
> + *val = readl(g_mbox->regs + offset);
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_NS(mtk_apu_mbox_read, MTK_APU_MAILBOX);
> +
> +static int mtk_apu_mailbox_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct mtk_apu_mailbox *mbox;
> + int irq = -1, ret = 0;
> +
> + mbox = devm_kzalloc(dev, sizeof(*mbox), GFP_KERNEL);
> + if (!mbox)
> + return -ENOMEM;
> +
> + mbox->dev = dev;
> + platform_set_drvdata(pdev, mbox);
> +
> + mbox->regs = devm_platform_ioremap_resource(pdev, 0);
> + if (IS_ERR(mbox->regs))
> + return PTR_ERR(mbox->regs);
> +
> + mbox->controller.txdone_irq = false;
> + mbox->controller.txdone_poll = true;
> + mbox->controller.txpoll_period = 1;
> + mbox->controller.ops = &mtk_apu_mailbox_ops;
> + mbox->controller.dev = dev;
> + /*
> + * Here we only register 1 mbox channel.
> + * The remaining channels are used by other modules.
> + */
> + mbox->controller.num_chans = 1;
> + mbox->controller.chans = devm_kcalloc(dev, mbox->controller.num_chans,
> + sizeof(*mbox->controller.chans),
> + GFP_KERNEL);
> + if (!mbox->controller.chans)
> + return -ENOMEM;
> +
> + ret = devm_mbox_controller_register(dev, &mbox->controller);
> + if (ret)
> + return ret;
> +
> + irq = platform_get_irq(pdev, 0);
> + if (irq < 0)
> + return irq;
> +
> + ret = devm_request_threaded_irq(dev, irq, mtk_apu_mailbox_irq_top_half,
> + mtk_apu_mailbox_irq_btm_half, IRQF_ONESHOT,
> + dev_name(dev), mbox);
> + if (ret)
> + return dev_err_probe(dev, ret, "Failed to request IRQ\n");
> +
> + g_mbox = mbox;
> +
> + dev_dbg(dev, "registered mtk apu mailbox\n");
No, drop such stuff.
> +
> + return 0;
> +}
> +
> +static void mtk_apu_mailbox_remove(struct platform_device *pdev)
> +{
> + g_mbox = NULL;
> +}
> +
> +static const struct of_device_id mtk_apu_mailbox_of_match[] = {
> + { .compatible = "mediatek,mt8188-apu-mailbox" },
> + { .compatible = "mediatek,mt8196-apu-mailbox" },
So devices are compatible? Make them compatible in the binding and drop
unneeded compatible here.
Best regards,
Krzysztof
next prev parent reply other threads:[~2024-10-24 9:46 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-24 9:25 [PATCH 0/3] Add MediaTek APU Mailbox Support For MT8196 Karl.Li
2024-10-24 9:25 ` [PATCH 1/3] dt-bindings: mailbox: mediatek: Add apu-mailbox document Karl.Li
2024-10-24 9:42 ` Krzysztof Kozlowski
2024-10-24 11:08 ` AngeloGioacchino Del Regno
2024-10-24 13:45 ` Rob Herring (Arm)
2024-10-24 9:25 ` [PATCH 2/3] mailbox: add support for bottom half received data Karl.Li
2024-10-24 11:05 ` AngeloGioacchino Del Regno
2024-10-24 9:25 ` [PATCH 3/3] mailbox: mediatek: Add mtk-apu-mailbox driver Karl.Li
2024-10-24 9:45 ` Krzysztof Kozlowski [this message]
2024-10-24 11:04 ` AngeloGioacchino Del Regno
2024-10-28 6:16 ` Chen-Yu Tsai
2024-10-29 8:27 ` Karl Li (李智嘉)
2024-12-05 7:05 ` Karl Li (李智嘉)
2024-12-05 7:32 ` Karl Li (李智嘉)
2024-12-10 8:32 ` AngeloGioacchino Del Regno
2024-12-10 8:44 ` Krzysztof Kozlowski
2024-12-10 8:45 ` Krzysztof Kozlowski
2024-10-27 4:38 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d1264f6b-07bd-41e4-848d-1775a1f45884@kernel.org \
--to=krzk@kernel.org \
--cc=Project_Global_Chrome_Upstream_Group@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=chungying.lu@mediatek.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jassisinghbrar@gmail.com \
--cc=karl.li@mediatek.com \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).