Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Andy Yan | e306779 | 2017-10-11 15:00:16 +0800 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 Rockchip Electronics Co., Ltd |
Andy Yan | e306779 | 2017-10-11 15:00:16 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Andy Yan | ecb103b | 2017-10-11 15:01:31 +0800 | [diff] [blame] | 7 | #include <adc.h> |
Andy Yan | e306779 | 2017-10-11 15:00:16 +0800 | [diff] [blame] | 8 | #include <asm/io.h> |
Kever Yang | 15f09a1 | 2019-03-28 11:01:23 +0800 | [diff] [blame^] | 9 | #include <asm/arch-rockchip/boot_mode.h> |
Andy Yan | e306779 | 2017-10-11 15:00:16 +0800 | [diff] [blame] | 10 | |
Philipp Tomsich | f07d76c | 2017-11-24 14:44:58 +0100 | [diff] [blame] | 11 | #if (CONFIG_ROCKCHIP_BOOT_MODE_REG == 0) |
| 12 | |
| 13 | int setup_boot_mode(void) |
| 14 | { |
| 15 | return 0; |
| 16 | } |
| 17 | |
| 18 | #else |
| 19 | |
Andy Yan | ecb103b | 2017-10-11 15:01:31 +0800 | [diff] [blame] | 20 | void set_back_to_bootrom_dnl_flag(void) |
| 21 | { |
| 22 | writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG); |
| 23 | } |
| 24 | |
| 25 | /* |
| 26 | * detect download key status by adc, most rockchip |
| 27 | * based boards use adc sample the download key status, |
| 28 | * but there are also some use gpio. So it's better to |
| 29 | * make this a weak function that can be override by |
| 30 | * some special boards. |
| 31 | */ |
| 32 | #define KEY_DOWN_MIN_VAL 0 |
| 33 | #define KEY_DOWN_MAX_VAL 30 |
| 34 | |
| 35 | __weak int rockchip_dnl_key_pressed(void) |
| 36 | { |
| 37 | unsigned int val; |
| 38 | |
| 39 | if (adc_channel_single_shot("saradc", 1, &val)) { |
| 40 | pr_err("%s: adc_channel_single_shot fail!\n", __func__); |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL)) |
| 45 | return true; |
| 46 | else |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | void rockchip_dnl_mode_check(void) |
| 51 | { |
| 52 | if (rockchip_dnl_key_pressed()) { |
| 53 | printf("download key pressed, entering download mode..."); |
| 54 | set_back_to_bootrom_dnl_flag(); |
| 55 | do_reset(NULL, 0, 0, NULL); |
| 56 | } |
| 57 | } |
| 58 | |
Andy Yan | e306779 | 2017-10-11 15:00:16 +0800 | [diff] [blame] | 59 | int setup_boot_mode(void) |
| 60 | { |
| 61 | void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG; |
| 62 | int boot_mode = readl(reg); |
| 63 | |
Philipp Tomsich | a2893ba | 2019-03-29 09:21:13 +0100 | [diff] [blame] | 64 | rockchip_dnl_mode_check(); |
Andy Yan | ecb103b | 2017-10-11 15:01:31 +0800 | [diff] [blame] | 65 | |
| 66 | boot_mode = readl(reg); |
| 67 | debug("%s: boot mode 0x%08x\n", __func__, boot_mode); |
Andy Yan | e306779 | 2017-10-11 15:00:16 +0800 | [diff] [blame] | 68 | |
| 69 | /* Clear boot mode */ |
| 70 | writel(BOOT_NORMAL, reg); |
| 71 | |
| 72 | switch (boot_mode) { |
| 73 | case BOOT_FASTBOOT: |
Andy Yan | ecb103b | 2017-10-11 15:01:31 +0800 | [diff] [blame] | 74 | debug("%s: enter fastboot!\n", __func__); |
Andy Yan | e306779 | 2017-10-11 15:00:16 +0800 | [diff] [blame] | 75 | env_set("preboot", "setenv preboot; fastboot usb0"); |
| 76 | break; |
| 77 | case BOOT_UMS: |
Andy Yan | ecb103b | 2017-10-11 15:01:31 +0800 | [diff] [blame] | 78 | debug("%s: enter UMS!\n", __func__); |
Andy Yan | e306779 | 2017-10-11 15:00:16 +0800 | [diff] [blame] | 79 | env_set("preboot", "setenv preboot; ums mmc 0"); |
| 80 | break; |
| 81 | } |
| 82 | |
| 83 | return 0; |
| 84 | } |
Philipp Tomsich | f07d76c | 2017-11-24 14:44:58 +0100 | [diff] [blame] | 85 | |
| 86 | #endif |