1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (c) 2022 Sartura Ltd.
12 #define LIMIT_DEVNAME 30
14 static int do_get(struct cmd_tbl *cmdtp, int flag, int argc,
21 printf("thermal device not selected\n");
22 return CMD_RET_FAILURE;
25 ret = uclass_get_device_by_name(UCLASS_THERMAL, argv[1], &dev);
27 printf("thermal device not found\n");
28 return CMD_RET_FAILURE;
31 ret = thermal_get_temp(dev, &temp);
33 return CMD_RET_FAILURE;
35 printf("%s: %d C\n", dev->name, temp);
37 return CMD_RET_SUCCESS;
40 static int do_list(struct cmd_tbl *cmdtp, int flag, int argc,
45 printf("| %-*.*s| %-*.*s| %s\n",
46 LIMIT_DEVNAME, LIMIT_DEVNAME, "Device",
47 LIMIT_DEVNAME, LIMIT_DEVNAME, "Driver",
50 uclass_foreach_dev_probe(UCLASS_THERMAL, dev) {
51 printf("| %-*.*s| %-*.*s| %s\n",
52 LIMIT_DEVNAME, LIMIT_DEVNAME, dev->name,
53 LIMIT_DEVNAME, LIMIT_DEVNAME, dev->driver->name,
57 return CMD_RET_SUCCESS;
60 static struct cmd_tbl temperature_subcmd[] = {
61 U_BOOT_CMD_MKENT(list, 1, 1, do_list, "", ""),
62 U_BOOT_CMD_MKENT(get, 2, 1, do_get, "", ""),
65 static int do_temperature(struct cmd_tbl *cmdtp, int flag, int argc,
73 cmd = find_cmd_tbl(argv[0], temperature_subcmd, ARRAY_SIZE(temperature_subcmd));
74 if (!cmd || argc > cmd->maxargs)
77 return cmd->cmd(cmdtp, flag, argc, argv);
80 U_BOOT_CMD(temperature, CONFIG_SYS_MAXARGS, 1, do_temperature,
81 "thermal sensor temperature",
82 "list\t\tshow list of temperature sensors\n"
83 "get [thermal device name]\tprint temperature in degrees C"