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