blob: fbd5f4d051bc23901b1032b76d4e0f63d8c01911 [file] [log] [blame]
Ramon Fried90e905bf2018-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
Stephan Gerhold2636e462021-08-03 12:12:37 +020036 if (mmc_init(mmc_dev))
37 return 0;
38
Ramon Fried90e905bf2018-08-03 16:25:35 +030039 return UNSTUFF_BITS(mmc_dev->cid, 16, 32);
40}
Ramon Fried2d0f3862018-08-03 16:25:36 +030041
42void msm_generate_mac_addr(u8 *mac)
43{
44 int i;
45 char sn[9];
46
Jan-Christoph Tebbea2912982020-03-16 17:51:51 +010047 snprintf(sn, 9, "%08x", msm_board_serial());
Ramon Fried2d0f3862018-08-03 16:25:36 +030048
49 /* fill in the mac with serialno, use locally adminstrated pool */
50 mac[0] = 0x02;
51 mac[1] = 00;
52 for (i = 3; i >= 0; i--) {
Simon Glass3ff49ec2021-07-24 09:03:29 -060053 mac[i + 2] = hextoul(&sn[2 * i], NULL);
Ramon Fried2d0f3862018-08-03 16:25:36 +030054 sn[2 * i] = 0;
55 }
56}