aboutsummaryrefslogtreecommitdiffstats
path: root/plugin_i2c_sensors.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--plugin_i2c_sensors.c172
1 files changed, 93 insertions, 79 deletions
diff --git a/plugin_i2c_sensors.c b/plugin_i2c_sensors.c
index 0c08b81..662f6c2 100644
--- a/plugin_i2c_sensors.c
+++ b/plugin_i2c_sensors.c
@@ -1,8 +1,9 @@
-/* $Id: plugin_i2c_sensors.c,v 1.10 2004/02/14 12:07:27 nicowallmeier Exp $
+/* $Id: plugin_i2c_sensors.c,v 1.11 2004/02/15 21:43:43 reinelt Exp $
*
* I2C sensors plugin
*
* Copyright 2003,2004 Xavier Vello <xavier66@free.fr>
+ * Copyright 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
*
* This file is part of LCD4Linux.
*
@@ -22,6 +23,12 @@
*
*
* $Log: plugin_i2c_sensors.c,v $
+ * Revision 1.11 2004/02/15 21:43:43 reinelt
+ * T6963 driver nearly finished
+ * framework for graphic displays done
+ * i2c_sensors patch from Xavier
+ * some more old generation files removed
+ *
* Revision 1.10 2004/02/14 12:07:27 nicowallmeier
* minor bugfix
*
@@ -41,7 +48,6 @@
* loadavg() uClibc replacement from Martin Heyl
* round() uClibc replacement from Martin Hejl
* warning in i2c_sensors fixed
- * [
*
* Revision 1.5 2004/01/29 05:55:30 reinelt
* check for /sys mounted
@@ -59,7 +65,6 @@
*
* I2C Sensors plugin from Xavier added
*
- *
*/
/*
@@ -67,22 +72,34 @@
*
* int plugin_init_i2c_sensors (void)
* adds function i2c_sensors() to retrieve informations from
- * the i2c sensors via the sysfs interface of 2.6.x kernels
+ * the i2c sensors via sysfs or procfs interface
*
* -- WARNING --
- * This plugin is only for kernel series 2.5/2.6 and higher !
- * It uses the new sysfs pseudo-filesystem that you can mount with:
- * mount -t sysfs none /sys
- *
- * -- WARNING #2 --
* This plugin should detect where your sensors are at startup.
* If you can't get any token to work, ensure you don't get
* an error message with "lcd4linux -Fvvv".
*
* If so, try to force the path to your sensors in the conf like this :
- * i2c_sensors-path '/sys/bus/i2c/devices/0-6000/'
- * (replace 0-6000 with the appropriate dir)
- *
+ * for sysfs: i2c_sensors-path '/sys/bus/i2c/devices/0-6000/'
+ * for procfs: i2c_sensors-path '/proc/sys/dev/sensors/via686a-isa-6000'
+ * /!\ these path are for my system, change the last dir according to yours
+ */
+
+/*
+ * Available tokens : # represents an int from 1 to 3 (or more)
+ * temp_input# -> temperature of sensor # (in °C)
+ * temp_max# and temp_hyst# -> max and min of sensor #
+ * in_input#, in_min# and in_max# -> voltages
+ * fan_input# -> speed (in RPM) of fan #
+ * fan_min# and fan_div#
+ *
+ * Tokens avaible only via sysfs if suported by your sensors:
+ * curr_input#, curr_min# and curr_max# -> value of current (in amps)
+ * pwm#
+ * temp_crit# -> critical value of sensor #
+ * vid -> cpu core voltage
+ * and maybe others
+ * (see /usr/src/linux/Documentation/i2c/sysfs-interface on linux 2.6)
*/
#include "config.h"
@@ -104,25 +121,31 @@
#endif
static char *path=NULL;
+static int use_sysfs=0;
static HASH I2Csensors = { 0, };
+static const char *procfs_tokens[4][3] = {
+ {"temp_hyst", "temp_max", "temp_input"}, // for temp#
+ {"in_min", "in_max", "in_input"}, // for in#
+ {"fan_div1", "fan_div2", "fan_div3"}, // for fan_div
+ {"fan_min", "fan_input", ""} // for fan#
+};
+
/***********************************************\
* Parsing for new 2.6 kernels 'sysfs' interface *
\***********************************************/
-static int parse_i2c_sensors_sysfs(RESULT *arg)
+
+static int parse_i2c_sensors_sysfs(char *key)
{
double value;
char val[32];
char buffer[32];
- char *key=R2S(arg);
char file[64];
FILE *stream;
- // construct absolute path to the file to read
strcpy(file, path);
strcat(file, key);
- // read of file to buffer
stream=fopen(file, "r");
if (stream==NULL) {
error ("fopen(%s) failed",file);
@@ -153,51 +176,52 @@ static int parse_i2c_sensors_sysfs(RESULT *arg)
// we supress this nasty \n at the end
val[strlen(val)-1]='\0';
}
-
+
hash_set (&I2Csensors, key, val);
- return 0;
-}
+ return 0;
-void my_i2c_sensors_sysfs(RESULT *result, RESULT *arg)
-{
- int age;
- char *val;
- char *key=R2S(arg);
-
- age=hash_age(&I2Csensors, key, &val);
- // refresh every 100msec
- if (age<0 || age>100) {
- parse_i2c_sensors_sysfs(arg);
- val=hash_get(&I2Csensors, key);
- }
- if (val) {
- SetResult(&result, R_STRING, val);
- } else {
- SetResult(&result, R_STRING, "??");
- }
}
-
/************************************************\
* Parsing for old 2.4 kernels 'procfs' interface *
\************************************************/
-static int parse_i2c_sensors_procfs(RESULT *arg)
+static int parse_i2c_sensors_procfs(char *key)
{
- char *key=R2S(arg);
- char file[64];
+ char file[64];
FILE *stream;
char buffer[32];
char *value;
char *running;
int pos=0;
- const char delim[3]= " \n";
+ const char delim[3]=" \n";
char final_key[32];
-
+ char *number = &key[strlen(key)-1];
+ int tokens_index;
+ //debug("%s -> %s", key, number);
strcpy(file, path);
- strcat(file, key);
+
+ if (!strncmp(key, "temp_", 5)) {
+ tokens_index=0;
+ strcat(file, "temp");
+ strcat(file, number);
+ } else if (!strncmp(key, "in_", 3)) {
+ tokens_index=1;
+ strcat(file, "in");
+ strcat(file, number);
+ } else if (!strncmp(key, "fan_div", 7)) {
+ tokens_index=2;
+ strcat(file, "fan_div");
+ number = "";
+ } else if (!strncmp(key, "fan_", 4)) {
+ tokens_index=3;
+ strcat(file, "fan");
+ strcat(file, number);
+ } else {
+ return -1;
+ }
stream=fopen(file, "r");
if (stream==NULL) {
@@ -211,15 +235,17 @@ static int parse_i2c_sensors_procfs(RESULT *arg)
error ("%s empty ?!",file);
return -1;
}
-
+
running=strdupa(buffer);
while(1) {
value = strsep (&running, delim);
- // debug("%s pos %i -> %s", key, pos , value);
- if (!value) {
+ debug("%s pos %i -> %s", file, pos , value);
+ if (!value || !strcmp(value, "")) {
+ debug("%s pos %i -> BREAK", file, pos);
break;
} else {
- sprintf (final_key, "%s.%i", key, pos);
+ sprintf (final_key, "%s%s", procfs_tokens[tokens_index][pos], number);
+ debug ("%s -> %s", final_key, value);
hash_set (&I2Csensors, final_key, value);
pos++;
}
@@ -227,29 +253,23 @@ static int parse_i2c_sensors_procfs(RESULT *arg)
return 0;
}
-void my_i2c_sensors_procfs(RESULT *result, int argc, RESULT *argv[])
+ /*****************************************\
+ * Common functions (path search and init) *
+ \*****************************************/
+
+void my_i2c_sensors(RESULT *result, RESULT *arg)
{
int age;
char *val;
- char *key;
+ char *key=R2S(arg);
- switch (argc) {
- case 1:
- sprintf(key, "%s.0", R2S(argv[0]));
- break;
- case 2:
- sprintf(key, "%s.%s", R2S(argv[0]), R2S(argv[1]));
- break;
- default:
- return;
- break;
- }
-
age=hash_age(&I2Csensors, key, &val);
-
- // refresh every 100msec
- if (age<0 || age>100) {
- parse_i2c_sensors_procfs(argv[0]);
+ if (age<0 || age>250) {
+ if (use_sysfs) {
+ parse_i2c_sensors_sysfs(key);
+ } else {
+ parse_i2c_sensors_procfs(key);
+ }
val=hash_get(&I2Csensors, key);
}
if (val) {
@@ -259,10 +279,6 @@ void my_i2c_sensors_procfs(RESULT *result, int argc, RESULT *argv[])
}
}
- /*****************************************\
- * Common functions (path search and init) *
- \*****************************************/
-
void my_i2c_sensors_path(char *method)
{
struct dirent *dir;
@@ -277,11 +293,10 @@ void my_i2c_sensors_path(char *method)
base="/sys/bus/i2c/devices/";
} else if (!strcmp(method, "procfs")) {
base="/proc/sys/dev/sensors/";
- //base="/sensors_2.4/"; // fake dir to test without rebooting 2.4 ;)
+ //base="/sensors_2.4/"; // fake dir to test without rebooting 2.4 ;)
} else {
return;
}
-
fd1 = opendir(base);
if (!fd1) {
@@ -295,9 +310,9 @@ void my_i2c_sensors_path(char *method)
while((dir = readdir(fd1))) {
// Skip non-directories and '.' and '..'
- if (dir->d_type!=DT_DIR ||
- strcmp(dir->d_name, "." )==0 ||
- strcmp(dir->d_name, "..")==0) {
+ if (dir->d_type!=DT_DIR ||
+ strcmp(dir->d_name, "." )==0 ||
+ strcmp(dir->d_name, "..")==0) {
continue;
}
@@ -327,7 +342,7 @@ int plugin_init_i2c_sensors (void)
char *path_cfg=cfg_get(NULL, "i2c_sensors-path", "");
if (strncmp(path_cfg, "/", 1)) {
- debug("No path to i2c sensors found in the conf, calling my_i2c_sensors_path()");
+ //debug("No path to i2c sensors found in the conf, calling my_i2c_sensors_path()");
my_i2c_sensors_path("sysfs");
if (!path)
my_i2c_sensors_path("procfs");
@@ -358,11 +373,10 @@ int plugin_init_i2c_sensors (void)
if (!path) {
free(path);
} else {
- if (!strncmp(path, "/sys", 4)) {
- AddFunction ("i2c_sensors", 1, my_i2c_sensors_sysfs);
- } else if (!strncmp(path, "/proc", 5)) {
- AddFunction ("i2c_sensors", -1, my_i2c_sensors_procfs);
+ if (strncmp(path, "/sys", 4)==0) {
+ use_sysfs=1;
}
+ AddFunction ("i2c_sensors", 1, my_i2c_sensors);
}
return 0;