blob: aaa561c2c68e9a8e3e7b0f1379a1ada49bc4a949 [file] [log] [blame]
Ramon Fried86e5e422018-08-03 16:25:35 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Miscellaneous Snapdragon functionality
4 *
5 * (C) Copyright 2018 Ramon Fried <ramon.fried@gmail.com>
6 *
7 */
8
9#include <common.h>
10#include <mmc.h>
11#include <asm/arch/misc.h>
12
13/* UNSTUFF_BITS macro taken from Linux Kernel: drivers/mmc/core/sd.c */
14#define UNSTUFF_BITS(resp, start, size) \
15 ({ \
16 const int __size = size; \
17 const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \
18 const int __off = 3 - ((start) / 32); \
19 const int __shft = (start) & 31; \
20 u32 __res; \
21 \
22 __res = resp[__off] >> __shft; \
23 if (__size + __shft > 32) \
24 __res |= resp[__off - 1] << ((32 - __shft) % 32); \
25 __res & __mask; \
26 })
27
28u32 msm_board_serial(void)
29{
30 struct mmc *mmc_dev;
31
32 mmc_dev = find_mmc_device(0);
33 if (!mmc_dev)
34 return 0;
35
36 return UNSTUFF_BITS(mmc_dev->cid, 16, 32);
37}
Ramon Friede0b04a12018-08-03 16:25:36 +030038
39void msm_generate_mac_addr(u8 *mac)
40{
41 int i;
42 char sn[9];
43
Jan-Christoph Tebbe74037022020-03-16 17:51:51 +010044 snprintf(sn, 9, "%08x", msm_board_serial());
Ramon Friede0b04a12018-08-03 16:25:36 +030045
46 /* fill in the mac with serialno, use locally adminstrated pool */
47 mac[0] = 0x02;
48 mac[1] = 00;
49 for (i = 3; i >= 0; i--) {
50 mac[i + 2] = simple_strtoul(&sn[2 * i], NULL, 16);
51 sn[2 * i] = 0;
52 }
53}