2 * Copyright (c) 2017 Intel Corporation
4 * SPDX-License-Identifier: GPL-2.0+
7 #include <dwc3-uboot.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 DECLARE_GLOBAL_DATA_PTR;
21 static struct dwc3_device dwc3_device_data = {
22 .maximum_speed = USB_SPEED_HIGH,
23 .base = CONFIG_SYS_USB_OTG_BASE,
24 .dr_mode = USB_DR_MODE_PERIPHERAL,
28 int usb_gadget_handle_interrupts(int controller_index)
30 dwc3_uboot_handle_interrupt(controller_index);
35 int board_usb_init(int index, enum usb_init_type init)
37 if (index == 0 && init == USB_INIT_DEVICE)
38 return dwc3_uboot_init(&dwc3_device_data);
42 int board_usb_cleanup(int index, enum usb_init_type init)
44 if (index == 0 && init == USB_INIT_DEVICE) {
45 dwc3_uboot_exit(index);
51 static void assign_serial(void)
53 struct mmc *mmc = find_mmc_device(0);
54 unsigned char ssn[16];
62 md5((unsigned char *)mmc->cid, sizeof(mmc->cid), ssn);
64 snprintf(usb0addr, sizeof(usb0addr), "02:00:86:%02x:%02x:%02x",
65 ssn[13], ssn[14], ssn[15]);
66 setenv("usb0addr", usb0addr);
68 for (i = 0; i < 16; i++)
69 snprintf(&serial[2 * i], 3, "%02x", ssn[i]);
70 setenv("serial#", serial);
72 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
77 static void assign_hardware_id(void)
79 struct ipc_ifwi_version v;
83 ret = scu_ipc_command(IPCMSG_GET_FW_REVISION, 1, NULL, 0, (u32 *)&v, 4);
85 printf("Can't retrieve hardware revision\n");
87 snprintf(hardware_id, sizeof(hardware_id), "%02X", v.hardware_id);
88 setenv("hardware_id", hardware_id);
90 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
95 int board_late_init(void)
97 if (!getenv("serial#"))
100 if (!getenv("hardware_id"))
101 assign_hardware_id();