tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / cpu / armv7 / sc8825 / 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 #include <linux/gpio.h>
11
12 extern int hw_watchdog_rst_pending(void);
13 unsigned check_reboot_mode(void)
14 {
15         unsigned rst_mode= 0;
16
17         rst_mode = ANA_REG_GET(ANA_HWRST_STATUS);
18         rst_mode &= HWRST_STATUS_POWERON_MASK;
19         ANA_REG_SET(ANA_HWRST_STATUS, 0); //clear flag
20
21         if(hw_watchdog_rst_pending()){
22                 printf("hw watchdog rst int pending\n");
23                 if(rst_mode == HWRST_STATUS_RECOVERY)
24                         return RECOVERY_MODE;
25                 else if(rst_mode == HWRST_STATUS_FASTBOOT)
26                         return FASTBOOT_MODE;
27                 else if(rst_mode == HWRST_STATUS_NORMAL)
28                         return NORMAL_MODE;
29                 else if(rst_mode == HWRST_STATUS_NORMAL2)
30                         return WATCHDOG_REBOOT;
31                 else if(rst_mode == HWRST_STATUS_ALARM)
32                         return ALARM_MODE;
33                 else if(rst_mode == HWRST_STATUS_SLEEP)
34                         return SLEEP_MODE;
35                 else if(rst_mode == HWRST_STATUS_SPECIAL)
36                         return SPECIAL_MODE;
37                 else if(rst_mode == HWRST_STATUS_PANIC)
38                         return PANIC_REBOOT;
39                 else{
40                         printf(" a boot mode not supported\n");
41                         return 0;
42                 }
43         }else{
44                 printf("no hw watchdog rst int pending\n");
45                 if(rst_mode == HWRST_STATUS_NORMAL2)
46                         return UNKNOW_REBOOT_MODE;
47                 else
48                         return 0;
49         }
50 }
51
52 void reboot_devices(unsigned reboot_mode)
53 {
54     unsigned rst_mode = 0;
55     if(reboot_mode == RECOVERY_MODE){
56       rst_mode = HWRST_STATUS_RECOVERY;
57     }
58     else if(reboot_mode == FASTBOOT_MODE){
59       rst_mode = HWRST_STATUS_FASTBOOT;
60     }else if(reboot_mode == NORMAL_MODE){
61       rst_mode = HWRST_STATUS_NORMAL;
62     }else{
63       rst_mode = 0;
64     }
65
66     ANA_REG_SET(ANA_HWRST_STATUS, rst_mode);
67     reset_cpu(0);
68 #if 0
69     asm volatile("ldr r1,=0x20900218"); //remap ROM to 0x0000_0000
70     asm volatile("ldr r2,=1");
71     asm volatile("str r2,[r1]");
72     asm volatile("mov pc,#0");
73 #endif
74 }
75 void power_down_devices(unsigned pd_cmd)
76 {
77     power_down_cpu(0);
78 }
79
80 int power_button_pressed(void)
81 {
82 #if 1
83         static int init_done = 0;
84         if(init_done == 0){
85                 gpio_request(EIC_KEY_POWER, "power_key");
86                 gpio_direction_input(EIC_KEY_POWER);
87                 init_done = 1;
88         }
89     return ! gpio_get_value_cansleep(EIC_KEY_POWER);
90 #else
91
92         ANA_REG_OR(ANA_APB_CLK_EN, BIT_3|BIT_11);
93         ANA_REG_SET(ADI_EIC_MASK, 0xff);
94         udelay(3000);
95         int status = ANA_REG_GET(ADI_EIC_DATA);
96         //printf("eica status %x\n", status);
97         #if !(defined (CONFIG_SC8825))
98         return !!(status & (1 << 3)/*PBINT*/);//low level if pb hold
99         #else
100         return !(status & (1 << 3)/*PBINT*/);
101         #endif
102 #endif
103 }
104
105 int charger_connected(void)
106 {
107 #if 1
108         static int init_done = 0;
109         if(init_done == 0){
110                 gpio_request(EIC_CHARGER_DETECT, "charger_key");
111                 gpio_direction_input(EIC_CHARGER_DETECT);
112                 init_done = 1;
113         }
114     return !! gpio_get_value_cansleep(EIC_CHARGER_DETECT);
115 #else
116         ANA_REG_OR(ANA_APB_CLK_EN, BIT_3|BIT_11);
117         ANA_REG_SET(ADI_EIC_MASK, 0xff);
118         udelay(3000);
119         int status = ANA_REG_GET(ADI_EIC_DATA);
120         //printf("charger_connected eica status %x\n", status);
121         return !!(status & (1 << 2));
122 #endif
123 }
124
125 int alarm_triggered(void)
126 {
127     printf("ANA_RTC_INT_RSTS is 0x%x\n", ANA_RTC_INT_RSTS);
128     printf("value of it 0x%x\n", ANA_REG_GET(ANA_RTC_INT_RSTS));
129     return ANA_REG_GET(ANA_RTC_INT_RSTS) & BIT_4;
130 }