Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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