2 #include <asm/arch/sci_types.h>
3 #include <asm/arch/sc_reg.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>
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)
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)
30 #if defined(CONFIG_ADIE_SC2723S)||defined(CONFIG_ADIE_SC2723)
31 #define BIT_AON_GPIO_EB BIT_GPIO_EB
35 #define debugf(fmt, args...) do { printf("%s(): ", __func__); printf(fmt, ##args); } while (0)
37 #define debugf(fmt, args...)
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);
51 unsigned check_reboot_mode(void)
54 unsigned hw_rst_mode = ANA_REG_GET(ANA_REG_GLB_POR_SRC_FLAG);
55 debugf("hw_rst_mode==%x\n", hw_rst_mode);
57 rst_mode = ANA_REG_GET(ANA_REG_GLB_POR_RST_MONITOR);
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);
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)
68 else if(rst_mode == HWRST_STATUS_FASTBOOT)
70 else if(rst_mode == HWRST_STATUS_NORMAL)
72 else if(rst_mode == HWRST_STATUS_NORMAL2)
73 return WATCHDOG_REBOOT;
74 else if(rst_mode == HWRST_STATUS_ALARM)
76 else if(rst_mode == HWRST_STATUS_SLEEP)
78 else if(rst_mode == HWRST_STATUS_CALIBRATION)
79 return CALIBRATION_MODE;
80 else if(rst_mode == HWRST_STATUS_PANIC)
82 else if(rst_mode == HWRST_STATUS_SPECIAL)
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;
89 debugf(" a boot mode not supported\n");
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)
101 return UNKNOW_REBOOT_MODE;
104 else if(is_7s_reset_for_systemdump())
106 return UNKNOW_REBOOT_MODE;
108 else if(is_7s_reset())
112 else if(hw_rst_mode & SW_EXT_RSTN_STATUS)
114 return EXT_RSTN_REBOOT_MODE;
116 #ifndef CONFIG_SS_FUNCTION
117 else if(is_smpl_bootup())
119 debugf("SMPL bootup!\n");
129 int charger_connected(void)
131 sprd_eic_request(EIC_CHG_INT);
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);
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));
140 return !!sprd_eic_get(EIC_CHG_INT);
144 int get_mode_from_gpio(void)
147 unsigned hw_rst_mode;
149 hw_rst_mode = ANA_REG_GET(ANA_REG_GLB_POR_SRC_FLAG);
150 ret = (hw_rst_mode & HW_PBINT2_STATUS) && !charger_connected();
155 void reboot_devices(unsigned reboot_mode)
157 unsigned rst_mode = 0;
158 if(reboot_mode == RECOVERY_MODE){
159 rst_mode = HWRST_STATUS_RECOVERY;
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;
169 ANA_REG_SET(ANA_REG_GLB_POR_RST_MONITOR, rst_mode);
173 void power_down_devices(unsigned pd_cmd)
177 #ifdef CONFIG_SMPL_MODE
178 int is_real_battery(void)
180 sprd_eic_request(EIC_BATDET);
182 return !!sprd_eic_get(EIC_BATDET);
185 int power_button_pressed(void)
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);
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);
196 sci_adi_set(ANA_REG_GLB_RTC_CLK_EN,BIT_RTC_EIC_EN);
198 ANA_REG_SET(ADI_EIC_MASK, 0xff);
202 int status = ANA_REG_GET(ADI_EIC_DATA);
203 status = status & (1 << 2);
205 debugf("power_button_pressed eica status 0x%x\n", status );
207 return !status;//low level if pb hold
211 int alarm_triggered(void)
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;