4 #include <linux/types.h>
5 #include <linux/keypad.h>
6 #include <linux/key_code.h>
8 #include <android_bootimg.h>
9 #include <asm/arch/gpio.h>
10 #include "tizen_misc.h"
12 #define COMMAND_MAX 128
16 #define DBG(fmt...) printf(fmt)
21 extern int power_button_pressed(void);
22 extern int charger_connected(void);
23 extern int alarm_triggered(void);
24 extern int cali_file_check(void);
25 extern int get_mode_from_gpio();
26 unsigned check_reboot_mode(void);
27 //extern void CHG_LateInit(void);
28 //extern void CHG_LowBatChg(void);
31 int boot_pwr_check(void)
33 static int total_cnt = 0;
34 if(!power_button_pressed())
38 #define mdelay(_ms) udelay(_ms*1000)
40 extern CBOOT_FUNC s_boot_func_array[CHECK_BOOTMODE_FUN_NUM] ;
42 static unsigned _reboot_mode_check(void)
44 static unsigned rst_mode = 0, check_times=0;
47 rst_mode = check_reboot_mode();
50 DBG("_reboot_mode_check rst_mode=0x%x\n",rst_mode);
55 // 0 get mode from calibration detect
56 boot_mode_enum_type get_mode_from_pctool (void){
58 if(cali_file_check() && !boot_pwr_check())
60 ret = pctool_mode_detect();
69 #ifndef CONFIG_MACH_CORI
70 #if !defined(CONFIG_KANAS_W) && !defined(CONFIG_KANAS_TD)
71 boot_mode_enum_type get_mode_from_bat_low (void){
73 if(charger_connected()) {
74 DBG("cboot:low battery,charging...\n");
78 DBG("cboot:low battery and shutdown\n");
79 return CMD_POWER_DOWN_DEVICE;
82 if(charger_connected()){
90 #ifdef CONFIG_SPRD_SYSDUMP
91 boot_mode_enum_type write_sysdump_before_boot_extend (void){
92 unsigned rst_mode = _reboot_mode_check();
93 write_sysdump_before_boot(rst_mode);
98 // 1 get mode from file
99 boot_mode_enum_type get_mode_from_file_extend (void){
100 switch(get_mode_from_file()){
102 DBG("cboot:get mode from file:recovery\n");
103 return CMD_RECOVERY_MODE;
110 // 2 get mode from watch dog
111 boot_mode_enum_type get_mode_from_watchdog (void){
112 unsigned rst_mode = _reboot_mode_check();
117 return CMD_RECOVERY_MODE;
119 return CMD_FASTBOOT_MODE;
121 return CMD_NORMAL_MODE;
122 case WATCHDOG_REBOOT:
123 return CMD_WATCHDOG_REBOOT;
124 case UNKNOW_REBOOT_MODE:
125 return CMD_UNKNOW_REBOOT_MODE;
127 return CMD_PANIC_REBOOT;
128 case AUTODLOADER_REBOOT:
129 return CMD_AUTODLOADER_REBOOT;
131 return CMD_SPECIAL_MODE;
132 case EXT_RSTN_REBOOT_MODE:
133 return CMD_NORMAL_MODE;
135 return CMD_IQ_REBOOT_MODE;
137 if((flag = alarm_flag_check())){
138 DBG("get_mode_from_watchdog flag=%d\n", flag);
140 return CMD_ALARM_MODE;
143 return CMD_NORMAL_MODE;
151 // 3 get mode from alarm register
152 boot_mode_enum_type get_mode_from_alarm_register(void){
155 if(alarm_triggered() && (flag = alarm_flag_check())){
156 DBG("get_mode_from_alarm_register flag=%d\n", flag);
158 return CMD_ALARM_MODE;
161 return CMD_NORMAL_MODE;
168 // 4 get mode from charger
169 boot_mode_enum_type get_mode_from_charger(void){
170 if(charger_connected()){
171 DBG("get mode from charger\n");
172 return CMD_CHARGE_MODE;
178 // 5 get mode from keypad
179 boot_mode_enum_type get_mode_from_keypad(void){
180 uint32_t key_mode = 0;
181 uint32_t key_code = 0;
184 if(boot_pwr_check() >= get_pwr_key_cnt()){
186 DBG("cboot:power key is down");
189 key_code = tizen_check_keypad();
191 key_code = board_key_scan();
193 DBG("cboot:key_scan times=%d\n",i);
194 if(key_code != KEY_RESERVED)
200 key_mode = check_key_boot(key_code);
201 DBG("cboot:get mode from keypad:0x%x\n",key_code);
204 return CMD_FASTBOOT_MODE;
206 return CMD_RECOVERY_MODE;
208 return CMD_ENGTEST_MODE;
209 case BOOT_FACTORYTEST:
210 return CMD_FACTORYTEST_MODE;
211 case BOOT_THOR_DOWNLOAD:
212 return CMD_THOR_MODE;
214 return CMD_NORMAL_MODE;
221 // 6 get mode from gpio
222 boot_mode_enum_type get_mode_from_gpio_extend(void){
223 if (get_mode_from_gpio()) {
224 DBG("pbint2 triggered, do normal mode\n");
225 return CMD_NORMAL_MODE;
232 extern int tizen_reboot_check(void);
235 int do_cboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
238 boot_mode_enum_type bootmode = CMD_NONE;
239 CBOOT_MODE_ENTRY boot_mode_array[20] ={0};
244 #ifdef CONFIG_AUTOBOOT
247 for (i=0; i<CHECK_BOOTMODE_FUN_NUM; i++){
248 if (0 != s_boot_func_array[i]){
249 DBG("cboot: i=%d\n", i);
250 bootmode = s_boot_func_array[i]();
251 if(CMD_NONE == bootmode){
259 // get mode from argument
261 DBG("cboot:get mode from argument:%s\n",argv[1]);
262 if(!strcmp(argv[1],"normal")){
263 bootmode = CMD_NORMAL_MODE;
266 if(!strcmp(argv[1],"recovery")){
267 bootmode = CMD_RECOVERY_MODE;
270 if(!strcmp(argv[1],"fastboot")){
271 bootmode = CMD_FASTBOOT_MODE;
274 if(!strcmp(argv[1],"charge")){
275 bootmode = CMD_CHARGE_MODE;
279 bootmode = CMD_POWER_DOWN_DEVICE;
284 DBG("do_cboot:boot mode is %d\n",bootmode);
287 if (bootmode == CMD_NONE || bootmode == CMD_CHARGE_MODE) {
288 if (bootmode == CMD_NONE)
289 bootmode = CMD_NORMAL_MODE;
290 if (tizen_reboot_check()) {
291 bootmode = CMD_THOR_MODE;
292 DBG("do_cboot:boot mode is %d\n",bootmode);
298 #ifdef CONFIG_LCD_LOGO
303 case CMD_NORMAL_MODE:
304 switch (check_pm_status()) {
308 case PM_STATE_NORMAL:
318 #endif /* CONFIG_LCD_LOGO */
320 cmd_mode_regist(boot_mode_array);
321 if((bootmode > CMD_POWER_DOWN_DEVICE) && (0 != boot_mode_array[bootmode])){
322 /* goto main_loop() if any input is hit from console */
325 DBG("do_cboot: enter boot mode\n");
326 boot_mode_array[bootmode]();
328 DBG("do_cboot: power down device\n");
329 power_down_devices();
339 cboot, CONFIG_SYS_MAXARGS, 1, do_cboot,
341 "mode: \nrecovery, fastboot, dloader, charge, normal, vlx, caliberation.\n"
342 "cboot could enter a mode specified by the mode descriptor.\n"
343 "it also could enter a proper mode automatically depending on "