All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
To: sbabic@denx.de, festevam@gmail.com
Cc: uboot-imx@nxp.com, u-boot@lists.denx.de, Ye Li <ye.li@nxp.com>
Subject: [PATCH V2 12/46] driver: misc: Add MU and S400 API to communicate with Sentinel
Date: Tue, 29 Jun 2021 10:32:06 +0800	[thread overview]
Message-ID: <20210629023240.22394-13-peng.fan@oss.nxp.com> (raw)
In-Reply-To: <20210629023240.22394-1-peng.fan@oss.nxp.com>

From: Ye Li <ye.li@nxp.com>

Add MU driver and S400 API. Need enable MISC driver to work

Signed-off-by: Ye Li <ye.li@nxp.com>
---
 arch/arm/include/asm/arch-imx8ulp/s400_api.h |  30 +++
 arch/arm/include/asm/global_data.h           |   5 +
 drivers/misc/Makefile                        |   1 +
 drivers/misc/imx8ulp/Makefile                |   3 +
 drivers/misc/imx8ulp/imx8ulp_mu.c            | 247 +++++++++++++++++++
 drivers/misc/imx8ulp/s400_api.c              |  41 +++
 6 files changed, 327 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-imx8ulp/s400_api.h
 create mode 100644 drivers/misc/imx8ulp/Makefile
 create mode 100644 drivers/misc/imx8ulp/imx8ulp_mu.c
 create mode 100644 drivers/misc/imx8ulp/s400_api.c

diff --git a/arch/arm/include/asm/arch-imx8ulp/s400_api.h b/arch/arm/include/asm/arch-imx8ulp/s400_api.h
new file mode 100644
index 0000000000..3ba6b525c5
--- /dev/null
+++ b/arch/arm/include/asm/arch-imx8ulp/s400_api.h
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2021 NXP
+ */
+
+#ifndef __S400_API_H__
+#define __S400_API_H__
+
+#define AHAB_VERSION    0x6
+#define AHAB_CMD_TAG    0x17
+#define AHAB_RESP_TAG   0xe1
+
+#define AHAB_LOG_CID            0x21
+#define AHAB_AUTH_OEM_CTNR_CID  0x87
+#define AHAB_VERIFY_IMG_CID     0x88
+#define AHAB_RELEASE_CTNR_CID   0x89
+#define AHAB_RELEASE_RDC_REQ_CID   0xC4
+
+#define S400_MAX_MSG          8U
+
+struct imx8ulp_s400_msg {
+	u8 version;
+	u8 size;
+	u8 command;
+	u8 tag;
+	u32 data[(S400_MAX_MSG - 1U)];
+};
+
+int ahab_release_rdc(u8 core_id);
+#endif
diff --git a/arch/arm/include/asm/global_data.h b/arch/arm/include/asm/global_data.h
index 2aff1c467c..cfedae05ea 100644
--- a/arch/arm/include/asm/global_data.h
+++ b/arch/arm/include/asm/global_data.h
@@ -87,6 +87,11 @@ struct arch_global_data {
 #ifdef CONFIG_ARCH_IMX8
 	struct udevice *scu_dev;
 #endif
+
+#ifdef CONFIG_ARCH_IMX8ULP
+	struct udevice *s400_dev;
+#endif
+
 };
 
 #include <asm-generic/global_data.h>
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 0c67d43a5d..b64cd2a4de 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -46,6 +46,7 @@ obj-$(CONFIG_SANDBOX) += irq_sandbox.o
 obj-$(CONFIG_$(SPL_)I2C_EEPROM) += i2c_eeprom.o
 obj-$(CONFIG_IHS_FPGA) += ihs_fpga.o
 obj-$(CONFIG_IMX8) += imx8/
+obj-$(CONFIG_IMX8ULP) += imx8ulp/
 obj-$(CONFIG_LED_STATUS) += status_led.o
 obj-$(CONFIG_LED_STATUS_GPIO) += gpio_led.o
 obj-$(CONFIG_MPC83XX_SERDES) += mpc83xx_serdes.o
diff --git a/drivers/misc/imx8ulp/Makefile b/drivers/misc/imx8ulp/Makefile
new file mode 100644
index 0000000000..1d792415d2
--- /dev/null
+++ b/drivers/misc/imx8ulp/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+obj-y += s400_api.o imx8ulp_mu.o
diff --git a/drivers/misc/imx8ulp/imx8ulp_mu.c b/drivers/misc/imx8ulp/imx8ulp_mu.c
new file mode 100644
index 0000000000..3f6dd558e6
--- /dev/null
+++ b/drivers/misc/imx8ulp/imx8ulp_mu.c
@@ -0,0 +1,247 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2020 NXP
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <dm.h>
+#include <dm/lists.h>
+#include <dm/root.h>
+#include <dm/device-internal.h>
+#include <asm/arch/s400_api.h>
+#include <linux/iopoll.h>
+#include <misc.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct mu_type {
+	u32 ver;
+	u32 par;
+	u32 cr;
+	u32 sr;
+	u32 reserved0[68];
+	u32 tcr;
+	u32 tsr;
+	u32 rcr;
+	u32 rsr;
+	u32 reserved1[52];
+	u32 tr[16];
+	u32 reserved2[16];
+	u32 rr[16];
+	u32 reserved4[14];
+	u32 mu_attr;
+};
+
+struct imx8ulp_mu {
+	struct mu_type *base;
+};
+
+#define MU_SR_TE0_MASK		BIT(0)
+#define MU_SR_RF0_MASK		BIT(0)
+#define MU_TR_COUNT		4
+#define MU_RR_COUNT		4
+
+static inline void mu_hal_init(struct mu_type *base)
+{
+	writel(0, &base->tcr);
+	writel(0, &base->rcr);
+}
+
+static int mu_hal_sendmsg(struct mu_type *base, u32 reg_index, u32 msg)
+{
+	u32 mask = MU_SR_TE0_MASK << reg_index;
+	u32 val;
+	int ret;
+
+	assert(reg_index < MU_TR_COUNT);
+
+	debug("sendmsg sr 0x%x\n", readl(&base->sr));
+
+	/* Wait TX register to be empty. */
+	ret = readl_poll_timeout(&base->tsr, val, val & mask, 10000);
+	if (ret < 0) {
+		debug("%s timeout\n", __func__);
+		return -ETIMEDOUT;
+	}
+
+	debug("tr[%d] 0x%x\n", reg_index, msg);
+
+	writel(msg, &base->tr[reg_index]);
+
+	return 0;
+}
+
+static int mu_hal_receivemsg(struct mu_type *base, u32 reg_index, u32 *msg)
+{
+	u32 mask = MU_SR_RF0_MASK << reg_index;
+	u32 val;
+	int ret;
+
+	assert(reg_index < MU_TR_COUNT);
+
+	debug("receivemsg sr 0x%x\n", readl(&base->sr));
+
+	/* Wait RX register to be full. */
+	ret = readl_poll_timeout(&base->rsr, val, val & mask, 10000);
+	if (ret < 0) {
+		debug("%s timeout\n", __func__);
+		return -ETIMEDOUT;
+	}
+
+	*msg = readl(&base->rr[reg_index]);
+
+	debug("rr[%d] 0x%x\n", reg_index, *msg);
+
+	return 0;
+}
+
+static int imx8ulp_mu_read(struct mu_type *base, void *data)
+{
+	struct imx8ulp_s400_msg *msg = (struct imx8ulp_s400_msg *)data;
+	int ret;
+	u8 count = 0;
+
+	if (!msg)
+		return -EINVAL;
+
+	/* Read first word */
+	ret = mu_hal_receivemsg(base, 0, (u32 *)msg);
+	if (ret)
+		return ret;
+	count++;
+
+	/* Check size */
+	if (msg->size > S400_MAX_MSG) {
+		*((u32 *)msg) = 0;
+		return -EINVAL;
+	}
+
+	/* Read remaining words */
+	while (count < msg->size) {
+		ret = mu_hal_receivemsg(base, count % MU_RR_COUNT,
+					&msg->data[count - 1]);
+		if (ret)
+			return ret;
+		count++;
+	}
+
+	return 0;
+}
+
+static int imx8ulp_mu_write(struct mu_type *base, void *data)
+{
+	struct imx8ulp_s400_msg *msg = (struct imx8ulp_s400_msg *)data;
+	int ret;
+	u8 count = 0;
+
+	if (!msg)
+		return -EINVAL;
+
+	/* Check size */
+	if (msg->size > S400_MAX_MSG)
+		return -EINVAL;
+
+	/* Write first word */
+	ret = mu_hal_sendmsg(base, 0, *((u32 *)msg));
+	if (ret)
+		return ret;
+	count++;
+
+	/* Write remaining words */
+	while (count < msg->size) {
+		ret = mu_hal_sendmsg(base, count % MU_TR_COUNT,
+				     msg->data[count - 1]);
+		if (ret)
+			return ret;
+		count++;
+	}
+
+	return 0;
+}
+
+/*
+ * Note the function prototype use msgid as the 2nd parameter, here
+ * we take it as no_resp.
+ */
+static int imx8ulp_mu_call(struct udevice *dev, int no_resp, void *tx_msg,
+			   int tx_size, void *rx_msg, int rx_size)
+{
+	struct imx8ulp_mu *priv = dev_get_priv(dev);
+	u32 result;
+	int ret;
+
+	/* Expect tx_msg, rx_msg are the same value */
+	if (rx_msg && tx_msg != rx_msg)
+		printf("tx_msg %p, rx_msg %p\n", tx_msg, rx_msg);
+
+	ret = imx8ulp_mu_write(priv->base, tx_msg);
+	if (ret)
+		return ret;
+	if (!no_resp) {
+		ret = imx8ulp_mu_read(priv->base, rx_msg);
+		if (ret)
+			return ret;
+	}
+
+	result = ((struct imx8ulp_s400_msg *)rx_msg)->data[0];
+	if ((result & 0xff) == 0)
+		return 0;
+
+	return -EIO;
+}
+
+static int imx8ulp_mu_probe(struct udevice *dev)
+{
+	struct imx8ulp_mu *priv = dev_get_priv(dev);
+	fdt_addr_t addr;
+
+	debug("%s(dev=%p) (priv=%p)\n", __func__, dev, priv);
+
+	addr = devfdt_get_addr(dev);
+	if (addr == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	priv->base = (struct mu_type *)addr;
+
+	debug("mu base 0x%lx\n", (ulong)priv->base);
+
+	/* U-Boot not enable interrupts, so need to enable RX interrupts */
+	mu_hal_init(priv->base);
+
+	gd->arch.s400_dev = dev;
+
+	return 0;
+}
+
+static int imx8ulp_mu_remove(struct udevice *dev)
+{
+	return 0;
+}
+
+static int imx8ulp_mu_bind(struct udevice *dev)
+{
+	debug("%s(dev=%p)\n", __func__, dev);
+
+	return 0;
+}
+
+static struct misc_ops imx8ulp_mu_ops = {
+	.call = imx8ulp_mu_call,
+};
+
+static const struct udevice_id imx8ulp_mu_ids[] = {
+	{ .compatible = "fsl,imx8ulp-mu" },
+	{ }
+};
+
+U_BOOT_DRIVER(imx8ulp_mu) = {
+	.name		= "imx8ulp_mu",
+	.id		= UCLASS_MISC,
+	.of_match	= imx8ulp_mu_ids,
+	.probe		= imx8ulp_mu_probe,
+	.bind		= imx8ulp_mu_bind,
+	.remove		= imx8ulp_mu_remove,
+	.ops		= &imx8ulp_mu_ops,
+	.priv_auto	= sizeof(struct imx8ulp_mu),
+};
diff --git a/drivers/misc/imx8ulp/s400_api.c b/drivers/misc/imx8ulp/s400_api.c
new file mode 100644
index 0000000000..82fd3117a4
--- /dev/null
+++ b/drivers/misc/imx8ulp/s400_api.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2020 NXP
+ *
+ */
+
+#include <common.h>
+#include <hang.h>
+#include <malloc.h>
+#include <asm/io.h>
+#include <dm.h>
+#include <asm/arch/s400_api.h>
+#include <misc.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+int ahab_release_rdc(u8 core_id)
+{
+	struct udevice *dev = gd->arch.s400_dev;
+	int size = sizeof(struct imx8ulp_s400_msg);
+	struct imx8ulp_s400_msg msg;
+	int ret;
+
+	if (!dev) {
+		printf("s400 dev is not initialized\n");
+		return -ENODEV;
+	}
+
+	msg.version = AHAB_VERSION;
+	msg.tag = AHAB_CMD_TAG;
+	msg.size = 2;
+	msg.command = AHAB_RELEASE_RDC_REQ_CID;
+	msg.data[0] = core_id;
+
+	ret = misc_call(dev, false, &msg, size, &msg, size);
+	if (ret)
+		printf("Error: %s: ret %d, core id %u, response 0x%x\n",
+		       __func__, ret, core_id, msg.data[0]);
+
+	return ret;
+}
-- 
2.30.0


  parent reply	other threads:[~2021-06-29  2:01 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-29  2:31 [PATCH V2 00/46] imx: add i.MX8ULP support Peng Fan (OSS)
2021-06-29  2:31 ` [PATCH V2 01/46] arm: imx: add i.MX8ULP basic Kconfig option Peng Fan (OSS)
2021-06-29  2:31 ` [PATCH V2 02/46] arm: imx: add i.MX8ULP cpu type and helper Peng Fan (OSS)
2021-06-29  2:31 ` [PATCH V2 03/46] arm: imx: sys_proto: move boot mode define to common header Peng Fan (OSS)
2021-06-29  2:31 ` [PATCH V2 04/46] arm: imx8ulp: support print cpu info Peng Fan (OSS)
2021-06-29  2:31 ` [PATCH V2 05/46] imx: imx8ulp: add get reset cause Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 06/46] arm: imx: basic i.MX8ULP support Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 07/46] arm: imx8: Move container parser and image to mach-imx common folder Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 08/46] arm: imx8: Move container image header file to mach-imx Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 09/46] arm: imx: parse-container: guard included header files Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 10/46] arm: imx8ulp: add container support Peng Fan (OSS)
2021-07-17 12:49   ` Stefano Babic
2021-07-19  1:41     ` Peng Fan
2021-06-29  2:32 ` [PATCH V2 11/46] arm: imx: move container Kconfig under mach-imx Peng Fan (OSS)
2021-06-29  2:32 ` Peng Fan (OSS) [this message]
2021-06-29  2:32 ` [PATCH V2 13/46] net: fec_mxc: support i.MX8ULP Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 14/46] pinctrl: Add pinctrl driver for imx8ulp Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 15/46] driver: serial: fsl_lpuart: support i.MX8ULP Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 16/46] arm: imx8ulp: add clock support Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 17/46] drivers: mmc: fsl_esdhc_imx: support i.MX8ULP Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 18/46] arm: imx8ulp: soc: Change to use CMC1 to get bootcfg Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 19/46] arm: imx8ulp: Enable full L2 cache in SPL Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 20/46] arm: imx8ulp: disable wdog3 Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 21/46] arm: imx8ulp: Update the reset vector in u-boot Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 22/46] drivers: misc: s400_api: Update S400_SUCCESS_IND to 0xd6 Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 23/46] drivers: misc: imx8ulp: Add S400 API for image authentication Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 24/46] drivers: misc: imx8ulp: Update S400 API for release RDC Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 25/46] drivers: misc: s400_api: Update API for fuse read and write Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 26/46] arm: imx8ulp: release and configure XRDC at early phase Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 27/46] arm: imx8ulp: add rdc support Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 28/46] arm: imx8ulp: add trdc release request Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 29/46] arm: imx8ulp: release trdc and assign lpav from RTD to APD Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 30/46] imx8ulp: unify rdc functions Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 31/46] arm: imx8ulp: Probe the S400 MU device in arch init Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 32/46] arm: iMX8ULP: Add boot device relevant functions Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 33/46] arm: imx8ulp: Allocate DCNANO and MIPI_DSI to AD domain Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 34/46] arm: imx8ulp: add dummy imx_get_mac_from_fuse Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 35/46] arm: imx8ulp: add iomuxc support Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 36/46] driver: misc: imx8ulp: Add fuse driver for imx8ulp Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 37/46] imx8ulp: soc: correct reset cause Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 38/46] imx8ulp: Use DGO_GP5 to get boot config Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 39/46] imx8ulp: Add workaround for eMMC boot Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 40/46] mx7ulp: Update unlock and refresh sequences in sWDOG driver Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 41/46] mx7ulp: wdog: Wait for WDOG unlock and reconfiguration to complete Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 42/46] imx8ulp: move struct mu_type to common header Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 43/46] imx8ulp: add upower api support Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 44/46] ddr: Add DDR driver for iMX8ULP Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 45/46] arm: dts: add i.MX8ULP dtsi Peng Fan (OSS)
2021-06-29  2:32 ` [PATCH V2 46/46] arm: imx: add i.MX8ULP EVK support Peng Fan (OSS)
2021-07-15  3:29 ` [PATCH V2 00/46] imx: add i.MX8ULP support Peng Fan (OSS)
2021-07-15  8:11   ` Stefano Babic

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=20210629023240.22394-13-peng.fan@oss.nxp.com \
    --to=peng.fan@oss.nxp.com \
    --cc=festevam@gmail.com \
    --cc=sbabic@denx.de \
    --cc=u-boot@lists.denx.de \
    --cc=uboot-imx@nxp.com \
    --cc=ye.li@nxp.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.