rtas-proc.c 22 KB

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