]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/device-ti-proprietary-open.git/blob - jacinto6/sgx_src/eurasia_km/services4/system/omap/sgxfreq_userspace.c
jacinto6: sgx: update DDK version to 1.12/2701748
[android-sdk/device-ti-proprietary-open.git] / jacinto6 / sgx_src / eurasia_km / services4 / system / omap / sgxfreq_userspace.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"
21 static int userspace_start(struct sgxfreq_sgx_data *data);
22 static void userspace_stop(void);
25 static struct sgxfreq_governor userspace_gov = {
26         .name = "userspace",
27         .gov_start = userspace_start,
28         .gov_stop = userspace_stop,
29 };
32 static struct userspace_data {
33         unsigned long freq_user; /* in Hz */
34 } usd;
37 /*********************** begin sysfs interface ***********************/
39 extern struct kobject *sgxfreq_kobj;
42 static ssize_t show_frequency_set(struct device *dev, struct device_attribute *attr,
43                             char *buf)
44 {
45         return sprintf(buf, "%lu\n", usd.freq_user);
46 }
49 static ssize_t store_frequency_set(struct device *dev,
50         struct device_attribute *attr, const char *buf, size_t count)
51 {
52         int ret;
53         unsigned long freq;
55         ret = sscanf(buf, "%lu", &freq);
56         if (ret != 1)
57                 return -EINVAL;
59         if (freq > sgxfreq_get_freq_max())
60                 freq = sgxfreq_get_freq_max();
61         usd.freq_user = sgxfreq_set_freq_request(freq);
62         trace_printk("USERSPACE: new freq=%luHz.\n", usd.freq_user);
64         return count;
65 }
68 static DEVICE_ATTR(frequency_set, 0644,
69         show_frequency_set, store_frequency_set);
72 static struct attribute *userspace_attributes[] = {
73         &dev_attr_frequency_set.attr,
74         NULL
75 };
78 static struct attribute_group userspace_attr_group = {
79         .attrs = userspace_attributes,
80         .name = "userspace",
81 };
83 /************************ end sysfs interface ************************/
86 int userspace_init(void)
87 {
88         int ret;
90         ret = sgxfreq_register_governor(&userspace_gov);
91         if (ret)
92                 return ret;
93         return 0;
94 }
97 int userspace_deinit(void)
98 {
99         return 0;
103 static int userspace_start(struct sgxfreq_sgx_data *data)
105         int ret;
107         usd.freq_user = sgxfreq_get_freq();
109         ret = sysfs_create_group(sgxfreq_kobj, &userspace_attr_group);
110         if (ret)
111                 return ret;
113         trace_printk("USERSPACE: started.\n");
115         return 0;
119 static void userspace_stop(void)
121         sysfs_remove_group(sgxfreq_kobj, &userspace_attr_group);
123         trace_printk("USERSPACE: stopped.\n");