Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/shaggy...
[linux-2.6] / arch / powerpc / 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 #include <linux/bitops.h>
26 #include <linux/rtc.h>
27
28 #include <asm/uaccess.h>
29 #include <asm/processor.h>
30 #include <asm/io.h>
31 #include <asm/prom.h>
32 #include <asm/rtas.h>
33 #include <asm/machdep.h> /* for ppc_md */
34 #include <asm/time.h>
35 #include <asm/systemcfg.h>
36
37 /* Token for Sensors */
38 #define KEY_SWITCH              0x0001
39 #define ENCLOSURE_SWITCH        0x0002
40 #define THERMAL_SENSOR          0x0003
41 #define LID_STATUS              0x0004
42 #define POWER_SOURCE            0x0005
43 #define BATTERY_VOLTAGE         0x0006
44 #define BATTERY_REMAINING       0x0007
45 #define BATTERY_PERCENTAGE      0x0008
46 #define EPOW_SENSOR             0x0009
47 #define BATTERY_CYCLESTATE      0x000a
48 #define BATTERY_CHARGING        0x000b
49
50 /* IBM specific sensors */
51 #define IBM_SURVEILLANCE        0x2328 /* 9000 */
52 #define IBM_FANRPM              0x2329 /* 9001 */
53 #define IBM_VOLTAGE             0x232a /* 9002 */
54 #define IBM_DRCONNECTOR         0x232b /* 9003 */
55 #define IBM_POWERSUPPLY         0x232c /* 9004 */
56
57 /* Status return values */
58 #define SENSOR_CRITICAL_HIGH    13
59 #define SENSOR_WARNING_HIGH     12
60 #define SENSOR_NORMAL           11
61 #define SENSOR_WARNING_LOW      10
62 #define SENSOR_CRITICAL_LOW      9
63 #define SENSOR_SUCCESS           0
64 #define SENSOR_HW_ERROR         -1
65 #define SENSOR_BUSY             -2
66 #define SENSOR_NOT_EXIST        -3
67 #define SENSOR_DR_ENTITY        -9000
68
69 /* Location Codes */
70 #define LOC_SCSI_DEV_ADDR       'A'
71 #define LOC_SCSI_DEV_LOC        'B'
72 #define LOC_CPU                 'C'
73 #define LOC_DISKETTE            'D'
74 #define LOC_ETHERNET            'E'
75 #define LOC_FAN                 'F'
76 #define LOC_GRAPHICS            'G'
77 /* reserved / not used          'H' */
78 #define LOC_IO_ADAPTER          'I'
79 /* reserved / not used          'J' */
80 #define LOC_KEYBOARD            'K'
81 #define LOC_LCD                 'L'
82 #define LOC_MEMORY              'M'
83 #define LOC_NV_MEMORY           'N'
84 #define LOC_MOUSE               'O'
85 #define LOC_PLANAR              'P'
86 #define LOC_OTHER_IO            'Q'
87 #define LOC_PARALLEL            'R'
88 #define LOC_SERIAL              'S'
89 #define LOC_DEAD_RING           'T'
90 #define LOC_RACKMOUNTED         'U' /* for _u_nit is rack mounted */
91 #define LOC_VOLTAGE             'V'
92 #define LOC_SWITCH_ADAPTER      'W'
93 #define LOC_OTHER               'X'
94 #define LOC_FIRMWARE            'Y'
95 #define LOC_SCSI                'Z'
96
97 /* Tokens for indicators */
98 #define TONE_FREQUENCY          0x0001 /* 0 - 1000 (HZ)*/
99 #define TONE_VOLUME             0x0002 /* 0 - 100 (%) */
100 #define SYSTEM_POWER_STATE      0x0003 
101 #define WARNING_LIGHT           0x0004
102 #define DISK_ACTIVITY_LIGHT     0x0005
103 #define HEX_DISPLAY_UNIT        0x0006
104 #define BATTERY_WARNING_TIME    0x0007
105 #define CONDITION_CYCLE_REQUEST 0x0008
106 #define SURVEILLANCE_INDICATOR  0x2328 /* 9000 */
107 #define DR_ACTION               0x2329 /* 9001 */
108 #define DR_INDICATOR            0x232a /* 9002 */
109 /* 9003 - 9004: Vendor specific */
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         rtas_progress ((char *)progress_led, hex);
376         return count;
377
378         /* clear the line */
379         /* rtas_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
556         int have_strings = 0;
557         int num_states = 0;
558         int temperature = 0;
559         int unknown = 0;
560
561         /* What kind of sensor do we have here? */
562         
563         switch (s->token) {
564                 case KEY_SWITCH:
565                         seq_printf(m, "Key switch:\t");
566                         num_states = sizeof(key_switch) / sizeof(char *);
567                         if (state < num_states) {
568                                 seq_printf(m, "%s\t", key_switch[state]);
569                                 have_strings = 1;
570                         }
571                         break;
572                 case ENCLOSURE_SWITCH:
573                         seq_printf(m, "Enclosure switch:\t");
574                         num_states = sizeof(enclosure_switch) / sizeof(char *);
575                         if (state < num_states) {
576                                 seq_printf(m, "%s\t", 
577                                                 enclosure_switch[state]);
578                                 have_strings = 1;
579                         }
580                         break;
581                 case THERMAL_SENSOR:
582                         seq_printf(m, "Temp. (C/F):\t");
583                         temperature = 1;
584                         break;
585                 case LID_STATUS:
586                         seq_printf(m, "Lid status:\t");
587                         num_states = sizeof(lid_status) / sizeof(char *);
588                         if (state < num_states) {
589                                 seq_printf(m, "%s\t", lid_status[state]);
590                                 have_strings = 1;
591                         }
592                         break;
593                 case POWER_SOURCE:
594                         seq_printf(m, "Power source:\t");
595                         num_states = sizeof(power_source) / sizeof(char *);
596                         if (state < num_states) {
597                                 seq_printf(m, "%s\t", 
598                                                 power_source[state]);
599                                 have_strings = 1;
600                         }
601                         break;
602                 case BATTERY_VOLTAGE:
603                         seq_printf(m, "Battery voltage:\t");
604                         break;
605                 case BATTERY_REMAINING:
606                         seq_printf(m, "Battery remaining:\t");
607                         num_states = sizeof(battery_remaining) / sizeof(char *);
608                         if (state < num_states)
609                         {
610                                 seq_printf(m, "%s\t", 
611                                                 battery_remaining[state]);
612                                 have_strings = 1;
613                         }
614                         break;
615                 case BATTERY_PERCENTAGE:
616                         seq_printf(m, "Battery percentage:\t");
617                         break;
618                 case EPOW_SENSOR:
619                         seq_printf(m, "EPOW Sensor:\t");
620                         num_states = sizeof(epow_sensor) / sizeof(char *);
621                         if (state < num_states) {
622                                 seq_printf(m, "%s\t", epow_sensor[state]);
623                                 have_strings = 1;
624                         }
625                         break;
626                 case BATTERY_CYCLESTATE:
627                         seq_printf(m, "Battery cyclestate:\t");
628                         num_states = sizeof(battery_cyclestate) / 
629                                         sizeof(char *);
630                         if (state < num_states) {
631                                 seq_printf(m, "%s\t", 
632                                                 battery_cyclestate[state]);
633                                 have_strings = 1;
634                         }
635                         break;
636                 case BATTERY_CHARGING:
637                         seq_printf(m, "Battery Charging:\t");
638                         num_states = sizeof(battery_charging) / sizeof(char *);
639                         if (state < num_states) {
640                                 seq_printf(m, "%s\t", 
641                                                 battery_charging[state]);
642                                 have_strings = 1;
643                         }
644                         break;
645                 case IBM_SURVEILLANCE:
646                         seq_printf(m, "Surveillance:\t");
647                         break;
648                 case IBM_FANRPM:
649                         seq_printf(m, "Fan (rpm):\t");
650                         break;
651                 case IBM_VOLTAGE:
652                         seq_printf(m, "Voltage (mv):\t");
653                         break;
654                 case IBM_DRCONNECTOR:
655                         seq_printf(m, "DR connector:\t");
656                         num_states = sizeof(ibm_drconnector) / sizeof(char *);
657                         if (state < num_states) {
658                                 seq_printf(m, "%s\t", 
659                                                 ibm_drconnector[state]);
660                                 have_strings = 1;
661                         }
662                         break;
663                 case IBM_POWERSUPPLY:
664                         seq_printf(m, "Powersupply:\t");
665                         break;
666                 default:
667                         seq_printf(m,  "Unknown sensor (type %d), ignoring it\n",
668                                         s->token);
669                         unknown = 1;
670                         have_strings = 1;
671                         break;
672         }
673         if (have_strings == 0) {
674                 if (temperature) {
675                         seq_printf(m, "%4d /%4d\t", state, cel_to_fahr(state));
676                 } else
677                         seq_printf(m, "%10d\t", state);
678         }
679         if (unknown == 0) {
680                 seq_printf(m, "%s\t", ppc_rtas_process_error(error));
681                 get_location_code(m, s, loc);
682         }
683 }
684
685 /* ****************************************************************** */
686
687 static void check_location(struct seq_file *m, char *c)
688 {
689         switch (c[0]) {
690                 case LOC_PLANAR:
691                         seq_printf(m, "Planar #%c", c[1]);
692                         break;
693                 case LOC_CPU:
694                         seq_printf(m, "CPU #%c", c[1]);
695                         break;
696                 case LOC_FAN:
697                         seq_printf(m, "Fan #%c", c[1]);
698                         break;
699                 case LOC_RACKMOUNTED:
700                         seq_printf(m, "Rack #%c", c[1]);
701                         break;
702                 case LOC_VOLTAGE:
703                         seq_printf(m, "Voltage #%c", c[1]);
704                         break;
705                 case LOC_LCD:
706                         seq_printf(m, "LCD #%c", c[1]);
707                         break;
708                 case '.':
709                         seq_printf(m, "- %c", c[1]);
710                         break;
711                 default:
712                         seq_printf(m, "Unknown location");
713                         break;
714         }
715 }
716
717
718 /* ****************************************************************** */
719 /* 
720  * Format: 
721  * ${LETTER}${NUMBER}[[-/]${LETTER}${NUMBER} [ ... ] ]
722  * the '.' may be an abbrevation
723  */
724 static void check_location_string(struct seq_file *m, char *c)
725 {
726         while (*c) {
727                 if (isalpha(*c) || *c == '.')
728                         check_location(m, c);
729                 else if (*c == '/' || *c == '-')
730                         seq_printf(m, " at ");
731                 c++;
732         }
733 }
734
735
736 /* ****************************************************************** */
737
738 static void get_location_code(struct seq_file *m, struct individual_sensor *s, char *loc)
739 {
740         if (!loc || !*loc) {
741                 seq_printf(m, "---");/* does not have a location */
742         } else {
743                 check_location_string(m, loc);
744         }
745         seq_putc(m, ' ');
746 }
747 /* ****************************************************************** */
748 /* INDICATORS - Tone Frequency                                        */
749 /* ****************************************************************** */
750 static ssize_t ppc_rtas_tone_freq_write(struct file *file,
751                 const char __user *buf, size_t count, loff_t *ppos)
752 {
753         unsigned long freq;
754         int error = parse_number(buf, count, &freq);
755         if (error)
756                 return error;
757
758         rtas_tone_frequency = freq; /* save it for later */
759         error = rtas_call(rtas_token("set-indicator"), 3, 1, NULL,
760                         TONE_FREQUENCY, 0, freq);
761         if (error)
762                 printk(KERN_WARNING "error: setting tone frequency returned: %s\n", 
763                                 ppc_rtas_process_error(error));
764         return count;
765 }
766 /* ****************************************************************** */
767 static int ppc_rtas_tone_freq_show(struct seq_file *m, void *v)
768 {
769         seq_printf(m, "%lu\n", rtas_tone_frequency);
770         return 0;
771 }
772 /* ****************************************************************** */
773 /* INDICATORS - Tone Volume                                           */
774 /* ****************************************************************** */
775 static ssize_t ppc_rtas_tone_volume_write(struct file *file,
776                 const char __user *buf, size_t count, loff_t *ppos)
777 {
778         unsigned long volume;
779         int error = parse_number(buf, count, &volume);
780         if (error)
781                 return error;
782
783         if (volume > 100)
784                 volume = 100;
785         
786         rtas_tone_volume = volume; /* save it for later */
787         error = rtas_call(rtas_token("set-indicator"), 3, 1, NULL,
788                         TONE_VOLUME, 0, volume);
789         if (error)
790                 printk(KERN_WARNING "error: setting tone volume returned: %s\n", 
791                                 ppc_rtas_process_error(error));
792         return count;
793 }
794 /* ****************************************************************** */
795 static int ppc_rtas_tone_volume_show(struct seq_file *m, void *v)
796 {
797         seq_printf(m, "%lu\n", rtas_tone_volume);
798         return 0;
799 }
800
801 #define RMO_READ_BUF_MAX 30
802
803 /* RTAS Userspace access */
804 static int ppc_rtas_rmo_buf_show(struct seq_file *m, void *v)
805 {
806         seq_printf(m, "%016lx %x\n", rtas_rmo_buf, RTAS_RMOBUF_MAX);
807         return 0;
808 }