Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Marek Behún | d63726e | 2022-06-01 17:17:06 +0200 | [diff] [blame] | 3 | * Copyright (C) 2018 Marek Behún <kabel@kernel.org> |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 6 | #include <vsprintf.h> |
Marek Behún | 1055ce1 | 2020-04-08 12:02:07 +0200 | [diff] [blame] | 7 | #include <asm/arch/soc.h> |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 8 | #include <asm/io.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 9 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 10 | #include <linux/delay.h> |
Pali Rohár | deb1e92 | 2022-02-23 14:15:47 +0100 | [diff] [blame] | 11 | #include <mach/mbox.h> |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 12 | |
Marek Behún | 1b01011 | 2023-10-20 16:29:16 +0200 | [diff] [blame] | 13 | #include "mox_sp.h" |
| 14 | |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 15 | const 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ár | 0e6dce7 | 2022-02-23 14:15:48 +0100 | [diff] [blame] | 24 | res = mbox_do_cmd(MBOX_CMD_ECDSA_PUB_KEY, NULL, 0, out, 16); |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 25 | 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 | |
| 37 | static 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ún | 1b01011 | 2023-10-20 16:29:16 +0200 | [diff] [blame] | 47 | int mbox_sp_get_board_info(u64 *sn, u8 *mac1, u8 *mac2, int *bv, int *ram, |
| 48 | enum cznic_a3720_board *board) |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 49 | { |
Marek Behún | 1b01011 | 2023-10-20 16:29:16 +0200 | [diff] [blame] | 50 | u32 out[9]; |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 51 | int res; |
| 52 | |
Marek Behún | 1b01011 | 2023-10-20 16:29:16 +0200 | [diff] [blame] | 53 | res = mbox_do_cmd(MBOX_CMD_BOARD_INFO, NULL, 0, out, 9); |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 54 | 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ún | 1b01011 | 2023-10-20 16:29:16 +0200 | [diff] [blame] | 75 | if (board) |
| 76 | *board = out[8] + 1; |
| 77 | |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 78 | return 0; |
| 79 | } |