1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
/*
* Copyright (C) 2012 Spreadtrum Communications Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/init.h>
#include <linux/suspend.h>
#include <linux/errno.h>
#include <linux/io.h>
extern void sc_pm_init(void);
#include <asm/irqflags.h>
#include <soc/sprd/pm_debug.h>
#include <soc/sprd/globalregs.h>
#if defined(CONFIG_ARCH_SCX35L64)||defined(CONFIG_ARCH_SCX35LT8)
#include <soc/sprd/sprd_persistent_clock.h>
#endif
extern unsigned int sprd_irq_pending(void);
extern int sprd_cpu_deep_sleep(unsigned int cpu);
extern void sc_pm_init(void);
extern void check_ldo(void);
extern void check_pd(void);
#if 0 /*comment for bug 179358 */
/*for battery*/
#define BATTERY_CHECK_INTERVAL 30000
extern int battery_updata(void);
static int __used sprd_check_battery(void)
{
int ret_val = 0;
if (battery_updata()) {
ret_val = 1;
}
return ret_val;
}
#endif
static void sprd_pm_standby(void)
{
cpu_do_idle();
}
static int sprd_pm_deepsleep(suspend_state_t state)
{
int ret_val = 0;
unsigned long flags;
unsigned int cpu = smp_processor_id();
u32 battery_time, cur_time;
battery_time = cur_time = get_sys_cnt();
/* add for debug & statisic*/
clr_sleep_mode();
time_statisic_begin();
/*
* when we get here, only boot cpu still alive
*/
if( cpu ){
__WARN();
goto enter_exit;
}
printk("cpu%d, enter %s\n", cpu, __func__ );
while(1){
local_fiq_disable();
local_irq_save(flags);
WARN_ONCE(!irqs_disabled(), "#####: Interrupts enabled in pm_enter()!\n");
sprd_cpu_deep_sleep(cpu);
if( sprd_irq_pending() ){
irq_wakeup_set();
local_irq_restore(flags);
local_fiq_enable();
break;
}
/*TODO: charging in power down
cur_time = get_sys_cnt();
if ((cur_time - battery_time) > BATTERY_CHECK_INTERVAL) {
battery_time = cur_time;
if (sprd_check_battery()) {
printk("###: battery low!\n");
break;
}
}
*/
}/*end while*/
time_statisic_end();
enter_exit:
return ret_val;
}
static int sprd_pm_enter(suspend_state_t state)
{
int rval = 0;
switch (state) {
case PM_SUSPEND_STANDBY:
sprd_pm_standby( );
break;
case PM_SUSPEND_MEM:
rval = sprd_pm_deepsleep(state);
break;
default:
break;
}
return rval;
}
static int sprd_pm_valid(suspend_state_t state)
{
pr_debug("pm_valid: %d\n", state);
switch (state) {
case PM_SUSPEND_ON:
case PM_SUSPEND_STANDBY:
case PM_SUSPEND_MEM:
return 1;
default:
return 0;
}
}
static int sprd_pm_prepare(void)
{
pr_debug("enter %s\n", __func__);
check_ldo();
check_pd();
return 0;
}
static void sprd_pm_finish(void)
{
pr_debug("enter %s\n", __func__);
print_statisic();
}
static struct platform_suspend_ops sprd_pm_ops = {
.valid = sprd_pm_valid,
.enter = sprd_pm_enter,
.prepare = sprd_pm_prepare,
.prepare_late = NULL,
.finish = sprd_pm_finish,
};
static int __init sprd_pm_init(void)
{
sc_pm_init();
#ifdef CONFIG_SUSPEND
suspend_set_ops(&sprd_pm_ops);
#endif
return 0;
}
subsys_initcall(sprd_pm_init);
|