rtas-proc.c 21 KB

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