1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2016 Rockchip Electronics Co., Ltd
9 #include <asm/arch-rockchip/boot_mode.h>
10 #include <dm/device.h>
11 #include <dm/uclass.h>
13 #if (CONFIG_ROCKCHIP_BOOT_MODE_REG == 0)
15 int setup_boot_mode(void)
22 void set_back_to_bootrom_dnl_flag(void)
24 writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);
28 * detect download key status by adc, most rockchip
29 * based boards use adc sample the download key status,
30 * but there are also some use gpio. So it's better to
31 * make this a weak function that can be override by
32 * some special boards.
34 #define KEY_DOWN_MIN_VAL 0
35 #define KEY_DOWN_MAX_VAL 30
37 __weak int rockchip_dnl_key_pressed(void)
44 ret = uclass_get(UCLASS_ADC, &uc);
49 uclass_foreach_dev(dev, uc) {
50 if (!strncmp(dev->name, "saradc", 6)) {
51 ret = adc_channel_single_shot(dev->name, 1, &val);
57 pr_warn("%s: no saradc device found\n", __func__);
60 pr_err("%s: adc_channel_single_shot fail!\n", __func__);
64 if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL))
70 void rockchip_dnl_mode_check(void)
72 if (rockchip_dnl_key_pressed()) {
73 printf("download key pressed, entering download mode...");
74 set_back_to_bootrom_dnl_flag();
75 do_reset(NULL, 0, 0, NULL);
79 int setup_boot_mode(void)
81 void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;
82 int boot_mode = readl(reg);
84 rockchip_dnl_mode_check();
86 boot_mode = readl(reg);
87 debug("%s: boot mode 0x%08x\n", __func__, boot_mode);
90 writel(BOOT_NORMAL, reg);
94 debug("%s: enter fastboot!\n", __func__);
95 env_set("preboot", "setenv preboot; fastboot usb0");
98 debug("%s: enter UMS!\n", __func__);
99 env_set("preboot", "setenv preboot; ums mmc 0");