rtas-proc.c 22 KB

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