2 * Copyright (c) 2017 Intel Corporation
4 * SPDX-License-Identifier: GPL-2.0+
7 #include <dwc3-uboot.h>
8 #include <environment.h>
10 #include <u-boot/md5.h>
14 #include <linux/usb/gadget.h>
16 #include <asm/cache.h>
18 #include <asm/u-boot-x86.h>
20 DECLARE_GLOBAL_DATA_PTR
;
22 static struct dwc3_device dwc3_device_data
= {
23 .maximum_speed
= USB_SPEED_HIGH
,
24 .base
= CONFIG_SYS_USB_OTG_BASE
,
25 .dr_mode
= USB_DR_MODE_PERIPHERAL
,
29 int usb_gadget_handle_interrupts(int controller_index
)
31 dwc3_uboot_handle_interrupt(controller_index
);
36 int board_usb_init(int index
, enum usb_init_type init
)
38 if (index
== 0 && init
== USB_INIT_DEVICE
)
39 return dwc3_uboot_init(&dwc3_device_data
);
43 int board_usb_cleanup(int index
, enum usb_init_type init
)
45 if (index
== 0 && init
== USB_INIT_DEVICE
) {
46 dwc3_uboot_exit(index
);
52 static void assign_serial(void)
54 struct mmc
*mmc
= find_mmc_device(0);
55 unsigned char ssn
[16];
63 md5((unsigned char *)mmc
->cid
, sizeof(mmc
->cid
), ssn
);
65 snprintf(usb0addr
, sizeof(usb0addr
), "02:00:86:%02x:%02x:%02x",
66 ssn
[13], ssn
[14], ssn
[15]);
67 setenv("usb0addr", usb0addr
);
69 for (i
= 0; i
< 16; i
++)
70 snprintf(&serial
[2 * i
], 3, "%02x", ssn
[i
]);
71 setenv("serial#", serial
);
73 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
78 static void assign_hardware_id(void)
80 struct ipc_ifwi_version v
;
84 ret
= scu_ipc_command(IPCMSG_GET_FW_REVISION
, 1, NULL
, 0, (u32
*)&v
, 4);
86 printf("Can't retrieve hardware revision\n");
88 snprintf(hardware_id
, sizeof(hardware_id
), "%02X", v
.hardware_id
);
89 setenv("hardware_id", hardware_id
);
91 #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
96 int board_late_init(void)
98 if (!getenv("serial#"))
101 if (!getenv("hardware_id"))
102 assign_hardware_id();