1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2017 Intel Corporation
6 #include <dwc3-uboot.h>
7 #include <environment.h>
9 #include <u-boot/md5.h>
13 #include <linux/usb/gadget.h>
15 #include <asm/cache.h>
17 #include <asm/u-boot-x86.h>
19 static struct dwc3_device dwc3_device_data = {
20 .maximum_speed = USB_SPEED_HIGH,
21 .base = CONFIG_SYS_USB_OTG_BASE,
22 .dr_mode = USB_DR_MODE_PERIPHERAL,
26 int usb_gadget_handle_interrupts(int controller_index)
28 dwc3_uboot_handle_interrupt(controller_index);
33 int board_usb_init(int index, enum usb_init_type init)
35 if (index == 0 && init == USB_INIT_DEVICE)
36 return dwc3_uboot_init(&dwc3_device_data);
40 int board_usb_cleanup(int index, enum usb_init_type init)
42 if (index == 0 && init == USB_INIT_DEVICE) {
43 dwc3_uboot_exit(index);
49 static void assign_serial(void)
51 struct mmc *mmc = find_mmc_device(0);
52 unsigned char ssn[16];
60 md5((unsigned char *)mmc->cid, sizeof(mmc->cid), ssn);
62 snprintf(usb0addr, sizeof(usb0addr), "02:00:86:%02x:%02x:%02x",
63 ssn[13], ssn[14], ssn[15]);
64 env_set("usb0addr", usb0addr);
66 for (i = 0; i < 16; i++)
67 snprintf(&serial[2 * i], 3, "%02x", ssn[i]);
68 env_set("serial#", serial);
70 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
75 static void assign_hardware_id(void)
77 struct ipc_ifwi_version v;
81 ret = scu_ipc_command(IPCMSG_GET_FW_REVISION, 1, NULL, 0, (u32 *)&v, 4);
83 printf("Can't retrieve hardware revision\n");
85 snprintf(hardware_id, sizeof(hardware_id), "%02X", v.hardware_id);
86 env_set("hardware_id", hardware_id);
88 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
93 int board_late_init(void)
95 if (!env_get("serial#"))
98 if (!env_get("hardware_id"))