rtas-proc.c 22 KB

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