summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerrit <chrome-bot@google.com>2012-03-14 07:06:07 -0700
committerGerrit Code Review <gerrit@gerrit.golo.chromium.org>2012-03-14 07:06:07 -0700
commit5f83ab456c08feb6c62dc79d4800c60e357125c3 (patch)
treeb6112c8d9c7a7789bac528a60d39ba258fa42dae
parent6f0512752f131cc5d5238707199337b0e2820af3 (diff)
parentdfe22b2b1e7bf6c810332357044cb3f462453d68 (diff)
downloadchrome-ec-5f83ab456c08feb6c62dc79d4800c60e357125c3.tar.gz
Merge "Add back LPC temperature read command as workaround."
-rw-r--r--common/build.mk2
-rw-r--r--common/temp_sensor_commands.c39
-rw-r--r--include/lpc_commands.h12
-rw-r--r--include/temp_sensor_commands.h22
-rw-r--r--util/ectool.c38
5 files changed, 112 insertions, 1 deletions
diff --git a/common/build.mk b/common/build.mk
index 6d47f8fcc5..a30288d383 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -17,7 +17,7 @@ common-$(CONFIG_FLASH)+=flash_commands.o
common-$(CONFIG_PSTORE)+=pstore_commands.o
common-$(CONFIG_PWM)+=pwm_commands.o
common-$(CONFIG_TASK_THERMAL)+=thermal.o thermal_commands.o
-common-$(CONFIG_TEMP_SENSOR)+=temp_sensor.o
+common-$(CONFIG_TEMP_SENSOR)+=temp_sensor.o temp_sensor_commands.o
common-$(CONFIG_TMP006)+=tmp006.o
common-$(CONFIG_LIGHTBAR)+=leds.o
diff --git a/common/temp_sensor_commands.c b/common/temp_sensor_commands.c
new file mode 100644
index 0000000000..77114aa727
--- /dev/null
+++ b/common/temp_sensor_commands.c
@@ -0,0 +1,39 @@
+/* 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 */
+/* This LPC command only serves as a workaround to provide reliable temperature
+ * reading method until we solve the I2C hanging issue. Remove this when
+ * possible. */
+
+#include "console.h"
+#include "host_command.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_RESULT_ERROR;
+ r->value = rv;
+
+ return EC_LPC_RESULT_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_LPC_COMMAND_TEMP_SENSOR_GET_READINGS,
+ temp_sensor_command_get_readings);
diff --git a/include/lpc_commands.h b/include/lpc_commands.h
index 4e92f9da23..dc92a8de87 100644
--- a/include/lpc_commands.h
+++ b/include/lpc_commands.h
@@ -423,6 +423,18 @@ struct lpc_response_battery_text {
#define EC_LPC_COMMAND_BATTERY_OEM 0x64
/*****************************************************************************/
+/* Temperature sensor commands */
+
+/* Get temperature readings */
+#define EC_LPC_COMMAND_TEMP_SENSOR_GET_READINGS 0x70
+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));
+
+/*****************************************************************************/
/* Host event commands */
#define EC_LPC_COMMAND_HOST_EVENT_GET_SMI_MASK 0x88
diff --git a/include/temp_sensor_commands.h b/include/temp_sensor_commands.h
new file mode 100644
index 0000000000..68ecdecfc1
--- /dev/null
+++ b/include/temp_sensor_commands.h
@@ -0,0 +1,22 @@
+/* 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 */
+/* This LPC command only serves as a workaround to provide reliable temperature
+ * reading method until we solve the I2C hanging issue. Remove this when
+ * possible. */
+
+#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 091bf01fec..a7c7c2cbc6 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -60,6 +60,8 @@ const char help_str[] =
" Prints EC version\n"
" temps <sensorid>\n"
" Print temperature.\n"
+ " tempread <sensorid>\n"
+ " Force a read of temperature sensor.\n"
" thermalget <sensor_id> <threshold_id>\n"
" Get the threshold temperature value from thermal engine.\n"
" thermalset <sensor_id> <threshold_id> <value>\n"
@@ -608,6 +610,41 @@ int cmd_temperature(int argc, char *argv[])
}
+int cmd_temperature_read(int argc, char *argv[])
+{
+ struct lpc_params_temp_sensor_get_readings p;
+ struct lpc_response_temp_sensor_get_readings r;
+ char *e;
+ int rv;
+
+ if (argc != 1) {
+ fprintf(stderr, "Usage: tempread <sensorid\n>");
+ return -1;
+ }
+
+ p.temp_sensor_id = strtol(argv[0], &e, 0);
+ if (e && *e) {
+ fprintf(stderr, "Bad sensor ID.\n");
+ return -1;
+ }
+
+ printf("Reading temperature...");
+
+ rv = ec_command(EC_LPC_COMMAND_TEMP_SENSOR_GET_READINGS,
+ &p, sizeof(p), &r, sizeof(r));
+ if (rv)
+ return rv;
+
+ if (r.value < 0) {
+ printf("Error\n");
+ return -1;
+ }
+
+ printf("%d\n", r.value);
+ return 0;
+}
+
+
int cmd_thermal_get_threshold(int argc, char *argv[])
{
struct lpc_params_thermal_get_threshold p;
@@ -1176,6 +1213,7 @@ const struct command commands[] = {
{"sertest", cmd_serial_test},
{"switches", cmd_switches},
{"temps", cmd_temperature},
+ {"tempread", cmd_temperature_read},
{"thermalget", cmd_thermal_get_threshold},
{"thermalset", cmd_thermal_set_threshold},
{"usbchargemode", cmd_usb_charge_set_mode},