blob: 11e7f74e47cca0c9733d698ad71eddcd77d03b76 [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 */
Tom Riniabb9a042024-05-18 20:20:43 -06005#include <common.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06006#include <env.h>
Simon Glassa7b51302019-11-14 12:57:46 -07007#include <init.h>
Andy Shevchenkod31315d2017-07-06 14:41:53 +03008#include <mmc.h>
9#include <u-boot/md5.h>
Andy Shevchenkod31315d2017-07-06 14:41:53 +030010
11#include <asm/cache.h>
Andy Shevchenko5ea5c952019-06-25 23:52:04 +030012#include <asm/pmu.h>
Andy Shevchenkod31315d2017-07-06 14:41:53 +030013#include <asm/scu.h>
14#include <asm/u-boot-x86.h>
15
Andy Shevchenko5ea5c952019-06-25 23:52:04 +030016/* List of Intel Tangier LSSs */
17#define PMU_LSS_TANGIER_SDIO0_01 1
18
19int board_early_init_r(void)
20{
21 pmu_turn_power(PMU_LSS_TANGIER_SDIO0_01, true);
22 return 0;
23}
24
Andy Shevchenkod31315d2017-07-06 14:41:53 +030025static void assign_serial(void)
26{
27 struct mmc *mmc = find_mmc_device(0);
28 unsigned char ssn[16];
29 char usb0addr[18];
30 char serial[33];
31 int i;
32
33 if (!mmc)
34 return;
35
36 md5((unsigned char *)mmc->cid, sizeof(mmc->cid), ssn);
37
38 snprintf(usb0addr, sizeof(usb0addr), "02:00:86:%02x:%02x:%02x",
39 ssn[13], ssn[14], ssn[15]);
Simon Glass6a38e412017-08-03 12:22:09 -060040 env_set("usb0addr", usb0addr);
Andy Shevchenkod31315d2017-07-06 14:41:53 +030041
42 for (i = 0; i < 16; i++)
43 snprintf(&serial[2 * i], 3, "%02x", ssn[i]);
Simon Glass6a38e412017-08-03 12:22:09 -060044 env_set("serial#", serial);
Andy Shevchenkod31315d2017-07-06 14:41:53 +030045
46#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
Simon Glassd49b8892017-08-03 12:22:08 -060047 env_save();
Andy Shevchenkod31315d2017-07-06 14:41:53 +030048#endif
49}
50
51static 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 Glass6a38e412017-08-03 12:22:09 -060062 env_set("hardware_id", hardware_id);
Andy Shevchenkod31315d2017-07-06 14:41:53 +030063
64#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
Simon Glassd49b8892017-08-03 12:22:08 -060065 env_save();
Andy Shevchenkod31315d2017-07-06 14:41:53 +030066#endif
67}
68
69int board_late_init(void)
70{
Simon Glass64b723f2017-08-03 12:22:12 -060071 if (!env_get("serial#"))
Andy Shevchenkod31315d2017-07-06 14:41:53 +030072 assign_serial();
73
Simon Glass64b723f2017-08-03 12:22:12 -060074 if (!env_get("hardware_id"))
Andy Shevchenkod31315d2017-07-06 14:41:53 +030075 assign_hardware_id();
76
77 return 0;
78}