rtas-proc.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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. static 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. static 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. static 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. static 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. static 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. static 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. static 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. if (!machine_is(pseries))
  228. return -ENODEV;
  229. rtas_node = of_find_node_by_name(NULL, "rtas");
  230. if (rtas_node == NULL)
  231. return -ENODEV;
  232. proc_create("powerpc/rtas/progress", S_IRUGO|S_IWUSR, NULL,
  233. &ppc_rtas_progress_operations);
  234. proc_create("powerpc/rtas/clock", S_IRUGO|S_IWUSR, NULL,
  235. &ppc_rtas_clock_operations);
  236. proc_create("powerpc/rtas/poweron", S_IWUSR|S_IRUGO, NULL,
  237. &ppc_rtas_poweron_operations);
  238. proc_create("powerpc/rtas/sensors", S_IRUGO, NULL,
  239. &ppc_rtas_sensors_operations);
  240. proc_create("powerpc/rtas/frequency", S_IWUSR|S_IRUGO, NULL,
  241. &ppc_rtas_tone_freq_operations);
  242. proc_create("powerpc/rtas/volume", S_IWUSR|S_IRUGO, NULL,
  243. &ppc_rtas_tone_volume_operations);
  244. proc_create("powerpc/rtas/rmo_buffer", S_IRUSR, NULL,
  245. &ppc_rtas_rmo_buf_ops);
  246. return 0;
  247. }
  248. __initcall(proc_rtas_init);
  249. static int parse_number(const char __user *p, size_t count, unsigned long *val)
  250. {
  251. char buf[40];
  252. char *end;
  253. if (count > 39)
  254. return -EINVAL;
  255. if (copy_from_user(buf, p, count))
  256. return -EFAULT;
  257. buf[count] = 0;
  258. *val = simple_strtoul(buf, &end, 10);
  259. if (*end && *end != '\n')
  260. return -EINVAL;
  261. return 0;
  262. }
  263. /* ****************************************************************** */
  264. /* POWER-ON-TIME */
  265. /* ****************************************************************** */
  266. static ssize_t ppc_rtas_poweron_write(struct file *file,
  267. const char __user *buf, size_t count, loff_t *ppos)
  268. {
  269. struct rtc_time tm;
  270. unsigned long nowtime;
  271. int error = parse_number(buf, count, &nowtime);
  272. if (error)
  273. return error;
  274. power_on_time = nowtime; /* save the time */
  275. to_tm(nowtime, &tm);
  276. error = rtas_call(rtas_token("set-time-for-power-on"), 7, 1, NULL,
  277. tm.tm_year, tm.tm_mon, tm.tm_mday,
  278. tm.tm_hour, tm.tm_min, tm.tm_sec, 0 /* nano */);
  279. if (error)
  280. printk(KERN_WARNING "error: setting poweron time returned: %s\n",
  281. ppc_rtas_process_error(error));
  282. return count;
  283. }
  284. /* ****************************************************************** */
  285. static int ppc_rtas_poweron_show(struct seq_file *m, void *v)
  286. {
  287. if (power_on_time == 0)
  288. seq_printf(m, "Power on time not set\n");
  289. else
  290. seq_printf(m, "%lu\n",power_on_time);
  291. return 0;
  292. }
  293. /* ****************************************************************** */
  294. /* PROGRESS */
  295. /* ****************************************************************** */
  296. static ssize_t ppc_rtas_progress_write(struct file *file,
  297. const char __user *buf, size_t count, loff_t *ppos)
  298. {
  299. unsigned long hex;
  300. if (count >= MAX_LINELENGTH)
  301. count = MAX_LINELENGTH -1;
  302. if (copy_from_user(progress_led, buf, count)) { /* save the string */
  303. return -EFAULT;
  304. }
  305. progress_led[count] = 0;
  306. /* Lets see if the user passed hexdigits */
  307. hex = simple_strtoul(progress_led, NULL, 10);
  308. rtas_progress ((char *)progress_led, hex);
  309. return count;
  310. /* clear the line */
  311. /* rtas_progress(" ", 0xffff);*/
  312. }
  313. /* ****************************************************************** */
  314. static int ppc_rtas_progress_show(struct seq_file *m, void *v)
  315. {
  316. if (progress_led[0])
  317. seq_printf(m, "%s\n", progress_led);
  318. return 0;
  319. }
  320. /* ****************************************************************** */
  321. /* CLOCK */
  322. /* ****************************************************************** */
  323. static ssize_t ppc_rtas_clock_write(struct file *file,
  324. const char __user *buf, size_t count, loff_t *ppos)
  325. {
  326. struct rtc_time tm;
  327. unsigned long nowtime;
  328. int error = parse_number(buf, count, &nowtime);
  329. if (error)
  330. return error;
  331. to_tm(nowtime, &tm);
  332. error = rtas_call(rtas_token("set-time-of-day"), 7, 1, NULL,
  333. tm.tm_year, tm.tm_mon, tm.tm_mday,
  334. tm.tm_hour, tm.tm_min, tm.tm_sec, 0);
  335. if (error)
  336. printk(KERN_WARNING "error: setting the clock returned: %s\n",
  337. ppc_rtas_process_error(error));
  338. return count;
  339. }
  340. /* ****************************************************************** */
  341. static int ppc_rtas_clock_show(struct seq_file *m, void *v)
  342. {
  343. int ret[8];
  344. int error = rtas_call(rtas_token("get-time-of-day"), 0, 8, ret);
  345. if (error) {
  346. printk(KERN_WARNING "error: reading the clock returned: %s\n",
  347. ppc_rtas_process_error(error));
  348. seq_printf(m, "0");
  349. } else {
  350. unsigned int year, mon, day, hour, min, sec;
  351. year = ret[0]; mon = ret[1]; day = ret[2];
  352. hour = ret[3]; min = ret[4]; sec = ret[5];
  353. seq_printf(m, "%lu\n",
  354. mktime(year, mon, day, hour, min, sec));
  355. }
  356. return 0;
  357. }
  358. /* ****************************************************************** */
  359. /* SENSOR STUFF */
  360. /* ****************************************************************** */
  361. static int ppc_rtas_sensors_show(struct seq_file *m, void *v)
  362. {
  363. int i,j;
  364. int state, error;
  365. int get_sensor_state = rtas_token("get-sensor-state");
  366. seq_printf(m, "RTAS (RunTime Abstraction Services) Sensor Information\n");
  367. seq_printf(m, "Sensor\t\tValue\t\tCondition\tLocation\n");
  368. seq_printf(m, "********************************************************\n");
  369. if (ppc_rtas_find_all_sensors() != 0) {
  370. seq_printf(m, "\nNo sensors are available\n");
  371. return 0;
  372. }
  373. for (i=0; i<sensors.quant; i++) {
  374. struct individual_sensor *p = &sensors.sensor[i];
  375. char rstr[64];
  376. const char *loc;
  377. int llen, offs;
  378. sprintf (rstr, SENSOR_PREFIX"%04d", p->token);
  379. loc = of_get_property(rtas_node, rstr, &llen);
  380. /* A sensor may have multiple instances */
  381. for (j = 0, offs = 0; j <= p->quant; j++) {
  382. error = rtas_call(get_sensor_state, 2, 2, &state,
  383. p->token, j);
  384. ppc_rtas_process_sensor(m, p, state, error, loc);
  385. seq_putc(m, '\n');
  386. if (loc) {
  387. offs += strlen(loc) + 1;
  388. loc += strlen(loc) + 1;
  389. if (offs >= llen)
  390. loc = NULL;
  391. }
  392. }
  393. }
  394. return 0;
  395. }
  396. /* ****************************************************************** */
  397. static int ppc_rtas_find_all_sensors(void)
  398. {
  399. const unsigned int *utmp;
  400. int len, i;
  401. utmp = of_get_property(rtas_node, "rtas-sensors", &len);
  402. if (utmp == NULL) {
  403. printk (KERN_ERR "error: could not get rtas-sensors\n");
  404. return 1;
  405. }
  406. sensors.quant = len / 8; /* int + int */
  407. for (i=0; i<sensors.quant; i++) {
  408. sensors.sensor[i].token = *utmp++;
  409. sensors.sensor[i].quant = *utmp++;
  410. }
  411. return 0;
  412. }
  413. /* ****************************************************************** */
  414. /*
  415. * Builds a string of what rtas returned
  416. */
  417. static char *ppc_rtas_process_error(int error)
  418. {
  419. switch (error) {
  420. case SENSOR_CRITICAL_HIGH:
  421. return "(critical high)";
  422. case SENSOR_WARNING_HIGH:
  423. return "(warning high)";
  424. case SENSOR_NORMAL:
  425. return "(normal)";
  426. case SENSOR_WARNING_LOW:
  427. return "(warning low)";
  428. case SENSOR_CRITICAL_LOW:
  429. return "(critical low)";
  430. case SENSOR_SUCCESS:
  431. return "(read ok)";
  432. case SENSOR_HW_ERROR:
  433. return "(hardware error)";
  434. case SENSOR_BUSY:
  435. return "(busy)";
  436. case SENSOR_NOT_EXIST:
  437. return "(non existent)";
  438. case SENSOR_DR_ENTITY:
  439. return "(dr entity removed)";
  440. default:
  441. return "(UNKNOWN)";
  442. }
  443. }
  444. /* ****************************************************************** */
  445. /*
  446. * Builds a string out of what the sensor said
  447. */
  448. static void ppc_rtas_process_sensor(struct seq_file *m,
  449. struct individual_sensor *s, int state, int error, const char *loc)
  450. {
  451. /* Defined return vales */
  452. const char * key_switch[] = { "Off\t", "Normal\t", "Secure\t",
  453. "Maintenance" };
  454. const char * enclosure_switch[] = { "Closed", "Open" };
  455. const char * lid_status[] = { " ", "Open", "Closed" };
  456. const char * power_source[] = { "AC\t", "Battery",
  457. "AC & Battery" };
  458. const char * battery_remaining[] = { "Very Low", "Low", "Mid", "High" };
  459. const char * epow_sensor[] = {
  460. "EPOW Reset", "Cooling warning", "Power warning",
  461. "System shutdown", "System halt", "EPOW main enclosure",
  462. "EPOW power off" };
  463. const char * battery_cyclestate[] = { "None", "In progress",
  464. "Requested" };
  465. const char * battery_charging[] = { "Charging", "Discharching",
  466. "No current flow" };
  467. const char * ibm_drconnector[] = { "Empty", "Present", "Unusable",
  468. "Exchange" };
  469. int have_strings = 0;
  470. int num_states = 0;
  471. int temperature = 0;
  472. int unknown = 0;
  473. /* What kind of sensor do we have here? */
  474. switch (s->token) {
  475. case KEY_SWITCH:
  476. seq_printf(m, "Key switch:\t");
  477. num_states = sizeof(key_switch) / sizeof(char *);
  478. if (state < num_states) {
  479. seq_printf(m, "%s\t", key_switch[state]);
  480. have_strings = 1;
  481. }
  482. break;
  483. case ENCLOSURE_SWITCH:
  484. seq_printf(m, "Enclosure switch:\t");
  485. num_states = sizeof(enclosure_switch) / sizeof(char *);
  486. if (state < num_states) {
  487. seq_printf(m, "%s\t",
  488. enclosure_switch[state]);
  489. have_strings = 1;
  490. }
  491. break;
  492. case THERMAL_SENSOR:
  493. seq_printf(m, "Temp. (C/F):\t");
  494. temperature = 1;
  495. break;
  496. case LID_STATUS:
  497. seq_printf(m, "Lid status:\t");
  498. num_states = sizeof(lid_status) / sizeof(char *);
  499. if (state < num_states) {
  500. seq_printf(m, "%s\t", lid_status[state]);
  501. have_strings = 1;
  502. }
  503. break;
  504. case POWER_SOURCE:
  505. seq_printf(m, "Power source:\t");
  506. num_states = sizeof(power_source) / sizeof(char *);
  507. if (state < num_states) {
  508. seq_printf(m, "%s\t",
  509. power_source[state]);
  510. have_strings = 1;
  511. }
  512. break;
  513. case BATTERY_VOLTAGE:
  514. seq_printf(m, "Battery voltage:\t");
  515. break;
  516. case BATTERY_REMAINING:
  517. seq_printf(m, "Battery remaining:\t");
  518. num_states = sizeof(battery_remaining) / sizeof(char *);
  519. if (state < num_states)
  520. {
  521. seq_printf(m, "%s\t",
  522. battery_remaining[state]);
  523. have_strings = 1;
  524. }
  525. break;
  526. case BATTERY_PERCENTAGE:
  527. seq_printf(m, "Battery percentage:\t");
  528. break;
  529. case EPOW_SENSOR:
  530. seq_printf(m, "EPOW Sensor:\t");
  531. num_states = sizeof(epow_sensor) / sizeof(char *);
  532. if (state < num_states) {
  533. seq_printf(m, "%s\t", epow_sensor[state]);
  534. have_strings = 1;
  535. }
  536. break;
  537. case BATTERY_CYCLESTATE:
  538. seq_printf(m, "Battery cyclestate:\t");
  539. num_states = sizeof(battery_cyclestate) /
  540. sizeof(char *);
  541. if (state < num_states) {
  542. seq_printf(m, "%s\t",
  543. battery_cyclestate[state]);
  544. have_strings = 1;
  545. }
  546. break;
  547. case BATTERY_CHARGING:
  548. seq_printf(m, "Battery Charging:\t");
  549. num_states = sizeof(battery_charging) / sizeof(char *);
  550. if (state < num_states) {
  551. seq_printf(m, "%s\t",
  552. battery_charging[state]);
  553. have_strings = 1;
  554. }
  555. break;
  556. case IBM_SURVEILLANCE:
  557. seq_printf(m, "Surveillance:\t");
  558. break;
  559. case IBM_FANRPM:
  560. seq_printf(m, "Fan (rpm):\t");
  561. break;
  562. case IBM_VOLTAGE:
  563. seq_printf(m, "Voltage (mv):\t");
  564. break;
  565. case IBM_DRCONNECTOR:
  566. seq_printf(m, "DR connector:\t");
  567. num_states = sizeof(ibm_drconnector) / sizeof(char *);
  568. if (state < num_states) {
  569. seq_printf(m, "%s\t",
  570. ibm_drconnector[state]);
  571. have_strings = 1;
  572. }
  573. break;
  574. case IBM_POWERSUPPLY:
  575. seq_printf(m, "Powersupply:\t");
  576. break;
  577. default:
  578. seq_printf(m, "Unknown sensor (type %d), ignoring it\n",
  579. s->token);
  580. unknown = 1;
  581. have_strings = 1;
  582. break;
  583. }
  584. if (have_strings == 0) {
  585. if (temperature) {
  586. seq_printf(m, "%4d /%4d\t", state, cel_to_fahr(state));
  587. } else
  588. seq_printf(m, "%10d\t", state);
  589. }
  590. if (unknown == 0) {
  591. seq_printf(m, "%s\t", ppc_rtas_process_error(error));
  592. get_location_code(m, s, loc);
  593. }
  594. }
  595. /* ****************************************************************** */
  596. static void check_location(struct seq_file *m, const char *c)
  597. {
  598. switch (c[0]) {
  599. case LOC_PLANAR:
  600. seq_printf(m, "Planar #%c", c[1]);
  601. break;
  602. case LOC_CPU:
  603. seq_printf(m, "CPU #%c", c[1]);
  604. break;
  605. case LOC_FAN:
  606. seq_printf(m, "Fan #%c", c[1]);
  607. break;
  608. case LOC_RACKMOUNTED:
  609. seq_printf(m, "Rack #%c", c[1]);
  610. break;
  611. case LOC_VOLTAGE:
  612. seq_printf(m, "Voltage #%c", c[1]);
  613. break;
  614. case LOC_LCD:
  615. seq_printf(m, "LCD #%c", c[1]);
  616. break;
  617. case '.':
  618. seq_printf(m, "- %c", c[1]);
  619. break;
  620. default:
  621. seq_printf(m, "Unknown location");
  622. break;
  623. }
  624. }
  625. /* ****************************************************************** */
  626. /*
  627. * Format:
  628. * ${LETTER}${NUMBER}[[-/]${LETTER}${NUMBER} [ ... ] ]
  629. * the '.' may be an abbrevation
  630. */
  631. static void check_location_string(struct seq_file *m, const char *c)
  632. {
  633. while (*c) {
  634. if (isalpha(*c) || *c == '.')
  635. check_location(m, c);
  636. else if (*c == '/' || *c == '-')
  637. seq_printf(m, " at ");
  638. c++;
  639. }
  640. }
  641. /* ****************************************************************** */
  642. static void get_location_code(struct seq_file *m, struct individual_sensor *s,
  643. const char *loc)
  644. {
  645. if (!loc || !*loc) {
  646. seq_printf(m, "---");/* does not have a location */
  647. } else {
  648. check_location_string(m, loc);
  649. }
  650. seq_putc(m, ' ');
  651. }
  652. /* ****************************************************************** */
  653. /* INDICATORS - Tone Frequency */
  654. /* ****************************************************************** */
  655. static ssize_t ppc_rtas_tone_freq_write(struct file *file,
  656. const char __user *buf, size_t count, loff_t *ppos)
  657. {
  658. unsigned long freq;
  659. int error = parse_number(buf, count, &freq);
  660. if (error)
  661. return error;
  662. rtas_tone_frequency = freq; /* save it for later */
  663. error = rtas_call(rtas_token("set-indicator"), 3, 1, NULL,
  664. TONE_FREQUENCY, 0, freq);
  665. if (error)
  666. printk(KERN_WARNING "error: setting tone frequency returned: %s\n",
  667. ppc_rtas_process_error(error));
  668. return count;
  669. }
  670. /* ****************************************************************** */
  671. static int ppc_rtas_tone_freq_show(struct seq_file *m, void *v)
  672. {
  673. seq_printf(m, "%lu\n", rtas_tone_frequency);
  674. return 0;
  675. }
  676. /* ****************************************************************** */
  677. /* INDICATORS - Tone Volume */
  678. /* ****************************************************************** */
  679. static ssize_t ppc_rtas_tone_volume_write(struct file *file,
  680. const char __user *buf, size_t count, loff_t *ppos)
  681. {
  682. unsigned long volume;
  683. int error = parse_number(buf, count, &volume);
  684. if (error)
  685. return error;
  686. if (volume > 100)
  687. volume = 100;
  688. rtas_tone_volume = volume; /* save it for later */
  689. error = rtas_call(rtas_token("set-indicator"), 3, 1, NULL,
  690. TONE_VOLUME, 0, volume);
  691. if (error)
  692. printk(KERN_WARNING "error: setting tone volume returned: %s\n",
  693. ppc_rtas_process_error(error));
  694. return count;
  695. }
  696. /* ****************************************************************** */
  697. static int ppc_rtas_tone_volume_show(struct seq_file *m, void *v)
  698. {
  699. seq_printf(m, "%lu\n", rtas_tone_volume);
  700. return 0;
  701. }
  702. #define RMO_READ_BUF_MAX 30
  703. /* RTAS Userspace access */
  704. static int ppc_rtas_rmo_buf_show(struct seq_file *m, void *v)
  705. {
  706. seq_printf(m, "%016lx %x\n", rtas_rmo_buf, RTAS_RMOBUF_MAX);
  707. return 0;
  708. }