From patchwork Mon Apr 27 10:51:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rayagonda Kokatanur X-Patchwork-Id: 238640 List-Id: U-Boot discussion From: rayagonda.kokatanur at broadcom.com (Rayagonda Kokatanur) Date: Mon, 27 Apr 2020 16:21:56 +0530 Subject: [PATCH v1 38/49] board: ns3: add generic MCU IPC command send API In-Reply-To: <20200427105207.5659-1-rayagonda.kokatanur@broadcom.com> References: <20200427105207.5659-1-rayagonda.kokatanur@broadcom.com> Message-ID: <20200427105207.5659-39-rayagonda.kokatanur@broadcom.com> From: Trac Hoang Add a generic CRMU IPC command send driver so that u-boot can access MCU services. Signed-off-by: Trac Hoang Signed-off-by: Rayagonda Kokatanur --- 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 +#include +#include + +#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__ */