ARM: dts: rockchip: sort rk3288 dts by base adress
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rockchip / rk_pm_tests / clk_volt.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/rockchip/dvfs.h>
20
21 #include "rk_pm_tests.h"
22 #include "clk_volt.h"
23 /***************************************************************************/
24 ssize_t clk_volt_show(struct kobject *kobj, struct kobj_attribute *attr,
25                 char *buf)
26 {
27         char *str = buf;
28         str += sprintf(str, "usage:\n");
29         str += sprintf(str, "get voltage:get [regulaotr_name]\n");
30         str += sprintf(str, "set voltage:set [regulaotr_name] [voltage(uV)]\n");
31         str += sprintf(str, "set suspend voltage:set [regulaotr_name] [voltage(uV)+1]\n");
32         if (str != buf)
33                 *(str - 1) = '\n';
34         return (str - buf);
35
36 }
37
38 #define SET_SUSPEND_VOLT_FLAG   (1<<0)
39
40 ssize_t clk_volt_store(struct kobject *kobj, struct kobj_attribute *attr,
41                 const char *buf, size_t n)
42 {
43         
44         struct regulator *regulator;
45         char cmd[20], regulator_name[20];
46         unsigned int volt;
47         int need_put_regulator=0, ret=0;
48
49         sscanf(buf, "%s %s %u", cmd, regulator_name, &volt);
50
51         PM_DBG("%s: cmd(%s), regulator_name(%s), volt(%u)\n", 
52                 __func__, cmd, regulator_name, volt);
53
54         regulator = dvfs_get_regulator(regulator_name);
55         if (IS_ERR_OR_NULL(regulator)) {
56                 regulator = regulator_get(NULL, regulator_name);
57                 if (IS_ERR(regulator)){
58                         PM_ERR("%s: get dvfs_regulator %s error\n", __func__, regulator_name);
59                         return n;
60                 }
61                 need_put_regulator = 1;
62         }       
63
64         if (!strncmp(cmd, "set", strlen("set"))){
65                 if (volt & SET_SUSPEND_VOLT_FLAG){
66                         volt &= ~SET_SUSPEND_VOLT_FLAG;
67                         //ret = regulator_set_suspend_voltage(regulator, volt); 
68                         if (!ret)
69                                 PM_DBG("%s: set %s suspend volt to %u uV ok\n", __func__, regulator_name, volt);
70                         else
71                                 PM_DBG("%s: regulator_set_suspend_voltage err(%d)\n", __func__, ret);
72                 }else{
73                         ret = regulator_set_voltage(regulator, volt, volt); 
74                         if (!ret)
75                                 PM_DBG("%s: set %s volt to %u uV ok\n", __func__, regulator_name, regulator_get_voltage(regulator));
76                         else
77                                 PM_DBG("%s: regulator_set_voltage err(%d)\n", __func__, ret);
78                 }
79                 
80         }
81         if (!strncmp(cmd, "get", strlen("get"))){
82                 printk("%s: %s current is %d uV\n", 
83                         __func__, regulator_name, regulator_get_voltage(regulator));
84         }
85
86         if (need_put_regulator)
87                 regulator_put(regulator);
88
89         return n;
90 }
91