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(void);
26 extern unsigned check_reboot_mode(void);
27 extern int pctool_mode_detect(void);
28 extern unsigned int get_pwr_key_cnt(void);
30 boot_mode_enum_type tizen_check_keypad(void);
32 #ifdef CONFIG_LCD_LOGO
33 extern void draw_image(int mode);
34 extern void lcd_display(void);
35 extern void MMU_DisableIDCM(void);
37 extern void cmd_mode_regist(CBOOT_MODE_ENTRY *array);
38 extern void power_down_devices(unsigned pd_cmd);
39 //extern void CHG_LateInit(void);
40 //extern void CHG_LowBatChg(void);
43 int boot_pwr_check(void)
45 static int total_cnt = 0;
46 if(!power_button_pressed())
50 #define mdelay(_ms) udelay(_ms*1000)
52 extern CBOOT_FUNC s_boot_func_array[CHECK_BOOTMODE_FUN_NUM] ;
54 static unsigned _reboot_mode_check(void)
56 static unsigned rst_mode = 0, check_times=0;
59 rst_mode = check_reboot_mode();
62 DBG("_reboot_mode_check rst_mode=0x%x\n",rst_mode);
67 // 0 get mode from calibration detect
68 boot_mode_enum_type get_mode_from_pctool (void){
70 if(cali_file_check() && !boot_pwr_check())
72 ret = pctool_mode_detect();
81 #ifndef CONFIG_MACH_CORI
82 #if !defined(CONFIG_KANAS_W) && !defined(CONFIG_KANAS_TD)
83 boot_mode_enum_type get_mode_from_bat_low (void){
85 if(charger_connected()) {
86 DBG("cboot:low battery,charging...\n");
90 DBG("cboot:low battery and shutdown\n");
91 return CMD_POWER_DOWN_DEVICE;
94 if(charger_connected()){
102 #ifdef CONFIG_SPRD_SYSDUMP
103 boot_mode_enum_type write_sysdump_before_boot_extend (void){
104 unsigned rst_mode = _reboot_mode_check();
105 write_sysdump_before_boot(rst_mode);
110 // 1 get mode from file
111 boot_mode_enum_type get_mode_from_file_extend (void){
112 switch(get_mode_from_file()){
114 DBG("cboot:get mode from file:recovery\n");
115 return CMD_RECOVERY_MODE;
122 // 2 get mode from watch dog
123 boot_mode_enum_type get_mode_from_watchdog (void){
124 unsigned rst_mode = _reboot_mode_check();
129 return CMD_RECOVERY_MODE;
131 return CMD_FASTBOOT_MODE;
133 return CMD_NORMAL_MODE;
134 case WATCHDOG_REBOOT:
135 return CMD_WATCHDOG_REBOOT;
136 case UNKNOW_REBOOT_MODE:
137 return CMD_UNKNOW_REBOOT_MODE;
139 return CMD_PANIC_REBOOT;
140 case AUTODLOADER_REBOOT:
141 return CMD_AUTODLOADER_REBOOT;
143 return CMD_SPECIAL_MODE;
144 case EXT_RSTN_REBOOT_MODE:
145 return CMD_NORMAL_MODE;
147 return CMD_IQ_REBOOT_MODE;
149 if((flag = alarm_flag_check())){
150 DBG("get_mode_from_watchdog flag=%d\n", flag);
152 return CMD_ALARM_MODE;
155 return CMD_NORMAL_MODE;
163 // 3 get mode from alarm register
164 boot_mode_enum_type get_mode_from_alarm_register(void){
167 if(alarm_triggered() && (flag = alarm_flag_check())){
168 DBG("get_mode_from_alarm_register flag=%d\n", flag);
170 return CMD_ALARM_MODE;
173 return CMD_NORMAL_MODE;
182 // 4 get mode from charger
183 boot_mode_enum_type get_mode_from_charger(void){
184 if(charger_connected()){
185 DBG("get mode from charger\n");
186 return CMD_CHARGE_MODE;
192 // 5 get mode from keypad
193 boot_mode_enum_type get_mode_from_keypad(void){
194 uint32_t key_mode = 0;
195 uint32_t key_code = 0;
198 if(boot_pwr_check() >= get_pwr_key_cnt()){
200 DBG("cboot:power key is down");
203 key_code = tizen_check_keypad();
205 key_code = board_key_scan();
207 DBG("cboot:key_scan times=%d\n",i);
208 if(key_code != KEY_RESERVED)
214 key_mode = check_key_boot(key_code);
215 DBG("cboot:get mode from keypad:0x%x\n",key_code);
218 return CMD_FASTBOOT_MODE;
220 return CMD_RECOVERY_MODE;
222 return CMD_ENGTEST_MODE;
223 case BOOT_FACTORYTEST:
224 return CMD_FACTORYTEST_MODE;
225 case BOOT_THOR_DOWNLOAD:
226 return CMD_THOR_MODE;
228 return CMD_NORMAL_MODE;
235 // 6 get mode from gpio
236 boot_mode_enum_type get_mode_from_gpio_extend(void){
237 if (get_mode_from_gpio()) {
238 DBG("pbint2 triggered, do normal mode\n");
239 return CMD_NORMAL_MODE;
246 extern int tizen_reboot_check(void);
247 extern int tizen_reboot_recovery_check(void);
250 int do_cboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
253 boot_mode_enum_type bootmode = CMD_NONE;
254 CBOOT_MODE_ENTRY boot_mode_array[20] ={0};
259 #ifdef CONFIG_AUTOBOOT
262 for (i=0; i<CHECK_BOOTMODE_FUN_NUM; i++){
263 if (0 != s_boot_func_array[i]){
264 DBG("cboot: i=%d\n", i);
265 bootmode = s_boot_func_array[i]();
266 if(CMD_NONE == bootmode){
274 // get mode from argument
276 DBG("cboot:get mode from argument:%s\n",argv[1]);
277 if(!strcmp(argv[1],"normal")){
278 bootmode = CMD_NORMAL_MODE;
281 if(!strcmp(argv[1],"recovery")){
282 bootmode = CMD_RECOVERY_MODE;
285 if(!strcmp(argv[1],"fastboot")){
286 bootmode = CMD_FASTBOOT_MODE;
289 if(!strcmp(argv[1],"charge")){
290 bootmode = CMD_CHARGE_MODE;
294 bootmode = CMD_POWER_DOWN_DEVICE;
299 DBG("do_cboot:boot mode is %d\n",bootmode);
302 if (bootmode == CMD_NONE || bootmode == CMD_CHARGE_MODE) {
303 if (bootmode == CMD_NONE)
304 bootmode = CMD_NORMAL_MODE;
305 if (tizen_reboot_check()) {
306 bootmode = CMD_THOR_MODE;
307 DBG("do_cboot:boot mode is %d\n",bootmode);
308 } else if (tizen_reboot_recovery_check()) {
309 #ifdef CONFIG_RAMDISK_BOOT
310 bootmode = CMD_RECOVERY_MODE;
312 bootmode = CMD_NORMAL_MODE;
314 DBG("do_cboot:boot mode is %d\n",bootmode);
320 #ifdef CONFIG_LCD_LOGO
325 case CMD_NORMAL_MODE:
326 switch (check_pm_status()) {
330 case PM_STATE_NORMAL:
340 #endif /* CONFIG_LCD_LOGO */
342 cmd_mode_regist(boot_mode_array);
343 if((bootmode > CMD_POWER_DOWN_DEVICE) && (0 != boot_mode_array[bootmode])){
344 /* goto main_loop() if any input is hit from console */
347 DBG("do_cboot: enter boot mode\n");
348 boot_mode_array[bootmode]();
350 DBG("do_cboot: power down device\n");
351 power_down_devices(0);
361 cboot, CONFIG_SYS_MAXARGS, 1, do_cboot,
363 "mode: \nrecovery, fastboot, dloader, charge, normal, vlx, caliberation.\n"
364 "cboot could enter a mode specified by the mode descriptor.\n"
365 "it also could enter a proper mode automatically depending on "