From patchwork Tue Sep 6 11:30:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Marko X-Patchwork-Id: 1674756 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=qPQebMlj; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MMPNz1xzPz1yh5 for ; Tue, 6 Sep 2022 22:10:59 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A6078849D9; Tue, 6 Sep 2022 14:10:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="qPQebMlj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9B1AD8499A; Tue, 6 Sep 2022 13:30:42 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3538F849AA for ; Tue, 6 Sep 2022 13:30:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=robimarko@gmail.com Received: by mail-ej1-x636.google.com with SMTP id lx1so22438939ejb.12 for ; Tue, 06 Sep 2022 04:30:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=udLo3G84zUIf+zXOeY0R1O0V3BrpkIK+M9z1Iii1crI=; b=qPQebMljo8tS3jTySa/Ips6hfg4D4NMWGfSHx5IrZY6Hszll6/tuHJcSQBlYRvQL5O AzfCDuqm3dWlmBDwoMhK9hKgVuvPqopvRpAO5xeP1Hz/239pb4fsGwRx+UrIaSWAnQLH 2CgHd8zESIaQMCi5iH/ACtZ8plGvftA8eeiyNyweQbpY1hlBsTLQsG5dYC/Q1gNSKMUG Q4Yp2Mqt4Ap7p8RJ1D4rZ2NwszOwVANYMt4LtW5qCK2wmDF2KEaW25fjk+SHoraOhMJr dT1k7YGkcYrMq3HszBZorMlaQTNxAaShSChbcnsrao03SWIo14Q3zfoMUwBNfEytb4/k 5m5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=udLo3G84zUIf+zXOeY0R1O0V3BrpkIK+M9z1Iii1crI=; b=WpPt9cny/2D4c+OaL8l0i1vficb+OQnqzOvhs1ck/WM3EhNx1VWIvoZDyjxzlX1HHm 1nckVpIxsFQdHRyVWL9Y6mUcPzx9h/fVbt/Nv/mkj3E9x0DidGI7CR2PzCgGnm0OKmLc 1tI8Q8yjgKgL22TDLi3dkTrAMVf+if94/UFt8xuMKtrfBugQyjeVV7Rg58Er117/xWr5 EvmCLsIHXusYnXWdrmLSWu5b6xw6jg6i5a5yB1frXsC0pKsHg6LfTiCI42DQltSRL579 FpY4jezJ38tUf4Ks+6cv8AQhpgKXv8XWEJ0/lTHGiK7eIx8a4EXiKIPII6FDW5FSM6Ca SMZw== X-Gm-Message-State: ACgBeo3DlBb7t1d7JiGRu+iLEXHtHR5OQyzzA5bR+qBahwvgu4WJgE6t YZzZNWNJyUuEZVWnM8xkZdI= X-Google-Smtp-Source: AA6agR7byIfq8EMFd7KjMKiWC884Ea/0AnQ4iiUktdQ3yPdkDdSBerPU5IbvcA37FbS0DpGs+CzxvQ== X-Received: by 2002:a17:907:9625:b0:730:ad62:9c86 with SMTP id gb37-20020a170907962500b00730ad629c86mr38704454ejc.281.1662463839581; Tue, 06 Sep 2022 04:30:39 -0700 (PDT) Received: from fedora.. (dh207-96-48.xnet.hr. [88.207.96.48]) by smtp.googlemail.com with ESMTPSA id x68-20020a50baca000000b0044bfdbd8a33sm8310867ede.88.2022.09.06.04.30.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 04:30:38 -0700 (PDT) From: Robert Marko X-Google-Original-From: Robert Marko To: sjg@chromium.org, pali@kernel.org, u-boot@lists.denx.de, trini@konsulko.com Cc: luka.perkov@sartura.hr, Robert Marko Subject: [PATCH v3 1/4] cmd: add temperature command Date: Tue, 6 Sep 2022 13:30:33 +0200 Message-Id: <20220906113036.1768055-1-robert.marko@sartura.hr> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 06 Sep 2022 14:10:39 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Currently, there is no way for users to check the readings from thermal sensors from U-boot console, only some boards print it during boot. So, lets add a simple "temperature" command that allows listing thermal uclass devices and getting their value. Note that the thermal devices are intenionally probed if list is used as almost always they will not get probed otherwise and there is no way for users to manually call probe on a certain device from console. Assumption is made that temperature is returned in degrees C and not milidegrees like in Linux as this is what most drivers seem to return. Signed-off-by: Robert Marko Reviewed-by: Simon Glass --- Changes in v2: * Drop by using uclass_get_device_by_name() * Make the unit clear in help * Expand Kconfig boolean and help * Drop degree symbol as test doesnt work with it. --- cmd/Kconfig | 6 ++++ cmd/Makefile | 1 + cmd/temperature.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 cmd/temperature.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 8ea064b8d2..4376909ca8 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1445,6 +1445,12 @@ config DEFAULT_SPI_MODE depends on CMD_SPI default 0 +config CMD_TEMPERATURE + bool "temperature - display the temperature from thermal sensors" + depends on DM_THERMAL + help + Provides a way to list thermal sensors and to get their readings. + config CMD_TSI148 bool "tsi148 - Command to access tsi148 device" help diff --git a/cmd/Makefile b/cmd/Makefile index 6e87522b62..141e440d01 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -152,6 +152,7 @@ obj-$(CONFIG_CMD_STRINGS) += strings.o obj-$(CONFIG_CMD_SMC) += smccc.o obj-$(CONFIG_CMD_SYSBOOT) += sysboot.o obj-$(CONFIG_CMD_STACKPROTECTOR_TEST) += stackprot_test.o +obj-$(CONFIG_CMD_TEMPERATURE) += temperature.o obj-$(CONFIG_CMD_TERMINAL) += terminal.o obj-$(CONFIG_CMD_TIME) += time.o obj-$(CONFIG_CMD_TIMER) += timer.o diff --git a/cmd/temperature.c b/cmd/temperature.c new file mode 100644 index 0000000000..420965de14 --- /dev/null +++ b/cmd/temperature.c @@ -0,0 +1,85 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +/* + * Copyright (c) 2022 Sartura Ltd. + * Written by Robert Marko + */ + +#include +#include +#include +#include + +#define LIMIT_DEVNAME 30 + +static int do_get(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct udevice *dev; + int ret, temp; + + if (argc < 2) { + printf("thermal device not selected\n"); + return CMD_RET_FAILURE; + } + + ret = uclass_get_device_by_name(UCLASS_THERMAL, argv[1], &dev); + if (ret) { + printf("thermal device not found\n"); + return CMD_RET_FAILURE; + } + + ret = thermal_get_temp(dev, &temp); + if (ret) + return CMD_RET_FAILURE; + + printf("%s: %d C\n", dev->name, temp); + + return CMD_RET_SUCCESS; +} + +static int do_list(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct udevice *dev; + + printf("| %-*.*s| %-*.*s| %s\n", + LIMIT_DEVNAME, LIMIT_DEVNAME, "Device", + LIMIT_DEVNAME, LIMIT_DEVNAME, "Driver", + "Parent"); + + uclass_foreach_dev_probe(UCLASS_THERMAL, dev) { + printf("| %-*.*s| %-*.*s| %s\n", + LIMIT_DEVNAME, LIMIT_DEVNAME, dev->name, + LIMIT_DEVNAME, LIMIT_DEVNAME, dev->driver->name, + dev->parent->name); + } + + return CMD_RET_SUCCESS; +} + +static struct cmd_tbl temperature_subcmd[] = { + U_BOOT_CMD_MKENT(list, 1, 1, do_list, "", ""), + U_BOOT_CMD_MKENT(get, 2, 1, do_get, "", ""), +}; + +static int do_temperature(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct cmd_tbl *cmd; + + argc--; + argv++; + + cmd = find_cmd_tbl(argv[0], temperature_subcmd, ARRAY_SIZE(temperature_subcmd)); + if (!cmd || argc > cmd->maxargs) + return CMD_RET_USAGE; + + return cmd->cmd(cmdtp, flag, argc, argv); +} + +U_BOOT_CMD(temperature, CONFIG_SYS_MAXARGS, 1, do_temperature, + "thermal sensor temperature", + "list\t\tshow list of temperature sensors\n" + "get [thermal device name]\tprint temperature in degrees C" +);