evga-icx/icx3.c
2025-01-19 23:27:43 -08:00

73 lines
1.8 KiB
C

#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <i2c/smbus.h>
#include "icx3.h"
void *print_icx3_temp(int fp)
{
int read_result;
char buff[1024];
struct icx3_fancontrol *fanstatus;
for (int i=0; i < ICX3_MAX_FANS; i++) {
read_result = i2c_smbus_read_i2c_block_data(fp, ICX3_REG_FANCONTROL + i, ICX3_FANCONTROL_SIZE, buff);
if (read_result != ICX3_FANCONTROL_SIZE) {
return 0;
}
fanstatus = (struct icx3_fancontrol*) &buff;
printf("%s: %d RPM (%d/%d%%, %s)\n",
icx3_fan_names[i],
fanstatus->rpm_status,
fanstatus->duty_status,
fanstatus->duty,
icx3_fan_mode_names[fanstatus->fanmode]
);
}
struct icx3_tempsensors *tempsensors;
read_result = i2c_smbus_read_i2c_block_data(fp, ICX3_REG_TEMPSENSOR, ICX3_TEMPSENSOR_SIZE, buff);
if (read_result != ICX3_TEMPSENSOR_SIZE) {
return 0;
}
tempsensors = (struct icx3_tempsensors*) &buff;
float cur_temp;
short cur_data;
for (int i=0; i<ICX3_NUM_TEMP_SENSORS; i++) {
cur_data = (short)(tempsensors->data[2*i+1] << 8) | (short)(tempsensors->data[2*i]);
cur_temp = (float)cur_data/10;
printf("%s %.1f C\n",
icx3_temp_sensor_names[i],
cur_temp);
}
}
/* Check an I2C device file for an ICX3 controller, returs the product id. */
enum icx3_product_id check_for_icx3(char *i2c_dev_path)
{
char data[I2C_SMBUS_BLOCK_MAX] = {};
int test_fd, read_result;
struct icx3_info *temp_info;
test_fd = fopen(i2c_dev_path, O_RDONLY);
if (!test_fd)
return ICX3_NONE;
if (ioctl(test_fd, I2C_SLAVE, ICX3_I2C_ADDR) < 0) {
close(test_fd);
return ICX3_NONE;
}
read_result = i2c_smbus_read_i2c_block_data(test_fd, ICX3_REG_READINFORMATION, ICX3_READINFORMATION_SIZE, buff);
if (read_result == ICX3_READINFORMATION_SIZE) {
temp_info = (struct *icx3_info)&buff;
if (temp_info->slave_address == ICX3_I2C_ADDR)
return temp_info->product_id;
}
return ICX3_NONE;
}