mailbox/arm_scpi: Add to support Phytium FT2000/4 CPUs, show temperature of cpu.
Commit Message
Add to support Phytium FT2000/4 CPUs, show temperature of cpu.
Signed-off-by: Wang Honghui <honghui.wang@ucas.com.cn>
---
drivers/firmware/arm_scpi.c | 1 +
drivers/mailbox/Kconfig | 6 +
drivers/mailbox/Makefile | 2 +
drivers/mailbox/phytium_mailbox.c | 193 ++++++++++++++++++++++++++++++
4 files changed, 202 insertions(+)
create mode 100644 drivers/mailbox/phytium_mailbox.c
Comments
On Thu, Dec 01, 2022 at 03:08:33PM +0800, Wang Honghui wrote:
> Add to support Phytium FT2000/4 CPUs, show temperature of cpu.
>
> Signed-off-by: Wang Honghui <honghui.wang@ucas.com.cn>
> ---
> drivers/firmware/arm_scpi.c | 1 +
> drivers/mailbox/Kconfig | 6 +
> drivers/mailbox/Makefile | 2 +
> drivers/mailbox/phytium_mailbox.c | 193 ++++++++++++++++++++++++++++++
> 4 files changed, 202 insertions(+)
> create mode 100644 drivers/mailbox/phytium_mailbox.c
>
> diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c
> index 435d0e2658a4..876eb2f9ff81 100644
> --- a/drivers/firmware/arm_scpi.c
> +++ b/drivers/firmware/arm_scpi.c
> @@ -904,6 +904,7 @@ static const struct of_device_id shmem_of_match[] __maybe_unused = {
> { .compatible = "amlogic,meson-axg-scp-shmem", },
> { .compatible = "arm,juno-scp-shmem", },
> { .compatible = "arm,scp-shmem", },
> + { .compatible = "phytium,ft2004-scpi-shmem", },
Where is the binding for this new compatible ?
And why do you need this ? Any particular reason why you can't use the
generic "arm,scp-shmem" ?
I don't see the need for this change. Please drop it.
--
Regards,
Sudeep
Hi Wang,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on fujitsu-integration/mailbox-for-next]
[also build test WARNING on linus/master v6.1 next-20221214]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Wang-Honghui/mailbox-arm_scpi-Add-to-support-Phytium-FT2000-4-CPUs-show-temperature-of-cpu/20221201-151019
base: https://git.linaro.org/landing-teams/working/fujitsu/integration.git mailbox-for-next
patch link: https://lore.kernel.org/r/414EB9088FC46457%2BY4hS8eOJa%2FXUQ8xR%40TP-P15V
patch subject: [PATCH]mailbox/arm_scpi: Add to support Phytium FT2000/4 CPUs, show temperature of cpu.
config: s390-randconfig-c005-20221213
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 6e4cea55f0d1104408b26ac574566a0e4de48036)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install s390 cross compiling tool for clang build
# apt-get install binutils-s390x-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/50aa4710f5b7844ea5fa922745d34475586380a1
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Wang-Honghui/mailbox-arm_scpi-Add-to-support-Phytium-FT2000-4-CPUs-show-temperature-of-cpu/20221201-151019
git checkout 50aa4710f5b7844ea5fa922745d34475586380a1
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=s390 SHELL=/bin/bash drivers/mailbox/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
All warnings (new ones prefixed by >>):
In file included from drivers/mailbox/phytium_mailbox.c:20:
In file included from include/linux/io.h:13:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __raw_readb(PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:37:59: note: expanded from macro '__le16_to_cpu'
#define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
^
include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16'
#define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
^
In file included from drivers/mailbox/phytium_mailbox.c:20:
In file included from include/linux/io.h:13:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:35:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32'
#define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
^
In file included from drivers/mailbox/phytium_mailbox.c:20:
In file included from include/linux/io.h:13:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
>> drivers/mailbox/phytium_mailbox.c:115:34: warning: unused variable 'phytium_mbox_of_match' [-Wunused-const-variable]
static const struct of_device_id phytium_mbox_of_match[] = {
^
13 warnings generated.
vim +/phytium_mbox_of_match +115 drivers/mailbox/phytium_mailbox.c
114
> 115 static const struct of_device_id phytium_mbox_of_match[] = {
116 { .compatible = "phytium,mbox", },
117 { },
118 };
119 MODULE_DEVICE_TABLE(of, phytium_mbox_of_match);
120
@@ -904,6 +904,7 @@ static const struct of_device_id shmem_of_match[] __maybe_unused = {
{ .compatible = "amlogic,meson-axg-scp-shmem", },
{ .compatible = "arm,juno-scp-shmem", },
{ .compatible = "arm,scp-shmem", },
+ { .compatible = "phytium,ft2004-scpi-shmem", },
{ }
};
@@ -41,6 +41,12 @@ config IMX_MBOX
help
Mailbox implementation for i.MX Messaging Unit (MU).
+config PHYTIUM_MBOX
+ tristate "Phytium SoC Mailbox Support"
+ depends on ARM_AMBA || COMPILE_TEST
+ help
+ This driver provides the support for the Phytium mailbox controller.
+
config PLATFORM_MHU
tristate "Platform MHU Mailbox"
depends on OF
@@ -11,6 +11,8 @@ obj-$(CONFIG_ARM_MHU_V2) += arm_mhuv2.o
obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o
+obj-$(CONFIG_PHYTIUM_MBOX) += phytium_mailbox.o
+
obj-$(CONFIG_ARMADA_37XX_RWTM_MBOX) += armada-37xx-rwtm-mailbox.o
obj-$(CONFIG_PLATFORM_MHU) += platform_mhu.o
new file mode 100644
@@ -0,0 +1,193 @@
+/*
+ * Phytium SoC mailbox driver
+ *
+ * Copyright (c) 2020 Phytium Corporation.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/acpi.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/mailbox_controller.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+
+#define INTR_STAT 0x0
+#define INTR_SET 0x8
+#define INTR_CLR 0x10
+
+#define TX_REG 0x100
+
+#define NR_CHANS 1
+
+struct phytium_mbox_link {
+ unsigned irq;
+ void __iomem *tx_reg;
+ void __iomem *rx_reg;
+};
+
+struct phytium_mbox {
+ void __iomem *base;
+ struct phytium_mbox_link mlink;
+ struct mbox_chan chan;
+ struct mbox_controller mbox;
+};
+
+static irqreturn_t phytium_mbox_rx_irq(int irq, void *ch)
+{
+ struct mbox_chan *chan = ch;
+ struct phytium_mbox_link *mlink = chan->con_priv;
+ u32 val;
+
+ val = readl_relaxed(mlink->rx_reg + INTR_STAT);
+ if (!val)
+ return IRQ_NONE;
+
+ mbox_chan_received_data(chan, (void *)&val);
+
+ writel_relaxed(val, mlink->rx_reg + INTR_CLR);
+
+ return IRQ_HANDLED;
+}
+
+static int phytium_mbox_send_data(struct mbox_chan *chan, void *data)
+{
+ struct phytium_mbox_link *mlink = chan->con_priv;
+ u32 *arg = data;
+
+ writel_relaxed(*arg, mlink->tx_reg + INTR_SET);
+
+ return 0;
+}
+
+static int phytium_mbox_startup(struct mbox_chan *chan)
+{
+ struct phytium_mbox_link *mlink = chan->con_priv;
+ u32 val;
+ int ret;
+
+ val = readl_relaxed(mlink->tx_reg + INTR_STAT);
+ writel_relaxed(val, mlink->tx_reg + INTR_CLR);
+
+ ret = request_irq(mlink->irq, phytium_mbox_rx_irq,
+ IRQF_SHARED, "phytium_mbox_link", chan);
+ if (ret) {
+ dev_err(chan->mbox->dev,
+ "Unable to acquire IRQ %d\n", mlink->irq);
+ }
+
+ return ret;
+}
+
+static void phytium_mbox_shutdown(struct mbox_chan *chan)
+{
+ struct phytium_mbox_link *mlink = chan->con_priv;
+
+ free_irq(mlink->irq, chan);
+}
+
+static bool phytium_mbox_last_tx_done(struct mbox_chan *chan)
+{
+ struct phytium_mbox_link *mlink = chan->con_priv;
+ u32 val = readl_relaxed(mlink->tx_reg + INTR_STAT);
+
+ return (val == (u32)(1U << 31));
+}
+
+static const struct mbox_chan_ops phytium_mbox_ops = {
+ .send_data = phytium_mbox_send_data,
+ .startup = phytium_mbox_startup,
+ .shutdown = phytium_mbox_shutdown,
+ .last_tx_done = phytium_mbox_last_tx_done,
+};
+
+static const struct of_device_id phytium_mbox_of_match[] = {
+ { .compatible = "phytium,mbox", },
+ { },
+};
+MODULE_DEVICE_TABLE(of, phytium_mbox_of_match);
+
+static int phytium_mbox_probe(struct platform_device *pdev)
+{
+ struct phytium_mbox *mbox;
+ struct resource *res;
+ int err, irq;
+
+ /* Allocate memory for device */
+ mbox = devm_kzalloc(&pdev->dev, sizeof(*mbox), GFP_KERNEL);
+ if (!mbox)
+ return -ENOMEM;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ mbox->base = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(mbox->base)) {
+ dev_err(&pdev->dev, "ioremap base failed\n");
+ return PTR_ERR(mbox->base);
+ }
+
+ irq = platform_get_irq(pdev, 0);
+ if (irq < 0) {
+ dev_err(&pdev->dev, "cannot obtain irq\n");
+ return irq;
+ }
+
+ mbox->chan.con_priv = &mbox->mlink;
+ mbox->mlink.irq = irq;
+ mbox->mlink.rx_reg = mbox->base;
+ mbox->mlink.tx_reg = mbox->mlink.rx_reg + TX_REG;
+
+ mbox->mbox.dev = &pdev->dev;
+ mbox->mbox.chans = &mbox->chan;
+ mbox->mbox.num_chans = NR_CHANS;
+ mbox->mbox.ops = &phytium_mbox_ops;
+ mbox->mbox.txdone_irq = false;
+ mbox->mbox.txdone_poll = true;
+ mbox->mbox.txpoll_period = 1;
+
+ platform_set_drvdata(pdev, mbox);
+
+ err = mbox_controller_register(&mbox->mbox);
+ if (err) {
+ dev_err(&pdev->dev, "Failed to register mailboxes %d\n", err);
+ goto fail;
+ }
+
+ dev_info(&pdev->dev, "Phytium SoC Mailbox registered\n");
+fail:
+ return err;
+}
+
+static int phytium_mbox_remove(struct platform_device *pdev)
+{
+ struct phytium_mbox *mbox = platform_get_drvdata(pdev);
+
+ mbox_controller_unregister(&mbox->mbox);
+
+ return 0;
+}
+
+static struct platform_driver phytium_mbox_driver = {
+ .probe = phytium_mbox_probe,
+ .remove = phytium_mbox_remove,
+ .driver = {
+ .name = "phytium-mbox",
+ .of_match_table = of_match_ptr(phytium_mbox_of_match),
+ },
+};
+
+module_platform_driver(phytium_mbox_driver);
+
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("Phytium SoC Mailbox Driver");
+MODULE_AUTHOR("Chen Baozi <chenbaozi@phytium.com.cn>");