mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-24 20:21:43 +00:00
Merge pull request 'libsensors: support SDIO devices' (#444) from wens/libsensors-sdio into master
This commit is contained in:
commit
5ef5910943
4 files changed
+38
-2
No files matched your search
@@ -386,6 +386,8 @@ const char *sensors_get_adapter_name(const sensors_bus_id *bus)
|
||||
return "MDIO adapter";
|
||||
case SENSORS_BUS_TYPE_SCSI:
|
||||
return "SCSI adapter";
|
||||
case SENSORS_BUS_TYPE_SDIO:
|
||||
return "SDIO adapter";
|
||||
}
|
||||
|
||||
/* bus types with several instances */
|
||||
|
||||
@@ -127,6 +127,8 @@ int sensors_parse_chip_name(const char *name, sensors_chip_name *res)
|
||||
res->bus.type = SENSORS_BUS_TYPE_MDIO;
|
||||
else if (!strncmp(name, "scsi", dash - name))
|
||||
res->bus.type = SENSORS_BUS_TYPE_SCSI;
|
||||
else if (!strncmp(name, "sdio", dash - name))
|
||||
res->bus.type = SENSORS_BUS_TYPE_SDIO;
|
||||
else
|
||||
goto ERROR;
|
||||
name = dash + 1;
|
||||
@@ -204,6 +206,10 @@ int sensors_snprintf_chip_name(char *str, size_t size,
|
||||
case SENSORS_BUS_TYPE_SCSI:
|
||||
return snprintf(str, size, "%s-scsi-%hd-%x", chip->prefix,
|
||||
chip->bus.nr, chip->addr);
|
||||
case SENSORS_BUS_TYPE_SDIO:
|
||||
return snprintf(str, size, "%s-sdio-%x:%04x:%x", chip->prefix,
|
||||
chip->bus.nr, (chip->addr >> 3),
|
||||
(chip->addr & 0x7));
|
||||
}
|
||||
|
||||
return -SENSORS_ERR_CHIP_NAME;
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#define SENSORS_BUS_TYPE_HID 6
|
||||
#define SENSORS_BUS_TYPE_MDIO 7
|
||||
#define SENSORS_BUS_TYPE_SCSI 8
|
||||
#define SENSORS_BUS_TYPE_SDIO 9
|
||||
#define SENSORS_BUS_NR_ANY (-1)
|
||||
#define SENSORS_BUS_NR_IGNORE (-2)
|
||||
|
||||
|
||||
+29
-2
@@ -692,6 +692,13 @@ static int classify_device(const char *dev_name,
|
||||
entry->chip.addr = (bus << 8) + (slot << 4) + fn;
|
||||
entry->chip.bus.type = SENSORS_BUS_TYPE_SCSI;
|
||||
entry->chip.bus.nr = domain;
|
||||
} else
|
||||
if (subsys && !strcmp(subsys, "sdio") &&
|
||||
sscanf(dev_name, "mmc%hx:%x:%x", &entry->chip.bus.nr, &slot, &fn) == 3) {
|
||||
/* mmc host(bus), address, function */
|
||||
/* adapter(host), channel(bus), id(target), lun */
|
||||
entry->chip.addr = (slot << 3) + fn;
|
||||
entry->chip.bus.type = SENSORS_BUS_TYPE_SDIO;
|
||||
} else {
|
||||
/* Unknown device */
|
||||
ret = 0;
|
||||
@@ -700,6 +707,26 @@ static int classify_device(const char *dev_name,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* realpath(3) that returns NULL for a path that isn't a symlink.
|
||||
This is needed to deal with devices that have a "device" sysfs
|
||||
entry that has the device ID, such as SDIO devices. */
|
||||
static char* realpath_no_symlink(const char *restrict path,
|
||||
char *restrict resolved_path)
|
||||
{
|
||||
struct stat st;
|
||||
int ret;
|
||||
|
||||
if (lstat(path, &st) < 0)
|
||||
return NULL;
|
||||
|
||||
if (!S_ISLNK(st.st_mode)) {
|
||||
errno = -EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return realpath(path, resolved_path);
|
||||
}
|
||||
|
||||
static int find_bus_type(const char *dev_path,
|
||||
const char *dev_name,
|
||||
sensors_chip_features *entry)
|
||||
@@ -740,7 +767,7 @@ static int find_bus_type(const char *dev_path,
|
||||
if (!ret) {
|
||||
snprintf(linkpath, NAME_MAX, "%s/device", my_dev_path);
|
||||
free(my_dev_path);
|
||||
my_dev_path = realpath(linkpath, NULL);
|
||||
my_dev_path = realpath_no_symlink(linkpath, NULL);
|
||||
if (my_dev_path != NULL)
|
||||
dev_name = strrchr(my_dev_path, '/') + 1;
|
||||
else if (errno == ENOMEM)
|
||||
@@ -838,7 +865,7 @@ static int sensors_add_hwmon_device(const char *path, const char *classdev)
|
||||
(void)classdev; /* hide warning */
|
||||
|
||||
snprintf(linkpath, NAME_MAX, "%s/device", path);
|
||||
dev_path = realpath(linkpath, NULL);
|
||||
dev_path = realpath_no_symlink(linkpath, NULL);
|
||||
if (dev_path == NULL) {
|
||||
if (errno == ENOMEM) {
|
||||
sensors_fatal_error(__func__, "Out of memory");
|
||||
|
||||
Reference in new issue
Block a user