aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/hdpuftrs/hdpu_cpustate.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc/hdpuftrs/hdpu_cpustate.c')
-rw-r--r--drivers/misc/hdpuftrs/hdpu_cpustate.c107
1 files changed, 55 insertions, 52 deletions
diff --git a/drivers/misc/hdpuftrs/hdpu_cpustate.c b/drivers/misc/hdpuftrs/hdpu_cpustate.c
index 276ba3c5143f..aa8ce7abe922 100644
--- a/drivers/misc/hdpuftrs/hdpu_cpustate.c
+++ b/drivers/misc/hdpuftrs/hdpu_cpustate.c
@@ -19,16 +19,41 @@
19#include <linux/spinlock.h> 19#include <linux/spinlock.h>
20#include <linux/miscdevice.h> 20#include <linux/miscdevice.h>
21#include <linux/proc_fs.h> 21#include <linux/proc_fs.h>
22#include <linux/hdpu_features.h>
22#include <linux/platform_device.h> 23#include <linux/platform_device.h>
23#include <asm/uaccess.h> 24#include <asm/uaccess.h>
24#include <linux/hdpu_features.h> 25#include <linux/seq_file.h>
26#include <asm/io.h>
25 27
26#define SKY_CPUSTATE_VERSION "1.1" 28#define SKY_CPUSTATE_VERSION "1.1"
27 29
28static int hdpu_cpustate_probe(struct platform_device *pdev); 30static int hdpu_cpustate_probe(struct platform_device *pdev);
29static int hdpu_cpustate_remove(struct platform_device *pdev); 31static int hdpu_cpustate_remove(struct platform_device *pdev);
30 32
31struct cpustate_t cpustate; 33static unsigned char cpustate_get_state(void);
34static int cpustate_proc_open(struct inode *inode, struct file *file);
35static int cpustate_proc_read(struct seq_file *seq, void *offset);
36
37static struct cpustate_t cpustate;
38
39static const struct file_operations proc_cpustate = {
40 .open = cpustate_proc_open,
41 .read = seq_read,
42 .llseek = seq_lseek,
43 .release = single_release,
44 .owner = THIS_MODULE,
45};
46
47static int cpustate_proc_open(struct inode *inode, struct file *file)
48{
49 return single_open(file, cpustate_proc_read, NULL);
50}
51
52static int cpustate_proc_read(struct seq_file *seq, void *offset)
53{
54 seq_printf(seq, "CPU State: %04x\n", cpustate_get_state());
55 return 0;
56}
32 57
33static int cpustate_get_ref(int excl) 58static int cpustate_get_ref(int excl)
34{ 59{
@@ -66,13 +91,13 @@ static int cpustate_free_ref(void)
66 return 0; 91 return 0;
67} 92}
68 93
69unsigned char cpustate_get_state(void) 94static unsigned char cpustate_get_state(void)
70{ 95{
71 96
72 return cpustate.cached_val; 97 return cpustate.cached_val;
73} 98}
74 99
75void cpustate_set_state(unsigned char new_state) 100static void cpustate_set_state(unsigned char new_state)
76{ 101{
77 unsigned int state = (new_state << 21); 102 unsigned int state = (new_state << 21);
78 103
@@ -134,29 +159,6 @@ static int cpustate_release(struct inode *inode, struct file *file)
134 return cpustate_free_ref(); 159 return cpustate_free_ref();
135} 160}
136 161
137/*
138 * Info exported via "/proc/sky_cpustate".
139 */
140static int cpustate_read_proc(char *page, char **start, off_t off,
141 int count, int *eof, void *data)
142{
143 char *p = page;
144 int len = 0;
145
146 p += sprintf(p, "CPU State: %04x\n", cpustate_get_state());
147 len = p - page;
148
149 if (len <= off + count)
150 *eof = 1;
151 *start = page + off;
152 len -= off;
153 if (len > count)
154 len = count;
155 if (len < 0)
156 len = 0;
157 return len;
158}
159
160static struct platform_driver hdpu_cpustate_driver = { 162static struct platform_driver hdpu_cpustate_driver = {
161 .probe = hdpu_cpustate_probe, 163 .probe = hdpu_cpustate_probe,
162 .remove = hdpu_cpustate_remove, 164 .remove = hdpu_cpustate_remove,
@@ -169,22 +171,18 @@ static struct platform_driver hdpu_cpustate_driver = {
169 * The various file operations we support. 171 * The various file operations we support.
170 */ 172 */
171static const struct file_operations cpustate_fops = { 173static const struct file_operations cpustate_fops = {
172 owner:THIS_MODULE, 174 .owner = THIS_MODULE,
173 open:cpustate_open, 175 .open = cpustate_open,
174 release:cpustate_release, 176 .release = cpustate_release,
175 read:cpustate_read, 177 .read = cpustate_read,
176 write:cpustate_write, 178 .write = cpustate_write,
177 fasync:NULL, 179 .llseek = no_llseek,
178 poll:NULL,
179 ioctl:NULL,
180 llseek:no_llseek,
181
182}; 180};
183 181
184static struct miscdevice cpustate_dev = { 182static struct miscdevice cpustate_dev = {
185 MISC_DYNAMIC_MINOR, 183 .minor = MISC_DYNAMIC_MINOR,
186 "sky_cpustate", 184 .name = "sky_cpustate",
187 &cpustate_fops 185 .fops = &cpustate_fops,
188}; 186};
189 187
190static int hdpu_cpustate_probe(struct platform_device *pdev) 188static int hdpu_cpustate_probe(struct platform_device *pdev)
@@ -194,23 +192,31 @@ static int hdpu_cpustate_probe(struct platform_device *pdev)
194 int ret; 192 int ret;
195 193
196 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 194 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
195 if (!res) {
196 printk(KERN_ERR "sky_cpustate: "
197 "Invalid memory resource.\n");
198 return -EINVAL;
199 }
197 cpustate.set_addr = (unsigned long *)res->start; 200 cpustate.set_addr = (unsigned long *)res->start;
198 cpustate.clr_addr = (unsigned long *)res->end - 1; 201 cpustate.clr_addr = (unsigned long *)res->end - 1;
199 202
200 ret = misc_register(&cpustate_dev); 203 ret = misc_register(&cpustate_dev);
201 if (ret) { 204 if (ret) {
202 printk(KERN_WARNING "sky_cpustate: Unable to register misc " 205 printk(KERN_WARNING "sky_cpustate: "
203 "device.\n"); 206 "Unable to register misc device.\n");
204 cpustate.set_addr = NULL; 207 cpustate.set_addr = NULL;
205 cpustate.clr_addr = NULL; 208 cpustate.clr_addr = NULL;
206 return ret; 209 return ret;
207 } 210 }
208 211
209 proc_de = create_proc_read_entry("sky_cpustate", 0, 0, 212 proc_de = create_proc_entry("sky_cpustate", 0666, &proc_root);
210 cpustate_read_proc, NULL); 213 if (!proc_de) {
211 if (proc_de == NULL) 214 printk(KERN_WARNING "sky_cpustate: "
212 printk(KERN_WARNING "sky_cpustate: Unable to create proc " 215 "Unable to create proc entry\n");
213 "dir entry\n"); 216 } else {
217 proc_de->proc_fops = &proc_cpustate;
218 proc_de->owner = THIS_MODULE;
219 }
214 220
215 printk(KERN_INFO "Sky CPU State Driver v" SKY_CPUSTATE_VERSION "\n"); 221 printk(KERN_INFO "Sky CPU State Driver v" SKY_CPUSTATE_VERSION "\n");
216 return 0; 222 return 0;
@@ -218,21 +224,18 @@ static int hdpu_cpustate_probe(struct platform_device *pdev)
218 224
219static int hdpu_cpustate_remove(struct platform_device *pdev) 225static int hdpu_cpustate_remove(struct platform_device *pdev)
220{ 226{
221
222 cpustate.set_addr = NULL; 227 cpustate.set_addr = NULL;
223 cpustate.clr_addr = NULL; 228 cpustate.clr_addr = NULL;
224 229
225 remove_proc_entry("sky_cpustate", NULL); 230 remove_proc_entry("sky_cpustate", NULL);
226 misc_deregister(&cpustate_dev); 231 misc_deregister(&cpustate_dev);
227 return 0;
228 232
233 return 0;
229} 234}
230 235
231static int __init cpustate_init(void) 236static int __init cpustate_init(void)
232{ 237{
233 int rc; 238 return platform_driver_register(&hdpu_cpustate_driver);
234 rc = platform_driver_register(&hdpu_cpustate_driver);
235 return rc;
236} 239}
237 240
238static void __exit cpustate_exit(void) 241static void __exit cpustate_exit(void)