summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2016-05-16 09:45:57 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2016-05-18 07:47:51 +0200
commit04624274360a345ef3e4ce89d5553115d49bfd8f (patch)
treec80ce8b6477e980fb81049c05232e7451d24534f
parent914480a542aabd56ba5220afe0e234fd8213411e (diff)
downloadbarebox-04624274360a345ef3e4ce89d5553115d49bfd8f.tar.gz
barebox-04624274360a345ef3e4ce89d5553115d49bfd8f.tar.xz
commands: Add 'hwmon' command
Add 'hwmon' command which allows to display the readings of all hardware monitoring sensors registered with Barebox. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--commands/Kconfig8
-rw-r--r--commands/Makefile1
-rw-r--r--commands/hwmon.c35
3 files changed, 44 insertions, 0 deletions
diff --git a/commands/Kconfig b/commands/Kconfig
index 80df4ddec2..ec8c752bc0 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1807,6 +1807,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 f1b482f049..7d848e7499 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -106,6 +106,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 0000000000..ace4503c0b
--- /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