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