summaryrefslogtreecommitdiffstats
path: root/commands/hwmon.c
blob: 04c3e728c63689f2f9da5612c0755b5add3e4d6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// SPDX-License-Identifier: GPL-2.0-only

#include <common.h>
#include <command.h>
#include <getopt.h>
#include <linux/err.h>
#include <linux/ctype.h>
#include <string.h>
#include <environment.h>
#include <aiodev.h>

static int do_hwmon(int argc, char *argv[])
{
	int i;
	struct aiodevice *aiodev;

	for_each_aiodevice(aiodev) {
		for (i = 0; i < aiodev->num_channels; i++) {
			struct aiochannel *chan = aiodev->channels[i];
			int value;
			int ret = aiochannel_get_value(chan, &value);

			if (!ret)
				printf("%s: %d %s\n", chan->name, value, chan->unit);
			else
				printf("%s: failed to read (%d)\n", chan->name, ret);
		}
	}

	return 0;
}

BAREBOX_CMD_START(hwmon)
	.cmd		= do_hwmon,
	BAREBOX_CMD_DESC("query hardware sensors (HWMON)")
	BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
BAREBOX_CMD_END