From 7cd23384f6720b025100e71e68072de1a198eb5b Mon Sep 17 00:00:00 2001 From: moosecrap Date: Sun, 16 Feb 2025 22:28:16 -0800 Subject: [PATCH] Added --i2c command line option --- README.md | 3 ++- evga-card.c | 11 ++++++++++- evga-card.h | 2 +- evga-icx.c | 16 +++++++++++++--- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 498d103..6d12709 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This program allows you to read temperature sensors off of supported EVGA 30-series iCX3 video cards, as well as control the fans individually. ## Prerequisites -A supported EVGA 30-series iCX3 card. I have not done extensive testing but belive this is every model of their: +A supported EVGA 30-series card with iCX3. This includes: * RTX 3060 Ti * RTX 3070 * RTX 3070 Ti @@ -39,6 +39,7 @@ Note that when controlling fans directly through iCX3 they will fall offline fro ```text Available options: +--i2c N : Only probe I2C bus N instead of all (may help with stuttering with --watch) --gpu N : Control only GPU N instead of all supported cards --fan SPEED : Set all fans at once to SPEED (see below) --fanN SPEED : Set fan N (0-3) to SPEED diff --git a/evga-card.c b/evga-card.c index 41f8cd7..1f0bd6f 100644 --- a/evga-card.c +++ b/evga-card.c @@ -8,7 +8,7 @@ /* Search all i2c device files for ones are on a PCI device of a supported GPU, and respond with the correct iCX3 version information */ -int find_evga_gpu_i2cs(struct card_info *infos, int max_gpus) +int find_evga_gpu_i2cs(struct card_info *infos, int max_gpus, int i2c_bus) { char i2c_devices_path[NAME_MAX]; char device_path[NAME_MAX]; @@ -20,6 +20,7 @@ int find_evga_gpu_i2cs(struct card_info *infos, int max_gpus) struct dirent *ent; int num_gpus = 0; + int current_i2c_bus = -1; unsigned short pci_vendor, pci_device, pci_subsystem_vendor, pci_subsystem_device = 0; /* Start looking for I2C adapters in /sys/bus/i2c/devices/ */ @@ -37,6 +38,14 @@ int find_evga_gpu_i2cs(struct card_info *infos, int max_gpus) if(strncmp(ent->d_name, "i2c-", 4) != 0) continue; + /* Only probe the specific device given (if provided) */ + if (i2c_bus >= 0) { + sscanf(ent->d_name, "i2c-%i", ¤t_i2c_bus); + if (current_i2c_bus != i2c_bus) + continue; + } + + strcpy(device_path, i2c_devices_path); strcat(device_path, ent->d_name); diff --git a/evga-card.h b/evga-card.h index 87353b2..79189bb 100644 --- a/evga-card.h +++ b/evga-card.h @@ -162,7 +162,7 @@ static struct gpu_pci_info evga_pci_ids[] = {"EVGA GeForce RTX 3090 Ti FTW3 Ultra Gaming" , NVIDIA_VEN, NVIDIA_RTX3090TI_DEV, EVGA_SUB_VEN, EVGA_RTX3090TI_FTW3_ULTRA_GAMING_SUB_DEV } }; -int find_evga_gpu_i2cs(struct card_info *infos, int max_gpus); +int find_evga_gpu_i2cs(struct card_info *infos, int max_gpus, int i2c_bus); unsigned short read_pci_id(char *device_path, char *field); char *read_nvidia_pci_address(char *device_path); diff --git a/evga-icx.c b/evga-icx.c index 38ae0be..64cd1fb 100644 --- a/evga-icx.c +++ b/evga-icx.c @@ -24,7 +24,8 @@ char *header_start = ""; char *header_end = ""; static const char helpstring[] = "Available options:\n" - "--gpu N : Control only GPU N instead of all supported cards\n" + "--i2c N : Only probe I2C bus N instead of all (may help with stuttering with --watch)\n" + "--gpu N : Control only GPU N instead of all supported cards\n" "--fan SPEED : Set all fans at once to SPEED (see below)\n" "--fanN SPEED : Set fan N (0-3) to SPEED\n" " SPEED may be one of the following:\n" @@ -47,13 +48,22 @@ int main (int argc, char **argv) int print_info = 0; int compact = 0; int gpu_num = -1; /* Card to control */ + int i2c_bus = -1; int overwrite = 0; unsigned int watch = 0; char *fan_speed[ICX3_MAX_FANS] = {NULL}; /* Input parsing */ for (int i = 1; i < argc; i++){ - if (strcmp(argv[i], "--gpu") == 0) { + if (strcmp(argv[i], "--i2c") == 0) { + i++; + if (i < argc) { + i2c_bus = atoi(argv[i]); + } else { + printf(helpstring); + return -1; + } + } else if (strcmp(argv[i], "--gpu") == 0) { i++; if (i < argc) { gpu_num = atoi(argv[i]); @@ -119,7 +129,7 @@ int main (int argc, char **argv) if (overwrite && !compact) overwrite = 0; - gpu_count = find_evga_gpu_i2cs(gpus, MAX_GPUS); + gpu_count = find_evga_gpu_i2cs(gpus, MAX_GPUS, i2c_bus); if (gpu_count == -1) { printf("Error scanning I2C devices\n");