summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2012-05-20 16:59:58 +0800
committerVic Yang <victoryang@chromium.org>2012-05-22 01:00:41 +0800
commitf618a74f7f72a89d764e727556778c8ad411761a (patch)
tree5e80b0c59254882a07bcf66b580b30c1970237d8
parent01e94792e7436e89e55f043982e9446e0759bf25 (diff)
downloadchrome-ec-f618a74f7f72a89d764e727556778c8ad411761a.tar.gz
Add host command to read temperature sensor info
In order to perform testing across all future boards and enable easier debugging, we need a host command to read temperature sensor name and sensor type. BUG=chrome-os-patner:9836 TEST='ectool tempsinfo 0' shows sensor name and its type. Change-Id: I06d9c6b045902394179c35e2ee8bc8dc551e8e98
-rw-r--r--common/build.mk2
-rw-r--r--common/temp_sensor_commands.c37
-rw-r--r--include/ec_commands.h14
-rw-r--r--util/ectool.c33
4 files changed, 85 insertions, 1 deletions
diff --git a/common/build.mk b/common/build.mk
index 99ce6eaffb..3c50e868a7 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -23,7 +23,7 @@ common-$(CONFIG_TASK_I8042CMD)+=i8042.o keyboard.o
common-$(CONFIG_TASK_LIGHTBAR)+=lightbar.o
common-$(CONFIG_TASK_POWERSTATE)+=smart_battery.o charge_state.o \
battery_precharge.o
-common-$(CONFIG_TASK_TEMPSENSOR)+=temp_sensor.o
+common-$(CONFIG_TASK_TEMPSENSOR)+=temp_sensor.o temp_sensor_commands.o
common-$(CONFIG_TASK_THERMAL)+=thermal.o thermal_commands.o
common-$(CONFIG_TASK_X86POWER)+=x86_power.o
common-$(CONFIG_TMP006)+=tmp006.o
diff --git a/common/temp_sensor_commands.c b/common/temp_sensor_commands.c
new file mode 100644
index 0000000000..be0a2d5723
--- /dev/null
+++ b/common/temp_sensor_commands.c
@@ -0,0 +1,37 @@
+/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Temp sensor host commands for Chrome EC */
+
+#include "host_command.h"
+#include "temp_sensor.h"
+#include "util.h"
+
+
+/* Defined in board_temp_sensor.c. Must be in the same order as
+ * in enum temp_sensor_id.
+ */
+extern const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT];
+
+
+int temp_sensor_command_get_info(uint8_t *data, int *resp_size)
+{
+ struct ec_params_temp_sensor_get_info *p =
+ (struct ec_params_temp_sensor_get_info *)data;
+ struct ec_response_temp_sensor_get_info *r =
+ (struct ec_response_temp_sensor_get_info *)data;
+ int id = p->id;
+
+ if (id >= TEMP_SENSOR_COUNT)
+ return EC_RES_ERROR;
+
+ strzcpy(r->sensor_name, temp_sensors[id].name, 30);
+ r->sensor_type = temp_sensors[id].type;
+
+ *resp_size = sizeof(struct ec_response_temp_sensor_get_info);
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_TEMP_SENSOR_GET_INFO,
+ temp_sensor_command_get_info);
diff --git a/include/ec_commands.h b/include/ec_commands.h
index d71d75c3d5..91b5443e79 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -502,6 +502,20 @@ struct ec_response_mkbp_info {
} __attribute__ ((packed));
/*****************************************************************************/
+/* Temperature sensor commands */
+
+/* Read temperature sensor info */
+#define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
+struct ec_params_temp_sensor_get_info {
+ uint8_t id;
+} __attribute__ ((packed));
+
+struct ec_response_temp_sensor_get_info {
+ char sensor_name[32];
+ uint8_t sensor_type;
+} __attribute__ ((packed));
+
+/*****************************************************************************/
/* Host event commands */
/* Host event mask params and response structures, shared by all of the host
diff --git a/util/ectool.c b/util/ectool.c
index f908c077b3..dd51dc62a9 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -76,6 +76,8 @@ const char help_str[] =
" Prints EC version\n"
" temps <sensorid>\n"
" Print temperature.\n"
+ " tempsinfo <sensorid>\n"
+ " Print temperature sensor info.\n"
" thermalget <sensor_id> <threshold_id>\n"
" Get the threshold temperature value from thermal engine.\n"
" thermalset <sensor_id> <threshold_id> <value>\n"
@@ -658,6 +660,36 @@ int cmd_temperature(int argc, char *argv[])
}
+int cmd_temp_sensor_info(int argc, char *argv[])
+{
+ struct ec_params_temp_sensor_get_info p;
+ struct ec_response_temp_sensor_get_info r;
+ int rv;
+ char *e;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <sensorid>\n", argv[0]);
+ return -1;
+ }
+
+ p.id = strtol(argv[1], &e, 0);
+ if (e && *e) {
+ fprintf(stderr, "Bad sensor ID.\n");
+ return -1;
+ }
+
+ rv = ec_command(EC_CMD_TEMP_SENSOR_GET_INFO,
+ &p, sizeof(p), &r, sizeof(r));
+ if (rv)
+ return rv;
+
+ printf("Sensor name: %s\n", r.sensor_name);
+ printf("Sensor type: %d\n", r.sensor_type);
+
+ return 0;
+}
+
+
int cmd_thermal_get_threshold(int argc, char *argv[])
{
struct ec_params_thermal_get_threshold p;
@@ -1463,6 +1495,7 @@ const struct command commands[] = {
{"sertest", cmd_serial_test},
{"switches", cmd_switches},
{"temps", cmd_temperature},
+ {"tempsinfo", cmd_temp_sensor_info},
{"thermalget", cmd_thermal_get_threshold},
{"thermalset", cmd_thermal_set_threshold},
{"usbchargemode", cmd_usb_charge_set_mode},