[PATCH 5/7] commands: Add 'hwmon' command
Andrey Smirnov
andrew.smirnov at gmail.com
Sun Dec 6 23:52:41 PST 2015
Add 'hwmon' command which allows to display the readings of all
hardware monitoring sensors registered with Barebox.
Signed-off-by: Andrey Smirnov <andrew.smirnov at gmail.com>
---
commands/Kconfig | 8 ++++++++
commands/Makefile | 1 +
commands/hwmon.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 56 insertions(+)
create mode 100644 commands/hwmon.c
diff --git a/commands/Kconfig b/commands/Kconfig
index 1743670..a338efd 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1799,6 +1799,14 @@ config CMD_HWCLOCK
help
The hwclock command allows to query or set the hardware clock (RTC).
+config CMD_HWMON
+ bool
+ depends on HWMON
+ 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 d985341..6c5158c 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -105,6 +105,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..84c0c70
--- /dev/null
+++ b/commands/hwmon.c
@@ -0,0 +1,47 @@
+#include <common.h>
+#include <command.h>
+#include <getopt.h>
+#include <linux/err.h>
+#include <linux/ctype.h>
+#include <string.h>
+#include <environment.h>
+#include <hwmon.h>
+
+static int do_hwmon(int argc, char *argv[])
+{
+ struct hwmon_sensor *s;
+
+ for_each_hwmon_sensor(s) {
+ s32 value;
+ int ret = hwmon_sensor_read(s, &value);
+
+ if (ret < 0) {
+ printf("%s -- failed to read the sensor (%d)\n", s->name, ret);
+ continue;
+ }
+
+ switch (s->type) {
+ case SENSOR_TEMPERATURE:
+ printf("name: %s, reading: %d.%03d C\n",
+ s->name, (int)(value / 1000), (int)abs(value % 1000));
+ break;
+ default:
+ printf("%s -- unknow type of sensor\n", s->name);
+ break;
+ }
+ }
+
+ return 0;
+}
+
+#if 0
+BAREBOX_CMD_HELP_START(hwmon)
+BAREBOX_CMD_HELP_END
+#endif
+
+BAREBOX_CMD_START(hwmon)
+ .cmd = do_hwmon,
+ BAREBOX_CMD_DESC("query hardware sensors (HWMON)")
+ BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
+ /* BAREBOX_CMD_HELP(cmd_hwmon_help) */
+BAREBOX_CMD_END
--
2.5.0
More information about the barebox
mailing list