From: aisheng.dong@nxp.com (Dong Aisheng)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH V2 1/4] soc: imx: add mu library functions support
Date: Sun, 17 Jun 2018 20:49:46 +0800 [thread overview]
Message-ID: <1529239789-26849-2-git-send-email-aisheng.dong@nxp.com> (raw)
In-Reply-To: <1529239789-26849-1-git-send-email-aisheng.dong@nxp.com>
This is used for i.MX multi core communication.
e.g. A core to SCU firmware(M core) on MX8.
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <kernel@pengutronix.de>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
---
v1->v2:
* introduce struct mu_priv to keep the private iomem info
* add the corresponding mu_exit()
---
drivers/soc/imx/Kconfig | 3 +
drivers/soc/imx/Makefile | 1 +
drivers/soc/imx/imx_mu.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++
include/soc/imx/mu.h | 24 +++++++
4 files changed, 193 insertions(+)
create mode 100644 drivers/soc/imx/imx_mu.c
create mode 100644 include/soc/imx/mu.h
diff --git a/drivers/soc/imx/Kconfig b/drivers/soc/imx/Kconfig
index a5b86a2..4858cd7 100644
--- a/drivers/soc/imx/Kconfig
+++ b/drivers/soc/imx/Kconfig
@@ -7,4 +7,7 @@ config IMX7_PM_DOMAINS
select PM_GENERIC_DOMAINS
default y if SOC_IMX7D
+config HAVE_IMX_MU
+ bool
+
endmenu
diff --git a/drivers/soc/imx/Makefile b/drivers/soc/imx/Makefile
index aab41a5c..113dc7f 100644
--- a/drivers/soc/imx/Makefile
+++ b/drivers/soc/imx/Makefile
@@ -1,2 +1,3 @@
obj-$(CONFIG_HAVE_IMX_GPC) += gpc.o
obj-$(CONFIG_IMX7_PM_DOMAINS) += gpcv2.o
+obj-$(CONFIG_HAVE_IMX_MU) += imx_mu.o
diff --git a/drivers/soc/imx/imx_mu.c b/drivers/soc/imx/imx_mu.c
new file mode 100644
index 0000000..44294d1
--- /dev/null
+++ b/drivers/soc/imx/imx_mu.c
@@ -0,0 +1,165 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2016 Freescale Semiconductor, Inc.
+ * Copyright 2017~2018 NXP
+ * Dong Aisheng <aisheng.dong@nxp.com>
+ */
+
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/of_address.h>
+#include <linux/slab.h>
+
+#define MU_ATR0 0x0
+#define MU_ARR0 0x10
+#define MU_ASR 0x20
+#define MU_ACR 0x24
+
+#define MU_CR_GIEn_MASK (0xf << 28)
+#define MU_CR_RIEn_MASK (0xf << 24)
+#define MU_CR_TIEn_MASK (0xf << 20)
+#define MU_CR_GIRn_MASK (0xf << 16)
+#define MU_CR_NMI_MASK (1 << 3)
+#define MU_CR_Fn_MASK 0x7
+
+#define MU_SR_TE0_MASK BIT(23)
+#define MU_SR_RF0_MASK BIT(27)
+
+#define MU_CR_RIE0_MASK BIT(27)
+#define MU_CR_GIE0_MASK BIT(31)
+
+struct mu_priv {
+ struct device_node *np;
+ void __iomem *base;
+};
+
+/*
+ * This function sets the Flag n of the MU.
+ */
+int32_t mu_set_fn(struct mu_priv *priv, uint32_t fn)
+{
+ uint32_t reg;
+
+ reg = fn & (~MU_CR_Fn_MASK);
+ if (reg > 0)
+ return -EINVAL;
+
+ reg = readl_relaxed(priv->base + MU_ACR);
+ /* Clear ABFn. */
+ reg &= ~MU_CR_Fn_MASK;
+ reg |= fn;
+ writel_relaxed(reg, priv->base + MU_ACR);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(mu_set_fn);
+
+/*
+ * This function reads the status from status register.
+ */
+uint32_t mu_read_status(struct mu_priv *priv)
+{
+ return readl_relaxed(priv->base + MU_ASR);
+}
+EXPORT_SYMBOL_GPL(mu_read_status);
+
+/*
+ * This function enables specific RX full interrupt.
+ */
+void mu_enable_rx_full_int(struct mu_priv *priv, uint32_t index)
+{
+ uint32_t reg;
+
+ reg = readl_relaxed(priv->base + MU_ACR);
+ reg &= ~(MU_CR_GIRn_MASK | MU_CR_NMI_MASK);
+ reg |= MU_CR_RIE0_MASK >> index;
+ writel_relaxed(reg, priv->base + MU_ACR);
+}
+EXPORT_SYMBOL_GPL(mu_enable_rx_full_int);
+
+/*
+ * This function enables specific general purpose interrupt.
+ */
+void mu_enable_general_int(struct mu_priv *priv, uint32_t index)
+{
+ uint32_t reg;
+
+ reg = readl_relaxed(priv->base + MU_ACR);
+ reg &= ~(MU_CR_GIRn_MASK | MU_CR_NMI_MASK);
+ reg |= MU_CR_GIE0_MASK >> index;
+ writel_relaxed(reg, priv->base + MU_ACR);
+}
+EXPORT_SYMBOL_GPL(mu_enable_general_int);
+
+/*
+ * Wait and send message to the other core.
+ */
+void mu_send_msg(struct mu_priv *priv, uint32_t index, uint32_t msg)
+{
+ uint32_t mask = MU_SR_TE0_MASK >> index;
+
+ /* Wait TX register to be empty. */
+ while (!(readl_relaxed(priv->base + MU_ASR) & mask))
+ ;
+ writel_relaxed(msg, priv->base + MU_ATR0 + (index * 4));
+}
+EXPORT_SYMBOL_GPL(mu_send_msg);
+
+/*
+ * Wait to receive message from the other core.
+ */
+void mu_receive_msg(struct mu_priv *priv, uint32_t index, uint32_t *msg)
+{
+ uint32_t mask = MU_SR_RF0_MASK >> index;
+
+ /* Wait RX register to be full. */
+ while (!(readl_relaxed(priv->base + MU_ASR) & mask))
+ ;
+ *msg = readl_relaxed(priv->base + MU_ARR0 + (index * 4));
+}
+EXPORT_SYMBOL_GPL(mu_receive_msg);
+
+struct device_node *mu_node(struct mu_priv *priv)
+{
+ return priv ? priv->np : NULL;
+}
+EXPORT_SYMBOL_GPL(mu_node);
+
+struct mu_priv *mu_init(struct device_node *np)
+{
+ struct mu_priv *priv;
+ uint32_t reg;
+
+ if (WARN_ON(!np))
+ return NULL;
+
+ priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return ERR_PTR(-ENOMEM);
+
+ priv->np = np;
+ priv->base = of_iomap(np, 0);
+ if (!priv->base) {
+ kfree(priv);
+ return ERR_PTR(-ENOMEM);
+ }
+
+ reg = readl_relaxed(priv->base + MU_ACR);
+ /* Clear GIEn, RIEn, TIEn, GIRn and ABFn. */
+ reg &= ~(MU_CR_GIEn_MASK | MU_CR_RIEn_MASK | MU_CR_TIEn_MASK
+ | MU_CR_GIRn_MASK | MU_CR_NMI_MASK | MU_CR_Fn_MASK);
+ writel_relaxed(reg, priv->base + MU_ACR);
+
+ return priv;
+}
+EXPORT_SYMBOL_GPL(mu_init);
+
+void mu_exit(struct mu_priv *priv)
+{
+ if (WARN_ON(!priv))
+ return;
+
+ iounmap(priv->base);
+ kfree(priv);
+}
+EXPORT_SYMBOL_GPL(mu_exit);
diff --git a/include/soc/imx/mu.h b/include/soc/imx/mu.h
new file mode 100644
index 0000000..0802193
--- /dev/null
+++ b/include/soc/imx/mu.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2016 Freescale Semiconductor, Inc.
+ * Copyright 2017-2018 NXP
+ */
+
+#ifndef IMX_MU_H
+#define IMX_MU_H
+
+#define MU_TR_COUNT 4
+#define MU_RR_COUNT 4
+
+struct mu_priv;
+
+void mu_exit(struct mu_priv *priv);
+struct mu_priv *mu_init(struct device_node *np);
+struct device_node *mu_node(struct mu_priv *priv);
+void mu_send_msg(struct mu_priv *priv, uint32_t index, uint32_t msg);
+void mu_receive_msg(struct mu_priv *priv, uint32_t index, uint32_t *msg);
+void mu_enable_general_int(struct mu_priv *priv, uint32_t index);
+void mu_enable_rx_full_int(struct mu_priv *priv, uint32_t index);
+uint32_t mu_read_status(struct mu_priv *priv);
+int32_t mu_set_fn(struct mu_priv *priv, uint32_t Fn);
+#endif
--
2.7.4
next prev parent reply other threads:[~2018-06-17 12:49 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-17 12:49 [PATCH V2 0/4] soc: imx: add scu firmware api support Dong Aisheng
2018-06-17 12:49 ` Dong Aisheng [this message]
2018-06-17 12:49 ` [PATCH V2 2/4] dt-bindings: arm: fsl: add mu binding doc Dong Aisheng
2018-06-20 19:43 ` Rob Herring
2018-06-21 7:46 ` Sascha Hauer
2018-06-21 17:11 ` A.s. Dong
2018-06-21 18:08 ` Oleksij Rempel
2018-06-22 3:31 ` A.s. Dong
2018-06-22 4:59 ` Oleksij Rempel
2018-06-22 5:59 ` A.s. Dong
2018-06-22 6:48 ` Oleksij Rempel
2018-06-22 8:16 ` A.s. Dong
2018-06-22 5:49 ` Sascha Hauer
2018-06-22 6:04 ` A.s. Dong
2018-06-17 12:49 ` [PATCH V2 3/4] dt-bindings: arm: fsl: add scu " Dong Aisheng
2018-06-20 19:44 ` Rob Herring
2018-06-21 3:38 ` A.s. Dong
2018-06-21 7:37 ` Sascha Hauer
2018-06-21 12:05 ` A.s. Dong
[not found] ` <1529239789-26849-5-git-send-email-aisheng.dong@nxp.com>
2018-06-18 8:58 ` [PATCH V2 4/4] soc: imx: add SC firmware IPC and APIs Leonard Crestez
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=1529239789-26849-2-git-send-email-aisheng.dong@nxp.com \
--to=aisheng.dong@nxp.com \
--cc=linux-arm-kernel@lists.infradead.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