1 #include <asm/arch/sci_types.h>
2 #include <asm/arch/sc_reg.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>
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)
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)
29 #if defined(CONFIG_ADIE_SC2723S)||defined(CONFIG_ADIE_SC2723)
30 #define BIT_AON_GPIO_EB BIT_GPIO_EB
34 #define debugf(fmt, args...) do { printf("%s(): ", __func__); printf(fmt, ##args); } while (0)
36 #define debugf(fmt, args...)
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 __attribute__ ((gnu_inline))inline int is_smpl_bootup(void);
45 unsigned check_reboot_mode(void)
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);
51 rst_mode = ANA_REG_GET(ANA_REG_GLB_POR_RST_MONITOR);
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);
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)
62 else if(rst_mode == HWRST_STATUS_FASTBOOT)
64 else if(rst_mode == HWRST_STATUS_NORMAL)
66 else if(rst_mode == HWRST_STATUS_NORMAL2)
67 return WATCHDOG_REBOOT;
68 else if(rst_mode == HWRST_STATUS_ALARM)
70 else if(rst_mode == HWRST_STATUS_SLEEP)
72 else if(rst_mode == HWRST_STATUS_CALIBRATION)
73 return CALIBRATION_MODE;
74 else if(rst_mode == HWRST_STATUS_PANIC)
76 else if(rst_mode == HWRST_STATUS_SPECIAL)
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;
83 debugf(" a boot mode not supported\n");
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)
95 return UNKNOW_REBOOT_MODE;
98 else if(is_7s_reset_for_systemdump())
100 return UNKNOW_REBOOT_MODE;
102 else if(is_7s_reset())
106 else if(hw_rst_mode & SW_EXT_RSTN_STATUS)
108 return EXT_RSTN_REBOOT_MODE;
110 #ifndef CONFIG_SS_FUNCTION
111 else if(is_smpl_bootup())
113 debugf("SMPL bootup!\n");
123 int get_mode_from_gpio()
126 unsigned hw_rst_mode;
128 hw_rst_mode = ANA_REG_GET(ANA_REG_GLB_POR_SRC_FLAG);
129 ret = (hw_rst_mode & HW_PBINT2_STATUS) && !charger_connected();
134 void reboot_devices(unsigned reboot_mode)
136 unsigned rst_mode = 0;
137 if(reboot_mode == RECOVERY_MODE){
138 rst_mode = HWRST_STATUS_RECOVERY;
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;
148 ANA_REG_SET(ANA_REG_GLB_POR_RST_MONITOR, rst_mode);
152 void power_down_devices(unsigned pd_cmd)
156 #ifdef CONFIG_SMPL_MODE
157 int is_real_battery(void)
159 sprd_eic_request(EIC_BATDET);
161 return !!sprd_eic_get(EIC_BATDET);
164 int power_button_pressed(void)
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);
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);
175 sci_adi_set(ANA_REG_GLB_RTC_CLK_EN,BIT_RTC_EIC_EN);
177 ANA_REG_SET(ADI_EIC_MASK, 0xff);
181 int status = ANA_REG_GET(ADI_EIC_DATA);
182 status = status & (1 << 2);
184 debugf("power_button_pressed eica status 0x%x\n", status );
186 return !status;//low level if pb hold
190 int charger_connected(void)
192 sprd_eic_request(EIC_CHG_INT);
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);
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));
201 return !!sprd_eic_get(EIC_CHG_INT);
205 int alarm_triggered(void)
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;