Ramon Fried | 86e5e42 | 2018-08-03 16:25:35 +0300 | [diff] [blame] | 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 | } |
Ramon Fried | e0b04a1 | 2018-08-03 16:25:36 +0300 | [diff] [blame] | 38 | |
| 39 | void msm_generate_mac_addr(u8 *mac) |
| 40 | { |
| 41 | int i; |
| 42 | char sn[9]; |
| 43 | |
Jan-Christoph Tebbe | 7403702 | 2020-03-16 17:51:51 +0100 | [diff] [blame] | 44 | snprintf(sn, 9, "%08x", msm_board_serial()); |
Ramon Fried | e0b04a1 | 2018-08-03 16:25:36 +0300 | [diff] [blame] | 45 | |
| 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 | } |