xref: /rk3399_rockchip-uboot/arch/arm/mach-rockchip/hotkey.c (revision 1490eb89f4697b02cfb8f826d2f5eaf37edcbd47)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2019 Fuzhou Rockchip Electronics Co., Ltd
4  */
5 
6 #include <common.h>
7 #include <bidram.h>
8 #include <cli.h>
9 #include <console.h>
10 #include <sysmem.h>
11 #include <asm/arch/hotkey.h>
12 
13 DECLARE_GLOBAL_DATA_PTR;
14 
15 #define CTRL_B		0x02	/* bootrom mode */
16 #define CTRL_D		0x04	/* download mde */
17 #define CTRL_F		0x06	/* fastboot mode */
18 #define CTRL_I		0x09	/* inicall debug for kernel */
19 #define CTRL_M		0x0d	/* memory(sysmem/bidram) */
20 #define CTRL_P		0x10	/* parameter(cmdline) dump */
21 #define CTRL_S		0x13	/* shell(cli) */
22 
23 #if defined(CONFIG_CONSOLE_DISABLE_CTRLC) && \
24 	defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY <= 0)
25 bool is_hotkey(enum hotkey_t id) { return false; }
26 void hotkey_run(enum hotkey_t id) { }
27 #else
28 bool is_hotkey(enum hotkey_t id)
29 {
30 	switch (id) {
31 	case HK_BROM_DNL:
32 		return gd->console_evt == CTRL_B;
33 	case HK_CMDLINE:
34 		return gd->console_evt == CTRL_P;
35 	case HK_FASTBOOT:
36 		return gd->console_evt == CTRL_F;
37 	case HK_INITCALL:
38 		return gd->console_evt == CTRL_I;
39 	case HK_ROCKUSB_DNL:
40 		return gd->console_evt == CTRL_D;
41 	case HK_SYSMEM:
42 		return gd->console_evt == CTRL_M;
43 	default:
44 		break;
45 	}
46 
47 	return false;
48 }
49 
50 void hotkey_run(enum hotkey_t id)
51 {
52 	switch ((id)) {
53 	case HK_SYSMEM:
54 		if (gd->console_evt == CTRL_M) {
55 			bidram_dump();
56 			sysmem_dump();
57 		}
58 		break;
59 	case HK_CMDLINE:
60 		if (gd->console_evt == CTRL_P)
61 			printf("cmdline: %s\n", env_get("bootargs"));
62 		break;
63 	case HK_INITCALL:
64 		if (gd->console_evt == CTRL_I)
65 			env_update("bootargs", "initcall_debug debug");
66 		break;
67 	case HK_CLI:
68 		if (gd->console_evt == CTRL_S)
69 			cli_loop();
70 		break;
71 	default:
72 		break;
73 	}
74 }
75 #endif
76