ARM: dts: rockchip: sort rk3288 dts by base adress
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rockchip / rk_pm_tests / dvfs_table_scan.c
1 #include <linux/clk.h>
2 #include <linux/kobject.h>
3 #include <linux/string.h>
4 #include <linux/resume-trace.h>
5 #include <linux/workqueue.h>
6 #include <linux/mutex.h>
7 #include <linux/module.h>
8 #include <linux/syscalls.h>
9 #include <linux/init.h>
10 #include <linux/interrupt.h>
11 #include <linux/delay.h>
12 #include <linux/cpu.h>
13 #include <linux/slab.h>
14 #include <linux/dma-mapping.h>
15 #include <linux/regulator/machine.h>
16 #include <linux/mfd/wm831x/core.h>
17 #include <linux/sysfs.h>
18 #include <linux/err.h>
19 #include <linux/watchdog.h>
20
21 #include <linux/fs.h>
22 #include <asm/unistd.h>
23 #include <asm/uaccess.h>
24 #include "rk_pm_tests.h"
25 #include "rk_pm_tests.h"
26 #include "dvfs_table_scan.h"
27 /***************************************************************************/
28 void rk29_wdt_start(void);
29 void rk29_wdt_stop(void);
30 void rk29_wdt_keepalive(void);
31 int rk29_wdt_set_heartbeat(int timeout);
32
33 #define ALIVE_INTERVAL                  2       //s
34 #define WATCHDOG_TIMEOUT                (10*ALIVE_INTERVAL)
35 #define RESERVE_TIME_FOR_TIMEOUT        600000  //ms
36
37 ssize_t dvfs_table_scan_show(struct kobject *kobj, struct kobj_attribute *attr,
38                 char *buf)
39 {
40         char *str = buf;
41         str += sprintf(str, "start: \tstart scan dvfs table, send alive every 2s\n"
42                         "stop: \tstop send alive signal\n");
43         if (str != buf)
44                 *(str - 1) = '\n';
45         return (str - buf);
46
47 }
48
49 ssize_t dvfs_table_scan_store(struct kobject *kobj, struct kobj_attribute *attr,
50                 const char *buf, size_t n)
51 {
52         char cmd[20];
53         int cur_test_need_time=0; //ms
54         static int cur_test_timeout_cnt = 0;
55
56         sscanf(buf, "%s %d", cmd, &cur_test_need_time);
57         
58         PM_DBG("%s: cmd(%s), cur_test_need_time(%d)\n", __func__, cmd, cur_test_need_time);
59                 
60         if (!strncmp(cmd, "start", strlen("start"))) {
61                 if (cur_test_need_time == 0)
62                         return n;
63                 cur_test_timeout_cnt = (cur_test_need_time + RESERVE_TIME_FOR_TIMEOUT)/1000/ALIVE_INTERVAL;
64                 rk29_wdt_start();
65                 rk29_wdt_set_heartbeat(WATCHDOG_TIMEOUT);
66         } else if (!strncmp(cmd, "alive", strlen("alive"))) {
67                 printk("cur_test_timeout_cnt:%d\n", cur_test_timeout_cnt);
68                 if (cur_test_timeout_cnt-- > 0)         
69                         rk29_wdt_keepalive();
70
71         } else if (!strncmp(cmd, "stop", strlen("stop"))) {
72                 cur_test_timeout_cnt = -1;
73                 rk29_wdt_stop();
74         }
75
76         return n;
77 }