Ramon Fried | 90e905bf | 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> |
Stephan Gerhold | 94844ae | 2021-08-03 12:12:38 +0200 | [diff] [blame] | 12 | #include <asm/unaligned.h> |
Ramon Fried | 90e905bf | 2018-08-03 16:25:35 +0300 | [diff] [blame] | 13 | |
| 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 | |
| 29 | u32 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 Gerhold | 2636e46 | 2021-08-03 12:12:37 +0200 | [diff] [blame] | 37 | if (mmc_init(mmc_dev)) |
| 38 | return 0; |
| 39 | |
Ramon Fried | 90e905bf | 2018-08-03 16:25:35 +0300 | [diff] [blame] | 40 | return UNSTUFF_BITS(mmc_dev->cid, 16, 32); |
| 41 | } |
Ramon Fried | 2d0f386 | 2018-08-03 16:25:36 +0300 | [diff] [blame] | 42 | |
| 43 | void msm_generate_mac_addr(u8 *mac) |
| 44 | { |
Stephan Gerhold | 94844ae | 2021-08-03 12:12:38 +0200 | [diff] [blame] | 45 | /* use locally adminstrated pool */ |
Ramon Fried | 2d0f386 | 2018-08-03 16:25:36 +0300 | [diff] [blame] | 46 | mac[0] = 0x02; |
Stephan Gerhold | 94844ae | 2021-08-03 12:12:38 +0200 | [diff] [blame] | 47 | 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 Fried | 2d0f386 | 2018-08-03 16:25:36 +0300 | [diff] [blame] | 55 | } |