Add support for virtual hwmon devices. This closes Red Hat bug #437637

and ticket #2305.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@5176 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2008-04-14 15:27:59 +00:00
1 parent c84fd9820e
commit 39b96fa477
6 files changed
+47 -10

No files matched your search

+2
View File
@@ -347,6 +347,8 @@ const char *sensors_get_adapter_name(const sensors_bus_id *bus)
so we don't have any custom string to return. */
case SENSORS_BUS_TYPE_SPI:
return "SPI adapter";
case SENSORS_BUS_TYPE_VIRTUAL:
return "Virtual device";
}
/* bus types with several instances */
+5
View File
@@ -109,6 +109,8 @@ int sensors_parse_chip_name(const char *name, sensors_chip_name *res)
res->bus.type = SENSORS_BUS_TYPE_PCI;
else if (!strncmp(name, "spi", dash - name))
res->bus.type = SENSORS_BUS_TYPE_SPI;
else if (!strncmp(name, "virtual", dash - name))
res->bus.type = SENSORS_BUS_TYPE_VIRTUAL;
else
goto ERROR;
name = dash + 1;
@@ -169,6 +171,9 @@ int sensors_snprintf_chip_name(char *str, size_t size,
case SENSORS_BUS_TYPE_SPI:
return snprintf(str, size, "%s-spi-%hd-%x", chip->prefix,
chip->bus.nr, chip->addr);
case SENSORS_BUS_TYPE_VIRTUAL:
return snprintf(str, size, "%s-virtual-%x", chip->prefix,
chip->addr);
}
return -SENSORS_ERR_CHIP_NAME;
+2 -1
View File
@@ -31,7 +31,7 @@
when the API + ABI breaks), the third digit is incremented to track small
API additions like new flags / enum values. The second digit is for tracking
larger additions like new methods. */
#define SENSORS_API_VERSION 0x400
#define SENSORS_API_VERSION 0x401
#define SENSORS_CHIP_NAME_PREFIX_ANY NULL
#define SENSORS_CHIP_NAME_ADDR_ANY -1
@@ -41,6 +41,7 @@
#define SENSORS_BUS_TYPE_ISA 1
#define SENSORS_BUS_TYPE_PCI 2
#define SENSORS_BUS_TYPE_SPI 3
#define SENSORS_BUS_TYPE_VIRTUAL 4
#define SENSORS_BUS_NR_ANY (-1)
#define SENSORS_BUS_NR_IGNORE (-2)
+23 -9
View File
@@ -476,6 +476,15 @@ static int sensors_read_one_sysfs_chip(const char *dev_path,
if (!entry.chip.path)
sensors_fatal_error(__func__, "Out of memory");
if (dev_path == NULL) {
/* Virtual device */
entry.chip.bus.type = SENSORS_BUS_TYPE_VIRTUAL;
entry.chip.bus.nr = 0;
/* For now we assume that virtual devices are unique */
entry.chip.addr = 0;
goto done;
}
/* Find bus type */
snprintf(linkpath, NAME_MAX, "%s/subsystem", dev_path);
sub_len = readlink(linkpath, subsys_path, NAME_MAX - 1);
@@ -545,6 +554,7 @@ static int sensors_read_one_sysfs_chip(const char *dev_path,
goto exit_free;
}
done:
if (sensors_read_dynamic_chip(&entry, hwmon_path) < 0)
goto exit_free;
if (!entry.subfeature) { /* No subfeature, discard chip */
@@ -593,16 +603,20 @@ static int sensors_add_hwmon_device(const char *path, const char *classdev)
snprintf(linkpath, NAME_MAX, "%s/device", path);
dev_len = readlink(linkpath, device, NAME_MAX - 1);
if (dev_len < 0)
return -SENSORS_ERR_KERNEL;
device[dev_len] = '\0';
device_p = strrchr(device, '/') + 1;
if (dev_len < 0) {
/* No device link? Treat as virtual */
err = sensors_read_one_sysfs_chip(NULL, NULL, path);
} else {
device[dev_len] = '\0';
device_p = strrchr(device, '/') + 1;
/* The attributes we want might be those of the hwmon class device,
or those of the device itself. */
err = sensors_read_one_sysfs_chip(linkpath, device_p, path);
if (err == 0)
err = sensors_read_one_sysfs_chip(linkpath, device_p, linkpath);
/* The attributes we want might be those of the hwmon class
device, or those of the device itself. */
err = sensors_read_one_sysfs_chip(linkpath, device_p, path);
if (err == 0)
err = sensors_read_one_sysfs_chip(linkpath, device_p,
linkpath);
}
if (err < 0)
return err;
return 0;