2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-07-06 11:41:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
|
|
|
#include <dwc3-uboot.h>
|
2017-08-03 18:22:08 +00:00
|
|
|
#include <environment.h>
|
2017-07-06 11:41:53 +00:00
|
|
|
#include <mmc.h>
|
|
|
|
#include <u-boot/md5.h>
|
|
|
|
#include <usb.h>
|
|
|
|
#include <watchdog.h>
|
|
|
|
|
|
|
|
#include <linux/usb/gadget.h>
|
|
|
|
|
|
|
|
#include <asm/cache.h>
|
2019-06-25 20:52:04 +00:00
|
|
|
#include <asm/pmu.h>
|
2017-07-06 11:41:53 +00:00
|
|
|
#include <asm/scu.h>
|
|
|
|
#include <asm/u-boot-x86.h>
|
|
|
|
|
2019-06-25 20:52:04 +00:00
|
|
|
/* List of Intel Tangier LSSs */
|
|
|
|
#define PMU_LSS_TANGIER_SDIO0_01 1
|
|
|
|
|
|
|
|
int board_early_init_r(void)
|
|
|
|
{
|
|
|
|
pmu_turn_power(PMU_LSS_TANGIER_SDIO0_01, true);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-06 11:41:53 +00:00
|
|
|
static struct dwc3_device dwc3_device_data = {
|
|
|
|
.maximum_speed = USB_SPEED_HIGH,
|
|
|
|
.base = CONFIG_SYS_USB_OTG_BASE,
|
|
|
|
.dr_mode = USB_DR_MODE_PERIPHERAL,
|
|
|
|
.index = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
int usb_gadget_handle_interrupts(int controller_index)
|
|
|
|
{
|
|
|
|
dwc3_uboot_handle_interrupt(controller_index);
|
|
|
|
WATCHDOG_RESET();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_usb_init(int index, enum usb_init_type init)
|
|
|
|
{
|
|
|
|
if (index == 0 && init == USB_INIT_DEVICE)
|
|
|
|
return dwc3_uboot_init(&dwc3_device_data);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_usb_cleanup(int index, enum usb_init_type init)
|
|
|
|
{
|
|
|
|
if (index == 0 && init == USB_INIT_DEVICE) {
|
|
|
|
dwc3_uboot_exit(index);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void assign_serial(void)
|
|
|
|
{
|
|
|
|
struct mmc *mmc = find_mmc_device(0);
|
|
|
|
unsigned char ssn[16];
|
|
|
|
char usb0addr[18];
|
|
|
|
char serial[33];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!mmc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
md5((unsigned char *)mmc->cid, sizeof(mmc->cid), ssn);
|
|
|
|
|
|
|
|
snprintf(usb0addr, sizeof(usb0addr), "02:00:86:%02x:%02x:%02x",
|
|
|
|
ssn[13], ssn[14], ssn[15]);
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set("usb0addr", usb0addr);
|
2017-07-06 11:41:53 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
snprintf(&serial[2 * i], 3, "%02x", ssn[i]);
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set("serial#", serial);
|
2017-07-06 11:41:53 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
|
2017-08-03 18:22:08 +00:00
|
|
|
env_save();
|
2017-07-06 11:41:53 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void assign_hardware_id(void)
|
|
|
|
{
|
|
|
|
struct ipc_ifwi_version v;
|
|
|
|
char hardware_id[4];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = scu_ipc_command(IPCMSG_GET_FW_REVISION, 1, NULL, 0, (u32 *)&v, 4);
|
|
|
|
if (ret < 0)
|
|
|
|
printf("Can't retrieve hardware revision\n");
|
|
|
|
|
|
|
|
snprintf(hardware_id, sizeof(hardware_id), "%02X", v.hardware_id);
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set("hardware_id", hardware_id);
|
2017-07-06 11:41:53 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
|
2017-08-03 18:22:08 +00:00
|
|
|
env_save();
|
2017-07-06 11:41:53 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_late_init(void)
|
|
|
|
{
|
2017-08-03 18:22:12 +00:00
|
|
|
if (!env_get("serial#"))
|
2017-07-06 11:41:53 +00:00
|
|
|
assign_serial();
|
|
|
|
|
2017-08-03 18:22:12 +00:00
|
|
|
if (!env_get("hardware_id"))
|
2017-07-06 11:41:53 +00:00
|
|
|
assign_hardware_id();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|