[PATCH v1 38/49] board: ns3: add generic MCU IPC command send API
Rayagonda Kokatanur
rayagonda.kokatanur at broadcom.com
Mon Apr 27 12:51:56 CEST 2020
From: Trac Hoang <trac.hoang at broadcom.com>
Add a generic CRMU IPC command send driver so that
u-boot can access MCU services.
Signed-off-by: Trac Hoang <trac.hoang at broadcom.com>
Signed-off-by: Rayagonda Kokatanur <rayagonda.kokatanur at broadcom.com>
---
board/broadcom/bcmns3/Makefile | 1 +
board/broadcom/bcmns3/mcu_cmd.c | 49 +++++++++++++++++++++++++++++++++
board/broadcom/bcmns3/mcu_cmd.h | 13 +++++++++
3 files changed, 63 insertions(+)
create mode 100644 board/broadcom/bcmns3/mcu_cmd.c
create mode 100644 board/broadcom/bcmns3/mcu_cmd.h
diff --git a/board/broadcom/bcmns3/Makefile b/board/broadcom/bcmns3/Makefile
index 08e1d7203b..f62da01701 100644
--- a/board/broadcom/bcmns3/Makefile
+++ b/board/broadcom/bcmns3/Makefile
@@ -3,4 +3,5 @@
# Copyright 2020 Broadcom.
obj-y := ns3.o
+obj-y += mcu_cmd.o
obj-$(CONFIG_CHIMP_OPTEE) += chimp_optee.o
diff --git a/board/broadcom/bcmns3/mcu_cmd.c b/board/broadcom/bcmns3/mcu_cmd.c
new file mode 100644
index 0000000000..aff41c3a19
--- /dev/null
+++ b/board/broadcom/bcmns3/mcu_cmd.c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2020 Broadcom.
+ *
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <linux/delay.h>
+
+#include "mcu_cmd.h"
+
+#define MCU_MAILBOX_0 0x66424024
+#define MCU_MAILBOX_1 0x66424028
+
+#define MCU_IPC_CMD_DONE_MASK 0x80000000
+#define MCU_IPC_CMD_REPLY_MASK 0x3fff0000
+#define MCU_IPC_CMD_REPLY_SHIFT 16
+
+int send_crmu_cmd(u32 cmd, u32 param, u32 timeout_msec)
+{
+ u32 val;
+ int ret = CMD_RET_FAILURE;
+
+ writel(cmd, MCU_MAILBOX_0);
+ writel(param, MCU_MAILBOX_1);
+
+ do {
+ mdelay(1);
+ val = readl(MCU_MAILBOX_0);
+ if (val & MCU_IPC_CMD_DONE_MASK) {
+ ret = CMD_RET_SUCCESS;
+ break;
+ }
+
+ } while (timeout_msec--);
+
+ if (ret == CMD_RET_FAILURE) {
+ pr_err("CRMU cmd timeout!\n");
+ return ret;
+ }
+
+ /* Obtain status */
+ val = (val & MCU_IPC_CMD_REPLY_MASK) >> MCU_IPC_CMD_REPLY_SHIFT;
+ if (val)
+ ret = CMD_RET_FAILURE;
+
+ return ret;
+}
diff --git a/board/broadcom/bcmns3/mcu_cmd.h b/board/broadcom/bcmns3/mcu_cmd.h
new file mode 100644
index 0000000000..82f0821248
--- /dev/null
+++ b/board/broadcom/bcmns3/mcu_cmd.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2019 Broadcom
+ */
+
+#ifndef __MCU_CMD_H__
+#define __MCU_CMD_H__
+
+#define MCU_CMD_DEFAULT_TIMEOUT_MS 10
+
+int send_crmu_cmd(u32 cmd, u32 param, u32 timeout_msec);
+
+#endif /* __MCU_CMD_H__ */
--
2.17.1
More information about the U-Boot
mailing list