1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (c) 2022 Sartura Ltd.
5 * Written by Robert Marko <robert.marko@sartura.hr>
13 #define LIMIT_DEVNAME 30
15 static int do_get(struct cmd_tbl *cmdtp, int flag, int argc,
22 printf("thermal device not selected\n");
23 return CMD_RET_FAILURE;
26 ret = uclass_get_device_by_name(UCLASS_THERMAL, argv[1], &dev);
28 printf("thermal device not found\n");
29 return CMD_RET_FAILURE;
32 ret = thermal_get_temp(dev, &temp);
34 return CMD_RET_FAILURE;
36 printf("%s: %d C\n", dev->name, temp);
38 return CMD_RET_SUCCESS;
41 static int do_list(struct cmd_tbl *cmdtp, int flag, int argc,
46 printf("| %-*.*s| %-*.*s| %s\n",
47 LIMIT_DEVNAME, LIMIT_DEVNAME, "Device",
48 LIMIT_DEVNAME, LIMIT_DEVNAME, "Driver",
51 uclass_foreach_dev_probe(UCLASS_THERMAL, dev) {
52 printf("| %-*.*s| %-*.*s| %s\n",
53 LIMIT_DEVNAME, LIMIT_DEVNAME, dev->name,
54 LIMIT_DEVNAME, LIMIT_DEVNAME, dev->driver->name,
58 return CMD_RET_SUCCESS;
61 static struct cmd_tbl temperature_subcmd[] = {
62 U_BOOT_CMD_MKENT(list, 1, 1, do_list, "", ""),
63 U_BOOT_CMD_MKENT(get, 2, 1, do_get, "", ""),
66 static int do_temperature(struct cmd_tbl *cmdtp, int flag, int argc,
74 cmd = find_cmd_tbl(argv[0], temperature_subcmd, ARRAY_SIZE(temperature_subcmd));
75 if (!cmd || argc > cmd->maxargs)
78 return cmd->cmd(cmdtp, flag, argc, argv);
81 U_BOOT_CMD(temperature, CONFIG_SYS_MAXARGS, 1, do_temperature,
82 "thermal sensor temperature",
83 "list\t\tshow list of temperature sensors\n"
84 "get [thermal device name]\tprint temperature in degrees C"