From 543632712ec9e8239228236832a6406719260f1b Mon Sep 17 00:00:00 2001 From: thomb Date: Mon, 21 Jun 2021 16:56:33 +0200 Subject: [PATCH] libsensors + sensors: Add freq_input support --- lib/sensors.h | 2 ++ lib/sysfs.c | 8 ++++++++ prog/sensors/chips.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/lib/sensors.h b/lib/sensors.h index 94f6f230..62ce22cd 100644 --- a/lib/sensors.h +++ b/lib/sensors.h @@ -148,6 +148,7 @@ typedef enum sensors_feature_type { SENSORS_FEATURE_INTRUSION = 0x11, SENSORS_FEATURE_MAX_OTHER, SENSORS_FEATURE_BEEP_ENABLE = 0x18, + SENSORS_FEATURE_FREQ, SENSORS_FEATURE_MAX, SENSORS_FEATURE_UNKNOWN = INT_MAX, } sensors_feature_type; @@ -251,6 +252,7 @@ typedef enum sensors_subfeature_type { SENSORS_SUBFEATURE_BEEP_ENABLE = SENSORS_FEATURE_BEEP_ENABLE << 8, + SENSORS_SUBFEATURE_FREQ_INPUT = SENSORS_FEATURE_FREQ << 8, SENSORS_SUBFEATURE_UNKNOWN = INT_MAX, } sensors_subfeature_type; diff --git a/lib/sysfs.c b/lib/sysfs.c index 9516cec4..2c11a436 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -152,6 +152,7 @@ int get_type_scaling(sensors_subfeature_type type) return 1; case SENSORS_SUBFEATURE_POWER_AVERAGE: case SENSORS_SUBFEATURE_ENERGY_INPUT: + case SENSORS_SUBFEATURE_FREQ_INPUT: return 1000000; } @@ -181,6 +182,7 @@ char *get_feature_name(sensors_feature_type ftype, char *sfname) case SENSORS_FEATURE_CURR: case SENSORS_FEATURE_HUMIDITY: case SENSORS_FEATURE_INTRUSION: + case SENSORS_FEATURE_FREQ: underscore = strchr(sfname, '_'); name = strndup(sfname, underscore - sfname); if (!name) @@ -329,6 +331,11 @@ static const struct subfeature_type_match intrusion_matches[] = { { "beep", SENSORS_SUBFEATURE_INTRUSION_BEEP }, { NULL, 0 } }; + +static const struct subfeature_type_match freq_matches[] = { + { "input", SENSORS_SUBFEATURE_FREQ_INPUT }, + { NULL, 0 } +}; static struct feature_type_match matches[] = { { "temp%d%c", temp_matches }, { "in%d%c", in_matches }, @@ -339,6 +346,7 @@ static struct feature_type_match matches[] = { { "energy%d%c", energy_matches }, { "intrusion%d%c", intrusion_matches }, { "humidity%d%c", humidity_matches }, + { "freq%d%c", freq_matches }, }; /* Return the subfeature type and channel number based on the subfeature diff --git a/prog/sensors/chips.c b/prog/sensors/chips.c index 0eb07418..82136618 100644 --- a/prog/sensors/chips.c +++ b/prog/sensors/chips.c @@ -833,6 +833,33 @@ static void print_chip_curr(const sensors_chip_name *name, printf("\n"); } +static void print_chip_freq(const sensors_chip_name *name, + const sensors_feature *feature, + int label_size) +{ + const sensors_subfeature *sf; + double val; + char *label; + + if (!(label = sensors_get_label(name, feature))) { + fprintf(stderr, "ERROR: Can't get label of feature %s!\n", + feature->name); + return; + } + print_label(label, label_size); + free(label); + + sf = sensors_get_subfeature(name, feature, + SENSORS_SUBFEATURE_FREQ_INPUT); + if (sf && get_input_value(name, sf, &val) == 0) { + printf("%4.0f %s", val, "MHz"); + } else { + printf(" N/A "); + } + + printf("\n"); +} + static void print_chip_intrusion(const sensors_chip_name *name, const sensors_feature *feature, int label_size) @@ -894,6 +921,9 @@ void print_chip(const sensors_chip_name *name) case SENSORS_FEATURE_HUMIDITY: print_chip_humidity(name, feature, label_size); break; + case SENSORS_FEATURE_FREQ: + print_chip_freq(name, feature, label_size); + break; default: continue; }