From patchwork Thu Dec 1 07:08:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Honghui X-Patchwork-Id: 28214 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp121328wrr; Wed, 30 Nov 2022 23:23:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf4cVvtv6wk+o5JUUiep7ArXEcFgYp06SigFx4LrHLgtqcTqBZLrhpCUn0Zpqec2Hd+sbPSQ X-Received: by 2002:a17:903:31cd:b0:180:be71:6773 with SMTP id v13-20020a17090331cd00b00180be716773mr47034371ple.42.1669879416927; Wed, 30 Nov 2022 23:23:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669879416; cv=none; d=google.com; s=arc-20160816; b=bVN2tRmLa6cgm0CgZqxSwHgY1duyLEIf9R11UVFWzjxvqcSPvK8PWmxZWPouz3mYVE Lqp/HQiyNd7k2YxQNxTFuF2MpvyiKbOfo7YKsgWoZ8xFUv0cTN1ecgoprwaBMp2Tlx9P EB4Jd/zuBoRDmD2GI4eVRtZjlbkl6iqUqOvAcyQMOB9LoPFPGxK2vIdP8QTQYP4/wu5w w27z9QZQ8GGhRuFg8o2c8ChzZXSccI2F1GZteU0JtpT7zKipsO3/G646czOE0kxmOO2L GSCCvauC4lPRSlSjvzthG9xDDm2zkQDk8qfxdJQR/NVFDW0PeiqTdwmP/ZfTMtHfAli6 hnqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-disposition:mime-version :message-id:subject:to:from:date; bh=nXoiHvNN6xKKKgKNN1JflwzhNcbC2k6N0NU76ZiT62c=; b=NoPwGeBe2xOg4yspI/rHE1PHeyrcZKEx7fN7pmUAyOJjDtNfELUDC9P/zc0QiS7r/w 9tSB5akMubky33RdFJxpRIXCRRJSH0wVglNTVrzAxV3X2BVidSpJ2os+nypQZdZ366n2 JurDUXxEFUwnofKABqFEyu5hf6vzTziQnzQNfqV04nd27ykULyj/AzeKm0HCAL7W9+Jp IPSRVI5F2R9RnRgDCUgIjIsJDt1JOR8ZX6fYi8O8khAPfVMrI8ADxzYmtScoH404amQz 4LwV11a5+gQos62V+uXWQ55K7T98mE3O0nXubswv37gAwGyIJBOGjwqCPIoK1R/l/Pbl +4tQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nk22-20020a17090b195600b001fe1cc52234si3658006pjb.67.2022.11.30.23.23.22; Wed, 30 Nov 2022 23:23:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229885AbiLAHJ3 (ORCPT + 99 others); Thu, 1 Dec 2022 02:09:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229800AbiLAHJ1 (ORCPT ); Thu, 1 Dec 2022 02:09:27 -0500 Received: from smtpbguseast3.qq.com (smtpbguseast3.qq.com [54.243.244.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6B014A9EF for ; Wed, 30 Nov 2022 23:09:19 -0800 (PST) X-QQ-mid: bizesmtp68t1669878514t9aa36n3 Received: from localhost ( [202.85.220.39]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 01 Dec 2022 15:08:33 +0800 (CST) X-QQ-SSF: 0140000000000080B000000A0000000 X-QQ-FEAT: q2IHZsLIAbhw2780UmiDVApHXo60V9ixJTSse5NXtpdKda0CQmDGHIOB+jH5r AuqgSi251yrgakBL+tG9BzSTK3BKVwuZCAOchD6XrMEXGGXXq/Iihuosu4DRnvr/7GW+IY4 acYCV5umEV+YCn9zzV0rLmsPAhO2nZPGfftYr96Lblt9PAri2YKi4Csp752rOnDkC5ZwzgP 1F4WDmVFEpioVsequEB/4xrZxbT7soeurar0lSlMzITV38ikEclXcljTZ2bZozwCXxjh6wp ngA55X0eGz/T4MvS/UFU8D1mzXd6DkZea7uKFkCVCmjY/jwG4vrMLIkwMk1eRi9FN1w2Seh /vODM2tjgNijmHrKnpY5sWqdW/TVA== X-QQ-GoodBg: 2 Date: Thu, 1 Dec 2022 15:08:33 +0800 From: Wang Honghui To: Sudeep Holla , Cristian Marussi , Jassi Brar , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH]mailbox/arm_scpi: Add to support Phytium FT2000/4 CPUs, show temperature of cpu. Message-ID: <414EB9088FC46457+Y4hS8eOJa/XUQ8xR@TP-P15V> MIME-Version: 1.0 Content-Disposition: inline X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:ucas.com.cn:qybglogicsvr:qybglogicsvr6 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750995479826261465?= X-GMAIL-MSGID: =?utf-8?q?1750995479826261465?= Add to support Phytium FT2000/4 CPUs, show temperature of cpu. Signed-off-by: Wang Honghui --- 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", }, { } }; diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig index 05d6fae800e3..4d08e8ebc831 100644 --- a/drivers/mailbox/Kconfig +++ b/drivers/mailbox/Kconfig @@ -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 diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index fc9376117111..e46cb9b29369 100644 --- a/drivers/mailbox/Makefile +++ b/drivers/mailbox/Makefile @@ -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 diff --git a/drivers/mailbox/phytium_mailbox.c b/drivers/mailbox/phytium_mailbox.c new file mode 100644 index 000000000000..8211db1d2ca0 --- /dev/null +++ b/drivers/mailbox/phytium_mailbox.c @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include + +#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 ");