2f60c79bde1a8f3ddef7fb8b3b61310f0da4d8f9
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / cpu / armv7 / tiger / check_reboot.c
1 #include <asm/arch/sci_types.h>
2 #include <asm/arch/sc_reg.h>
3 #include <asm/arch/adi_hal_internal.h>
4 #include <boot_mode.h>
5 #include <asm/arch/gpio.h>
6 #include <asm/arch/asm_generic_gpio.h>
7 #include <asm/arch/gpio_phy.h>
8 #include <asm/arch/rtc_reg_v3.h>
9 #include <asm/arch/mfp.h>
10
11 unsigned check_reboot_mode(void)
12 {
13         unsigned rst_mode= 0;
14
15         rst_mode = ANA_REG_GET(ANA_HWRST_STATUS);
16         rst_mode &= HWRST_STATUS_POWERON_MASK;
17         ANA_REG_SET(ANA_HWRST_STATUS, 0); //clear flag
18         if(rst_mode == HWRST_STATUS_RECOVERY)
19                 return RECOVERY_MODE;
20         else if(rst_mode == HWRST_STATUS_FASTBOOT)
21                 return FASTBOOT_MODE;
22         else if(rst_mode == HWRST_STATUS_NORMAL)
23                 return NORMAL_MODE;
24         else if(rst_mode == HWRST_STATUS_ALARM)
25                 return ALARM_MODE;
26         else if(rst_mode == HWRST_STATUS_SLEEP)
27                 return SLEEP_MODE;
28         else
29                 return 0;
30 }
31
32 void reboot_devices(unsigned reboot_mode)
33 {
34     unsigned rst_mode = 0;
35     if(reboot_mode == RECOVERY_MODE){
36       rst_mode = HWRST_STATUS_RECOVERY;
37     }
38     else if(reboot_mode == FASTBOOT_MODE){
39       rst_mode = HWRST_STATUS_FASTBOOT;
40     }else if(reboot_mode == NORMAL_MODE){
41       rst_mode = HWRST_STATUS_NORMAL;
42     }else{
43       rst_mode = 0;
44     }
45
46     ANA_REG_SET(ANA_HWRST_STATUS, rst_mode);
47     reset_cpu(0);
48 #if 0
49     asm volatile("ldr r1,=0x20900218"); //remap ROM to 0x0000_0000
50     asm volatile("ldr r2,=1");
51     asm volatile("str r2,[r1]");
52     asm volatile("mov pc,#0");
53 #endif
54 }
55 void power_down_devices(unsigned pd_cmd)
56 {
57     power_down_cpu(0);
58 }
59
60 #define POWER_BUTTON_GPIO_NUM 163
61 extern int sprd_gpio_get( struct gpio_chip * chip, unsigned offset);
62 extern int sprd_gpio_request(struct gpio_chip *chip, unsigned offset);
63 extern void sprd_gpio_init(void);
64 static unsigned long pwr_gpio_cfg =
65     MFP_ANA_CFG_X(PBINT, AF0, DS1, F_PULL_UP,S_PULL_UP, IO_IE);
66 int power_button_pressed(void)
67 {
68 #if 0
69     struct gpio_chip power_button_chip;
70     sprd_gpio_init();
71     sprd_mfp_config(&pwr_gpio_cfg, 1);
72     sprd_gpio_request(&power_button_chip, POWER_BUTTON_GPIO_NUM);
73     sprd_gpio_direction_input(&power_button_chip,POWER_BUTTON_GPIO_NUM); 
74     return sprd_gpio_get(&power_button_chip, POWER_BUTTON_GPIO_NUM);
75 #else
76         ANA_REG_OR(ANA_APB_CLK_EN, BIT_3|BIT_11);
77         ANA_REG_SET(ADI_EIC_MASK, 0xff);
78         udelay(3000);
79         int status = ANA_REG_GET(ADI_EIC_DATA);
80         //printf("eica status %x\n", status);
81         return !!(status & (1 << 3)/*PBINT*/);//low level if pb hold
82 #endif
83 }
84
85 #define CHG_GPIO_NUM 162
86 static unsigned long chg_gpio_cfg =
87     MFP_ANA_CFG_X(CHIP_RSTN, AF0, DS1, F_PULL_UP,S_PULL_UP, IO_IE);
88     //MFP_ANA_CFG_X(CHIP_RSTN, AF0, DS1, F_PULL_DOWN,S_PULL_UP, IO_IE);
89 int charger_connected(void)
90 {
91  #if  0 //mingwei
92     struct gpio_chip chg_chip;
93     sprd_mfp_config(&chg_gpio_cfg, 1);
94     sprd_gpio_request(&chg_chip, CHG_GPIO_NUM);
95     sprd_gpio_direction_input(&chg_chip,CHG_GPIO_NUM); 
96     return sprd_gpio_get(&chg_chip, CHG_GPIO_NUM);
97 #else
98         ANA_REG_OR(ANA_APB_CLK_EN, BIT_3|BIT_11);
99         ANA_REG_SET(ADI_EIC_MASK, 0xff);
100         udelay(3000);
101         int status = ANA_REG_GET(ADI_EIC_DATA);
102         //printf("charger_connected eica status %x\n", status);
103         return !!(status & (1 << 2));
104 #endif
105     
106 }
107
108 int alarm_triggered(void)
109 {
110     printf("ANA_RTC_INT_RSTS is 0x%x\n", ANA_RTC_INT_RSTS);
111     printf("value of it 0x%x\n", ANA_REG_GET(ANA_RTC_INT_RSTS));
112     return ANA_REG_GET(ANA_RTC_INT_RSTS) & BIT_4;
113 }