From cc6c1a12a4cffb19cfc6e9123be9202ed35be76a Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Wed, 31 Dec 2003 21:30:43 +0000 Subject: [PATCH] Add support for the Linux 2.6 version of the lm90 driver. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2197 7894878c-1315-0410-8ee3-d5d059ff63e0 --- etc/sensors.conf.eg | 16 +++++++++++++++- lib/chips.c | 2 +- lib/proc.c | 22 ++++++++++++++++++++-- prog/sensors/chips.c | 39 ++++++++++++++++++++++++++++++--------- 4 files changed, 66 insertions(+), 13 deletions(-) diff --git a/etc/sensors.conf.eg b/etc/sensors.conf.eg index 1f59cfc2..243adf3c 100644 --- a/etc/sensors.conf.eg +++ b/etc/sensors.conf.eg @@ -1628,8 +1628,22 @@ chip "lm90-*" "adm1032-*" # set tcrit2 85 # change the hysteresis value to fit your needs -# relative value, applies to both critical thresholds +# This is a little bit tricky. Under Linux 2.4, this is a relative value +# and applies to both critical thresholds. This is a direct representation +# of the chipset register. # set hyst 5 +# Under Linux 2.6 however, this is an absolute value and applies to +# tcrit2. Keep in mind that this is still internally represented as a +# relative, common value (because there's a single register, holding a +# relative value, in the chipset itself) so it is important to set it +# *after* setting tcrit2 (i.e. don't change the set lines order). +# set hyst 80 +# Tcrit1 hysteresis value will be set automatically, with the same delta. +# In this example (with tcrit1=75 and tcrit2=85), the internal register +# would be set to 5, and the hysteresis temperature for tcrit1 would be 70. +# Note that the internal register cannot hold values greater than 31, so +# the delta between critical temperatures and respective absolute hysteresis +# can never exceed this value. chip "vt1211-*" "vt8231-*" # diff --git a/lib/chips.c b/lib/chips.c index 62a9e635..605b116c 100644 --- a/lib/chips.c +++ b/lib/chips.c @@ -729,7 +729,7 @@ static sensors_chip_feature lm90_features[] = RW, LM90_SYSCTL_REMOTE_TCRIT, VALUE(1), 0 }, { SENSORS_LM90_TCRIT_HYST, "hyst", NOMAP, NOMAP, - RW, LM90_SYSCTL_HYST, VALUE(1), 0 }, + RW, LM90_SYSCTL_HYST, VALUE(1), 0, "temp_hyst2", 3 }, { SENSORS_LM90_ALARMS, "alarms", NOMAP, NOMAP, R, LM90_SYSCTL_ALARMS, VALUE(1), 0 }, diff --git a/lib/proc.c b/lib/proc.c index 47ae2735..d73ea1cd 100644 --- a/lib/proc.c +++ b/lib/proc.c @@ -411,7 +411,7 @@ int sensors_write_proc(sensors_chip_name name, int feature, double value) Returns the sysfs name and magnitude for a given feature. First looks for a sysfs name and magnitude in the feature structure. These should be added in chips.c for all non-standard feature names. - If that fails, converts common /proc feature names + If that fails, converts common /proc feature names to their sysfs equivalent, and uses common sysfs magnitude. Common magnitudes are #defined above. Common conversions are as follows: @@ -424,8 +424,11 @@ int sensors_write_proc(sensors_chip_name name, int feature, double value) temp%d_over -> temp_max%d (to be changed after kernel patch) temp%d_hyst -> temp_min%d ("") temp%d_max -> temp_max%d + temp%d_high -> temp_max%d temp%d_min -> temp_min%d + temp%d_low -> temp_min%d temp%d -> temp_input%d + tcrit%d -> temp_crit%d AND all conversions listed in the matches[] structure below. If that fails, returns old /proc feature name and magnitude. @@ -450,7 +453,7 @@ int getsysname(const sensors_chip_feature *feature, char *sysname, int *sysmag) struct match matches[] = { { "beeps", "beep_mask", 0 }, { "pwm", "pwm1", 0 }, - { "rempte_temp", "temp_input2", TEMPMAG }, + { "remote_temp", "temp_input2", TEMPMAG }, { "remote_temp_hyst", "temp_hyst2", TEMPMAG }, { "remote_temp_low", "temp_min2", TEMPMAG }, { "remote_temp_over", "temp_max2", TEMPMAG }, @@ -541,11 +544,26 @@ int getsysname(const sensors_chip_feature *feature, char *sysname, int *sysmag) *sysmag = TEMPMAG; return 0; } + if(sscanf(name, "temp%d_lo%c%c", &num, &last, &check) == 2 && last == 'w') { + sprintf(sysname, "temp_min%d", num); + *sysmag = TEMPMAG; + return 0; + } if(sscanf(name, "temp%d_ma%c%c", &num, &last, &check) == 2 && last == 'x') { sprintf(sysname, "temp_max%d", num); *sysmag = TEMPMAG; return 0; } + if(sscanf(name, "temp%d_hig%c%c", &num, &last, &check) == 2 && last == 'h') { + sprintf(sysname, "temp_max%d", num); + *sysmag = TEMPMAG; + return 0; + } + if(sscanf(name, "tcrit%d%c", &num, &check) == 1) { + sprintf(sysname, "temp_crit%d", num); + *sysmag = TEMPMAG; + return 0; + } if(sscanf(name, "temp%d%c", &num, &check) == 1) { sprintf(sysname, "temp_input%d", num); *sysmag = TEMPMAG; diff --git a/prog/sensors/chips.c b/prog/sensors/chips.c index fef007de..17115311 100644 --- a/prog/sensors/chips.c +++ b/prog/sensors/chips.c @@ -4536,7 +4536,7 @@ void print_lm83(const sensors_chip_name *name) void print_lm90(const sensors_chip_name *name) { char *label; - double cur, high, low; + double cur, high, low, hyst; int valid, alarms; if (!sensors_get_feature(*name, SENSORS_LM90_ALARMS, &cur)) @@ -4579,13 +4579,36 @@ void print_lm90(const sensors_chip_name *name) printf("ERROR: Can't get remote temperature data!\n"); free_the_label(&label); + /* 2.6 tweak: + * In 2.4 there is only one, relative hyst value, (default 10). + * In 2.6 there are two, absolute values. + * The library will link hyst (2.4) to temp_hyst2 (2.6) and we have + * to compute the relative value from temp_hyst2 and temp_crit2. + * We detect that using the following rules: + * - if hyst is not in the range 0..31, it is absolute (2.6); + * - if hyst exceeds tcrit1 or tcrit2, it is absolute (2.6); + * - if hyst is greater than it would be if considered absolute, + * it is absolute (heuristic); + * - else it is relative (2.4). + * Also note that the use of low and high right below is + * arbitrary, only to reuse previously defined variables, at the + * admitted cost of a lower readability. + */ + if (!sensors_get_feature(*name, SENSORS_LM90_TCRIT_HYST, &hyst) + && !sensors_get_feature(*name, SENSORS_LM90_LOCAL_TCRIT, &low) + && !sensors_get_feature(*name, SENSORS_LM90_REMOTE_TCRIT, &high)) { + if (hyst<=-0.5 || hyst>=31.5 || hyst>low || hyst>high || hyst>high-hyst) + hyst = high-hyst; + } else { + printf("ERROR: Can't get hyst data!\n"); + hyst = 10; + } + if (!sensors_get_label_and_valid(*name, SENSORS_LM90_LOCAL_TCRIT, - &label, &valid) - && !sensors_get_feature(*name, SENSORS_LM90_LOCAL_TCRIT, &high) - && !sensors_get_feature(*name, SENSORS_LM90_TCRIT_HYST, &low)) { + &label, &valid)) { if (valid) { print_label(label, 10); - print_temp_info(high, high-low, 0, HYSTONLY, 0, 0); + print_temp_info(low, low-hyst, 0, HYSTONLY, 0, 0); printf("\n"); } } else @@ -4593,12 +4616,10 @@ void print_lm90(const sensors_chip_name *name) free_the_label(&label); if (!sensors_get_label_and_valid(*name, SENSORS_LM90_REMOTE_TCRIT, - &label, &valid) - && !sensors_get_feature(*name, SENSORS_LM90_REMOTE_TCRIT, &high) - && !sensors_get_feature(*name, SENSORS_LM90_TCRIT_HYST, &low)) { + &label, &valid)) { if (valid) { print_label(label, 10); - print_temp_info(high, high-low, 0, HYSTONLY, 0, 0); + print_temp_info(high, high-hyst, 0, HYSTONLY, 0, 0); printf("\n"); } } else