2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-10-11 07:00:16 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2016 Rockchip Electronics Co., Ltd
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2017-10-11 07:01:31 +00:00
|
|
|
#include <adc.h>
|
2020-05-10 17:40:03 +00:00
|
|
|
#include <command.h>
|
|
|
|
#include <env.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2017-10-11 07:00:16 +00:00
|
|
|
#include <asm/io.h>
|
2019-03-28 03:01:23 +00:00
|
|
|
#include <asm/arch-rockchip/boot_mode.h>
|
2020-01-25 16:19:36 +00:00
|
|
|
#include <dm/device.h>
|
|
|
|
#include <dm/uclass.h>
|
2017-10-11 07:00:16 +00:00
|
|
|
|
2017-11-24 13:44:58 +00:00
|
|
|
#if (CONFIG_ROCKCHIP_BOOT_MODE_REG == 0)
|
|
|
|
|
|
|
|
int setup_boot_mode(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2017-10-11 07:01:31 +00:00
|
|
|
void set_back_to_bootrom_dnl_flag(void)
|
|
|
|
{
|
|
|
|
writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* detect download key status by adc, most rockchip
|
|
|
|
* based boards use adc sample the download key status,
|
|
|
|
* but there are also some use gpio. So it's better to
|
|
|
|
* make this a weak function that can be override by
|
|
|
|
* some special boards.
|
|
|
|
*/
|
|
|
|
#define KEY_DOWN_MIN_VAL 0
|
|
|
|
#define KEY_DOWN_MAX_VAL 30
|
|
|
|
|
|
|
|
__weak int rockchip_dnl_key_pressed(void)
|
|
|
|
{
|
|
|
|
unsigned int val;
|
2020-01-25 16:19:36 +00:00
|
|
|
struct udevice *dev;
|
|
|
|
struct uclass *uc;
|
|
|
|
int ret;
|
2017-10-11 07:01:31 +00:00
|
|
|
|
2020-01-25 16:19:36 +00:00
|
|
|
ret = uclass_get(UCLASS_ADC, &uc);
|
|
|
|
if (ret)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ret = -ENODEV;
|
|
|
|
uclass_foreach_dev(dev, uc) {
|
|
|
|
if (!strncmp(dev->name, "saradc", 6)) {
|
|
|
|
ret = adc_channel_single_shot(dev->name, 1, &val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == -ENODEV) {
|
|
|
|
pr_warn("%s: no saradc device found\n", __func__);
|
|
|
|
return false;
|
|
|
|
} else if (ret) {
|
2017-10-11 07:01:31 +00:00
|
|
|
pr_err("%s: adc_channel_single_shot fail!\n", __func__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL))
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rockchip_dnl_mode_check(void)
|
|
|
|
{
|
|
|
|
if (rockchip_dnl_key_pressed()) {
|
|
|
|
printf("download key pressed, entering download mode...");
|
|
|
|
set_back_to_bootrom_dnl_flag();
|
|
|
|
do_reset(NULL, 0, 0, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-11 07:00:16 +00:00
|
|
|
int setup_boot_mode(void)
|
|
|
|
{
|
|
|
|
void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;
|
|
|
|
int boot_mode = readl(reg);
|
|
|
|
|
2019-03-29 08:21:13 +00:00
|
|
|
rockchip_dnl_mode_check();
|
2017-10-11 07:01:31 +00:00
|
|
|
|
|
|
|
boot_mode = readl(reg);
|
|
|
|
debug("%s: boot mode 0x%08x\n", __func__, boot_mode);
|
2017-10-11 07:00:16 +00:00
|
|
|
|
|
|
|
/* Clear boot mode */
|
|
|
|
writel(BOOT_NORMAL, reg);
|
|
|
|
|
|
|
|
switch (boot_mode) {
|
|
|
|
case BOOT_FASTBOOT:
|
2017-10-11 07:01:31 +00:00
|
|
|
debug("%s: enter fastboot!\n", __func__);
|
2017-10-11 07:00:16 +00:00
|
|
|
env_set("preboot", "setenv preboot; fastboot usb0");
|
|
|
|
break;
|
|
|
|
case BOOT_UMS:
|
2017-10-11 07:01:31 +00:00
|
|
|
debug("%s: enter UMS!\n", __func__);
|
2017-10-11 07:00:16 +00:00
|
|
|
env_set("preboot", "setenv preboot; ums mmc 0");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2017-11-24 13:44:58 +00:00
|
|
|
|
|
|
|
#endif
|