66c084223c9eb91c4964158757b0c6da007d9daa
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / cpu / armv7 / sc8830 / 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_IQMODE                 (0xb0)
21 #define   HWRST_STATUS_NORMAL2                  (0Xf0)
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 #if defined(CONFIG_ADIE_SC2723S)||defined(CONFIG_ADIE_SC2723)
30 #define BIT_AON_GPIO_EB BIT_GPIO_EB
31 #endif
32
33 #ifdef DEBUG
34 #define debugf(fmt, args...) do { printf("%s(): ", __func__); printf(fmt, ##args); } while (0)
35 #else
36 #define debugf(fmt, args...)
37 #endif
38
39
40 extern int hw_watchdog_rst_pending(void);
41 extern inline int is_7s_reset(void);
42 extern int is_7s_reset_for_systemdump(void);
43 extern inline int is_hw_smpl_enable(void);
44 extern inline int is_smpl_bootup(void);
45 unsigned check_reboot_mode(void)
46 {
47         unsigned val, rst_mode= 0;
48         unsigned hw_rst_mode = ANA_REG_GET(ANA_REG_GLB_POR_SRC_FLAG);
49         debugf("hw_rst_mode==%x\n", hw_rst_mode);
50
51         rst_mode = ANA_REG_GET(ANA_REG_GLB_POR_RST_MONITOR);
52         rst_mode &= 0x7FFF;
53         ANA_REG_SET(ANA_REG_GLB_POR_RST_MONITOR, 0); //clear flag
54         /* clear the flag which used by modem side in any scenes , prevent some errors */
55         ANA_REG_SET(ANA_REG_GLB_WDG_RST_MONITOR, 0);
56
57         debugf("rst_mode==%x\n",rst_mode);
58         if(hw_watchdog_rst_pending()){
59                 debugf("hw watchdog rst int pending\n");
60                 if(rst_mode == HWRST_STATUS_RECOVERY)
61                         return RECOVERY_MODE;
62                 else if(rst_mode == HWRST_STATUS_FASTBOOT)
63                         return FASTBOOT_MODE;
64                 else if(rst_mode == HWRST_STATUS_NORMAL)
65                         return NORMAL_MODE;
66                 else if(rst_mode == HWRST_STATUS_NORMAL2)
67                         return WATCHDOG_REBOOT;
68                 else if(rst_mode == HWRST_STATUS_ALARM)
69                         return ALARM_MODE;
70                 else if(rst_mode == HWRST_STATUS_SLEEP)
71                         return SLEEP_MODE;
72                 else if(rst_mode == HWRST_STATUS_CALIBRATION)
73                         return CALIBRATION_MODE;
74                 else if(rst_mode == HWRST_STATUS_PANIC)
75                         return PANIC_REBOOT;
76                 else if(rst_mode == HWRST_STATUS_SPECIAL)
77                         return SPECIAL_MODE;
78                 else if(rst_mode == HWRST_STATUS_AUTODLOADER)
79                         return AUTODLOADER_REBOOT;
80                 else if(rst_mode == HWRST_STATUS_IQMODE)
81                         return IQ_REBOOT_MODE;
82                 else{
83                         debugf(" a boot mode not supported\n");
84                         return 0;
85                 }
86         }else{
87                 debugf("is_7s_reset 0x%x, systemdump 0x%x\n", is_7s_reset(), is_7s_reset_for_systemdump());
88                 debugf("is_hw_smpl_enable %d\n", is_hw_smpl_enable());
89                 debugf("no hw watchdog rst int pending\n");
90                 if(rst_mode == HWRST_STATUS_NORMAL2)
91                         return UNKNOW_REBOOT_MODE;
92 #if 0 /* SC2711 & SC2723 change */
93                 else if(hw_rst_mode & HW_7SRST_STATUS)
94                 {
95                         return UNKNOW_REBOOT_MODE;
96                 }
97 #endif
98                 else if(is_7s_reset_for_systemdump())
99                 {
100                         return UNKNOW_REBOOT_MODE;
101                 }
102                 else if(is_7s_reset())
103                 {
104                         return NORMAL_MODE;
105                 }
106                 else if(hw_rst_mode & SW_EXT_RSTN_STATUS)
107                 {
108                         return EXT_RSTN_REBOOT_MODE;
109                 }
110 #ifndef CONFIG_SS_FUNCTION
111                 else if(is_smpl_bootup())
112                 {
113                         debugf("SMPL bootup!\n");
114                         return NORMAL_MODE;
115                 }
116 #endif
117                 else
118                         return 0;
119         }
120
121 }
122
123 int get_mode_from_gpio()
124 {
125         int ret = 0;
126         unsigned hw_rst_mode;
127
128         hw_rst_mode = ANA_REG_GET(ANA_REG_GLB_POR_SRC_FLAG);
129         ret = (hw_rst_mode & HW_PBINT2_STATUS) && !charger_connected();
130
131         return ret;
132 }
133
134 void reboot_devices(unsigned reboot_mode)
135 {
136         unsigned rst_mode = 0;
137         if(reboot_mode == RECOVERY_MODE){
138                 rst_mode = HWRST_STATUS_RECOVERY;
139         }
140         else if(reboot_mode == FASTBOOT_MODE){
141                 rst_mode = HWRST_STATUS_FASTBOOT;
142         }else if(reboot_mode == NORMAL_MODE){
143                 rst_mode = HWRST_STATUS_NORMAL;
144         }else{
145                 rst_mode = 0;
146         }
147
148         ANA_REG_SET(ANA_REG_GLB_POR_RST_MONITOR, rst_mode);
149
150         reset_cpu(0);
151 }
152 void power_down_devices(unsigned pd_cmd)
153 {
154         power_down_cpu(0);
155 }
156 #ifdef CONFIG_SMPL_MODE
157 int is_real_battery(void)
158 {
159         sprd_eic_request(EIC_BATDET);
160         udelay(3000);
161         return !!sprd_eic_get(EIC_BATDET);
162 }
163 #endif
164 int power_button_pressed(void)
165 {
166 #if defined (CONFIG_SPX15)||defined(CONFIG_ADIE_SC2723S)||defined(CONFIG_ADIE_SC2723)
167         sci_glb_set(REG_AON_APB_APB_EB0,BIT_AON_GPIO_EB | BIT_EIC_EB);
168         sci_glb_set(REG_AON_APB_APB_RTC_EB,BIT_EIC_RTC_EB);
169         sci_adi_set(ANA_REG_GLB_ARM_MODULE_EN, BIT_ANA_EIC_EN);
170 #else
171         sci_glb_set(REG_AON_APB_APB_EB0,BIT_GPIO_EB | BIT_EIC_EB);
172         sci_glb_set(REG_AON_APB_APB_RTC_EB,BIT_EIC_RTC_EB);
173         sci_adi_set(ANA_REG_GLB_ARM_MODULE_EN, BIT_ANA_EIC_EN | BIT_ANA_GPIO_EN);
174 #endif
175         sci_adi_set(ANA_REG_GLB_RTC_CLK_EN,BIT_RTC_EIC_EN);
176
177         ANA_REG_SET(ADI_EIC_MASK, 0xff);
178
179         udelay(3000);
180
181         int status = ANA_REG_GET(ADI_EIC_DATA);
182         status = status & (1 << 2);
183
184         debugf("power_button_pressed eica status 0x%x\n", status );
185         
186         return !status;//low level if pb hold
187
188 }
189
190 int charger_connected(void)
191 {
192         sprd_eic_request(EIC_CHG_INT);
193         udelay(3000);
194         debugf("eica status %x\n", sprd_eic_get(EIC_CHG_INT));
195 #ifdef  CONFIG_SHARK_PAD_HW_V102
196         sprd_eic_request(EIC_USB_DETECT);
197         udelay(3000);
198         debugf("eica status %x\n", sprd_eic_get(EIC_USB_DETECT));
199         return (!!sprd_eic_get(EIC_USB_DETECT)) ||(!!sprd_eic_get(EIC_CHG_INT));
200 #else
201         return !!sprd_eic_get(EIC_CHG_INT);
202 #endif
203 }
204
205 int alarm_triggered(void)
206 {
207         //printf("ANA_RTC_INT_RSTS is 0x%x\n", ANA_RTC_INT_RSTS);
208         debugf("value of it 0x%x\n", ANA_REG_GET(ANA_RTC_INT_RSTS));
209         return ANA_REG_GET(ANA_RTC_INT_RSTS) & BIT_4;
210 }
211