| // SPDX-License-Identifier: GPL-2.0 |
| /* |
| * Copyright (C) 2019 BayLibre SAS |
| */ |
| |
| #include <common.h> |
| #include <dm.h> |
| #include <mmc.h> |
| #include "../../../drivers/watchdog/mtk_wdt.h" |
| |
| #define WDT_DRIVER_NAME "mtk_wdt" |
| #define REBOOT_BOOTLOADER_VALUE (1) |
| #define REBOOT_BOOTLOADER_MASK (1) |
| #define REBOOT_BOOTLOADER_SHIFT (2) |
| |
| int fastboot_set_reboot_flag(void) { |
| struct udevice *dev; |
| struct uclass *uc; |
| int ret = -ENOSYS; |
| |
| ret = uclass_get(UCLASS_WDT, &uc); |
| if (ret) |
| return -ENOSYS; |
| |
| uclass_foreach_dev(dev, uc) { |
| if (strncmp(dev->driver->name, WDT_DRIVER_NAME, strlen(WDT_DRIVER_NAME)) == 0) { |
| mtk_wdt_set_nonrst2(dev, REBOOT_BOOTLOADER_MASK << REBOOT_BOOTLOADER_SHIFT, |
| REBOOT_BOOTLOADER_VALUE << REBOOT_BOOTLOADER_SHIFT); |
| return 0; |
| } |
| } |
| |
| return -ENOSYS; |
| } |
| |
| int misc_init_r(void) { |
| int ret; |
| struct udevice *dev; |
| struct uclass *uc; |
| struct mmc *mmc; |
| int reg_val; |
| int mmc_dev = 0; |
| |
| ret = uclass_get(UCLASS_WDT, &uc); |
| if (ret) |
| return -ENOSYS; |
| |
| uclass_foreach_dev(dev, uc) { |
| if (strncmp(dev->driver->name, WDT_DRIVER_NAME, strlen(WDT_DRIVER_NAME)) == 0) { |
| reg_val = mtk_wdt_get_nonrst2(dev); |
| if (reg_val & (REBOOT_BOOTLOADER_VALUE << REBOOT_BOOTLOADER_SHIFT)) { |
| env_set("force_fastboot", "1"); |
| mtk_wdt_set_nonrst2(dev, REBOOT_BOOTLOADER_MASK << REBOOT_BOOTLOADER_SHIFT, 0); |
| } |
| } |
| } |
| |
| env_set("serial#", "0123456789ABCDEF"); |
| |
| mmc = find_mmc_device(mmc_dev); |
| if (mmc) { |
| if (!mmc_init(mmc) && mmc->capacity >= 7000000000) { |
| printf("EVT2 detected\n"); |
| env_set("evt2_board", "1"); |
| } |
| } |
| |
| return 0; |
| } |
| |
| int board_init(void) |
| { |
| struct udevice *dev; |
| |
| uclass_first_device_err(UCLASS_USB_GADGET_GENERIC, &dev); |
| |
| #ifdef CONFIG_USB_ETHER |
| usb_ether_init(); |
| #endif |
| |
| return 0; |
| } |