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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
#include <linux/kernel.h>
#include <mach/ext_wd_drv.h>
#include <mach/local_wd_drv.h>
#include <mach/wd_api.h>
#include <linux/smp.h>
extern void wk_cpu_update_bit_flag(int cpu, int plug_status);
extern unsigned int get_check_bit(void);
extern unsigned int get_kick_bit(void);
static int wd_cpu_hot_plug_on_notify(int cpu);
static int wd_cpu_hot_plug_off_notify(int cpu);
static int spmwdt_mode_config(WD_REQ_CTL en, WD_REQ_MODE mode);
static int thermal_mode_config(WD_REQ_CTL en, WD_REQ_MODE mode);
static int confirm_hwreboot(void);
static void resume_notify(void);
static void suspend_notify(void);
static int mtk_wk_wdt_config(enum ext_wdt_mode mode, int timeout_val);
static unsigned int wd_get_check_bit(void);
static unsigned int wd_get_kick_bit(void);
static int disable_all_wd(void);
static int disable_ext(void);
static int disable_local(void);
static int wd_sw_reset(int type);
static int wd_restart(enum wd_restart_type type);
static int set_mode(enum ext_wdt_mode mode);
static int wd_dram_reserved_mode(bool enabled);
static int thermal_direct_mode_config(WD_REQ_CTL en, WD_REQ_MODE mode);
static struct wd_api g_wd_api_obj = {
.ready = 1,
.wd_cpu_hot_plug_on_notify = wd_cpu_hot_plug_on_notify, /* for cpu hot plug */
.wd_cpu_hot_plug_off_notify = wd_cpu_hot_plug_off_notify, /* for cpu hot plug */
.wd_spmwdt_mode_config = spmwdt_mode_config,
.wd_thermal_mode_config = thermal_mode_config,
.wd_sw_reset = wd_sw_reset,
.wd_restart = wd_restart,
.wd_config = mtk_wk_wdt_config,
.wd_set_mode = set_mode,
.wd_aee_confirm_hwreboot = confirm_hwreboot,
.wd_disable_ext = disable_ext,
.wd_disable_local = disable_local,
.wd_suspend_notify = suspend_notify,
.wd_resume_notify = resume_notify,
.wd_disable_all = disable_all_wd,
.wd_get_check_bit = wd_get_check_bit,
.wd_get_kick_bit = wd_get_kick_bit,
.wd_dram_reserved_mode = wd_dram_reserved_mode,
.wd_thermal_direct_mode_config = thermal_direct_mode_config,
};
/* struct wd_private_api *g_wd_private_api_obj; */
/* apiimplimentation */
#ifdef CONFIG_MTK_WD_KICKER
static unsigned int wd_get_check_bit(void)
{
return get_check_bit();
}
static unsigned int wd_get_kick_bit(void)
{
return get_kick_bit();
}
static int wd_restart(enum wd_restart_type type)
{
#ifdef CONFIG_LOCAL_WDT
#ifdef CONFIG_SMP
on_each_cpu((smp_call_func_t) mpcore_wdt_restart, WD_TYPE_NORMAL, 0);
#else
mpcore_wdt_restart(type);
#endif
#endif
mtk_wdt_restart(type);
return 0;
}
static int wd_cpu_hot_plug_on_notify(int cpu)
{
int res = 0;
wk_cpu_update_bit_flag(cpu, 1);
mtk_wdt_restart(WD_TYPE_NOLOCK); /* for KICK external wdt */
printk("WD wd_cpu_hot_plug_on_notify kick ext wd\n");
return res;
}
static int wd_cpu_hot_plug_off_notify(int cpu)
{
int res = 0;
wk_cpu_update_bit_flag(cpu, 0);
return res;
}
static int wd_sw_reset(int type)
{
wdt_arch_reset(type);
return 0;
}
static int mtk_wk_wdt_config(enum ext_wdt_mode mode, int timeout_val)
{
mtk_wdt_mode_config(TRUE, TRUE, TRUE, FALSE, TRUE);
mtk_wdt_set_time_out_value(timeout_val);
#ifdef CONFIG_LOCAL_WDT
mpcore_wk_wdt_config(0, 0, timeout_val - 5); /* local 25s time out */
/* mpcore_wdt_set_heartbeat(timeout_val - 5);//local 25s time out */
#endif
return 0;
}
static int disable_ext(void)
{
mtk_wdt_enable(WK_WDT_DIS);
return 0;
}
static int disable_local(void)
{
#ifdef CONFIG_LOCAL_WDT
#ifdef CONFIG_SMP
on_each_cpu((smp_call_func_t) local_wdt_enable, WK_WDT_DIS, 0);
#else
local_wdt_enable(WK_WDT_DIS);
#endif
#endif
printk(" wd_api disable_local not support now\n");
return 0;
}
static int set_mode(enum ext_wdt_mode mode)
{
printk(" support only irq mode-20140522");
switch (mode) {
case WDT_DUAL_MODE:
break;
case WDT_HW_REBOOT_ONLY_MODE:
break;
case WDT_IRQ_ONLY_MODE:
printk("wd set only irq mode for debug\n");
mtk_wdt_mode_config(FALSE, TRUE, TRUE, FALSE, TRUE);
break;
}
return 0;
}
static int confirm_hwreboot(void)
{
mtk_wdt_confirm_hwreboot();
return 0;
}
static void suspend_notify(void)
{
mtk_wd_suspend();
}
static void resume_notify(void)
{
mtk_wd_resume();
}
static int disable_all_wd(void)
{
disable_ext();
#ifdef CONFIG_LOCAL_WDT
disable_local();
#endif
return 0;
}
static int spmwdt_mode_config(WD_REQ_CTL en, WD_REQ_MODE mode)
{
int res = 0;
if (WD_REQ_EN == en) {
/* g_ext_wd_drv.reques_en_set(MTK_WDT_REQ_SPM_SCPSYS_MARK,WD_REQ_EN); */
res = mtk_wdt_request_en_set(MTK_WDT_REQ_SPM_SCPSYS_MARK, WD_REQ_EN);
} else if (WD_REQ_DIS == en) {
/* g_ext_wd_drv.reques_en_set(MTK_WDT_REQ_SPM_SCPSYS_MARK,WD_REQ_DIS); */
res = mtk_wdt_request_en_set(MTK_WDT_REQ_SPM_SCPSYS_MARK, WD_REQ_DIS);
} else {
res = -2;
}
if (WD_REQ_IRQ_MODE == mode) {
res = mtk_wdt_request_mode_set(MTK_WDT_REQ_SPM_SCPSYS_MARK, WD_REQ_IRQ_MODE);
/* g_ext_wd_drv.reques_mode_set(MTK_WDT_REQ_SPM_SCPSYS_MARK,WD_REQ_IRQ_MODE); */
} else if (WD_REQ_RST_MODE == mode) {
res = mtk_wdt_request_mode_set(MTK_WDT_REQ_SPM_SCPSYS_MARK, WD_REQ_RST_MODE);
/* g_ext_wd_drv.reques_mode_set(MTK_WDT_REQ_SPM_SCPSYS_MARK,WD_REQ_RST_MODE); */
} else {
res = -3;
}
return res;
}
static int thermal_mode_config(WD_REQ_CTL en, WD_REQ_MODE mode)
{
int res = 0;
if (WD_REQ_EN == en) {
/* g_ext_wd_drv.reques_en_set(MTK_WDT_REQ_SPM_THERMAL_MARK,WD_REQ_EN); */
res = mtk_wdt_request_en_set(MTK_WDT_REQ_SPM_THERMAL_MARK, WD_REQ_EN);
} else if (WD_REQ_DIS == en) {
/* g_ext_wd_drv.reques_en_set(MTK_WDT_REQ_SPM_THERMAL_MARK,WD_REQ_DIS); */
res = mtk_wdt_request_en_set(MTK_WDT_REQ_SPM_THERMAL_MARK, WD_REQ_DIS);
} else {
res = -2;
}
if (WD_REQ_IRQ_MODE == mode) {
/* g_ext_wd_drv.reques_mode_set(MTK_WDT_REQ_SPM_THERMAL_MARK,WD_REQ_IRQ_MODE); */
res = mtk_wdt_request_mode_set(MTK_WDT_REQ_SPM_THERMAL_MARK, WD_REQ_IRQ_MODE);
} else if (WD_REQ_RST_MODE == mode) {
/* g_ext_wd_drv.reques_mode_set(MTK_WDT_REQ_SPM_THERMAL_MARK,WD_REQ_RST_MODE); */
res = mtk_wdt_request_mode_set(MTK_WDT_REQ_SPM_THERMAL_MARK, WD_REQ_RST_MODE);
} else {
res = -3;
}
return res;
}
static int thermal_direct_mode_config(WD_REQ_CTL en, WD_REQ_MODE mode)
{
int res = 0;
printk("thermal_direct_mode_config(en:0x%x,mode:0x%x)\n", en, mode);
if (WD_REQ_EN == en) {
/* g_ext_wd_drv.reques_en_set(MTK_WDT_REQ_SPM_THERMAL_MARK,WD_REQ_EN); */
res = mtk_wdt_request_en_set(MTK_WDT_REQ_THERMAL_MARK, WD_REQ_EN);
} else if (WD_REQ_DIS == en) {
/* g_ext_wd_drv.reques_en_set(MTK_WDT_REQ_SPM_THERMAL_MARK,WD_REQ_DIS); */
res = mtk_wdt_request_en_set(MTK_WDT_REQ_THERMAL_MARK, WD_REQ_DIS);
} else {
res = -2;
}
if (WD_REQ_IRQ_MODE == mode) {
/* g_ext_wd_drv.reques_mode_set(MTK_WDT_REQ_SPM_THERMAL_MARK,WD_REQ_IRQ_MODE); */
res = mtk_wdt_request_mode_set(MTK_WDT_REQ_THERMAL_MARK, WD_REQ_IRQ_MODE);
} else if (WD_REQ_RST_MODE == mode) {
/* g_ext_wd_drv.reques_mode_set(MTK_WDT_REQ_SPM_THERMAL_MARK,WD_REQ_RST_MODE); */
res = mtk_wdt_request_mode_set(MTK_WDT_REQ_THERMAL_MARK, WD_REQ_RST_MODE);
} else {
res = -3;
}
return res;
}
static int wd_dram_reserved_mode(bool enabled)
{
int ret = 0;
if (true == enabled) {
mtk_wdt_swsysret_config(0x10000000, 1);
} else {
mtk_wdt_swsysret_config(0x10000000, 0);
}
return ret;
}
#else
/* dummy api */
static unsigned int wd_get_check_bit(void)
{
printk("dummy wd_get_check_bit");
return 0;
}
static unsigned int wd_get_kick_bit(void)
{
printk("dummy wd_get_kick_bit");
return 0;
}
static int wd_restart(enum wd_restart_type type)
{
printk("dummy wd_restart");
return 0;
}
static int wd_cpu_hot_plug_on_notify(int cpu)
{
int res = 0;
printk("dummy wd_cpu_hot_plug_on_notify");
return res;
}
static int wd_cpu_hot_plug_off_notify(int cpu)
{
int res = 0;
printk("dummy wd_cpu_hot_plug_off_notify");
return res;
}
static int wd_sw_reset(int type)
{
printk("dummy wd_sw_reset");
wdt_arch_reset(type);
return 0;
}
static int mtk_wk_wdt_config(enum ext_wdt_mode mode, int timeout_val)
{
printk("dummy mtk_wk_wdt_config");
return 0;
}
static int disable_ext(void)
{
printk("dummy disable_ext");
return 0;
}
static int disable_local(void)
{
printk("dummy disable_local");
return 0;
}
static int set_mode(enum ext_wdt_mode mode)
{
printk("dummy set_mode");
return 0;
}
static int confirm_hwreboot(void)
{
printk("dummy confirm_hwreboot");
return 0;
}
static void suspend_notify(void)
{
printk("dummy suspend_notify \n ");
}
static void resume_notify(void)
{
printk("dummy resume_notify \n ");
}
static int disable_all_wd(void)
{
printk("dummy disable_all_wd \n ");
return 0;
}
static int spmwdt_mode_config(WD_REQ_CTL en, WD_REQ_MODE mode)
{
int res = 0;
printk("dummy spmwdt_mode_config \n ");
return res;
}
static int thermal_mode_config(WD_REQ_CTL en, WD_REQ_MODE mode)
{
int res = 0;
printk("dummy thermal_mode_config \n ");
return res;
}
static int wd_dram_reserved_mode(bool enabled)
{
int res = 0;
printk("dummy wd_dram_reserved_mode \n ");
return res;
}
static int thermal_direct_mode_config(WD_REQ_CTL en, WD_REQ_MODE mode)
{
int res = 0;
printk("thermal_direct_mode_config in dummy driver (en:0x%x,mode:0x%x)\n", en, mode);
if (WD_REQ_EN == en) {
/* g_ext_wd_drv.reques_en_set(MTK_WDT_REQ_SPM_THERMAL_MARK,WD_REQ_EN); */
res = mtk_wdt_request_en_set(MTK_WDT_REQ_THERMAL_MARK, WD_REQ_EN);
} else if (WD_REQ_DIS == en) {
/* g_ext_wd_drv.reques_en_set(MTK_WDT_REQ_SPM_THERMAL_MARK,WD_REQ_DIS); */
res = mtk_wdt_request_en_set(MTK_WDT_REQ_THERMAL_MARK, WD_REQ_DIS);
} else {
res = -2;
}
if (WD_REQ_IRQ_MODE == mode) {
/* g_ext_wd_drv.reques_mode_set(MTK_WDT_REQ_SPM_THERMAL_MARK,WD_REQ_IRQ_MODE); */
res = mtk_wdt_request_mode_set(MTK_WDT_REQ_THERMAL_MARK, WD_REQ_IRQ_MODE);
} else if (WD_REQ_RST_MODE == mode) {
/* g_ext_wd_drv.reques_mode_set(MTK_WDT_REQ_SPM_THERMAL_MARK,WD_REQ_RST_MODE); */
res = mtk_wdt_request_mode_set(MTK_WDT_REQ_THERMAL_MARK, WD_REQ_RST_MODE);
} else {
res = -3;
}
return res;
}
#endif
/* public interface implimentation end */
int wd_api_init(void)
{
int i = 0;
long *check_p = NULL;
int api_size = 0;
api_size = (sizeof(g_wd_api_obj) / sizeof(long));
printk("wd api_size=%d\n", api_size);
/* check wd api */
check_p = (long *)&g_wd_api_obj;
for (i = 1; i < api_size; i++) {
printk("p[%d]=%lx\n", i, *(check_p + i));
if (0 == check_p[i]) {
printk("wd_api init fail the %d api not init\n", i);
g_wd_api_obj.ready = 0;
return -1;
}
}
printk("wd_api init ok\n");
return 0;
}
int get_wd_api(struct wd_api **obj)
{
int res = 0;
*obj = &g_wd_api_obj;
if (NULL == *obj) {
res = -1;
/* printk("get_wd_public_interface_obj null pointer error\n"); */
}
if ((*obj)->ready == 0) {
res = -2;
/* printk("get_wd_public_api not ready\n"); */
}
return res;
}
|