Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2017 Intel Corporation |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 4 | */ |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 5 | #include <env.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 6 | #include <init.h> |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 7 | #include <mmc.h> |
| 8 | #include <u-boot/md5.h> |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 9 | |
| 10 | #include <asm/cache.h> |
Andy Shevchenko | 5ea5c95 | 2019-06-25 23:52:04 +0300 | [diff] [blame] | 11 | #include <asm/pmu.h> |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 12 | #include <asm/scu.h> |
| 13 | #include <asm/u-boot-x86.h> |
| 14 | |
Andy Shevchenko | 5ea5c95 | 2019-06-25 23:52:04 +0300 | [diff] [blame] | 15 | /* List of Intel Tangier LSSs */ |
| 16 | #define PMU_LSS_TANGIER_SDIO0_01 1 |
| 17 | |
| 18 | int board_early_init_r(void) |
| 19 | { |
| 20 | pmu_turn_power(PMU_LSS_TANGIER_SDIO0_01, true); |
| 21 | return 0; |
| 22 | } |
| 23 | |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 24 | static void assign_serial(void) |
| 25 | { |
| 26 | struct mmc *mmc = find_mmc_device(0); |
| 27 | unsigned char ssn[16]; |
| 28 | char usb0addr[18]; |
| 29 | char serial[33]; |
| 30 | int i; |
| 31 | |
| 32 | if (!mmc) |
| 33 | return; |
| 34 | |
Raymond Mao | c35e1a4 | 2024-10-03 14:50:17 -0700 | [diff] [blame] | 35 | md5_wd((unsigned char *)mmc->cid, sizeof(mmc->cid), ssn, |
| 36 | MD5_DEF_CHUNK_SZ); |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 37 | |
| 38 | snprintf(usb0addr, sizeof(usb0addr), "02:00:86:%02x:%02x:%02x", |
| 39 | ssn[13], ssn[14], ssn[15]); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 40 | env_set("usb0addr", usb0addr); |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 41 | |
| 42 | for (i = 0; i < 16; i++) |
| 43 | snprintf(&serial[2 * i], 3, "%02x", ssn[i]); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 44 | env_set("serial#", serial); |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 45 | |
| 46 | #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) |
Simon Glass | d49b889 | 2017-08-03 12:22:08 -0600 | [diff] [blame] | 47 | env_save(); |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 48 | #endif |
| 49 | } |
| 50 | |
| 51 | static void assign_hardware_id(void) |
| 52 | { |
| 53 | struct ipc_ifwi_version v; |
| 54 | char hardware_id[4]; |
| 55 | int ret; |
| 56 | |
| 57 | ret = scu_ipc_command(IPCMSG_GET_FW_REVISION, 1, NULL, 0, (u32 *)&v, 4); |
| 58 | if (ret < 0) |
| 59 | printf("Can't retrieve hardware revision\n"); |
| 60 | |
| 61 | snprintf(hardware_id, sizeof(hardware_id), "%02X", v.hardware_id); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 62 | env_set("hardware_id", hardware_id); |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 63 | |
| 64 | #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) |
Simon Glass | d49b889 | 2017-08-03 12:22:08 -0600 | [diff] [blame] | 65 | env_save(); |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 66 | #endif |
| 67 | } |
| 68 | |
| 69 | int board_late_init(void) |
| 70 | { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 71 | if (!env_get("serial#")) |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 72 | assign_serial(); |
| 73 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 74 | if (!env_get("hardware_id")) |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 75 | assign_hardware_id(); |
| 76 | |
| 77 | return 0; |
| 78 | } |