tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / cpu / armv7 / sc9630 / check_reboot.c
1 #include <asm/arch/sci_types.h>
2 #include <asm/arch/sc_reg.h>
3 #include <boot_mode.h>
4 #include <asm/arch/sprd_reg.h>
5 #include <asm/arch/sprd_eic.h>
6 #include <asm/arch/rtc_reg_v3.h>
7 #include <asm/arch/regs_adi.h>
8 #include <asm/arch/adi_hal_internal.h>
9
10 #define   HWRST_STATUS_POWERON_MASK             (0xf0)
11 #define   HWRST_STATUS_RECOVERY                 (0x20)
12 #define   HWRST_STATUS_FASTBOOT                 (0X30)
13 #define   HWRST_STATUS_NORMAL                   (0X40)
14 #define   HWRST_STATUS_ALARM                    (0X50)
15 #define   HWRST_STATUS_SLEEP                    (0X60)
16 #define   HWRST_STATUS_SPECIAL                  (0x70)
17 #define   HWRST_STATUS_CALIBRATION                      (0x90)
18 #define   HWRST_STATUS_PANIC                    (0x80)
19 #define   HWRST_STATUS_AUTODLOADER (0Xa0)
20 #define   HWRST_STATUS_NORMAL2                  (0Xf0)
21 #define   HWRST_STATUS_IQMODE                 (0xb0)
22
23 #define   HW_PBINT2_STATUS                      (0x8)
24 #define   HW_VCHG_STATUS                        (0x20)
25 #define   HW_7SRST_STATUS                       (0x80)
26 #define   SW_EXT_RSTN_STATUS                    (0x800)
27 #define   SW_7SRST_STATUS                       (0x1000)
28
29
30 #ifdef DEBUG
31 #define debugf(fmt, args...) do { printf("%s(): ", __func__); printf(fmt, ##args); } while (0)
32 #else
33 #define debugf(fmt, args...)
34 #endif
35
36
37 extern int hw_watchdog_rst_pending(void);
38 extern inline int is_7s_reset(void);
39 extern int is_7s_reset_for_systemdump(void);
40 extern inline int is_hw_smpl_enable(void);
41 extern inline int is_smpl_bootup(void);
42 unsigned check_reboot_mode(void)
43 {
44         unsigned val, rst_mode= 0;
45         unsigned hw_rst_mode = ANA_REG_GET(ANA_REG_GLB_POR_SRC_FLAG);
46         debugf("hw_rst_mode==%x\n", hw_rst_mode);
47
48         rst_mode = ANA_REG_GET(ANA_REG_GLB_POR_RST_MONITOR);
49         rst_mode &= 0x7FFF;
50         ANA_REG_SET(ANA_REG_GLB_POR_RST_MONITOR, 0); //clear flag
51
52         debugf("rst_mode==%x\n",rst_mode);
53         if(hw_watchdog_rst_pending()){
54                 debugf("hw watchdog rst int pending\n");
55                 if(rst_mode == HWRST_STATUS_RECOVERY)
56                         return RECOVERY_MODE;
57                 else if(rst_mode == HWRST_STATUS_FASTBOOT)
58                         return FASTBOOT_MODE;
59                 else if(rst_mode == HWRST_STATUS_NORMAL)
60                         return NORMAL_MODE;
61                 else if(rst_mode == HWRST_STATUS_NORMAL2)
62                         return WATCHDOG_REBOOT;
63                 else if(rst_mode == HWRST_STATUS_ALARM)
64                         return ALARM_MODE;
65                 else if(rst_mode == HWRST_STATUS_SLEEP)
66                         return SLEEP_MODE;
67                 else if(rst_mode == HWRST_STATUS_CALIBRATION)
68                         return CALIBRATION_MODE;
69                 else if(rst_mode == HWRST_STATUS_PANIC)
70                         return PANIC_REBOOT;
71                 else if(rst_mode == HWRST_STATUS_SPECIAL)
72                         return SPECIAL_MODE;
73                 else if(rst_mode == HWRST_STATUS_AUTODLOADER)
74                         return AUTODLOADER_REBOOT;
75                 else if(rst_mode == HWRST_STATUS_IQMODE)
76                         return IQ_REBOOT_MODE;
77                 else{
78                         debugf(" a boot mode not supported\n");
79                         return 0;
80                 }
81         }else{
82                 debugf("is_7s_reset 0x%x, systemdump 0x%x\n", is_7s_reset(), is_7s_reset_for_systemdump());
83                 debugf("is_hw_smpl_enable %d\n", is_hw_smpl_enable());
84                 debugf("no hw watchdog rst int pending\n");
85                 if(rst_mode == HWRST_STATUS_NORMAL2)
86                         return UNKNOW_REBOOT_MODE;
87 #if 0 /* SC2711 & SC2723 change */
88                 else if(hw_rst_mode & HW_7SRST_STATUS)
89                 {
90                         return UNKNOW_REBOOT_MODE;
91                 }
92 #endif
93                 else if(is_7s_reset_for_systemdump())
94                 {
95                         return UNKNOW_REBOOT_MODE;
96                 }
97                 else if(is_7s_reset())
98                 {
99                         return NORMAL_MODE;
100                 }
101                 else if(hw_rst_mode & SW_EXT_RSTN_STATUS)
102                 {
103                         return EXT_RSTN_REBOOT_MODE;
104                 }
105 #ifndef CONFIG_SS_FUNCTION
106                 else if(is_smpl_bootup())
107                 {
108                         debugf("SMPL bootup!\n");
109                         return NORMAL_MODE;
110                 }
111 #endif
112                 else
113                         return 0;
114         }
115
116 }
117
118 int get_mode_from_gpio()
119 {
120         int ret = 0;
121         unsigned hw_rst_mode;
122
123         hw_rst_mode = ANA_REG_GET(ANA_REG_GLB_POR_SRC_FLAG);
124         ret = (hw_rst_mode & HW_PBINT2_STATUS) && !charger_connected();
125
126         return ret;
127 }
128
129 void reboot_devices(unsigned reboot_mode)
130 {
131         unsigned rst_mode = 0;
132         if(reboot_mode == RECOVERY_MODE){
133                 rst_mode = HWRST_STATUS_RECOVERY;
134         }
135         else if(reboot_mode == FASTBOOT_MODE){
136                 rst_mode = HWRST_STATUS_FASTBOOT;
137         }else if(reboot_mode == NORMAL_MODE){
138                 rst_mode = HWRST_STATUS_NORMAL;
139         }else{
140                 rst_mode = 0;
141         }
142
143         ANA_REG_SET(ANA_REG_GLB_POR_RST_MONITOR, rst_mode);
144
145         reset_cpu(0);
146 }
147 void power_down_devices(unsigned pd_cmd)
148 {
149         power_down_cpu(0);
150 }
151
152 int power_button_pressed(void)
153 {
154         #if defined (CONFIG_SPX15)||defined(CONFIG_ARCH_SCX35L)
155         sci_glb_set(REG_AON_APB_APB_EB0,BIT_AON_GPIO_EB | BIT_EIC_EB);
156         sci_glb_set(REG_AON_APB_APB_RTC_EB,BIT_EIC_RTC_EB);
157         sci_adi_set(ANA_REG_GLB_ARM_MODULE_EN, BIT_ANA_EIC_EN);
158         #else
159         sci_glb_set(REG_AON_APB_APB_EB0,BIT_GPIO_EB | BIT_EIC_EB);
160         sci_glb_set(REG_AON_APB_APB_RTC_EB,BIT_EIC_RTC_EB);
161         sci_adi_set(ANA_REG_GLB_ARM_MODULE_EN, BIT_ANA_EIC_EN | BIT_ANA_GPIO_EN);
162         #endif
163         sci_adi_set(ANA_REG_GLB_RTC_CLK_EN,BIT_RTC_EIC_EN);
164
165         ANA_REG_SET(ADI_EIC_MASK, 0xff);
166
167         udelay(3000);
168
169         int status = ANA_REG_GET(ADI_EIC_DATA);
170         status = status & (1 << 2);
171
172         debugf("power_button_pressed eica status 0x%x\n", status );
173         
174         return !status;//low level if pb hold
175
176 }
177
178 int charger_connected(void)
179 {
180         sprd_eic_request(EIC_CHG_INT);
181         udelay(3000);
182         debugf("eica status %x\n", sprd_eic_get(EIC_CHG_INT));
183 #ifdef  CONFIG_SHARK_PAD_HW_V102
184         sprd_eic_request(EIC_USB_DETECT);
185         udelay(3000);
186         debugf("eica status %x\n", sprd_eic_get(EIC_USB_DETECT));
187         return (!!sprd_eic_get(EIC_USB_DETECT)) ||(!!sprd_eic_get(EIC_CHG_INT));
188 #else
189         return !!sprd_eic_get(EIC_CHG_INT);
190 #endif
191 }
192
193 int alarm_triggered(void)
194 {
195         //printf("ANA_RTC_INT_RSTS is 0x%x\n", ANA_RTC_INT_RSTS);
196         debugf("value of it 0x%x\n", ANA_REG_GET(ANA_RTC_INT_RSTS));
197         return ANA_REG_GET(ANA_RTC_INT_RSTS) & BIT_4;
198 }
199