Skip to content

Commit 99cd3ac

Browse files
rgetzpcercuei
authored andcommitted
scanning: add hwmon only systems to scanning.
previously scanning on devices like default Raspberry Pi, would show things like: pi@raspberrypi:~ $ iio_info -s No IIO context found. However, this is not correct, since it has HWMON devices (which libiio now understands). So make sure we add this to the scan context. After the patch is applied, we get things like: pi@raspberrypi:~/libiio $ ./build/tests/iio_info -s Available contexts: 0: (cpu_thermal, rpi_volt on Raspberry Pi 4 Model B Rev 1.1) [local:] which is correct. Signed-off-by: Robin Getz <[email protected]>
1 parent 8492a78 commit 99cd3ac

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

local.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,7 +2170,7 @@ static int build_names(void *d, const char *path)
21702170
char *names = (char *)d;
21712171
size_t len;
21722172

2173-
if (!strstr(path, "iio:device"))
2173+
if (!strstr(path, "iio:device") && !(WITH_HWMON && strstr(path, "class/hwmon")))
21742174
return 0;
21752175

21762176
iio_snprintf(buf, sizeof(buf), "%s/name", path);
@@ -2195,15 +2195,32 @@ int local_context_scan(struct iio_scan_result *scan_result)
21952195
bool exists = false;
21962196
char *desc, *uri, *machine, buf[2 * BUF_SIZE], names[BUF_SIZE];
21972197
int ret;
2198+
bool no_iio;
21982199

21992200
ret = foreach_in_dir(&exists, "/sys/bus/iio", true, check_device);
2200-
if (ret < 0 || !exists)
2201+
no_iio = ret == -ENOENT;
2202+
if (WITH_HWMON && no_iio)
2203+
ret = 0; /* Not an error, unless we also have no hwmon devices */
2204+
if (ret < 0)
22012205
return 0;
22022206

22032207
names[0] = '\0';
2204-
ret = foreach_in_dir(&names, "/sys/bus/iio/devices", true, build_names);
2205-
if (ret < 0)
2206-
return 0;
2208+
if (!no_iio) {
2209+
ret = foreach_in_dir(&names, "/sys/bus/iio/devices", true, build_names);
2210+
if (ret < 0)
2211+
return 0;
2212+
}
2213+
2214+
if (WITH_HWMON) {
2215+
ret = foreach_in_dir(&exists, "/sys/class/hwmon", true, check_device);
2216+
if (ret == -ENOENT && !no_iio)
2217+
ret = 0; /* IIO devices but no hwmon devices - not an error */
2218+
if (ret < 0)
2219+
return 0;
2220+
ret = foreach_in_dir(&names, "/sys/class/hwmon", true, build_names);
2221+
if (ret < 0)
2222+
return 0;
2223+
}
22072224

22082225
machine = cat_file("/sys/firmware/devicetree/base/model");
22092226
if (!machine)

0 commit comments

Comments
 (0)