summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB R, Harsha <harsha.b.r@intel.com>2021-10-29 08:02:18 +0530
committerCommit Bot <commit-bot@chromium.org>2021-11-12 22:23:49 +0000
commit8b8561d3d871bafbc36b26aa6d190f4f7138f5d4 (patch)
treea975ad02e9d6c206aceaa8e5d68d4f4758194fcd
parent98264cad7719487bf3ecbc4f45b80e900b174cf8 (diff)
downloadchrome-ec-8b8561d3d871bafbc36b26aa6d190f4f7138f5d4.tar.gz
ectool: Change "ectool temps all" output similar to EC console command
Retrieve sensor name and thermal fan percentage. To the print statement add additional parameters - sensor_name, temperature converted from kelvin to Celsius and thermal_fan_percent in addition to temperature reading in Kelvin. Also update the display and help message of temps command for both EC and CPU console Sample output: 21-11-12 23:48:28.062 DDR and SOC 314 K (= 41 C) 40% CPU Console: localhost ~ # ectool temps all --sensor name -------- temperature -------- fan speed -- DDR and SOC 314 K (= 41 C) 40% BRANCH=none TEST=make buildall -j, zmake testall, Run ectool temps all on CPU console and Run temps all on EC console, See a sample output above Signed-off-by: B R, Harsha <harsha.b.r@intel.com> Change-Id: Id86652d426fdbf30a1b27db8c2d2e7ce1b9a1d4c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3252569 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--common/temp_sensor.c8
-rw-r--r--util/ectool.c59
2 files changed, 53 insertions, 14 deletions
diff --git a/common/temp_sensor.c b/common/temp_sensor.c
index 219e28254c..2f6480e31d 100644
--- a/common/temp_sensor.c
+++ b/common/temp_sensor.c
@@ -108,18 +108,18 @@ int print_temps(void)
int rv, rv1 = EC_SUCCESS;
for (i = 0; i < TEMP_SENSOR_COUNT; ++i) {
- ccprintf(" %-20s: ", temp_sensors[i].name);
+ ccprintf(" %-20s ", temp_sensors[i].name);
rv = temp_sensor_read(i, &t);
if (rv)
rv1 = rv;
switch (rv) {
case EC_SUCCESS:
- ccprintf("%d K = %d C", t, K_TO_C(t));
+ ccprintf("%d K (= %d C)", t, K_TO_C(t));
#ifdef CONFIG_THROTTLE_AP
if (thermal_params[i].temp_fan_off &&
thermal_params[i].temp_fan_max)
- ccprintf(" %d%%",
+ ccprintf(" %11d%%",
thermal_fan_percent(
thermal_params[i].temp_fan_off,
thermal_params[i].temp_fan_max,
@@ -151,7 +151,7 @@ static int command_temps(int argc, char **argv)
}
DECLARE_CONSOLE_COMMAND(temps, command_temps,
NULL,
- "Print temp sensors");
+ "Print temp sensors and fan speed");
#endif
/*****************************************************************************/
diff --git a/util/ectool.c b/util/ectool.c
index 6e0a1f91cb..0bc35ef3b4 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -305,7 +305,7 @@ const char help_str[] =
" switches\n"
" Prints current EC switch positions\n"
" temps <sensorid>\n"
- " Print temperature.\n"
+ " Print temperature and fan speed\n"
" tempsinfo <sensorid>\n"
" Print temperature sensor info.\n"
" thermalget <platform-specific args>\n"
@@ -3022,12 +3022,50 @@ int read_mapped_temperature(int id)
return rv;
}
+static int get_thermal_fan_percent(int temp)
+{
+ struct ec_params_thermal_get_threshold_v1 p;
+ struct ec_thermal_config r;
+ int rv = 0;
+
+ rv = ec_command(EC_CMD_THERMAL_GET_THRESHOLD, 1, &p, sizeof(p),
+ &r, sizeof(r));
+
+ if (rv <= 0 || r.temp_fan_max == r.temp_fan_off)
+ return -1;
+ if (temp < r.temp_fan_off)
+ return 0;
+ if (temp > r.temp_fan_max)
+ return 100;
+ return 100 * (temp - r.temp_fan_off) /
+ (r.temp_fan_max - r.temp_fan_off);
+}
+
+static int cmd_temperature_print(int id, int mtemp)
+{
+ struct ec_response_temp_sensor_get_info r;
+ struct ec_params_temp_sensor_get_info p;
+ int rc;
+ int temp = mtemp + EC_TEMP_SENSOR_OFFSET;
+
+ p.id = id;
+ rc = ec_command(EC_CMD_TEMP_SENSOR_GET_INFO, 0, &p, sizeof(p),
+ &r, sizeof(r));
+ if (rc < 0)
+ return rc;
+ printf("%-20s %d K (= %d C) %11d%%\n", r.sensor_name, temp,
+ K_TO_C(temp), get_thermal_fan_percent(temp));
+
+ return 0;
+}
int cmd_temperature(int argc, char *argv[])
{
- int rv;
+ int mtemp;
int id;
char *e;
+ const char header[] = "--sensor name -------- temperature "
+ "-------- fan speed --\n";
if (argc != 2) {
fprintf(stderr, "Usage: %s <sensorid> | all\n", argv[0]);
@@ -3035,11 +3073,12 @@ int cmd_temperature(int argc, char *argv[])
}
if (strcmp(argv[1], "all") == 0) {
+ fprintf(stdout, header);
for (id = 0;
id < EC_TEMP_SENSOR_ENTRIES + EC_TEMP_SENSOR_B_ENTRIES;
id++) {
- rv = read_mapped_temperature(id);
- switch (rv) {
+ mtemp = read_mapped_temperature(id);
+ switch (mtemp) {
case EC_TEMP_SENSOR_NOT_PRESENT:
break;
case EC_TEMP_SENSOR_ERROR:
@@ -3053,8 +3092,7 @@ int cmd_temperature(int argc, char *argv[])
id);
break;
default:
- printf("%d: %d K\n", id,
- rv + EC_TEMP_SENSOR_OFFSET);
+ cmd_temperature_print(id, mtemp);
}
}
return 0;
@@ -3073,9 +3111,9 @@ int cmd_temperature(int argc, char *argv[])
}
printf("Reading temperature...");
- rv = read_mapped_temperature(id);
+ mtemp = read_mapped_temperature(id);
- switch (rv) {
+ switch (mtemp) {
case EC_TEMP_SENSOR_NOT_PRESENT:
printf("Sensor not present\n");
return -1;
@@ -3089,8 +3127,9 @@ int cmd_temperature(int argc, char *argv[])
fprintf(stderr, "Sensor not calibrated\n");
return -1;
default:
- printf("%d K\n", rv + EC_TEMP_SENSOR_OFFSET);
- return 0;
+ fprintf(stdout, "\n");
+ fprintf(stdout, header);
+ return cmd_temperature_print(id, mtemp);
}
}