rtas-proc.c 22 KB

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