blob: 7d452f4529b79c161e58af4eeafa7d2d651d65d5 [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>
Stephan Gerhold94844ae2021-08-03 12:12:38 +020012#include <asm/unaligned.h>
Ramon Fried90e905bf2018-08-03 16:25:35 +030013
14/* UNSTUFF_BITS macro taken from Linux Kernel: drivers/mmc/core/sd.c */
15#define UNSTUFF_BITS(resp, start, size) \
16 ({ \
17 const int __size = size; \
18 const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \
19 const int __off = 3 - ((start) / 32); \
20 const int __shft = (start) & 31; \
21 u32 __res; \
22 \
23 __res = resp[__off] >> __shft; \
24 if (__size + __shft > 32) \
25 __res |= resp[__off - 1] << ((32 - __shft) % 32); \
26 __res & __mask; \
27 })
28
29u32 msm_board_serial(void)
30{
31 struct mmc *mmc_dev;
32
33 mmc_dev = find_mmc_device(0);
34 if (!mmc_dev)
35 return 0;
36
Stephan Gerhold2636e462021-08-03 12:12:37 +020037 if (mmc_init(mmc_dev))
38 return 0;
39
Ramon Fried90e905bf2018-08-03 16:25:35 +030040 return UNSTUFF_BITS(mmc_dev->cid, 16, 32);
41}
Ramon Fried2d0f3862018-08-03 16:25:36 +030042
43void msm_generate_mac_addr(u8 *mac)
44{
Stephan Gerhold94844ae2021-08-03 12:12:38 +020045 /* use locally adminstrated pool */
Ramon Fried2d0f3862018-08-03 16:25:36 +030046 mac[0] = 0x02;
Stephan Gerhold94844ae2021-08-03 12:12:38 +020047 mac[1] = 0x00;
48
49 /*
50 * Put the 32-bit serial number in the last 32-bit of the MAC address.
51 * Use big endian order so it is consistent with the serial number
52 * written as a hexadecimal string, e.g. 0x1234abcd -> 02:00:12:34:ab:cd
53 */
54 put_unaligned_be32(msm_board_serial(), &mac[2]);
Ramon Fried2d0f3862018-08-03 16:25:36 +030055}