From nobody Sun Nov 24 23:07:00 2024 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 470001CC88C for ; Thu, 31 Oct 2024 20:47:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730407666; cv=none; b=pF5pytu/ymqWtMkNZR4Eswo/XooJH39hZWvYwOny6N7xE9NcXAxD83+INzqpgGSwG3w+OAL9xeZyDHsN3Ew5ZWKp1WNl7pxmNUB28acjjgc7ICKCyFfaJGN3YKRvs+1DJ5dpxBCifMGZ0zzjy/CE6zOaDfLfrCXxVbOd0p/WueQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730407666; c=relaxed/simple; bh=p1aGIAIQ30yHRB3g87qsYqrlAnIwusF/8c167MToFEY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=dmpRjTgH3CQQJsIsY4GJEbZZe9xJOYVRRDRXMaigVmWt2vPj43mHb49+1SkVIxj38e/PXnSnjQYhH1kurMdEcoZfMjluqOSVne7aooncRcUXUrNKapV/viK6ByFpPETc0zZdeaQ+uxG/qYRiiPHqFAs3F45APP0FKF24SNw1BGk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=kJ3El+7g; arc=none smtp.client-ip=210.118.77.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="kJ3El+7g" Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20241031204737euoutp025aaed910826896c31a6913f97f2cdba1~DpJihy7eF2196821968euoutp02u for ; Thu, 31 Oct 2024 20:47:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20241031204737euoutp025aaed910826896c31a6913f97f2cdba1~DpJihy7eF2196821968euoutp02u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1730407657; bh=dkahNnGGCiryvz/YIk3Koma9tzvUz9qNYXCl2UIggEs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kJ3El+7gWCyM8yvJuOl/JJ+Fzm4klP5dknFIYHORfqwlI7R0HE+XanS4SH+latWaU T27OyvX9HlUXN4vk94aklP7u01kc3Um/Bx83WPbzjpmMCS/2SfIVI9t9HYCy1+xyEH emIvGo6KaGxd5ypWVrBskyppRwNoxXIMYQkLF7lI= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20241031204735eucas1p1ce4824f17b77238c81aaf374436fe164~DpJhL721h2189621896eucas1p1f; Thu, 31 Oct 2024 20:47:35 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 9D.00.20397.7ECE3276; Thu, 31 Oct 2024 20:47:35 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20241031204734eucas1p1ec2a8a101e805802a851b01d87709061~DpJf4t5bi2174621746eucas1p1T; Thu, 31 Oct 2024 20:47:34 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20241031204734eusmtrp2373c40e9c0baaae21f183a7fec87160c~DpJf38rAy1392413924eusmtrp2u; Thu, 31 Oct 2024 20:47:34 +0000 (GMT) X-AuditID: cbfec7f5-e59c770000004fad-55-6723ece74606 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id F7.53.19920.6ECE3276; Thu, 31 Oct 2024 20:47:34 +0000 (GMT) Received: from AMDC4942.home (unknown [106.210.136.40]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20241031204733eusmtip1acf139a23240eadc0e8953ee0ee8e5be~DpJfDylTx1276712767eusmtip1q; Thu, 31 Oct 2024 20:47:33 +0000 (GMT) From: Michal Wilczynski To: drew@pdp7.com, guoren@kernel.org, wefu@redhat.com, jassisinghbrar@gmail.com, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, m.szyprowski@samsung.com, samuel.holland@sifive.com, emil.renner.berthing@canonical.com Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Michal Wilczynski Subject: [PATCH v5 1/3] mailbox: Introduce support for T-head TH1520 Mailbox driver Date: Thu, 31 Oct 2024 21:47:21 +0100 Message-Id: <20241031204723.1149912-2-m.wilczynski@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241031204723.1149912-1-m.wilczynski@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrMKsWRmVeSWpSXmKPExsWy7djPc7rP3yinG7z9oG2x9fcsdos1e88x Wcw/co7V4t6lLUwWlzpXMFq82NvIYnFtxVx2i5ez7rFZXN41h81i2+cWNou1R+6yW6z/Op/J 4uXlHmaLtln8Fv/37GC3WH3uCotFy/4pLA6CHrMaetk83rx8yeJxuOMLu8fOWXfZ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V2JpTgj0VCLuag4EQDnxE+RYwMAAA== X-CMS-MailID: 20241031204734eucas1p1ec2a8a101e805802a851b01d87709061 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20241031204734eucas1p1ec2a8a101e805802a851b01d87709061 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20241031204734eucas1p1ec2a8a101e805802a851b01d87709061 References: <20241031204723.1149912-1-m.wilczynski@samsung.com> This driver was tested using the drm/imagination GPU driver. It was able to successfully power on the GPU, by passing a command through mailbox from E910 core to E902 that's responsible for powering up the GPU. The GPU driver was able to read the BVNC version from control registers, which confirms it was successfully powered on. [ 33.957467] powervr ffef400000.gpu: [drm] loaded firmware powervr/rogue_36.52.104.182_v1.fw [ 33.966008] powervr ffef400000.gpu: [drm] FW version v1.0 (build 6621747 OS) [ 38.978542] powervr ffef400000.gpu: [drm] *ERROR* Firmware failed to boot Though the driver still fails to boot the firmware, the mailbox driver works when used with the not-yet-upstreamed firmware AON driver. There is ongoing work to get the BXM-4-64 supported with the drm/imagination driver [1], though it's not completed yet. This work is based on the driver from the vendor kernel [2]. Link: https://gitlab.freedesktop.org/imagination/linux-firmware/-/issues/2 = [1] Link: https://github.com/revyos/thead-kernel.git [2] Signed-off-by: Michal Wilczynski --- MAINTAINERS | 1 + drivers/mailbox/Kconfig | 10 + drivers/mailbox/Makefile | 2 + drivers/mailbox/mailbox-th1520.c | 592 +++++++++++++++++++++++++++++++ 4 files changed, 605 insertions(+) create mode 100644 drivers/mailbox/mailbox-th1520.c diff --git a/MAINTAINERS b/MAINTAINERS index a27407950242..df36684221ff 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19818,6 +19818,7 @@ T: git https://github.com/pdp7/linux.git F: Documentation/devicetree/bindings/clock/thead,th1520-clk-ap.yaml F: arch/riscv/boot/dts/thead/ F: drivers/clk/thead/clk-th1520-ap.c +F: drivers/mailbox/mailbox-th1520.c F: include/dt-bindings/clock/thead,th1520-clk-ap.h =20 RNBD BLOCK DRIVERS diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig index 6fb995778636..52f8162896f5 100644 --- a/drivers/mailbox/Kconfig +++ b/drivers/mailbox/Kconfig @@ -295,4 +295,14 @@ config QCOM_IPCC acts as an interrupt controller for receiving interrupts from clients. Say Y here if you want to build this driver. =20 +config THEAD_TH1520_MBOX + tristate "T-head TH1520 Mailbox" + depends on ARCH_THEAD || COMPILE_TEST + help + Mailbox driver implementation for the Thead TH-1520 platform. Enables + two cores within the SoC to communicate and coordinate by passing + messages. Could be used to communicate between E910 core, on which the + kernel is running, and E902 core used for power management among other + things. + endif diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index 3c3c27d54c13..5f4f5b0ce2cc 100644 --- a/drivers/mailbox/Makefile +++ b/drivers/mailbox/Makefile @@ -64,3 +64,5 @@ obj-$(CONFIG_SPRD_MBOX) +=3D sprd-mailbox.o obj-$(CONFIG_QCOM_CPUCP_MBOX) +=3D qcom-cpucp-mbox.o =20 obj-$(CONFIG_QCOM_IPCC) +=3D qcom-ipcc.o + +obj-$(CONFIG_THEAD_TH1520_MBOX) +=3D mailbox-th1520.o diff --git a/drivers/mailbox/mailbox-th1520.c b/drivers/mailbox/mailbox-th1= 520.c new file mode 100644 index 000000000000..d24861025a47 --- /dev/null +++ b/drivers/mailbox/mailbox-th1520.c @@ -0,0 +1,592 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2021 Alibaba Group Holding Limited. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Status Register */ +#define TH_1520_MBOX_STA 0x0 +#define TH_1520_MBOX_CLR 0x4 +#define TH_1520_MBOX_MASK 0xc + +/* Transmit/receive data register: + * INFO0 ~ INFO6 + */ +#define TH_1520_MBOX_INFO_NUM 8 +#define TH_1520_MBOX_DATA_INFO_NUM 7 +#define TH_1520_MBOX_INFO0 0x14 +/* Transmit ack register: INFO7 */ +#define TH_1520_MBOX_INFO7 0x30 + +/* Generate remote icu IRQ Register */ +#define TH_1520_MBOX_GEN 0x10 +#define TH_1520_MBOX_GEN_RX_DATA BIT(6) +#define TH_1520_MBOX_GEN_TX_ACK BIT(7) + +#define TH_1520_MBOX_CHAN_RES_SIZE 0x1000 +#define TH_1520_MBOX_CHANS 4 +#define TH_1520_MBOX_CHAN_NAME_SIZE 20 + +#define TH_1520_MBOX_ACK_MAGIC 0xdeadbeaf + +#ifdef CONFIG_PM_SLEEP +/* store MBOX context across system-wide suspend/resume transitions */ +struct th1520_mbox_context { + u32 intr_mask[TH_1520_MBOX_CHANS - 1]; +}; +#endif + +enum th1520_mbox_icu_cpu_id { + TH_1520_MBOX_ICU_KERNEL_CPU0, /* 910T */ + TH_1520_MBOX_ICU_CPU1, /* 902 */ + TH_1520_MBOX_ICU_CPU2, /* 906 */ + TH_1520_MBOX_ICU_CPU3, /* 910R */ +}; + +struct th1520_mbox_con_priv { + enum th1520_mbox_icu_cpu_id idx; + void __iomem *comm_local_base; + void __iomem *comm_remote_base; + char irq_desc[TH_1520_MBOX_CHAN_NAME_SIZE]; + struct mbox_chan *chan; +}; + +struct th1520_mbox_priv { + struct device *dev; + void __iomem *local_icu[TH_1520_MBOX_CHANS]; + void __iomem *remote_icu[TH_1520_MBOX_CHANS - 1]; + void __iomem *cur_cpu_ch_base; + spinlock_t mbox_lock; /* control register lock */ + + struct mbox_controller mbox; + struct mbox_chan mbox_chans[TH_1520_MBOX_CHANS]; + struct clk_bulk_data clocks[TH_1520_MBOX_CHANS]; + struct th1520_mbox_con_priv con_priv[TH_1520_MBOX_CHANS]; + int irq; +#ifdef CONFIG_PM_SLEEP + struct th1520_mbox_context *ctx; +#endif +}; + +static struct th1520_mbox_priv * +to_th1520_mbox_priv(struct mbox_controller *mbox) +{ + return container_of(mbox, struct th1520_mbox_priv, mbox); +} + +static void th1520_mbox_write(struct th1520_mbox_priv *priv, u32 val, u32 = offs) +{ + iowrite32(val, priv->cur_cpu_ch_base + offs); +} + +static u32 th1520_mbox_read(struct th1520_mbox_priv *priv, u32 offs) +{ + return ioread32(priv->cur_cpu_ch_base + offs); +} + +static u32 th1520_mbox_rmw(struct th1520_mbox_priv *priv, u32 off, u32 set, + u32 clr) +{ + unsigned long flags; + u32 val; + + spin_lock_irqsave(&priv->mbox_lock, flags); + val =3D th1520_mbox_read(priv, off); + val &=3D ~clr; + val |=3D set; + th1520_mbox_write(priv, val, off); + spin_unlock_irqrestore(&priv->mbox_lock, flags); + + return val; +} + +static void th1520_mbox_chan_write(struct th1520_mbox_con_priv *cp, u32 va= l, + u32 offs, bool is_remote) +{ + if (is_remote) + iowrite32(val, cp->comm_remote_base + offs); + else + iowrite32(val, cp->comm_local_base + offs); +} + +static u32 th1520_mbox_chan_read(struct th1520_mbox_con_priv *cp, u32 offs, + bool is_remote) +{ + if (is_remote) + return ioread32(cp->comm_remote_base + offs); + else + return ioread32(cp->comm_local_base + offs); +} + +static void th1520_mbox_chan_rmw(struct th1520_mbox_con_priv *cp, u32 off, + u32 set, u32 clr, bool is_remote) +{ + struct th1520_mbox_priv *priv =3D to_th1520_mbox_priv(cp->chan->mbox); + unsigned long flags; + u32 val; + + spin_lock_irqsave(&priv->mbox_lock, flags); + val =3D th1520_mbox_chan_read(cp, off, is_remote); + val &=3D ~clr; + val |=3D set; + th1520_mbox_chan_write(cp, val, off, is_remote); + spin_unlock_irqrestore(&priv->mbox_lock, flags); +} + +static void th1520_mbox_chan_rd_data(struct th1520_mbox_con_priv *cp, + void *data, bool is_remote) +{ + u32 off =3D TH_1520_MBOX_INFO0; + u32 *arg =3D data; + u32 i; + + /* read info0 ~ info6, totally 28 bytes + * requires data memory size is 28 bytes + */ + for (i =3D 0; i < TH_1520_MBOX_DATA_INFO_NUM; i++) { + *arg =3D th1520_mbox_chan_read(cp, off, is_remote); + off +=3D 4; + arg++; + } +} + +static void th1520_mbox_chan_wr_data(struct th1520_mbox_con_priv *cp, + void *data, bool is_remote) +{ + u32 off =3D TH_1520_MBOX_INFO0; + u32 *arg =3D data; + u32 i; + + /* write info0 ~ info6, totally 28 bytes + * requires data memory is 28 bytes valid data + */ + for (i =3D 0; i < TH_1520_MBOX_DATA_INFO_NUM; i++) { + th1520_mbox_chan_write(cp, *arg, off, is_remote); + off +=3D 4; + arg++; + } +} + +static void th1520_mbox_chan_wr_ack(struct th1520_mbox_con_priv *cp, void = *data, + bool is_remote) +{ + u32 off =3D TH_1520_MBOX_INFO7; + u32 *arg =3D data; + + th1520_mbox_chan_write(cp, *arg, off, is_remote); +} + +static int th1520_mbox_chan_id_to_mapbit(struct th1520_mbox_con_priv *cp) +{ + int mapbit =3D 0; + int i; + + for (i =3D 0; i < TH_1520_MBOX_CHANS; i++) { + if (i =3D=3D cp->idx) + return mapbit; + + if (i !=3D TH_1520_MBOX_ICU_KERNEL_CPU0) + mapbit++; + } + + if (i =3D=3D TH_1520_MBOX_CHANS) + dev_err(cp->chan->mbox->dev, "convert to mapbit failed\n"); + + return 0; +} + +static irqreturn_t th1520_mbox_isr(int irq, void *p) +{ + struct mbox_chan *chan =3D p; + struct th1520_mbox_priv *priv =3D to_th1520_mbox_priv(chan->mbox); + struct th1520_mbox_con_priv *cp =3D chan->con_priv; + int mapbit =3D th1520_mbox_chan_id_to_mapbit(cp); + u32 sta, dat[TH_1520_MBOX_DATA_INFO_NUM]; + u32 ack_magic =3D TH_1520_MBOX_ACK_MAGIC; + u32 info0_data, info7_data; + + sta =3D th1520_mbox_read(priv, TH_1520_MBOX_STA); + if (!(sta & BIT(mapbit))) + return IRQ_NONE; + + /* clear chan irq bit in STA register */ + th1520_mbox_rmw(priv, TH_1520_MBOX_CLR, BIT(mapbit), 0); + + /* info0 is the protocol word, should not be zero! */ + info0_data =3D th1520_mbox_chan_read(cp, TH_1520_MBOX_INFO0, false); + if (info0_data) { + /* read info0~info6 data */ + th1520_mbox_chan_rd_data(cp, dat, false); + + /* clear local info0 */ + th1520_mbox_chan_write(cp, 0x0, TH_1520_MBOX_INFO0, false); + + /* notify remote cpu */ + th1520_mbox_chan_wr_ack(cp, &ack_magic, true); + /* CPU1 902/906 use polling mode to monitor info7 */ + if (cp->idx !=3D TH_1520_MBOX_ICU_CPU1 && + cp->idx !=3D TH_1520_MBOX_ICU_CPU2) + th1520_mbox_chan_rmw(cp, TH_1520_MBOX_GEN, + TH_1520_MBOX_GEN_TX_ACK, 0, true); + + /* transfer the data to client */ + mbox_chan_received_data(chan, (void *)dat); + } + + /* info7 magic value mean the real ack signal, not generate bit7 */ + info7_data =3D th1520_mbox_chan_read(cp, TH_1520_MBOX_INFO7, false); + if (info7_data =3D=3D TH_1520_MBOX_ACK_MAGIC) { + /* clear local info7 */ + th1520_mbox_chan_write(cp, 0x0, TH_1520_MBOX_INFO7, false); + + /* notify framework the last TX has completed */ + mbox_chan_txdone(chan, 0); + } + + if (!info0_data && !info7_data) + return IRQ_NONE; + + return IRQ_HANDLED; +} + +static int th1520_mbox_send_data(struct mbox_chan *chan, void *data) +{ + struct th1520_mbox_con_priv *cp =3D chan->con_priv; + + th1520_mbox_chan_wr_data(cp, data, true); + th1520_mbox_chan_rmw(cp, TH_1520_MBOX_GEN, TH_1520_MBOX_GEN_RX_DATA, 0, + true); + return 0; +} + +static int th1520_mbox_startup(struct mbox_chan *chan) +{ + struct th1520_mbox_priv *priv =3D to_th1520_mbox_priv(chan->mbox); + struct th1520_mbox_con_priv *cp =3D chan->con_priv; + u32 data[8] =3D {}; + int mask_bit; + int ret; + + /* clear local and remote generate and info0~info7 */ + th1520_mbox_chan_rmw(cp, TH_1520_MBOX_GEN, 0x0, 0xff, true); + th1520_mbox_chan_rmw(cp, TH_1520_MBOX_GEN, 0x0, 0xff, false); + th1520_mbox_chan_wr_ack(cp, &data[7], true); + th1520_mbox_chan_wr_ack(cp, &data[7], false); + th1520_mbox_chan_wr_data(cp, &data[0], true); + th1520_mbox_chan_wr_data(cp, &data[0], false); + + /* enable the chan mask */ + mask_bit =3D th1520_mbox_chan_id_to_mapbit(cp); + th1520_mbox_rmw(priv, TH_1520_MBOX_MASK, BIT(mask_bit), 0); + + /* + * Mixing devm_ managed resources with manual IRQ handling is generally + * discouraged due to potential complexities with resource management, + * especially when dealing with shared interrupts. However, in this case, + * the approach is safe and effective because: + * + * 1. Each mailbox channel requests its IRQ within the .startup() callback + * and frees it within the .shutdown() callback. + * 2. During device unbinding, the devm_ managed mailbox controller first + * iterates through all channels, ensuring that their IRQs are freed b= efore + * any other devm_ resources are released. + * + * This ordering guarantees that no interrupts can be triggered from the = device + * while it is being unbound, preventing race conditions and ensuring sys= tem + * stability. + */ + ret =3D request_irq(priv->irq, th1520_mbox_isr, + IRQF_SHARED | IRQF_NO_SUSPEND, cp->irq_desc, chan); + if (ret) { + dev_err(priv->dev, "Unable to acquire IRQ %d\n", priv->irq); + return ret; + } + + return 0; +} + +static void th1520_mbox_shutdown(struct mbox_chan *chan) +{ + struct th1520_mbox_priv *priv =3D to_th1520_mbox_priv(chan->mbox); + struct th1520_mbox_con_priv *cp =3D chan->con_priv; + int mask_bit; + + free_irq(priv->irq, chan); + + /* clear the chan mask */ + mask_bit =3D th1520_mbox_chan_id_to_mapbit(cp); + th1520_mbox_rmw(priv, TH_1520_MBOX_MASK, 0, BIT(mask_bit)); +} + +static const struct mbox_chan_ops th1520_mbox_ops =3D { + .send_data =3D th1520_mbox_send_data, + .startup =3D th1520_mbox_startup, + .shutdown =3D th1520_mbox_shutdown, +}; + +static int th1520_mbox_init_generic(struct th1520_mbox_priv *priv) +{ +#ifdef CONFIG_PM_SLEEP + priv->ctx =3D devm_kzalloc(priv->dev, sizeof(*priv->ctx), GFP_KERNEL); + if (!priv->ctx) + return -ENOMEM; +#endif + /* Set default configuration */ + th1520_mbox_write(priv, 0xff, TH_1520_MBOX_CLR); + th1520_mbox_write(priv, 0x0, TH_1520_MBOX_MASK); + return 0; +} + +static struct mbox_chan *th1520_mbox_xlate(struct mbox_controller *mbox, + const struct of_phandle_args *sp) +{ + u32 chan; + + if (sp->args_count !=3D 1) { + dev_err(mbox->dev, "Invalid argument count %d\n", + sp->args_count); + return ERR_PTR(-EINVAL); + } + + chan =3D sp->args[0]; /* comm remote channel */ + + if (chan >=3D mbox->num_chans) { + dev_err(mbox->dev, "Not supported channel number: %d\n", chan); + return ERR_PTR(-EINVAL); + } + + if (chan =3D=3D TH_1520_MBOX_ICU_KERNEL_CPU0) { + dev_err(mbox->dev, "Cannot communicate with yourself\n"); + return ERR_PTR(-EINVAL); + } + + return &mbox->chans[chan]; +} + +static void __iomem *th1520_map_mmio(struct platform_device *pdev, + char *res_name, size_t offset) +{ + void __iomem *mapped; + struct resource *res; + + res =3D platform_get_resource_byname(pdev, IORESOURCE_MEM, res_name); + + if (!res) { + dev_err(&pdev->dev, "Failed to get resource: %s\n", res_name); + return ERR_PTR(-EINVAL); + } + + mapped =3D devm_ioremap(&pdev->dev, res->start + offset, + resource_size(res) - offset); + if (IS_ERR(mapped)) + dev_err(&pdev->dev, "Failed to map resource: %s\n", res_name); + + return mapped; +} + +static int th1520_mbox_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct th1520_mbox_priv *priv; + unsigned int remote_idx =3D 0; + unsigned int i; + int ret; + + priv =3D devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->dev =3D dev; + + priv->clocks[0].id =3D "clk-local"; + priv->clocks[1].id =3D "clk-remote-icu0"; + priv->clocks[2].id =3D "clk-remote-icu1"; + priv->clocks[3].id =3D "clk-remote-icu2"; + + ret =3D devm_clk_bulk_get(dev, ARRAY_SIZE(priv->clocks), + priv->clocks); + if (ret) { + dev_err(dev, "Failed to get clocks\n"); + return ret; + } + + ret =3D clk_bulk_prepare_enable(ARRAY_SIZE(priv->clocks), priv->clocks); + if (ret) { + dev_err(dev, "Failed to enable clocks\n"); + return ret; + } + + /* + * The address mappings in the device tree align precisely with those + * outlined in the manual. However, register offsets within these + * mapped regions are irregular, particularly for remote-icu0. + * Consequently, th1520_map_mmio() requires an additional parameter to + * handle this quirk. + */ + priv->local_icu[TH_1520_MBOX_ICU_KERNEL_CPU0] =3D + th1520_map_mmio(pdev, "local", 0x0); + if (IS_ERR(priv->local_icu[TH_1520_MBOX_ICU_KERNEL_CPU0])) + return PTR_ERR(priv->local_icu[TH_1520_MBOX_ICU_KERNEL_CPU0]); + + priv->remote_icu[0] =3D th1520_map_mmio(pdev, "remote-icu0", 0x4000); + if (IS_ERR(priv->remote_icu[0])) + return PTR_ERR(priv->remote_icu[0]); + + priv->remote_icu[1] =3D th1520_map_mmio(pdev, "remote-icu1", 0x0); + if (IS_ERR(priv->remote_icu[1])) + return PTR_ERR(priv->remote_icu[1]); + + priv->remote_icu[2] =3D th1520_map_mmio(pdev, "remote-icu2", 0x0); + if (IS_ERR(priv->remote_icu[2])) + return PTR_ERR(priv->remote_icu[2]); + + priv->local_icu[TH_1520_MBOX_ICU_CPU1] =3D + priv->local_icu[TH_1520_MBOX_ICU_KERNEL_CPU0] + + TH_1520_MBOX_CHAN_RES_SIZE; + priv->local_icu[TH_1520_MBOX_ICU_CPU2] =3D + priv->local_icu[TH_1520_MBOX_ICU_CPU1] + + TH_1520_MBOX_CHAN_RES_SIZE; + priv->local_icu[TH_1520_MBOX_ICU_CPU3] =3D + priv->local_icu[TH_1520_MBOX_ICU_CPU2] + + TH_1520_MBOX_CHAN_RES_SIZE; + + priv->cur_cpu_ch_base =3D priv->local_icu[TH_1520_MBOX_ICU_KERNEL_CPU0]; + + priv->irq =3D platform_get_irq(pdev, 0); + if (priv->irq < 0) + return priv->irq; + + /* init the chans */ + for (i =3D 0; i < TH_1520_MBOX_CHANS; i++) { + struct th1520_mbox_con_priv *cp =3D &priv->con_priv[i]; + + cp->idx =3D i; + cp->chan =3D &priv->mbox_chans[i]; + priv->mbox_chans[i].con_priv =3D cp; + snprintf(cp->irq_desc, sizeof(cp->irq_desc), + "th1520_mbox_chan[%i]", cp->idx); + + cp->comm_local_base =3D priv->local_icu[i]; + if (i !=3D TH_1520_MBOX_ICU_KERNEL_CPU0) { + cp->comm_remote_base =3D priv->remote_icu[remote_idx]; + remote_idx++; + } + } + + spin_lock_init(&priv->mbox_lock); + + priv->mbox.dev =3D dev; + priv->mbox.ops =3D &th1520_mbox_ops; + priv->mbox.chans =3D priv->mbox_chans; + priv->mbox.num_chans =3D TH_1520_MBOX_CHANS; + priv->mbox.of_xlate =3D th1520_mbox_xlate; + priv->mbox.txdone_irq =3D true; + + platform_set_drvdata(pdev, priv); + + ret =3D th1520_mbox_init_generic(priv); + if (ret) { + dev_err(dev, "Failed to init mailbox context\n"); + return ret; + } + + return devm_mbox_controller_register(dev, &priv->mbox); +} + +static void th1520_mbox_remove(struct platform_device *pdev) +{ + struct th1520_mbox_priv *priv =3D platform_get_drvdata(pdev); + + clk_bulk_disable_unprepare(ARRAY_SIZE(priv->clocks), priv->clocks); +} + +static const struct of_device_id th1520_mbox_dt_ids[] =3D { + { .compatible =3D "thead,th1520-mbox" }, + {} +}; +MODULE_DEVICE_TABLE(of, th1520_mbox_dt_ids); + +#ifdef CONFIG_PM_SLEEP +static int __maybe_unused th1520_mbox_suspend_noirq(struct device *dev) +{ + struct th1520_mbox_priv *priv =3D dev_get_drvdata(dev); + struct th1520_mbox_context *ctx =3D priv->ctx; + u32 i; + /* + * ONLY interrupt mask bit should be stored and restores. + * INFO data all assumed to be lost. + */ + for (i =3D 0; i < TH_1520_MBOX_CHANS; i++) { + ctx->intr_mask[i] =3D + ioread32(priv->local_icu[i] + TH_1520_MBOX_MASK); + } + return 0; +} + +static int __maybe_unused th1520_mbox_resume_noirq(struct device *dev) +{ + struct th1520_mbox_priv *priv =3D dev_get_drvdata(dev); + struct th1520_mbox_context *ctx =3D priv->ctx; + u32 i; + + for (i =3D 0; i < TH_1520_MBOX_CHANS; i++) { + iowrite32(ctx->intr_mask[i], + priv->local_icu[i] + TH_1520_MBOX_MASK); + } + + return 0; +} +#endif + +static int __maybe_unused th1520_mbox_runtime_suspend(struct device *dev) +{ + struct th1520_mbox_priv *priv =3D dev_get_drvdata(dev); + + clk_bulk_disable_unprepare(ARRAY_SIZE(priv->clocks), priv->clocks); + + return 0; +} + +static int __maybe_unused th1520_mbox_runtime_resume(struct device *dev) +{ + struct th1520_mbox_priv *priv =3D dev_get_drvdata(dev); + int ret; + + ret =3D clk_bulk_prepare_enable(ARRAY_SIZE(priv->clocks), priv->clocks); + if (ret) + dev_err(dev, "Failed to enable clocks in runtime resume\n"); + + return ret; +} + +static const struct dev_pm_ops th1520_mbox_pm_ops =3D { +#ifdef CONFIG_PM_SLEEP + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(th1520_mbox_suspend_noirq, + th1520_mbox_resume_noirq) +#endif + SET_RUNTIME_PM_OPS(th1520_mbox_runtime_suspend, + th1520_mbox_runtime_resume, NULL) +}; + +static struct platform_driver th1520_mbox_driver =3D { + .probe =3D th1520_mbox_probe, + .remove =3D th1520_mbox_remove, + .driver =3D { + .name =3D "th1520-mbox", + .of_match_table =3D th1520_mbox_dt_ids, + .pm =3D &th1520_mbox_pm_ops, + }, +}; +module_platform_driver(th1520_mbox_driver); + +MODULE_DESCRIPTION("Thead TH-1520 mailbox IPC driver"); +MODULE_LICENSE("GPL"); --=20 2.34.1 From nobody Sun Nov 24 23:07:00 2024 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A2BD14A4F3 for ; Thu, 31 Oct 2024 20:47:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730407671; cv=none; b=lPOylmJLMeruGzQhgaPEhpUXZTezxwtuSuwYi04Qy6uihfy2J8W9MOPw4nCpE8KNkOI6xthrLKxpmMHbEqUaboVhYdtmHVj8qGsA0sYvZcaa2ZkO1dPV5a/7pcr7ito0IKaGaN/PpxRyruGxiew1nP+vm8B4r8+T0lwheCLgoKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730407671; c=relaxed/simple; bh=LA2kxQTEYdVZLGp1k9PWf+jvRLv3J+pclp8bu/Z+MZM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=YS0XbHnmw0IpNuuKdgQoueRkZ5dGLXhfxTMPQviFVgPX1/3Rk3iEIjSDx55xXn8YIJKUuX6yCie6xj8IwYvP4TMdXZyUYYFACjkvFsTBZlrcB2Sc00rzfz42m3KFRxkSKg/m/LrQKx9qPPoPO+cJnksi6kccNG43L1fu6IEW8Gk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=CYNKNlmx; arc=none smtp.client-ip=210.118.77.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="CYNKNlmx" Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20241031204737euoutp01ba3d20983c4fe8d25ac87826a8f4f2b9~DpJiqFInJ1761517615euoutp01t for ; Thu, 31 Oct 2024 20:47:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20241031204737euoutp01ba3d20983c4fe8d25ac87826a8f4f2b9~DpJiqFInJ1761517615euoutp01t DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1730407657; bh=bcy6XB4drLGQ91Hj3yeaQos3MgyWXtw63xNApEC7seA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CYNKNlmxE94UjOQwVnErajIwuGkd1CNxGtmnopqnhNzRD1Ul0ILVEukLVNuATfGE5 FIzNb6o9OvGiTT80v7eM0p0zCv9IFnp8kZ8LoRDtZHsmtR5YNcwAXjvWk711uS7M5s bX+hZikPErB/FML0vQig+SLQDbCJCL8lCeETU1g0= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20241031204736eucas1p1279b8dd0ddac1a2501d54066bd76d5a4~DpJhZHV-P2981929819eucas1p1N; Thu, 31 Oct 2024 20:47:36 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id DD.C6.20409.7ECE3276; Thu, 31 Oct 2024 20:47:35 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20241031204735eucas1p2cfe90f4279c3db29b0af1e61ac29904d~DpJgxtgmw3276032760eucas1p2X; Thu, 31 Oct 2024 20:47:35 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20241031204735eusmtrp17f0701f25650e2541679f605b0341db3~DpJgxEqJE2946129461eusmtrp1D; Thu, 31 Oct 2024 20:47:35 +0000 (GMT) X-AuditID: cbfec7f4-c39fa70000004fb9-1b-6723ece7884b Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 2E.20.19654.7ECE3276; Thu, 31 Oct 2024 20:47:35 +0000 (GMT) Received: from AMDC4942.home (unknown [106.210.136.40]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20241031204734eusmtip1658680ee384ae2da9e4c285b487a4326~DpJfy94yI1402214022eusmtip1g; Thu, 31 Oct 2024 20:47:34 +0000 (GMT) From: Michal Wilczynski To: drew@pdp7.com, guoren@kernel.org, wefu@redhat.com, jassisinghbrar@gmail.com, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, m.szyprowski@samsung.com, samuel.holland@sifive.com, emil.renner.berthing@canonical.com Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Michal Wilczynski , Krzysztof Kozlowski Subject: [PATCH v5 2/3] dt-bindings: mailbox: Add thead,th1520-mailbox bindings Date: Thu, 31 Oct 2024 21:47:22 +0100 Message-Id: <20241031204723.1149912-3-m.wilczynski@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241031204723.1149912-1-m.wilczynski@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrJKsWRmVeSWpSXmKPExsWy7djPc7rP3yinGxy5bGWx9fcsdos1e88x Wcw/co7V4t6lLUwWlzpXMFq82NvIYnFtxVx2i5ez7rFZ7H29ld3i8q45bBbbPrewWaw9cpfd Yv3X+UwWLy/3MFu0zeK3+L9nB7vF6nNXWCxa9k9hcRDymNXQy+bx5uVLFo/DHV/YPXbOusvu sWlVJ5vHnWt72Dw2L6n3aFl7jMnj/b6rbB59W1Yxelxqvs7u8XmTXABPFJdNSmpOZllqkb5d AlfGxw8T2QtWy1Vsv3qIuYFxm3gXIyeHhICJxJZvE9i7GLk4hARWMEpsfHyFHSQhJPCFUWLp TmWIxGdGic/3HzDDdLy4/oENIrGcUWL63Cao9jeMEg8bzjKBVLEJGEk8WD6fFSQhIrCeSeLZ 7mVgVcwCRxklNkx7CrZEWCBQ4sH6LWAdLAKqElO/vgKL8wrYS7ycdIIdYp+8xP6DZ8F2cwo4 SMze1QpVIyhxcuYTFhCbGaimeetsqPt2c0p8fAL1nYtEw/V5jBC2sMSr41ugZspInJ7cwwJh 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GQkbjW/ZIFwhaW+HOtC6roFaPE83v3GEES bAJGEg+Wz2cFsUUE9jNJvD5bBGIzC5xklFg8Wx/EFhbwl9g6YSZYDYuAqsTUr6/YQWxeAXuJ l5NOsEMskJfYf/As2GJOAQeJ2btaweJCQDVHW/dA1QtKnJz5hAVivrxE89bZzBMYBWYhSc1C klrAyLSKUSS1tDg3PbfYSK84Mbe4NC9dLzk/dxMjMIq3Hfu5ZQfjylcf9Q4xMnEwHmKU4GBW EuH9UKCcLsSbklhZlVqUH19UmpNafIjRFOjuicxSosn5wDSSVxJvaGZgamhiZmlgamlmrCTO y3blfJqQQHpiSWp2ampBahFMHxMHp1QD00btVe2JXTMcnmyKcJm821462UHzW3fwz81fbCxj nzlO43wqe8ffrPqvyLJWBqk5YacX76gXu3R9/eyctVNUfsjtYXv7aE9P457kYouvmoV/uPy2 7b/f+EuQ5dQhV4eS3xrre29dOPeRu+fXlbwjCnsnML7YkXZo0aTn+xVfBJX0hbC6BgUu1H1U Eckw+17rQ0kZY8nLDlPPu25cWyv7PecsW+uNeWoxl+ayXv1vsfnp5ySVy/XxSvy7vypUKUt/ l1ie9rHMcW7bshuRS6efdr2gY5e/uWfvFjXRU193+gTXuHXtWr1jzZTbz5/mz9ErW2sd9cqq XyPplEvkot8xv02vP020a5wSc2nq1xbONl4lluKMREMt5qLiRAAGgSpUawMAAA== X-CMS-MailID: 20241031204735eucas1p2cfe90f4279c3db29b0af1e61ac29904d X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20241031204735eucas1p2cfe90f4279c3db29b0af1e61ac29904d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20241031204735eucas1p2cfe90f4279c3db29b0af1e61ac29904d References: <20241031204723.1149912-1-m.wilczynski@samsung.com> Add bindings for the mailbox controller. This work is based on the vendor kernel. [1] Link: https://github.com/revyos/thead-kernel.git [1] Signed-off-by: Michal Wilczynski Reviewed-by: Krzysztof Kozlowski --- .../bindings/mailbox/thead,th1520-mbox.yaml | 89 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 90 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/thead,th1520-= mbox.yaml diff --git a/Documentation/devicetree/bindings/mailbox/thead,th1520-mbox.ya= ml b/Documentation/devicetree/bindings/mailbox/thead,th1520-mbox.yaml new file mode 100644 index 000000000000..0971fb97896e --- /dev/null +++ b/Documentation/devicetree/bindings/mailbox/thead,th1520-mbox.yaml @@ -0,0 +1,89 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mailbox/thead,th1520-mbox.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: T-head TH1520 Mailbox Controller + +description: + The T-head mailbox controller enables communication and coordination bet= ween + cores within the SoC by passing messages (e.g., data, status, and contro= l) + through mailbox channels. It also allows one core to signal another proc= essor + using interrupts via the Interrupt Controller Unit (ICU). + +maintainers: + - Michal Wilczynski + +properties: + compatible: + const: thead,th1520-mbox + + clocks: + items: + - description: Clock for the local mailbox + - description: Clock for remote ICU 0 + - description: Clock for remote ICU 1 + - description: Clock for remote ICU 2 + + clock-names: + items: + - const: clk-local + - const: clk-remote-icu0 + - const: clk-remote-icu1 + - const: clk-remote-icu2 + + reg: + items: + - description: Mailbox local base address + - description: Remote ICU 0 base address + - description: Remote ICU 1 base address + - description: Remote ICU 2 base address + + reg-names: + items: + - const: local + - const: remote-icu0 + - const: remote-icu1 + - const: remote-icu2 + + interrupts: + maxItems: 1 + + '#mbox-cells': + const: 1 + description: + The one and only cell describes destination CPU ID. + +required: + - compatible + - clocks + - clock-names + - reg + - reg-names + - interrupts + - '#mbox-cells' + +additionalProperties: false + +examples: + - | + #include + soc { + #address-cells =3D <2>; + #size-cells =3D <2>; + mailbox@ffffc38000 { + compatible =3D "thead,th1520-mbox"; + reg =3D <0xff 0xffc38000 0x0 0x4000>, + <0xff 0xffc44000 0x0 0x1000>, + <0xff 0xffc4c000 0x0 0x1000>, + <0xff 0xffc54000 0x0 0x1000>; + reg-names =3D "local", "remote-icu0", "remote-icu1", "remote-icu2"; + clocks =3D <&clk CLK_MBOX0>, <&clk CLK_MBOX1>, <&clk CLK_MBOX2>, + <&clk CLK_MBOX3>; + clock-names =3D "clk-local", "clk-remote-icu0", "clk-remote-icu1", + "clk-remote-icu2"; + interrupts =3D <28>; + #mbox-cells =3D <1>; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index df36684221ff..506cdea74694 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19816,6 +19816,7 @@ L: linux-riscv@lists.infradead.org S: Maintained T: git https://github.com/pdp7/linux.git F: Documentation/devicetree/bindings/clock/thead,th1520-clk-ap.yaml +F: Documentation/devicetree/bindings/mailbox/thead,th1520-mbox.yaml F: arch/riscv/boot/dts/thead/ F: drivers/clk/thead/clk-th1520-ap.c F: drivers/mailbox/mailbox-th1520.c --=20 2.34.1 From nobody Sun Nov 24 23:07:00 2024 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 347921CDFD6 for ; Thu, 31 Oct 2024 20:47:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.118.77.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730407675; cv=none; b=jxMi6QCiYc9wN4roYSeLl0u+r1wxEwezGM1pUendtb0bZFaDZNbYpz/BVXi6VDz5W/TmyOZX9o70QXjzgNqQKqBdM3AkJOP1POmFLpLyT6ZOkS721hd4citKzKRDYabHEPXNyLimeG8uVwN6rQXOva3j8P670JjuOdyHkSJpSrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730407675; c=relaxed/simple; bh=rFgxEKAY53F1vr1UjWz5Op/T157tTAWmRMUpgFYnWY0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=ewL3r5AeLuT6fgSL7NkqOarlX3Xo4zA0A3B0tTxFjUlWtrv+S8edsvkPIFBqcKUQcgINcW1UxTQRzpusyHEUZ/QhfNpiyxqbdEQWqfGo8wnNFIFJlOrihi9Npk2A3Q1l63++BjJ2gXqQLRf3XbPw11ruzz+MKlPLA9WH5A+wVTI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=pPNLMeeI; arc=none smtp.client-ip=210.118.77.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="pPNLMeeI" Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20241031204738euoutp01137c53752de240423dff379de05983b9~DpJj6iYa_1761317613euoutp01r for ; Thu, 31 Oct 2024 20:47:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20241031204738euoutp01137c53752de240423dff379de05983b9~DpJj6iYa_1761317613euoutp01r DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1730407658; bh=vxNiS8XZmEMSZYQqnfyixq5+aqnBLp9jGcPWzOWdRC0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pPNLMeeIVisSQc/wiEnyU5IsPQoSJdo4/2MqulL6DREOjMBM64OC7JXt1cf2U5Oat x23tnPw9KWUcOSyVw7WiIlv/meGN0jtTXhCBYeCmvSwMQ+mEB/q36Ub6vJAD+nCB58 cifC5eBezs+GSpGUJH31I+8SZq/qgSB+x52hNJ9Q= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20241031204737eucas1p15251ab7dfccfaa4906d9ac64859ef16c~DpJigZ9Mx2981929819eucas1p1P; Thu, 31 Oct 2024 20:47:37 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 0F.C6.20409.9ECE3276; Thu, 31 Oct 2024 20:47:37 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20241031204736eucas1p119124263356d8e5924b03f07a5638b42~DpJheAmKM2174621746eucas1p1U; Thu, 31 Oct 2024 20:47:36 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20241031204736eusmtrp2bd47663bb74eb2ad5ced19e5d4694f4a~DpJhdR-oD1392413924eusmtrp2v; Thu, 31 Oct 2024 20:47:36 +0000 (GMT) X-AuditID: cbfec7f4-c39fa70000004fb9-1d-6723ece943d1 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 19.53.19920.8ECE3276; Thu, 31 Oct 2024 20:47:36 +0000 (GMT) Received: from AMDC4942.home (unknown [106.210.136.40]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20241031204735eusmtip106d535dfcd5976eb7d664912f7f31151~DpJgqUCFN1679316793eusmtip1K; Thu, 31 Oct 2024 20:47:35 +0000 (GMT) From: Michal Wilczynski To: drew@pdp7.com, guoren@kernel.org, wefu@redhat.com, jassisinghbrar@gmail.com, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, m.szyprowski@samsung.com, samuel.holland@sifive.com, emil.renner.berthing@canonical.com Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Michal Wilczynski Subject: [PATCH v5 3/3] riscv: dts: thead: Add mailbox node Date: Thu, 31 Oct 2024 21:47:23 +0100 Message-Id: <20241031204723.1149912-4-m.wilczynski@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241031204723.1149912-1-m.wilczynski@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrPKsWRmVeSWpSXmKPExsWy7djP87ov3yinG/x9z26x9fcsdos1e88x Wcw/co7V4t6lLUwWlzpXMFq82NvIYnFtxVx2i5ez7rFZXN41h81i2+cWNou1R+6yW6z/Op/J 4uXlHmaLtln8Fv/37GC3WH3uCotFy/4pLA6CHrMaetk83rx8yeJxuOMLu8fOWXfZPTat6mTz 2Lyk3qNl7TEmj/f7rrJ59G1Zxehxqfk6u8fnTXIB3FFcNimpOZllqUX6dglcGS+/trAVHOGq OHnnLGMD436OLkZODgkBE4ntW1eydzFycQgJrGCUWP5wGSuE84VRYsLEmcwgVUICnxklZj2S hOn4++4fI0TRckaJZfefMkE4bxglTq66ywJSxSZgJPFg+XywUSIC65kknu1eBraEWaCXUWLq 3plMIFXCAtYSS+e8A7I5OFgEVCXe3kgCCfMK2Eus/PuNBWKdvMT+g2fBzuAUcJCYvauVHaJG UOLkzCdgNcxANc1bZzODzJcQWM8pcfDWHHaIZheJ9dfmMkHYwhKvjm+BistI/N85HyqeL/Fg 6ydmCLtGYmfPcSjbWuLOuV9sILcxC2hKrN+lDxF2lOhZeJ0VJCwhwCdx460gxAl8EpO2TWeG CPNKdLQJQVSrSUzt6YVbem7FNqilHhLzT9xjmsCoOAvJM7OQPDMLYe8CRuZVjOKppcW56anF Rnmp5XrFibnFpXnpesn5uZsYgWnw9L/jX3YwLn/1Ue8QIx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xiQ73ixNzi0rx0veT83E2MwIjdduzn5h2M81591DvEyMTBeIhRgoNZSYT3Q4Fy uhBvSmJlVWpRfnxRaU5q8SFGU6CzJzJLiSbnA1NGXkm8oZmBqaGJmaWBqaWZsZI4r9vl82lC AumJJanZqakFqUUwfUwcnFINTOX1f1rPtgldebKyJ2g+d9jfxqMZ1ietQucKXmVoYak+YLto enKSgl/ZtCMa2xfUMDIYqPa95f6fvdDavGyq4p33Hcp3P/a3d3x94iLBsG2Zs8bJ+FlhQYs3 qOXarHJ08TvNfrGEaZKqQ+9THcU8vo5+jxrXsviT3foe3HFGPw0aPX4dy5ZWUFieqfhJknd5 hWrHwjpmbmfbA8niTyXzVnxhtbxzX8f2vdizVTfEXbqcl/v75iYeyGl6/UJKdfPWbR8maRgv qci68nnV4te3GBqPc/LzcCXHSiw/J3hzmTjXf7uAnOzF0ipvPTP/ZonMNOn5nlja4+T7yLTt rrrO7jmeQslqm9vP9fbbmCqxFGckGmoxFxUnAgBI2BACYQMAAA== X-CMS-MailID: 20241031204736eucas1p119124263356d8e5924b03f07a5638b42 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20241031204736eucas1p119124263356d8e5924b03f07a5638b42 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20241031204736eucas1p119124263356d8e5924b03f07a5638b42 References: <20241031204723.1149912-1-m.wilczynski@samsung.com> Add mailbox device tree node. This work is based on the vendor kernel [1]. Link: https://github.com/revyos/thead-kernel.git [1] Signed-off-by: Michal Wilczynski --- arch/riscv/boot/dts/thead/th1520.dtsi | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/riscv/boot/dts/thead/th1520.dtsi b/arch/riscv/boot/dts/th= ead/th1520.dtsi index 6992060e6a54..89de5634d3d3 100644 --- a/arch/riscv/boot/dts/thead/th1520.dtsi +++ b/arch/riscv/boot/dts/thead/th1520.dtsi @@ -520,6 +520,22 @@ timer7: timer@ffffc3303c { status =3D "disabled"; }; =20 + mbox_910t: mailbox@ffffc38000 { + compatible =3D "thead,th1520-mbox"; + reg =3D <0xff 0xffc38000 0x0 0x6000>, + <0xff 0xffc40000 0x0 0x6000>, + <0xff 0xffc4c000 0x0 0x2000>, + <0xff 0xffc54000 0x0 0x2000>; + reg-names =3D "local", "remote-icu0", "remote-icu1", "remote-icu2"; + clocks =3D <&clk CLK_MBOX0>, <&clk CLK_MBOX1>, <&clk CLK_MBOX2>, + <&clk CLK_MBOX3>; + clock-names =3D "clk-local", "clk-remote-icu0", "clk-remote-icu1", + "clk-remote-icu2"; + interrupt-parent =3D <&plic>; + interrupts =3D <28 IRQ_TYPE_LEVEL_HIGH>; + #mbox-cells =3D <1>; + }; + ao_gpio0: gpio@fffff41000 { compatible =3D "snps,dw-apb-gpio"; reg =3D <0xff 0xfff41000 0x0 0x1000>; --=20 2.34.1