2 * (C) Copyright 2016 Rockchip Electronics Co., Ltd
4 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/arch/boot_mode.h>
12 #if (CONFIG_ROCKCHIP_BOOT_MODE_REG == 0)
14 int setup_boot_mode(void)
21 void set_back_to_bootrom_dnl_flag(void)
23 writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);
27 * detect download key status by adc, most rockchip
28 * based boards use adc sample the download key status,
29 * but there are also some use gpio. So it's better to
30 * make this a weak function that can be override by
31 * some special boards.
33 #define KEY_DOWN_MIN_VAL 0
34 #define KEY_DOWN_MAX_VAL 30
36 __weak int rockchip_dnl_key_pressed(void)
40 if (adc_channel_single_shot("saradc", 1, &val)) {
41 pr_err("%s: adc_channel_single_shot fail!\n", __func__);
45 if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL))
51 void rockchip_dnl_mode_check(void)
53 if (rockchip_dnl_key_pressed()) {
54 printf("download key pressed, entering download mode...");
55 set_back_to_bootrom_dnl_flag();
56 do_reset(NULL, 0, 0, NULL);
60 int setup_boot_mode(void)
62 void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;
63 int boot_mode = readl(reg);
65 rockchip_dnl_mode_check();
67 boot_mode = readl(reg);
68 debug("%s: boot mode 0x%08x\n", __func__, boot_mode);
71 writel(BOOT_NORMAL, reg);
75 debug("%s: enter fastboot!\n", __func__);
76 env_set("preboot", "setenv preboot; fastboot usb0");
79 debug("%s: enter UMS!\n", __func__);
80 env_set("preboot", "setenv preboot; ums mmc 0");