1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2016 Rockchip Electronics Co., Ltd
11 #include <asm/arch-rockchip/boot_mode.h>
12 #include <dm/device.h>
13 #include <dm/uclass.h>
15 #if (CONFIG_ROCKCHIP_BOOT_MODE_REG == 0)
17 int setup_boot_mode(void)
24 void set_back_to_bootrom_dnl_flag(void)
26 writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);
30 * detect download key status by adc, most rockchip
31 * based boards use adc sample the download key status,
32 * but there are also some use gpio. So it's better to
33 * make this a weak function that can be override by
34 * some special boards.
36 #define KEY_DOWN_MIN_VAL 0
37 #define KEY_DOWN_MAX_VAL 30
39 __weak int rockchip_dnl_key_pressed(void)
46 ret = uclass_get(UCLASS_ADC, &uc);
51 uclass_foreach_dev(dev, uc) {
52 if (!strncmp(dev->name, "saradc", 6)) {
53 ret = adc_channel_single_shot(dev->name, 1, &val);
59 pr_warn("%s: no saradc device found\n", __func__);
62 pr_err("%s: adc_channel_single_shot fail!\n", __func__);
66 if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL))
72 void rockchip_dnl_mode_check(void)
74 if (rockchip_dnl_key_pressed()) {
75 printf("download key pressed, entering download mode...");
76 set_back_to_bootrom_dnl_flag();
77 do_reset(NULL, 0, 0, NULL);
81 int setup_boot_mode(void)
83 void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;
84 int boot_mode = readl(reg);
86 rockchip_dnl_mode_check();
88 boot_mode = readl(reg);
89 debug("%s: boot mode 0x%08x\n", __func__, boot_mode);
92 writel(BOOT_NORMAL, reg);
96 debug("%s: enter fastboot!\n", __func__);
97 env_set("preboot", "setenv preboot; fastboot usb0");
100 debug("%s: enter UMS!\n", __func__);
101 env_set("preboot", "setenv preboot; ums mmc 0");