From: Keerthy <j-keerthy@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/3] cmd: thermal: Add command line interface to read out temperatures
Date: Mon, 11 Mar 2019 11:42:58 +0530 [thread overview]
Message-ID: <20190311061259.31048-3-j-keerthy@ti.com> (raw)
In-Reply-To: <20190311061259.31048-1-j-keerthy@ti.com>
Add command line interface to read out temperatures from SoC.
Takes two arguments. One is 'temperature' and the other is
instance number. In case instance number is not provided by
default 0th instance temperature is read out.
Signed-off-by: Keerthy <j-keerthy@ti.com>
---
cmd/Kconfig | 5 +++++
cmd/Makefile | 1 +
cmd/thermal.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 65 insertions(+)
create mode 100644 cmd/thermal.c
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 4bcc5c4557..d252e93d64 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1044,6 +1044,11 @@ config CMD_SPI
help
SPI utility command.
+config CMD_THERMAL
+ bool "thermal"
+ help
+ THERMAL support.
+
config CMD_TSI148
bool "tsi148 - Command to access tsi148 device"
help
diff --git a/cmd/Makefile b/cmd/Makefile
index acb85f49fb..2b66f9e36a 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -128,6 +128,7 @@ obj-$(CONFIG_CMD_SPI) += spi.o
obj-$(CONFIG_CMD_STRINGS) += strings.o
obj-$(CONFIG_CMD_SMC) += smccc.o
obj-$(CONFIG_CMD_TERMINAL) += terminal.o
+obj-$(CONFIG_CMD_THERMAL) += thermal.o
obj-$(CONFIG_CMD_TIME) += time.o
obj-$(CONFIG_CMD_TRACE) += trace.o
obj-$(CONFIG_HUSH_PARSER) += test.o
diff --git a/cmd/thermal.c b/cmd/thermal.c
new file mode 100644
index 0000000000..a31f992425
--- /dev/null
+++ b/cmd/thermal.c
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Thermal CMD
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ */
+#include <common.h>
+#include <errno.h>
+#include <dm.h>
+#include <dm/uclass-internal.h>
+#include <thermal.h>
+
+#define MAX_TEMP 150
+
+static int do_read_temp(cmd_tbl_t *cmdtp, int flag, int argc,
+ char * const argv[])
+{
+ struct udevice *tdev;
+ int cpu_temp, ret = 0;
+ u8 instance;
+ const char *units;
+
+ if (argc > 2) {
+ printf("Max Number of arguments is 2\n");
+ return -EINVAL;
+ }
+
+ /* In case instance is not given default 0th instnace is reported */
+ if (argc == 2)
+ instance = (u8)simple_strtoul(argv[1], NULL, 10);
+ else
+ instance = 0;
+
+ ret = uclass_get_device(UCLASS_THERMAL, 0, &tdev);
+ if (!ret) {
+ ret = thermal_get_temp(tdev, instance, &cpu_temp);
+ if (!ret) {
+ if (abs(cpu_temp) < MAX_TEMP)
+ units = "C";
+ else
+ units = "mC";
+
+ printf("Instance %d Temperature@%d%s\n", instance,
+ cpu_temp, units);
+ } else {
+ debug(" - invalid sensor data\n");
+ }
+ } else {
+ printf(" - invalid sensor device\n");
+ }
+
+ return ret;
+}
+
+U_BOOT_CMD(
+ temperature, 2, 0, do_read_temp,
+ "Reads temperature of a given sensor",
+ " [sensor number] - number of the temperature sensor"
+);
--
2.17.1
next prev parent reply other threads:[~2019-03-11 6:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-11 6:12 [U-Boot] [PATCH 0/3] thermal: Add multiple instance support Keerthy
2019-03-11 6:12 ` [U-Boot] [PATCH 1/3] " Keerthy
2019-03-19 1:23 ` Simon Glass
2019-03-19 14:23 ` keerthy
2019-03-21 5:22 ` Simon Glass
2019-03-11 6:12 ` Keerthy [this message]
2019-03-22 7:53 ` [U-Boot] [PATCH 2/3] cmd: thermal: Add command line interface to read out temperatures Simon Glass
2019-03-11 6:12 ` [U-Boot] [PATCH 3/3] configs: dra7xx_evm_defconfig: Enable TI_DRA7_THERMAL & CMD_THERMAL Keerthy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190311061259.31048-3-j-keerthy@ti.com \
--to=j-keerthy@ti.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.