Add back LPC temperature read command as workaround.

Until we solve the I2C hanging issue, we need a reliable way to read
temperature. Add back LPC temperature read command that actually trigger
a I2C read.

Signed-off-by: Vic Yang <victoryang@google.com>

BUG=chrome-os-partner:8452,chrome-os-partner:8495
TEST=none

Change-Id: Icddd1fe3c1f09889bca633af19041a8aca582de9
This commit is contained in:
Vic Yang
2012-03-14 20:09:42 +08:00
parent a7b90e65b4
commit dfe22b2b1e
5 changed files with 112 additions and 1 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -422,6 +422,18 @@ struct lpc_response_battery_text {
/* Get battery OEM name */
#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 */

View File

@@ -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 */

View File

@@ -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},