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>
21 #include <asm/unistd.h>
22 #include <asm/uaccess.h>
23 #include <linux/rockchip/dvfs.h>
25 #include "rk_pm_tests.h"
27 /***************************************************************************/
28 #define FILE_GOV_MODE "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
31 static int file_read(char *file_path, char *buf)
33 struct file *file = NULL;
37 PM_DBG("%s: read %s\n", __func__, file_path);
38 file = filp_open(file_path, O_RDONLY, 0);
41 PM_ERR("%s: error open file %s\n", __func__, file_path);
48 file->f_op->read(file, (char *)buf, 32, &offset);
49 sscanf(buf, "%s", buf);
52 filp_close(file, NULL);
61 static int file_write(char *file_path, char *buf)
63 struct file *file = NULL;
67 PM_DBG("%s: write %s %s size = %d\n", __func__,
68 file_path, buf, (int)strlen(buf));
69 file = filp_open(file_path, O_RDWR, 0);
72 PM_ERR("%s: error open file %s\n", __func__, file_path);
79 file->f_op->write(file, (char *)buf, strlen(buf), &offset);
82 filp_close(file, NULL);
90 ssize_t clk_rate_show(struct kobject *kobj, struct kobj_attribute *attr,
94 str += sprintf(str, "set [clk_name] [rate(Hz)]\n"
95 "rawset [clk_name] [rate(Hz)]\n");
102 ssize_t clk_rate_store(struct kobject *kobj, struct kobj_attribute *attr,
103 const char *buf, size_t n)
105 struct dvfs_node *clk_dvfs_node = NULL;
107 char cmd[20], clk_name[20];
108 unsigned long rate=0;
111 sscanf(buf, "%s %s %lu", cmd, clk_name, &rate);
113 PM_DBG("%s: cmd(%s), clk_name(%s), rate(%lu)\n", __func__, cmd, clk_name, rate);
115 if (!strncmp(cmd, "set", strlen("set"))) {
116 clk_dvfs_node = clk_get_dvfs_node(clk_name);
117 if (!clk_dvfs_node) {
118 PM_ERR("%s: clk(%s) get dvfs node error\n", __func__, clk_name);
122 if (!strncmp(clk_name, "clk_core", strlen("clk_core"))) {
123 if (file_write(FILE_GOV_MODE, "userspace") != 0) {
124 PM_ERR("%s: set current governor error\n", __func__);
129 ret = dvfs_clk_enable_limit(clk_dvfs_node, rate, rate);
131 clk = clk_get(NULL, clk_name);
132 if (IS_ERR_OR_NULL(clk)) {
133 PM_ERR("%s: get clk(%s) err(%ld)\n",
134 __func__, clk_name, PTR_ERR(clk));
138 if (!strncmp(cmd, "rawset", strlen("rawset"))) {
139 ret = clk_set_rate(clk, rate);
140 } else if (!strncmp(cmd, "open", strlen("open"))) {
141 ret = clk_prepare_enable(clk);
142 } else if (!strncmp(cmd, "close", strlen("close"))) {
143 clk_disable_unprepare(clk);
148 PM_ERR("%s: set rate err(%d)", __func__, ret);