[android-sdk/device-ti-proprietary-open.git] / jacinto6 / sgx_src / eurasia_km / services4 / system / omap4 / sgxfreq_activeidle.c
1 /*
2 * Copyright (C) 2012 Texas Instruments, Inc
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17 #include <linux/sysfs.h>
18 #include "sgxfreq.h"
20 static int activeidle_start(struct sgxfreq_sgx_data *data);
21 static void activeidle_stop(void);
22 static void activeidle_sgx_active(void);
23 static void activeidle_sgx_idle(void);
25 static struct activeidle_data {
26 unsigned long freq_active;
27 unsigned long freq_idle;
28 struct mutex mutex;
29 bool sgx_active;
30 } aid;
32 static struct sgxfreq_governor activeidle_gov = {
33 .name = "activeidle",
34 .gov_start = activeidle_start,
35 .gov_stop = activeidle_stop,
36 .sgx_active = activeidle_sgx_active,
37 .sgx_idle = activeidle_sgx_idle,
38 };
40 /*********************** begin sysfs interface ***********************/
42 extern struct kobject *sgxfreq_kobj;
44 static ssize_t show_freq_active(struct device *dev,
45 struct device_attribute *attr,
46 char *buf)
47 {
48 return sprintf(buf, "%lu\n", aid.freq_active);
49 }
51 static ssize_t store_freq_active(struct device *dev,
52 struct device_attribute *attr,
53 const char *buf, size_t count)
54 {
55 int ret;
56 unsigned long freq;
58 ret = sscanf(buf, "%lu", &freq);
59 if (ret != 1)
60 return -EINVAL;
62 freq = sgxfreq_get_freq_ceil(freq);
64 mutex_lock(&aid.mutex);
66 aid.freq_active = freq;
67 if (aid.sgx_active)
68 sgxfreq_set_freq_request(aid.freq_active);
70 mutex_unlock(&aid.mutex);
72 return count;
73 }
75 static ssize_t show_freq_idle(struct device *dev, struct device_attribute *attr,
76 char *buf)
77 {
78 return sprintf(buf, "%lu\n", aid.freq_idle);
79 }
81 static ssize_t store_freq_idle(struct device *dev, struct device_attribute *attr,
82 const char *buf, size_t count)
83 {
84 int ret;
85 unsigned long freq;
87 ret = sscanf(buf, "%lu", &freq);
88 if (ret != 1)
89 return -EINVAL;
91 freq = sgxfreq_get_freq_floor(freq);
93 mutex_lock(&aid.mutex);
95 aid.freq_idle = freq;
96 if (!aid.sgx_active)
97 sgxfreq_set_freq_request(aid.freq_idle);
99 mutex_unlock(&aid.mutex);
101 return count;
102 }
103 static DEVICE_ATTR(freq_active, 0644, show_freq_active, store_freq_active);
104 static DEVICE_ATTR(freq_idle, 0644, show_freq_idle, store_freq_idle);
106 static struct attribute *activeidle_attributes[] = {
107 &dev_attr_freq_active.attr,
108 &dev_attr_freq_idle.attr,
109 NULL
110 };
112 static struct attribute_group activeidle_attr_group = {
113 .attrs = activeidle_attributes,
114 .name = "activeidle",
115 };
117 /************************ end sysfs interface ************************/
119 int activeidle_init(void)
120 {
121 int ret;
123 mutex_init(&aid.mutex);
125 ret = sgxfreq_register_governor(&activeidle_gov);
126 if (ret)
127 return ret;
129 aid.freq_idle = sgxfreq_get_freq_min();
130 aid.freq_active = sgxfreq_get_freq_max();
132 return 0;
133 }
135 int activeidle_deinit(void)
136 {
137 return 0;
138 }
140 static int activeidle_start(struct sgxfreq_sgx_data *data)
141 {
142 int ret;
144 aid.sgx_active = data->active;
146 ret = sysfs_create_group(sgxfreq_kobj, &activeidle_attr_group);
147 if (ret)
148 return ret;
150 if (aid.sgx_active)
151 sgxfreq_set_freq_request(aid.freq_active);
152 else
153 sgxfreq_set_freq_request(aid.freq_idle);
155 return 0;
156 }
158 static void activeidle_stop(void)
159 {
160 sysfs_remove_group(sgxfreq_kobj, &activeidle_attr_group);
161 }
163 static void activeidle_sgx_active(void)
164 {
165 mutex_lock(&aid.mutex);
167 aid.sgx_active = true;
168 sgxfreq_set_freq_request(aid.freq_active);
170 mutex_unlock(&aid.mutex);
171 }
173 static void activeidle_sgx_idle(void)
174 {
175 mutex_lock(&aid.mutex);
177 aid.sgx_active = false;
178 sgxfreq_set_freq_request(aid.freq_idle);
180 mutex_unlock(&aid.mutex);
181 }