Skip to content

Commit

Permalink
scanning: add hwmon only systems to scanning.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
rgetz authored and pcercuei committed Jul 17, 2023
1 parent 8492a78 commit 99cd3ac
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions local.c
Original file line number Diff line number Diff line change
Expand Up @@ -2170,7 +2170,7 @@ static int build_names(void *d, const char *path)
char *names = (char *)d;
size_t len;

if (!strstr(path, "iio:device"))
if (!strstr(path, "iio:device") && !(WITH_HWMON && strstr(path, "class/hwmon")))
return 0;

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

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

names[0] = '\0';
ret = foreach_in_dir(&names, "/sys/bus/iio/devices", true, build_names);
if (ret < 0)
return 0;
if (!no_iio) {
ret = foreach_in_dir(&names, "/sys/bus/iio/devices", true, build_names);
if (ret < 0)
return 0;
}

if (WITH_HWMON) {
ret = foreach_in_dir(&exists, "/sys/class/hwmon", true, check_device);
if (ret == -ENOENT && !no_iio)
ret = 0; /* IIO devices but no hwmon devices - not an error */
if (ret < 0)
return 0;
ret = foreach_in_dir(&names, "/sys/class/hwmon", true, build_names);
if (ret < 0)
return 0;
}

machine = cat_file("/sys/firmware/devicetree/base/model");
if (!machine)
Expand Down

0 comments on commit 99cd3ac

Please sign in to comment.