blob: 911ffda2fc7811c9ce798183d648fbadbff3ce37 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Andy Shevchenkod31315d2017-07-06 14:41:53 +03002/*
3 * Copyright (c) 2017 Intel Corporation
Andy Shevchenkod31315d2017-07-06 14:41:53 +03004 */
Simon Glass5e6201b2019-08-01 09:46:51 -06005#include <env.h>
Simon Glassa7b51302019-11-14 12:57:46 -07006#include <init.h>
Andy Shevchenkod31315d2017-07-06 14:41:53 +03007#include <mmc.h>
8#include <u-boot/md5.h>
Andy Shevchenkod31315d2017-07-06 14:41:53 +03009
10#include <asm/cache.h>
Andy Shevchenko5ea5c952019-06-25 23:52:04 +030011#include <asm/pmu.h>
Andy Shevchenkod31315d2017-07-06 14:41:53 +030012#include <asm/scu.h>
13#include <asm/u-boot-x86.h>
14
Andy Shevchenko5ea5c952019-06-25 23:52:04 +030015/* List of Intel Tangier LSSs */
16#define PMU_LSS_TANGIER_SDIO0_01 1
17
18int board_early_init_r(void)
19{
20 pmu_turn_power(PMU_LSS_TANGIER_SDIO0_01, true);
21 return 0;
22}
23
Andy Shevchenkod31315d2017-07-06 14:41:53 +030024static 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
35 md5((unsigned char *)mmc->cid, sizeof(mmc->cid), ssn);
36
37 snprintf(usb0addr, sizeof(usb0addr), "02:00:86:%02x:%02x:%02x",
38 ssn[13], ssn[14], ssn[15]);
Simon Glass6a38e412017-08-03 12:22:09 -060039 env_set("usb0addr", usb0addr);
Andy Shevchenkod31315d2017-07-06 14:41:53 +030040
41 for (i = 0; i < 16; i++)
42 snprintf(&serial[2 * i], 3, "%02x", ssn[i]);
Simon Glass6a38e412017-08-03 12:22:09 -060043 env_set("serial#", serial);
Andy Shevchenkod31315d2017-07-06 14:41:53 +030044
45#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
Simon Glassd49b8892017-08-03 12:22:08 -060046 env_save();
Andy Shevchenkod31315d2017-07-06 14:41:53 +030047#endif
48}
49
50static void assign_hardware_id(void)
51{
52 struct ipc_ifwi_version v;
53 char hardware_id[4];
54 int ret;
55
56 ret = scu_ipc_command(IPCMSG_GET_FW_REVISION, 1, NULL, 0, (u32 *)&v, 4);
57 if (ret < 0)
58 printf("Can't retrieve hardware revision\n");
59
60 snprintf(hardware_id, sizeof(hardware_id), "%02X", v.hardware_id);
Simon Glass6a38e412017-08-03 12:22:09 -060061 env_set("hardware_id", hardware_id);
Andy Shevchenkod31315d2017-07-06 14:41:53 +030062
63#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
Simon Glassd49b8892017-08-03 12:22:08 -060064 env_save();
Andy Shevchenkod31315d2017-07-06 14:41:53 +030065#endif
66}
67
68int board_late_init(void)
69{
Simon Glass64b723f2017-08-03 12:22:12 -060070 if (!env_get("serial#"))
Andy Shevchenkod31315d2017-07-06 14:41:53 +030071 assign_serial();
72
Simon Glass64b723f2017-08-03 12:22:12 -060073 if (!env_get("hardware_id"))
Andy Shevchenkod31315d2017-07-06 14:41:53 +030074 assign_hardware_id();
75
76 return 0;
77}