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_NORMAL2 (0Xf0)
21 #define HWRST_STATUS_IQMODE (0xb0)
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)
31 #define debugf(fmt, args...) do { printf("%s(): ", __func__); printf(fmt, ##args); } while (0)
33 #define debugf(fmt, args...)
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)
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);
48 rst_mode = ANA_REG_GET(ANA_REG_GLB_POR_RST_MONITOR);
50 ANA_REG_SET(ANA_REG_GLB_POR_RST_MONITOR, 0); //clear flag
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)
57 else if(rst_mode == HWRST_STATUS_FASTBOOT)
59 else if(rst_mode == HWRST_STATUS_NORMAL)
61 else if(rst_mode == HWRST_STATUS_NORMAL2)
62 return WATCHDOG_REBOOT;
63 else if(rst_mode == HWRST_STATUS_ALARM)
65 else if(rst_mode == HWRST_STATUS_SLEEP)
67 else if(rst_mode == HWRST_STATUS_CALIBRATION)
68 return CALIBRATION_MODE;
69 else if(rst_mode == HWRST_STATUS_PANIC)
71 else if(rst_mode == HWRST_STATUS_SPECIAL)
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;
78 debugf(" a boot mode not supported\n");
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)
90 return UNKNOW_REBOOT_MODE;
93 else if(is_7s_reset_for_systemdump())
95 return UNKNOW_REBOOT_MODE;
97 else if(is_7s_reset())
101 else if(hw_rst_mode & SW_EXT_RSTN_STATUS)
103 return EXT_RSTN_REBOOT_MODE;
105 #ifndef CONFIG_SS_FUNCTION
106 else if(is_smpl_bootup())
108 debugf("SMPL bootup!\n");
118 int get_mode_from_gpio()
121 unsigned hw_rst_mode;
123 hw_rst_mode = ANA_REG_GET(ANA_REG_GLB_POR_SRC_FLAG);
124 ret = (hw_rst_mode & HW_PBINT2_STATUS) && !charger_connected();
129 void reboot_devices(unsigned reboot_mode)
131 unsigned rst_mode = 0;
132 if(reboot_mode == RECOVERY_MODE){
133 rst_mode = HWRST_STATUS_RECOVERY;
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;
143 ANA_REG_SET(ANA_REG_GLB_POR_RST_MONITOR, rst_mode);
147 void power_down_devices(unsigned pd_cmd)
152 int power_button_pressed(void)
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);
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);
163 sci_adi_set(ANA_REG_GLB_RTC_CLK_EN,BIT_RTC_EIC_EN);
165 ANA_REG_SET(ADI_EIC_MASK, 0xff);
169 int status = ANA_REG_GET(ADI_EIC_DATA);
170 status = status & (1 << 2);
172 debugf("power_button_pressed eica status 0x%x\n", status );
174 return !status;//low level if pb hold
178 int charger_connected(void)
180 sprd_eic_request(EIC_CHG_INT);
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);
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));
189 return !!sprd_eic_get(EIC_CHG_INT);
193 int alarm_triggered(void)
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;