tizen 2.4 release
[kernel/u-boot-tm1.git] / arch / arm / cpu / armv7 / sc8810 / check_reboot.c
1 #include <asm/arch/sci_types.h>
2 #include <asm/arch/sc_reg.h>
3 #include <asm/arch/adi_hal_internal.h>
4 #include <boot_mode.h>
5 #include <asm/arch/gpio.h>
6 #include <asm/arch/asm_generic_gpio.h>
7 #include <asm/arch/gpio_phy.h>
8 #include <asm/arch/rtc_reg_v3.h>
9 #include <asm/arch/mfp.h>
10
11 unsigned check_reboot_mode(void)
12 {
13         unsigned rst_mode= 0;
14
15         rst_mode = ANA_REG_GET(ANA_HWRST_STATUS);
16         rst_mode &= HWRST_STATUS_POWERON_MASK;
17         ANA_REG_SET(ANA_HWRST_STATUS, 0); //clear flag
18         if(rst_mode == HWRST_STATUS_RECOVERY)
19                 return RECOVERY_MODE;
20         else if(rst_mode == HWRST_STATUS_FASTBOOT)
21                 return FASTBOOT_MODE;
22         else if(rst_mode == HWRST_STATUS_NORMAL)
23                 return NORMAL_MODE;
24         else if(rst_mode == HWRST_STATUS_NORMAL2)
25                 return WATCHDOG_REBOOT;
26         else if(rst_mode == HWRST_STATUS_ALARM)
27                 return ALARM_MODE;
28         else if(rst_mode == HWRST_STATUS_SLEEP)
29                 return SLEEP_MODE;
30         else if(rst_mode == HWRST_STATUS_SPECIAL)
31                 return SPECIAL_MODE;
32         else if(rst_mode == HWRST_STATUS_PANIC)
33                 return PANIC_REBOOT;
34         else
35                 return 0;
36 }
37
38 void reboot_devices(unsigned reboot_mode)
39 {
40     unsigned rst_mode = 0;
41     if(reboot_mode == RECOVERY_MODE){
42       rst_mode = HWRST_STATUS_RECOVERY;
43     }
44     else if(reboot_mode == FASTBOOT_MODE){
45       rst_mode = HWRST_STATUS_FASTBOOT;
46     }else if(reboot_mode == NORMAL_MODE){
47       rst_mode = HWRST_STATUS_NORMAL;
48     }else{
49       rst_mode = 0;
50     }
51
52     ANA_REG_SET(ANA_HWRST_STATUS, rst_mode);
53     reset_cpu(0);
54 #if 0
55     asm volatile("ldr r1,=0x20900218"); //remap ROM to 0x0000_0000
56     asm volatile("ldr r2,=1");
57     asm volatile("str r2,[r1]");
58     asm volatile("mov pc,#0");
59 #endif
60 }
61 void power_down_devices(unsigned pd_cmd)
62 {
63     power_down_cpu(0);
64 }
65
66 int power_button_pressed(void)
67 {
68 #ifdef CONFIG_SC7710G2
69         ANA_REG_OR(ANA_APB_CLK_EN, BIT_3);
70         ANA_REG_OR(ANA_RTC_CLK_EN, BIT_3);
71 #else
72         ANA_REG_OR(ANA_APB_CLK_EN, BIT_3|BIT_11);
73 #endif
74         ANA_REG_SET(ADI_EIC_MASK, 0xff);
75         udelay(3000);
76         int status = ANA_REG_GET(ADI_EIC_DATA);
77         //printf("eica status %x\n", status);
78         return !!(status & (1 << 3)/*PBINT*/);//low level if pb hold
79 }
80
81 int charger_connected(void)
82 {
83 #ifdef CONFIG_SC7710G2
84         ANA_REG_OR(ANA_APB_CLK_EN, BIT_3);
85         ANA_REG_OR(ANA_RTC_CLK_EN, BIT_3);
86 #else
87         ANA_REG_OR(ANA_APB_CLK_EN, BIT_3|BIT_11);
88 #endif
89         ANA_REG_SET(ADI_EIC_MASK, 0xff);
90         udelay(3000);
91         int status = ANA_REG_GET(ADI_EIC_DATA);
92         //printf("charger_connected eica status %x\n", status);
93         return !!(status & (1 << 2));
94 }
95
96 int alarm_triggered(void)
97 {
98     printf("ANA_RTC_INT_RSTS is 0x%x\n", ANA_RTC_INT_RSTS);
99     printf("value of it 0x%x\n", ANA_REG_GET(ANA_RTC_INT_RSTS));
100     return ANA_REG_GET(ANA_RTC_INT_RSTS) & BIT_4;
101 }
102