@@ -3,4 +3,5 @@
# Copyright 2020 Broadcom.
obj-y := ns3.o
+obj-y += mcu_cmd.o
obj-$(CONFIG_CHIMP_OPTEE) += chimp_optee.o
new file mode 100644
@@ -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;
+}
new file mode 100644
@@ -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__ */