diff options
Diffstat (limited to 'arch/ppc64/kernel/rtas-proc.c')
-rw-r--r-- | arch/ppc64/kernel/rtas-proc.c | 807 |
1 files changed, 807 insertions, 0 deletions
diff --git a/arch/ppc64/kernel/rtas-proc.c b/arch/ppc64/kernel/rtas-proc.c new file mode 100644 index 000000000000..28b1f1521f21 --- /dev/null +++ b/arch/ppc64/kernel/rtas-proc.c | |||
@@ -0,0 +1,807 @@ | |||
1 | /* | ||
2 | * arch/ppc64/kernel/rtas-proc.c | ||
3 | * Copyright (C) 2000 Tilmann Bitterberg | ||
4 | * (tilmann@bitterberg.de) | ||
5 | * | ||
6 | * RTAS (Runtime Abstraction Services) stuff | ||
7 | * Intention is to provide a clean user interface | ||
8 | * to use the RTAS. | ||
9 | * | ||
10 | * TODO: | ||
11 | * Split off a header file and maybe move it to a different | ||
12 | * location. Write Documentation on what the /proc/rtas/ entries | ||
13 | * actually do. | ||
14 | */ | ||
15 | |||
16 | #include <linux/errno.h> | ||
17 | #include <linux/sched.h> | ||
18 | #include <linux/proc_fs.h> | ||
19 | #include <linux/stat.h> | ||
20 | #include <linux/ctype.h> | ||
21 | #include <linux/time.h> | ||
22 | #include <linux/string.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/seq_file.h> | ||
25 | #include <linux/bitops.h> | ||
26 | |||
27 | #include <asm/uaccess.h> | ||
28 | #include <asm/processor.h> | ||
29 | #include <asm/io.h> | ||
30 | #include <asm/prom.h> | ||
31 | #include <asm/rtas.h> | ||
32 | #include <asm/machdep.h> /* for ppc_md */ | ||
33 | #include <asm/time.h> | ||
34 | #include <asm/systemcfg.h> | ||
35 | |||
36 | /* Token for Sensors */ | ||
37 | #define KEY_SWITCH 0x0001 | ||
38 | #define ENCLOSURE_SWITCH 0x0002 | ||
39 | #define THERMAL_SENSOR 0x0003 | ||
40 | #define LID_STATUS 0x0004 | ||
41 | #define POWER_SOURCE 0x0005 | ||
42 | #define BATTERY_VOLTAGE 0x0006 | ||
43 | #define BATTERY_REMAINING 0x0007 | ||
44 | #define BATTERY_PERCENTAGE 0x0008 | ||
45 | #define EPOW_SENSOR 0x0009 | ||
46 | #define BATTERY_CYCLESTATE 0x000a | ||
47 | #define BATTERY_CHARGING 0x000b | ||
48 | |||
49 | /* IBM specific sensors */ | ||
50 | #define IBM_SURVEILLANCE 0x2328 /* 9000 */ | ||
51 | #define IBM_FANRPM 0x2329 /* 9001 */ | ||
52 | #define IBM_VOLTAGE 0x232a /* 9002 */ | ||
53 | #define IBM_DRCONNECTOR 0x232b /* 9003 */ | ||
54 | #define IBM_POWERSUPPLY 0x232c /* 9004 */ | ||
55 | |||
56 | /* Status return values */ | ||
57 | #define SENSOR_CRITICAL_HIGH 13 | ||
58 | #define SENSOR_WARNING_HIGH 12 | ||
59 | #define SENSOR_NORMAL 11 | ||
60 | #define SENSOR_WARNING_LOW 10 | ||
61 | #define SENSOR_CRITICAL_LOW 9 | ||
62 | #define SENSOR_SUCCESS 0 | ||
63 | #define SENSOR_HW_ERROR -1 | ||
64 | #define SENSOR_BUSY -2 | ||
65 | #define SENSOR_NOT_EXIST -3 | ||
66 | #define SENSOR_DR_ENTITY -9000 | ||
67 | |||
68 | /* Location Codes */ | ||
69 | #define LOC_SCSI_DEV_ADDR 'A' | ||
70 | #define LOC_SCSI_DEV_LOC 'B' | ||
71 | #define LOC_CPU 'C' | ||
72 | #define LOC_DISKETTE 'D' | ||
73 | #define LOC_ETHERNET 'E' | ||
74 | #define LOC_FAN 'F' | ||
75 | #define LOC_GRAPHICS 'G' | ||
76 | /* reserved / not used 'H' */ | ||
77 | #define LOC_IO_ADAPTER 'I' | ||
78 | /* reserved / not used 'J' */ | ||
79 | #define LOC_KEYBOARD 'K' | ||
80 | #define LOC_LCD 'L' | ||
81 | #define LOC_MEMORY 'M' | ||
82 | #define LOC_NV_MEMORY 'N' | ||
83 | #define LOC_MOUSE 'O' | ||
84 | #define LOC_PLANAR 'P' | ||
85 | #define LOC_OTHER_IO 'Q' | ||
86 | #define LOC_PARALLEL 'R' | ||
87 | #define LOC_SERIAL 'S' | ||
88 | #define LOC_DEAD_RING 'T' | ||
89 | #define LOC_RACKMOUNTED 'U' /* for _u_nit is rack mounted */ | ||
90 | #define LOC_VOLTAGE 'V' | ||
91 | #define LOC_SWITCH_ADAPTER 'W' | ||
92 | #define LOC_OTHER 'X' | ||
93 | #define LOC_FIRMWARE 'Y' | ||
94 | #define LOC_SCSI 'Z' | ||
95 | |||
96 | /* Tokens for indicators */ | ||
97 | #define TONE_FREQUENCY 0x0001 /* 0 - 1000 (HZ)*/ | ||
98 | #define TONE_VOLUME 0x0002 /* 0 - 100 (%) */ | ||
99 | #define SYSTEM_POWER_STATE 0x0003 | ||
100 | #define WARNING_LIGHT 0x0004 | ||
101 | #define DISK_ACTIVITY_LIGHT 0x0005 | ||
102 | #define HEX_DISPLAY_UNIT 0x0006 | ||
103 | #define BATTERY_WARNING_TIME 0x0007 | ||
104 | #define CONDITION_CYCLE_REQUEST 0x0008 | ||
105 | #define SURVEILLANCE_INDICATOR 0x2328 /* 9000 */ | ||
106 | #define DR_ACTION 0x2329 /* 9001 */ | ||
107 | #define DR_INDICATOR 0x232a /* 9002 */ | ||
108 | /* 9003 - 9004: Vendor specific */ | ||
109 | /* 9006 - 9999: Vendor specific */ | ||
110 | |||
111 | /* other */ | ||
112 | #define MAX_SENSORS 17 /* I only know of 17 sensors */ | ||
113 | #define MAX_LINELENGTH 256 | ||
114 | #define SENSOR_PREFIX "ibm,sensor-" | ||
115 | #define cel_to_fahr(x) ((x*9/5)+32) | ||
116 | |||
117 | |||
118 | /* Globals */ | ||
119 | static struct rtas_sensors sensors; | ||
120 | static struct device_node *rtas_node = NULL; | ||
121 | static unsigned long power_on_time = 0; /* Save the time the user set */ | ||
122 | static char progress_led[MAX_LINELENGTH]; | ||
123 | |||
124 | static unsigned long rtas_tone_frequency = 1000; | ||
125 | static unsigned long rtas_tone_volume = 0; | ||
126 | |||
127 | /* ****************STRUCTS******************************************* */ | ||
128 | struct individual_sensor { | ||
129 | unsigned int token; | ||
130 | unsigned int quant; | ||
131 | }; | ||
132 | |||
133 | struct rtas_sensors { | ||
134 | struct individual_sensor sensor[MAX_SENSORS]; | ||
135 | unsigned int quant; | ||
136 | }; | ||
137 | |||
138 | /* ****************************************************************** */ | ||
139 | /* Declarations */ | ||
140 | static int ppc_rtas_sensors_show(struct seq_file *m, void *v); | ||
141 | static int ppc_rtas_clock_show(struct seq_file *m, void *v); | ||
142 | static ssize_t ppc_rtas_clock_write(struct file *file, | ||
143 | const char __user *buf, size_t count, loff_t *ppos); | ||
144 | static int ppc_rtas_progress_show(struct seq_file *m, void *v); | ||
145 | static ssize_t ppc_rtas_progress_write(struct file *file, | ||
146 | const char __user *buf, size_t count, loff_t *ppos); | ||
147 | static int ppc_rtas_poweron_show(struct seq_file *m, void *v); | ||
148 | static ssize_t ppc_rtas_poweron_write(struct file *file, | ||
149 | const char __user *buf, size_t count, loff_t *ppos); | ||
150 | |||
151 | static ssize_t ppc_rtas_tone_freq_write(struct file *file, | ||
152 | const char __user *buf, size_t count, loff_t *ppos); | ||
153 | static int ppc_rtas_tone_freq_show(struct seq_file *m, void *v); | ||
154 | static ssize_t ppc_rtas_tone_volume_write(struct file *file, | ||
155 | const char __user *buf, size_t count, loff_t *ppos); | ||
156 | static int ppc_rtas_tone_volume_show(struct seq_file *m, void *v); | ||
157 | static int ppc_rtas_rmo_buf_show(struct seq_file *m, void *v); | ||
158 | |||
159 | static int sensors_open(struct inode *inode, struct file *file) | ||
160 | { | ||
161 | return single_open(file, ppc_rtas_sensors_show, NULL); | ||
162 | } | ||
163 | |||
164 | struct file_operations ppc_rtas_sensors_operations = { | ||
165 | .open = sensors_open, | ||
166 | .read = seq_read, | ||
167 | .llseek = seq_lseek, | ||
168 | .release = single_release, | ||
169 | }; | ||
170 | |||
171 | static int poweron_open(struct inode *inode, struct file *file) | ||
172 | { | ||
173 | return single_open(file, ppc_rtas_poweron_show, NULL); | ||
174 | } | ||
175 | |||
176 | struct file_operations ppc_rtas_poweron_operations = { | ||
177 | .open = poweron_open, | ||
178 | .read = seq_read, | ||
179 | .llseek = seq_lseek, | ||
180 | .write = ppc_rtas_poweron_write, | ||
181 | .release = single_release, | ||
182 | }; | ||
183 | |||
184 | static int progress_open(struct inode *inode, struct file *file) | ||
185 | { | ||
186 | return single_open(file, ppc_rtas_progress_show, NULL); | ||
187 | } | ||
188 | |||
189 | struct file_operations ppc_rtas_progress_operations = { | ||
190 | .open = progress_open, | ||
191 | .read = seq_read, | ||
192 | .llseek = seq_lseek, | ||
193 | .write = ppc_rtas_progress_write, | ||
194 | .release = single_release, | ||
195 | }; | ||
196 | |||
197 | static int clock_open(struct inode *inode, struct file *file) | ||
198 | { | ||
199 | return single_open(file, ppc_rtas_clock_show, NULL); | ||
200 | } | ||
201 | |||
202 | struct file_operations ppc_rtas_clock_operations = { | ||
203 | .open = clock_open, | ||
204 | .read = seq_read, | ||
205 | .llseek = seq_lseek, | ||
206 | .write = ppc_rtas_clock_write, | ||
207 | .release = single_release, | ||
208 | }; | ||
209 | |||
210 | static int tone_freq_open(struct inode *inode, struct file *file) | ||
211 | { | ||
212 | return single_open(file, ppc_rtas_tone_freq_show, NULL); | ||
213 | } | ||
214 | |||
215 | struct file_operations ppc_rtas_tone_freq_operations = { | ||
216 | .open = tone_freq_open, | ||
217 | .read = seq_read, | ||
218 | .llseek = seq_lseek, | ||
219 | .write = ppc_rtas_tone_freq_write, | ||
220 | .release = single_release, | ||
221 | }; | ||
222 | |||
223 | static int tone_volume_open(struct inode *inode, struct file *file) | ||
224 | { | ||
225 | return single_open(file, ppc_rtas_tone_volume_show, NULL); | ||
226 | } | ||
227 | |||
228 | struct file_operations ppc_rtas_tone_volume_operations = { | ||
229 | .open = tone_volume_open, | ||
230 | .read = seq_read, | ||
231 | .llseek = seq_lseek, | ||
232 | .write = ppc_rtas_tone_volume_write, | ||
233 | .release = single_release, | ||
234 | }; | ||
235 | |||
236 | static int rmo_buf_open(struct inode *inode, struct file *file) | ||
237 | { | ||
238 | return single_open(file, ppc_rtas_rmo_buf_show, NULL); | ||
239 | } | ||
240 | |||
241 | struct file_operations ppc_rtas_rmo_buf_ops = { | ||
242 | .open = rmo_buf_open, | ||
243 | .read = seq_read, | ||
244 | .llseek = seq_lseek, | ||
245 | .release = single_release, | ||
246 | }; | ||
247 | |||
248 | static int ppc_rtas_find_all_sensors(void); | ||
249 | static void ppc_rtas_process_sensor(struct seq_file *m, | ||
250 | struct individual_sensor *s, int state, int error, char *loc); | ||
251 | static char *ppc_rtas_process_error(int error); | ||
252 | static void get_location_code(struct seq_file *m, | ||
253 | struct individual_sensor *s, char *loc); | ||
254 | static void check_location_string(struct seq_file *m, char *c); | ||
255 | static void check_location(struct seq_file *m, char *c); | ||
256 | |||
257 | static int __init proc_rtas_init(void) | ||
258 | { | ||
259 | struct proc_dir_entry *entry; | ||
260 | |||
261 | if (!(systemcfg->platform & PLATFORM_PSERIES)) | ||
262 | return 1; | ||
263 | |||
264 | rtas_node = of_find_node_by_name(NULL, "rtas"); | ||
265 | if (rtas_node == NULL) | ||
266 | return 1; | ||
267 | |||
268 | entry = create_proc_entry("ppc64/rtas/progress", S_IRUGO|S_IWUSR, NULL); | ||
269 | if (entry) | ||
270 | entry->proc_fops = &ppc_rtas_progress_operations; | ||
271 | |||
272 | entry = create_proc_entry("ppc64/rtas/clock", S_IRUGO|S_IWUSR, NULL); | ||
273 | if (entry) | ||
274 | entry->proc_fops = &ppc_rtas_clock_operations; | ||
275 | |||
276 | entry = create_proc_entry("ppc64/rtas/poweron", S_IWUSR|S_IRUGO, NULL); | ||
277 | if (entry) | ||
278 | entry->proc_fops = &ppc_rtas_poweron_operations; | ||
279 | |||
280 | entry = create_proc_entry("ppc64/rtas/sensors", S_IRUGO, NULL); | ||
281 | if (entry) | ||
282 | entry->proc_fops = &ppc_rtas_sensors_operations; | ||
283 | |||
284 | entry = create_proc_entry("ppc64/rtas/frequency", S_IWUSR|S_IRUGO, | ||
285 | NULL); | ||
286 | if (entry) | ||
287 | entry->proc_fops = &ppc_rtas_tone_freq_operations; | ||
288 | |||
289 | entry = create_proc_entry("ppc64/rtas/volume", S_IWUSR|S_IRUGO, NULL); | ||
290 | if (entry) | ||
291 | entry->proc_fops = &ppc_rtas_tone_volume_operations; | ||
292 | |||
293 | entry = create_proc_entry("ppc64/rtas/rmo_buffer", S_IRUSR, NULL); | ||
294 | if (entry) | ||
295 | entry->proc_fops = &ppc_rtas_rmo_buf_ops; | ||
296 | |||
297 | return 0; | ||
298 | } | ||
299 | |||
300 | __initcall(proc_rtas_init); | ||
301 | |||
302 | static int parse_number(const char __user *p, size_t count, unsigned long *val) | ||
303 | { | ||
304 | char buf[40]; | ||
305 | char *end; | ||
306 | |||
307 | if (count > 39) | ||
308 | return -EINVAL; | ||
309 | |||
310 | if (copy_from_user(buf, p, count)) | ||
311 | return -EFAULT; | ||
312 | |||
313 | buf[count] = 0; | ||
314 | |||
315 | *val = simple_strtoul(buf, &end, 10); | ||
316 | if (*end && *end != '\n') | ||
317 | return -EINVAL; | ||
318 | |||
319 | return 0; | ||
320 | } | ||
321 | |||
322 | /* ****************************************************************** */ | ||
323 | /* POWER-ON-TIME */ | ||
324 | /* ****************************************************************** */ | ||
325 | static ssize_t ppc_rtas_poweron_write(struct file *file, | ||
326 | const char __user *buf, size_t count, loff_t *ppos) | ||
327 | { | ||
328 | struct rtc_time tm; | ||
329 | unsigned long nowtime; | ||
330 | int error = parse_number(buf, count, &nowtime); | ||
331 | if (error) | ||
332 | return error; | ||
333 | |||
334 | power_on_time = nowtime; /* save the time */ | ||
335 | |||
336 | to_tm(nowtime, &tm); | ||
337 | |||
338 | error = rtas_call(rtas_token("set-time-for-power-on"), 7, 1, NULL, | ||
339 | tm.tm_year, tm.tm_mon, tm.tm_mday, | ||
340 | tm.tm_hour, tm.tm_min, tm.tm_sec, 0 /* nano */); | ||
341 | if (error) | ||
342 | printk(KERN_WARNING "error: setting poweron time returned: %s\n", | ||
343 | ppc_rtas_process_error(error)); | ||
344 | return count; | ||
345 | } | ||
346 | /* ****************************************************************** */ | ||
347 | static int ppc_rtas_poweron_show(struct seq_file *m, void *v) | ||
348 | { | ||
349 | if (power_on_time == 0) | ||
350 | seq_printf(m, "Power on time not set\n"); | ||
351 | else | ||
352 | seq_printf(m, "%lu\n",power_on_time); | ||
353 | return 0; | ||
354 | } | ||
355 | |||
356 | /* ****************************************************************** */ | ||
357 | /* PROGRESS */ | ||
358 | /* ****************************************************************** */ | ||
359 | static ssize_t ppc_rtas_progress_write(struct file *file, | ||
360 | const char __user *buf, size_t count, loff_t *ppos) | ||
361 | { | ||
362 | unsigned long hex; | ||
363 | |||
364 | if (count >= MAX_LINELENGTH) | ||
365 | count = MAX_LINELENGTH -1; | ||
366 | if (copy_from_user(progress_led, buf, count)) { /* save the string */ | ||
367 | return -EFAULT; | ||
368 | } | ||
369 | progress_led[count] = 0; | ||
370 | |||
371 | /* Lets see if the user passed hexdigits */ | ||
372 | hex = simple_strtoul(progress_led, NULL, 10); | ||
373 | |||
374 | ppc_md.progress ((char *)progress_led, hex); | ||
375 | return count; | ||
376 | |||
377 | /* clear the line */ | ||
378 | /* ppc_md.progress(" ", 0xffff);*/ | ||
379 | } | ||
380 | /* ****************************************************************** */ | ||
381 | static int ppc_rtas_progress_show(struct seq_file *m, void *v) | ||
382 | { | ||
383 | if (progress_led) | ||
384 | seq_printf(m, "%s\n", progress_led); | ||
385 | return 0; | ||
386 | } | ||
387 | |||
388 | /* ****************************************************************** */ | ||
389 | /* CLOCK */ | ||
390 | /* ****************************************************************** */ | ||
391 | static ssize_t ppc_rtas_clock_write(struct file *file, | ||
392 | const char __user *buf, size_t count, loff_t *ppos) | ||
393 | { | ||
394 | struct rtc_time tm; | ||
395 | unsigned long nowtime; | ||
396 | int error = parse_number(buf, count, &nowtime); | ||
397 | if (error) | ||
398 | return error; | ||
399 | |||
400 | to_tm(nowtime, &tm); | ||
401 | error = rtas_call(rtas_token("set-time-of-day"), 7, 1, NULL, | ||
402 | tm.tm_year, tm.tm_mon, tm.tm_mday, | ||
403 | tm.tm_hour, tm.tm_min, tm.tm_sec, 0); | ||
404 | if (error) | ||
405 | printk(KERN_WARNING "error: setting the clock returned: %s\n", | ||
406 | ppc_rtas_process_error(error)); | ||
407 | return count; | ||
408 | } | ||
409 | /* ****************************************************************** */ | ||
410 | static int ppc_rtas_clock_show(struct seq_file *m, void *v) | ||
411 | { | ||
412 | int ret[8]; | ||
413 | int error = rtas_call(rtas_token("get-time-of-day"), 0, 8, ret); | ||
414 | |||
415 | if (error) { | ||
416 | printk(KERN_WARNING "error: reading the clock returned: %s\n", | ||
417 | ppc_rtas_process_error(error)); | ||
418 | seq_printf(m, "0"); | ||
419 | } else { | ||
420 | unsigned int year, mon, day, hour, min, sec; | ||
421 | year = ret[0]; mon = ret[1]; day = ret[2]; | ||
422 | hour = ret[3]; min = ret[4]; sec = ret[5]; | ||
423 | seq_printf(m, "%lu\n", | ||
424 | mktime(year, mon, day, hour, min, sec)); | ||
425 | } | ||
426 | return 0; | ||
427 | } | ||
428 | |||
429 | /* ****************************************************************** */ | ||
430 | /* SENSOR STUFF */ | ||
431 | /* ****************************************************************** */ | ||
432 | static int ppc_rtas_sensors_show(struct seq_file *m, void *v) | ||
433 | { | ||
434 | int i,j; | ||
435 | int state, error; | ||
436 | int get_sensor_state = rtas_token("get-sensor-state"); | ||
437 | |||
438 | seq_printf(m, "RTAS (RunTime Abstraction Services) Sensor Information\n"); | ||
439 | seq_printf(m, "Sensor\t\tValue\t\tCondition\tLocation\n"); | ||
440 | seq_printf(m, "********************************************************\n"); | ||
441 | |||
442 | if (ppc_rtas_find_all_sensors() != 0) { | ||
443 | seq_printf(m, "\nNo sensors are available\n"); | ||
444 | return 0; | ||
445 | } | ||
446 | |||
447 | for (i=0; i<sensors.quant; i++) { | ||
448 | struct individual_sensor *p = &sensors.sensor[i]; | ||
449 | char rstr[64]; | ||
450 | char *loc; | ||
451 | int llen, offs; | ||
452 | |||
453 | sprintf (rstr, SENSOR_PREFIX"%04d", p->token); | ||
454 | loc = (char *) get_property(rtas_node, rstr, &llen); | ||
455 | |||
456 | /* A sensor may have multiple instances */ | ||
457 | for (j = 0, offs = 0; j <= p->quant; j++) { | ||
458 | error = rtas_call(get_sensor_state, 2, 2, &state, | ||
459 | p->token, j); | ||
460 | |||
461 | ppc_rtas_process_sensor(m, p, state, error, loc); | ||
462 | seq_putc(m, '\n'); | ||
463 | if (loc) { | ||
464 | offs += strlen(loc) + 1; | ||
465 | loc += strlen(loc) + 1; | ||
466 | if (offs >= llen) | ||
467 | loc = NULL; | ||
468 | } | ||
469 | } | ||
470 | } | ||
471 | return 0; | ||
472 | } | ||
473 | |||
474 | /* ****************************************************************** */ | ||
475 | |||
476 | static int ppc_rtas_find_all_sensors(void) | ||
477 | { | ||
478 | unsigned int *utmp; | ||
479 | int len, i; | ||
480 | |||
481 | utmp = (unsigned int *) get_property(rtas_node, "rtas-sensors", &len); | ||
482 | if (utmp == NULL) { | ||
483 | printk (KERN_ERR "error: could not get rtas-sensors\n"); | ||
484 | return 1; | ||
485 | } | ||
486 | |||
487 | sensors.quant = len / 8; /* int + int */ | ||
488 | |||
489 | for (i=0; i<sensors.quant; i++) { | ||
490 | sensors.sensor[i].token = *utmp++; | ||
491 | sensors.sensor[i].quant = *utmp++; | ||
492 | } | ||
493 | return 0; | ||
494 | } | ||
495 | |||
496 | /* ****************************************************************** */ | ||
497 | /* | ||
498 | * Builds a string of what rtas returned | ||
499 | */ | ||
500 | static char *ppc_rtas_process_error(int error) | ||
501 | { | ||
502 | switch (error) { | ||
503 | case SENSOR_CRITICAL_HIGH: | ||
504 | return "(critical high)"; | ||
505 | case SENSOR_WARNING_HIGH: | ||
506 | return "(warning high)"; | ||
507 | case SENSOR_NORMAL: | ||
508 | return "(normal)"; | ||
509 | case SENSOR_WARNING_LOW: | ||
510 | return "(warning low)"; | ||
511 | case SENSOR_CRITICAL_LOW: | ||
512 | return "(critical low)"; | ||
513 | case SENSOR_SUCCESS: | ||
514 | return "(read ok)"; | ||
515 | case SENSOR_HW_ERROR: | ||
516 | return "(hardware error)"; | ||
517 | case SENSOR_BUSY: | ||
518 | return "(busy)"; | ||
519 | case SENSOR_NOT_EXIST: | ||
520 | return "(non existent)"; | ||
521 | case SENSOR_DR_ENTITY: | ||
522 | return "(dr entity removed)"; | ||
523 | default: | ||
524 | return "(UNKNOWN)"; | ||
525 | } | ||
526 | } | ||
527 | |||
528 | /* ****************************************************************** */ | ||
529 | /* | ||
530 | * Builds a string out of what the sensor said | ||
531 | */ | ||
532 | |||
533 | static void ppc_rtas_process_sensor(struct seq_file *m, | ||
534 | struct individual_sensor *s, int state, int error, char *loc) | ||
535 | { | ||
536 | /* Defined return vales */ | ||
537 | const char * key_switch[] = { "Off\t", "Normal\t", "Secure\t", | ||
538 | "Maintenance" }; | ||
539 | const char * enclosure_switch[] = { "Closed", "Open" }; | ||
540 | const char * lid_status[] = { " ", "Open", "Closed" }; | ||
541 | const char * power_source[] = { "AC\t", "Battery", | ||
542 | "AC & Battery" }; | ||
543 | const char * battery_remaining[] = { "Very Low", "Low", "Mid", "High" }; | ||
544 | const char * epow_sensor[] = { | ||
545 | "EPOW Reset", "Cooling warning", "Power warning", | ||
546 | "System shutdown", "System halt", "EPOW main enclosure", | ||
547 | "EPOW power off" }; | ||
548 | const char * battery_cyclestate[] = { "None", "In progress", | ||
549 | "Requested" }; | ||
550 | const char * battery_charging[] = { "Charging", "Discharching", | ||
551 | "No current flow" }; | ||
552 | const char * ibm_drconnector[] = { "Empty", "Present", "Unusable", | ||
553 | "Exchange" }; | ||
554 | |||
555 | int have_strings = 0; | ||
556 | int num_states = 0; | ||
557 | int temperature = 0; | ||
558 | int unknown = 0; | ||
559 | |||
560 | /* What kind of sensor do we have here? */ | ||
561 | |||
562 | switch (s->token) { | ||
563 | case KEY_SWITCH: | ||
564 | seq_printf(m, "Key switch:\t"); | ||
565 | num_states = sizeof(key_switch) / sizeof(char *); | ||
566 | if (state < num_states) { | ||
567 | seq_printf(m, "%s\t", key_switch[state]); | ||
568 | have_strings = 1; | ||
569 | } | ||
570 | break; | ||
571 | case ENCLOSURE_SWITCH: | ||
572 | seq_printf(m, "Enclosure switch:\t"); | ||
573 | num_states = sizeof(enclosure_switch) / sizeof(char *); | ||
574 | if (state < num_states) { | ||
575 | seq_printf(m, "%s\t", | ||
576 | enclosure_switch[state]); | ||
577 | have_strings = 1; | ||
578 | } | ||
579 | break; | ||
580 | case THERMAL_SENSOR: | ||
581 | seq_printf(m, "Temp. (C/F):\t"); | ||
582 | temperature = 1; | ||
583 | break; | ||
584 | case LID_STATUS: | ||
585 | seq_printf(m, "Lid status:\t"); | ||
586 | num_states = sizeof(lid_status) / sizeof(char *); | ||
587 | if (state < num_states) { | ||
588 | seq_printf(m, "%s\t", lid_status[state]); | ||
589 | have_strings = 1; | ||
590 | } | ||
591 | break; | ||
592 | case POWER_SOURCE: | ||
593 | seq_printf(m, "Power source:\t"); | ||
594 | num_states = sizeof(power_source) / sizeof(char *); | ||
595 | if (state < num_states) { | ||
596 | seq_printf(m, "%s\t", | ||
597 | power_source[state]); | ||
598 | have_strings = 1; | ||
599 | } | ||
600 | break; | ||
601 | case BATTERY_VOLTAGE: | ||
602 | seq_printf(m, "Battery voltage:\t"); | ||
603 | break; | ||
604 | case BATTERY_REMAINING: | ||
605 | seq_printf(m, "Battery remaining:\t"); | ||
606 | num_states = sizeof(battery_remaining) / sizeof(char *); | ||
607 | if (state < num_states) | ||
608 | { | ||
609 | seq_printf(m, "%s\t", | ||
610 | battery_remaining[state]); | ||
611 | have_strings = 1; | ||
612 | } | ||
613 | break; | ||
614 | case BATTERY_PERCENTAGE: | ||
615 | seq_printf(m, "Battery percentage:\t"); | ||
616 | break; | ||
617 | case EPOW_SENSOR: | ||
618 | seq_printf(m, "EPOW Sensor:\t"); | ||
619 | num_states = sizeof(epow_sensor) / sizeof(char *); | ||
620 | if (state < num_states) { | ||
621 | seq_printf(m, "%s\t", epow_sensor[state]); | ||
622 | have_strings = 1; | ||
623 | } | ||
624 | break; | ||
625 | case BATTERY_CYCLESTATE: | ||
626 | seq_printf(m, "Battery cyclestate:\t"); | ||
627 | num_states = sizeof(battery_cyclestate) / | ||
628 | sizeof(char *); | ||
629 | if (state < num_states) { | ||
630 | seq_printf(m, "%s\t", | ||
631 | battery_cyclestate[state]); | ||
632 | have_strings = 1; | ||
633 | } | ||
634 | break; | ||
635 | case BATTERY_CHARGING: | ||
636 | seq_printf(m, "Battery Charging:\t"); | ||
637 | num_states = sizeof(battery_charging) / sizeof(char *); | ||
638 | if (state < num_states) { | ||
639 | seq_printf(m, "%s\t", | ||
640 | battery_charging[state]); | ||
641 | have_strings = 1; | ||
642 | } | ||
643 | break; | ||
644 | case IBM_SURVEILLANCE: | ||
645 | seq_printf(m, "Surveillance:\t"); | ||
646 | break; | ||
647 | case IBM_FANRPM: | ||
648 | seq_printf(m, "Fan (rpm):\t"); | ||
649 | break; | ||
650 | case IBM_VOLTAGE: | ||
651 | seq_printf(m, "Voltage (mv):\t"); | ||
652 | break; | ||
653 | case IBM_DRCONNECTOR: | ||
654 | seq_printf(m, "DR connector:\t"); | ||
655 | num_states = sizeof(ibm_drconnector) / sizeof(char *); | ||
656 | if (state < num_states) { | ||
657 | seq_printf(m, "%s\t", | ||
658 | ibm_drconnector[state]); | ||
659 | have_strings = 1; | ||
660 | } | ||
661 | break; | ||
662 | case IBM_POWERSUPPLY: | ||
663 | seq_printf(m, "Powersupply:\t"); | ||
664 | break; | ||
665 | default: | ||
666 | seq_printf(m, "Unknown sensor (type %d), ignoring it\n", | ||
667 | s->token); | ||
668 | unknown = 1; | ||
669 | have_strings = 1; | ||
670 | break; | ||
671 | } | ||
672 | if (have_strings == 0) { | ||
673 | if (temperature) { | ||
674 | seq_printf(m, "%4d /%4d\t", state, cel_to_fahr(state)); | ||
675 | } else | ||
676 | seq_printf(m, "%10d\t", state); | ||
677 | } | ||
678 | if (unknown == 0) { | ||
679 | seq_printf(m, "%s\t", ppc_rtas_process_error(error)); | ||
680 | get_location_code(m, s, loc); | ||
681 | } | ||
682 | } | ||
683 | |||
684 | /* ****************************************************************** */ | ||
685 | |||
686 | static void check_location(struct seq_file *m, char *c) | ||
687 | { | ||
688 | switch (c[0]) { | ||
689 | case LOC_PLANAR: | ||
690 | seq_printf(m, "Planar #%c", c[1]); | ||
691 | break; | ||
692 | case LOC_CPU: | ||
693 | seq_printf(m, "CPU #%c", c[1]); | ||
694 | break; | ||
695 | case LOC_FAN: | ||
696 | seq_printf(m, "Fan #%c", c[1]); | ||
697 | break; | ||
698 | case LOC_RACKMOUNTED: | ||
699 | seq_printf(m, "Rack #%c", c[1]); | ||
700 | break; | ||
701 | case LOC_VOLTAGE: | ||
702 | seq_printf(m, "Voltage #%c", c[1]); | ||
703 | break; | ||
704 | case LOC_LCD: | ||
705 | seq_printf(m, "LCD #%c", c[1]); | ||
706 | break; | ||
707 | case '.': | ||
708 | seq_printf(m, "- %c", c[1]); | ||
709 | break; | ||
710 | default: | ||
711 | seq_printf(m, "Unknown location"); | ||
712 | break; | ||
713 | } | ||
714 | } | ||
715 | |||
716 | |||
717 | /* ****************************************************************** */ | ||
718 | /* | ||
719 | * Format: | ||
720 | * ${LETTER}${NUMBER}[[-/]${LETTER}${NUMBER} [ ... ] ] | ||
721 | * the '.' may be an abbrevation | ||
722 | */ | ||
723 | static void check_location_string(struct seq_file *m, char *c) | ||
724 | { | ||
725 | while (*c) { | ||
726 | if (isalpha(*c) || *c == '.') | ||
727 | check_location(m, c); | ||
728 | else if (*c == '/' || *c == '-') | ||
729 | seq_printf(m, " at "); | ||
730 | c++; | ||
731 | } | ||
732 | } | ||
733 | |||
734 | |||
735 | /* ****************************************************************** */ | ||
736 | |||
737 | static void get_location_code(struct seq_file *m, struct individual_sensor *s, char *loc) | ||
738 | { | ||
739 | if (!loc || !*loc) { | ||
740 | seq_printf(m, "---");/* does not have a location */ | ||
741 | } else { | ||
742 | check_location_string(m, loc); | ||
743 | } | ||
744 | seq_putc(m, ' '); | ||
745 | } | ||
746 | /* ****************************************************************** */ | ||
747 | /* INDICATORS - Tone Frequency */ | ||
748 | /* ****************************************************************** */ | ||
749 | static ssize_t ppc_rtas_tone_freq_write(struct file *file, | ||
750 | const char __user *buf, size_t count, loff_t *ppos) | ||
751 | { | ||
752 | unsigned long freq; | ||
753 | int error = parse_number(buf, count, &freq); | ||
754 | if (error) | ||
755 | return error; | ||
756 | |||
757 | rtas_tone_frequency = freq; /* save it for later */ | ||
758 | error = rtas_call(rtas_token("set-indicator"), 3, 1, NULL, | ||
759 | TONE_FREQUENCY, 0, freq); | ||
760 | if (error) | ||
761 | printk(KERN_WARNING "error: setting tone frequency returned: %s\n", | ||
762 | ppc_rtas_process_error(error)); | ||
763 | return count; | ||
764 | } | ||
765 | /* ****************************************************************** */ | ||
766 | static int ppc_rtas_tone_freq_show(struct seq_file *m, void *v) | ||
767 | { | ||
768 | seq_printf(m, "%lu\n", rtas_tone_frequency); | ||
769 | return 0; | ||
770 | } | ||
771 | /* ****************************************************************** */ | ||
772 | /* INDICATORS - Tone Volume */ | ||
773 | /* ****************************************************************** */ | ||
774 | static ssize_t ppc_rtas_tone_volume_write(struct file *file, | ||
775 | const char __user *buf, size_t count, loff_t *ppos) | ||
776 | { | ||
777 | unsigned long volume; | ||
778 | int error = parse_number(buf, count, &volume); | ||
779 | if (error) | ||
780 | return error; | ||
781 | |||
782 | if (volume > 100) | ||
783 | volume = 100; | ||
784 | |||
785 | rtas_tone_volume = volume; /* save it for later */ | ||
786 | error = rtas_call(rtas_token("set-indicator"), 3, 1, NULL, | ||
787 | TONE_VOLUME, 0, volume); | ||
788 | if (error) | ||
789 | printk(KERN_WARNING "error: setting tone volume returned: %s\n", | ||
790 | ppc_rtas_process_error(error)); | ||
791 | return count; | ||
792 | } | ||
793 | /* ****************************************************************** */ | ||
794 | static int ppc_rtas_tone_volume_show(struct seq_file *m, void *v) | ||
795 | { | ||
796 | seq_printf(m, "%lu\n", rtas_tone_volume); | ||
797 | return 0; | ||
798 | } | ||
799 | |||
800 | #define RMO_READ_BUF_MAX 30 | ||
801 | |||
802 | /* RTAS Userspace access */ | ||
803 | static int ppc_rtas_rmo_buf_show(struct seq_file *m, void *v) | ||
804 | { | ||
805 | seq_printf(m, "%016lx %x\n", rtas_rmo_buf, RTAS_RMOBUF_MAX); | ||
806 | return 0; | ||
807 | } | ||