linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: aisheng.dong@nxp.com (Dong Aisheng)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/4] soc: imx: add mu library functions support
Date: Sat, 28 Apr 2018 02:46:13 +0800	[thread overview]
Message-ID: <1524854776-14863-2-git-send-email-aisheng.dong@nxp.com> (raw)
In-Reply-To: <1524854776-14863-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>
---
 drivers/soc/imx/Kconfig  |   3 ++
 drivers/soc/imx/Makefile |   1 +
 drivers/soc/imx/imx_mu.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++
 include/soc/imx/mu.h     |  21 ++++++++
 4 files changed, 150 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..e5f3f47
--- /dev/null
+++ b/drivers/soc/imx/imx_mu.c
@@ -0,0 +1,125 @@
+// 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>
+
+#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)
+
+/*
+ * This function sets the Flag n of the MU.
+ */
+int32_t mu_set_fn(void __iomem *base, uint32_t fn)
+{
+	uint32_t reg;
+
+	reg = fn & (~MU_CR_Fn_MASK);
+	if (reg > 0)
+		return -EINVAL;
+
+	reg = readl_relaxed(base + MU_ACR);
+	/*  Clear ABFn. */
+	reg &= ~MU_CR_Fn_MASK;
+	reg |= fn;
+	writel_relaxed(reg, base + MU_ACR);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(mu_set_fn);
+
+/*
+ * This function reads the status from status register.
+ */
+uint32_t mu_read_status(void __iomem *base)
+{
+	return readl_relaxed(base + MU_ASR);
+}
+EXPORT_SYMBOL_GPL(mu_read_status);
+
+/*
+ * This function enables specific RX full interrupt.
+ */
+void mu_enable_rx_full_int(void __iomem *base, uint32_t index)
+{
+	uint32_t reg;
+
+	reg = readl_relaxed(base + MU_ACR);
+	reg &= ~(MU_CR_GIRn_MASK | MU_CR_NMI_MASK);
+	reg |= MU_CR_RIE0_MASK >> index;
+	writel_relaxed(reg, base + MU_ACR);
+}
+EXPORT_SYMBOL_GPL(mu_enable_rx_full_int);
+
+/*
+ * This function enables specific general purpose interrupt.
+ */
+void mu_enable_general_int(void __iomem *base, uint32_t index)
+{
+	uint32_t reg;
+
+	reg = readl_relaxed(base + MU_ACR);
+	reg &= ~(MU_CR_GIRn_MASK | MU_CR_NMI_MASK);
+	reg |= MU_CR_GIE0_MASK >> index;
+	writel_relaxed(reg, base + MU_ACR);
+}
+EXPORT_SYMBOL_GPL(mu_enable_general_int);
+
+/*
+ * Wait and send message to the other core.
+ */
+void mu_send_msg(void __iomem *base, uint32_t index, uint32_t msg)
+{
+	uint32_t mask = MU_SR_TE0_MASK >> index;
+
+	/* Wait TX register to be empty. */
+	while (!(readl_relaxed(base + MU_ASR) & mask))
+		;
+	writel_relaxed(msg, base + MU_ATR0  + (index * 4));
+}
+EXPORT_SYMBOL_GPL(mu_send_msg);
+
+/*
+ * Wait to receive message from the other core.
+ */
+void mu_receive_msg(void __iomem *base, uint32_t index, uint32_t *msg)
+{
+	uint32_t mask = MU_SR_RF0_MASK >> index;
+
+	/* Wait RX register to be full. */
+	while (!(readl_relaxed(base + MU_ASR) & mask))
+		;
+	*msg = readl_relaxed(base + MU_ARR0 + (index * 4));
+}
+EXPORT_SYMBOL_GPL(mu_receive_msg);
+
+void mu_init(void __iomem *base)
+{
+	uint32_t reg;
+
+	reg = readl_relaxed(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, base + MU_ACR);
+}
+EXPORT_SYMBOL_GPL(mu_init);
diff --git a/include/soc/imx/mu.h b/include/soc/imx/mu.h
new file mode 100644
index 0000000..1f54667
--- /dev/null
+++ b/include/soc/imx/mu.h
@@ -0,0 +1,21 @@
+/* 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_SIZE			0x10000
+#define MU_TR_COUNT		4
+#define MU_RR_COUNT		4
+
+void mu_init(void __iomem *base);
+void mu_send_msg(void __iomem *base, uint32_t index, uint32_t msg);
+void mu_receive_msg(void __iomem *base, uint32_t index, uint32_t *msg);
+void mu_enable_general_int(void __iomem *base, uint32_t index);
+void mu_enable_rx_full_int(void __iomem *base, uint32_t index);
+uint32_t mu_read_status(void __iomem *base);
+int32_t mu_set_fn(void __iomem *base, uint32_t Fn);
+#endif
-- 
2.7.4

  reply	other threads:[~2018-04-27 18:46 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-27 18:46 [PATCH 0/4] soc: imx: add scu firmware api support Dong Aisheng
2018-04-27 18:46 ` Dong Aisheng [this message]
2018-04-27 18:46 ` [PATCH 2/4] dt-bindings: arm: fsl: add mu binding doc Dong Aisheng
2018-05-01 15:25   ` Rob Herring
2018-05-02 17:29     ` A.s. Dong
2018-04-27 18:46 ` [PATCH 3/4] dt-bindings: arm: fsl: add scu " Dong Aisheng
2018-05-01 15:29   ` Rob Herring
2018-05-01  5:59 ` [PATCH 0/4] soc: imx: add scu firmware api support Oleksij Rempel
2018-05-02 18:54   ` A.s. Dong
2018-05-03  6:24     ` Oleksij Rempel
2018-05-03  7:33       ` A.s. Dong
     [not found] ` <1524854776-14863-5-git-send-email-aisheng.dong@nxp.com>
2018-05-02 10:04   ` [PATCH 4/4] soc: imx: add SC firmware IPC and APIs Sascha Hauer
2018-05-02 18:40     ` A.s. Dong
2018-05-03 11:06       ` Sascha Hauer
2018-05-03 12:29         ` A.s. Dong
2018-05-03 12:40           ` Sascha Hauer
2018-05-24  8:56             ` A.s. Dong
2018-05-28  9:24               ` A.s. Dong
2018-06-06 10:28                 ` A.s. Dong
2018-06-06 14:15               ` Sascha Hauer
2018-06-07  4:18                 ` A.s. Dong
2018-06-07  7:08                   ` Sascha Hauer
2018-06-07 13:59                     ` A.s. Dong
2018-06-08  4:13                       ` Sascha Hauer
2018-06-08  5:52                         ` A.s. Dong
2018-06-19 11:15     ` A.s. Dong

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=1524854776-14863-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;
as well as URLs for NNTP newsgroup(s).