xref: /openbmc/u-boot/arch/arm/mach-snapdragon/misc.c (revision 86e5e429468310d0f1716a1ebb95159aba3b61b4)
1 // 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 
28 u32 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 }
38