blob: d80ee3aa8a6389d051d5495f9cce49a6609d3a82 [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 */
5#include <common.h>
6#include <dwc3-uboot.h>
Simon Glassd49b8892017-08-03 12:22:08 -06007#include <environment.h>
Andy Shevchenkod31315d2017-07-06 14:41:53 +03008#include <mmc.h>
9#include <u-boot/md5.h>
10#include <usb.h>
11#include <watchdog.h>
12
13#include <linux/usb/gadget.h>
14
15#include <asm/cache.h>
Andy Shevchenko5ea5c952019-06-25 23:52:04 +030016#include <asm/pmu.h>
Andy Shevchenkod31315d2017-07-06 14:41:53 +030017#include <asm/scu.h>
18#include <asm/u-boot-x86.h>
19
Andy Shevchenko5ea5c952019-06-25 23:52:04 +030020/* List of Intel Tangier LSSs */
21#define PMU_LSS_TANGIER_SDIO0_01 1
22
23int board_early_init_r(void)
24{
25 pmu_turn_power(PMU_LSS_TANGIER_SDIO0_01, true);
26 return 0;
27}
28
Andy Shevchenkod31315d2017-07-06 14:41:53 +030029static struct dwc3_device dwc3_device_data = {
30 .maximum_speed = USB_SPEED_HIGH,
31 .base = CONFIG_SYS_USB_OTG_BASE,
32 .dr_mode = USB_DR_MODE_PERIPHERAL,
33 .index = 0,
34};
35
36int usb_gadget_handle_interrupts(int controller_index)
37{
38 dwc3_uboot_handle_interrupt(controller_index);
39 WATCHDOG_RESET();
40 return 0;
41}
42
43int board_usb_init(int index, enum usb_init_type init)
44{
45 if (index == 0 && init == USB_INIT_DEVICE)
46 return dwc3_uboot_init(&dwc3_device_data);
47 return -EINVAL;
48}
49
50int board_usb_cleanup(int index, enum usb_init_type init)
51{
52 if (index == 0 && init == USB_INIT_DEVICE) {
53 dwc3_uboot_exit(index);
54 return 0;
55 }
56 return -EINVAL;
57}
58
59static void assign_serial(void)
60{
61 struct mmc *mmc = find_mmc_device(0);
62 unsigned char ssn[16];
63 char usb0addr[18];
64 char serial[33];
65 int i;
66
67 if (!mmc)
68 return;
69
70 md5((unsigned char *)mmc->cid, sizeof(mmc->cid), ssn);
71
72 snprintf(usb0addr, sizeof(usb0addr), "02:00:86:%02x:%02x:%02x",
73 ssn[13], ssn[14], ssn[15]);
Simon Glass6a38e412017-08-03 12:22:09 -060074 env_set("usb0addr", usb0addr);
Andy Shevchenkod31315d2017-07-06 14:41:53 +030075
76 for (i = 0; i < 16; i++)
77 snprintf(&serial[2 * i], 3, "%02x", ssn[i]);
Simon Glass6a38e412017-08-03 12:22:09 -060078 env_set("serial#", serial);
Andy Shevchenkod31315d2017-07-06 14:41:53 +030079
80#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
Simon Glassd49b8892017-08-03 12:22:08 -060081 env_save();
Andy Shevchenkod31315d2017-07-06 14:41:53 +030082#endif
83}
84
85static void assign_hardware_id(void)
86{
87 struct ipc_ifwi_version v;
88 char hardware_id[4];
89 int ret;
90
91 ret = scu_ipc_command(IPCMSG_GET_FW_REVISION, 1, NULL, 0, (u32 *)&v, 4);
92 if (ret < 0)
93 printf("Can't retrieve hardware revision\n");
94
95 snprintf(hardware_id, sizeof(hardware_id), "%02X", v.hardware_id);
Simon Glass6a38e412017-08-03 12:22:09 -060096 env_set("hardware_id", hardware_id);
Andy Shevchenkod31315d2017-07-06 14:41:53 +030097
98#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
Simon Glassd49b8892017-08-03 12:22:08 -060099 env_save();
Andy Shevchenkod31315d2017-07-06 14:41:53 +0300100#endif
101}
102
103int board_late_init(void)
104{
Simon Glass64b723f2017-08-03 12:22:12 -0600105 if (!env_get("serial#"))
Andy Shevchenkod31315d2017-07-06 14:41:53 +0300106 assign_serial();
107
Simon Glass64b723f2017-08-03 12:22:12 -0600108 if (!env_get("hardware_id"))
Andy Shevchenkod31315d2017-07-06 14:41:53 +0300109 assign_hardware_id();
110
111 return 0;
112}