diff options
Diffstat (limited to 'drivers/misc')
-rw-r--r-- | drivers/misc/hdpuftrs/hdpu_cpustate.c | 107 | ||||
-rw-r--r-- | drivers/misc/hdpuftrs/hdpu_nexus.c | 88 |
2 files changed, 122 insertions, 73 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 | ||
28 | static int hdpu_cpustate_probe(struct platform_device *pdev); | 30 | static int hdpu_cpustate_probe(struct platform_device *pdev); |
29 | static int hdpu_cpustate_remove(struct platform_device *pdev); | 31 | static int hdpu_cpustate_remove(struct platform_device *pdev); |
30 | 32 | ||
31 | struct cpustate_t cpustate; | 33 | static unsigned char cpustate_get_state(void); |
34 | static int cpustate_proc_open(struct inode *inode, struct file *file); | ||
35 | static int cpustate_proc_read(struct seq_file *seq, void *offset); | ||
36 | |||
37 | static struct cpustate_t cpustate; | ||
38 | |||
39 | static 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 | |||
47 | static int cpustate_proc_open(struct inode *inode, struct file *file) | ||
48 | { | ||
49 | return single_open(file, cpustate_proc_read, NULL); | ||
50 | } | ||
51 | |||
52 | static 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 | ||
33 | static int cpustate_get_ref(int excl) | 58 | static 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 | ||
69 | unsigned char cpustate_get_state(void) | 94 | static unsigned char cpustate_get_state(void) |
70 | { | 95 | { |
71 | 96 | ||
72 | return cpustate.cached_val; | 97 | return cpustate.cached_val; |
73 | } | 98 | } |
74 | 99 | ||
75 | void cpustate_set_state(unsigned char new_state) | 100 | static 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 | */ | ||
140 | static 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 | |||
160 | static struct platform_driver hdpu_cpustate_driver = { | 162 | static 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 | */ |
171 | static const struct file_operations cpustate_fops = { | 173 | static 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 | ||
184 | static struct miscdevice cpustate_dev = { | 182 | static 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 | ||
190 | static int hdpu_cpustate_probe(struct platform_device *pdev) | 188 | static 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 | ||
219 | static int hdpu_cpustate_remove(struct platform_device *pdev) | 225 | static 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 | ||
231 | static int __init cpustate_init(void) | 236 | static 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 | ||
238 | static void __exit cpustate_exit(void) | 241 | static void __exit cpustate_exit(void) |
diff --git a/drivers/misc/hdpuftrs/hdpu_nexus.c b/drivers/misc/hdpuftrs/hdpu_nexus.c index 60c8b26f0678..2887b2147980 100644 --- a/drivers/misc/hdpuftrs/hdpu_nexus.c +++ b/drivers/misc/hdpuftrs/hdpu_nexus.c | |||
@@ -18,17 +18,38 @@ | |||
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/proc_fs.h> | 19 | #include <linux/proc_fs.h> |
20 | #include <linux/hdpu_features.h> | 20 | #include <linux/hdpu_features.h> |
21 | |||
22 | #include <linux/platform_device.h> | 21 | #include <linux/platform_device.h> |
22 | #include <linux/seq_file.h> | ||
23 | #include <asm/io.h> | ||
23 | 24 | ||
24 | static int hdpu_nexus_probe(struct platform_device *pdev); | 25 | static int hdpu_nexus_probe(struct platform_device *pdev); |
25 | static int hdpu_nexus_remove(struct platform_device *pdev); | 26 | static int hdpu_nexus_remove(struct platform_device *pdev); |
27 | static int hdpu_slot_id_open(struct inode *inode, struct file *file); | ||
28 | static int hdpu_slot_id_read(struct seq_file *seq, void *offset); | ||
29 | static int hdpu_chassis_id_open(struct inode *inode, struct file *file); | ||
30 | static int hdpu_chassis_id_read(struct seq_file *seq, void *offset); | ||
26 | 31 | ||
27 | static struct proc_dir_entry *hdpu_slot_id; | 32 | static struct proc_dir_entry *hdpu_slot_id; |
28 | static struct proc_dir_entry *hdpu_chassis_id; | 33 | static struct proc_dir_entry *hdpu_chassis_id; |
29 | static int slot_id = -1; | 34 | static int slot_id = -1; |
30 | static int chassis_id = -1; | 35 | static int chassis_id = -1; |
31 | 36 | ||
37 | static const struct file_operations proc_slot_id = { | ||
38 | .open = hdpu_slot_id_open, | ||
39 | .read = seq_read, | ||
40 | .llseek = seq_lseek, | ||
41 | .release = single_release, | ||
42 | .owner = THIS_MODULE, | ||
43 | }; | ||
44 | |||
45 | static const struct file_operations proc_chassis_id = { | ||
46 | .open = hdpu_chassis_id_open, | ||
47 | .read = seq_read, | ||
48 | .llseek = seq_lseek, | ||
49 | .release = single_release, | ||
50 | .owner = THIS_MODULE, | ||
51 | }; | ||
52 | |||
32 | static struct platform_driver hdpu_nexus_driver = { | 53 | static struct platform_driver hdpu_nexus_driver = { |
33 | .probe = hdpu_nexus_probe, | 54 | .probe = hdpu_nexus_probe, |
34 | .remove = hdpu_nexus_remove, | 55 | .remove = hdpu_nexus_remove, |
@@ -37,43 +58,67 @@ static struct platform_driver hdpu_nexus_driver = { | |||
37 | }, | 58 | }, |
38 | }; | 59 | }; |
39 | 60 | ||
40 | int hdpu_slot_id_read(char *buffer, char **buffer_location, off_t offset, | 61 | static int hdpu_slot_id_open(struct inode *inode, struct file *file) |
41 | int buffer_length, int *zero, void *ptr) | ||
42 | { | 62 | { |
63 | return single_open(file, hdpu_slot_id_read, NULL); | ||
64 | } | ||
43 | 65 | ||
44 | if (offset > 0) | 66 | static int hdpu_slot_id_read(struct seq_file *seq, void *offset) |
45 | return 0; | 67 | { |
46 | return sprintf(buffer, "%d\n", slot_id); | 68 | seq_printf(seq, "%d\n", slot_id); |
69 | return 0; | ||
47 | } | 70 | } |
48 | 71 | ||
49 | int hdpu_chassis_id_read(char *buffer, char **buffer_location, off_t offset, | 72 | static int hdpu_chassis_id_open(struct inode *inode, struct file *file) |
50 | int buffer_length, int *zero, void *ptr) | ||
51 | { | 73 | { |
74 | return single_open(file, hdpu_chassis_id_read, NULL); | ||
75 | } | ||
52 | 76 | ||
53 | if (offset > 0) | 77 | static int hdpu_chassis_id_read(struct seq_file *seq, void *offset) |
54 | return 0; | 78 | { |
55 | return sprintf(buffer, "%d\n", chassis_id); | 79 | seq_printf(seq, "%d\n", chassis_id); |
80 | return 0; | ||
56 | } | 81 | } |
57 | 82 | ||
58 | static int hdpu_nexus_probe(struct platform_device *pdev) | 83 | static int hdpu_nexus_probe(struct platform_device *pdev) |
59 | { | 84 | { |
60 | struct resource *res; | 85 | struct resource *res; |
86 | int *nexus_id_addr; | ||
61 | 87 | ||
62 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 88 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
63 | int *nexus_id_addr; | 89 | if (!res) { |
64 | nexus_id_addr = | 90 | printk(KERN_ERR "sky_nexus: " |
65 | ioremap(res->start, (unsigned long)(res->end - res->start)); | 91 | "Invalid memory resource.\n"); |
92 | return -EINVAL; | ||
93 | } | ||
94 | nexus_id_addr = ioremap(res->start, | ||
95 | (unsigned long)(res->end - res->start)); | ||
66 | if (nexus_id_addr) { | 96 | if (nexus_id_addr) { |
67 | slot_id = (*nexus_id_addr >> 8) & 0x1f; | 97 | slot_id = (*nexus_id_addr >> 8) & 0x1f; |
68 | chassis_id = *nexus_id_addr & 0xff; | 98 | chassis_id = *nexus_id_addr & 0xff; |
69 | iounmap(nexus_id_addr); | 99 | iounmap(nexus_id_addr); |
70 | } else | 100 | } else { |
71 | printk("Could not map slot id\n"); | 101 | printk(KERN_ERR "sky_nexus: Could not map slot id\n"); |
102 | } | ||
103 | |||
72 | hdpu_slot_id = create_proc_entry("sky_slot_id", 0666, &proc_root); | 104 | hdpu_slot_id = create_proc_entry("sky_slot_id", 0666, &proc_root); |
73 | hdpu_slot_id->read_proc = hdpu_slot_id_read; | 105 | if (!hdpu_slot_id) { |
106 | printk(KERN_WARNING "sky_nexus: " | ||
107 | "Unable to create proc dir entry: sky_slot_id\n"); | ||
108 | } else { | ||
109 | hdpu_slot_id->proc_fops = &proc_slot_id; | ||
110 | hdpu_slot_id->owner = THIS_MODULE; | ||
111 | } | ||
74 | 112 | ||
75 | hdpu_chassis_id = create_proc_entry("sky_chassis_id", 0666, &proc_root); | 113 | hdpu_chassis_id = create_proc_entry("sky_chassis_id", 0666, &proc_root); |
76 | hdpu_chassis_id->read_proc = hdpu_chassis_id_read; | 114 | if (!hdpu_chassis_id) { |
115 | printk(KERN_WARNING "sky_nexus: " | ||
116 | "Unable to create proc dir entry: sky_chassis_id\n"); | ||
117 | } else { | ||
118 | hdpu_chassis_id->proc_fops = &proc_chassis_id; | ||
119 | hdpu_chassis_id->owner = THIS_MODULE; | ||
120 | } | ||
121 | |||
77 | return 0; | 122 | return 0; |
78 | } | 123 | } |
79 | 124 | ||
@@ -81,18 +126,19 @@ static int hdpu_nexus_remove(struct platform_device *pdev) | |||
81 | { | 126 | { |
82 | slot_id = -1; | 127 | slot_id = -1; |
83 | chassis_id = -1; | 128 | chassis_id = -1; |
129 | |||
84 | remove_proc_entry("sky_slot_id", &proc_root); | 130 | remove_proc_entry("sky_slot_id", &proc_root); |
85 | remove_proc_entry("sky_chassis_id", &proc_root); | 131 | remove_proc_entry("sky_chassis_id", &proc_root); |
132 | |||
86 | hdpu_slot_id = 0; | 133 | hdpu_slot_id = 0; |
87 | hdpu_chassis_id = 0; | 134 | hdpu_chassis_id = 0; |
135 | |||
88 | return 0; | 136 | return 0; |
89 | } | 137 | } |
90 | 138 | ||
91 | static int __init nexus_init(void) | 139 | static int __init nexus_init(void) |
92 | { | 140 | { |
93 | int rc; | 141 | return platform_driver_register(&hdpu_nexus_driver); |
94 | rc = platform_driver_register(&hdpu_nexus_driver); | ||
95 | return rc; | ||
96 | } | 142 | } |
97 | 143 | ||
98 | static void __exit nexus_exit(void) | 144 | static void __exit nexus_exit(void) |