summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@google.com>2011-12-21 17:03:43 +0800
committerVic Yang <victoryang@google.com>2011-12-22 13:51:07 +0800
commitb228bc14c01f54bc70b82ea85bcb82dd402006a1 (patch)
tree79842c8aa2894a11abe75954e4e99da7edd61744
parent84a286b1f49c25df1d44bbf87d748b20421f5521 (diff)
downloadchrome-ec-b228bc14c01f54bc70b82ea85bcb82dd402006a1.tar.gz
Add host command to read temperature sensor value
Add a LPC host command to read temperature sensor value with given sensor id. Add ectool command to read temperature sensor value through LPC. BUG=chrome-os-partner:7329 TEST=Manual check the reading received is the same as value printed by console command. Change-Id: Id3386774435be6c3ae010a143f4fa894568efdb8
-rw-r--r--common/build.mk2
-rw-r--r--common/host_command.c4
-rw-r--r--common/temp_sensor_commands.c33
-rw-r--r--include/lpc_commands.h12
-rw-r--r--include/temp_sensor_commands.h19
-rw-r--r--util/ectool.c31
6 files changed, 100 insertions, 1 deletions
diff --git a/common/build.mk b/common/build.mk
index f398119bf8..1943d688c3 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -4,4 +4,4 @@
common-objs=main.o util.o console.o vboot.o
common-objs+=flash_commands.o host_command.o port80.o keyboard.o i8042.o
-common-objs+=memory_commands.o shared_mem.o
+common-objs+=memory_commands.o shared_mem.o temp_sensor_commands.o
diff --git a/common/host_command.c b/common/host_command.c
index 578fe33093..0d7c959792 100644
--- a/common/host_command.c
+++ b/common/host_command.c
@@ -9,6 +9,7 @@
#include "console.h"
#include "flash_commands.h"
#include "host_command.h"
+#include "temp_sensor_commands.h"
#include "lpc.h"
#include "lpc_commands.h"
#include "system.h"
@@ -172,6 +173,9 @@ static void command_process(int slot)
lpc_send_host_response(slot, flash_command_checksum(data));
return;
#endif
+ case EC_LPC_COMMAND_TEMP_SENSOR_GET_READINGS:
+ lpc_send_host_response(slot, temp_sensor_command_get_readings(data));
+ return;
default:
lpc_send_host_response(slot, EC_LPC_STATUS_INVALID_COMMAND);
}
diff --git a/common/temp_sensor_commands.c b/common/temp_sensor_commands.c
new file mode 100644
index 0000000000..a532144df2
--- /dev/null
+++ b/common/temp_sensor_commands.c
@@ -0,0 +1,33 @@
+/* Copyright (c) 2011 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.
+ */
+
+/* Temperature sensor module for Chrome EC */
+
+#include "console.h"
+#include "temp_sensor.h"
+#include "temp_sensor_commands.h"
+#include "lpc_commands.h"
+#include "uart.h"
+#include "util.h"
+
+
+/*****************************************************************************/
+/* Host commands */
+
+enum lpc_status temp_sensor_command_get_readings(uint8_t *data)
+{
+ struct lpc_params_temp_sensor_get_readings *p =
+ (struct lpc_params_temp_sensor_get_readings *)data;
+ struct lpc_response_temp_sensor_get_readings *r =
+ (struct lpc_response_temp_sensor_get_readings *)data;
+
+ int rv;
+ rv = temp_sensor_read(p->temp_sensor_id);
+ if (rv == -1)
+ return EC_LPC_STATUS_ERROR;
+ r->value = rv;
+
+ return EC_LPC_STATUS_SUCCESS;
+}
diff --git a/include/lpc_commands.h b/include/lpc_commands.h
index 08b4d9c1d8..a7ba4818c9 100644
--- a/include/lpc_commands.h
+++ b/include/lpc_commands.h
@@ -205,4 +205,16 @@ struct lpc_response_flash_checksum {
#endif /* SUPPORT_CHECKSUM */
+/*****************************************************************************/
+/* Temperature sensor commands */
+
+/* Get temperature readings */
+#define EC_LPC_COMMAND_TEMP_SENSOR_GET_READINGS 0x30
+struct lpc_params_temp_sensor_get_readings {
+ uint8_t temp_sensor_id;
+} __attribute__ ((packed));
+struct lpc_response_temp_sensor_get_readings {
+ uint32_t value;
+} __attribute__ ((packed));
+
#endif /* __CROS_EC_LPC_COMMANDS_H */
diff --git a/include/temp_sensor_commands.h b/include/temp_sensor_commands.h
new file mode 100644
index 0000000000..6971804895
--- /dev/null
+++ b/include/temp_sensor_commands.h
@@ -0,0 +1,19 @@
+/* Copyright (c) 2011 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.
+ */
+
+/* Temperature sensor commands for Chrome EC */
+
+#ifndef __CROS_EC_TEMP_SENSOR_COMMANDS_H
+#define __CROS_EC_TEMP_SENSOR_COMMANDS_H
+
+#include "common.h"
+
+/* Initializes the module. */
+int temp_sensor_commands_init(void);
+
+/* Host command handlers. */
+enum lpc_status temp_sensor_command_get_readings(uint8_t *data);
+
+#endif /* __CROS_EC_TEMP_SENSOR_COMMANDS_H */
diff --git a/util/ectool.c b/util/ectool.c
index 2b1f40d3e1..11012069d9 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -10,6 +10,7 @@
#include <unistd.h>
#include "lpc_commands.h"
+#include "temp_sensor.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
/* Don't use a macro where an inline will do... */
@@ -34,6 +35,8 @@ const char help_str[] =
" Serial output test for COM2\n"
" version\n"
" Prints EC version\n"
+ " temps\n"
+ " Print temperature\n"
"\n"
"Not working for you? Make sure LPC I/O is configured:\n"
" pci_write32 0 0x1f 0 0x88 0x007c0801\n"
@@ -430,6 +433,32 @@ int cmd_serial_test(int argc, char *argv[])
return 0;
}
+int get_temperature(int sensor_id, const char* name)
+{
+ struct lpc_params_temp_sensor_get_readings p;
+ struct lpc_response_temp_sensor_get_readings r;
+ int rv;
+
+ p.temp_sensor_id = sensor_id;
+ printf("Reading %s...", name);
+ rv = ec_command(EC_LPC_COMMAND_TEMP_SENSOR_GET_READINGS, &p, sizeof(p), &r, sizeof(r));
+ if (rv)
+ printf("Error\n");
+ else
+ printf("%d\n", r.value);
+ return rv;
+}
+
+int cmd_temperature(void)
+{
+ int rv1, rv2, rv3;
+ rv1 = get_temperature(TEMP_SENSOR_CASE, "TEMP_SENSOR_CASE");
+ rv2 = get_temperature(TEMP_SENSOR_CASE_DIE, "TEMP_SENSOR_CASE_DIE");
+ rv3 = get_temperature(TEMP_SENSOR_EC_INTERNAL, "TEMP_SENSOR_EC_INTERNAL");
+ if (rv1 || rv2 || rv3)
+ return -1;
+ return 0;
+}
int main(int argc, char *argv[])
{
@@ -462,6 +491,8 @@ int main(int argc, char *argv[])
return cmd_serial_test(argc - 2, argv + 2);
if (!strcasecmp(argv[1], "version"))
return cmd_version();
+ if (!strcasecmp(argv[1], "temps"))
+ return cmd_temperature();
/* If we're still here, command was unknown */
fprintf(stderr, "Unknown command '%s'\n\n", argv[1]);