1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2016 Rockchip Electronics Co., Ltd
12 #include <asm/arch-rockchip/boot_mode.h>
13 #include <dm/device.h>
14 #include <dm/uclass.h>
16 #if (CONFIG_ROCKCHIP_BOOT_MODE_REG == 0)
18 int setup_boot_mode(void)
25 void set_back_to_bootrom_dnl_flag(void)
27 writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);
31 * detect download key status by adc, most rockchip
32 * based boards use adc sample the download key status,
33 * but there are also some use gpio. So it's better to
34 * make this a weak function that can be override by
35 * some special boards.
37 #define KEY_DOWN_MIN_VAL 0
38 #define KEY_DOWN_MAX_VAL 30
40 __weak int rockchip_dnl_key_pressed(void)
47 ret = uclass_get(UCLASS_ADC, &uc);
52 uclass_foreach_dev(dev, uc) {
53 if (!strncmp(dev->name, "saradc", 6)) {
54 ret = adc_channel_single_shot(dev->name, 1, &val);
60 pr_warn("%s: no saradc device found\n", __func__);
63 pr_err("%s: adc_channel_single_shot fail!\n", __func__);
67 if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL))
73 void rockchip_dnl_mode_check(void)
75 if (rockchip_dnl_key_pressed()) {
76 printf("download key pressed, entering download mode...");
77 set_back_to_bootrom_dnl_flag();
78 do_reset(NULL, 0, 0, NULL);
82 int setup_boot_mode(void)
84 void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;
85 int boot_mode = readl(reg);
87 rockchip_dnl_mode_check();
89 boot_mode = readl(reg);
90 debug("%s: boot mode 0x%08x\n", __func__, boot_mode);
93 writel(BOOT_NORMAL, reg);
97 debug("%s: enter fastboot!\n", __func__);
98 env_set("preboot", "setenv preboot; fastboot usb0");
101 debug("%s: enter UMS!\n", __func__);
102 env_set("preboot", "setenv preboot; ums mmc 0");