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