1ab12bf0fd5a5a73919dec3f492e1d337beb22c8
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rockchip / rk_pm_tests / rk_pm_tests.c
1 /* arch/arm/mach-rk30/rk_pm_tests.c
2  *
3  * Copyright (C) 2010 ROCKCHIP, Inc.
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  */
15
16
17 /*************************************************************************/
18 /*        COPYRIGHT (C)  ROCK-CHIPS FUZHOU . ALL RIGHTS RESERVED.*/
19 /*************************************************************************
20 FILE            :         rk_pm_tests.c
21 DESC            :         Power management in dynning state
22 AUTHOR          :         chenxing
23 DATE            :         2012-7-2
24 NOTES           :
25 $LOG: GPIO.C,V $
26 REVISION 0.01
27 #include <linux/clk.h>
28 #include <linux/kobject.h>
29  ***************************************************************************/
30 #include <linux/string.h>
31 #include <linux/resume-trace.h>
32 #include <linux/workqueue.h>
33 #include <linux/mutex.h>
34 #include <linux/module.h>
35 #include <linux/syscalls.h>
36 #include <linux/init.h>
37 #include <linux/interrupt.h>
38 #include <linux/delay.h>
39 #include <linux/cpu.h>
40 #include <linux/slab.h>
41 #include <linux/dma-mapping.h>
42 #include <linux/regulator/machine.h>
43 #include <linux/mfd/wm831x/core.h>
44 #include <linux/sysfs.h>
45 #include <linux/err.h>
46
47 #include "rk_pm_tests.h"
48 #include "clk_rate.h"
49 #include "clk_volt.h"
50 #include "cpu_usage.h"
51 #include "dvfs_table_scan.h"
52
53 struct kobject *rk_pm_tests_kobj=NULL;
54 struct pm_attribute {
55         struct attribute        attr;
56         ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,
57                         char *buf);
58         ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
59                         const char *buf, size_t n);
60 };
61
62 extern ssize_t pvtm_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf);
63 extern ssize_t pvtm_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t n);
64
65 static struct pm_attribute pm_attrs[] = {
66         /* node_name    permision       show_func       store_func*/
67         __ATTR(clk_rate, S_IRUGO | S_IWUSR | S_IWUGO, clk_rate_show, clk_rate_store),
68         __ATTR(clk_volt, S_IRUGO | S_IWUSR | S_IWUGO, clk_volt_show, clk_volt_store),
69         __ATTR(dvfs_table_scan, S_IRUGO | S_IWUSR | S_IWUGO, dvfs_table_scan_show, dvfs_table_scan_store),
70         __ATTR(cpu_usage, S_IRUGO | S_IWUSR, cpu_usage_show, cpu_usage_store),
71         __ATTR(pvtm, S_IRUGO | S_IWUSR, pvtm_show, pvtm_store),
72 /*
73         __ATTR(maxfreq_volt, S_IRUGO | S_IWUSR, maxfreq_show, maxfreq_store),
74         __ATTR(freq_limit, S_IRUGO | S_IWUSR, freq_limit_show, freq_limit_store),
75         __ATTR(cpu_usage, S_IRUGO | S_IWUSR, cpu_usage_show, cpu_usage_store),
76         __ATTR(auto_wakeup, S_IRUGO | S_IWUSR, auto_wakeup_show, auto_wakeup_store),
77         __ATTR(suspend_test,   S_IRUGO | S_IWUSR,   suspend_test_show, suspend_test_store),
78         __ATTR(clk_auto_volt, S_IRUGO | S_IWUSR, clk_auto_volt_show, clk_auto_volt_store),
79 */
80 };
81
82 static void __exit rk_pm_tests_exit(void)
83 {
84         kobject_put(rk_pm_tests_kobj);
85 }
86
87 struct kobject *get_rk_pm_tests_kobj(void)
88 {
89
90     if(rk_pm_tests_kobj==NULL)
91     {
92         rk_pm_tests_kobj = kobject_create_and_add("pm_tests", NULL);
93
94         if (!rk_pm_tests_kobj)
95                 return NULL;
96     }
97     return rk_pm_tests_kobj;
98 }
99
100 int rk_pm_tests_kobj_atrradd(const struct attribute *attr)
101 {
102     int ret;
103     struct kobject * pm_kobj;
104     pm_kobj =get_rk_pm_tests_kobj();
105
106     if (!pm_kobj)
107     return -ENOMEM;
108
109     ret = sysfs_create_file(pm_kobj,attr);
110     if (ret != 0) {
111         PM_ERR("pm tests create %s node error\n",attr->name);
112         return ret;
113     }
114     return ret;
115 }
116
117 static int __init rk_pm_tests_init(void)
118 {
119         int i, ret = 0;
120          struct kobject * pm_kobj;
121         pm_kobj =get_rk_pm_tests_kobj();
122
123         if (!pm_kobj)
124                 return -ENOMEM;
125
126         for (i = 0; i < ARRAY_SIZE(pm_attrs); i++) {
127                 ret = sysfs_create_file(pm_kobj, &pm_attrs[i].attr);
128                 if (ret != 0) {
129                         PM_ERR("create index %d error\n", i);
130                         return ret;
131                 }
132         }
133         
134         return ret;
135 }
136
137 late_initcall(rk_pm_tests_init);
138 module_exit(rk_pm_tests_exit);