blob: 1591b40deee6694f13c304db371c228dba0e5fcf [file] [log] [blame]
Marek Behún35572c92018-12-17 16:10:08 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
Marek Behúnd63726e2022-06-01 17:17:06 +02003 * Copyright (C) 2018 Marek Behún <kabel@kernel.org>
Marek Behún35572c92018-12-17 16:10:08 +01004 */
5
Tom Rinidec7ea02024-05-20 13:35:03 -06006#include <vsprintf.h>
Marek Behún1055ce12020-04-08 12:02:07 +02007#include <asm/arch/soc.h>
Marek Behún35572c92018-12-17 16:10:08 +01008#include <asm/io.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -06009#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060010#include <linux/delay.h>
Pali Rohárdeb1e922022-02-23 14:15:47 +010011#include <mach/mbox.h>
Marek Behún35572c92018-12-17 16:10:08 +010012
Marek Behún1b010112023-10-20 16:29:16 +020013#include "mox_sp.h"
14
Marek Behún35572c92018-12-17 16:10:08 +010015const char *mox_sp_get_ecdsa_public_key(void)
16{
17 static char public_key[135];
18 u32 out[16];
19 int res;
20
21 if (public_key[0])
22 return public_key;
23
Pali Rohár0e6dce72022-02-23 14:15:48 +010024 res = mbox_do_cmd(MBOX_CMD_ECDSA_PUB_KEY, NULL, 0, out, 16);
Marek Behún35572c92018-12-17 16:10:08 +010025 if (res < 0)
26 return NULL;
27
28 sprintf(public_key,
29 "%06x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x",
30 (u32)res, out[0], out[1], out[2], out[3], out[4], out[5],
31 out[6], out[7], out[8], out[9], out[10], out[11], out[12],
32 out[13], out[14], out[15]);
33
34 return public_key;
35}
36
37static inline void res_to_mac(u8 *mac, u32 t1, u32 t2)
38{
39 mac[0] = t1 >> 8;
40 mac[1] = t1;
41 mac[2] = t2 >> 24;
42 mac[3] = t2 >> 16;
43 mac[4] = t2 >> 8;
44 mac[5] = t2;
45}
46
Marek Behún1b010112023-10-20 16:29:16 +020047int mbox_sp_get_board_info(u64 *sn, u8 *mac1, u8 *mac2, int *bv, int *ram,
48 enum cznic_a3720_board *board)
Marek Behún35572c92018-12-17 16:10:08 +010049{
Marek Behún1b010112023-10-20 16:29:16 +020050 u32 out[9];
Marek Behún35572c92018-12-17 16:10:08 +010051 int res;
52
Marek Behún1b010112023-10-20 16:29:16 +020053 res = mbox_do_cmd(MBOX_CMD_BOARD_INFO, NULL, 0, out, 9);
Marek Behún35572c92018-12-17 16:10:08 +010054 if (res < 0)
55 return res;
56
57 if (sn) {
58 *sn = out[1];
59 *sn <<= 32;
60 *sn |= out[0];
61 }
62
63 if (bv)
64 *bv = out[2];
65
66 if (ram)
67 *ram = out[3];
68
69 if (mac1)
70 res_to_mac(mac1, out[4], out[5]);
71
72 if (mac2)
73 res_to_mac(mac2, out[6], out[7]);
74
Marek Behún1b010112023-10-20 16:29:16 +020075 if (board)
76 *board = out[8] + 1;
77
Marek Behún35572c92018-12-17 16:10:08 +010078 return 0;
79}