[PATCH 4/6] commands: Add 'hwmon' command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add 'hwmon' command which allows to display the readings of all
hardware monitoring sensors registered with Barebox.

Signed-off-by: Andrey Smirnov <andrew.smirnov@xxxxxxxxx>
---
 commands/Kconfig  |  8 ++++++++
 commands/Makefile |  1 +
 commands/hwmon.c  | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+)
 create mode 100644 commands/hwmon.c

diff --git a/commands/Kconfig b/commands/Kconfig
index 57f2878..44a457b 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1830,6 +1830,14 @@ config CMD_HWCLOCK
 	help
 	  The hwclock command allows to query or set the hardware clock (RTC).
 
+config CMD_HWMON
+	bool
+	depends on AIODEV
+	prompt "hwmon command"
+	default y
+	help
+	  The hwmon command allows to query hardware sensors.
+
 config CMD_I2C
 	bool
 	depends on I2C
diff --git a/commands/Makefile b/commands/Makefile
index 065d649..3c8ad77 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -107,6 +107,7 @@ obj-$(CONFIG_CMD_REGULATOR)	+= regulator.o
 obj-$(CONFIG_CMD_LSPCI)		+= lspci.o
 obj-$(CONFIG_CMD_IMD)		+= imd.o
 obj-$(CONFIG_CMD_HWCLOCK)	+= hwclock.o
+obj-$(CONFIG_CMD_HWMON)		+= hwmon.o
 obj-$(CONFIG_CMD_USBGADGET)	+= usbgadget.o
 obj-$(CONFIG_CMD_FIRMWARELOAD)	+= firmwareload.o
 obj-$(CONFIG_CMD_CMP)		+= cmp.o
diff --git a/commands/hwmon.c b/commands/hwmon.c
new file mode 100644
index 0000000..ace4503
--- /dev/null
+++ b/commands/hwmon.c
@@ -0,0 +1,35 @@
+#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
-- 
2.5.5


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux