Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2017 Intel Corporation |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 4 | */ |
| 5 | #include <common.h> |
| 6 | #include <dwc3-uboot.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame^] | 7 | #include <env.h> |
Simon Glass | d49b889 | 2017-08-03 12:22:08 -0600 | [diff] [blame] | 8 | #include <environment.h> |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 9 | #include <mmc.h> |
| 10 | #include <u-boot/md5.h> |
| 11 | #include <usb.h> |
| 12 | #include <watchdog.h> |
| 13 | |
| 14 | #include <linux/usb/gadget.h> |
| 15 | |
| 16 | #include <asm/cache.h> |
Andy Shevchenko | 5ea5c95 | 2019-06-25 23:52:04 +0300 | [diff] [blame] | 17 | #include <asm/pmu.h> |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 18 | #include <asm/scu.h> |
| 19 | #include <asm/u-boot-x86.h> |
| 20 | |
Andy Shevchenko | 5ea5c95 | 2019-06-25 23:52:04 +0300 | [diff] [blame] | 21 | /* List of Intel Tangier LSSs */ |
| 22 | #define PMU_LSS_TANGIER_SDIO0_01 1 |
| 23 | |
| 24 | int board_early_init_r(void) |
| 25 | { |
| 26 | pmu_turn_power(PMU_LSS_TANGIER_SDIO0_01, true); |
| 27 | return 0; |
| 28 | } |
| 29 | |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 30 | static struct dwc3_device dwc3_device_data = { |
| 31 | .maximum_speed = USB_SPEED_HIGH, |
| 32 | .base = CONFIG_SYS_USB_OTG_BASE, |
| 33 | .dr_mode = USB_DR_MODE_PERIPHERAL, |
| 34 | .index = 0, |
| 35 | }; |
| 36 | |
| 37 | int usb_gadget_handle_interrupts(int controller_index) |
| 38 | { |
| 39 | dwc3_uboot_handle_interrupt(controller_index); |
| 40 | WATCHDOG_RESET(); |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | int board_usb_init(int index, enum usb_init_type init) |
| 45 | { |
| 46 | if (index == 0 && init == USB_INIT_DEVICE) |
| 47 | return dwc3_uboot_init(&dwc3_device_data); |
| 48 | return -EINVAL; |
| 49 | } |
| 50 | |
| 51 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 52 | { |
| 53 | if (index == 0 && init == USB_INIT_DEVICE) { |
| 54 | dwc3_uboot_exit(index); |
| 55 | return 0; |
| 56 | } |
| 57 | return -EINVAL; |
| 58 | } |
| 59 | |
| 60 | static void assign_serial(void) |
| 61 | { |
| 62 | struct mmc *mmc = find_mmc_device(0); |
| 63 | unsigned char ssn[16]; |
| 64 | char usb0addr[18]; |
| 65 | char serial[33]; |
| 66 | int i; |
| 67 | |
| 68 | if (!mmc) |
| 69 | return; |
| 70 | |
| 71 | md5((unsigned char *)mmc->cid, sizeof(mmc->cid), ssn); |
| 72 | |
| 73 | snprintf(usb0addr, sizeof(usb0addr), "02:00:86:%02x:%02x:%02x", |
| 74 | ssn[13], ssn[14], ssn[15]); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 75 | env_set("usb0addr", usb0addr); |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 76 | |
| 77 | for (i = 0; i < 16; i++) |
| 78 | snprintf(&serial[2 * i], 3, "%02x", ssn[i]); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 79 | env_set("serial#", serial); |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 80 | |
| 81 | #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) |
Simon Glass | d49b889 | 2017-08-03 12:22:08 -0600 | [diff] [blame] | 82 | env_save(); |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 83 | #endif |
| 84 | } |
| 85 | |
| 86 | static void assign_hardware_id(void) |
| 87 | { |
| 88 | struct ipc_ifwi_version v; |
| 89 | char hardware_id[4]; |
| 90 | int ret; |
| 91 | |
| 92 | ret = scu_ipc_command(IPCMSG_GET_FW_REVISION, 1, NULL, 0, (u32 *)&v, 4); |
| 93 | if (ret < 0) |
| 94 | printf("Can't retrieve hardware revision\n"); |
| 95 | |
| 96 | snprintf(hardware_id, sizeof(hardware_id), "%02X", v.hardware_id); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 97 | env_set("hardware_id", hardware_id); |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 98 | |
| 99 | #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE) |
Simon Glass | d49b889 | 2017-08-03 12:22:08 -0600 | [diff] [blame] | 100 | env_save(); |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 101 | #endif |
| 102 | } |
| 103 | |
| 104 | int board_late_init(void) |
| 105 | { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 106 | if (!env_get("serial#")) |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 107 | assign_serial(); |
| 108 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 109 | if (!env_get("hardware_id")) |
Andy Shevchenko | d31315d | 2017-07-06 14:41:53 +0300 | [diff] [blame] | 110 | assign_hardware_id(); |
| 111 | |
| 112 | return 0; |
| 113 | } |