1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Marek Behun <marek.behun@nic.cz>
7 #include <asm/arch/soc.h>
10 #define RWTM_BASE (MVEBU_REGISTER(0xb0000))
11 #define RWTM_CMD_PARAM(i) (size_t)(RWTM_BASE + (i) * 4)
12 #define RWTM_CMD (RWTM_BASE + 0x40)
13 #define RWTM_CMD_RETSTATUS (RWTM_BASE + 0x80)
14 #define RWTM_CMD_STATUS(i) (size_t)(RWTM_BASE + 0x84 + (i) * 4)
16 #define RWTM_HOST_INT_RESET (RWTM_BASE + 0xc8)
17 #define RWTM_HOST_INT_MASK (RWTM_BASE + 0xcc)
18 #define SP_CMD_COMPLETE BIT(0)
20 #define MBOX_STS_SUCCESS (0x0 << 30)
21 #define MBOX_STS_FAIL (0x1 << 30)
22 #define MBOX_STS_BADCMD (0x2 << 30)
23 #define MBOX_STS_LATER (0x3 << 30)
24 #define MBOX_STS_ERROR(s) ((s) & (3 << 30))
25 #define MBOX_STS_VALUE(s) (((s) >> 10) & 0xfffff)
26 #define MBOX_STS_CMD(s) ((s) & 0x3ff)
29 MBOX_CMD_GET_RANDOM = 1,
31 MBOX_CMD_ECDSA_PUB_KEY,
40 static int mbox_do_cmd(enum mbox_cmd cmd, u32 *out, int nout)
46 clrbits_le32(RWTM_HOST_INT_MASK, SP_CMD_COMPLETE);
48 writel(cmd, RWTM_CMD);
50 for (i = 0; i < tries; ++i) {
52 if (readl(RWTM_HOST_INT_RESET) & SP_CMD_COMPLETE)
57 /* if timed out, don't read status */
58 setbits_le32(RWTM_HOST_INT_RESET, SP_CMD_COMPLETE);
62 for (i = 0; i < nout; ++i)
63 out[i] = readl(RWTM_CMD_STATUS(i));
64 status = readl(RWTM_CMD_RETSTATUS);
66 setbits_le32(RWTM_HOST_INT_RESET, SP_CMD_COMPLETE);
68 if (MBOX_STS_CMD(status) != cmd)
70 else if (MBOX_STS_ERROR(status) == MBOX_STS_FAIL)
71 return -(int)MBOX_STS_VALUE(status);
72 else if (MBOX_STS_ERROR(status) != MBOX_STS_SUCCESS)
75 return MBOX_STS_VALUE(status);
78 const char *mox_sp_get_ecdsa_public_key(void)
80 static char public_key[135];
87 res = mbox_do_cmd(MBOX_CMD_ECDSA_PUB_KEY, out, 16);
92 "%06x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x",
93 (u32)res, out[0], out[1], out[2], out[3], out[4], out[5],
94 out[6], out[7], out[8], out[9], out[10], out[11], out[12],
95 out[13], out[14], out[15]);
100 static inline void res_to_mac(u8 *mac, u32 t1, u32 t2)
110 int mbox_sp_get_board_info(u64 *sn, u8 *mac1, u8 *mac2, int *bv, int *ram)
115 res = mbox_do_cmd(MBOX_CMD_BOARD_INFO, out, 8);
132 res_to_mac(mac1, out[4], out[5]);
135 res_to_mac(mac2, out[6], out[7]);